Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX
21 : #define INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX
22 :
23 : #include <basebmp/accessortraits.hxx>
24 : #include <basebmp/accessoradapters.hxx>
25 :
26 : #include <vigra/metaprogramming.hxx>
27 :
28 : namespace basebmp
29 : {
30 :
31 : // convenience functionality, providing everything necessary for a new
32 : // pixel format. simply plug in two conversion functors from/to a
33 : // common color format.
34 :
35 : /** Accessor selection metafunction, used to wrap a given accessor
36 : with one converting between the pixel and color types
37 :
38 : Use the nested template's typedef type, to retrieve an
39 : AccessorAdapter which operates on a pixel value accessor, and
40 : provides color values to the outside.
41 :
42 : Nested like this, to avoid template template parameters at other
43 : places: an instantiated version of AccessorSelector can be passed
44 : to other templates, which in turn can invoke the nested meta
45 : function.
46 : */
47 : template< typename Getter,
48 : typename Setter > struct AccessorSelector
49 : {
50 : template< typename Accessor > struct wrap_accessor
51 : {
52 : typedef UnaryFunctionAccessorAdapter< Accessor,
53 : Getter,
54 : Setter > type;
55 : };
56 : };
57 :
58 :
59 :
60 : /** Convert color value to pixel data type
61 : */
62 : template< class Accessor, typename DataType > struct ColorConvert
63 : {
64 5587955 : DataType operator()( const Accessor& acc,
65 : typename Accessor::value_type v ) const
66 : {
67 5587955 : return acc.setter(v);
68 : }
69 : };
70 :
71 :
72 :
73 : /** Macro generates partial specialization for color-conversion
74 : UnaryFunctionAccessorAdapter, and the given getter/setter functors
75 : */
76 : #define BASEBMP_SPECIALIZE_ACCESSORTRAITS(Getter,Setter) \
77 : template< class Accessor > struct AccessorTraits< \
78 : UnaryFunctionAccessorAdapter< Accessor, \
79 : Getter, \
80 : Setter > > \
81 : { \
82 : typedef typename Accessor::value_type data_type; \
83 : typedef UnaryFunctionAccessorAdapter< \
84 : Accessor, \
85 : Getter, \
86 : Setter > accessor_type; \
87 : typedef typename accessor_type::value_type value_type; \
88 : typedef ColorConvert< accessor_type, \
89 : data_type > color_lookup; \
90 : typedef Accessor raw_accessor; \
91 : typedef vigra::VigraFalseType xor_accessor; \
92 : template< class MaskAccessor, \
93 : class Iterator, \
94 : class MaskIterator > struct masked_accessor\
95 : { typedef vigra::VigraFalseType type; }; \
96 : }
97 :
98 : } // namespace basebmp
99 :
100 : #endif /* INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX */
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|