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