• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5<html xmlns="http://www.w3.org/1999/xhtml">
6  <head>
7    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
9    <title>Pixel Iterator - Boost.GIL  documentation</title>
10    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
11    <link rel="stylesheet" href="../_static/style.css" type="text/css" />
12    <script type="text/javascript">
13      var DOCUMENTATION_OPTIONS = {
14          URL_ROOT:    '../',
15          VERSION:     '',
16          COLLAPSE_MODINDEX: false,
17          FILE_SUFFIX: '.html'
18      };
19    </script>
20    <script type="text/javascript" src="../_static/jquery.js"></script>
21    <script type="text/javascript" src="../_static/underscore.js"></script>
22    <script type="text/javascript" src="../_static/doctools.js"></script>
23    <link rel="index" title="Index" href="../genindex.html" />
24    <link rel="search" title="Search" href="../search.html" />
25    <link rel="top" title="Boost.GIL  documentation" href="../index.html" />
26    <link rel="up" title="Design Guide" href="index.html" />
27    <link rel="next" title="Pixel Locator" href="pixel_locator.html" />
28    <link rel="prev" title="Pixel" href="pixel.html" />
29  </head>
30  <body>
31    <div class="header">
32    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
33    "header">
34      <tr>
35        <td valign="top" width="300">
36          <h3><a href="../index.html"><img
37          alt="C++ Boost" src="../_static/gil.png" border="0"></a></h3>
38        </td>
39
40        <td >
41          <h1 align="center"><a href="../index.html"></a></h1>
42        </td>
43	<td>
44      <div id="searchbox" style="display: none">
45        <form class="search" action="../search.html" method="get">
46          <input type="text" name="q" size="18" />
47          <input type="submit" value="Search" />
48          <input type="hidden" name="check_keywords" value="yes" />
49          <input type="hidden" name="area" value="default" />
50        </form>
51      </div>
52      <script type="text/javascript">$('#searchbox').show(0);</script>
53	</td>
54      </tr>
55    </table>
56    </div>
57    <hr/>
58    <div class="content">
59    <div class="navbar" style="text-align:right;">
60
61
62      <a class="prev" title="Pixel" href="pixel.html"><img src="../_static/prev.png" alt="prev"/></a>
63      <a class="up" title="Design Guide" href="index.html"><img src="../_static/up.png" alt="up"/></a>
64      <a class="next" title="Pixel Locator" href="pixel_locator.html"><img src="../_static/next.png" alt="next"/></a>
65
66    </div>
67
68  <div class="section" id="pixel-iterator">
69<h1>Pixel Iterator</h1>
70<div class="contents local topic" id="contents">
71<ul class="simple">
72<li><a class="reference internal" href="#overview" id="id4">Overview</a></li>
73<li><a class="reference internal" href="#fundamental-iterator" id="id5">Fundamental Iterator</a><ul>
74<li><a class="reference internal" href="#models" id="id6">Models</a></li>
75</ul>
76</li>
77<li><a class="reference internal" href="#iterator-adaptor" id="id7">Iterator Adaptor</a><ul>
78<li><a class="reference internal" href="#id1" id="id8">Models</a></li>
79</ul>
80</li>
81<li><a class="reference internal" href="#pixel-dereference-adaptor" id="id9">Pixel Dereference Adaptor</a><ul>
82<li><a class="reference internal" href="#id2" id="id10">Models</a></li>
83</ul>
84</li>
85<li><a class="reference internal" href="#step-iterator" id="id11">Step Iterator</a><ul>
86<li><a class="reference internal" href="#id3" id="id12">Models</a></li>
87</ul>
88</li>
89</ul>
90</div>
91<div class="section" id="overview">
92<h2><a class="toc-backref" href="#id4">Overview</a></h2>
93<p>Pixel iterators are random traversal iterators whose <code class="docutils literal"><span class="pre">value_type</span>
94<span class="pre">models</span></code> <code class="docutils literal"><span class="pre">PixelValueConcept</span></code>.</p>
95</div>
96<div class="section" id="fundamental-iterator">
97<h2><a class="toc-backref" href="#id5">Fundamental Iterator</a></h2>
98<p>Pixel iterators provide metafunctions to determine whether they are mutable
99(i.e. whether they allow for modifying the pixel they refer to), to get the
100immutable (read-only) type of the iterator, and to determine whether they are
101plain iterators or adaptors over another pixel iterator:</p>
102<div class="highlight-cpp"><div class="highlight"><pre><span class="n">concept</span> <span class="n">PixelIteratorConcept</span><span class="o">&lt;</span><span class="n">RandomAccessTraversalIteratorConcept</span> <span class="n">Iterator</span><span class="o">&gt;</span>
103    <span class="o">:</span> <span class="n">PixelBasedConcept</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span>
104<span class="p">{</span>
105  <span class="n">where</span> <span class="n">PixelValueConcept</span><span class="o">&lt;</span><span class="n">value_type</span><span class="o">&gt;</span><span class="p">;</span>
106  <span class="k">typename</span> <span class="n">const_iterator_type</span><span class="o">&lt;</span><span class="n">It</span><span class="o">&gt;::</span><span class="n">type</span><span class="p">;</span>
107      <span class="n">where</span> <span class="n">PixelIteratorConcept</span><span class="o">&lt;</span><span class="n">const_iterator_type</span><span class="o">&lt;</span><span class="n">It</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&gt;</span><span class="p">;</span>
108  <span class="k">static</span> <span class="k">const</span> <span class="kt">bool</span>  <span class="n">iterator_is_mutable</span><span class="o">&lt;</span><span class="n">It</span><span class="o">&gt;::</span><span class="n">value</span><span class="p">;</span>
109  <span class="k">static</span> <span class="k">const</span> <span class="kt">bool</span>  <span class="n">is_iterator_adaptor</span><span class="o">&lt;</span><span class="n">It</span><span class="o">&gt;::</span><span class="n">value</span><span class="p">;</span>   <span class="c1">// is it an iterator adaptor</span>
110<span class="p">};</span>
111
112<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Iterator</span><span class="o">&gt;</span>
113<span class="n">concept</span> <span class="nl">MutablePixelIteratorConcept</span> <span class="p">:</span> <span class="n">PixelIteratorConcept</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span><span class="p">,</span> <span class="n">MutableRandomAccessIteratorConcept</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span> <span class="p">{};</span>
114</pre></div>
115</div>
116<div class="admonition seealso">
117<p class="first admonition-title">See also</p>
118<ul class="last simple">
119<li><a class="reference external" href="reference/group___pixel_iterator_concept_pixel_iterator.html">PixelIteratorConcept&lt;Iterator&gt;</a></li>
120<li><a class="reference external" href="reference/structboost_1_1gil_1_1_mutable_pixel_iterator_concept.html">MutablePixelIteratorConcept&lt;Iterator&gt;</a></li>
121</ul>
122</div>
123<div class="section" id="models">
124<h3><a class="toc-backref" href="#id6">Models</a></h3>
125<p>A built-in pointer to pixel, <code class="docutils literal"><span class="pre">pixel&lt;ChannelValue,Layout&gt;*</span></code>, is GIL model for
126pixel iterator over interleaved homogeneous pixels. Similarly,
127<code class="docutils literal"><span class="pre">packed_pixel&lt;PixelData,ChannelRefVec,Layout&gt;*</span></code> is GIL model for an iterator
128over interleaved packed pixels.</p>
129<p>For planar homogeneous pixels, GIL provides the class
130<code class="docutils literal"><span class="pre">planar_pixel_iterator</span></code>, templated over a channel iterator and color space.
131Here is how the standard mutable and read-only planar RGB iterators over
132unsigned char are defined:</p>
133<div class="highlight-cpp"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">ChannelPtr</span><span class="p">,</span> <span class="k">typename</span> <span class="n">ColorSpace</span><span class="o">&gt;</span>
134<span class="k">struct</span> <span class="n">planar_pixel_iterator</span><span class="p">;</span>
135
136<span class="c1">// GIL provided typedefs</span>
137<span class="k">typedef</span> <span class="n">planar_pixel_iterator</span><span class="o">&lt;</span><span class="k">const</span> <span class="n">bits8</span><span class="o">*</span><span class="p">,</span> <span class="n">rgb_t</span><span class="o">&gt;</span> <span class="n">rgb8c_planar_ptr_t</span><span class="p">;</span>
138<span class="k">typedef</span> <span class="n">planar_pixel_iterator</span><span class="o">&lt;</span>      <span class="n">bits8</span><span class="o">*</span><span class="p">,</span> <span class="n">rgb_t</span><span class="o">&gt;</span> <span class="n">rgb8_planar_ptr_t</span><span class="p">;</span>
139</pre></div>
140</div>
141<p><code class="docutils literal"><span class="pre">planar_pixel_iterator</span></code> also models <code class="docutils literal"><span class="pre">HomogeneousColorBaseConcept</span></code> (it
142subclasses from <code class="docutils literal"><span class="pre">homogeneous_color_base</span></code>) and, as a result, all color base
143algorithms apply to it. The element type of its color base is a channel
144iterator. For example, GIL implements <code class="docutils literal"><span class="pre">operator++</span></code> of planar iterators
145approximately like this:</p>
146<div class="highlight-cpp"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
147<span class="k">struct</span> <span class="nl">inc</span> <span class="p">:</span> <span class="k">public</span> <span class="n">std</span><span class="o">::</span><span class="n">unary_function</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="n">T</span><span class="o">&gt;</span>
148<span class="p">{</span>
149  <span class="n">T</span> <span class="k">operator</span><span class="p">()(</span><span class="n">T</span> <span class="n">x</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="o">++</span><span class="n">x</span><span class="p">;</span> <span class="p">}</span>
150<span class="p">};</span>
151
152<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">ChannelPtr</span><span class="p">,</span> <span class="k">typename</span> <span class="n">ColorSpace</span><span class="o">&gt;</span>
153<span class="n">planar_pixel_iterator</span><span class="o">&lt;</span><span class="n">ChannelPtr</span><span class="p">,</span><span class="n">ColorSpace</span><span class="o">&gt;&amp;</span>
154<span class="n">planar_pixel_iterator</span><span class="o">&lt;</span><span class="n">ChannelPtr</span><span class="p">,</span><span class="n">ColorSpace</span><span class="o">&gt;::</span><span class="k">operator</span><span class="o">++</span><span class="p">()</span>
155<span class="p">{</span>
156  <span class="n">static_transform</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">,</span><span class="n">inc</span><span class="o">&lt;</span><span class="n">ChannelPtr</span><span class="o">&gt;</span><span class="p">());</span>
157  <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
158<span class="p">}</span>
159</pre></div>
160</div>
161<p>Since <code class="docutils literal"><span class="pre">static_transform</span></code> uses compile-time recursion, incrementing an
162instance of <code class="docutils literal"><span class="pre">rgb8_planar_ptr_t</span></code> amounts to three pointer increments.
163GIL also uses the class <code class="docutils literal"><span class="pre">bit_aligned_pixel_iterator</span></code> as a model for a pixel
164iterator over bit-aligned pixels. Internally it keeps track of the current
165byte and the bit offset.</p>
166</div>
167</div>
168<div class="section" id="iterator-adaptor">
169<h2><a class="toc-backref" href="#id7">Iterator Adaptor</a></h2>
170<p>Iterator adaptor is an iterator that wraps around another iterator. Its
171<code class="docutils literal"><span class="pre">is_iterator_adaptor</span></code> metafunction must evaluate to true, and it needs to
172provide a member method to return the base iterator, a metafunction to get its
173type, and a metafunction to rebind to another base iterator:</p>
174<div class="highlight-cpp"><div class="highlight"><pre><span class="n">concept</span> <span class="n">IteratorAdaptorConcept</span><span class="o">&lt;</span><span class="n">RandomAccessTraversalIteratorConcept</span> <span class="n">Iterator</span><span class="o">&gt;</span>
175<span class="p">{</span>
176  <span class="n">where</span> <span class="n">SameType</span><span class="o">&lt;</span><span class="n">is_iterator_adaptor</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;::</span><span class="n">type</span><span class="p">,</span> <span class="n">mpl</span><span class="o">::</span><span class="n">true_</span><span class="o">&gt;</span><span class="p">;</span>
177
178  <span class="k">typename</span> <span class="n">iterator_adaptor_get_base</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span><span class="p">;</span>
179      <span class="n">where</span> <span class="n">Metafunction</span><span class="o">&lt;</span><span class="n">iterator_adaptor_get_base</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">;</span>
180      <span class="n">where</span> <span class="n">boost_concepts</span><span class="o">::</span><span class="n">ForwardTraversalConcept</span><span class="o">&lt;</span><span class="n">iterator_adaptor_get_base</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&gt;</span><span class="p">;</span>
181
182  <span class="k">typename</span> <span class="n">another_iterator</span><span class="p">;</span>
183  <span class="k">typename</span> <span class="n">iterator_adaptor_rebind</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="p">,</span><span class="n">another_iterator</span><span class="o">&gt;::</span><span class="n">type</span><span class="p">;</span>
184      <span class="n">where</span> <span class="n">boost_concepts</span><span class="o">::</span><span class="n">ForwardTraversalConcept</span><span class="o">&lt;</span><span class="n">another_iterator</span><span class="o">&gt;</span><span class="p">;</span>
185      <span class="n">where</span> <span class="n">IteratorAdaptorConcept</span><span class="o">&lt;</span><span class="n">iterator_adaptor_rebind</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="p">,</span><span class="n">another_iterator</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&gt;</span><span class="p">;</span>
186
187  <span class="k">const</span> <span class="n">iterator_adaptor_get_base</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&amp;</span> <span class="n">Iterator</span><span class="o">::</span><span class="n">base</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
188<span class="p">};</span>
189
190<span class="k">template</span> <span class="o">&lt;</span><span class="n">boost_concepts</span><span class="o">::</span><span class="n">Mutable_ForwardIteratorConcept</span> <span class="n">Iterator</span><span class="o">&gt;</span>
191<span class="n">concept</span> <span class="nl">MutableIteratorAdaptorConcept</span> <span class="p">:</span> <span class="n">IteratorAdaptorConcept</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span> <span class="p">{};</span>
192</pre></div>
193</div>
194<div class="admonition seealso">
195<p class="first admonition-title">See also</p>
196<ul class="last simple">
197<li><a class="reference external" href="reference/structboost_1_1gil_1_1_iterator_adaptor_concept.html">IteratorAdaptorConcept&lt;Iterator&gt;</a></li>
198<li><a class="reference external" href="reference/structboost_1_1gil_1_1_mutable_iterator_adaptor_concept.html">MutableIteratorAdaptorConcept&lt;Iterator&gt;</a></li>
199</ul>
200</div>
201<div class="section" id="id1">
202<h3><a class="toc-backref" href="#id8">Models</a></h3>
203<p>GIL provides several models of <code class="docutils literal"><span class="pre">IteratorAdaptorConcept</span></code>:</p>
204<ul class="simple">
205<li><code class="docutils literal"><span class="pre">memory_based_step_iterator&lt;Iterator&gt;</span></code>: An iterator adaptor that changes
206the fundamental step of the base iterator
207(see <span class="xref std std-ref">design/pixel_iterator:Step Iterator</span>)</li>
208<li><code class="docutils literal"><span class="pre">dereference_iterator_adaptor&lt;Iterator,Fn&gt;</span></code>: An iterator that applies a
209unary function <code class="docutils literal"><span class="pre">Fn</span></code> upon dereferencing. It is used, for example, for
210on-the-fly color conversion. It can be used to construct a shallow image
211&#8220;view&#8221; that pretends to have a different color space or channel depth.
212See <a class="reference internal" href="image_view.html"><span class="doc">Image View</span></a> for more. The unary function <code class="docutils literal"><span class="pre">Fn</span></code> must
213model <code class="docutils literal"><span class="pre">PixelDereferenceAdaptorConcept</span></code> (see below).</li>
214</ul>
215</div>
216</div>
217<div class="section" id="pixel-dereference-adaptor">
218<h2><a class="toc-backref" href="#id9">Pixel Dereference Adaptor</a></h2>
219<p>Pixel dereference adaptor is a unary function that can be applied upon
220dereferencing a pixel iterator. Its argument type could be anything (usually a
221<code class="docutils literal"><span class="pre">PixelConcept</span></code>) and the result type must be convertible to <code class="docutils literal"><span class="pre">PixelConcept</span></code>:</p>
222<div class="highlight-cpp"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">UnaryFunctionConcept</span> <span class="n">D</span><span class="o">&gt;</span>
223<span class="n">concept</span> <span class="nl">PixelDereferenceAdaptorConcept</span><span class="p">:</span>
224    <span class="n">DefaultConstructibleConcept</span><span class="o">&lt;</span><span class="n">D</span><span class="o">&gt;</span><span class="p">,</span>
225    <span class="n">CopyConstructibleConcept</span><span class="o">&lt;</span><span class="n">D</span><span class="o">&gt;</span><span class="p">,</span>
226    <span class="n">AssignableConcept</span><span class="o">&lt;</span><span class="n">D</span><span class="o">&gt;</span>
227<span class="p">{</span>
228  <span class="k">typename</span> <span class="n">const_t</span><span class="p">;</span>         <span class="n">where</span> <span class="n">PixelDereferenceAdaptorConcept</span><span class="o">&lt;</span><span class="n">const_t</span><span class="o">&gt;</span><span class="p">;</span>
229  <span class="k">typename</span> <span class="n">value_type</span><span class="p">;</span>      <span class="n">where</span> <span class="n">PixelValueConcept</span><span class="o">&lt;</span><span class="n">value_type</span><span class="o">&gt;</span><span class="p">;</span>
230  <span class="k">typename</span> <span class="n">reference</span><span class="p">;</span>       <span class="n">where</span> <span class="n">PixelConcept</span><span class="o">&lt;</span><span class="n">remove_reference</span><span class="o">&lt;</span><span class="n">reference</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&gt;</span><span class="p">;</span>  <span class="c1">// may be mutable</span>
231  <span class="k">typename</span> <span class="n">const_reference</span><span class="p">;</span>   <span class="c1">// must not be mutable</span>
232  <span class="k">static</span> <span class="k">const</span> <span class="kt">bool</span> <span class="n">D</span><span class="o">::</span><span class="n">is_mutable</span><span class="p">;</span>
233
234  <span class="n">where</span> <span class="n">Convertible</span><span class="o">&lt;</span><span class="n">value_type</span><span class="p">,</span> <span class="n">result_type</span><span class="o">&gt;</span><span class="p">;</span>
235<span class="p">};</span>
236</pre></div>
237</div>
238<div class="section" id="id2">
239<h3><a class="toc-backref" href="#id10">Models</a></h3>
240<p>GIL provides several models of <code class="docutils literal"><span class="pre">PixelDereferenceAdaptorConcept</span></code>:</p>
241<ul class="simple">
242<li><code class="docutils literal"><span class="pre">color_convert_deref_fn</span></code>: a function object that performs color conversion</li>
243<li><code class="docutils literal"><span class="pre">detail::nth_channel_deref_fn</span></code>: a function object that returns a grayscale
244pixel corresponding to the n-th channel of a given pixel</li>
245<li><code class="docutils literal"><span class="pre">deref_compose</span></code>: a function object that composes two models of
246<code class="docutils literal"><span class="pre">PixelDereferenceAdaptorConcept</span></code>. Similar to <code class="docutils literal"><span class="pre">std::unary_compose</span></code>,
247except it needs to pull the additional typedefs required by
248<code class="docutils literal"><span class="pre">PixelDereferenceAdaptorConcept</span></code></li>
249</ul>
250<p>GIL uses pixel dereference adaptors to implement image views that perform
251color conversion upon dereferencing, or that return the N-th channel of the
252underlying pixel. They can be used to model virtual image views that perform
253an arbitrary function upon dereferencing, for example a view of the Mandelbrot
254set. <code class="docutils literal"><span class="pre">dereference_iterator_adaptor&lt;Iterator,Fn&gt;</span></code> is an iterator wrapper over
255a pixel iterator <code class="docutils literal"><span class="pre">Iterator</span></code> that invokes the given dereference iterator
256adaptor <code class="docutils literal"><span class="pre">Fn</span></code> upon dereferencing.</p>
257</div>
258</div>
259<div class="section" id="step-iterator">
260<h2><a class="toc-backref" href="#id11">Step Iterator</a></h2>
261<p>Sometimes we want to traverse pixels with a unit step other than the one
262provided by the fundamental pixel iterators. Examples where this would be
263useful:</p>
264<ul class="simple">
265<li>a single-channel view of the red channel of an RGB interleaved image</li>
266<li>left-to-right flipped image (step = -fundamental_step)</li>
267<li>subsampled view, taking every N-th pixel (step = N*fundamental_step)</li>
268<li>traversal in vertical direction (step = number of bytes per row)</li>
269<li>any combination of the above (steps are multiplied)</li>
270</ul>
271<p>Step iterators are forward traversal iterators that allow changing the step
272between adjacent values:</p>
273<div class="highlight-cpp"><div class="highlight"><pre><span class="n">concept</span> <span class="n">StepIteratorConcept</span><span class="o">&lt;</span><span class="n">boost_concepts</span><span class="o">::</span><span class="n">ForwardTraversalConcept</span> <span class="n">Iterator</span><span class="o">&gt;</span>
274<span class="p">{</span>
275  <span class="k">template</span> <span class="o">&lt;</span><span class="n">Integral</span> <span class="n">D</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">Iterator</span><span class="o">::</span><span class="n">set_step</span><span class="p">(</span><span class="n">D</span> <span class="n">step</span><span class="p">);</span>
276<span class="p">};</span>
277
278<span class="n">concept</span> <span class="n">MutableStepIteratorConcept</span><span class="o">&lt;</span><span class="n">boost_concepts</span><span class="o">::</span><span class="n">Mutable_ForwardIteratorConcept</span> <span class="n">Iterator</span><span class="o">&gt;</span>
279    <span class="o">:</span> <span class="n">StepIteratorConcept</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span>
280<span class="p">{};</span>
281</pre></div>
282</div>
283<p>GIL currently provides a step iterator whose <code class="docutils literal"><span class="pre">value_type</span> <span class="pre">models</span></code>
284<code class="docutils literal"><span class="pre">PixelValueConcept</span></code>. In addition, the step is specified in memory units
285(which are bytes or bits). This is necessary, for example, when implementing
286an iterator navigating along a column of pixels - the size of a row of pixels
287may sometimes not be divisible by the size of a pixel; for example rows may be
288word-aligned.</p>
289<p>To advance in bytes/bits, the base iterator must model
290<code class="docutils literal"><span class="pre">MemoryBasedIteratorConcept</span></code>. A memory-based iterator has an inherent memory
291unit, which is either a bit or a byte. It must supply functions returning the
292number of bits per memory unit (1 or 8), the current step in memory units, the
293memory-unit distance between two iterators, and a reference a given distance
294in memunits away. It must also supply a function that advances an iterator a
295given distance in memory units. <code class="docutils literal"><span class="pre">memunit_advanced</span></code> and
296<code class="docutils literal"><span class="pre">memunit_advanced_ref</span></code> have a default implementation but some iterators may
297supply a more efficient version:</p>
298<div class="highlight-cpp"><div class="highlight"><pre><span class="n">concept</span> <span class="n">MemoryBasedIteratorConcept</span>
299<span class="o">&lt;</span>
300    <span class="n">boost_concepts</span><span class="o">::</span><span class="n">RandomAccessTraversalConcept</span> <span class="n">Iterator</span>
301<span class="o">&gt;</span>
302<span class="p">{</span>
303  <span class="k">typename</span> <span class="n">byte_to_memunit</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span><span class="p">;</span> <span class="n">where</span> <span class="n">metafunction</span><span class="o">&lt;</span><span class="n">byte_to_memunit</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">;</span>
304  <span class="n">std</span><span class="o">::</span><span class="kt">ptrdiff_t</span>      <span class="n">memunit_step</span><span class="p">(</span><span class="k">const</span> <span class="n">Iterator</span><span class="o">&amp;</span><span class="p">);</span>
305  <span class="n">std</span><span class="o">::</span><span class="kt">ptrdiff_t</span>      <span class="n">memunit_distance</span><span class="p">(</span><span class="k">const</span> <span class="n">Iterator</span><span class="o">&amp;</span> <span class="p">,</span> <span class="k">const</span> <span class="n">Iterator</span><span class="o">&amp;</span><span class="p">);</span>
306  <span class="kt">void</span>                <span class="nf">memunit_advance</span><span class="p">(</span><span class="n">Iterator</span><span class="o">&amp;</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="kt">ptrdiff_t</span> <span class="n">diff</span><span class="p">);</span>
307  <span class="n">Iterator</span>            <span class="nf">memunit_advanced</span><span class="p">(</span><span class="k">const</span> <span class="n">Iterator</span><span class="o">&amp;</span> <span class="n">p</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="kt">ptrdiff_t</span> <span class="n">diff</span><span class="p">)</span> <span class="p">{</span> <span class="n">Iterator</span> <span class="n">tmp</span><span class="p">;</span> <span class="n">memunit_advance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="n">diff</span><span class="p">);</span> <span class="k">return</span> <span class="n">tmp</span><span class="p">;</span> <span class="p">}</span>
308  <span class="n">Iterator</span><span class="o">::</span><span class="n">reference</span> <span class="n">memunit_advanced_ref</span><span class="p">(</span><span class="k">const</span> <span class="n">Iterator</span><span class="o">&amp;</span> <span class="n">p</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="kt">ptrdiff_t</span> <span class="n">diff</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="o">*</span><span class="n">memunit_advanced</span><span class="p">(</span><span class="n">p</span><span class="p">,</span><span class="n">diff</span><span class="p">);</span> <span class="p">}</span>
309<span class="p">};</span>
310</pre></div>
311</div>
312<p>It is useful to be able to construct a step iterator over another iterator.
313More generally, given a type, we want to be able to construct an equivalent
314type that allows for dynamically specified horizontal step:</p>
315<div class="highlight-cpp"><div class="highlight"><pre><span class="n">concept</span> <span class="n">HasDynamicXStepTypeConcept</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
316<span class="p">{</span>
317  <span class="k">typename</span> <span class="n">dynamic_x_step_type</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">;</span>
318      <span class="n">where</span> <span class="n">Metafunction</span><span class="o">&lt;</span><span class="n">dynamic_x_step_type</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">;</span>
319<span class="p">};</span>
320</pre></div>
321</div>
322<p>All models of pixel iterators, locators and image views that GIL provides
323support <code class="docutils literal"><span class="pre">HasDynamicXStepTypeConcept</span></code>.</p>
324<div class="admonition seealso">
325<p class="first admonition-title">See also</p>
326<ul class="last simple">
327<li><a class="reference external" href="reference/structboost_1_1gil_1_1_step_iterator_concept.html">StepIteratorConcept&lt;Iterator&gt;</a></li>
328<li><a class="reference external" href="reference/structboost_1_1gil_1_1_mutable_step_iterator_concept.html">MutableStepIteratorConcept&lt;Iterator&gt;</a></li>
329<li><a class="reference external" href="reference/structboost_1_1gil_1_1_memory_based_iterator_concept.html">MemoryBasedIteratorConcept&lt;Iterator&gt;</a></li>
330<li><a class="reference external" href="reference/structboost_1_1gil_1_1_has_dynamic_x_step_type_concept.html">HasDynamicXStepTypeConcept&lt;T&gt;</a></li>
331</ul>
332</div>
333<div class="section" id="id3">
334<h3><a class="toc-backref" href="#id12">Models</a></h3>
335<p>All standard memory-based iterators GIL currently provides model
336<code class="docutils literal"><span class="pre">MemoryBasedIteratorConcept</span></code>. GIL provides the class
337<code class="docutils literal"><span class="pre">memory_based_step_iterator</span></code> which models <code class="docutils literal"><span class="pre">PixelIteratorConcept</span></code>,
338<code class="docutils literal"><span class="pre">StepIteratorConcept</span></code>, and <code class="docutils literal"><span class="pre">MemoryBasedIteratorConcept</span></code>. It takes the base
339iterator as a template parameter (which must model <code class="docutils literal"><span class="pre">PixelIteratorConcept</span></code>
340and <code class="docutils literal"><span class="pre">MemoryBasedIteratorConcept</span></code>) and allows changing the step dynamically.
341GIL implementation contains the base iterator and a <code class="docutils literal"><span class="pre">ptrdiff_t</span></code> denoting the
342number of memory units (bytes or bits) to skip for a unit step. It may also be
343used with a negative number. GIL provides a function to create a step iterator
344from a base iterator and a step:</p>
345<div class="highlight-cpp"><div class="highlight"><pre><span class="c1">// Iterator models MemoryBasedIteratorConcept, HasDynamicXStepTypeConcept</span>
346<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Iterator</span><span class="o">&gt;</span>
347<span class="k">typename</span> <span class="n">dynamic_x_step_type</span><span class="o">&lt;</span><span class="n">Iterator</span><span class="o">&gt;::</span><span class="n">type</span> <span class="n">make_step_iterator</span><span class="p">(</span><span class="n">Iterator</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">it</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="kt">ptrdiff_t</span> <span class="n">step</span><span class="p">);</span>
348</pre></div>
349</div>
350<p>GIL also provides a model of an iterator over a virtual array of pixels,
351<code class="docutils literal"><span class="pre">position_iterator</span></code>. It is a step iterator that keeps track of the pixel
352position and invokes a function object to get the value of the pixel upon
353dereferencing. It models <code class="docutils literal"><span class="pre">PixelIteratorConcept</span></code> and <code class="docutils literal"><span class="pre">StepIteratorConcept</span></code>
354but not <code class="docutils literal"><span class="pre">MemoryBasedIteratorConcept</span></code>.</p>
355</div>
356</div>
357</div>
358
359
360    <div class="navbar" style="text-align:right;">
361
362
363      <a class="prev" title="Pixel" href="pixel.html"><img src="../_static/prev.png" alt="prev"/></a>
364      <a class="up" title="Design Guide" href="index.html"><img src="../_static/up.png" alt="up"/></a>
365      <a class="next" title="Pixel Locator" href="pixel_locator.html"><img src="../_static/next.png" alt="next"/></a>
366
367    </div>
368    </div>
369    <div class="footer" role="contentinfo">
370      Last updated on 2020-08-11 15:08:48.
371      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.6.
372    </div>
373  </body>
374</html>