1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX
29 #define INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX
30 
31 #include <basebmp/color.hxx>
32 #include <basebmp/accessor.hxx>
33 #include <basebmp/pixeliterator.hxx>
34 #include <basebmp/pixelformatadapters.hxx>
35 
36 #include <vigra/rgbvalue.hxx>
37 
38 #include <functional>
39 
40 namespace basebmp
41 {
42 
43 template< typename PixelType, typename ColorType > struct RGBValueGetter :
44         public std::unary_function<PixelType, ColorType>
45 {
46     ColorType operator()( PixelType const& c ) const
47     {
48         return ColorType(c.red(),c.green(),c.blue());
49     }
50 };
51 
52 template< typename PixelType, typename ColorType > struct RGBValueSetter :
53     public std::unary_function<ColorType, PixelType>
54 {
55     PixelType operator()( ColorType const& c ) const
56     {
57         PixelType res;
58         res.setRed(c.getRed());
59         res.setGreen(c.getGreen());
60         res.setBlue(c.getBlue());
61         return res;
62     }
63 };
64 
65 //-----------------------------------------------------------------------------
66 
67 template< typename PixelType > struct PixelFormatTraitsTemplate_RGBValue
68 {
69     typedef PixelType                     pixel_type;
70 
71     typedef RGBValueGetter<pixel_type,
72                            Color>         getter_type;
73     typedef RGBValueSetter<pixel_type,
74                            Color>         setter_type;
75 
76     typedef PixelIterator<pixel_type>     iterator_type;
77     typedef StandardAccessor<pixel_type>  raw_accessor_type;
78     typedef AccessorSelector<
79         getter_type, setter_type>         accessor_selector;
80 };
81 
82 //-----------------------------------------------------------------------------
83 
84 // 24bpp RGB
85 typedef PixelFormatTraitsTemplate_RGBValue<
86     vigra::RGBValue<sal_uInt8> >            PixelFormatTraits_RGB24;
87 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB24::getter_type,
88                                   PixelFormatTraits_RGB24::setter_type);
89 
90 // 24bpp BGR
91 typedef PixelFormatTraitsTemplate_RGBValue<
92     vigra::RGBValue<sal_uInt8,2,1,0> >      PixelFormatTraits_BGR24;
93 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGR24::getter_type,
94                                   PixelFormatTraits_BGR24::setter_type);
95 
96 } // namespace basebmp
97 
98 #endif /* INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX */
99