xref: /trunk/main/basebmp/source/intconversion.hxx (revision 06db55ca6e7b86cf496b9e4c4bd824b1b77c53c0)
148cdb363SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
348cdb363SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
448cdb363SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
548cdb363SAndrew Rist  * distributed with this work for additional information
648cdb363SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
748cdb363SAndrew Rist  * to you under the Apache License, Version 2.0 (the
848cdb363SAndrew Rist  * "License"); you may not use this file except in compliance
948cdb363SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1148cdb363SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1348cdb363SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1448cdb363SAndrew Rist  * software distributed under the License is distributed on an
1548cdb363SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1648cdb363SAndrew Rist  * KIND, either express or implied.  See the License for the
1748cdb363SAndrew Rist  * specific language governing permissions and limitations
1848cdb363SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2048cdb363SAndrew Rist  *************************************************************/
2148cdb363SAndrew Rist 
22cdf0e10cSrcweir #ifndef INCLUDED_BASEBMP_INTCONVERSION_HXX
23cdf0e10cSrcweir #define INCLUDED_BASEBMP_INTCONVERSION_HXX
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <vigra/rgbvalue.hxx>
26cdf0e10cSrcweir #include <functional>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir namespace basebmp
29cdf0e10cSrcweir {
30cdf0e10cSrcweir     // metafunctions to retrieve correct POD from/to basebmp::Color
31cdf0e10cSrcweir     //------------------------------------------------------------------------
32cdf0e10cSrcweir 
33*06db55caSmseidel     // type-safe conversion from RgbValue to packed int32
34cdf0e10cSrcweir     template< class RgbVal > struct UInt32FromRgbValue
35cdf0e10cSrcweir     {
operator ()basebmp::UInt32FromRgbValue36cdf0e10cSrcweir         sal_uInt32 operator()( RgbVal const& c ) const
37cdf0e10cSrcweir         {
38cdf0e10cSrcweir             return (c[0] << 16) | (c[1] << 8) | c[2];
39cdf0e10cSrcweir         }
40cdf0e10cSrcweir     };
41cdf0e10cSrcweir 
42*06db55caSmseidel     // type-safe conversion from packed int32 to RgbValue
43cdf0e10cSrcweir     template< class RgbVal > struct RgbValueFromUInt32
44cdf0e10cSrcweir     {
operator ()basebmp::RgbValueFromUInt3245cdf0e10cSrcweir         RgbVal operator()( sal_uInt32 c ) const
46cdf0e10cSrcweir         {
47cdf0e10cSrcweir             return RgbVal((c >> 16) & 0xFF,
48cdf0e10cSrcweir                           (c >> 8) & 0xFF,
49cdf0e10cSrcweir                           c & 0xFF);
50cdf0e10cSrcweir         }
51cdf0e10cSrcweir     };
52cdf0e10cSrcweir 
53*06db55caSmseidel     // Get converter from given data type to sal_uInt32
54cdf0e10cSrcweir     template< typename DataType > struct uInt32Converter
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir         typedef std::identity<DataType> to;
57cdf0e10cSrcweir         typedef std::identity<DataType> from;
58cdf0e10cSrcweir     };
59cdf0e10cSrcweir     template< unsigned int RedIndex,
60cdf0e10cSrcweir               unsigned int GreenIndex,
61cdf0e10cSrcweir               unsigned int BlueIndex > struct uInt32Converter<
62cdf0e10cSrcweir                   vigra::RGBValue< sal_uInt8,
63cdf0e10cSrcweir                                    RedIndex,
64cdf0e10cSrcweir                                    GreenIndex,
65cdf0e10cSrcweir                                    BlueIndex > >
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         typedef UInt32FromRgbValue<
68cdf0e10cSrcweir             vigra::RGBValue< sal_uInt8,
69cdf0e10cSrcweir                              RedIndex,
70cdf0e10cSrcweir                              GreenIndex,
71cdf0e10cSrcweir                              BlueIndex > >
72cdf0e10cSrcweir             to;
73cdf0e10cSrcweir         typedef RgbValueFromUInt32<
74cdf0e10cSrcweir             vigra::RGBValue< sal_uInt8,
75cdf0e10cSrcweir                              RedIndex,
76cdf0e10cSrcweir                              GreenIndex,
77cdf0e10cSrcweir                              BlueIndex > >
78cdf0e10cSrcweir             from;
79cdf0e10cSrcweir     };
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir #endif /* INCLUDED_BASEBMP_INTCONVERSION_HXX */
83*06db55caSmseidel 
84*06db55caSmseidel /* vim: set noet sw=4 ts=4: */
85