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