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_ACCESSORTRAITS_HXX 25cdf0e10cSrcweir #define INCLUDED_BASEBMP_ACCESSORTRAITS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <basebmp/accessorfunctors.hxx> 28cdf0e10cSrcweir #include <basebmp/accessoradapters.hxx> 29cdf0e10cSrcweir #include <basebmp/metafunctions.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <functional> 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace basebmp 34cdf0e10cSrcweir { 35cdf0e10cSrcweir 36cdf0e10cSrcweir struct FastMask; 37cdf0e10cSrcweir struct NoFastMask; 38cdf0e10cSrcweir 39cdf0e10cSrcweir /// Metafunction to select output mask functor from iterator and mask value type 40cdf0e10cSrcweir template< typename T, typename M, bool polarity, typename DUMMY > struct outputMaskFunctorSelector : public 41cdf0e10cSrcweir ifBothScalarIntegral< T, M, 42cdf0e10cSrcweir IntegerOutputMaskFunctor< T, M, polarity >, 43cdf0e10cSrcweir GenericOutputMaskFunctor< T, M, polarity > > 44cdf0e10cSrcweir { 45cdf0e10cSrcweir }; 46cdf0e10cSrcweir template< typename T, typename M, bool polarity > struct outputMaskFunctorSelector< T, M, polarity, FastMask > : public 47cdf0e10cSrcweir ifBothScalarIntegral< T, M, 48cdf0e10cSrcweir FastIntegerOutputMaskFunctor< T, M, polarity >, 49cdf0e10cSrcweir GenericOutputMaskFunctor< T, M, polarity > > 50cdf0e10cSrcweir { 51cdf0e10cSrcweir }; 52cdf0e10cSrcweir 53cdf0e10cSrcweir /** Metafunction providing a point of configuration for iterators 54cdf0e10cSrcweir capable of employing the fast output mask functor. 55cdf0e10cSrcweir 56cdf0e10cSrcweir Specialize this metafunction for your case, and pass FastMask to 57cdf0e10cSrcweir the outputMaskFunctorSelector. 58cdf0e10cSrcweir */ 59cdf0e10cSrcweir template< class Accessor, 60cdf0e10cSrcweir class MaskAccessor, 61cdf0e10cSrcweir class Iterator, 62cdf0e10cSrcweir class MaskIterator, 63cdf0e10cSrcweir bool polarity > struct maskedAccessorSelector 64cdf0e10cSrcweir { 65cdf0e10cSrcweir typedef TernarySetterFunctionAccessorAdapter< 66cdf0e10cSrcweir Accessor, 67cdf0e10cSrcweir MaskAccessor, 68cdf0e10cSrcweir typename outputMaskFunctorSelector< 69cdf0e10cSrcweir typename Accessor::value_type, 70cdf0e10cSrcweir typename MaskAccessor::value_type, 71cdf0e10cSrcweir polarity, 72cdf0e10cSrcweir NoFastMask > ::type > 73cdf0e10cSrcweir type; 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir //----------------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir /** Traits template for Accessor 79cdf0e10cSrcweir 80cdf0e10cSrcweir Provides wrapped types for color lookup, raw pixel access, xor and 81cdf0e10cSrcweir mask accessors. 82cdf0e10cSrcweir */ 83cdf0e10cSrcweir template< class Accessor > struct AccessorTraits 84cdf0e10cSrcweir { 85cdf0e10cSrcweir /// value type of described accessor 86cdf0e10cSrcweir typedef typename Accessor::value_type value_type; 87cdf0e10cSrcweir 88cdf0e10cSrcweir /// Retrieve stand-alone color lookup function for given Accessor type 89cdf0e10cSrcweir typedef std::project2nd< Accessor, value_type > color_lookup; 90cdf0e10cSrcweir 91cdf0e10cSrcweir /// Retrieve raw pixel data accessor for given Accessor type 92cdf0e10cSrcweir typedef Accessor raw_accessor; 93cdf0e10cSrcweir 94cdf0e10cSrcweir /// Retrieve wrapped accessor for XOR setter access 95cdf0e10cSrcweir typedef BinarySetterFunctionAccessorAdapter< 96cdf0e10cSrcweir Accessor, 97cdf0e10cSrcweir XorFunctor< value_type > > xor_accessor; 98cdf0e10cSrcweir 99cdf0e10cSrcweir /** Retrieve masked accessor for given types 100cdf0e10cSrcweir 101cdf0e10cSrcweir A masked accessor works like a filter, where the mask gates 102cdf0e10cSrcweir the accessor's setter methods (if the mask contains a 0 at a 103cdf0e10cSrcweir given iterator position, the original value is 104cdf0e10cSrcweir preserved. Otherwise, the new value gets set). 105cdf0e10cSrcweir 106cdf0e10cSrcweir @attention be careful when retrieving a masked accessor for a 107cdf0e10cSrcweir set of types, and using it for a different one - there are 108cdf0e10cSrcweir partial specializations that take an optimized functor for 109cdf0e10cSrcweir certain mask accessors. 110cdf0e10cSrcweir */ 111cdf0e10cSrcweir template< class MaskAccessor, 112cdf0e10cSrcweir class Iterator, 113cdf0e10cSrcweir class MaskIterator, 114cdf0e10cSrcweir bool polarity > struct masked_accessor : 115cdf0e10cSrcweir public maskedAccessorSelector< Accessor, 116cdf0e10cSrcweir MaskAccessor, 117cdf0e10cSrcweir Iterator, 118cdf0e10cSrcweir MaskIterator, 119cdf0e10cSrcweir polarity > 120cdf0e10cSrcweir {}; 121cdf0e10cSrcweir 122cdf0e10cSrcweir }; 123cdf0e10cSrcweir 124cdf0e10cSrcweir } // namespace basebmp 125cdf0e10cSrcweir 126cdf0e10cSrcweir #endif /* INCLUDED_BASEBMP_ACCESSORTRAITS_HXX */ 127