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_PIXELFORMATADAPTERS_HXX 25 #define INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX 26 27 #include <basebmp/accessortraits.hxx> 28 #include <basebmp/accessoradapters.hxx> 29 30 #include <vigra/metaprogramming.hxx> 31 32 namespace basebmp 33 { 34 35 // convenience functionality, providing everything necessary for a new 36 // pixel format. simply plug in two conversion functors from/to a 37 // common color format. 38 39 /** Accessor selection metafunction, used to wrap a given accessor 40 with one converting between the pixel and color types 41 42 Use the nested template's typedef type, to retrieve an 43 AccessorAdapter which operates on a pixel value accessor, and 44 provides color values to the outside. 45 46 Nested like this, to avoid template template parameters at other 47 places: an instantiated version of AccessorSelector can be passed 48 to other templates, which in turn can invoke the nested meta 49 function. 50 */ 51 template< typename Getter, 52 typename Setter > struct AccessorSelector 53 { 54 template< typename Accessor > struct wrap_accessor 55 { 56 typedef UnaryFunctionAccessorAdapter< Accessor, 57 Getter, 58 Setter > type; 59 }; 60 }; 61 62 //----------------------------------------------------------------------------- 63 64 /** Convert color value to pixel data type 65 */ 66 template< class Accessor, typename DataType > struct ColorConvert 67 { operator ()basebmp::ColorConvert68 DataType operator()( const Accessor& acc, 69 typename Accessor::value_type v ) const 70 { 71 return acc.setter(v); 72 } 73 }; 74 75 //----------------------------------------------------------------------------- 76 77 /** Macro generates partial specialization for color-conversion 78 UnaryFunctionAccessorAdapter, and the given getter/setter functors 79 */ 80 #define BASEBMP_SPECIALIZE_ACCESSORTRAITS(Getter,Setter) \ 81 template< class Accessor > struct AccessorTraits< \ 82 UnaryFunctionAccessorAdapter< Accessor, \ 83 Getter, \ 84 Setter > > \ 85 { \ 86 typedef typename Accessor::value_type data_type; \ 87 typedef UnaryFunctionAccessorAdapter< \ 88 Accessor, \ 89 Getter, \ 90 Setter > accessor_type; \ 91 typedef typename accessor_type::value_type value_type; \ 92 typedef ColorConvert< accessor_type, \ 93 data_type > color_lookup; \ 94 typedef Accessor raw_accessor; \ 95 typedef vigra::VigraFalseType xor_accessor; \ 96 template< class MaskAccessor, \ 97 class Iterator, \ 98 class MaskIterator > struct masked_accessor\ 99 { typedef vigra::VigraFalseType type; }; \ 100 } 101 102 } // namespace basebmp 103 104 #endif /* INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX */ 105