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_SOURCE_INTCONVERSION_HXX
21 #define INCLUDED_BASEBMP_SOURCE_INTCONVERSION_HXX
23 #include <vigra/rgbvalue.hxx>
28 // metafunctions to retrieve correct POD from/to basebmp::Color
30 /// type-safe conversion from RgbValue to packed int32
31 template< class RgbVal
> struct UInt32FromRgbValue
33 sal_uInt32
operator()( RgbVal
const& c
) const
35 return (c
[0] << 16) | (c
[1] << 8) | c
[2];
39 /// type-safe conversion from packed int32 to RgbValue
40 template< class RgbVal
> struct RgbValueFromUInt32
42 RgbVal
operator()( sal_uInt32 c
) const
44 return RgbVal((c
>> 16) & 0xFF,
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
>
53 T
& operator()(T
& x
) const { return x
; }
54 const T
& operator()(const T
& x
) const { return x
; }
57 /// Get converter from given data type to sal_uInt32
58 template< typename DataType
> struct uInt32Converter
60 typedef SGI_identity
<DataType
> to
;
61 typedef SGI_identity
<DataType
> from
;
63 template< unsigned int RedIndex
,
64 unsigned int GreenIndex
,
65 unsigned int BlueIndex
> struct uInt32Converter
<
66 vigra::RGBValue
< sal_uInt8
,
71 typedef UInt32FromRgbValue
<
72 vigra::RGBValue
< sal_uInt8
,
77 typedef RgbValueFromUInt32
<
78 vigra::RGBValue
< sal_uInt8
,
86 #endif // INCLUDED_BASEBMP_SOURCE_INTCONVERSION_HXX
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */