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_PACKEDPIXELFORMATS_HXX
25cdf0e10cSrcweir #define INCLUDED_BASEBMP_PACKEDPIXELFORMATS_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <basebmp/color.hxx>
28cdf0e10cSrcweir #include <basebmp/colortraits.hxx>
29cdf0e10cSrcweir #include <basebmp/accessor.hxx>
30cdf0e10cSrcweir #include <basebmp/pixeliterator.hxx>
31cdf0e10cSrcweir #include <basebmp/packedpixeliterator.hxx>
32cdf0e10cSrcweir #include <basebmp/pixelformatadapters.hxx>
33cdf0e10cSrcweir #include <basebmp/paletteimageaccessor.hxx>
34cdf0e10cSrcweir #include <basebmp/metafunctions.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <vigra/numerictraits.hxx>
37cdf0e10cSrcweir #include <vigra/metaprogramming.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <functional>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace basebmp
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //-----------------------------------------------------------------------------
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /** Lookup index value for given color value in a PaletteImageAccessor
47cdf0e10cSrcweir  */
48cdf0e10cSrcweir template< class Accessor > struct ColorLookup
49cdf0e10cSrcweir {
operator ()basebmp::ColorLookup50cdf0e10cSrcweir     typename Accessor::data_type operator()( const Accessor&               acc,
51cdf0e10cSrcweir                                              typename Accessor::value_type v ) const
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         return acc.lookup(v);
54cdf0e10cSrcweir     }
55cdf0e10cSrcweir };
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //-----------------------------------------------------------------------------
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // partial specialization of AccessorTraits for PaletteAccessor
60cdf0e10cSrcweir template< class Accessor, typename ColorType > struct AccessorTraits<
61cdf0e10cSrcweir     PaletteImageAccessor< Accessor, ColorType > >
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     /// value type of described accessor
64cdf0e10cSrcweir     typedef typename PaletteImageAccessor< Accessor, ColorType >::value_type  value_type;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /// Retrieve stand-alone color lookup function for given Accessor type
67cdf0e10cSrcweir     typedef ColorLookup< PaletteImageAccessor< Accessor, ColorType > >        color_lookup;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /// Retrieve raw pixel data accessor for given Accessor type
70cdf0e10cSrcweir     typedef Accessor                                                          raw_accessor;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /** accessor for XOR setter access is disabled, since the results
73cdf0e10cSrcweir      *  are usually completely unintended - you'll usually want to
74cdf0e10cSrcweir      *  wrap an xor_accessor with a PaletteAccessor, not the other way
75cdf0e10cSrcweir      *  around.
76cdf0e10cSrcweir      */
77cdf0e10cSrcweir     typedef vigra::VigraFalseType                                             xor_accessor;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /** accessor for masked setter access is disabled, since the
80cdf0e10cSrcweir      *  results are usually completely unintended - you'll usually
81cdf0e10cSrcweir      *  want to wrap a masked_accessor with a PaletteAccessor, not the
82cdf0e10cSrcweir      *  other way around.
83cdf0e10cSrcweir      */
84cdf0e10cSrcweir     template< class MaskAccessor,
85cdf0e10cSrcweir               class Iterator,
86cdf0e10cSrcweir               class MaskIterator > struct                                     masked_accessor
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         typedef vigra::VigraFalseType type;
89cdf0e10cSrcweir     };
90cdf0e10cSrcweir };
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //-----------------------------------------------------------------------------
93cdf0e10cSrcweir 
94cdf0e10cSrcweir template< typename ColorType > struct PaletteAccessorSelector
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     template< class Accessor > struct wrap_accessor
97cdf0e10cSrcweir     {
98cdf0e10cSrcweir         typedef PaletteImageAccessor< Accessor, ColorType > type;
99cdf0e10cSrcweir     };
100cdf0e10cSrcweir };
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //-----------------------------------------------------------------------------
103cdf0e10cSrcweir 
104cdf0e10cSrcweir template< class Iterator,
105cdf0e10cSrcweir           class Accessor > struct PixelFormatTraitsTemplate_Palette
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     typedef typename Iterator::value_type       pixel_type;
108cdf0e10cSrcweir     typedef Iterator                            iterator_type;
109cdf0e10cSrcweir     typedef Accessor                            raw_accessor_type;
110cdf0e10cSrcweir     typedef PaletteAccessorSelector<Color>      accessor_selector;
111cdf0e10cSrcweir };
112cdf0e10cSrcweir 
113cdf0e10cSrcweir template< int BitsPerPixel,
114cdf0e10cSrcweir           bool MsbFirst > struct PixelFormatTraitsTemplate_PackedPalette :
115cdf0e10cSrcweir     public PixelFormatTraitsTemplate_Palette<
116cdf0e10cSrcweir                PackedPixelIterator< sal_uInt8,
117cdf0e10cSrcweir                                     BitsPerPixel,
118cdf0e10cSrcweir                                     MsbFirst >,
119cdf0e10cSrcweir                NonStandardAccessor< sal_uInt8 > >
120cdf0e10cSrcweir {};
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //-----------------------------------------------------------------------------
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // 1bpp MSB
125cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedPalette<1, true>  PixelFormatTraits_PAL1_MSB;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir // 1bpp LSB
128cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedPalette<1, false> PixelFormatTraits_PAL1_LSB;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // 4bpp MSB
131cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedPalette<4, true>  PixelFormatTraits_PAL4_MSB;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir // 4bpp LSB
134cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedPalette<4, false> PixelFormatTraits_PAL4_LSB;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // 8bpp
137cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_Palette<
138cdf0e10cSrcweir     PixelIterator< sal_uInt8 >,
139cdf0e10cSrcweir     StandardAccessor< sal_uInt8 > >                       PixelFormatTraits_PAL8;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir } // namespace basebmp
142cdf0e10cSrcweir 
143cdf0e10cSrcweir #endif /* INCLUDED_BASEBMP_PACKEDPIXELFORMATS_HXX */
144