1 <!-- Copyright 2008 Lubomir Bourdev and Hailin Jin
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
9 Copyright 2005-2007 Adobe Systems Incorporated
10 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
11 or a copy at http://stlab.adobe.com/licenses.html)
13 Some files are held under additional license.
14 Please see "http://stlab.adobe.com/licenses.html" for more information.
17 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
18 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
19 <html xmlns=
"http://www.w3.org/1999/xhtml" lang=
"en" xml:
lang=
"en">
22 <TITLE>Generic Image Library: channel_algorithm.hpp Source File
</TITLE>
23 <META HTTP-EQUIV=
"content-type" CONTENT=
"text/html;charset=ISO-8859-1"/>
24 <LINK TYPE=
"text/css" REL=
"stylesheet" HREF=
"adobe_source.css"/>
27 <table border=
"0" cellspacing=
"0" cellpadding=
"0" style='width:
100%; margin:
0; padding:
0'
><tr>
28 <td width=
"100%" valign=
"top" style='padding-left:
10px; padding-right:
10px; padding-bottom:
10px'
>
29 <div class=
"qindex"><a class=
"qindex" href=
"index.html">Modules
</a>
30 |
<a class=
"qindex" href=
"classes.html">Alphabetical List
</a>
31 |
<a class=
"qindex" href=
"annotated.html">Class List
</a>
32 |
<a class=
"qindex" href=
"dirs.html">Directories
</a>
33 |
<a class=
"qindex" href=
"files.html">File List
</a>
34 |
<a class=
"qindex" href=
"../index.html">GIL Home Page
</a>
37 <!-- Generated by Doxygen 1.5.6 -->
38 <div class=
"navpath"><a class=
"el" href=
"g_i_l_0076.html">boost
</a> »
<a class=
"el" href=
"g_i_l_0079.html">gil
</a>
40 <div class=
"contents">
41 <h1>channel_algorithm.hpp
</h1><a href=
"g_i_l_0016.html">Go to the documentation of this file.
</a><div class=
"fragment"><pre class=
"fragment"><a name=
"l00001"></a>00001 <span class=
"comment">/*
</span>
42 <a name=
"l00002"></a>00002 <span class=
"comment"> Copyright
2005-
2007 Adobe Systems Incorporated
</span>
43 <a name=
"l00003"></a>00003 <span class=
"comment"> </span>
44 <a name=
"l00004"></a>00004 <span class=
"comment"> Use, modification and distribution are subject to the Boost Software License,
</span>
45 <a name=
"l00005"></a>00005 <span class=
"comment"> Version
1.0. (See accompanying file LICENSE_1_0.txt or copy at
</span>
46 <a name=
"l00006"></a>00006 <span class=
"comment"> http://www.boost.org/LICENSE_1_0.txt).
</span>
47 <a name=
"l00007"></a>00007 <span class=
"comment"></span>
48 <a name=
"l00008"></a>00008 <span class=
"comment"> See http://opensource.adobe.com/gil for most recent version including documentation.
</span>
49 <a name=
"l00009"></a>00009 <span class=
"comment">*/
</span>
50 <a name=
"l00010"></a>00010 <span class=
"comment">/*************************************************************************************************/
</span>
51 <a name=
"l00011"></a>00011
52 <a name=
"l00012"></a>00012 <span class=
"preprocessor">#ifndef GIL_CHANNEL_ALGORITHM_HPP
</span>
53 <a name=
"l00013"></a>00013 <span class=
"preprocessor"></span><span class=
"preprocessor">#define GIL_CHANNEL_ALGORITHM_HPP
</span>
54 <a name=
"l00014"></a>00014 <span class=
"preprocessor"></span>
55 <a name=
"l00025"></a>00025
56 <a name=
"l00026"></a>00026 <span class=
"preprocessor">#include
"<a class="code
" href="g_i_l_0094.html
" title="GIL configuration file.
">gil_config.hpp</a>"</span>
57 <a name=
"l00027"></a>00027 <span class=
"preprocessor">#include
"<a class="code
" href="channel_8hpp.html
" title="Channel utilities.
">channel.hpp</a>"</span>
58 <a name=
"l00028"></a>00028 <span class=
"preprocessor">#include
<boost/mpl/less.hpp
></span>
59 <a name=
"l00029"></a>00029 <span class=
"preprocessor">#include
<boost/mpl/integral_c.hpp
></span>
60 <a name=
"l00030"></a>00030 <span class=
"preprocessor">#include
<boost/mpl/greater.hpp
></span>
61 <a name=
"l00031"></a>00031 <span class=
"preprocessor">#include
<boost/type_traits.hpp
></span>
62 <a name=
"l00032"></a>00032
63 <a name=
"l00033"></a>00033 <span class=
"keyword">namespace
</span>boost {
<span class=
"keyword">namespace
</span>gil {
64 <a name=
"l00034"></a>00034
65 <a name=
"l00035"></a>00035 <span class=
"comment">//#ifdef _MSC_VER
</span>
66 <a name=
"l00036"></a>00036 <span class=
"comment">//#pragma warning(push)
</span>
67 <a name=
"l00037"></a>00037 <span class=
"comment">//#pragma warning(disable:
4309) // disable truncation of constant value warning (using -
1 to get the max value of an integral)
</span>
68 <a name=
"l00038"></a>00038 <span class=
"comment">//#endif
</span>
69 <a name=
"l00039"></a>00039
70 <a name=
"l00040"></a>00040 <span class=
"keyword">namespace
</span>detail {
71 <a name=
"l00041"></a>00041
72 <a name=
"l00042"></a>00042 <span class=
"comment">// some forward declarations
</span>
73 <a name=
"l00043"></a>00043 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> SrcChannelV,
<span class=
"keyword">typename
</span> DstChannelV,
<span class=
"keywordtype">bool
</span> SrcIsIntegral,
<span class=
"keywordtype">bool
</span> DstIsIntegral
> <span class=
"keyword">struct
</span>channel_converter_unsigned_impl;
74 <a name=
"l00044"></a>00044 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> SrcChannelV,
<span class=
"keyword">typename
</span> DstChannelV,
<span class=
"keywordtype">bool
</span> SrcIsGreater
> <span class=
"keyword">struct
</span>channel_converter_unsigned_integral;
75 <a name=
"l00045"></a>00045 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> SrcChannelV,
<span class=
"keyword">typename
</span> DstChannelV,
<span class=
"keywordtype">bool
</span> SrcLessThanDst,
<span class=
"keywordtype">bool
</span> SrcDivisible
> <span class=
"keyword">struct
</span>channel_converter_unsigned_integral_impl;
76 <a name=
"l00046"></a>00046 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> SrcChannelV,
<span class=
"keyword">typename
</span> DstChannelV,
<span class=
"keywordtype">bool
</span> SrcLessThanDst,
<span class=
"keywordtype">bool
</span> CannotFitInInteger
> <span class=
"keyword">struct
</span>channel_converter_unsigned_integral_nondivisible;
77 <a name=
"l00047"></a>00047
78 <a name=
"l00051"></a>00051
79 <a name=
"l00052"></a>00052
80 <a name=
"l00053"></a>00053 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> Un
<span class=
"keywordtype">signed
</span>IntegralChannel
>
81 <a name=
"l00054"></a>00054 <span class=
"keyword">struct
</span>unsigned_integral_max_value :
<span class=
"keyword">public
</span> mpl::integral_c
<UnsignedIntegralChannel,-
1> {};
82 <a name=
"l00055"></a>00055
83 <a name=
"l00056"></a>00056 <span class=
"keyword">template
</span> <>
84 <a name=
"l00057"></a>00057 <span class=
"keyword">struct
</span>unsigned_integral_max_value
<uint8_t
> :
<span class=
"keyword">public
</span> mpl::integral_c
<uint32_t,
0xFF> {};
85 <a name=
"l00058"></a>00058 <span class=
"keyword">template
</span> <>
86 <a name=
"l00059"></a>00059 <span class=
"keyword">struct
</span>unsigned_integral_max_value
<uint16_t
> :
<span class=
"keyword">public
</span> mpl::integral_c
<uint32_t,
0xFFFF> {};
87 <a name=
"l00060"></a>00060 <span class=
"keyword">template
</span> <>
88 <a name=
"l00061"></a>00061 <span class=
"keyword">struct
</span>unsigned_integral_max_value
<uint32_t
> :
<span class=
"keyword">public
</span> mpl::integral_c
<uintmax_t,
0xFFFFFFFF> {};
89 <a name=
"l00062"></a>00062
90 <a name=
"l00063"></a>00063
91 <a name=
"l00064"></a>00064 <span class=
"keyword">template
</span> <<span class=
"keywordtype">int
</span> K
>
92 <a name=
"l00065"></a>00065 <span class=
"keyword">struct
</span>unsigned_integral_max_value
<packed_channel_value
<K
> >
93 <a name=
"l00066"></a>00066 :
<span class=
"keyword">public
</span> mpl::integral_c
<typename packed_channel_value
<K
>::integer_t, (
1<<K)-
1> {};
94 <a name=
"l00067"></a>00067
95 <a name=
"l00071"></a>00071
96 <a name=
"l00072"></a>00072 template
<typename UnsignedIntegralChannel
>
97 <a name=
"l00073"></a>00073 struct unsigned_integral_num_bits : public mpl::int_
<sizeof(UnsignedIntegralChannel)*
8> {};
98 <a name=
"l00074"></a>00074
99 <a name=
"l00075"></a>00075 template
<int K
>
100 <a name=
"l00076"></a>00076 struct unsigned_integral_num_bits
<packed_channel_value
<K
> >
101 <a name=
"l00077"></a>00077 : public mpl::int_
<K
> {};
102 <a name=
"l00078"></a>00078
103 <a name=
"l00079"></a>00079 }
<span class=
"comment">// namespace detail
</span>
104 <a name=
"l00080"></a>00080
105 <a name=
"l00114"></a>00114
106 <a name=
"l00115"></a>00115
107 <a name=
"l00116"></a>00116
108 <a name=
"l00117"></a>00117
109 <a name=
"l00118"></a>00118 template
<typename SrcChannelV, typename DstChannelV
> <span class=
"comment">// Model ChannelValueConcept
</span>
110 <a name=
"l00119"></a>00119 struct channel_converter_unsigned
111 <a name=
"l00120"></a>00120 : public detail::channel_converter_unsigned_impl
<SrcChannelV,DstChannelV,is_integral
<SrcChannelV
>::value,is_integral
<DstChannelV
>::value
> {};
112 <a name=
"l00121"></a>00121
113 <a name=
"l00122"></a>00122
114 <a name=
"l00124"></a><a class=
"code" href=
"g_i_l_0410.html">00124</a> template
<typename T
> struct channel_converter_unsigned
<T,T
> : public detail::identity
<T
> {};
115 <a name=
"l00125"></a>00125
116 <a name=
"l00126"></a>00126
117 <a name=
"l00127"></a>00127 namespace detail {
118 <a name=
"l00128"></a>00128
119 <a name=
"l00132"></a>00132
120 <a name=
"l00134"></a>00134 template
<typename SrcChannelV, typename DstChannelV, bool SrcIsIntegral, bool DstIsIntegral
>
121 <a name=
"l00135"></a><a class=
"code" href=
"g_i_l_0477.html">00135</a> struct channel_converter_unsigned_impl : public std::unary_function
<DstChannelV,SrcChannelV
> {
122 <a name=
"l00136"></a>00136 DstChannelV operator()(SrcChannelV src) const {
123 <a name=
"l00137"></a>00137 return DstChannelV(channel_traits
<DstChannelV
>::min_value() +
124 <a name=
"l00138"></a>00138 (src - channel_traits
<SrcChannelV
>::min_value()) / channel_range
<SrcChannelV
>() * channel_range
<DstChannelV
>());
125 <a name=
"l00139"></a>00139 }
126 <a name=
"l00140"></a>00140 private:
127 <a name=
"l00141"></a>00141 template
<typename C
>
128 <a name=
"l00142"></a>00142 static double channel_range() {
129 <a name=
"l00143"></a>00143 return double(channel_traits
<C
>::max_value()) - double(channel_traits
<C
>::min_value());
130 <a name=
"l00144"></a>00144 }
131 <a name=
"l00145"></a>00145 };
132 <a name=
"l00146"></a>00146
133 <a name=
"l00147"></a>00147 <span class=
"comment">// When both the source and the destination are integral channels, perform a faster conversion
</span>
134 <a name=
"l00148"></a>00148 template
<typename SrcChannelV, typename DstChannelV
>
135 <a name=
"l00149"></a>00149 struct channel_converter_unsigned_impl
<SrcChannelV,DstChannelV,true,true
>
136 <a name=
"l00150"></a>00150 : public channel_converter_unsigned_integral
<SrcChannelV,DstChannelV,
137 <a name=
"l00151"></a>00151 mpl::less
<unsigned_integral_max_value
<SrcChannelV
>,unsigned_integral_max_value
<DstChannelV
> >::value
> {};
138 <a name=
"l00152"></a>00152
139 <a name=
"l00153"></a>00153
140 <a name=
"l00157"></a>00157
141 <a name=
"l00158"></a>00158 template
<typename SrcChannelV, typename DstChannelV
>
142 <a name=
"l00159"></a>00159 struct channel_converter_unsigned_integral
<SrcChannelV,DstChannelV,true
>
143 <a name=
"l00160"></a>00160 : public channel_converter_unsigned_integral_impl
<SrcChannelV,DstChannelV,true,
144 <a name=
"l00161"></a>00161 !(unsigned_integral_max_value
<DstChannelV
>::value % unsigned_integral_max_value
<SrcChannelV
>::value)
> {};
145 <a name=
"l00162"></a>00162
146 <a name=
"l00163"></a>00163 template
<typename SrcChannelV, typename DstChannelV
>
147 <a name=
"l00164"></a>00164 struct channel_converter_unsigned_integral
<SrcChannelV,DstChannelV,false
>
148 <a name=
"l00165"></a>00165 : public channel_converter_unsigned_integral_impl
<SrcChannelV,DstChannelV,false,
149 <a name=
"l00166"></a>00166 !(unsigned_integral_max_value
<SrcChannelV
>::value % unsigned_integral_max_value
<DstChannelV
>::value)
> {};
150 <a name=
"l00167"></a>00167
151 <a name=
"l00168"></a>00168
152 <a name=
"l00172"></a>00172
153 <a name=
"l00173"></a>00173 <span class=
"comment">// Both source and destination are unsigned integral channels,
</span>
154 <a name=
"l00174"></a>00174 <span class=
"comment">// the src max value is less than the dst max value,
</span>
155 <a name=
"l00175"></a>00175 <span class=
"comment">// and the dst max value is divisible by the src max value
</span>
156 <a name=
"l00176"></a>00176 template
<typename SrcChannelV, typename DstChannelV
>
157 <a name=
"l00177"></a>00177 struct channel_converter_unsigned_integral_impl
<SrcChannelV,DstChannelV,true,true
> {
158 <a name=
"l00178"></a>00178 DstChannelV operator()(SrcChannelV src) const {
159 <a name=
"l00179"></a>00179 typedef typename unsigned_integral_max_value
<DstChannelV
>::value_type integer_t;
160 <a name=
"l00180"></a>00180 static const integer_t mul = unsigned_integral_max_value
<DstChannelV
>::value / unsigned_integral_max_value
<SrcChannelV
>::value;
161 <a name=
"l00181"></a>00181 return DstChannelV(src * mul);
162 <a name=
"l00182"></a>00182 }
163 <a name=
"l00183"></a>00183 };
164 <a name=
"l00184"></a>00184
165 <a name=
"l00185"></a>00185 <span class=
"comment">// Both source and destination are unsigned integral channels,
</span>
166 <a name=
"l00186"></a>00186 <span class=
"comment">// the dst max value is less than (or equal to) the src max value,
</span>
167 <a name=
"l00187"></a>00187 <span class=
"comment">// and the src max value is divisible by the dst max value
</span>
168 <a name=
"l00188"></a>00188 template
<typename SrcChannelV, typename DstChannelV
>
169 <a name=
"l00189"></a>00189 struct channel_converter_unsigned_integral_impl
<SrcChannelV,DstChannelV,false,true
> {
170 <a name=
"l00190"></a>00190 DstChannelV operator()(SrcChannelV src) const {
171 <a name=
"l00191"></a>00191 typedef typename unsigned_integral_max_value
<SrcChannelV
>::value_type integer_t;
172 <a name=
"l00192"></a>00192 static const integer_t div = unsigned_integral_max_value
<SrcChannelV
>::value / unsigned_integral_max_value
<DstChannelV
>::value;
173 <a name=
"l00193"></a>00193 static const integer_t div2 = div/
2;
174 <a name=
"l00194"></a>00194 return DstChannelV((src + div2) / div);
175 <a name=
"l00195"></a>00195 }
176 <a name=
"l00196"></a>00196 };
177 <a name=
"l00197"></a>00197
178 <a name=
"l00198"></a>00198 <span class=
"comment">// Prevent overflow for the largest integral type
</span>
179 <a name=
"l00199"></a>00199 template
<typename DstChannelV
>
180 <a name=
"l00200"></a>00200 struct channel_converter_unsigned_integral_impl
<uintmax_t,DstChannelV,false,true
> {
181 <a name=
"l00201"></a>00201 DstChannelV operator()(uintmax_t src) const {
182 <a name=
"l00202"></a>00202 static const uintmax_t div = unsigned_integral_max_value
<bits32
>::value / unsigned_integral_max_value
<DstChannelV
>::value;
183 <a name=
"l00203"></a>00203 static const uintmax_t div2 = div/
2;
184 <a name=
"l00204"></a>00204 if (src
> unsigned_integral_max_value
<uintmax_t
>::value - div2)
185 <a name=
"l00205"></a>00205 return unsigned_integral_max_value
<DstChannelV
>::value;
186 <a name=
"l00206"></a>00206 return DstChannelV((src + div2) / div);
187 <a name=
"l00207"></a>00207 }
188 <a name=
"l00208"></a>00208 };
189 <a name=
"l00209"></a>00209
190 <a name=
"l00210"></a>00210 <span class=
"comment">// Both source and destination are unsigned integral channels,
</span>
191 <a name=
"l00211"></a>00211 <span class=
"comment">// and the dst max value is not divisible by the src max value
</span>
192 <a name=
"l00212"></a>00212 <span class=
"comment">// See if you can represent the expression (src * dst_max) / src_max in integral form
</span>
193 <a name=
"l00213"></a>00213 template
<typename SrcChannelV, typename DstChannelV, bool SrcLessThanDst
>
194 <a name=
"l00214"></a>00214 struct channel_converter_unsigned_integral_impl
<SrcChannelV,DstChannelV,SrcLessThanDst,false
>
195 <a name=
"l00215"></a>00215 : public channel_converter_unsigned_integral_nondivisible
<SrcChannelV,DstChannelV,SrcLessThanDst,
196 <a name=
"l00216"></a>00216 mpl::greater
<
197 <a name=
"l00217"></a>00217 mpl::plus
<unsigned_integral_num_bits
<SrcChannelV
>,unsigned_integral_num_bits
<DstChannelV
> >,
198 <a name=
"l00218"></a>00218 unsigned_integral_num_bits
<uintmax_t
>
199 <a name=
"l00219"></a>00219 >::value
> {};
200 <a name=
"l00220"></a>00220
201 <a name=
"l00221"></a>00221
202 <a name=
"l00222"></a>00222 <span class=
"comment">// Both source and destination are unsigned integral channels,
</span>
203 <a name=
"l00223"></a>00223 <span class=
"comment">// the src max value is less than the dst max value,
</span>
204 <a name=
"l00224"></a>00224 <span class=
"comment">// and the dst max value is not divisible by the src max value
</span>
205 <a name=
"l00225"></a>00225 <span class=
"comment">// The expression (src * dst_max) / src_max fits in an integer
</span>
206 <a name=
"l00226"></a>00226 template
<typename SrcChannelV, typename DstChannelV
>
207 <a name=
"l00227"></a>00227 struct channel_converter_unsigned_integral_nondivisible
<SrcChannelV,DstChannelV,true,false
> {
208 <a name=
"l00228"></a>00228 DstChannelV operator()(SrcChannelV src) const {
209 <a name=
"l00229"></a>00229 typedef typename detail::min_fast_uint
<unsigned_integral_num_bits
<SrcChannelV
>::value+unsigned_integral_num_bits
<DstChannelV
>::value
>::type integer_t;
210 <a name=
"l00230"></a>00230 return DstChannelV(integer_t(src * unsigned_integral_max_value
<DstChannelV
>::value) / unsigned_integral_max_value
<SrcChannelV
>::value);
211 <a name=
"l00231"></a>00231 }
212 <a name=
"l00232"></a>00232 };
213 <a name=
"l00233"></a>00233
214 <a name=
"l00234"></a>00234 <span class=
"comment">// Both source and destination are unsigned integral channels,
</span>
215 <a name=
"l00235"></a>00235 <span class=
"comment">// the src max value is less than the dst max value,
</span>
216 <a name=
"l00236"></a>00236 <span class=
"comment">// and the dst max value is not divisible by the src max value
</span>
217 <a name=
"l00237"></a>00237 <span class=
"comment">// The expression (src * dst_max) / src_max cannot fit in an integer (overflows). Use a double
</span>
218 <a name=
"l00238"></a>00238 template
<typename SrcChannelV, typename DstChannelV
>
219 <a name=
"l00239"></a>00239 struct channel_converter_unsigned_integral_nondivisible
<SrcChannelV,DstChannelV,true,true
> {
220 <a name=
"l00240"></a>00240 DstChannelV operator()(SrcChannelV src) const {
221 <a name=
"l00241"></a>00241 static const double mul = unsigned_integral_max_value
<DstChannelV
>::value / double(unsigned_integral_max_value
<SrcChannelV
>::value);
222 <a name=
"l00242"></a>00242 return DstChannelV(src * mul);
223 <a name=
"l00243"></a>00243 }
224 <a name=
"l00244"></a>00244 };
225 <a name=
"l00245"></a>00245
226 <a name=
"l00246"></a>00246
227 <a name=
"l00247"></a>00247 <span class=
"comment">// Both source and destination are unsigned integral channels,
</span>
228 <a name=
"l00248"></a>00248 <span class=
"comment">// the dst max value is less than (or equal to) the src max value,
</span>
229 <a name=
"l00249"></a>00249 <span class=
"comment">// and the src max value is not divisible by the dst max value
</span>
230 <a name=
"l00250"></a>00250 template
<typename SrcChannelV, typename DstChannelV, bool CannotFit
>
231 <a name=
"l00251"></a>00251 struct channel_converter_unsigned_integral_nondivisible
<SrcChannelV,DstChannelV,false,CannotFit
> {
232 <a name=
"l00252"></a>00252 DstChannelV operator()(SrcChannelV src) const {
233 <a name=
"l00253"></a>00253 typedef typename unsigned_integral_max_value
<SrcChannelV
>::value_type integer_t;
234 <a name=
"l00254"></a>00254
235 <a name=
"l00255"></a>00255 static const double div = unsigned_integral_max_value
<SrcChannelV
>::value / double(unsigned_integral_max_value
<DstChannelV
>::value);
236 <a name=
"l00256"></a>00256 static const integer_t div2 = integer_t(div/
2);
237 <a name=
"l00257"></a>00257 return DstChannelV((src + div2) / div);
238 <a name=
"l00258"></a>00258 }
239 <a name=
"l00259"></a>00259 };
240 <a name=
"l00260"></a>00260
241 <a name=
"l00261"></a>00261 }
<span class=
"comment">// namespace detail
</span>
242 <a name=
"l00262"></a>00262
243 <a name=
"l00266"></a>00266
244 <a name=
"l00267"></a><a class=
"code" href=
"g_i_l_0414.html">00267</a> template
<typename DstChannelV
> struct channel_converter_unsigned
<bits32f,DstChannelV
> : public std::unary_function
<bits32f,DstChannelV
> {
245 <a name=
"l00268"></a>00268 DstChannelV operator()(bits32f x) const { return DstChannelV(x*channel_traits
<DstChannelV
>::max_value()+
0.5f); }
246 <a name=
"l00269"></a>00269 };
247 <a name=
"l00270"></a>00270
248 <a name=
"l00271"></a>00271 template
<typename SrcChannelV
> struct channel_converter_unsigned
<SrcChannelV,bits32f
> : public std::unary_function
<SrcChannelV,bits32f
> {
249 <a name=
"l00272"></a>00272 bits32f operator()(SrcChannelV x) const { return bits32f(x/float(channel_traits
<SrcChannelV
>::max_value())); }
250 <a name=
"l00273"></a>00273 };
251 <a name=
"l00274"></a>00274
252 <a name=
"l00275"></a>00275 template
<> struct channel_converter_unsigned
<bits32f,bits32f
> : public std::unary_function
<bits32f,bits32f
> {
253 <a name=
"l00276"></a>00276 bits32f operator()(bits32f x) const { return x; }
254 <a name=
"l00277"></a>00277 };
255 <a name=
"l00278"></a>00278
256 <a name=
"l00279"></a>00279
257 <a name=
"l00281"></a><a class=
"code" href=
"g_i_l_0412.html">00281</a> template
<> struct channel_converter_unsigned
<bits32,bits32f
> : public std::unary_function
<bits32,bits32f
> {
258 <a name=
"l00282"></a>00282 bits32f operator()(bits32 x) const {
259 <a name=
"l00283"></a>00283 <span class=
"comment">// unfortunately without an explicit check it is possible to get a round-off error. We must ensure that max_value of bits32 matches max_value of bits32f
</span>
260 <a name=
"l00284"></a>00284 if (x
>=channel_traits
<bits32
>::max_value()) return
<a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
</a><bits32f
>::max_value();
261 <a name=
"l00285"></a>00285 return float(x) / float(channel_traits
<bits32
>::max_value());
262 <a name=
"l00286"></a>00286 }
263 <a name=
"l00287"></a>00287 };
264 <a name=
"l00289"></a><a class=
"code" href=
"g_i_l_0416.html">00289</a> template
<> struct channel_converter_unsigned
<bits32f,bits32
> :
<span class=
"keyword">public
</span> std::unary_function
<bits32f,bits32
> {
265 <a name=
"l00290"></a>00290 bits32 operator()(
<a class=
"code" href=
"g_i_l_0620.html" title=
"A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">bits32f
</a> x)
<span class=
"keyword"> const
</span>{
266 <a name=
"l00291"></a>00291 <span class=
"comment">// unfortunately without an explicit check it is possible to get a round-off error. We must ensure that max_value of bits32 matches max_value of bits32f
</span>
267 <a name=
"l00292"></a>00292 <span class=
"keywordflow">if
</span> (x
>=
<a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<bits32f
>::max_value
</a>())
<span class=
"keywordflow">return
</span> <a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<bits32
>::max_value
</a>();
268 <a name=
"l00293"></a>00293 <span class=
"keywordflow">return
</span> bits32(x *
<a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<bits32
>::max_value
</a>() +
0.5f);
269 <a name=
"l00294"></a>00294 }
270 <a name=
"l00295"></a>00295 };
271 <a name=
"l00296"></a>00296
272 <a name=
"l00298"></a>00298
273 <a name=
"l00299"></a>00299 <span class=
"keyword">namespace
</span>detail {
274 <a name=
"l00300"></a>00300 <span class=
"comment">// Converting from signed to unsigned integral channel.
</span>
275 <a name=
"l00301"></a>00301 <span class=
"comment">// It is both a unary function, and a metafunction (thus requires the 'type' nested typedef, which equals result_type)
</span>
276 <a name=
"l00302"></a>00302 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> ChannelValue
> <span class=
"comment">// Model ChannelValueConcept
</span>
277 <a name=
"l00303"></a>00303 <span class=
"keyword">struct
</span>channel_convert_to_unsigned :
<span class=
"keyword">public
</span> detail::identity
<ChannelValue
> {
278 <a name=
"l00304"></a>00304 <span class=
"keyword">typedef
</span> ChannelValue type;
279 <a name=
"l00305"></a>00305 };
280 <a name=
"l00306"></a>00306
281 <a name=
"l00307"></a>00307 <span class=
"keyword">template
</span> <> <span class=
"keyword">struct
</span>channel_convert_to_unsigned
<bits8s
> :
<span class=
"keyword">public
</span> std::unary_function
<bits8s,bits8
> {
282 <a name=
"l00308"></a>00308 <span class=
"keyword">typedef
</span> bits8 type;
283 <a name=
"l00309"></a>00309 type operator()(bits8s val)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> val+
128; }
284 <a name=
"l00310"></a>00310 };
285 <a name=
"l00311"></a>00311
286 <a name=
"l00312"></a>00312 <span class=
"keyword">template
</span> <> <span class=
"keyword">struct
</span>channel_convert_to_unsigned
<bits16s
> :
<span class=
"keyword">public
</span> std::unary_function
<bits16s,bits16
> {
287 <a name=
"l00313"></a>00313 <span class=
"keyword">typedef
</span> bits16 type;
288 <a name=
"l00314"></a>00314 type operator()(bits16s val)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> val+
32768; }
289 <a name=
"l00315"></a>00315 };
290 <a name=
"l00316"></a>00316
291 <a name=
"l00317"></a>00317 <span class=
"keyword">template
</span> <> <span class=
"keyword">struct
</span>channel_convert_to_unsigned
<bits32s
> :
<span class=
"keyword">public
</span> std::unary_function
<bits32s,bits32
> {
292 <a name=
"l00318"></a>00318 <span class=
"keyword">typedef
</span> bits32 type;
293 <a name=
"l00319"></a>00319 type operator()(bits32s x)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> <span class=
"keyword">static_cast
<</span>bits32
<span class=
"keyword">></span>(x+(
1<<31)); }
294 <a name=
"l00320"></a>00320 };
295 <a name=
"l00321"></a>00321
296 <a name=
"l00322"></a>00322
297 <a name=
"l00323"></a>00323 <span class=
"comment">// Converting from unsigned to signed integral channel
</span>
298 <a name=
"l00324"></a>00324 <span class=
"comment">// It is both a unary function, and a metafunction (thus requires the 'type' nested typedef, which equals result_type)
</span>
299 <a name=
"l00325"></a>00325 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> ChannelValue
> <span class=
"comment">// Model ChannelValueConcept
</span>
300 <a name=
"l00326"></a>00326 <span class=
"keyword">struct
</span>channel_convert_from_unsigned :
<span class=
"keyword">public
</span> detail::identity
<ChannelValue
> {
301 <a name=
"l00327"></a>00327 <span class=
"keyword">typedef
</span> ChannelValue type;
302 <a name=
"l00328"></a>00328 };
303 <a name=
"l00329"></a>00329
304 <a name=
"l00330"></a>00330 <span class=
"keyword">template
</span> <> <span class=
"keyword">struct
</span>channel_convert_from_unsigned
<bits8s
> :
<span class=
"keyword">public
</span> std::unary_function
<bits8,bits8s
> {
305 <a name=
"l00331"></a>00331 <span class=
"keyword">typedef
</span> bits8s type;
306 <a name=
"l00332"></a>00332 type operator()(bits8 val)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> val-
128; }
307 <a name=
"l00333"></a>00333 };
308 <a name=
"l00334"></a>00334
309 <a name=
"l00335"></a>00335 <span class=
"keyword">template
</span> <> <span class=
"keyword">struct
</span>channel_convert_from_unsigned
<bits16s
> :
<span class=
"keyword">public
</span> std::unary_function
<bits16,bits16s
> {
310 <a name=
"l00336"></a>00336 <span class=
"keyword">typedef
</span> bits16s type;
311 <a name=
"l00337"></a>00337 type operator()(bits16 val)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> val-
32768; }
312 <a name=
"l00338"></a>00338 };
313 <a name=
"l00339"></a>00339
314 <a name=
"l00340"></a>00340 <span class=
"keyword">template
</span> <> <span class=
"keyword">struct
</span>channel_convert_from_unsigned
<bits32s
> :
<span class=
"keyword">public
</span> std::unary_function
<bits32,bits32s
> {
315 <a name=
"l00341"></a>00341 <span class=
"keyword">typedef
</span> bits32s type;
316 <a name=
"l00342"></a>00342 type operator()(bits32 x)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> <span class=
"keyword">static_cast
<</span>bits32s
<span class=
"keyword">></span>(x-(
1<<31)); }
317 <a name=
"l00343"></a>00343 };
318 <a name=
"l00344"></a>00344
319 <a name=
"l00345"></a>00345 }
<span class=
"comment">// namespace detail
</span>
320 <a name=
"l00346"></a>00346
321 <a name=
"l00349"></a>00349 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> SrcChannelV,
<span class=
"keyword">typename
</span> DstChannelV
> <span class=
"comment">// Model ChannelValueConcept
</span>
322 <a name=
"l00350"></a><a class=
"code" href=
"g_i_l_0408.html">00350</a> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0408.html" title=
"A unary function object converting between channel types.">channel_converter
</a> :
<span class=
"keyword">public
</span> std::unary_function
<SrcChannelV,DstChannelV
> {
323 <a name=
"l00351"></a>00351 DstChannelV operator()(SrcChannelV src)
<span class=
"keyword"> const
</span>{
324 <a name=
"l00352"></a>00352 <span class=
"keyword">typedef
</span> detail::channel_convert_to_unsigned
<SrcChannelV
> to_unsigned;
325 <a name=
"l00353"></a>00353 <span class=
"keyword">typedef
</span> detail::channel_convert_from_unsigned
<DstChannelV
> from_unsigned;
326 <a name=
"l00354"></a>00354 <span class=
"keyword">typedef
</span> channel_converter_unsigned
<typename to_unsigned::result_type, typename from_unsigned::argument_type
> converter_unsigned;
327 <a name=
"l00355"></a>00355 <span class=
"keywordflow">return
</span> from_unsigned()(converter_unsigned()(to_unsigned()(src)));
328 <a name=
"l00356"></a>00356 }
329 <a name=
"l00357"></a>00357 };
330 <a name=
"l00358"></a>00358
331 <a name=
"l00361"></a>00361 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> DstChannel,
<span class=
"keyword">typename
</span> SrcChannel
> <span class=
"comment">// Model ChannelConcept (could be channel references)
</span>
332 <a name=
"l00362"></a><a class=
"code" href=
"g_i_l_0099.html#gf04e6ac30a35a1f68a8bb84730e34786">00362</a> <span class=
"keyword">inline
</span> <span class=
"keyword">typename
</span> <a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<DstChannel
>::value_type
</a> <a class=
"code" href=
"g_i_l_0099.html#gf04e6ac30a35a1f68a8bb84730e34786" title=
"Converting from one channel type to another.">channel_convert
</a>(SrcChannel src) {
333 <a name=
"l00363"></a>00363 <span class=
"keywordflow">return
</span> <a class=
"code" href=
"g_i_l_0408.html" title=
"A unary function object converting between channel types.">channel_converter
<typename channel_traits
<SrcChannel
>::value_type
</a>,
334 <a name=
"l00364"></a>00364 <span class=
"keyword">typename
</span> <a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<DstChannel
>::value_type
</a>>()(src);
335 <a name=
"l00365"></a>00365 }
336 <a name=
"l00366"></a>00366
337 <a name=
"l00371"></a><a class=
"code" href=
"g_i_l_0450.html">00371</a> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0450.html" title=
"Same as channel_converter, except it takes the destination channel by reference,...">default_channel_converter
</a> {
338 <a name=
"l00372"></a>00372 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> Ch1,
<span class=
"keyword">typename
</span> Ch2
>
339 <a name=
"l00373"></a>00373 <span class=
"keywordtype">void
</span> operator()(
<span class=
"keyword">const
</span> Ch1
& src, Ch2
& dst)
<span class=
"keyword"> const
</span>{
340 <a name=
"l00374"></a>00374 dst=channel_convert
<Ch2
>(src);
341 <a name=
"l00375"></a>00375 }
342 <a name=
"l00376"></a>00376 };
343 <a name=
"l00377"></a>00377
344 <a name=
"l00378"></a>00378 <span class=
"keyword">namespace
</span>detail {
345 <a name=
"l00379"></a>00379 <span class=
"comment">// fast integer division by
255</span>
346 <a name=
"l00380"></a>00380 <span class=
"keyword">inline
</span> uint32_t div255(uint32_t in) { uint32_t tmp=in+
128;
<span class=
"keywordflow">return
</span> (tmp + (tmp
>>8))
>>8; }
347 <a name=
"l00381"></a>00381
348 <a name=
"l00382"></a>00382 <span class=
"comment">// fast integer divison by
32768</span>
349 <a name=
"l00383"></a>00383 <span class=
"keyword">inline
</span> uint32_t div32768(uint32_t in) {
<span class=
"keywordflow">return
</span> (in+
16384)
>>15; }
350 <a name=
"l00384"></a>00384 }
351 <a name=
"l00385"></a>00385
352 <a name=
"l00399"></a>00399
353 <a name=
"l00400"></a>00400
354 <a name=
"l00402"></a>00402 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> ChannelValue
>
355 <a name=
"l00403"></a><a class=
"code" href=
"g_i_l_0422.html">00403</a> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0422.html" title=
"This is the default implementation. Performance specializatons are provided.">channel_multiplier_unsigned
</a> :
<span class=
"keyword">public
</span> std::binary_function
<ChannelValue,ChannelValue,ChannelValue
> {
356 <a name=
"l00404"></a>00404 ChannelValue operator()(ChannelValue a, ChannelValue b)
<span class=
"keyword"> const
</span>{
357 <a name=
"l00405"></a>00405 <span class=
"keywordflow">return
</span> ChannelValue(a /
<span class=
"keywordtype">double
</span>(
<a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<ChannelValue
>::max_value
</a>()) * b);
358 <a name=
"l00406"></a>00406 }
359 <a name=
"l00407"></a>00407 };
360 <a name=
"l00408"></a>00408
361 <a name=
"l00410"></a><a class=
"code" href=
"g_i_l_0428.html">00410</a> <span class=
"keyword">template
</span><> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0422.html" title=
"This is the default implementation. Performance specializatons are provided.">channel_multiplier_unsigned
</a><bits8
> :
<span class=
"keyword">public
</span> std::binary_function
<bits8,bits8,bits8
> {
362 <a name=
"l00411"></a>00411 bits8 operator()(bits8 a, bits8 b)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> bits8(detail::div255(uint32_t(a) * uint32_t(b))); }
363 <a name=
"l00412"></a>00412 };
364 <a name=
"l00413"></a>00413
365 <a name=
"l00415"></a><a class=
"code" href=
"g_i_l_0424.html">00415</a> <span class=
"keyword">template
</span><> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0422.html" title=
"This is the default implementation. Performance specializatons are provided.">channel_multiplier_unsigned
</a><bits16
> :
<span class=
"keyword">public
</span> std::binary_function
<bits16,bits16,bits16
> {
366 <a name=
"l00416"></a>00416 bits16 operator()(bits16 a, bits16 b)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> bits16((uint32_t(a) * uint32_t(b))/
65535); }
367 <a name=
"l00417"></a>00417 };
368 <a name=
"l00418"></a>00418
369 <a name=
"l00420"></a><a class=
"code" href=
"g_i_l_0426.html">00420</a> <span class=
"keyword">template
</span><> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0422.html" title=
"This is the default implementation. Performance specializatons are provided.">channel_multiplier_unsigned
</a><<a class=
"code" href=
"g_i_l_0620.html" title=
"A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">bits32f
</a>> :
<span class=
"keyword">public
</span> std::binary_function
<bits32f,bits32f,bits32f
> {
370 <a name=
"l00421"></a>00421 <a class=
"code" href=
"g_i_l_0620.html" title=
"A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">bits32f
</a> operator()(
<a class=
"code" href=
"g_i_l_0620.html" title=
"A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">bits32f
</a> a,
<a class=
"code" href=
"g_i_l_0620.html" title=
"A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">bits32f
</a> b)
<span class=
"keyword"> const
</span>{
<span class=
"keywordflow">return
</span> a*b; }
371 <a name=
"l00422"></a>00422 };
372 <a name=
"l00423"></a>00423
373 <a name=
"l00425"></a>00425 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> ChannelValue
>
374 <a name=
"l00426"></a><a class=
"code" href=
"g_i_l_0420.html">00426</a> <span class=
"keyword">struct
</span><a class=
"code" href=
"g_i_l_0420.html" title=
"A function object to multiply two channels. result = a * b / max_value.">channel_multiplier
</a> :
<span class=
"keyword">public
</span> std::binary_function
<ChannelValue, ChannelValue, ChannelValue
> {
375 <a name=
"l00427"></a>00427 ChannelValue operator()(ChannelValue a, ChannelValue b)
<span class=
"keyword"> const
</span>{
376 <a name=
"l00428"></a>00428 <span class=
"keyword">typedef
</span> detail::channel_convert_to_unsigned
<ChannelValue
> to_unsigned;
377 <a name=
"l00429"></a>00429 <span class=
"keyword">typedef
</span> detail::channel_convert_from_unsigned
<ChannelValue
> from_unsigned;
378 <a name=
"l00430"></a>00430 <span class=
"keyword">typedef
</span> <a class=
"code" href=
"g_i_l_0422.html" title=
"This is the default implementation. Performance specializatons are provided.">channel_multiplier_unsigned
<typename to_unsigned::result_type
></a> multiplier_unsigned;
379 <a name=
"l00431"></a>00431 <span class=
"keywordflow">return
</span> from_unsigned()(multiplier_unsigned()(to_unsigned()(a), to_unsigned()(b)));
380 <a name=
"l00432"></a>00432 }
381 <a name=
"l00433"></a>00433 };
382 <a name=
"l00434"></a>00434
383 <a name=
"l00436"></a>00436 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> Channel
> <span class=
"comment">// Models ChannelConcept (could be a channel reference)
</span>
384 <a name=
"l00437"></a><a class=
"code" href=
"g_i_l_0103.html#gf73b2a47a7877767534df0eee46dda17">00437</a> <span class=
"keyword">inline
</span> <span class=
"keyword">typename
</span> <a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<Channel
>::value_type
</a> <a class=
"code" href=
"g_i_l_0103.html#gf73b2a47a7877767534df0eee46dda17" title=
"A function multiplying two channels. result = a * b / max_value.">channel_multiply
</a>(Channel a, Channel b) {
385 <a name=
"l00438"></a>00438 <span class=
"keywordflow">return
</span> <a class=
"code" href=
"g_i_l_0420.html" title=
"A function object to multiply two channels. result = a * b / max_value.">channel_multiplier
<typename channel_traits
<Channel
>::value_type
</a>>()(a,b);
386 <a name=
"l00439"></a>00439 }
387 <a name=
"l00441"></a>00441
388 <a name=
"l00456"></a>00456
389 <a name=
"l00457"></a>00457
390 <a name=
"l00458"></a>00458 <span class=
"keyword">template
</span> <<span class=
"keyword">typename
</span> Channel
> <span class=
"comment">// Models ChannelConcept (could be a channel reference)
</span>
391 <a name=
"l00459"></a><a class=
"code" href=
"g_i_l_0101.html#ge2e0267865f89610ef26148874a04bb5">00459</a> <span class=
"keyword">inline
</span> <span class=
"keyword">typename
</span> <a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<Channel
>::value_type
</a> <a class=
"code" href=
"g_i_l_0101.html#ge2e0267865f89610ef26148874a04bb5" title=
"Default implementation. Provide overloads for performance.">channel_invert
</a>(Channel x) {
392 <a name=
"l00460"></a>00460 <span class=
"keywordflow">return
</span> <a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<Channel
>::max_value
</a>()-x +
<a class=
"code" href=
"g_i_l_0429.html" title=
"Traits for channels. Contains the following members:.">channel_traits
<Channel
>::min_value
</a>();
393 <a name=
"l00461"></a>00461 }
394 <a name=
"l00462"></a>00462
395 <a name=
"l00463"></a>00463 <span class=
"comment">//#ifdef _MSC_VER
</span>
396 <a name=
"l00464"></a>00464 <span class=
"comment">//#pragma warning(pop)
</span>
397 <a name=
"l00465"></a>00465 <span class=
"comment">//#endif
</span>
398 <a name=
"l00466"></a>00466
399 <a name=
"l00467"></a>00467 } }
<span class=
"comment">// namespace boost::gil
</span>
400 <a name=
"l00468"></a>00468
401 <a name=
"l00469"></a>00469 <span class=
"preprocessor">#endif
</span>
403 <hr size=
"1"><address style=
"text-align: right;"><small>Generated on Sat May
2 13:
50:
13 2009 for Generic Image Library by
404 <a href=
"http://www.doxygen.org/index.html">
405 <img src=
"doxygen.png" alt=
"doxygen" align=
"middle" border=
"0"></a> 1.5.6 </small></address>