LCOV - code coverage report
Current view: top level - basebmp/source - intconversion.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 3 33.3 %
Date: 2015-06-13 12:38:46 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_BASEBMP_SOURCE_INTCONVERSION_HXX
      21             : #define INCLUDED_BASEBMP_SOURCE_INTCONVERSION_HXX
      22             : 
      23             : #include <vigra/rgbvalue.hxx>
      24             : #include <functional>
      25             : 
      26             : namespace basebmp
      27             : {
      28             :     // metafunctions to retrieve correct POD from/to basebmp::Color
      29             : 
      30             :     /// type-safe conversion from RgbValue to packed int32
      31             :     template< class RgbVal > struct UInt32FromRgbValue
      32             :     {
      33           0 :         sal_uInt32 operator()( RgbVal const& c ) const
      34             :         {
      35           0 :             return (c[0] << 16) | (c[1] << 8) | c[2];
      36             :         }
      37             :     };
      38             : 
      39             :     /// type-safe conversion from packed int32 to RgbValue
      40             :     template< class RgbVal > struct RgbValueFromUInt32
      41             :     {
      42             :         RgbVal operator()( sal_uInt32 c ) const
      43             :         {
      44             :             return RgbVal((c >> 16) & 0xFF,
      45             :                           (c >> 8) & 0xFF,
      46             :                           c & 0xFF);
      47             :         }
      48             :     };
      49             : 
      50             :     //Current c++0x draft (apparently) has std::identity, but not operator()
      51             :     template<typename T> struct SGI_identity : public std::unary_function<T,T>
      52             :     {
      53             :         T& operator()(T& x) const { return x; }
      54           4 :         const T& operator()(const T& x) const { return x; }
      55             :     };
      56             : 
      57             :     /// Get converter from given data type to sal_uInt32
      58             :     template< typename DataType > struct uInt32Converter
      59             :     {
      60             :         typedef SGI_identity<DataType> to;
      61             :         typedef SGI_identity<DataType> from;
      62             :     };
      63             :     template< unsigned int RedIndex,
      64             :               unsigned int GreenIndex,
      65             :               unsigned int BlueIndex > struct uInt32Converter<
      66             :                   vigra::RGBValue< sal_uInt8,
      67             :                                    RedIndex,
      68             :                                    GreenIndex,
      69             :                                    BlueIndex > >
      70             :     {
      71             :         typedef UInt32FromRgbValue<
      72             :             vigra::RGBValue< sal_uInt8,
      73             :                              RedIndex,
      74             :                              GreenIndex,
      75             :                              BlueIndex > >
      76             :             to;
      77             :         typedef RgbValueFromUInt32<
      78             :             vigra::RGBValue< sal_uInt8,
      79             :                              RedIndex,
      80             :                              GreenIndex,
      81             :                              BlueIndex > >
      82             :             from;
      83             :     };
      84             : }
      85             : 
      86             : #endif // INCLUDED_BASEBMP_SOURCE_INTCONVERSION_HXX
      87             : 
      88             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11