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_GREYLEVELFORMATS_HXX 25cdf0e10cSrcweir #define INCLUDED_BASEBMP_GREYLEVELFORMATS_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/metafunctions.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <vigra/numerictraits.hxx> 36cdf0e10cSrcweir #include <vigra/metaprogramming.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <functional> 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace basebmp 41cdf0e10cSrcweir { 42cdf0e10cSrcweir 43cdf0e10cSrcweir template< typename PixelType, 44cdf0e10cSrcweir typename ColorType, 45cdf0e10cSrcweir int UsedRange > struct GreylevelGetter : 46cdf0e10cSrcweir public std::unary_function<PixelType, ColorType> 47cdf0e10cSrcweir { operator ()basebmp::GreylevelGetter48cdf0e10cSrcweir ColorType operator()( PixelType const& c ) const 49cdf0e10cSrcweir { 50cdf0e10cSrcweir return ColorTraits<ColorType>::fromGreyscale( 51cdf0e10cSrcweir vigra::NumericTraits<PixelType>::toPromote(c) * 52cdf0e10cSrcweir vigra::NumericTraits<PixelType>::maxConst / UsedRange ); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir }; 55cdf0e10cSrcweir 56cdf0e10cSrcweir template< typename PixelType, 57cdf0e10cSrcweir typename ColorType, 58cdf0e10cSrcweir int UsedRange > struct GreylevelSetter : 59cdf0e10cSrcweir public std::unary_function<ColorType, PixelType> 60cdf0e10cSrcweir { operator ()basebmp::GreylevelSetter61cdf0e10cSrcweir PixelType operator()( ColorType const& c ) const 62cdf0e10cSrcweir { 63cdf0e10cSrcweir return vigra::NumericTraits<PixelType>::toPromote( 64cdf0e10cSrcweir ColorTraits<ColorType>::toGreyscale(c)) * 65cdf0e10cSrcweir UsedRange / 66cdf0e10cSrcweir vigra::NumericTraits<PixelType>::maxConst; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir 70cdf0e10cSrcweir //----------------------------------------------------------------------------- 71cdf0e10cSrcweir 72cdf0e10cSrcweir template< class Iterator, 73cdf0e10cSrcweir class Accessor, 74cdf0e10cSrcweir int UsedRange > struct PixelFormatTraitsTemplate_Greylevel 75cdf0e10cSrcweir { 76cdf0e10cSrcweir typedef typename Iterator::value_type pixel_type; 77cdf0e10cSrcweir 78cdf0e10cSrcweir typedef GreylevelGetter<pixel_type, 79cdf0e10cSrcweir Color, 80cdf0e10cSrcweir UsedRange> getter_type; 81cdf0e10cSrcweir typedef GreylevelSetter<pixel_type, 82cdf0e10cSrcweir Color, 83cdf0e10cSrcweir UsedRange> setter_type; 84cdf0e10cSrcweir 85cdf0e10cSrcweir typedef Iterator iterator_type; 86cdf0e10cSrcweir typedef Accessor raw_accessor_type; 87cdf0e10cSrcweir typedef AccessorSelector< 88cdf0e10cSrcweir getter_type, 89cdf0e10cSrcweir setter_type > accessor_selector; 90cdf0e10cSrcweir }; 91cdf0e10cSrcweir 92cdf0e10cSrcweir template< int BitsPerPixel, 93cdf0e10cSrcweir bool MsbFirst > struct PixelFormatTraitsTemplate_PackedGreylevel : 94cdf0e10cSrcweir public PixelFormatTraitsTemplate_Greylevel< 95cdf0e10cSrcweir PackedPixelIterator< sal_uInt8, 96cdf0e10cSrcweir BitsPerPixel, 97cdf0e10cSrcweir true >, 98cdf0e10cSrcweir NonStandardAccessor< sal_uInt8 >, 99cdf0e10cSrcweir (1UL << BitsPerPixel)-1 > 100cdf0e10cSrcweir {}; 101cdf0e10cSrcweir 102cdf0e10cSrcweir //----------------------------------------------------------------------------- 103cdf0e10cSrcweir 104cdf0e10cSrcweir // 1bpp MSB 105cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedGreylevel<1, true> PixelFormatTraits_GREY1_MSB; 106cdf0e10cSrcweir 107cdf0e10cSrcweir // 1bpp LSB 108cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedGreylevel<1, false> PixelFormatTraits_GREY1_LSB; 109cdf0e10cSrcweir BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY1_MSB::getter_type, 110cdf0e10cSrcweir PixelFormatTraits_GREY1_MSB::setter_type); 111cdf0e10cSrcweir 112cdf0e10cSrcweir 113cdf0e10cSrcweir // 4bpp MSB 114cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedGreylevel<4, true> PixelFormatTraits_GREY4_MSB; 115cdf0e10cSrcweir 116cdf0e10cSrcweir // 4bpp LSB 117cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_PackedGreylevel<4, false> PixelFormatTraits_GREY4_LSB; 118cdf0e10cSrcweir BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY4_MSB::getter_type, 119cdf0e10cSrcweir PixelFormatTraits_GREY4_MSB::setter_type); 120cdf0e10cSrcweir 121cdf0e10cSrcweir // 8bpp 122cdf0e10cSrcweir typedef PixelFormatTraitsTemplate_Greylevel< 123cdf0e10cSrcweir PixelIterator< sal_uInt8 >, 124cdf0e10cSrcweir StandardAccessor< sal_uInt8 >, 125cdf0e10cSrcweir 255 > PixelFormatTraits_GREY8; 126cdf0e10cSrcweir BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY8::getter_type, 127cdf0e10cSrcweir PixelFormatTraits_GREY8::setter_type); 128cdf0e10cSrcweir 129cdf0e10cSrcweir } // namespace basebmp 130cdf0e10cSrcweir 131cdf0e10cSrcweir #endif /* INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX */ 132