1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASEBMP_INTCONVERSION_HXX
21 #define INCLUDED_BASEBMP_INTCONVERSION_HXX
23 #include <vigra/rgbvalue.hxx>
28 // metafunctions to retrieve correct POD from/to basebmp::Color
29 //------------------------------------------------------------------------
31 /// type-safe conversion from RgbValue to packed int32
32 template< class RgbVal
> struct UInt32FromRgbValue
34 sal_uInt32
operator()( RgbVal
const& c
) const
36 return (c
[0] << 16) | (c
[1] << 8) | c
[2];
40 /// type-safe conversion from packed int32 to RgbValue
41 template< class RgbVal
> struct RgbValueFromUInt32
43 RgbVal
operator()( sal_uInt32 c
) const
45 return RgbVal((c
>> 16) & 0xFF,
51 //Current c++0x draft (apparently) has std::identity, but not operator()
52 template<typename T
> struct SGI_identity
: public std::unary_function
<T
,T
>
54 T
& operator()(T
& x
) const { return x
; }
55 const T
& operator()(const T
& x
) const { return x
; }
58 /// Get converter from given data type to sal_uInt32
59 template< typename DataType
> struct uInt32Converter
61 typedef SGI_identity
<DataType
> to
;
62 typedef SGI_identity
<DataType
> from
;
64 template< unsigned int RedIndex
,
65 unsigned int GreenIndex
,
66 unsigned int BlueIndex
> struct uInt32Converter
<
67 vigra::RGBValue
< sal_uInt8
,
72 typedef UInt32FromRgbValue
<
73 vigra::RGBValue
< sal_uInt8
,
78 typedef RgbValueFromUInt32
<
79 vigra::RGBValue
< sal_uInt8
,
87 #endif /* INCLUDED_BASEBMP_INTCONVERSION_HXX */
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */