1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX
25 #define INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX
26 
27 #include <basebmp/color.hxx>
28 #include <basebmp/accessor.hxx>
29 #include <basebmp/pixeliterator.hxx>
30 #include <basebmp/pixelformatadapters.hxx>
31 
32 #include <vigra/rgbvalue.hxx>
33 
34 #include <functional>
35 
36 namespace basebmp
37 {
38 
39 template< typename PixelType, typename ColorType > struct RGBValueGetter :
40         public std::unary_function<PixelType, ColorType>
41 {
operator ()basebmp::RGBValueGetter42     ColorType operator()( PixelType const& c ) const
43     {
44         return ColorType(c.red(),c.green(),c.blue());
45     }
46 };
47 
48 template< typename PixelType, typename ColorType > struct RGBValueSetter :
49     public std::unary_function<ColorType, PixelType>
50 {
operator ()basebmp::RGBValueSetter51     PixelType operator()( ColorType const& c ) const
52     {
53         PixelType res;
54         res.setRed(c.getRed());
55         res.setGreen(c.getGreen());
56         res.setBlue(c.getBlue());
57         return res;
58     }
59 };
60 
61 //-----------------------------------------------------------------------------
62 
63 template< typename PixelType > struct PixelFormatTraitsTemplate_RGBValue
64 {
65     typedef PixelType                     pixel_type;
66 
67     typedef RGBValueGetter<pixel_type,
68                            Color>         getter_type;
69     typedef RGBValueSetter<pixel_type,
70                            Color>         setter_type;
71 
72     typedef PixelIterator<pixel_type>     iterator_type;
73     typedef StandardAccessor<pixel_type>  raw_accessor_type;
74     typedef AccessorSelector<
75         getter_type, setter_type>         accessor_selector;
76 };
77 
78 //-----------------------------------------------------------------------------
79 
80 // 24bpp RGB
81 typedef PixelFormatTraitsTemplate_RGBValue<
82     vigra::RGBValue<sal_uInt8> >            PixelFormatTraits_RGB24;
83 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB24::getter_type,
84                                   PixelFormatTraits_RGB24::setter_type);
85 
86 // 24bpp BGR
87 typedef PixelFormatTraitsTemplate_RGBValue<
88     vigra::RGBValue<sal_uInt8,2,1,0> >      PixelFormatTraits_BGR24;
89 BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGR24::getter_type,
90                                   PixelFormatTraits_BGR24::setter_type);
91 
92 } // namespace basebmp
93 
94 #endif /* INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX */
95