3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Using IO</title>
5 <link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
7 <link rel="home" href="../../index.html" title="Chapter 1. Boost.GIL.IO">
8 <link rel="up" href="../../index.html" title="Chapter 1. Boost.GIL.IO">
9 <link rel="prev" href="tutorial.html" title="Tutorial">
10 <link rel="next" href="running_gil__io_tests.html" title="Running gil::io tests">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="tutorial.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="running_gil__io_tests.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
25 <div class="section gil_io_using_io">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="gil.io.using_io"></a><a class="link" href="using_io.html" title="Using IO">Using IO</a>
28 </h2></div></div></div>
30 <a name="gil.io.using_io.h0"></a>
31 <span class="phrase"><a name="gil.io.using_io.general_overview"></a></span><a class="link" href="using_io.html#gil.io.using_io.general_overview">General
35 The tutorial pointed out some use cases for reading and writing images in various
36 image formats. This section will provide a more thorough overview.
39 The next sections will introduce the Read and Write interface. But it might
40 be worth poiting out that by using some advanced metaprogramming techniques
41 the interface is rather small and hopefully easy to understand.
44 Besides the general interface the user also has the ability to interface directly
45 with the underlying image format. For that each reader or writer provides access
46 to the so-called backend. For instance:
48 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">get_reader_backend</span><span class="special"><</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span>
49 <span class="special">,</span> <span class="identifier">tag_t</span>
50 <span class="special">>::</span><span class="identifier">type</span> <span class="identifier">backend_t</span><span class="special">;</span>
52 <span class="identifier">backend_t</span> <span class="identifier">backend</span> <span class="special">=</span> <span class="identifier">read_image_info</span><span class="special">(</span> <span class="identifier">bmp_filename</span>
53 <span class="special">,</span> <span class="identifier">tag_t</span><span class="special">()</span>
54 <span class="special">);</span>
56 <span class="identifier">BOOST_CHECK_EQUAL</span><span class="special">(</span> <span class="identifier">backend</span><span class="special">.</span><span class="identifier">_info</span><span class="special">.</span><span class="identifier">_width</span> <span class="special">,</span> <span class="number">127</span> <span class="special">);</span>
57 <span class="identifier">BOOST_CHECK_EQUAL</span><span class="special">(</span> <span class="identifier">backend</span><span class="special">.</span><span class="identifier">_info</span><span class="special">.</span><span class="identifier">_height</span><span class="special">,</span> <span class="number">64</span> <span class="special">);</span>
60 Of course, the typedef can be removed when using c++11's auto feature.
63 <a name="gil.io.using_io.h1"></a>
64 <span class="phrase"><a name="gil.io.using_io.read_interface"></a></span><a class="link" href="using_io.html#gil.io.using_io.read_interface">Read
68 As the Tutorial demonstrated there are a few ways to read images. Here is an
69 enumeration of all read functions with a short description:
71 <pre class="programlisting"><span class="special">*</span> <span class="identifier">read_image</span> <span class="special">-</span> <span class="identifier">read</span> <span class="identifier">into</span> <span class="identifier">a</span> <span class="identifier">gil</span> <span class="identifier">image</span> <span class="identifier">with</span> <span class="identifier">no</span> <span class="identifier">conversion</span><span class="special">.</span> <span class="identifier">Memory</span> <span class="identifier">is</span> <span class="identifier">allocated</span><span class="special">.</span>
72 <span class="special">*</span> <span class="identifier">read_view</span> <span class="special">-</span> <span class="identifier">read</span> <span class="identifier">into</span> <span class="identifier">a</span> <span class="identifier">gil</span> <span class="identifier">view</span> <span class="identifier">with</span> <span class="identifier">no</span> <span class="identifier">conversion</span><span class="special">.</span>
73 <span class="special">*</span> <span class="identifier">read_and_convert_image</span> <span class="special">-</span> <span class="identifier">read</span> <span class="keyword">and</span> <span class="identifier">convert</span> <span class="identifier">into</span> <span class="identifier">a</span> <span class="identifier">gil</span> <span class="identifier">image</span><span class="special">.</span> <span class="identifier">Memory</span> <span class="identifier">is</span> <span class="identifier">allocated</span><span class="special">.</span>
74 <span class="special">*</span> <span class="identifier">read_and_convert_view</span> <span class="special">-</span> <span class="identifier">read</span> <span class="keyword">and</span> <span class="identifier">convert</span> <span class="identifier">into</span> <span class="identifier">a</span> <span class="identifier">gil</span> <span class="identifier">view</span><span class="special">.</span>
75 <span class="special">*</span> <span class="identifier">read_image_info</span> <span class="special">-</span> <span class="identifier">read</span> <span class="identifier">the</span> <span class="identifier">image</span> <span class="identifier">header</span><span class="special">.</span>
78 Conversion in this context is necessary if the source ( file ) has an incompatible
79 color space with the destination ( gil image type ). If that's the case the
80 user has to use the xxx_and_convert_xxx variants.
83 All functions take the filename or a device as the first parameter. The filename
84 can be anything from a c string, std::string, std::wstring, and a boost::filesystem
85 path. When using the path object the user needs to define the ADD_FS_PATH_SUPPORT
86 compiler symbol to include the boost::filesystem dependency. Devices could
87 be a FILE*, std::ifstream, and a TIFF* for TIFF images.
90 The second parameter is either an image or view type depending on the read_xxx
91 function. The third and last parameter is either an instance of the image_read_settings<FormatTag>
92 or just the FormatTag. The settings can be various depending on the format
93 which is being read. But the all share settings for reading a partial image
94 area. The first point describes the top left image coordinate whereas the second
95 are the dimensions in x and y directions. Here an example of setting up partial
98 <pre class="programlisting"><span class="identifier">read_image</span><span class="special">(</span> <span class="identifier">filename</span>
99 <span class="special">,</span> <span class="identifier">img</span>
100 <span class="special">,</span> <span class="identifier">image_read_settings</span><span class="special"><</span> <span class="identifier">tiff_tag</span> <span class="special">>(</span> <span class="identifier">point_t</span><span class="special">(</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span> <span class="special">),</span> <span class="identifier">point_t</span><span class="special">(</span> <span class="number">50</span><span class="special">,</span> <span class="number">50</span> <span class="special">)</span> <span class="special">)</span>
101 <span class="special">);</span>
104 Each format supports reading just the header information, using read_image_info().
105 Please refer to the format specific sections under 3.3. A basic example follows:
107 <pre class="programlisting"><span class="identifier">image_read_info</span><span class="special"><</span> <span class="identifier">tiff_t</span> <span class="special">></span> <span class="identifier">info</span> <span class="special">=</span> <span class="identifier">read_image_info</span><span class="special">(</span> <span class="identifier">filename</span>
108 <span class="special">,</span> <span class="identifier">tiff_t</span><span class="special">()</span>
109 <span class="special">);</span>
112 GIL also comes with a dynamic image extension. In the context of GIL.IO a user
113 can define an any_image type based on several image types. The IO extension
114 would then pick the matching image type to the current image file. The following
115 example shows this feature:
117 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">gray8_image_t</span>
118 <span class="special">,</span> <span class="identifier">gray16_image_t</span>
119 <span class="special">,</span> <span class="identifier">rgb8_image_t</span>
120 <span class="special">,</span> <span class="identifier">rgba_image_t</span>
121 <span class="special">></span> <span class="identifier">my_img_types</span><span class="special">;</span>
123 <span class="identifier">any_image</span><span class="special"><</span> <span class="identifier">my_img_types</span> <span class="special">></span> <span class="identifier">runtime_image</span><span class="special">;</span>
125 <span class="identifier">read_image</span><span class="special">(</span> <span class="identifier">filename</span>
126 <span class="special">,</span> <span class="identifier">runtime_image</span>
127 <span class="special">,</span> <span class="identifier">tiff_tag</span><span class="special">()</span>
128 <span class="special">);</span>
131 During the review it became clear that there is a need to read big images scanline
132 by scanline. To support such use case a scanline_reader is implemented for
133 all supported image formats. The scanline_read_iterators will then allow to
134 traverse through the image. The following code sample shows the usage:
136 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">tiff_tag</span> <span class="identifier">tag_t</span><span class="special">;</span>
138 <span class="keyword">typedef</span> <span class="identifier">scanline_reader</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">get_read_device</span><span class="special"><</span> <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span>
139 <span class="special">,</span> <span class="identifier">tag_t</span>
140 <span class="special">>::</span><span class="identifier">type</span>
141 <span class="special">,</span> <span class="identifier">tag_t</span>
142 <span class="special">></span> <span class="identifier">reader_t</span><span class="special">;</span>
144 <span class="identifier">reader_t</span> <span class="identifier">reader</span> <span class="special">=</span> <span class="identifier">make_scanline_reader</span><span class="special">(</span> <span class="string">"C:/boost/libs/gil/io/test_images/tiff/test.tif"</span><span class="special">,</span> <span class="identifier">tag_t</span><span class="special">()</span> <span class="special">);</span>
146 <span class="keyword">typedef</span> <span class="identifier">rgba8_image_t</span> <span class="identifier">image_t</span><span class="special">;</span>
148 <span class="identifier">image_t</span> <span class="identifier">dst</span><span class="special">(</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">_info</span><span class="special">.</span><span class="identifier">_width</span><span class="special">,</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">_info</span><span class="special">.</span><span class="identifier">_height</span> <span class="special">);</span>
149 <span class="identifier">fill_pixels</span><span class="special">(</span> <span class="identifier">view</span><span class="special">(</span><span class="identifier">dst</span><span class="special">),</span> <span class="identifier">image_t</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">()</span> <span class="special">);</span>
151 <span class="keyword">typedef</span> <span class="identifier">reader_t</span><span class="special">::</span><span class="identifier">iterator_t</span> <span class="identifier">iterator_t</span><span class="special">;</span>
153 <span class="identifier">iterator_t</span> <span class="identifier">it</span> <span class="special">=</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
154 <span class="identifier">iterator_t</span> <span class="identifier">end</span> <span class="special">=</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
156 <span class="keyword">for</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">row</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">it</span> <span class="special">!=</span> <span class="identifier">end</span><span class="special">;</span> <span class="special">++</span><span class="identifier">it</span><span class="special">,</span> <span class="special">++</span><span class="identifier">row</span> <span class="special">)</span>
157 <span class="special">{</span>
158 <span class="identifier">copy_pixels</span><span class="special">(</span> <span class="identifier">interleaved_view</span><span class="special">(</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">_info</span><span class="special">.</span><span class="identifier">_width</span>
159 <span class="special">,</span> <span class="number">1</span>
160 <span class="special">,</span> <span class="special">(</span> <span class="identifier">image_t</span><span class="special">::</span><span class="identifier">view_t</span><span class="special">::</span><span class="identifier">x_iterator</span> <span class="special">)</span> <span class="special">*</span><span class="identifier">it</span>
161 <span class="special">,</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">_scanline_length</span>
162 <span class="special">)</span>
163 <span class="special">,</span> <span class="identifier">subimage_view</span><span class="special">(</span> <span class="identifier">view</span><span class="special">(</span> <span class="identifier">dst</span> <span class="special">)</span>
164 <span class="special">,</span> <span class="number">0</span>
165 <span class="special">,</span> <span class="identifier">row</span>
166 <span class="special">,</span> <span class="identifier">reader</span><span class="special">.</span><span class="identifier">_info</span><span class="special">.</span><span class="identifier">_width</span>
167 <span class="special">,</span> <span class="number">1</span>
168 <span class="special">)</span>
169 <span class="special">);</span>
170 <span class="special">}</span>
173 There are many ways to travese an image but for as of now only by scanline
177 <a name="gil.io.using_io.h2"></a>
178 <span class="phrase"><a name="gil.io.using_io.write_interface"></a></span><a class="link" href="using_io.html#gil.io.using_io.write_interface">Write
182 There is only one function for writing out images, write_view. Similar to reading
183 the first parameter is either a filename or a device. The filename can be anything
184 from a c string, std::string, std::wstring, and a boost::filesystem path. When
185 using the path object the user needs to define the ADD_FS_PATH_SUPPORT compiler
186 symbol to include the boost::filesystem dependency. Devices could be a FILE*,
187 std::ifstream, and a TIFF* for TIFF images.
190 The second parameter is an view object to image being written. The third and
191 last parameter is either a tag or an image_write_info< FormatTag > object
192 containing more settings. One example for instance is the jpeg quality. Refer
193 to the format specific sections under 3.3. to have a list of all the possible
197 Writing an any_image<...> is supported. See the following example:
199 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">gray8_image_t</span>
200 <span class="special">,</span> <span class="identifier">gray16_image_t</span>
201 <span class="special">,</span> <span class="identifier">rgb8_image_t</span>
202 <span class="special">,</span> <span class="identifier">rgba_image_t</span>
203 <span class="special">></span> <span class="identifier">my_img_types</span><span class="special">;</span>
206 <span class="identifier">any_image</span><span class="special"><</span> <span class="identifier">my_img_types</span> <span class="special">></span> <span class="identifier">runtime_image</span><span class="special">;</span>
208 <span class="comment">// fill any_image </span>
210 <span class="identifier">write_view</span><span class="special">(</span> <span class="identifier">filename</span>
211 <span class="special">,</span> <span class="identifier">view</span><span class="special">(</span> <span class="identifier">runtime_image</span> <span class="special">)</span>
212 <span class="special">,</span> <span class="identifier">tiff_tag</span><span class="special">()</span>
213 <span class="special">);</span>
216 <a name="gil.io.using_io.h3"></a>
217 <span class="phrase"><a name="gil.io.using_io.compiler_symbols"></a></span><a class="link" href="using_io.html#gil.io.using_io.compiler_symbols">Compiler
221 The following table gives an overview of all supported compiler symbols that
222 can be set by the user:
225 <a name="gil.io.using_io.t0"></a><p class="title"><b>Table 1.1. Compiler Symbols</b></p>
226 <div class="table-contents"><table class="table" summary="Compiler Symbols">
247 BOOST_GIL_IO_ENABLE_GRAY_ALPHA
252 Enable the color space "gray_alpha".
259 BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
264 Enable boost::filesystem 3.0 library.
271 BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
276 Use libpng in floating point mode. This symbol is incompatible with
277 BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED.
284 BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
289 Use libpng in integer mode. This symbol is incompatible with BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED.
296 BOOST_GIL_EXTENSION_IO_JPEG_C_LIB_COMPILED_AS_CPLUSPLUS
301 libjpeg is compiled as c++ lib.
308 BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS
313 libpng is compiled as c++ lib.
320 BOOST_GIL_EXTENSION_IO_RAW_C_LIB_COMPILED_AS_CPLUSPLUS
325 libraw is compiled as c++ lib.
332 BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS
337 libtiff is compiled as c++ lib.
344 BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
349 Allow basic test images to be read from local hard drive. The paths
350 can be set in paths.hpp
357 BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
362 Allow images to be written to the local hard drive. The paths can
370 BOOST_GIL_IO_USE_BMP_TEST_SUITE_IMAGES
375 Run tests using the bmp test images suite. See <a href="http://entropymine.com/jason/bmpsuite/" target="_top">http://entropymine.com/jason/bmpsuite/</a>
382 BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
387 Run tests using the png test images suite. See <a href="http://www.schaik.com/pngsuite/pngsuite.html" target="_top">http://www.schaik.com/pngsuite/pngsuite.html</a>
394 BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
399 Run tests using the pnm test images suite. Send me an email for accessing
407 BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES
412 Run tests using the targa file format test images suite. See <a href="http://www.fileformat.info/format/tga/sample/index.htm" target="_top">http://www.fileformat.info/format/tga/sample/index.htm</a>
419 BOOST_GIL_IO_USE_TIFF_LIBTIFF_TEST_SUITE_IMAGES
424 Run tests using the targa file format test images suite. See <a href="http://www.remotesensing.org/libtiff/images.html" target="_top">http://www.remotesensing.org/libtiff/images.html</a>
431 BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
436 Run tests using the targa file format test images suite. See <a href="ftp://ftp.graphicsmagick.org/pub/tiff-samples/tiff-sample-images-be.tar.gz" target="_top">ftp://ftp.graphicsmagick.org/pub/tiff-samples/tiff-sample-images-be.tar.gz</a>
443 <br class="table-break"><h3>
444 <a name="gil.io.using_io.h4"></a>
445 <span class="phrase"><a name="gil.io.using_io.supported_image_formats"></a></span><a class="link" href="using_io.html#gil.io.using_io.supported_image_formats">Supported
449 <a name="gil.io.using_io.h5"></a>
450 <span class="phrase"><a name="gil.io.using_io.bmp"></a></span><a class="link" href="using_io.html#gil.io.using_io.bmp">BMP</a>
453 For a general overview of the BMP image file format go to the following <a href="http://en.wikipedia.org/wiki/BMP_file_format" target="_top">http://en.wikipedia.org/wiki/BMP_file_format</a>.
456 Please note, the code has not been tested on X Windows System variations of
457 the BMP format which are usually referred to XBM and XPM formats.
460 Here, only the MS Windows and OS/2 format is relevant.
463 Currently the code is able to read and write the following image types:
466 Read: gray1_image_t, gray4_image_t, gray8_image_t, rgb8_image_t and, rgba8_image_t
467 Write: rgb8_image_t and, rgba8_image_t
470 The lack of having an indexed image type in gil restricts the current interface
471 to only write out non-indexed images. This is subject to change soon.
474 <a name="gil.io.using_io.h6"></a>
475 <span class="phrase"><a name="gil.io.using_io.jpeg"></a></span><a class="link" href="using_io.html#gil.io.using_io.jpeg">JPEG</a>
478 For a general overview of the JPEG image file format go to the following <a href="http://en.wikipedia.org/wiki/JPEG" target="_top">http://en.wikipedia.org/wiki/JPEG</a>.
481 This jpeg extension is based on the libjpeg library which can be found here,
482 <span class="underline">JPEG_Lib</span>.
485 The user has to make sure this library is properly installed. I strongly recommend
486 the user to build the library yourself. It could potentially save you a lot
490 Currently the code is able to read and write the following image types:
493 Read: gray8_image_t, rgb8_image_t, cmyk8_image_t Write: gray8_image_t, rgb8_image_t,
497 Reading YCbCr or YCCK images is possible but might result in inaccuracies since
498 both color spaces aren't available yet for gil. For now these color space are
499 read as rgb images. This is subject to change soon.
502 <a name="gil.io.using_io.h7"></a>
503 <span class="phrase"><a name="gil.io.using_io.png"></a></span><a class="link" href="using_io.html#gil.io.using_io.png">PNG</a>
506 For a general overview of the PNG image file format go to the following <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics" target="_top">http://en.wikipedia.org/wiki/Portable_Network_Graphics</a>.
509 This png extension is based on the libpng, which can be found here, _PNG_Lib.
512 The user has to make sure this library is properly installed. I strongly recommend
513 the user to build the library yourself. It could potentially save you a lot
517 Currently the code is able to read and write the following image types:
520 Read: gray1, gray2, gray4, gray8, gray16, gray_alpha_8, gray_alpha_16, rgb8,
521 rgb16, rgba8, rgba16 Write: gray1, gray2, gray4, gray8, gray16, gray_alpha_8,
522 gray_alpha_16, rgb8, rgb16, rgba8, rgba16
525 For reading gray_alpha images the user has to enable the ENABLE_GRAY_ALPHA
526 compiler switch. This color space is defined in the toolbox by using gray_alpha.hpp.
529 <a name="gil.io.using_io.h8"></a>
530 <span class="phrase"><a name="gil.io.using_io.pnm"></a></span><a class="link" href="using_io.html#gil.io.using_io.pnm">PNM</a>
533 For a general overview of the PNM image file format go to the following <a href="http://en.wikipedia.org/wiki/Portable_anymap" target="_top">http://en.wikipedia.org/wiki/Portable_anymap</a>.
536 No external library is needed for the pnm format. Both ascii and binary formats
540 Currently the code is able to read and write the following image types:
543 Read: gray1, gray8, rgb8 Write: gray1, gray8, rgb8
546 When reading a mono text image the data is read as a gray8 image.
549 <a name="gil.io.using_io.h9"></a>
550 <span class="phrase"><a name="gil.io.using_io.raw"></a></span><a class="link" href="using_io.html#gil.io.using_io.raw">RAW</a>
553 For a general overview see _RAW_Wiki.
556 Currently the extension is only able to read rgb8 images.
559 <a name="gil.io.using_io.h10"></a>
560 <span class="phrase"><a name="gil.io.using_io.targa"></a></span><a class="link" href="using_io.html#gil.io.using_io.targa">TARGA</a>
563 For a general overview of the BMP image file format go to the following <span class="underline">TARGA_Wiki</span>.
566 Currently the code is able to read and write the following image types:
569 Read: rgb8_image_t and rgba8_image_t Write: rgb8_image_t and rgba8_image_t
572 The lack of having an indexed image type in gil restricts the current interface
573 to only write out non-indexed images. This is subject to change soon.
576 <a name="gil.io.using_io.h11"></a>
577 <span class="phrase"><a name="gil.io.using_io.tiff"></a></span><a class="link" href="using_io.html#gil.io.using_io.tiff">TIFF</a>
580 For a general overview of the TIFF image file format go to the following <a href="http://en.wikipedia.org/wiki/Tagged_Image_File_Format" target="_top">http://en.wikipedia.org/wiki/Tagged_Image_File_Format</a>.
583 This tiff extension is based on the libtiff, which can be found, <a href="http://www.remotesensing.org/libtiff/" target="_top">http://www.remotesensing.org/libtiff/</a>.
586 The user has to make sure this library is properly installed. I strongly recommend
587 the user to build the library yourself. It could potentially save you a lot
591 TIFF images can virtually encode all kinds of channel sizes representing various
592 color spaces. Even planar images are possible. For instance, rbg323 or gray7.
593 The channels also can have specific formats, like integer values or floating
594 point values. For a complete set of options please consult the following websites:
596 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
597 <li class="listitem">
598 <a href="http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html" target="_top">http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html</a>
600 <li class="listitem">
601 <a href="http://www.awaresystems.be/imaging/tiff/tifftags/extension.html" target="_top">http://www.awaresystems.be/imaging/tiff/tifftags/extension.html</a>
605 The author of this extension is not claiming all tiff formats are supported.
606 This extension is likely to be a moving target adding new features with each
607 new milestone. Here is an incomplete lists:
609 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
610 <li class="listitem">
611 Multi-page tiffs - read only
613 <li class="listitem">
614 Strip tiffs - read and write support
616 <li class="listitem">
617 Tiled tiffs - read and write support with user defined tiled sizes
619 <li class="listitem">
620 bit images tiffs - fully supported, like gray1_image_t ( minisblack )
622 <li class="listitem">
623 planar tiffs - fully supported
625 <li class="listitem">
626 floating point tiffs - fully supported
628 <li class="listitem">
629 palette tiffs - supported but no indexed image type is available as of
634 This gil extension uses two different test image suites to test read and write
635 capabilities. See test_image folder. It's advisable to use ImageMagick's test
636 viewer to display images.
639 <a name="gil.io.using_io.h12"></a>
640 <span class="phrase"><a name="gil.io.using_io.extending_gil__io_with_new_formats"></a></span><a class="link" href="using_io.html#gil.io.using_io.extending_gil__io_with_new_formats">Extending
641 GIL::IO with new Formats</a>
644 Extending the gil::io with new formats is meant to be simple and straightforward.
645 Before adding I would recommend to have a look at existing implementations
646 and then trying to follow a couple of guidelines:
648 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
649 <li class="listitem">
650 Create the following files for your new xxx format
651 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
652 <li class="listitem">
653 xxx_read.hpp // Only includes read code
655 <li class="listitem">
656 xxx_write.hpp // Only includes write code
658 <li class="listitem">
659 xxx_all.hpp // includes xxx_read.hpp and xxx_write.hpp
663 <li class="listitem">
664 Add the code to the boost::gil::detail namespace
666 <li class="listitem">
667 Create a tag type for the new format. Like this:
668 <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">xxx_tag</span> <span class="special">:</span> <span class="identifier">format_tag</span> <span class="special">{};</span>
671 <li class="listitem">
672 Create the image_read_info for the new format. It contains all the information
673 that are necessary to read an image. It should be filled and returned by
674 the get_info() member of the reader class. See below.
675 <pre class="programlisting"><span class="keyword">template</span><span class="special"><></span> <span class="keyword">struct</span> <span class="identifier">image_read_info</span><span class="special"><</span> <span class="identifier">xxx_tag</span> <span class="special">></span> <span class="special">{};</span>
678 <li class="listitem">
679 Create the image_write_info for the new format. It contains all the information
680 that are necessary to write an image.
681 <pre class="programlisting"><span class="keyword">template</span><span class="special"><></span> <span class="keyword">struct</span> <span class="identifier">image_write_info</span><span class="special"><</span> <span class="identifier">xxx_tag</span> <span class="special">></span> <span class="special">{};</span>
684 <li class="listitem">
685 Use the following reader skeleton as a start:
686 <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Device</span>
687 <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">ConversionPolicy</span>
688 <span class="special">></span>
689 <span class="keyword">class</span> <span class="identifier">reader</span><span class="special"><</span> <span class="identifier">Device</span>
690 <span class="special">,</span> <span class="identifier">xxx_tag</span>
691 <span class="special">,</span> <span class="identifier">ConversionPolicy</span>
692 <span class="special">></span>
693 <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">reader_base</span><span class="special"><</span> <span class="identifier">xxx_tag</span>
694 <span class="special">,</span> <span class="identifier">ConversionPolicy</span>
695 <span class="special">></span>
696 <span class="special">{</span>
697 <span class="keyword">private</span><span class="special">:</span>
699 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">ConversionPolicy</span><span class="special">::</span><span class="identifier">color_converter_type</span> <span class="identifier">cc_t</span><span class="special">;</span>
701 <span class="keyword">public</span><span class="special">:</span>
703 <span class="identifier">reader</span><span class="special">(</span> <span class="identifier">Device</span><span class="special">&</span> <span class="identifier">device</span> <span class="special">)</span>
704 <span class="special">:</span> <span class="identifier">_io_dev</span><span class="special">(</span> <span class="identifier">device</span> <span class="special">)</span>
705 <span class="special">{}</span>
707 <span class="identifier">reader</span><span class="special">(</span> <span class="identifier">Device</span><span class="special">&</span> <span class="identifier">device</span>
708 <span class="special">,</span> <span class="keyword">const</span> <span class="identifier">cc_t</span><span class="special">&</span> <span class="identifier">cc</span>
709 <span class="special">)</span>
710 <span class="special">:</span> <span class="identifier">_io_dev</span><span class="special">(</span> <span class="identifier">device</span> <span class="special">)</span>
711 <span class="special">,</span> <span class="identifier">reader_base</span><span class="special"><</span> <span class="identifier">xxx_tag</span>
712 <span class="special">,</span> <span class="identifier">ConversionPolicy</span>
713 <span class="special">>(</span> <span class="identifier">cc</span> <span class="special">)</span>
714 <span class="special">{}</span>
716 <span class="identifier">image_read_info</span><span class="special"><</span> <span class="identifier">xxx_tag</span> <span class="special">></span> <span class="identifier">get_info</span><span class="special">()</span>
717 <span class="special">{</span>
718 <span class="comment">// your implementation here</span>
719 <span class="special">}</span>
721 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">View</span> <span class="special">></span>
722 <span class="keyword">void</span> <span class="identifier">apply</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">View</span><span class="special">&</span> <span class="identifier">dst_view</span> <span class="special">)</span>
723 <span class="special">{</span>
724 <span class="comment">// your implementation here</span>
725 <span class="special">}</span>
726 <span class="special">};</span>
729 <li class="listitem">
731 <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Device</span> <span class="special">></span>
732 <span class="keyword">class</span> <span class="identifier">writer</span><span class="special"><</span> <span class="identifier">Device</span>
733 <span class="special">,</span> <span class="identifier">xxx_tag</span>
734 <span class="special">></span>
735 <span class="special">{</span>
736 <span class="keyword">public</span><span class="special">:</span>
738 <span class="identifier">writer</span><span class="special">(</span> <span class="identifier">Device</span> <span class="special">&</span> <span class="identifier">file</span> <span class="special">)</span>
739 <span class="special">:</span> <span class="identifier">out</span><span class="special">(</span><span class="identifier">file</span><span class="special">)</span>
740 <span class="special">{}</span>
742 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">View</span><span class="special">></span>
743 <span class="keyword">void</span> <span class="identifier">apply</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">View</span><span class="special">&</span> <span class="identifier">view</span> <span class="special">)</span>
744 <span class="special">{</span>
745 <span class="comment">// your implementation here</span>
746 <span class="special">}</span>
748 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">View</span><span class="special">></span>
749 <span class="keyword">void</span> <span class="identifier">apply</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">View</span><span class="special">&</span> <span class="identifier">view</span>
750 <span class="special">,</span> <span class="keyword">const</span> <span class="identifier">image_write_info</span><span class="special"><</span> <span class="identifier">xxx_tag</span> <span class="special">>&</span> <span class="identifier">info</span> <span class="special">)</span>
751 <span class="special">{</span>
752 <span class="comment">// your implementation here</span>
753 <span class="special">}</span>
754 <span class="special">};</span>
759 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
760 <td align="left"></td>
761 <td align="right"><div class="copyright-footer">Copyright © 2013 Christian Henning<p>
762 Distributed under the Boost Software License, Version 1.0. (See accompanying
763 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
768 <div class="spirit-nav">
769 <a accesskey="p" href="tutorial.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="running_gil__io_tests.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>