/Src/Dependencies/Boost/libs/gil/doc/html/g_i_l_0638.html

http://hadesmem.googlecode.com/ · HTML · 162 lines · 143 code · 3 blank · 16 comment · 0 complexity · e43cede677e29085c39fdf790990d131 MD5 · raw file

  1. <!-- Copyright 2008 Lubomir Bourdev and Hailin Jin
  2. Distributed under the Boost Software License, Version 1.0.
  3. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. -->
  6. <!--
  7. Copyright 2005-2007 Adobe Systems Incorporated
  8. Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
  9. or a copy at http://stlab.adobe.com/licenses.html)
  10. Some files are held under additional license.
  11. Please see "http://stlab.adobe.com/licenses.html" for more information.
  12. -->
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  14. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  15. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  16. <head>
  17. <TITLE>Generic Image Library: tiff_dynamic_io.hpp Source File</TITLE>
  18. <META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/>
  19. <LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/>
  20. </head>
  21. <body>
  22. <table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr>
  23. <td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'>
  24. <div class="qindex"><a class="qindex" href="index.html">Modules</a>
  25. | <a class="qindex" href="classes.html">Alphabetical List</a>
  26. | <a class="qindex" href="annotated.html">Class List</a>
  27. | <a class="qindex" href="dirs.html">Directories</a>
  28. | <a class="qindex" href="files.html">File List</a>
  29. | <a class="qindex" href="../index.html">GIL Home Page</a>
  30. </div>
  31. <!-- End Header -->
  32. <!-- Generated by Doxygen 1.5.6 -->
  33. <div class="navpath"><a class="el" href="g_i_l_0076.html">boost</a>&nbsp;&raquo&nbsp;<a class="el" href="g_i_l_0079.html">gil</a>&nbsp;&raquo&nbsp;<a class="el" href="g_i_l_0078.html">extension</a>&nbsp;&raquo&nbsp;<a class="el" href="g_i_l_0077.html">io</a>
  34. </div>
  35. <div class="contents">
  36. <h1>tiff_dynamic_io.hpp</h1><a href="g_i_l_0639.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
  37. <a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span>
  38. <a name="l00003"></a>00003 <span class="comment"> </span>
  39. <a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span>
  40. <a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
  41. <a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span>
  42. <a name="l00007"></a>00007 <span class="comment"></span>
  43. <a name="l00008"></a>00008 <span class="comment"> See http://opensource.adobe.com/gil for most recent version including documentation.</span>
  44. <a name="l00009"></a>00009 <span class="comment">*/</span>
  45. <a name="l00010"></a>00010
  46. <a name="l00011"></a>00011 <span class="comment">/*************************************************************************************************/</span>
  47. <a name="l00012"></a>00012
  48. <a name="l00013"></a>00013 <span class="preprocessor">#ifndef GIL_TIFF_DYNAMIC_IO_H</span>
  49. <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define GIL_TIFF_DYNAMIC_IO_H</span>
  50. <a name="l00015"></a>00015 <span class="preprocessor"></span>
  51. <a name="l00022"></a>00022 <span class="comment">//</span>
  52. <a name="l00023"></a>00023 <span class="comment">// We are currently providing the following functions:</span>
  53. <a name="l00024"></a>00024 <span class="comment">// template &lt;typename Images&gt; void tiff_read_image(const char*,any_image&lt;Images&gt;)</span>
  54. <a name="l00025"></a>00025 <span class="comment">// template &lt;typename Views&gt; void tiff_write_view(const char*,any_image_view&lt;Views&gt;)</span>
  55. <a name="l00026"></a>00026 <span class="comment">//</span>
  56. <a name="l00027"></a>00027
  57. <a name="l00028"></a>00028 <span class="preprocessor">#include &lt;string&gt;</span>
  58. <a name="l00029"></a>00029 <span class="preprocessor">#include &lt;boost/mpl/bool.hpp&gt;</span>
  59. <a name="l00030"></a>00030 <span class="preprocessor">#include "../dynamic_image/dynamic_image_all.hpp"</span>
  60. <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="io__error_8hpp.html" title="Handle input-output errors.">io_error.hpp</a>"</span>
  61. <a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="tiff__io_8hpp.html" title="Support for reading and writing TIFF files Requires libtiff!">tiff_io.hpp</a>"</span>
  62. <a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="g_i_l_0085.html" title="Generic io functions for dealing with dynamic images.">dynamic_io.hpp</a>"</span>
  63. <a name="l00034"></a>00034
  64. <a name="l00035"></a>00035 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil {
  65. <a name="l00036"></a>00036
  66. <a name="l00037"></a>00037 <span class="keyword">namespace </span>detail {
  67. <a name="l00038"></a>00038
  68. <a name="l00039"></a>00039 <span class="keyword">struct </span>tiff_write_is_supported {
  69. <a name="l00040"></a>00040 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt; <span class="keyword">struct </span>apply
  70. <a name="l00041"></a>00041 : <span class="keyword">public</span> mpl::bool_&lt;tiff_write_support&lt;View&gt;::is_supported&gt; {};
  71. <a name="l00042"></a>00042 };
  72. <a name="l00043"></a>00043
  73. <a name="l00044"></a>00044 <span class="keyword">class </span>tiff_writer_dynamic : <span class="keyword">public</span> tiff_writer {
  74. <a name="l00045"></a>00045 <span class="keyword">public</span>:
  75. <a name="l00046"></a>00046 <span class="keyword">typedef</span> <span class="keywordtype">void</span> result_type;
  76. <a name="l00047"></a>00047 tiff_writer_dynamic(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : tiff_writer(filename) {}
  77. <a name="l00048"></a>00048
  78. <a name="l00049"></a>00049 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Views&gt;
  79. <a name="l00050"></a>00050 <span class="keywordtype">void</span> write_view(<span class="keyword">const</span> any_image_view&lt;Views&gt;&amp; runtime_view) {
  80. <a name="l00051"></a>00051 dynamic_io_fnobj&lt;tiff_write_is_supported, tiff_writer&gt; op(<span class="keyword">this</span>);
  81. <a name="l00052"></a>00052 <a class="code" href="group___variant.html#g3dc0a90911c08815be11e1e49ec06037" title="Invokes a generic constant operation (represented as a binary function object) on...">apply_operation</a>(runtime_view,op);
  82. <a name="l00053"></a>00053 }
  83. <a name="l00054"></a>00054 };
  84. <a name="l00055"></a>00055
  85. <a name="l00056"></a>00056 <span class="keyword">class </span>tiff_type_format_checker {
  86. <a name="l00057"></a>00057 <span class="keywordtype">int</span> _bit_depth;
  87. <a name="l00058"></a>00058 <span class="keywordtype">int</span> _color_type;
  88. <a name="l00059"></a>00059 <span class="keyword">public</span>:
  89. <a name="l00060"></a>00060 tiff_type_format_checker(<span class="keywordtype">int</span> bit_depth_in,<span class="keywordtype">int</span> color_type_in) :
  90. <a name="l00061"></a>00061 _bit_depth(bit_depth_in),_color_type(color_type_in) {}
  91. <a name="l00062"></a>00062 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Image&gt;
  92. <a name="l00063"></a>00063 <span class="keywordtype">bool</span> apply() {
  93. <a name="l00064"></a>00064 <span class="keywordflow">return</span> tiff_read_support&lt;typename Image::view_t&gt;::bit_depth==_bit_depth &amp;&amp;
  94. <a name="l00065"></a>00065 tiff_read_support&lt;typename Image::view_t&gt;::color_type==_color_type;
  95. <a name="l00066"></a>00066 }
  96. <a name="l00067"></a>00067 };
  97. <a name="l00068"></a>00068
  98. <a name="l00069"></a>00069 <span class="keyword">struct </span>tiff_read_is_supported {
  99. <a name="l00070"></a>00070 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt; <span class="keyword">struct </span>apply
  100. <a name="l00071"></a>00071 : <span class="keyword">public</span> mpl::bool_&lt;tiff_read_support&lt;View&gt;::is_supported&gt; {};
  101. <a name="l00072"></a>00072 };
  102. <a name="l00073"></a>00073
  103. <a name="l00074"></a>00074 <span class="keyword">class </span>tiff_reader_dynamic : <span class="keyword">public</span> tiff_reader {
  104. <a name="l00075"></a>00075 <span class="keyword">public</span>:
  105. <a name="l00076"></a>00076 tiff_reader_dynamic(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : tiff_reader(filename) {}
  106. <a name="l00077"></a>00077
  107. <a name="l00078"></a>00078 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Images&gt;
  108. <a name="l00079"></a>00079 <span class="keywordtype">void</span> read_image(any_image&lt;Images&gt;&amp; im) {
  109. <a name="l00080"></a>00080 <span class="keywordtype">int</span> width,height;
  110. <a name="l00081"></a>00081 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> bps,photometric;
  111. <a name="l00082"></a>00082 TIFFGetField(_tp,TIFFTAG_IMAGEWIDTH,&amp;width);
  112. <a name="l00083"></a>00083 TIFFGetField(_tp,TIFFTAG_IMAGELENGTH,&amp;height);
  113. <a name="l00084"></a>00084 TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&amp;bps);
  114. <a name="l00085"></a>00085 TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&amp;photometric);
  115. <a name="l00086"></a>00086 <span class="keywordflow">if</span> (!construct_matched(im,tiff_type_format_checker(bps,photometric))) {
  116. <a name="l00087"></a>00087 io_error(<span class="stringliteral">"tiff_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file"</span>);
  117. <a name="l00088"></a>00088 } <span class="keywordflow">else</span> {
  118. <a name="l00089"></a>00089 im.recreate(width,height);
  119. <a name="l00090"></a>00090 dynamic_io_fnobj&lt;tiff_read_is_supported, tiff_reader&gt; op(<span class="keyword">this</span>);
  120. <a name="l00091"></a>00091 <a class="code" href="group___variant.html#g3dc0a90911c08815be11e1e49ec06037" title="Invokes a generic constant operation (represented as a binary function object) on...">apply_operation</a>(<a class="code" href="g_i_l_0135.html#g55e45a15dddfc0d870c2f7fb9739cb2e" title="Returns the non-constant-pixel view of any image. The returned view is any view.">view</a>(im),op);
  121. <a name="l00092"></a>00092 }
  122. <a name="l00093"></a>00093 }
  123. <a name="l00094"></a>00094 };
  124. <a name="l00095"></a>00095
  125. <a name="l00096"></a>00096 } <span class="comment">// namespace detail</span>
  126. <a name="l00097"></a>00097
  127. <a name="l00103"></a>00103 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Images&gt;
  128. <a name="l00104"></a><a class="code" href="g_i_l_0216.html#g6668f0775908d834ab5fdf0cb2e41e34">00104</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0216.html#g14ff6b4a743878cac2b32fdaedd5e705" title="Allocates a new image whose dimensions are determined by the given tiff image file...">tiff_read_image</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename,<a class="code" href="g_i_l_0018.html" title="Represents a run-time specified image. Note it does NOT model ImageConcept.">any_image&lt;Images&gt;</a>&amp; im) {
  129. <a name="l00105"></a>00105 detail::tiff_reader_dynamic m(filename);
  130. <a name="l00106"></a>00106 m.read_image(im);
  131. <a name="l00107"></a>00107 }
  132. <a name="l00108"></a>00108
  133. <a name="l00111"></a>00111 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Images&gt;
  134. <a name="l00112"></a><a class="code" href="g_i_l_0216.html#gd98fe891bca440cb0e68a08aaa9e4574">00112</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0216.html#g14ff6b4a743878cac2b32fdaedd5e705" title="Allocates a new image whose dimensions are determined by the given tiff image file...">tiff_read_image</a>(<span class="keyword">const</span> std::string&amp; filename,<a class="code" href="g_i_l_0018.html" title="Represents a run-time specified image. Note it does NOT model ImageConcept.">any_image&lt;Images&gt;</a>&amp; im) {
  135. <a name="l00113"></a>00113 <a class="code" href="g_i_l_0216.html#g14ff6b4a743878cac2b32fdaedd5e705" title="Allocates a new image whose dimensions are determined by the given tiff image file...">tiff_read_image</a>(filename.c_str(),im);
  136. <a name="l00114"></a>00114 }
  137. <a name="l00115"></a>00115
  138. <a name="l00120"></a>00120 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Views&gt;
  139. <a name="l00121"></a><a class="code" href="g_i_l_0216.html#g512a713ae6fc8aa9da4415a1f554a67e">00121</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0216.html#g99ce921bc92a5bbcf2145d3387e5e323" title="Saves the view to a tiff file specified by the given tiff image file name.">tiff_write_view</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename,<span class="keyword">const</span> <a class="code" href="g_i_l_0020.html" title="Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCo...">any_image_view&lt;Views&gt;</a>&amp; runtime_view) {
  140. <a name="l00122"></a>00122 detail::tiff_writer_dynamic m(filename);
  141. <a name="l00123"></a>00123 m.write_view(runtime_view);
  142. <a name="l00124"></a>00124 }
  143. <a name="l00125"></a>00125
  144. <a name="l00128"></a>00128 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Views&gt;
  145. <a name="l00129"></a><a class="code" href="g_i_l_0216.html#g718fc306c4dba31246989bb6255dd3fb">00129</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0216.html#g99ce921bc92a5bbcf2145d3387e5e323" title="Saves the view to a tiff file specified by the given tiff image file name.">tiff_write_view</a>(<span class="keyword">const</span> std::string&amp; filename,<span class="keyword">const</span> <a class="code" href="g_i_l_0020.html" title="Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCo...">any_image_view&lt;Views&gt;</a>&amp; runtime_view) {
  146. <a name="l00130"></a>00130 <a class="code" href="g_i_l_0216.html#g99ce921bc92a5bbcf2145d3387e5e323" title="Saves the view to a tiff file specified by the given tiff image file name.">tiff_write_view</a>(filename.c_str(),runtime_view);
  147. <a name="l00131"></a>00131 }
  148. <a name="l00132"></a>00132
  149. <a name="l00133"></a>00133 } } <span class="comment">// namespace boost::gil</span>
  150. <a name="l00134"></a>00134
  151. <a name="l00135"></a>00135 <span class="preprocessor">#endif</span>
  152. </pre></div></div>
  153. <hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:15 2009 for Generic Image Library by&nbsp;
  154. <a href="http://www.doxygen.org/index.html">
  155. <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
  156. </body>
  157. </html>