PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/gil/doc/html/g_i_l_0014.html

https://github.com/delalond/boost_1_54_0-bgq
HTML | 516 lines | 497 code | 3 blank | 16 comment | 0 complexity | a16299ff01bd5f167e63c24ea4967a2d MD5 | raw file
  1. <!-- Copyright 2008 Lubomir Bourdev and Hailin Jin
  2. Distributed under the Boost Software License, Version 1.0.
  3. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. -->
  6. <!--
  7. Copyright 2005-2007 Adobe Systems Incorporated
  8. Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
  9. or a copy at http://stlab.adobe.com/licenses.html)
  10. Some files are held under additional license.
  11. Please see "http://stlab.adobe.com/licenses.html" for more information.
  12. -->
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  14. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  15. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  16. <head>
  17. <TITLE>Generic Image Library: channel.hpp Source File</TITLE>
  18. <META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/>
  19. <LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/>
  20. </head>
  21. <body>
  22. <table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr>
  23. <td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'>
  24. <div class="qindex"><a class="qindex" href="index.html">Modules</a>
  25. | <a class="qindex" href="classes.html">Alphabetical List</a>
  26. | <a class="qindex" href="annotated.html">Class List</a>
  27. | <a class="qindex" href="dirs.html">Directories</a>
  28. | <a class="qindex" href="files.html">File List</a>
  29. | <a class="qindex" href="../index.html">GIL Home Page</a>
  30. </div>
  31. <!-- End Header -->
  32. <!-- Generated by Doxygen 1.5.6 -->
  33. <div class="navpath"><a class="el" href="g_i_l_0076.html">boost</a>&nbsp;&raquo&nbsp;<a class="el" href="g_i_l_0079.html">gil</a>
  34. </div>
  35. <div class="contents">
  36. <h1>channel.hpp</h1><a href="channel_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
  37. <a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span>
  38. <a name="l00003"></a>00003 <span class="comment"> </span>
  39. <a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span>
  40. <a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
  41. <a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span>
  42. <a name="l00007"></a>00007 <span class="comment"></span>
  43. <a name="l00008"></a>00008 <span class="comment"> See http://stlab.adobe.com/gil for most recent version including documentation.</span>
  44. <a name="l00009"></a>00009 <span class="comment">*/</span>
  45. <a name="l00010"></a>00010
  46. <a name="l00011"></a>00011 <span class="comment">/*************************************************************************************************/</span>
  47. <a name="l00012"></a>00012
  48. <a name="l00013"></a>00013 <span class="preprocessor">#ifndef GIL_CHANNEL_HPP</span>
  49. <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define GIL_CHANNEL_HPP</span>
  50. <a name="l00015"></a>00015 <span class="preprocessor"></span>
  51. <a name="l00026"></a>00026
  52. <a name="l00027"></a>00027 <span class="preprocessor">#include &lt;limits&gt;</span>
  53. <a name="l00028"></a>00028 <span class="preprocessor">#include &lt;cassert&gt;</span>
  54. <a name="l00029"></a>00029 <span class="preprocessor">#include &lt;boost/cstdint.hpp&gt;</span>
  55. <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="g_i_l_0094.html" title="GIL configuration file.">gil_config.hpp</a>"</span>
  56. <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="utilities_8hpp.html" title="Various utilities not specific to the image library. Some are non-standard STL extensions...">utilities.hpp</a>"</span>
  57. <a name="l00032"></a>00032
  58. <a name="l00033"></a>00033 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil {
  59. <a name="l00034"></a>00034
  60. <a name="l00035"></a>00035
  61. <a name="l00050"></a>00050
  62. <a name="l00051"></a>00051 <span class="keyword">namespace </span>detail {
  63. <a name="l00052"></a>00052 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keywordtype">bool</span> is_<span class="keyword">class</span>&gt; <span class="keyword">struct </span>channel_traits_impl;
  64. <a name="l00053"></a>00053
  65. <a name="l00054"></a>00054 <span class="comment">// channel traits for custom class</span>
  66. <a name="l00055"></a>00055 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
  67. <a name="l00056"></a>00056 <span class="keyword">struct </span>channel_traits_impl&lt;T, true&gt; {
  68. <a name="l00057"></a>00057 <span class="keyword">typedef</span> <span class="keyword">typename</span> T::value_type value_type;
  69. <a name="l00058"></a>00058 <span class="keyword">typedef</span> <span class="keyword">typename</span> T::reference reference;
  70. <a name="l00059"></a>00059 <span class="keyword">typedef</span> <span class="keyword">typename</span> T::pointer pointer;
  71. <a name="l00060"></a>00060 <span class="keyword">typedef</span> <span class="keyword">typename</span> T::const_reference const_reference;
  72. <a name="l00061"></a>00061 <span class="keyword">typedef</span> <span class="keyword">typename</span> T::const_pointer const_pointer;
  73. <a name="l00062"></a>00062 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>, is_mutable=T::is_mutable);
  74. <a name="l00063"></a>00063 <span class="keyword">static</span> value_type min_value() { <span class="keywordflow">return</span> T::min_value(); }
  75. <a name="l00064"></a>00064 <span class="keyword">static</span> value_type max_value() { <span class="keywordflow">return</span> T::max_value(); }
  76. <a name="l00065"></a>00065 };
  77. <a name="l00066"></a>00066
  78. <a name="l00067"></a>00067 <span class="comment">// channel traits implementation for built-in integral or floating point channel type</span>
  79. <a name="l00068"></a>00068 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
  80. <a name="l00069"></a>00069 <span class="keyword">struct </span>channel_traits_impl&lt;T, false&gt; {
  81. <a name="l00070"></a>00070 <span class="keyword">typedef</span> T value_type;
  82. <a name="l00071"></a>00071 <span class="keyword">typedef</span> T&amp; reference;
  83. <a name="l00072"></a>00072 <span class="keyword">typedef</span> T* pointer;
  84. <a name="l00073"></a>00073 <span class="keyword">typedef</span> <span class="keyword">const</span> T&amp; const_reference;
  85. <a name="l00074"></a>00074 <span class="keyword">typedef</span> T <span class="keyword">const</span>* const_pointer;
  86. <a name="l00075"></a>00075 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>, is_mutable=<span class="keyword">true</span>);
  87. <a name="l00076"></a>00076 <span class="keyword">static</span> value_type min_value() { <span class="keywordflow">return</span> (std::numeric_limits&lt;T&gt;::min)(); }
  88. <a name="l00077"></a>00077 <span class="keyword">static</span> value_type max_value() { <span class="keywordflow">return</span> (std::numeric_limits&lt;T&gt;::max)(); }
  89. <a name="l00078"></a>00078 };
  90. <a name="l00079"></a>00079
  91. <a name="l00080"></a>00080 <span class="comment">// channel traits implementation for constant built-in scalar or floating point type</span>
  92. <a name="l00081"></a>00081 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
  93. <a name="l00082"></a>00082 <span class="keyword">struct </span>channel_traits_impl&lt;const T, false&gt; : <span class="keyword">public</span> channel_traits_impl&lt;T, false&gt; {
  94. <a name="l00083"></a>00083 <span class="keyword">typedef</span> <span class="keyword">const</span> T&amp; reference;
  95. <a name="l00084"></a>00084 <span class="keyword">typedef</span> <span class="keyword">const</span> T* pointer;
  96. <a name="l00085"></a>00085 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>, is_mutable=<span class="keyword">false</span>);
  97. <a name="l00086"></a>00086 };
  98. <a name="l00087"></a>00087 }
  99. <a name="l00088"></a>00088
  100. <a name="l00107"></a>00107 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
  101. <a name="l00108"></a><a class="code" href="g_i_l_0429.html">00108</a> <span class="keyword">struct </span><a class="code" href="g_i_l_0429.html" title="Traits for channels. Contains the following members:.">channel_traits</a> : <span class="keyword">public</span> detail::channel_traits_impl&lt;T, is_class&lt;T&gt;::value&gt; {};
  102. <a name="l00109"></a>00109
  103. <a name="l00110"></a>00110 <span class="comment">// Channel traits for C++ reference type - remove the reference</span>
  104. <a name="l00111"></a>00111 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt; <span class="keyword">struct </span><a class="code" href="g_i_l_0429.html" title="Traits for channels. Contains the following members:.">channel_traits</a>&lt; T&amp;&gt; : <span class="keyword">public</span> <a class="code" href="g_i_l_0429.html" title="Traits for channels. Contains the following members:.">channel_traits&lt;T&gt;</a> {};
  105. <a name="l00112"></a>00112
  106. <a name="l00113"></a>00113 <span class="comment">// Channel traits for constant C++ reference type</span>
  107. <a name="l00114"></a>00114 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt; <span class="keyword">struct </span>channel_traits&lt;const T&amp;&gt; : <span class="keyword">public</span> channel_traits&lt;T&gt; {
  108. <a name="l00115"></a>00115 <span class="keyword">typedef</span> <span class="keyword">typename</span> channel_traits&lt;T&gt;::const_reference reference;
  109. <a name="l00116"></a>00116 <span class="keyword">typedef</span> <span class="keyword">typename</span> channel_traits&lt;T&gt;::const_pointer pointer;
  110. <a name="l00117"></a>00117 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>, is_mutable=<span class="keyword">false</span>);
  111. <a name="l00118"></a>00118 };
  112. <a name="l00119"></a>00119
  113. <a name="l00125"></a>00125
  114. <a name="l00146"></a>00146
  115. <a name="l00147"></a>00147
  116. <a name="l00148"></a>00148 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BaseChannelValue, <span class="comment">// base channel (models ChannelValueConcept)</span>
  117. <a name="l00149"></a>00149 <span class="keyword">typename</span> MinVal, <span class="keyword">typename</span> MaxVal&gt; <span class="comment">// classes with a static apply() function returning the minimum/maximum channel values</span>
  118. <a name="l00150"></a><a class="code" href="g_i_l_0620.html">00150</a> <span class="keyword">struct </span><a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a> {
  119. <a name="l00151"></a>00151 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a>;
  120. <a name="l00152"></a>00152 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a>&amp; <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">reference</a>;
  121. <a name="l00153"></a>00153 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a>* <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">pointer</a>;
  122. <a name="l00154"></a>00154 <span class="keyword">typedef</span> <span class="keyword">const</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a>&amp; <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">const_reference</a>;
  123. <a name="l00155"></a>00155 <span class="keyword">typedef</span> <span class="keyword">const</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a>* <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">const_pointer</a>;
  124. <a name="l00156"></a>00156 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>, is_mutable=<a class="code" href="g_i_l_0429.html" title="Traits for channels. Contains the following members:.">channel_traits&lt;BaseChannelValue&gt;::is_mutable</a>);
  125. <a name="l00157"></a>00157
  126. <a name="l00158"></a>00158 <span class="keyword">static</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a> min_value() { <span class="keywordflow">return</span> MinVal::apply(); }
  127. <a name="l00159"></a>00159 <span class="keyword">static</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">value_type</a> max_value() { <span class="keywordflow">return</span> MaxVal::apply(); }
  128. <a name="l00160"></a>00160
  129. <a name="l00161"></a>00161 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>() {}
  130. <a name="l00162"></a>00162 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>(<span class="keyword">const</span> <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; c) : _value(c.<a class="code" href="g_i_l_0620.html#734cfc58c2d23ec05c26288f29070346">_value</a>) {}
  131. <a name="l00163"></a>00163 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>(BaseChannelValue val) : _value(val) {}
  132. <a name="l00164"></a>00164
  133. <a name="l00165"></a>00165 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator++() { ++_value; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  134. <a name="l00166"></a>00166 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator--() { --_value; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  135. <a name="l00167"></a>00167
  136. <a name="l00168"></a>00168 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a> operator++(<span class="keywordtype">int</span>) { <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a> tmp=*<span class="keyword">this</span>; this-&gt;operator++(); <span class="keywordflow">return</span> tmp; }
  137. <a name="l00169"></a>00169 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a> operator--(<span class="keywordtype">int</span>) { <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a> tmp=*<span class="keyword">this</span>; this-&gt;operator--(); <span class="keywordflow">return</span> tmp; }
  138. <a name="l00170"></a>00170
  139. <a name="l00171"></a>00171 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Scalar2&gt; <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator+=(Scalar2 v) { _value+=v; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  140. <a name="l00172"></a>00172 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Scalar2&gt; <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator-=(Scalar2 v) { _value-=v; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  141. <a name="l00173"></a>00173 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Scalar2&gt; <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator*=(Scalar2 v) { _value*=v; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  142. <a name="l00174"></a>00174 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Scalar2&gt; <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator/=(Scalar2 v) { _value/=v; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  143. <a name="l00175"></a>00175
  144. <a name="l00176"></a>00176 <a class="code" href="g_i_l_0620.html" title="A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept...">scoped_channel_value</a>&amp; operator=(BaseChannelValue v) { _value=v; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  145. <a name="l00177"></a>00177 operator BaseChannelValue()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _value; }
  146. <a name="l00178"></a>00178 <span class="keyword">private</span>:
  147. <a name="l00179"></a>00179 BaseChannelValue _value;
  148. <a name="l00180"></a>00180 };
  149. <a name="l00181"></a>00181
  150. <a name="l00182"></a>00182 <span class="keyword">struct </span>float_zero { <span class="keyword">static</span> <span class="keywordtype">float</span> apply() { <span class="keywordflow">return</span> 0.0f; } };
  151. <a name="l00183"></a>00183 <span class="keyword">struct </span>float_one { <span class="keyword">static</span> <span class="keywordtype">float</span> apply() { <span class="keywordflow">return</span> 1.0f; } };
  152. <a name="l00184"></a>00184
  153. <a name="l00185"></a>00185
  154. <a name="l00191"></a>00191
  155. <a name="l00192"></a>00192 <span class="comment">// It is necessary for packed channels to have their own value type. They cannot simply use an integral large enough to store the data. Here is why:</span>
  156. <a name="l00193"></a>00193 <span class="comment">// - Any operation that requires returning the result by value will otherwise return the built-in integral type, which will have incorrect range</span>
  157. <a name="l00194"></a>00194 <span class="comment">// That means that after getting the value of the channel we cannot properly do channel_convert, channel_invert, etc.</span>
  158. <a name="l00195"></a>00195 <span class="comment">// - Two channels are declared compatible if they have the same value type. That means that a packed channel is incorrectly declared compatible with an integral type</span>
  159. <a name="l00196"></a>00196 <span class="keyword">namespace </span>detail {
  160. <a name="l00197"></a>00197 <span class="comment">// returns the smallest fast unsigned integral type that has at least NumBits bits</span>
  161. <a name="l00198"></a>00198 <span class="keyword">template</span> &lt;<span class="keywordtype">int</span> NumBits&gt;
  162. <a name="l00199"></a>00199 <span class="keyword">struct </span>min_fast_uint : <span class="keyword">public</span> mpl::if_c&lt; (NumBits&lt;=8),
  163. <a name="l00200"></a>00200 uint_least8_t,
  164. <a name="l00201"></a>00201 typename mpl::if_c&lt; (NumBits&lt;=16),
  165. <a name="l00202"></a>00202 uint_least16_t,
  166. <a name="l00203"></a>00203 typename mpl::if_c&lt; (NumBits&lt;=32),
  167. <a name="l00204"></a>00204 uint_least32_t,
  168. <a name="l00205"></a>00205 uintmax_t
  169. <a name="l00206"></a>00206 &gt;::type
  170. <a name="l00207"></a>00207 &gt;::type
  171. <a name="l00208"></a>00208 &gt; {};
  172. <a name="l00209"></a>00209 }
  173. <a name="l00210"></a>00210
  174. <a name="l00227"></a>00227
  175. <a name="l00228"></a>00228
  176. <a name="l00229"></a>00229 template &lt;int NumBits&gt;
  177. <a name="l00230"></a><a class="code" href="g_i_l_0052.html">00230</a> class packed_channel_value {
  178. <a name="l00231"></a>00231 static const std::size_t num_values = 1&lt;&lt;NumBits;
  179. <a name="l00232"></a>00232 public:
  180. <a name="l00233"></a>00233 typedef typename detail::min_fast_uint&lt;NumBits&gt;::type integer_t;
  181. <a name="l00234"></a>00234
  182. <a name="l00235"></a>00235 typedef packed_channel_value value_type;
  183. <a name="l00236"></a>00236 typedef value_type&amp; reference;
  184. <a name="l00237"></a>00237 typedef const value_type&amp; const_reference;
  185. <a name="l00238"></a>00238 typedef value_type* pointer;
  186. <a name="l00239"></a>00239 typedef const value_type* const_pointer;
  187. <a name="l00240"></a>00240
  188. <a name="l00241"></a>00241 static value_type min_value() { return value_type(0); }
  189. <a name="l00242"></a>00242 static value_type max_value() { return value_type(num_values-1); }
  190. <a name="l00243"></a>00243 BOOST_STATIC_CONSTANT(bool, is_mutable=true);
  191. <a name="l00244"></a>00244
  192. <a name="l00245"></a>00245 packed_channel_value() {}
  193. <a name="l00246"></a>00246 packed_channel_value(integer_t v) : _value(v % num_values) {}
  194. <a name="l00247"></a>00247 packed_channel_value(const packed_channel_value&amp; v) : _value(v._value) {}
  195. <a name="l00248"></a>00248 template &lt;typename Scalar&gt; packed_channel_value(Scalar v) : _value(integer_t(v) % num_values) {} <span class="comment">// suppress GCC implicit conversion warnings in channel regression file </span>
  196. <a name="l00249"></a>00249
  197. <a name="l00250"></a>00250 operator integer_t() const { return _value; }
  198. <a name="l00251"></a>00251 private:
  199. <a name="l00252"></a>00252 integer_t _value;
  200. <a name="l00253"></a>00253 };
  201. <a name="l00254"></a>00254
  202. <a name="l00255"></a>00255 namespace detail {
  203. <a name="l00256"></a>00256
  204. <a name="l00257"></a>00257 template &lt;std::size_t K&gt;
  205. <a name="l00258"></a>00258 struct static_copy_bytes {
  206. <a name="l00259"></a>00259 void operator()(const unsigned char* from, unsigned char* to) const {
  207. <a name="l00260"></a>00260 *to = *from;
  208. <a name="l00261"></a>00261 static_copy_bytes&lt;K-1&gt;()(++from,++to);
  209. <a name="l00262"></a>00262 }
  210. <a name="l00263"></a>00263 };
  211. <a name="l00264"></a>00264
  212. <a name="l00265"></a>00265 template &lt;&gt;
  213. <a name="l00266"></a>00266 struct static_copy_bytes&lt;0&gt; {
  214. <a name="l00267"></a>00267 void operator()(const unsigned char* , unsigned char*) const {}
  215. <a name="l00268"></a>00268 };
  216. <a name="l00269"></a>00269
  217. <a name="l00270"></a>00270 template &lt;typename Derived, typename BitField, int NumBits, bool Mutable&gt;
  218. <a name="l00271"></a>00271 class packed_channel_reference_base {
  219. <a name="l00272"></a>00272 protected:
  220. <a name="l00273"></a>00273 typedef typename mpl::if_c&lt;Mutable,void*,const void*&gt;::type data_ptr_t;
  221. <a name="l00274"></a>00274 public:
  222. <a name="l00275"></a>00275 data_ptr_t _data_ptr; <span class="comment">// void* pointer to the first byte of the bit range</span>
  223. <a name="l00276"></a>00276
  224. <a name="l00277"></a>00277 typedef packed_channel_value&lt;NumBits&gt; value_type;
  225. <a name="l00278"></a>00278 typedef const Derived reference;
  226. <a name="l00279"></a>00279 typedef value_type* pointer;
  227. <a name="l00280"></a>00280 typedef const value_type* const_pointer;
  228. <a name="l00281"></a>00281 BOOST_STATIC_CONSTANT(int, num_bits=NumBits);
  229. <a name="l00282"></a>00282 BOOST_STATIC_CONSTANT(bool, is_mutable=Mutable);
  230. <a name="l00283"></a>00283
  231. <a name="l00284"></a>00284 static value_type min_value() { return channel_traits&lt;value_type&gt;::min_value(); }
  232. <a name="l00285"></a>00285 static value_type max_value() { return channel_traits&lt;value_type&gt;::max_value(); }
  233. <a name="l00286"></a>00286
  234. <a name="l00287"></a>00287 typedef BitField bitfield_t;
  235. <a name="l00288"></a>00288 typedef typename value_type::integer_t integer_t;
  236. <a name="l00289"></a>00289
  237. <a name="l00290"></a>00290 packed_channel_reference_base(data_ptr_t data_ptr) : _data_ptr(data_ptr) {}
  238. <a name="l00291"></a>00291 packed_channel_reference_base(const packed_channel_reference_base&amp; ref) : _data_ptr(ref._data_ptr) {}
  239. <a name="l00292"></a>00292 const Derived&amp; operator=(integer_t v) const { set(v); return derived(); }
  240. <a name="l00293"></a>00293
  241. <a name="l00294"></a>00294 const Derived&amp; operator++() const { set(get()+1); return derived(); }
  242. <a name="l00295"></a>00295 const Derived&amp; operator--() const { set(get()-1); return derived(); }
  243. <a name="l00296"></a>00296
  244. <a name="l00297"></a>00297 Derived operator++(int) const { Derived tmp=derived(); this-&gt;operator++(); return tmp; }
  245. <a name="l00298"></a>00298 Derived operator--(int) const { Derived tmp=derived(); this-&gt;operator--(); return tmp; }
  246. <a name="l00299"></a>00299
  247. <a name="l00300"></a>00300 template &lt;typename Scalar2&gt; const Derived&amp; operator+=(Scalar2 v) const { set(get()+v); return derived(); }
  248. <a name="l00301"></a>00301 template &lt;typename Scalar2&gt; const Derived&amp; operator-=(Scalar2 v) const { set(get()-v); return derived(); }
  249. <a name="l00302"></a>00302 template &lt;typename Scalar2&gt; const Derived&amp; operator*=(Scalar2 v) const { set(get()*v); return derived(); }
  250. <a name="l00303"></a>00303 template &lt;typename Scalar2&gt; const Derived&amp; operator/=(Scalar2 v) const { set(get()/v); return derived(); }
  251. <a name="l00304"></a>00304
  252. <a name="l00305"></a>00305 operator integer_t() const { return get(); }
  253. <a name="l00306"></a>00306 data_ptr_t operator &amp;() const {return _data_ptr;}
  254. <a name="l00307"></a>00307 protected:
  255. <a name="l00308"></a>00308 static const integer_t max_val = (1&lt;&lt;NumBits) - 1;
  256. <a name="l00309"></a>00309
  257. <a name="l00310"></a>00310 #ifdef GIL_NONWORD_POINTER_ALIGNMENT_SUPPORTED
  258. <a name="l00311"></a>00311 const bitfield_t&amp; get_data() const { return *static_cast&lt;const bitfield_t*&gt;(_data_ptr); }
  259. <a name="l00312"></a>00312 void set_data(const bitfield_t&amp; val) const { *static_cast&lt; bitfield_t*&gt;(_data_ptr) = val; }
  260. <a name="l00313"></a>00313 #else
  261. <a name="l00314"></a>00314 bitfield_t get_data() const {
  262. <a name="l00315"></a>00315 bitfield_t ret;
  263. <a name="l00316"></a>00316 static_copy_bytes&lt;sizeof(bitfield_t) &gt;()(gil_reinterpret_cast_c&lt;const unsigned char*&gt;(_data_ptr),gil_reinterpret_cast&lt;unsigned char*&gt;(&amp;ret));
  264. <a name="l00317"></a>00317 return ret;
  265. <a name="l00318"></a>00318 }
  266. <a name="l00319"></a>00319 void set_data(const bitfield_t&amp; val) const {
  267. <a name="l00320"></a>00320 static_copy_bytes&lt;sizeof(bitfield_t) &gt;()(gil_reinterpret_cast_c&lt;const unsigned char*&gt;(&amp;val),gil_reinterpret_cast&lt;unsigned char*&gt;(_data_ptr));
  268. <a name="l00321"></a>00321 }
  269. <a name="l00322"></a>00322 #endif
  270. <a name="l00323"></a>00323
  271. <a name="l00324"></a>00324 private:
  272. <a name="l00325"></a>00325 void set(integer_t value) const { <span class="comment">// can this be done faster??</span>
  273. <a name="l00326"></a>00326 const integer_t num_values = max_val+1;
  274. <a name="l00327"></a>00327 this-&gt;derived().set_unsafe(((value % num_values) + num_values) % num_values);
  275. <a name="l00328"></a>00328 }
  276. <a name="l00329"></a>00329 integer_t get() const { return derived().get(); }
  277. <a name="l00330"></a>00330 const Derived&amp; derived() const { return static_cast&lt;const Derived&amp;&gt;(*this); }
  278. <a name="l00331"></a>00331 };
  279. <a name="l00332"></a>00332 } <span class="comment">// namespace detail</span>
  280. <a name="l00333"></a>00333
  281. <a name="l00350"></a>00350 template &lt;typename BitField, <span class="comment">// A type that holds the bits of the pixel from which the channel is referenced. Typically an integral type, like boost::uint16_t</span>
  282. <a name="l00351"></a>00351 int FirstBit, int NumBits,<span class="comment">// Defines the sequence of bits in the data value that contain the channel </span>
  283. <a name="l00352"></a>00352 bool Mutable&gt; <span class="comment">// true if the reference is mutable </span>
  284. <a name="l00353"></a>00353 class packed_channel_reference;
  285. <a name="l00354"></a>00354
  286. <a name="l00355"></a>00355 template &lt;typename BitField, <span class="comment">// A type that holds the bits of the pixel from which the channel is referenced. Typically an integral type, like boost::uint16_t</span>
  287. <a name="l00356"></a>00356 int NumBits, <span class="comment">// Defines the sequence of bits in the data value that contain the channel </span>
  288. <a name="l00357"></a>00357 bool Mutable&gt; <span class="comment">// true if the reference is mutable </span>
  289. <a name="l00358"></a>00358 class packed_dynamic_channel_reference;
  290. <a name="l00359"></a>00359
  291. <a name="l00362"></a>00362 template &lt;typename BitField, int FirstBit, int NumBits&gt;
  292. <a name="l00363"></a><a class="code" href="g_i_l_0048.html">00363</a> class packed_channel_reference&lt;BitField,FirstBit,NumBits,false&gt;
  293. <a name="l00364"></a>00364 : public detail::packed_channel_reference_base&lt;packed_channel_reference&lt;BitField,FirstBit,NumBits,false&gt;,BitField,NumBits,false&gt; {
  294. <a name="l00365"></a>00365 typedef detail::packed_channel_reference_base&lt;packed_channel_reference&lt;BitField,FirstBit,NumBits,false&gt;,BitField,NumBits,false&gt; parent_t;
  295. <a name="l00366"></a>00366 friend class packed_channel_reference&lt;BitField,FirstBit,NumBits,true&gt;;
  296. <a name="l00367"></a>00367
  297. <a name="l00368"></a>00368 static const BitField channel_mask = parent_t::max_val&lt;&lt;FirstBit;
  298. <a name="l00369"></a>00369 void operator=(const packed_channel_reference&amp;);
  299. <a name="l00370"></a>00370 public:
  300. <a name="l00371"></a>00371 typedef const packed_channel_reference&lt;BitField,FirstBit,NumBits,false&gt; const_reference;
  301. <a name="l00372"></a>00372 typedef const packed_channel_reference&lt;BitField,FirstBit,NumBits,true&gt; mutable_reference;
  302. <a name="l00373"></a>00373 typedef typename parent_t::integer_t integer_t;
  303. <a name="l00374"></a>00374
  304. <a name="l00375"></a>00375 explicit packed_channel_reference(const void* data_ptr) : parent_t(data_ptr) {}
  305. <a name="l00376"></a>00376 packed_channel_reference(const packed_channel_reference&amp; ref) : parent_t(ref._data_ptr) {}
  306. <a name="l00377"></a>00377 packed_channel_reference(const mutable_reference&amp; ref) : parent_t(ref._data_ptr) {}
  307. <a name="l00378"></a>00378
  308. <a name="l00379"></a>00379 unsigned first_bit() const { return FirstBit; }
  309. <a name="l00380"></a>00380
  310. <a name="l00381"></a>00381 integer_t get() const { return integer_t((this-&gt;get_data()&amp;channel_mask) &gt;&gt; FirstBit); }
  311. <a name="l00382"></a>00382 };
  312. <a name="l00383"></a>00383
  313. <a name="l00386"></a>00386 template &lt;typename BitField, int FirstBit, int NumBits&gt;
  314. <a name="l00387"></a><a class="code" href="g_i_l_0050.html">00387</a> class packed_channel_reference&lt;BitField,FirstBit,NumBits,true&gt;
  315. <a name="l00388"></a>00388 : public detail::packed_channel_reference_base&lt;packed_channel_reference&lt;BitField,FirstBit,NumBits,true&gt;,BitField,NumBits,true&gt; {
  316. <a name="l00389"></a>00389 typedef detail::packed_channel_reference_base&lt;packed_channel_reference&lt;BitField,FirstBit,NumBits,true&gt;,BitField,NumBits,true&gt; parent_t;
  317. <a name="l00390"></a>00390 friend class packed_channel_reference&lt;BitField,FirstBit,NumBits,false&gt;;
  318. <a name="l00391"></a>00391
  319. <a name="l00392"></a>00392 static const BitField channel_mask = parent_t::max_val&lt;&lt;FirstBit;
  320. <a name="l00393"></a>00393 public:
  321. <a name="l00394"></a>00394 typedef const packed_channel_reference&lt;BitField,FirstBit,NumBits,false&gt; const_reference;
  322. <a name="l00395"></a>00395 typedef const packed_channel_reference&lt;BitField,FirstBit,NumBits,true&gt; mutable_reference;
  323. <a name="l00396"></a>00396 typedef typename parent_t::integer_t integer_t;
  324. <a name="l00397"></a>00397
  325. <a name="l00398"></a>00398 explicit packed_channel_reference(void* data_ptr) : parent_t(data_ptr) {}
  326. <a name="l00399"></a>00399 packed_channel_reference(const packed_channel_reference&amp; ref) : parent_t(ref._data_ptr) {}
  327. <a name="l00400"></a>00400
  328. <a name="l00401"></a>00401 const packed_channel_reference&amp; operator=(integer_t value) const { assert(value&lt;=parent_t::max_val); set_unsafe(value); return *this; }
  329. <a name="l00402"></a>00402 const packed_channel_reference&amp; operator=(const mutable_reference&amp; ref) const { set_from_reference(ref.get_data()); return *this; }
  330. <a name="l00403"></a>00403 const packed_channel_reference&amp; operator=(const const_reference&amp; ref) const { set_from_reference(ref.get_data()); return *this; }
  331. <a name="l00404"></a>00404
  332. <a name="l00405"></a>00405 template &lt;bool Mutable1&gt;
  333. <a name="l00406"></a>00406 const packed_channel_reference&amp; operator=(const packed_dynamic_channel_reference&lt;BitField,NumBits,Mutable1&gt;&amp; ref) const { set_unsafe(ref.get()); return *this; }
  334. <a name="l00407"></a>00407
  335. <a name="l00408"></a>00408 unsigned first_bit() const { return FirstBit; }
  336. <a name="l00409"></a>00409
  337. <a name="l00410"></a>00410 integer_t get() const { return integer_t((this-&gt;get_data()&amp;channel_mask) &gt;&gt; FirstBit); }
  338. <a name="l00411"></a>00411 void set_unsafe(integer_t value) const { this-&gt;set_data((this-&gt;get_data() &amp; ~channel_mask) | (value&lt;&lt;FirstBit)); }
  339. <a name="l00412"></a>00412 private:
  340. <a name="l00413"></a>00413 void set_from_reference(const BitField&amp; other_bits) const { this-&gt;set_data((this-&gt;get_data() &amp; ~channel_mask) | (other_bits &amp; channel_mask)); }
  341. <a name="l00414"></a>00414 };
  342. <a name="l00415"></a>00415
  343. <a name="l00416"></a>00416 } } <span class="comment">// namespace boost::gil</span>
  344. <a name="l00417"></a>00417
  345. <a name="l00418"></a>00418 namespace std {
  346. <a name="l00419"></a>00419 <span class="comment">// We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.</span>
  347. <a name="l00420"></a>00420 <span class="comment">// swap with 'left bias': </span>
  348. <a name="l00421"></a>00421 <span class="comment">// - swap between proxy and anything</span>
  349. <a name="l00422"></a>00422 <span class="comment">// - swap between value type and proxy</span>
  350. <a name="l00423"></a>00423 <span class="comment">// - swap between proxy and proxy</span>
  351. <a name="l00424"></a>00424
  352. <a name="l00427"></a>00427 template &lt;typename BF, int FB, int NB, bool M, typename R&gt; inline
  353. <a name="l00428"></a><a class="code" href="g_i_l_0176.html#g80e89636c0d110249fedf6ea14a477f7">00428</a> void swap(const boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt; x, R&amp; y) {
  354. <a name="l00429"></a>00429 boost::gil::swap_proxy&lt;typename boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt;::value_type&gt;(x,y);
  355. <a name="l00430"></a>00430 }
  356. <a name="l00431"></a>00431
  357. <a name="l00432"></a>00432
  358. <a name="l00435"></a>00435 template &lt;typename BF, int FB, int NB, bool M&gt; inline
  359. <a name="l00436"></a><a class="code" href="g_i_l_0176.html#g9541bc0769202d632e1b869e1cf217e0">00436</a> void swap(typename boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt;::value_type&amp; x, const boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt; y) {
  360. <a name="l00437"></a>00437 boost::gil::swap_proxy&lt;typename boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt;::value_type&gt;(x,y);
  361. <a name="l00438"></a>00438 }
  362. <a name="l00439"></a>00439
  363. <a name="l00440"></a>00440
  364. <a name="l00443"></a>00443 template &lt;typename BF, int FB, int NB, bool M&gt; inline
  365. <a name="l00444"></a><a class="code" href="g_i_l_0176.html#g20a753330c605ac59c89aa784ab89eca">00444</a> void swap(const boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt; x, const boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt; y) {
  366. <a name="l00445"></a>00445 boost::gil::swap_proxy&lt;typename boost::gil::packed_channel_reference&lt;BF,FB,NB,M&gt;::value_type&gt;(x,y);
  367. <a name="l00446"></a>00446 }
  368. <a name="l00447"></a>00447 } <span class="comment">// namespace std</span>
  369. <a name="l00448"></a>00448
  370. <a name="l00449"></a>00449 namespace boost { namespace gil {
  371. <a name="l00450"></a>00450
  372. <a name="l00468"></a>00468
  373. <a name="l00469"></a>00469
  374. <a name="l00470"></a>00470
  375. <a name="l00471"></a>00471 template &lt;typename BitField, int NumBits&gt;
  376. <a name="l00472"></a><a class="code" href="g_i_l_0054.html">00472</a> class packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt;
  377. <a name="l00473"></a>00473 : public detail::packed_channel_reference_base&lt;packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt;,BitField,NumBits,false&gt; {
  378. <a name="l00474"></a>00474 typedef detail::packed_channel_reference_base&lt;packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt;,BitField,NumBits,false&gt; parent_t;
  379. <a name="l00475"></a>00475 friend class packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt;;
  380. <a name="l00476"></a>00476
  381. <a name="l00477"></a>00477 unsigned _first_bit; <span class="comment">// 0..7</span>
  382. <a name="l00478"></a>00478
  383. <a name="l00479"></a>00479 void operator=(const packed_dynamic_channel_reference&amp;);
  384. <a name="l00480"></a>00480 public:
  385. <a name="l00481"></a>00481 typedef const packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt; const_reference;
  386. <a name="l00482"></a>00482 typedef const packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt; mutable_reference;
  387. <a name="l00483"></a>00483 typedef typename parent_t::integer_t integer_t;
  388. <a name="l00484"></a>00484
  389. <a name="l00485"></a>00485 packed_dynamic_channel_reference(const void* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {}
  390. <a name="l00486"></a>00486 packed_dynamic_channel_reference(const const_reference&amp; ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {}
  391. <a name="l00487"></a>00487 packed_dynamic_channel_reference(const mutable_reference&amp; ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {}
  392. <a name="l00488"></a>00488
  393. <a name="l00489"></a>00489 unsigned first_bit() const { return _first_bit; }
  394. <a name="l00490"></a>00490
  395. <a name="l00491"></a>00491 integer_t get() const {
  396. <a name="l00492"></a>00492 const BitField channel_mask = parent_t::max_val&lt;&lt;_first_bit;
  397. <a name="l00493"></a>00493 return (this-&gt;get_data()&amp;channel_mask) &gt;&gt; _first_bit;
  398. <a name="l00494"></a>00494 }
  399. <a name="l00495"></a>00495 };
  400. <a name="l00496"></a>00496
  401. <a name="l00500"></a>00500 template &lt;typename BitField, int NumBits&gt;
  402. <a name="l00501"></a><a class="code" href="g_i_l_0056.html">00501</a> class packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt;
  403. <a name="l00502"></a>00502 : <span class="keyword">public</span> detail::packed_channel_reference_base&lt;packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt;,BitField,NumBits,true&gt; {
  404. <a name="l00503"></a>00503 <span class="keyword">typedef</span> detail::packed_channel_reference_base&lt;packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt;,BitField,NumBits,<span class="keyword">true</span>&gt; parent_t;
  405. <a name="l00504"></a>00504 <span class="keyword">friend</span> <span class="keyword">class </span>packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt;;
  406. <a name="l00505"></a>00505
  407. <a name="l00506"></a>00506 <span class="keywordtype">unsigned</span> _first_bit;
  408. <a name="l00507"></a>00507
  409. <a name="l00508"></a>00508 <span class="keyword">public</span>:
  410. <a name="l00509"></a>00509 <span class="keyword">typedef</span> <span class="keyword">const</span> packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt; <a class="code" href="g_i_l_0054.html" title="Models a constant subbyte channel reference whose bit offset is a runtime parameter...">const_reference</a>;
  411. <a name="l00510"></a>00510 <span class="keyword">typedef</span> <span class="keyword">const</span> packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt; <a class="code" href="g_i_l_0056.html" title="Models a mutable subbyte channel reference whose bit offset is a runtime parameter...">mutable_reference</a>;
  412. <a name="l00511"></a>00511 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::integer_t integer_t;
  413. <a name="l00512"></a>00512
  414. <a name="l00513"></a>00513 packed_dynamic_channel_reference(<span class="keywordtype">void</span>* data_ptr, <span class="keywordtype">unsigned</span> first_bit) : parent_t(data_ptr), _first_bit(first_bit) {}
  415. <a name="l00514"></a>00514 packed_dynamic_channel_reference(<span class="keyword">const</span> packed_dynamic_channel_reference&amp; ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {}
  416. <a name="l00515"></a>00515
  417. <a name="l00516"></a>00516 <span class="keyword">const</span> packed_dynamic_channel_reference&amp; operator=(integer_t value)<span class="keyword"> const </span>{ assert(value&lt;=parent_t::max_val); set_unsafe(value); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  418. <a name="l00517"></a>00517 <span class="keyword">const</span> packed_dynamic_channel_reference&amp; operator=(<span class="keyword">const</span> <a class="code" href="g_i_l_0056.html" title="Models a mutable subbyte channel reference whose bit offset is a runtime parameter...">mutable_reference</a>&amp; ref)<span class="keyword"> const </span>{ set_unsafe(ref.<a class="code" href="g_i_l_0056.html#acb80df4b55e284a1e5cc442604aedea">get</a>()); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  419. <a name="l00518"></a>00518 <span class="keyword">const</span> packed_dynamic_channel_reference&amp; operator=(<span class="keyword">const</span> <a class="code" href="g_i_l_0054.html" title="Models a constant subbyte channel reference whose bit offset is a runtime parameter...">const_reference</a>&amp; ref)<span class="keyword"> const </span>{ set_unsafe(ref.<a class="code" href="g_i_l_0054.html#acb80df4b55e284a1e5cc442604aedea">get</a>()); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  420. <a name="l00519"></a>00519
  421. <a name="l00520"></a>00520 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField1, <span class="keywordtype">int</span> FirstBit1, <span class="keywordtype">bool</span> Mutable1&gt;
  422. <a name="l00521"></a>00521 <span class="keyword">const</span> packed_dynamic_channel_reference&amp; operator=(<span class="keyword">const</span> packed_channel_reference&lt;BitField1, FirstBit1, NumBits, Mutable1&gt;&amp; ref)<span class="keyword"> const </span>
  423. <a name="l00522"></a>00522 <span class="keyword"> </span>{ set_unsafe(ref.get()); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
  424. <a name="l00523"></a>00523
  425. <a name="l00524"></a>00524 <span class="keywordtype">unsigned</span> first_bit()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _first_bit; }
  426. <a name="l00525"></a>00525
  427. <a name="l00526"></a>00526 integer_t <span class="keyword">get</span>() <span class="keyword">const</span> {
  428. <a name="l00527"></a>00527 <span class="keyword">const</span> BitField channel_mask = parent_t::max_val&lt;&lt;_first_bit;
  429. <a name="l00528"></a>00528 <span class="keywordflow">return</span> (this-&gt;get_data()&amp;channel_mask) &gt;&gt; _first_bit;
  430. <a name="l00529"></a>00529 }
  431. <a name="l00530"></a>00530 <span class="keywordtype">void</span> set_unsafe(integer_t value)<span class="keyword"> const </span>{
  432. <a name="l00531"></a>00531 <span class="keyword">const</span> BitField channel_mask = parent_t::max_val&lt;&lt;_first_bit;
  433. <a name="l00532"></a>00532 this-&gt;set_data((this-&gt;get_data() &amp; ~channel_mask) | value&lt;&lt;_first_bit);
  434. <a name="l00533"></a>00533 }
  435. <a name="l00534"></a>00534 };
  436. <a name="l00535"></a>00535 } } <span class="comment">// namespace boost::gil</span>
  437. <a name="l00536"></a>00536
  438. <a name="l00537"></a>00537 <span class="keyword">namespace </span>std {
  439. <a name="l00538"></a>00538 <span class="comment">// We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.</span>
  440. <a name="l00539"></a>00539 <span class="comment">// swap with 'left bias': </span>
  441. <a name="l00540"></a>00540 <span class="comment">// - swap between proxy and anything</span>
  442. <a name="l00541"></a>00541 <span class="comment">// - swap between value type and proxy</span>
  443. <a name="l00542"></a>00542 <span class="comment">// - swap between proxy and proxy</span>
  444. <a name="l00543"></a>00543
  445. <a name="l00544"></a>00544
  446. <a name="l00547"></a>00547 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BF, <span class="keywordtype">int</span> NB, <span class="keywordtype">bool</span> M, <span class="keyword">typename</span> R&gt; <span class="keyword">inline</span>
  447. <a name="l00548"></a><a class="code" href="g_i_l_0175.html#g45affd7c290ef9a24ac79edbd6f9ca7f">00548</a> <span class="keywordtype">void</span> swap(<span class="keyword">const</span> boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt; x, R&amp; y) {
  448. <a name="l00549"></a>00549 boost::gil::swap_proxy&lt;typename boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt;::value_type&gt;(x,y);
  449. <a name="l00550"></a>00550 }
  450. <a name="l00551"></a>00551
  451. <a name="l00552"></a>00552
  452. <a name="l00555"></a>00555 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BF, <span class="keywordtype">int</span> NB, <span class="keywordtype">bool</span> M&gt; <span class="keyword">inline</span>
  453. <a name="l00556"></a><a class="code" href="g_i_l_0175.html#gc25302c1ae9ad02851565565fd95e03e">00556</a> <span class="keywordtype">void</span> swap(<span class="keyword">typename</span> boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt;::value_type&amp; x, <span class="keyword">const</span> boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt; y) {
  454. <a name="l00557"></a>00557 boost::gil::swap_proxy&lt;typename boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt;::value_type&gt;(x,y);
  455. <a name="l00558"></a>00558 }
  456. <a name="l00559"></a>00559
  457. <a name="l00560"></a>00560
  458. <a name="l00563"></a>00563 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BF, <span class="keywordtype">int</span> NB, <span class="keywordtype">bool</span> M&gt; <span class="keyword">inline</span>
  459. <a name="l00564"></a><a class="code" href="g_i_l_0175.html#gd5c9bdabc34d65825f30d2ae71cb07dc">00564</a> <span class="keywordtype">void</span> swap(<span class="keyword">const</span> boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt; x, <span class="keyword">const</span> boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt; y) {
  460. <a name="l00565"></a>00565 boost::gil::swap_proxy&lt;typename boost::gil::packed_dynamic_channel_reference&lt;BF,NB,M&gt;::value_type&gt;(x,y);
  461. <a name="l00566"></a>00566 }
  462. <a name="l00567"></a>00567 } <span class="comment">// namespace std</span>
  463. <a name="l00568"></a>00568
  464. <a name="l00569"></a>00569 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil {
  465. <a name="l00575"></a>00575
  466. <a name="l00579"></a>00579
  467. <a name="l00581"></a>00581 <span class="keyword">typedef</span> uint8_t bits8;
  468. <a name="l00582"></a>00582
  469. <a name="l00586"></a>00586
  470. <a name="l00588"></a>00588 <span class="keyword">typedef</span> uint16_t bits16;
  471. <a name="l00589"></a>00589
  472. <a name="l00593"></a>00593
  473. <a name="l00595"></a>00595 <span class="keyword">typedef</span> uint32_t bits32;
  474. <a name="l00596"></a>00596
  475. <a name="l00600"></a>00600
  476. <a name="l00602"></a>00602 <span class="keyword">typedef</span> int8_t bits8s;
  477. <a name="l00603"></a>00603
  478. <a name="l00607"></a>00607
  479. <a name="l00609"></a>00609 <span class="keyword">typedef</span> int16_t bits16s;
  480. <a name="l00610"></a>00610
  481. <a name="l00614"></a>00614
  482. <a name="l00616"></a>00616 <span class="keyword">typedef</span> int32_t bits32s;
  483. <a name="l00617"></a>00617
  484. <a name="l00621"></a>00621
  485. <a name="l00623"></a>00623 <span class="keyword">typedef</span> scoped_channel_value&lt;float,float_zero,float_one&gt; bits32f;
  486. <a name="l00624"></a>00624
  487. <a name="l00625"></a>00625 } } <span class="comment">// namespace boost::gil</span>
  488. <a name="l00626"></a>00626
  489. <a name="l00627"></a>00627 <span class="keyword">namespace </span>boost {
  490. <a name="l00628"></a>00628
  491. <a name="l00629"></a>00629 <span class="keyword">template</span> &lt;<span class="keywordtype">int</span> NumBits&gt;
  492. <a name="l00630"></a>00630 <span class="keyword">struct </span>is_integral&lt;gil::packed_channel_value&lt;NumBits&gt; &gt; : <span class="keyword">public</span> mpl::true_ {};
  493. <a name="l00631"></a>00631
  494. <a name="l00632"></a>00632 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField, <span class="keywordtype">int</span> FirstBit, <span class="keywordtype">int</span> NumBits, <span class="keywordtype">bool</span> IsMutable&gt;
  495. <a name="l00633"></a>00633 <span class="keyword">struct </span>is_integral&lt;gil::packed_channel_reference&lt;BitField,FirstBit,NumBits,IsMutable&gt; &gt; : <span class="keyword">public</span> mpl::true_ {};
  496. <a name="l00634"></a>00634
  497. <a name="l00635"></a>00635 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField, <span class="keywordtype">int</span> NumBits, <span class="keywordtype">bool</span> IsMutable&gt;
  498. <a name="l00636"></a>00636 <span class="keyword">struct </span>is_integral&lt;gil::packed_dynamic_channel_reference&lt;BitField,NumBits,IsMutable&gt; &gt; : <span class="keyword">public</span> mpl::true_ {};
  499. <a name="l00637"></a>00637
  500. <a name="l00638"></a>00638 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BaseChannelValue, <span class="keyword">typename</span> MinVal, <span class="keyword">typename</span> MaxVal&gt;
  501. <a name="l00639"></a>00639 <span class="keyword">struct </span>is_integral&lt;gil::scoped_channel_value&lt;BaseChannelValue,MinVal,MaxVal&gt; &gt; : <span class="keyword">public</span> is_integral&lt;BaseChannelValue&gt; {};
  502. <a name="l00640"></a>00640
  503. <a name="l00641"></a>00641 }
  504. <a name="l00642"></a>00642
  505. <a name="l00643"></a>00643 <span class="preprocessor">#endif</span>
  506. </pre></div></div>
  507. <hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:13 2009 for Generic Image Library by&nbsp;
  508. <a href="http://www.doxygen.org/index.html">
  509. <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
  510. </body>
  511. </html>