1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: intconversion.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_BASEBMP_INTCONVERSION_HXX
32 #define INCLUDED_BASEBMP_INTCONVERSION_HXX
34 #include <vigra/rgbvalue.hxx>
39 // metafunctions to retrieve correct POD from/to basebmp::Color
40 //------------------------------------------------------------------------
42 /// type-safe conversion from RgbValue to packed int32
43 template< class RgbVal
> struct UInt32FromRgbValue
45 sal_uInt32
operator()( RgbVal
const& c
) const
47 return (c
[0] << 16) | (c
[1] << 8) | c
[2];
51 /// type-safe conversion from packed int32 to RgbValue
52 template< class RgbVal
> struct RgbValueFromUInt32
54 RgbVal
operator()( sal_uInt32 c
) const
56 return RgbVal((c
>> 16) & 0xFF,
62 /// Get converter from given data type to sal_uInt32
63 template< typename DataType
> struct uInt32Converter
65 typedef std::identity
<DataType
> to
;
66 typedef std::identity
<DataType
> from
;
68 template< unsigned int RedIndex
,
69 unsigned int GreenIndex
,
70 unsigned int BlueIndex
> struct uInt32Converter
<
71 vigra::RGBValue
< sal_uInt8
,
76 typedef UInt32FromRgbValue
<
77 vigra::RGBValue
< sal_uInt8
,
82 typedef RgbValueFromUInt32
<
83 vigra::RGBValue
< sal_uInt8
,
91 #endif /* INCLUDED_BASEBMP_INTCONVERSION_HXX */