io.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>IO extensions - Boost.GIL documentation</title>
  7. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/style.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: './',
  12. VERSION: '',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html'
  15. };
  16. </script>
  17. <script type="text/javascript" src="_static/jquery.js"></script>
  18. <script type="text/javascript" src="_static/underscore.js"></script>
  19. <script type="text/javascript" src="_static/doctools.js"></script>
  20. <link rel="index" title="Index" href="genindex.html" />
  21. <link rel="search" title="Search" href="search.html" />
  22. <link rel="top" title="Boost.GIL documentation" href="index.html" />
  23. <link rel="next" title="ToolBox extension" href="toolbox.html" />
  24. <link rel="prev" title="Affine region detectors" href="image_processing/affine-region-detectors.html" />
  25. </head>
  26. <body>
  27. <div class="header">
  28. <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
  29. "header">
  30. <tr>
  31. <td valign="top" width="300">
  32. <h3><a href="index.html"><img
  33. alt="C++ Boost" src="_static/gil.png" border="0"></a></h3>
  34. </td>
  35. <td >
  36. <h1 align="center"><a href="index.html"></a></h1>
  37. </td>
  38. <td>
  39. <div id="searchbox" style="display: none">
  40. <form class="search" action="search.html" method="get">
  41. <input type="text" name="q" size="18" />
  42. <input type="submit" value="Search" />
  43. <input type="hidden" name="check_keywords" value="yes" />
  44. <input type="hidden" name="area" value="default" />
  45. </form>
  46. </div>
  47. <script type="text/javascript">$('#searchbox').show(0);</script>
  48. </td>
  49. </tr>
  50. </table>
  51. </div>
  52. <hr/>
  53. <div class="content">
  54. <div class="navbar" style="text-align:right;">
  55. <a class="prev" title="Affine region detectors" href="image_processing/affine-region-detectors.html"><img src="_static/prev.png" alt="prev"/></a>
  56. <a class="next" title="ToolBox extension" href="toolbox.html"><img src="_static/next.png" alt="next"/></a>
  57. </div>
  58. <div class="section" id="io-extensions">
  59. <h1>IO extensions</h1>
  60. <div class="section" id="overview">
  61. <h2>Overview</h2>
  62. <p>This extension to boost::gil provides an easy to use interface for reading and
  63. writing various image formats. It also includes a framework for adding
  64. new formats.</p>
  65. <p>Please see section 3.3 for all supported image formats. A basic tutorial is
  66. provided in section [link gil.io.tutorial Tutorial].
  67. Also, this extension requires Boost version 1.42 and up.
  68. Furthermore the GIL extension Toolbox is used.</p>
  69. <p>For adding new image formats please refer to section
  70. [link gil.io.using_io.extending_gil__io_with_new_formats Extending GIL::IO with new Formats].</p>
  71. </div>
  72. <div class="section" id="supported-platforms">
  73. <h2>Supported Platforms</h2>
  74. <p>All platforms supported by Boost which have a decent C++ compiler.
  75. Depending on the image format one or more of the following image
  76. libraries might be needed:</p>
  77. <ul class="simple">
  78. <li>libtiff</li>
  79. <li>libjpeg</li>
  80. <li>libpng</li>
  81. <li>libraw</li>
  82. <li>zlib</li>
  83. </ul>
  84. <p>The library is designed to support as many formats as required by the user.
  85. For instance, if the user only needs bmp support none of the above mentioned
  86. dependencies are required.</p>
  87. <p>There are more details available in this documentation on the image format
  88. dependencies. Please see section
  89. [link gil.io.using_io.supported_image_formats Supported Image Formats].</p>
  90. </div>
  91. <div class="section" id="tutorial">
  92. <h2>Tutorial</h2>
  93. <p>Thanks to modern C++ programming techniques the interface for this library
  94. is rather small and easy to use. In this tutorial I&#8217;ll give you a short
  95. walk-around on how to use this boost::gil extension.
  96. For more details please refer to section 3.</p>
  97. <p>For each supported IO format a single top-level header file is provided.
  98. For instance, include <cite>boost/gil/extension/io/tiff.hpp</cite> to be able
  99. to read or write TIFF files.</p>
  100. <div class="section" id="reading-an-image">
  101. <h3>Reading An Image</h3>
  102. <p>Probably the most common case to read a tiff image can be done as follows:</p>
  103. <div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">filename</span><span class="p">(</span> <span class="s">&quot;image.tif&quot;</span> <span class="p">);</span>
  104. <span class="n">rgb8_image_t</span> <span class="n">img</span><span class="p">;</span>
  105. <span class="n">read_image</span><span class="p">(</span> <span class="n">filename</span><span class="p">,</span> <span class="n">img</span><span class="p">,</span> <span class="n">tiff_tag</span><span class="p">()</span> <span class="p">);</span>
  106. </pre></div>
  107. </div>
  108. <p>The code would be same for all other image formats. The only thing that needs
  109. to change is the tag type ( tiff_tag ) in the read_image call.
  110. The read_image() expects the supplied image type to be compatible with the
  111. image stored in the file. If the user doesn&#8217;t know what format an image has she
  112. can use read_and_convert_image().
  113. Another important fact is that read_image() will allocate the appropriate
  114. memory needed for the read operation. There are <code class="docutils literal"><span class="pre">read_view</span></code> or
  115. <code class="docutils literal"><span class="pre">read_and_convert_view</span></code> counterparts, if the memory is already allocated.</p>
  116. <p>Sometimes the user only wants to read a sub-part of an image,
  117. then the above call would look as follows:</p>
  118. <div class="highlight-c++"><div class="highlight"><pre><span class="n">read_image</span><span class="p">(</span> <span class="n">filename</span>
  119. <span class="p">,</span> <span class="n">img</span>
  120. <span class="p">,</span> <span class="n">image_read_settings</span><span class="o">&lt;</span> <span class="n">tiff_tag</span> <span class="o">&gt;</span><span class="p">(</span> <span class="n">point_t</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> <span class="p">),</span> <span class="n">point_t</span><span class="p">(</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">50</span> <span class="p">)</span> <span class="p">)</span>
  121. <span class="p">);</span>
  122. </pre></div>
  123. </div>
  124. <p>The image_read_settings class will provide the user with image format
  125. independent reading setting but can also serves as a pointer for format
  126. dependent settings.
  127. Please see the specific image format sections
  128. [link gil.io.using_io.supported_image_formats Supported Image Formats]
  129. for more details.</p>
  130. </div>
  131. <div class="section" id="writing-an-image">
  132. <h3>Writing An Image</h3>
  133. <p>Besides reading the information also writing is the second part of this
  134. Boost.GIL extension. Writing is a lot simpler than reading since an existing
  135. image view contains all the information.</p>
  136. <p>For instance writing an image can be done as follows:</p>
  137. <div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">filename</span><span class="p">(</span> <span class="s">&quot;image.tif&quot;</span> <span class="p">);</span>
  138. <span class="n">rgb8_image_t</span> <span class="nf">img</span><span class="p">(</span> <span class="mi">640</span><span class="p">,</span> <span class="mi">480</span> <span class="p">);</span>
  139. <span class="c1">// write data into image</span>
  140. <span class="n">write_view</span><span class="p">(</span> <span class="n">filename</span>
  141. <span class="p">,</span> <span class="n">view</span><span class="p">(</span> <span class="n">img</span> <span class="p">)</span>
  142. <span class="p">,</span> <span class="n">tiff_tag</span><span class="p">()</span>
  143. <span class="p">);</span>
  144. </pre></div>
  145. </div>
  146. <p>The interface is similar to reading an image. To add image format specific
  147. parameter the user can use <code class="docutils literal"><span class="pre">image_write_info</span></code> class.
  148. For instance, a user can specify the JPEG quality when writing like this:</p>
  149. <div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">filename</span><span class="p">(</span> <span class="s">&quot;image.jpg&quot;</span> <span class="p">);</span>
  150. <span class="n">rgb8_image_t</span> <span class="nf">img</span><span class="p">(</span> <span class="mi">640</span><span class="p">,</span> <span class="mi">480</span> <span class="p">);</span>
  151. <span class="c1">// write data into image</span>
  152. <span class="n">write_view</span><span class="p">(</span> <span class="n">filename</span>
  153. <span class="p">,</span> <span class="n">view</span><span class="p">(</span> <span class="n">img</span> <span class="p">)</span>
  154. <span class="p">,</span> <span class="n">image_write_info</span><span class="o">&lt;</span> <span class="n">jpeg_tag</span> <span class="o">&gt;</span><span class="p">(</span> <span class="mi">95</span> <span class="p">)</span>
  155. <span class="p">);</span>
  156. </pre></div>
  157. </div>
  158. <p>The above example will write an image where the jpeg quality is
  159. set to 95 percent.</p>
  160. </div>
  161. <div class="section" id="reading-and-writing-in-memory-buffers">
  162. <h3>Reading And Writing In-Memory Buffers</h3>
  163. <p>Reading and writing in-memory buffers are supported as well. See as follows:</p>
  164. <div class="highlight-c++"><div class="highlight"><pre><span class="c1">// 1. Read an image.</span>
  165. <span class="n">ifstream</span> <span class="nf">in</span><span class="p">(</span> <span class="s">&quot;test.tif&quot;</span><span class="p">,</span> <span class="n">ios</span><span class="o">::</span><span class="n">binary</span> <span class="p">);</span>
  166. <span class="n">rgb8_image_t</span> <span class="n">img</span><span class="p">;</span>
  167. <span class="n">read_image</span><span class="p">(</span> <span class="n">in</span><span class="p">,</span> <span class="n">img</span><span class="p">,</span> <span class="n">tiff_tag</span><span class="p">()</span> <span class="p">);</span>
  168. <span class="c1">// 2. Write image to in-memory buffer.</span>
  169. <span class="n">stringstream</span> <span class="nf">out_buffer</span><span class="p">(</span> <span class="n">ios_base</span><span class="o">::</span><span class="n">out</span> <span class="o">|</span> <span class="n">ios_base</span><span class="o">::</span><span class="n">binary</span> <span class="p">);</span>
  170. <span class="n">rgb8_image_t</span> <span class="n">src</span><span class="p">;</span>
  171. <span class="n">write_view</span><span class="p">(</span> <span class="n">out_buffer</span><span class="p">,</span> <span class="n">view</span><span class="p">(</span> <span class="n">src</span> <span class="p">),</span> <span class="n">tiff_tag</span><span class="p">()</span> <span class="p">);</span>
  172. <span class="c1">// 3. Copy in-memory buffer to another.</span>
  173. <span class="n">stringstream</span> <span class="nf">in_buffer</span><span class="p">(</span> <span class="n">ios_base</span><span class="o">::</span><span class="n">in</span> <span class="o">|</span> <span class="n">ios_base</span><span class="o">::</span><span class="n">binary</span> <span class="p">);</span>
  174. <span class="n">in_buffer</span> <span class="o">&lt;&lt;</span> <span class="n">out_buffer</span><span class="p">.</span><span class="n">rdbuf</span><span class="p">();</span>
  175. <span class="c1">// 4. Read in-memory buffer to gil image</span>
  176. <span class="n">rgb8_image_t</span> <span class="n">dst</span><span class="p">;</span>
  177. <span class="n">read_image</span><span class="p">(</span> <span class="n">in_buffer</span><span class="p">,</span> <span class="n">dst</span><span class="p">,</span> <span class="n">tag_t</span><span class="p">()</span> <span class="p">);</span>
  178. <span class="c1">// 5. Write out image.</span>
  179. <span class="n">string</span> <span class="nf">filename</span><span class="p">(</span> <span class="s">&quot;out.tif&quot;</span> <span class="p">);</span>
  180. <span class="n">ofstream</span> <span class="nf">out</span><span class="p">(</span> <span class="n">filename</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">ios_base</span><span class="o">::</span><span class="n">binary</span> <span class="p">);</span>
  181. <span class="n">write_view</span><span class="p">(</span> <span class="n">out</span><span class="p">,</span> <span class="n">view</span><span class="p">(</span> <span class="n">dst</span> <span class="p">),</span> <span class="n">tiff_tag</span><span class="p">()</span> <span class="p">);</span>
  182. </pre></div>
  183. </div>
  184. <p>In case the user is using his own stream classes he has to make sure it
  185. has the common interface read, write, seek, close, etc. Interface.</p>
  186. </div>
  187. </div>
  188. <div class="section" id="using-io">
  189. <h2>Using IO</h2>
  190. <div class="section" id="general-overview">
  191. <h3>General Overview</h3>
  192. <p>The tutorial pointed out some use cases for reading and writing images in
  193. various image formats. This section will provide a more thorough overview.</p>
  194. <p>The next sections will introduce the Read and Write interface. But it might be
  195. worth pointing out that by using some advanced metaprogramming techniques the
  196. interface is rather small and hopefully easy to understand.</p>
  197. <p>Besides the general interface the user also has the ability to interface
  198. directly with the underlying image format. For that each reader or writer
  199. provides access to the so-called backend.</p>
  200. <p>For instance:</p>
  201. <div class="highlight-c++"><div class="highlight"><pre><span class="k">typedef</span> <span class="n">get_reader_backend</span><span class="o">&lt;</span> <span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span>
  202. <span class="p">,</span> <span class="n">tag_t</span>
  203. <span class="o">&gt;::</span><span class="n">type</span> <span class="n">backend_t</span><span class="p">;</span>
  204. <span class="n">backend_t</span> <span class="n">backend</span> <span class="o">=</span> <span class="n">read_image_info</span><span class="p">(</span> <span class="n">bmp_filename</span>
  205. <span class="p">,</span> <span class="n">tag_t</span><span class="p">()</span>
  206. <span class="p">);</span>
  207. <span class="n">BOOST_CHECK_EQUAL</span><span class="p">(</span> <span class="n">backend</span><span class="p">.</span><span class="n">_info</span><span class="p">.</span><span class="n">_width</span> <span class="p">,</span> <span class="mi">127</span> <span class="p">);</span>
  208. <span class="n">BOOST_CHECK_EQUAL</span><span class="p">(</span> <span class="n">backend</span><span class="p">.</span><span class="n">_info</span><span class="p">.</span><span class="n">_height</span><span class="p">,</span> <span class="mi">64</span> <span class="p">);</span>
  209. </pre></div>
  210. </div>
  211. <p>Of course, the typedef can be removed when using c++11&#8217;s auto feature.</p>
  212. </div>
  213. <div class="section" id="read-interface">
  214. <h3>Read Interface</h3>
  215. <p>As the Tutorial demonstrated there are a few ways to read images.
  216. Here is an enumeration of all read functions with a short description:</p>
  217. <ul class="simple">
  218. <li><code class="docutils literal"><span class="pre">read_image</span></code> - read into a gil image with no conversion.
  219. Memory is allocated.</li>
  220. <li><code class="docutils literal"><span class="pre">read_view</span></code> - read into a gil view with no conversion.</li>
  221. <li><code class="docutils literal"><span class="pre">read_and_convert_image</span></code> - read and convert into a gil image.
  222. Memory is allocated.</li>
  223. <li><code class="docutils literal"><span class="pre">read_and_convert_view</span></code> - read and convert into a gil view.</li>
  224. <li><code class="docutils literal"><span class="pre">read_image_info</span></code> - read the image header.</li>
  225. </ul>
  226. <p>Conversion in this context is necessary if the source (file) has an
  227. incompatible color space with the destination (gil image type).
  228. If that&#8217;s the case the user has to use the xxx_and_convert_xxx variants.</p>
  229. <p>All functions take the filename or a device as the first parameter.
  230. The filename can be anything from a C-string, <code class="docutils literal"><span class="pre">std::string</span></code>,
  231. <code class="docutils literal"><span class="pre">std::wstring</span></code> and <code class="docutils literal"><span class="pre">boost::filesystem</span></code> path. When using the path
  232. object the user needs to define the ADD_FS_PATH_SUPPORT compiler symbol to
  233. include the boost::filesystem dependency.
  234. Devices could be a <code class="docutils literal"><span class="pre">FILE*</span></code>, <code class="docutils literal"><span class="pre">std::ifstream</span></code>, and <code class="docutils literal"><span class="pre">TIFF*</span></code> for TIFF images.</p>
  235. <p>The second parameter is either an image or view type depending on the
  236. <code class="docutils literal"><span class="pre">read_xxx</span></code> function.
  237. The third and last parameter is either an instance of the
  238. <code class="docutils literal"><span class="pre">image_read_settings&lt;FormatTag&gt;</span></code> or just the <code class="docutils literal"><span class="pre">FormatTag</span></code>.
  239. The settings can be various depending on the format which is being read.
  240. But the all share settings for reading a partial image area.
  241. The first point describes the top left image coordinate whereas the second
  242. are the dimensions in x and y directions.</p>
  243. <p>Here an example of setting up partial read:</p>
  244. <div class="highlight-c++"><div class="highlight"><pre><span class="n">read_image</span><span class="p">(</span> <span class="n">filename</span>
  245. <span class="p">,</span> <span class="n">img</span>
  246. <span class="p">,</span> <span class="n">image_read_settings</span><span class="o">&lt;</span> <span class="n">tiff_tag</span> <span class="o">&gt;</span><span class="p">(</span> <span class="n">point_t</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> <span class="p">),</span> <span class="n">point_t</span><span class="p">(</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">50</span> <span class="p">)</span> <span class="p">)</span>
  247. <span class="p">);</span>
  248. </pre></div>
  249. </div>
  250. <p>Each format supports reading just the header information,
  251. using <code class="docutils literal"><span class="pre">read_image_info</span></code>. Please refer to the format specific sections
  252. under 3.3. A basic example follows:</p>
  253. <div class="highlight-c++"><div class="highlight"><pre><span class="n">image_read_info</span><span class="o">&lt;</span> <span class="n">tiff_t</span> <span class="o">&gt;</span> <span class="n">info</span> <span class="o">=</span> <span class="n">read_image_info</span><span class="p">(</span> <span class="n">filename</span>
  254. <span class="p">,</span> <span class="n">tiff_t</span><span class="p">()</span>
  255. <span class="p">);</span>
  256. </pre></div>
  257. </div>
  258. <p>GIL also comes with a dynamic image extension.
  259. In the context of GIL.IO a user can define an <code class="docutils literal"><span class="pre">any_image</span></code> type based on
  260. several image types. The IO extension would then pick the matching image type
  261. to the current image file.
  262. The following example shows this feature:</p>
  263. <div class="highlight-c++"><div class="highlight"><pre><span class="k">typedef</span> <span class="n">mpl</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span> <span class="n">gray8_image_t</span>
  264. <span class="p">,</span> <span class="n">gray16_image_t</span>
  265. <span class="p">,</span> <span class="n">rgb8_image_t</span>
  266. <span class="p">,</span> <span class="n">rgba_image_t</span>
  267. <span class="o">&gt;</span> <span class="n">my_img_types</span><span class="p">;</span>
  268. <span class="n">any_image</span><span class="o">&lt;</span> <span class="n">my_img_types</span> <span class="o">&gt;</span> <span class="n">runtime_image</span><span class="p">;</span>
  269. <span class="n">read_image</span><span class="p">(</span> <span class="n">filename</span>
  270. <span class="p">,</span> <span class="n">runtime_image</span>
  271. <span class="p">,</span> <span class="n">tiff_tag</span><span class="p">()</span>
  272. <span class="p">);</span>
  273. </pre></div>
  274. </div>
  275. <p>During the review it became clear that there is a need to read big images
  276. scanline by scanline. To support such use case a <code class="docutils literal"><span class="pre">scanline_reader</span></code> is
  277. implemented for all supported image formats.
  278. The <code class="docutils literal"><span class="pre">scanline_read_iterators</span></code> will then allow to traverse through the image.
  279. The following code sample shows the usage:</p>
  280. <div class="highlight-c++"><div class="highlight"><pre><span class="k">typedef</span> <span class="n">tiff_tag</span> <span class="n">tag_t</span><span class="p">;</span>
  281. <span class="k">typedef</span> <span class="n">scanline_reader</span><span class="o">&lt;</span> <span class="k">typename</span> <span class="n">get_read_device</span><span class="o">&lt;</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span>
  282. <span class="p">,</span> <span class="n">tag_t</span>
  283. <span class="o">&gt;::</span><span class="n">type</span>
  284. <span class="p">,</span> <span class="n">tag_t</span>
  285. <span class="o">&gt;</span> <span class="n">reader_t</span><span class="p">;</span>
  286. <span class="n">reader_t</span> <span class="n">reader</span> <span class="o">=</span> <span class="n">make_scanline_reader</span><span class="p">(</span> <span class="s">&quot;C:/boost/libs/gil/test/extension/io/images/tiff/test.tif&quot;</span><span class="p">,</span> <span class="n">tag_t</span><span class="p">()</span> <span class="p">);</span>
  287. <span class="k">typedef</span> <span class="n">rgba8_image_t</span> <span class="n">image_t</span><span class="p">;</span>
  288. <span class="n">image_t</span> <span class="nf">dst</span><span class="p">(</span> <span class="n">reader</span><span class="p">.</span><span class="n">_info</span><span class="p">.</span><span class="n">_width</span><span class="p">,</span> <span class="n">reader</span><span class="p">.</span><span class="n">_info</span><span class="p">.</span><span class="n">_height</span> <span class="p">);</span>
  289. <span class="n">fill_pixels</span><span class="p">(</span> <span class="n">view</span><span class="p">(</span><span class="n">dst</span><span class="p">),</span> <span class="n">image_t</span><span class="o">::</span><span class="n">value_type</span><span class="p">()</span> <span class="p">);</span>
  290. <span class="k">typedef</span> <span class="n">reader_t</span><span class="o">::</span><span class="n">iterator_t</span> <span class="n">iterator_t</span><span class="p">;</span>
  291. <span class="n">iterator_t</span> <span class="n">it</span> <span class="o">=</span> <span class="n">reader</span><span class="p">.</span><span class="n">begin</span><span class="p">();</span>
  292. <span class="n">iterator_t</span> <span class="n">end</span> <span class="o">=</span> <span class="n">reader</span><span class="p">.</span><span class="n">end</span><span class="p">();</span>
  293. <span class="k">for</span><span class="p">(</span> <span class="kt">int</span> <span class="n">row</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">it</span> <span class="o">!=</span> <span class="n">end</span><span class="p">;</span> <span class="o">++</span><span class="n">it</span><span class="p">,</span> <span class="o">++</span><span class="n">row</span> <span class="p">)</span>
  294. <span class="p">{</span>
  295. <span class="n">copy_pixels</span><span class="p">(</span> <span class="n">interleaved_view</span><span class="p">(</span> <span class="n">reader</span><span class="p">.</span><span class="n">_info</span><span class="p">.</span><span class="n">_width</span>
  296. <span class="p">,</span> <span class="mi">1</span>
  297. <span class="p">,</span> <span class="p">(</span> <span class="n">image_t</span><span class="o">::</span><span class="n">view_t</span><span class="o">::</span><span class="n">x_iterator</span> <span class="p">)</span> <span class="o">*</span><span class="n">it</span>
  298. <span class="p">,</span> <span class="n">reader</span><span class="p">.</span><span class="n">_scanline_length</span>
  299. <span class="p">)</span>
  300. <span class="p">,</span> <span class="n">subimage_view</span><span class="p">(</span> <span class="n">view</span><span class="p">(</span> <span class="n">dst</span> <span class="p">)</span>
  301. <span class="p">,</span> <span class="mi">0</span>
  302. <span class="p">,</span> <span class="n">row</span>
  303. <span class="p">,</span> <span class="n">reader</span><span class="p">.</span><span class="n">_info</span><span class="p">.</span><span class="n">_width</span>
  304. <span class="p">,</span> <span class="mi">1</span>
  305. <span class="p">)</span>
  306. <span class="p">);</span>
  307. <span class="p">}</span>
  308. </pre></div>
  309. </div>
  310. <p>There are many ways to traverse an image but for as of now only by
  311. scanline is supported.</p>
  312. </div>
  313. <div class="section" id="write-interface">
  314. <h3>Write Interface</h3>
  315. <p>There is only one function for writing out images, write_view.
  316. Similar to reading the first parameter is either a filename or a device.
  317. The filename can be anything from a C-string, <code class="docutils literal"><span class="pre">std::string</span></code>,
  318. <code class="docutils literal"><span class="pre">std::wstring</span></code>, and <code class="docutils literal"><span class="pre">boost::filesystem</span></code> path. When using the path object
  319. the user needs to define the <code class="docutils literal"><span class="pre">ADD_FS_PATH_SUPPORT</span></code> compiler symbol to
  320. include the <code class="docutils literal"><span class="pre">boost::filesystem</span></code> dependency.
  321. Devices could be <code class="docutils literal"><span class="pre">FILE*</span></code>, <code class="docutils literal"><span class="pre">std::ifstream</span></code>, and <code class="docutils literal"><span class="pre">TIFF*</span></code> for TIFF images.</p>
  322. <p>The second parameter is an view object to image being written.
  323. The third and last parameter is either a tag or an
  324. <code class="docutils literal"><span class="pre">image_write_info&lt;FormatTag&gt;</span></code> object containing more settings.
  325. One example for instance is the JPEG quality.
  326. Refer to the format specific sections under 3.3. to have a list of all
  327. the possible settings.</p>
  328. <p>Writing an any_image&lt;...&gt; is supported. See the following example:</p>
  329. <div class="highlight-c++"><div class="highlight"><pre><span class="k">typedef</span> <span class="n">mpl</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span> <span class="n">gray8_image_t</span>
  330. <span class="p">,</span> <span class="n">gray16_image_t</span>
  331. <span class="p">,</span> <span class="n">rgb8_image_t</span>
  332. <span class="p">,</span> <span class="n">rgba_image_t</span>
  333. <span class="o">&gt;</span> <span class="n">my_img_types</span><span class="p">;</span>
  334. <span class="n">any_image</span><span class="o">&lt;</span> <span class="n">my_img_types</span> <span class="o">&gt;</span> <span class="n">runtime_image</span><span class="p">;</span>
  335. <span class="c1">// fill any_image</span>
  336. <span class="n">write_view</span><span class="p">(</span> <span class="n">filename</span>
  337. <span class="p">,</span> <span class="n">view</span><span class="p">(</span> <span class="n">runtime_image</span> <span class="p">)</span>
  338. <span class="p">,</span> <span class="n">tiff_tag</span><span class="p">()</span>
  339. <span class="p">);</span>
  340. </pre></div>
  341. </div>
  342. </div>
  343. <div class="section" id="compiler-symbols">
  344. <h3>Compiler Symbols</h3>
  345. <p>The following table gives an overview of all supported compiler symbols
  346. that can be set by the user:</p>
  347. <table border="1" class="docutils">
  348. <colgroup>
  349. <col width="34%" />
  350. <col width="66%" />
  351. </colgroup>
  352. <thead valign="bottom">
  353. <tr class="row-odd"><th class="head">Symbol</th>
  354. <th class="head">Description</th>
  355. </tr>
  356. </thead>
  357. <tbody valign="top">
  358. <tr class="row-even"><td>BOOST_GIL_IO_ENABLE_GRAY_ALPHA</td>
  359. <td>Enable the color space &#8220;gray_alpha&#8221;.</td>
  360. </tr>
  361. <tr class="row-odd"><td>BOOST_GIL_IO_ADD_FS_PATH_SUPPORT</td>
  362. <td>Enable boost::filesystem 3.0 library.</td>
  363. </tr>
  364. <tr class="row-even"><td>BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED</td>
  365. <td>Use libpng in floating point mode. This symbol is incompatible with BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED.</td>
  366. </tr>
  367. <tr class="row-odd"><td>BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED</td>
  368. <td>Use libpng in integer mode. This symbol is incompatible with BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED.</td>
  369. </tr>
  370. <tr class="row-even"><td>BOOST_GIL_IO_PNG_DITHERING_SUPPORTED</td>
  371. <td>Look up &#8220;dithering&#8221; in libpng manual for explanation.</td>
  372. </tr>
  373. <tr class="row-odd"><td>BOOST_GIL_IO_PNG_1_4_OR_LOWER</td>
  374. <td>Allow compiling with libpng 1.4 or lower.</td>
  375. </tr>
  376. <tr class="row-even"><td>BOOST_GIL_EXTENSION_IO_JPEG_C_LIB_COMPILED_AS_CPLUSPLUS</td>
  377. <td>libjpeg is compiled as c++ lib.</td>
  378. </tr>
  379. <tr class="row-odd"><td>BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS</td>
  380. <td>libpng is compiled as c++ lib.</td>
  381. </tr>
  382. <tr class="row-even"><td>BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS</td>
  383. <td>libtiff is compiled as c++ lib.</td>
  384. </tr>
  385. <tr class="row-odd"><td>BOOST_GIL_EXTENSION_IO_ZLIB_C_LIB_COMPILED_AS_CPLUSPLUS</td>
  386. <td>zlib is compiled as c++ lib.</td>
  387. </tr>
  388. <tr class="row-even"><td>BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES</td>
  389. <td>Allow basic test images to be read from local hard drive. The paths can be set in paths.hpp</td>
  390. </tr>
  391. <tr class="row-odd"><td>BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES</td>
  392. <td>Allow images to be written to the local hard drive. The paths can be set in paths.hpp</td>
  393. </tr>
  394. <tr class="row-even"><td>BOOST_GIL_IO_USE_BMP_TEST_SUITE_IMAGES</td>
  395. <td>Run tests using the bmp test images suite. See _BMP_TEST_FILES</td>
  396. </tr>
  397. <tr class="row-odd"><td>BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES</td>
  398. <td>Run tests using the png test images suite. See _PNG_TEST_FILES</td>
  399. </tr>
  400. <tr class="row-even"><td>BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES</td>
  401. <td>Run tests using the pnm test images suite. Send me an email for accessing the files.</td>
  402. </tr>
  403. <tr class="row-odd"><td>BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES</td>
  404. <td>Run tests using the targa file format test images suite. See _TARGA_TEST_FILES</td>
  405. </tr>
  406. <tr class="row-even"><td>BOOST_GIL_IO_USE_TIFF_LIBTIFF_TEST_SUITE_IMAGES</td>
  407. <td>Run tests using the targa file format test images suite. See _TIFF_LIB_TIFF_TEST_FILES</td>
  408. </tr>
  409. <tr class="row-odd"><td>BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES</td>
  410. <td>Run tests using the targa file format test images suite. See _TIFF_GRAPHICSMAGICK_TEST_FILES</td>
  411. </tr>
  412. </tbody>
  413. </table>
  414. </div>
  415. <div class="section" id="supported-image-formats">
  416. <h3>Supported Image Formats</h3>
  417. <div class="section" id="bmp">
  418. <h4>BMP</h4>
  419. <p>For a general overview of the BMP image file format go to the
  420. following <a class="reference external" href="http://en.wikipedia.org/wiki/BMP_file_format">BMP_Wiki</a>.</p>
  421. <p>Please note, the code has not been tested on X Windows System variations
  422. of the BMP format which are usually referred to XBM and XPM formats.</p>
  423. <p>Here, only the MS Windows and OS/2 format is relevant.</p>
  424. <p>Currently the code is able to read and write the following image types:</p>
  425. <table class="docutils field-list" frame="void" rules="none">
  426. <col class="field-name" />
  427. <col class="field-body" />
  428. <tbody valign="top">
  429. <tr class="field-odd field"><th class="field-name">Read:</th><td class="field-body"><code class="docutils literal"><span class="pre">gray1_image_t</span></code>, <code class="docutils literal"><span class="pre">gray4_image_t</span></code>, <code class="docutils literal"><span class="pre">gray8_image_t</span></code>, <code class="docutils literal"><span class="pre">rgb8_image_t</span></code> and, <code class="docutils literal"><span class="pre">rgba8_image_t</span></code></td>
  430. </tr>
  431. <tr class="field-even field"><th class="field-name">Write:</th><td class="field-body"><code class="docutils literal"><span class="pre">rgb8_image_t</span></code> and, <code class="docutils literal"><span class="pre">rgba8_image_t</span></code></td>
  432. </tr>
  433. </tbody>
  434. </table>
  435. <p>The lack of having an indexed image type in gil restricts the current
  436. interface to only write out non-indexed images.
  437. This is subject to change soon.</p>
  438. </div>
  439. <div class="section" id="jpeg">
  440. <h4>JPEG</h4>
  441. <p>For a general overview of the JPEG image file format go to the
  442. following <a class="reference external" href="http://en.wikipedia.org/wiki/JPEG">JPEG_Wiki</a>.</p>
  443. <p>This jpeg extension is based on the libjpeg library which can be
  444. found here, <a class="reference external" href="http://www.ijg.org/">JPEG_Lib</a>.</p>
  445. <p>All versions starting from 8x are supported.</p>
  446. <p>The user has to make sure this library is properly installed.
  447. I strongly recommend the user to build the library yourself.
  448. It could potentially save you a lot of trouble.</p>
  449. <p>Currently the code is able to read and write the following image types:</p>
  450. <table class="docutils field-list" frame="void" rules="none">
  451. <col class="field-name" />
  452. <col class="field-body" />
  453. <tbody valign="top">
  454. <tr class="field-odd field"><th class="field-name">Read:</th><td class="field-body"><code class="docutils literal"><span class="pre">gray8_image_t</span></code>, <code class="docutils literal"><span class="pre">rgb8_image_t</span></code>, <code class="docutils literal"><span class="pre">cmyk8_image_t</span></code></td>
  455. </tr>
  456. <tr class="field-even field"><th class="field-name">Write:</th><td class="field-body"><code class="docutils literal"><span class="pre">gray8_image_t</span></code>, <code class="docutils literal"><span class="pre">rgb8_image_t</span></code>, <code class="docutils literal"><span class="pre">cmyk8_image_t</span></code></td>
  457. </tr>
  458. </tbody>
  459. </table>
  460. <p>Reading YCbCr or YCCK images is possible but might result in inaccuracies since
  461. both color spaces aren&#8217;t available yet for gil.
  462. For now these color space are read as rgb images.
  463. This is subject to change soon.</p>
  464. </div>
  465. <div class="section" id="png">
  466. <h4>PNG</h4>
  467. <p>For a general overview of the PNG image file format go to the
  468. following <a class="reference external" href="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG_Wiki</a>.</p>
  469. <p>This png extension is based on the libpng, which can be found
  470. here, <a class="reference external" href="http://libpng.org/pub/png/libpng.html">PNG_Lib</a>.</p>
  471. <p>All versions starting from 1.5.x are supported.</p>
  472. <p>The user has to make sure this library is properly installed.
  473. I strongly recommend the user to build the library yourself.
  474. It could potentially save you a lot of trouble.</p>
  475. <p>Currently the code is able to read and write the following image types:</p>
  476. <table class="docutils field-list" frame="void" rules="none">
  477. <col class="field-name" />
  478. <col class="field-body" />
  479. <tbody valign="top">
  480. <tr class="field-odd field"><th class="field-name">Read:</th><td class="field-body">gray1, gray2, gray4, gray8, gray16, gray_alpha_8, gray_alpha_16, rgb8, rgb16, rgba8, rgba16</td>
  481. </tr>
  482. <tr class="field-even field"><th class="field-name">Write:</th><td class="field-body">gray1, gray2, gray4, gray8, gray16, gray_alpha_8, gray_alpha_16, rgb8, rgb16, rgba8, rgba16</td>
  483. </tr>
  484. </tbody>
  485. </table>
  486. <p>For reading gray_alpha images the user has to compile application with <code class="docutils literal"><span class="pre">BOOST_GIL_IO_ENABLE_GRAY_ALPHA</span></code>
  487. macro defined. This color space is defined in the toolbox by using <code class="docutils literal"><span class="pre">gray_alpha.hpp</span></code>.</p>
  488. </div>
  489. <div class="section" id="pnm">
  490. <h4>PNM</h4>
  491. <p>For a general overview of the PNM image file format go to the
  492. following <a class="reference external" href="http://en.wikipedia.org/wiki/Portable_anymap">PNM_Wiki</a>. No external library is needed for the pnm format.</p>
  493. <p>The extension can read images in both flavours of the formats, ASCII and binary,
  494. that is types from P1 through P6; can write only binary formats.</p>
  495. <p>Currently the code is able to read and write the following image types:</p>
  496. <table class="docutils field-list" frame="void" rules="none">
  497. <col class="field-name" />
  498. <col class="field-body" />
  499. <tbody valign="top">
  500. <tr class="field-odd field"><th class="field-name">Read:</th><td class="field-body">gray1, gray8, rgb8</td>
  501. </tr>
  502. <tr class="field-even field"><th class="field-name">Write:</th><td class="field-body">gray1, gray8, rgb8</td>
  503. </tr>
  504. </tbody>
  505. </table>
  506. <p>When reading a mono text image the data is read as a gray8 image.</p>
  507. </div>
  508. <div class="section" id="raw">
  509. <h4>RAW</h4>
  510. <p>For a general overview see <a class="reference external" href="http://en.wikipedia.org/wiki/Raw_image_format">RAW_Wiki</a>.</p>
  511. <p>Currently the extension is only able to read rgb8 images.</p>
  512. </div>
  513. <div class="section" id="targa">
  514. <h4>TARGA</h4>
  515. <p>For a general overview of the BMP image file format go to the
  516. following <a class="reference external" href="http://en.wikipedia.org/wiki/Truevision_TGA">TARGA_Wiki</a>.</p>
  517. <p>Currently the code is able to read and write the following image types:</p>
  518. <table class="docutils field-list" frame="void" rules="none">
  519. <col class="field-name" />
  520. <col class="field-body" />
  521. <tbody valign="top">
  522. <tr class="field-odd field"><th class="field-name">Read:</th><td class="field-body">rgb8_image_t and rgba8_image_t</td>
  523. </tr>
  524. <tr class="field-even field"><th class="field-name">Write:</th><td class="field-body">rgb8_image_t and rgba8_image_t</td>
  525. </tr>
  526. </tbody>
  527. </table>
  528. <p>The lack of having an indexed image type in gil restricts the current
  529. interface to only write out non-indexed images.
  530. This is subject to change soon.</p>
  531. </div>
  532. <div class="section" id="tiff">
  533. <h4>TIFF</h4>
  534. <p>For a general overview of the TIFF image file format go to the
  535. following <a class="reference external" href="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF_Wiki</a>.</p>
  536. <p>This tiff extension is based on the libtiff, which can be found, <a class="reference external" href="http://www.remotesensing.org/libtiff/">TIFF_Lib</a>.</p>
  537. <p>All versions starting from 3.9.x are supported.</p>
  538. <p>The user has to make sure this library is properly installed. I strongly
  539. recommend the user to build the library yourself. It could potentially
  540. save you a lot of trouble.</p>
  541. <p>TIFF images can virtually encode all kinds of channel sizes representing
  542. various color spaces. Even planar images are possible.
  543. For instance, <code class="docutils literal"><span class="pre">rbg323</span></code> or <code class="docutils literal"><span class="pre">gray7</span></code>. The channels also can have specific
  544. formats, like integer values or floating point values.</p>
  545. <p>For a complete set of options please consult the following websites:</p>
  546. <ul class="simple">
  547. <li><a class="reference external" href="http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html">TIFF_Base_Tags</a></li>
  548. <li><a class="reference external" href="http://www.awaresystems.be/imaging/tiff/tifftags/extension.html">TIFF_Extension_Tags</a></li>
  549. </ul>
  550. <p>The author of this extension is not claiming all tiff formats are supported.
  551. This extension is likely to be a moving target adding new features with each
  552. new milestone. Here is an incomplete lists:</p>
  553. <ul class="simple">
  554. <li>Multi-page TIFF - read only</li>
  555. <li>Strip TIFF - read and write support</li>
  556. <li>Tiled TIFF - read and write support with user defined tiled sizes</li>
  557. <li>Bit images TIFF - fully supported, like <code class="docutils literal"><span class="pre">gray1_image_t</span></code> (minisblack)</li>
  558. <li>Planar TIFF - fully supported</li>
  559. <li>Floating-point TIFF - fully supported</li>
  560. <li>Palette TIFF - supported but no indexed image type is available as of now</li>
  561. </ul>
  562. <p>This gil extension uses two different test image suites to test read and
  563. write capabilities. See <code class="docutils literal"><span class="pre">test_image</span></code> folder.
  564. It&#8217;s advisable to use ImageMagick test viewer to display images.</p>
  565. </div>
  566. </div>
  567. <div class="section" id="extending-gil-io-with-new-formats">
  568. <h3>Extending GIL::IO with new Formats</h3>
  569. <p>Extending the gil::io with new formats is meant to be simple and
  570. straightforward. Before adding I would recommend to have a look at existing
  571. implementations and then trying to follow a couple of guidelines:</p>
  572. <ul>
  573. <li><dl class="first docutils">
  574. <dt>Create the following files for your new xxx format</dt>
  575. <dd><ul class="first last simple">
  576. <li><code class="docutils literal"><span class="pre">xxx_read.hpp</span></code> - Only includes read code</li>
  577. <li><code class="docutils literal"><span class="pre">xxx_write.hpp</span></code> - Only includes write code</li>
  578. <li><code class="docutils literal"><span class="pre">xxx_all.hpp</span></code> - includes xxx_read.hpp and xxx_write.hpp</li>
  579. </ul>
  580. </dd>
  581. </dl>
  582. </li>
  583. <li><p class="first">Add the code to the <code class="docutils literal"><span class="pre">boost::gil::detail</span></code> namespace</p>
  584. </li>
  585. <li><p class="first">Create a tag type for the new format. Like this:</p>
  586. <div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="nl">xxx_tag</span> <span class="p">:</span> <span class="n">format_tag</span> <span class="p">{};</span>
  587. </pre></div>
  588. </div>
  589. </li>
  590. <li><p class="first">Create the image_read_info for the new format. It contains all the
  591. information that are necessary to read an image. It should be filled
  592. and returned by the <code class="docutils literal"><span class="pre">get_info</span></code> member of the reader class. See below:</p>
  593. <div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;&gt;</span> <span class="k">struct</span> <span class="n">image_read_info</span><span class="o">&lt;</span> <span class="n">xxx_tag</span> <span class="o">&gt;</span> <span class="p">{};</span>
  594. </pre></div>
  595. </div>
  596. </li>
  597. <li><p class="first">Create the image_write_info for the new format. It contains all the
  598. information that are necessary to write an image:</p>
  599. <div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;&gt;</span> <span class="k">struct</span> <span class="n">image_write_info</span><span class="o">&lt;</span> <span class="n">xxx_tag</span> <span class="o">&gt;</span> <span class="p">{};</span>
  600. </pre></div>
  601. </div>
  602. </li>
  603. <li><p class="first">Use the following reader skeleton as a start:</p>
  604. <div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;</span> <span class="k">typename</span> <span class="n">Device</span>
  605. <span class="p">,</span> <span class="k">typename</span> <span class="n">ConversionPolicy</span>
  606. <span class="o">&gt;</span>
  607. <span class="k">class</span> <span class="nc">reader</span><span class="o">&lt;</span> <span class="n">Device</span>
  608. <span class="p">,</span> <span class="n">xxx_tag</span>
  609. <span class="p">,</span> <span class="n">ConversionPolicy</span>
  610. <span class="o">&gt;</span>
  611. <span class="o">:</span> <span class="k">public</span> <span class="n">reader_base</span><span class="o">&lt;</span> <span class="n">xxx_tag</span>
  612. <span class="p">,</span> <span class="n">ConversionPolicy</span>
  613. <span class="o">&gt;</span>
  614. <span class="p">{</span>
  615. <span class="k">private</span><span class="o">:</span>
  616. <span class="k">typedef</span> <span class="k">typename</span> <span class="n">ConversionPolicy</span><span class="o">::</span><span class="n">color_converter_type</span> <span class="n">cc_t</span><span class="p">;</span>
  617. <span class="k">public</span><span class="o">:</span>
  618. <span class="n">reader</span><span class="p">(</span> <span class="n">Device</span><span class="o">&amp;</span> <span class="n">device</span> <span class="p">)</span>
  619. <span class="o">:</span> <span class="n">_io_dev</span><span class="p">(</span> <span class="n">device</span> <span class="p">)</span>
  620. <span class="p">{}</span>
  621. <span class="n">reader</span><span class="p">(</span> <span class="n">Device</span><span class="o">&amp;</span> <span class="n">device</span>
  622. <span class="p">,</span> <span class="k">const</span> <span class="n">cc_t</span><span class="o">&amp;</span> <span class="n">cc</span>
  623. <span class="p">)</span>
  624. <span class="o">:</span> <span class="n">_io_dev</span><span class="p">(</span> <span class="n">device</span> <span class="p">)</span>
  625. <span class="p">,</span> <span class="n">reader_base</span><span class="o">&lt;</span> <span class="n">xxx_tag</span>
  626. <span class="p">,</span> <span class="n">ConversionPolicy</span>
  627. <span class="o">&gt;</span><span class="p">(</span> <span class="n">cc</span> <span class="p">)</span>
  628. <span class="p">{}</span>
  629. <span class="n">image_read_info</span><span class="o">&lt;</span> <span class="n">xxx_tag</span> <span class="o">&gt;</span> <span class="n">get_info</span><span class="p">()</span>
  630. <span class="p">{</span>
  631. <span class="c1">// your implementation here</span>
  632. <span class="p">}</span>
  633. <span class="k">template</span><span class="o">&lt;</span> <span class="k">typename</span> <span class="n">View</span> <span class="o">&gt;</span>
  634. <span class="kt">void</span> <span class="n">apply</span><span class="p">(</span> <span class="k">const</span> <span class="n">View</span><span class="o">&amp;</span> <span class="n">dst_view</span> <span class="p">)</span>
  635. <span class="p">{</span>
  636. <span class="c1">// your implementation here</span>
  637. <span class="p">}</span>
  638. <span class="p">};</span>
  639. </pre></div>
  640. </div>
  641. </li>
  642. <li><p class="first">The writer skeleton:</p>
  643. <div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;</span> <span class="k">typename</span> <span class="n">Device</span> <span class="o">&gt;</span>
  644. <span class="k">class</span> <span class="nc">writer</span><span class="o">&lt;</span> <span class="n">Device</span>
  645. <span class="p">,</span> <span class="n">xxx_tag</span>
  646. <span class="o">&gt;</span>
  647. <span class="p">{</span>
  648. <span class="k">public</span><span class="o">:</span>
  649. <span class="n">writer</span><span class="p">(</span> <span class="n">Device</span> <span class="o">&amp;</span> <span class="n">file</span> <span class="p">)</span>
  650. <span class="o">:</span> <span class="n">out</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
  651. <span class="p">{}</span>
  652. <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">View</span><span class="o">&gt;</span>
  653. <span class="kt">void</span> <span class="n">apply</span><span class="p">(</span> <span class="k">const</span> <span class="n">View</span><span class="o">&amp;</span> <span class="n">view</span> <span class="p">)</span>
  654. <span class="p">{</span>
  655. <span class="c1">// your implementation here</span>
  656. <span class="p">}</span>
  657. <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">View</span><span class="o">&gt;</span>
  658. <span class="kt">void</span> <span class="n">apply</span><span class="p">(</span> <span class="k">const</span> <span class="n">View</span><span class="o">&amp;</span> <span class="n">view</span>
  659. <span class="p">,</span> <span class="k">const</span> <span class="n">image_write_info</span><span class="o">&lt;</span> <span class="n">xxx_tag</span> <span class="o">&gt;&amp;</span> <span class="n">info</span> <span class="p">)</span>
  660. <span class="p">{</span>
  661. <span class="c1">// your implementation here</span>
  662. <span class="p">}</span>
  663. <span class="p">};</span>
  664. </pre></div>
  665. </div>
  666. </li>
  667. </ul>
  668. </div>
  669. </div>
  670. <div class="section" id="running-gil-io-tests">
  671. <h2>Running gil::io tests</h2>
  672. <p>gil::io comes with a large suite of test cases which reads and writes various
  673. file formats. It uses some test image suites which can be found online or
  674. which can be demanded from me by sending me an email.</p>
  675. <p>There are some test images created by me in the test folder.
  676. To enable unit tests which make use of them set the following compiler options
  677. <code class="docutils literal"><span class="pre">BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES</span></code> and
  678. <code class="docutils literal"><span class="pre">BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES</span></code>.</p>
  679. <p>The following list provides all links to the image suites the compiler symbol
  680. to enable the tests:</p>
  681. <table class="docutils field-list" frame="void" rules="none">
  682. <col class="field-name" />
  683. <col class="field-body" />
  684. <tbody valign="top">
  685. <tr class="field-odd field"><th class="field-name">BMP:</th><td class="field-body"><a class="reference external" href="http://entropymine.com/jason/bmpsuite/">BMP_TEST_FILES</a> &#8211; BOOST_GIL_IO_USE_BMP_TEST_SUITE_IMAGES</td>
  686. </tr>
  687. <tr class="field-even field"><th class="field-name">PNG:</th><td class="field-body"><a class="reference external" href="http://www.schaik.com/pngsuite/pngsuite.html">PNG_TEST_FILES</a> &#8211; BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES</td>
  688. </tr>
  689. <tr class="field-odd field"><th class="field-name">PNM:</th><td class="field-body">request files from me &#8211; BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES</td>
  690. </tr>
  691. <tr class="field-even field"><th class="field-name">TARGA:</th><td class="field-body"><a class="reference external" href="http://www.fileformat.info/format/tga/sample/index.htm">TARGA_TEST_FILES</a> &#8211; BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES</td>
  692. </tr>
  693. <tr class="field-odd field"><th class="field-name">TIFF:</th><td class="field-body"><a class="reference external" href="http://www.remotesensing.org/libtiff/images.html">TIFF_LIB_TIFF_TEST_FILES</a> &#8211; BOOST_GIL_IO_USE_TIFF_LIBTIFF_TEST_SUITE_IMAGES</td>
  694. </tr>
  695. <tr class="field-even field"><th class="field-name">TIFF:</th><td class="field-body"><a class="reference external" href="ftp://ftp.graphicsmagick.org/pub/tiff-samples/tiff-sample-images-be.tar.gz">TIFF_GRAPHICSMAGICK_TEST_FILES</a> &#8211; BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES</td>
  696. </tr>
  697. </tbody>
  698. </table>
  699. </div>
  700. </div>
  701. <div class="navbar" style="text-align:right;">
  702. <a class="prev" title="Affine region detectors" href="image_processing/affine-region-detectors.html"><img src="_static/prev.png" alt="prev"/></a>
  703. <a class="next" title="ToolBox extension" href="toolbox.html"><img src="_static/next.png" alt="next"/></a>
  704. </div>
  705. </div>
  706. <div class="footer" role="contentinfo">
  707. Last updated on 2019-12-10 00:12:10.
  708. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.6.
  709. </div>
  710. </body>
  711. </html>