blob: 8a8aafce5a0d8c2459082e02ceaf7c78676ecec1 [file] [log] [blame]
<!-- Copyright 2008 Lubomir Bourdev and Hailin Jin
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
-->
<!--
Copyright 2005-2007 Adobe Systems Incorporated
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
or a copy at http://stlab.adobe.com/licenses.html)
Some files are held under additional license.
Please see "http://stlab.adobe.com/licenses.html" for more information.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<TITLE>Generic Image Library: bit_aligned_pixel_reference.hpp Source File</TITLE>
<META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/>
<LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr>
<td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'>
<div class="qindex"><a class="qindex" href="index.html">Modules</a>
| <a class="qindex" href="classes.html">Alphabetical List</a>
| <a class="qindex" href="annotated.html">Class List</a>
| <a class="qindex" href="dirs.html">Directories</a>
| <a class="qindex" href="files.html">File List</a>
| <a class="qindex" href="../index.html">GIL Home Page</a>
</div>
<!-- End Header -->
<!-- Generated by Doxygen 1.5.6 -->
<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>
</div>
<div class="contents">
<h1>bit_aligned_pixel_reference.hpp</h1><a href="g_i_l_0013.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span>
<a name="l00003"></a>00003 <span class="comment"> </span>
<a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span>
<a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
<a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment"> See http://stlab.adobe.com/gil for most recent version including documentation.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010
<a name="l00011"></a>00011 <span class="comment">/*************************************************************************************************/</span>
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="preprocessor">#ifndef GIL_BIT_ALIGNED_PIXEL_REFERENCE_HPP</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define GIL_BIT_ALIGNED_PIXEL_REFERENCE_HPP</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span>
<a name="l00024"></a>00024
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;functional&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;boost/mpl/accumulate.hpp&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;boost/mpl/at.hpp&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;boost/mpl/bool.hpp&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;boost/mpl/if.hpp&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;boost/mpl/plus.hpp&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;boost/mpl/push_back.hpp&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;boost/mpl/vector.hpp&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="g_i_l_0094.html" title="GIL configuration file.">gil_config.hpp</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="pixel_8hpp.html" title="pixel class and related utilities">pixel.hpp</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="channel_8hpp.html" title="Channel utilities.">channel.hpp</a>"</span>
<a name="l00036"></a>00036
<a name="l00037"></a>00037 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil {
<a name="l00038"></a>00038
<a name="l00040"></a>00040 <span class="comment">// bit_range</span>
<a name="l00041"></a>00041 <span class="comment">//</span>
<a name="l00042"></a>00042 <span class="comment">// Represents a range of bits that can span multiple consecutive bytes. The range has a size fixed at compile time, but the offset is specified at run time.</span>
<a name="l00044"></a>00044 <span class="comment"></span>
<a name="l00045"></a>00045 <span class="keyword">template</span> &lt;<span class="keywordtype">int</span> RangeSize, <span class="keywordtype">bool</span> Mutable&gt;
<a name="l00046"></a>00046 <span class="keyword">class </span>bit_range {
<a name="l00047"></a>00047 <span class="keyword">public</span>:
<a name="l00048"></a>00048 <span class="keyword">typedef</span> <span class="keyword">typename</span> mpl::if_c&lt;Mutable,unsigned char,const unsigned char&gt;::type byte_t;
<a name="l00049"></a>00049 <span class="keyword">typedef</span> std::ptrdiff_t difference_type;
<a name="l00050"></a>00050 <span class="keyword">template</span> &lt;<span class="keywordtype">int</span> RS, <span class="keywordtype">bool</span> M&gt; <span class="keyword">friend</span> <span class="keyword">class </span>bit_range;
<a name="l00051"></a>00051 <span class="keyword">private</span>:
<a name="l00052"></a>00052 byte_t* _current_byte; <span class="comment">// the starting byte of the bit range</span>
<a name="l00053"></a>00053 <span class="keywordtype">int</span> _bit_offset; <span class="comment">// offset from the beginning of the current byte. 0&lt;=_bit_offset&lt;=7</span>
<a name="l00054"></a>00054
<a name="l00055"></a>00055 <span class="keyword">public</span>:
<a name="l00056"></a>00056 bit_range() : _current_byte(NULL), _bit_offset(0) {}
<a name="l00057"></a>00057 bit_range(byte_t* current_byte, <span class="keywordtype">int</span> bit_offset) : _current_byte(current_byte), _bit_offset(bit_offset) { assert(bit_offset&gt;=0 &amp;&amp; bit_offset&lt;8); }
<a name="l00058"></a>00058
<a name="l00059"></a>00059 bit_range(<span class="keyword">const</span> bit_range&amp; br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
<a name="l00060"></a>00060 <span class="keyword">template</span> &lt;<span class="keywordtype">bool</span> M&gt; bit_range(<span class="keyword">const</span> bit_range&lt;RangeSize,M&gt;&amp; br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
<a name="l00061"></a>00061
<a name="l00062"></a>00062 bit_range&amp; operator=(<span class="keyword">const</span> bit_range&amp; br) { _current_byte = br._current_byte; _bit_offset=br._bit_offset; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
<a name="l00063"></a>00063 <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> bit_range&amp; br)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _current_byte==br._current_byte &amp;&amp; _bit_offset==br._bit_offset; }
<a name="l00064"></a>00064
<a name="l00065"></a>00065 bit_range&amp; operator++() {
<a name="l00066"></a>00066 _current_byte += (_bit_offset+RangeSize) / 8;
<a name="l00067"></a>00067 _bit_offset = (_bit_offset+RangeSize) % 8;
<a name="l00068"></a>00068 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 bit_range&amp; operator--() { bit_advance(-RangeSize); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
<a name="l00071"></a>00071
<a name="l00072"></a>00072 <span class="keywordtype">void</span> bit_advance(difference_type num_bits) {
<a name="l00073"></a>00073 <span class="keywordtype">int</span> new_offset = int(_bit_offset+num_bits);
<a name="l00074"></a>00074 _current_byte += new_offset / 8;
<a name="l00075"></a>00075 _bit_offset = new_offset % 8;
<a name="l00076"></a>00076 <span class="keywordflow">if</span> (_bit_offset&lt;0) {
<a name="l00077"></a>00077 _bit_offset+=8;
<a name="l00078"></a>00078 --_current_byte;
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081 difference_type bit_distance_to(<span class="keyword">const</span> bit_range&amp; b)<span class="keyword"> const </span>{
<a name="l00082"></a>00082 <span class="keywordflow">return</span> (b.current_byte() - current_byte())*8 + b.bit_offset()-bit_offset();
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084 byte_t* current_byte()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _current_byte; }
<a name="l00085"></a>00085 <span class="keywordtype">int</span> bit_offset()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _bit_offset; }
<a name="l00086"></a>00086 };
<a name="l00087"></a>00087
<a name="l00088"></a>00088
<a name="l00092"></a>00092
<a name="l00116"></a>00116
<a name="l00117"></a>00117
<a name="l00118"></a>00118 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField,
<a name="l00119"></a>00119 <span class="keyword">typename</span> ChannelBitSizes, <span class="comment">// MPL integral vector defining the number of bits for each channel. For example, for 565RGB, vector_c&lt;int,5,6,5&gt;</span>
<a name="l00120"></a>00120 <span class="keyword">typename</span> Layout,
<a name="l00121"></a>00121 <span class="keywordtype">bool</span> IsMutable&gt;
<a name="l00122"></a><a class="code" href="g_i_l_0403.html">00122</a> <span class="keyword">struct </span><a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a> {
<a name="l00123"></a>00123 BOOST_STATIC_CONSTANT(<span class="keywordtype">int</span>, bit_size = (mpl::accumulate&lt;ChannelBitSizes, mpl::int_&lt;0&gt;, mpl::plus&lt;mpl::_1, mpl::_2&gt; &gt;::type::value));
<a name="l00124"></a>00124 <span class="keyword">typedef</span> boost::gil::bit_range&lt;bit_size,IsMutable&gt; bit_range_t;
<a name="l00125"></a>00125 <span class="keyword">typedef</span> BitField bitfield_t;
<a name="l00126"></a>00126 <span class="keyword">typedef</span> <span class="keyword">typename</span> mpl::if_c&lt;IsMutable,unsigned char*,const unsigned char*&gt;::type data_ptr_t;
<a name="l00127"></a>00127
<a name="l00128"></a>00128 <span class="keyword">typedef</span> Layout layout_t;
<a name="l00129"></a>00129
<a name="l00130"></a>00130 <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="g_i_l_0597.html" title="Returns the type of a packed pixel given its bitfield type, the bit size of its channels...">packed_pixel_type&lt;bitfield_t,ChannelBitSizes,Layout&gt;::type</a> <a class="code" href="g_i_l_0595.html" title="Heterogeneous pixel value whose channel references can be constructed from the pixel...">value_type</a>;
<a name="l00131"></a>00131 <span class="keyword">typedef</span> <span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">reference</a>;
<a name="l00132"></a>00132 <span class="keyword">typedef</span> <span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference&lt;BitField,ChannelBitSizes,Layout,false&gt;</a> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">const_reference</a>;
<a name="l00133"></a>00133
<a name="l00134"></a>00134 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>, is_mutable = IsMutable);
<a name="l00135"></a>00135
<a name="l00136"></a>00136 <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>(){}
<a name="l00137"></a>00137 <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>(data_ptr_t data_ptr, <span class="keywordtype">int</span> bit_offset) : _bit_range(data_ptr, bit_offset) {}
<a name="l00138"></a>00138 <span class="keyword">explicit</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>(<span class="keyword">const</span> bit_range_t&amp; bit_range) : _bit_range(bit_range) {}
<a name="l00139"></a>00139 <span class="keyword">template</span> &lt;<span class="keywordtype">bool</span> IsMutable2&gt; <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>(<span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference&lt;BitField,ChannelBitSizes,Layout,IsMutable2&gt;</a>&amp; p) : _bit_range(p.<a class="code" href="g_i_l_0403.html#7495e83a5b66f6f3825fe94aca667c72">_bit_range</a>) {}
<a name="l00140"></a>00140
<a name="l00141"></a>00141 <span class="comment">// Grayscale references can be constructed from the channel reference</span>
<a name="l00142"></a>00142 <span class="keyword">explicit</span> bit_aligned_pixel_reference(<span class="keyword">const</span> <span class="keyword">typename</span> kth_element_type&lt;bit_aligned_pixel_reference,0&gt;::type channel0) : _bit_range(static_cast&lt;data_ptr_t&gt;(&amp;channel0), channel0.first_bit()) {
<a name="l00143"></a>00143 BOOST_STATIC_ASSERT((<a class="code" href="g_i_l_0581.html" title="Returns the number of channels of a pixel-based GIL construct.">num_channels&lt;bit_aligned_pixel_reference&gt;::value</a>==1));
<a name="l00144"></a>00144 }
<a name="l00145"></a>00145
<a name="l00146"></a>00146 <span class="comment">// Construct from another compatible pixel type</span>
<a name="l00147"></a>00147 bit_aligned_pixel_reference(<span class="keyword">const</span> bit_aligned_pixel_reference&amp; p) : _bit_range(p.<a class="code" href="g_i_l_0403.html#7495e83a5b66f6f3825fe94aca667c72">_bit_range</a>) {}
<a name="l00148"></a>00148 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BF, <span class="keyword">typename</span> CR&gt; bit_aligned_pixel_reference(<a class="code" href="g_i_l_0595.html" title="Heterogeneous pixel value whose channel references can be constructed from the pixel...">packed_pixel&lt;BF,CR,Layout&gt;</a>&amp; p) : _bit_range(static_cast&lt;data_ptr_t&gt;(&amp;at_c&lt;0&gt;(p)), at_c&lt;0&gt;(p).first_bit()) {
<a name="l00149"></a>00149 check_compatible&lt;packed_pixel&lt;BF,CR,Layout&gt; &gt;();
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151
<a name="l00152"></a>00152 <span class="keyword">const</span> bit_aligned_pixel_reference&amp; operator=(<span class="keyword">const</span> bit_aligned_pixel_reference&amp; p)<span class="keyword"> const </span>{ static_copy(p,*<span class="keyword">this</span>); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
<a name="l00153"></a>00153 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> P&gt; <span class="keyword">const</span> bit_aligned_pixel_reference&amp; operator=(<span class="keyword">const</span> P&amp; p)<span class="keyword"> const </span>{ assign(p, mpl::bool_&lt;is_pixel&lt;P&gt;::value&gt;()); <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
<a name="l00154"></a>00154
<a name="l00155"></a>00155 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> P&gt; <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> P&amp; p)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> equal(p, mpl::bool_&lt;is_pixel&lt;P&gt;::value&gt;()); }
<a name="l00156"></a>00156 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> P&gt; <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> P&amp; p)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> !(*<span class="keyword">this</span>==p); }
<a name="l00157"></a>00157
<a name="l00158"></a>00158 <span class="keyword">const</span> bit_aligned_pixel_reference* operator-&gt;()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">this</span>; }
<a name="l00159"></a>00159
<a name="l00160"></a>00160 <span class="keyword">const</span> bit_range_t&amp; bit_range()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _bit_range; }
<a name="l00161"></a>00161 <span class="keyword">private</span>:
<a name="l00162"></a>00162 <span class="keyword">mutable</span> bit_range_t _bit_range;
<a name="l00163"></a>00163 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M&gt; <span class="keyword">friend</span> <span class="keyword">struct </span>bit_aligned_pixel_reference;
<a name="l00164"></a>00164
<a name="l00165"></a>00165 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Pixel&gt; <span class="keyword">static</span> <span class="keywordtype">void</span> check_compatible() { gil_function_requires&lt;PixelsCompatibleConcept&lt;Pixel,bit_aligned_pixel_reference&gt; &gt;(); }
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Pixel&gt; <span class="keywordtype">void</span> assign(<span class="keyword">const</span> Pixel&amp; p, mpl::true_)<span class="keyword"> const </span>{ check_compatible&lt;Pixel&gt;(); static_copy(p,*<span class="keyword">this</span>); }
<a name="l00168"></a>00168 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Pixel&gt; <span class="keywordtype">bool</span> <a class="code" href="g_i_l_0214.html#g4ed3cf71cb0fbf435d1389df8567a4e5" title="std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d">equal</a>(<span class="keyword">const</span> Pixel&amp; p, mpl::true_)<span class="keyword"> const </span>{ check_compatible&lt;Pixel&gt;(); <span class="keywordflow">return</span> static_equal(*<span class="keyword">this</span>,p); }
<a name="l00169"></a>00169
<a name="l00170"></a>00170 <span class="keyword">private</span>:
<a name="l00171"></a>00171 <span class="keyword">static</span> <span class="keywordtype">void</span> check_gray() { BOOST_STATIC_ASSERT((is_same&lt;typename Layout::color_space_t, gray_t&gt;::value)); }
<a name="l00172"></a>00172 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Channel&gt; <span class="keywordtype">void</span> assign(<span class="keyword">const</span> Channel&amp; chan, mpl::false_)<span class="keyword"> const </span>{ check_gray(); at_c&lt;0&gt;(*this)=chan; }
<a name="l00173"></a>00173 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Channel&gt; <span class="keywordtype">bool</span> <a class="code" href="g_i_l_0214.html#g4ed3cf71cb0fbf435d1389df8567a4e5" title="std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d">equal</a> (<span class="keyword">const</span> Channel&amp; chan, mpl::false_)<span class="keyword"> const </span>{ check_gray(); <span class="keywordflow">return</span> at_c&lt;0&gt;(*this)==chan; }
<a name="l00174"></a>00174 };
<a name="l00175"></a>00175
<a name="l00177"></a>00177 <span class="comment">// ColorBasedConcept</span>
<a name="l00179"></a>00179 <span class="comment"></span>
<a name="l00180"></a>00180 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField, <span class="keyword">typename</span> ChannelBitSizes, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> IsMutable, <span class="keywordtype">int</span> K&gt;
<a name="l00181"></a>00181 <span class="keyword">struct </span>kth_element_type&lt;<a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>&lt;BitField,ChannelBitSizes,L,IsMutable&gt;, K&gt; {
<a name="l00182"></a>00182 <span class="keyword">public</span>:
<a name="l00183"></a>00183 <span class="keyword">typedef</span> <span class="keyword">const</span> packed_dynamic_channel_reference&lt;BitField, mpl::at_c&lt;ChannelBitSizes,K&gt;::type::value, IsMutable&gt; type;
<a name="l00184"></a>00184 };
<a name="l00185"></a>00185
<a name="l00186"></a>00186 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M, <span class="keywordtype">int</span> K&gt;
<a name="l00187"></a>00187 <span class="keyword">struct </span>kth_element_reference_type&lt;bit_aligned_pixel_reference&lt;B,C,L,M&gt;, K&gt;
<a name="l00188"></a>00188 : <span class="keyword">public</span> kth_element_type&lt;bit_aligned_pixel_reference&lt;B,C,L,M&gt;, K&gt; {};
<a name="l00189"></a>00189
<a name="l00190"></a>00190 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M, <span class="keywordtype">int</span> K&gt;
<a name="l00191"></a>00191 <span class="keyword">struct </span>kth_element_const_reference_type&lt;bit_aligned_pixel_reference&lt;B,C,L,M&gt;, K&gt;
<a name="l00192"></a>00192 : <span class="keyword">public</span> kth_element_type&lt;bit_aligned_pixel_reference&lt;B,C,L,M&gt;, K&gt; {};
<a name="l00193"></a>00193
<a name="l00194"></a>00194
<a name="l00195"></a>00195 <span class="keyword">namespace </span>detail {
<a name="l00196"></a>00196 <span class="comment">// returns sum of IntegralVector[0] ... IntegralVector[K-1]</span>
<a name="l00197"></a>00197 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> IntegralVector, <span class="keywordtype">int</span> K&gt;
<a name="l00198"></a>00198 <span class="keyword">struct </span>sum_k : <span class="keyword">public</span> mpl::plus&lt;sum_k&lt;IntegralVector,K-1&gt;, typename mpl::at_c&lt;IntegralVector,K-1&gt;::type &gt; {};
<a name="l00199"></a>00199
<a name="l00200"></a>00200 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> IntegralVector&gt; <span class="keyword">struct </span>sum_k&lt;IntegralVector,0&gt; : <span class="keyword">public</span> mpl::int_&lt;0&gt; {};
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202
<a name="l00203"></a>00203 <span class="comment">// at_c required by MutableColorBaseConcept</span>
<a name="l00204"></a>00204 <span class="keyword">template</span> &lt;<span class="keywordtype">int</span> K, <span class="keyword">typename</span> BitField, <span class="keyword">typename</span> ChannelBitSizes, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> Mutable&gt; <span class="keyword">inline</span>
<a name="l00205"></a>00205 <span class="keyword">typename</span> kth_element_reference_type&lt;bit_aligned_pixel_reference&lt;BitField,ChannelBitSizes,L,Mutable&gt;,K&gt;::type
<a name="l00206"></a>00206 at_c(<span class="keyword">const</span> bit_aligned_pixel_reference&lt;BitField,ChannelBitSizes,L,Mutable&gt;&amp; p) {
<a name="l00207"></a>00207 <span class="keyword">typedef</span> bit_aligned_pixel_reference&lt;BitField,ChannelBitSizes,L,Mutable&gt; pixel_t;
<a name="l00208"></a>00208 <span class="keyword">typedef</span> <span class="keyword">typename</span> kth_element_reference_type&lt;pixel_t,K&gt;::type channel_t;
<a name="l00209"></a>00209 <span class="keyword">typedef</span> <span class="keyword">typename</span> pixel_t::bit_range_t bit_range_t;
<a name="l00210"></a>00210
<a name="l00211"></a>00211 bit_range_t bit_range(p.bit_range());
<a name="l00212"></a>00212 bit_range.bit_advance(detail::sum_k&lt;ChannelBitSizes,K&gt;::value);
<a name="l00213"></a>00213
<a name="l00214"></a>00214 <span class="keywordflow">return</span> channel_t(bit_range.current_byte(), bit_range.bit_offset());
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216
<a name="l00218"></a>00218 <span class="comment">// PixelConcept</span>
<a name="l00220"></a>00220 <span class="comment"></span>
<a name="l00222"></a>00222 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M&gt;
<a name="l00223"></a><a class="code" href="g_i_l_0542.html">00223</a> <span class="keyword">struct </span>is_pixel&lt;<a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>&lt;B,C,L,M&gt; &gt; : <span class="keyword">public</span> mpl::true_{};
<a name="l00224"></a>00224
<a name="l00226"></a>00226 <span class="comment">// PixelBasedConcept</span>
<a name="l00228"></a>00228 <span class="comment"></span>
<a name="l00229"></a>00229 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M&gt;
<a name="l00230"></a>00230 <span class="keyword">struct </span>color_space_type&lt;<a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">bit_aligned_pixel_reference</a>&lt;B,C,L,M&gt; &gt; {
<a name="l00231"></a>00231 <span class="keyword">typedef</span> <span class="keyword">typename</span> L::color_space_t type;
<a name="l00232"></a>00232 };
<a name="l00233"></a>00233
<a name="l00234"></a>00234 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M&gt;
<a name="l00235"></a>00235 <span class="keyword">struct </span>channel_mapping_type&lt;bit_aligned_pixel_reference&lt;B,C,L,M&gt; &gt; {
<a name="l00236"></a>00236 <span class="keyword">typedef</span> <span class="keyword">typename</span> L::channel_mapping_t type;
<a name="l00237"></a>00237 };
<a name="l00238"></a>00238
<a name="l00239"></a>00239 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keywordtype">bool</span> M&gt;
<a name="l00240"></a>00240 <span class="keyword">struct </span>is_planar&lt;bit_aligned_pixel_reference&lt;B,C,L,M&gt; &gt; : mpl::false_ {};
<a name="l00241"></a>00241
<a name="l00243"></a>00243 <span class="comment">// pixel_reference_type</span>
<a name="l00245"></a>00245 <span class="comment"></span>
<a name="l00246"></a>00246 <span class="keyword">namespace </span>detail {
<a name="l00247"></a>00247 <span class="comment">// returns a vector containing K copies of the type T</span>
<a name="l00248"></a>00248 <span class="keyword">template</span> &lt;<span class="keywordtype">unsigned</span> K, <span class="keyword">typename</span> T&gt; <span class="keyword">struct </span>k_copies;
<a name="l00249"></a>00249 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt; <span class="keyword">struct </span>k_copies&lt;0,T&gt; {
<a name="l00250"></a>00250 <span class="keyword">typedef</span> mpl::vector0&lt;&gt; type;
<a name="l00251"></a>00251 };
<a name="l00252"></a>00252 <span class="keyword">template</span> &lt;<span class="keywordtype">unsigned</span> K, <span class="keyword">typename</span> T&gt; <span class="keyword">struct </span>k_copies : <span class="keyword">public</span> mpl::push_back&lt;typename k_copies&lt;K-1,T&gt;::type, T&gt; {};
<a name="l00253"></a>00253 }
<a name="l00254"></a>00254
<a name="l00255"></a>00255 <span class="comment">// Constructs a homogeneous bit_aligned_pixel_reference given a channel reference</span>
<a name="l00256"></a>00256 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField, <span class="keywordtype">int</span> NumBits, <span class="keyword">typename</span> Layout&gt;
<a name="l00257"></a>00257 <span class="keyword">struct </span>pixel_reference_type&lt;const packed_dynamic_channel_reference&lt;BitField,NumBits,false&gt;, Layout, false, false&gt; {
<a name="l00258"></a>00258 <span class="keyword">private</span>:
<a name="l00259"></a>00259 <span class="keyword">typedef</span> <span class="keyword">typename</span> mpl::size&lt;typename Layout::color_space_t&gt;::type size_t;
<a name="l00260"></a>00260 <span class="keyword">typedef</span> <span class="keyword">typename</span> detail::k_copies&lt;size_t::value,mpl::integral_c&lt;unsigned,NumBits&gt; &gt;::type channel_bit_sizes_t;
<a name="l00261"></a>00261 <span class="keyword">public</span>:
<a name="l00262"></a>00262 <span class="keyword">typedef</span> bit_aligned_pixel_reference&lt;BitField, channel_bit_sizes_t, Layout, false&gt; type;
<a name="l00263"></a>00263 };
<a name="l00264"></a>00264
<a name="l00265"></a>00265 <span class="comment">// Same but for the mutable case. We cannot combine the mutable and read-only cases because this triggers ambiguity</span>
<a name="l00266"></a>00266 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> BitField, <span class="keywordtype">int</span> NumBits, <span class="keyword">typename</span> Layout&gt;
<a name="l00267"></a>00267 <span class="keyword">struct </span>pixel_reference_type&lt;const packed_dynamic_channel_reference&lt;BitField,NumBits,true&gt;, Layout, false, true&gt; {
<a name="l00268"></a>00268 <span class="keyword">private</span>:
<a name="l00269"></a>00269 <span class="keyword">typedef</span> <span class="keyword">typename</span> mpl::size&lt;typename Layout::color_space_t&gt;::type size_t;
<a name="l00270"></a>00270 <span class="keyword">typedef</span> <span class="keyword">typename</span> detail::k_copies&lt;size_t::value,mpl::integral_c&lt;unsigned,NumBits&gt; &gt;::type channel_bit_sizes_t;
<a name="l00271"></a>00271 <span class="keyword">public</span>:
<a name="l00272"></a>00272 <span class="keyword">typedef</span> bit_aligned_pixel_reference&lt;BitField, channel_bit_sizes_t, Layout, true&gt; type;
<a name="l00273"></a>00273 };
<a name="l00274"></a>00274
<a name="l00275"></a>00275 } } <span class="comment">// namespace boost::gil</span>
<a name="l00276"></a>00276
<a name="l00277"></a>00277 <span class="keyword">namespace </span>std {
<a name="l00278"></a>00278 <span class="comment">// We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.</span>
<a name="l00279"></a>00279 <span class="comment">// swap with 'left bias': </span>
<a name="l00280"></a>00280 <span class="comment">// - swap between proxy and anything</span>
<a name="l00281"></a>00281 <span class="comment">// - swap between value type and proxy</span>
<a name="l00282"></a>00282 <span class="comment">// - swap between proxy and proxy</span>
<a name="l00283"></a>00283 <span class="comment">// Having three overloads allows us to swap between different (but compatible) models of PixelConcept</span>
<a name="l00284"></a>00284
<a name="l00285"></a>00285 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L, <span class="keyword">typename</span> R&gt; <span class="keyword">inline</span>
<a name="l00286"></a>00286 <span class="keywordtype">void</span> swap(<span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;</a> x, R&amp; y) {
<a name="l00287"></a>00287 boost::gil::swap_proxy&lt;typename boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;::value_type&gt;(x,y);
<a name="l00288"></a>00288 }
<a name="l00289"></a>00289
<a name="l00290"></a>00290
<a name="l00291"></a>00291 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L&gt; <span class="keyword">inline</span>
<a name="l00292"></a>00292 <span class="keywordtype">void</span> swap(<span class="keyword">typename</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;::value_type</a>&amp; x, <span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;</a> y) {
<a name="l00293"></a>00293 boost::gil::swap_proxy&lt;typename boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;::value_type&gt;(x,y);
<a name="l00294"></a>00294 }
<a name="l00295"></a>00295
<a name="l00296"></a>00296
<a name="l00297"></a>00297 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> B, <span class="keyword">typename</span> C, <span class="keyword">typename</span> L&gt; <span class="keyword">inline</span>
<a name="l00298"></a>00298 <span class="keywordtype">void</span> swap(<span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;</a> x, <span class="keyword">const</span> <a class="code" href="g_i_l_0403.html" title="Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models...">boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;</a> y) {
<a name="l00299"></a>00299 boost::gil::swap_proxy&lt;typename boost::gil::bit_aligned_pixel_reference&lt;B,C,L,true&gt;::value_type&gt;(x,y);
<a name="l00300"></a>00300 }
<a name="l00301"></a>00301 } <span class="comment">// namespace std</span>
<a name="l00302"></a>00302 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:13 2009 for Generic Image Library by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>