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_INTCONVERSION_HXX
21 : #define INCLUDED_BASEBMP_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 :
31 : /// type-safe conversion from RgbValue to packed int32
32 : template< class RgbVal > struct UInt32FromRgbValue
33 : {
34 0 : sal_uInt32 operator()( RgbVal const& c ) const
35 : {
36 0 : return (c[0] << 16) | (c[1] << 8) | c[2];
37 : }
38 : };
39 :
40 : /// type-safe conversion from packed int32 to RgbValue
41 : template< class RgbVal > struct RgbValueFromUInt32
42 : {
43 : RgbVal operator()( sal_uInt32 c ) const
44 : {
45 : return RgbVal((c >> 16) & 0xFF,
46 : (c >> 8) & 0xFF,
47 : c & 0xFF);
48 : }
49 : };
50 :
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>
53 : {
54 : T& operator()(T& x) const { return x; }
55 4 : const T& operator()(const T& x) const { return x; }
56 : };
57 :
58 : /// Get converter from given data type to sal_uInt32
59 : template< typename DataType > struct uInt32Converter
60 : {
61 : typedef SGI_identity<DataType> to;
62 : typedef SGI_identity<DataType> from;
63 : };
64 : template< unsigned int RedIndex,
65 : unsigned int GreenIndex,
66 : unsigned int BlueIndex > struct uInt32Converter<
67 : vigra::RGBValue< sal_uInt8,
68 : RedIndex,
69 : GreenIndex,
70 : BlueIndex > >
71 : {
72 : typedef UInt32FromRgbValue<
73 : vigra::RGBValue< sal_uInt8,
74 : RedIndex,
75 : GreenIndex,
76 : BlueIndex > >
77 : to;
78 : typedef RgbValueFromUInt32<
79 : vigra::RGBValue< sal_uInt8,
80 : RedIndex,
81 : GreenIndex,
82 : BlueIndex > >
83 : from;
84 : };
85 : }
86 :
87 : #endif /* INCLUDED_BASEBMP_INTCONVERSION_HXX */
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|