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