blob: 635ea4122ea9669c959fe0187508a8d03cfe7e53 [file] [log] [blame]
<!-- Copyright 2008 Lubomir Bourdev and Hailin Jin
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
-->
<!--
Copyright 2005-2007 Adobe Systems Incorporated
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
or a copy at http://stlab.adobe.com/licenses.html)
Some files are held under additional license.
Please see "http://stlab.adobe.com/licenses.html" for more information.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<TITLE>Generic Image Library: png_dynamic_io.hpp Source File</TITLE>
<META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/>
<LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr>
<td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'>
<div class="qindex"><a class="qindex" href="index.html">Modules</a>
| <a class="qindex" href="classes.html">Alphabetical List</a>
| <a class="qindex" href="annotated.html">Class List</a>
| <a class="qindex" href="dirs.html">Directories</a>
| <a class="qindex" href="files.html">File List</a>
| <a class="qindex" href="../index.html">GIL Home Page</a>
</div>
<!-- End Header -->
<!-- Generated by Doxygen 1.5.6 -->
<div class="navpath"><a class="el" href="g_i_l_0076.html">boost</a>&nbsp;&raquo&nbsp;<a class="el" href="g_i_l_0079.html">gil</a>&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>
</div>
<div class="contents">
<h1>png_dynamic_io.hpp</h1><a href="g_i_l_0251.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span>
<a name="l00003"></a>00003 <span class="comment"> </span>
<a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span>
<a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
<a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment"> See http://opensource.adobe.com/gil for most recent version including documentation.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010
<a name="l00011"></a>00011 <span class="comment">/*************************************************************************************************/</span>
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="preprocessor">#ifndef GIL_PNG_DYNAMIC_IO_H</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define GIL_PNG_DYNAMIC_IO_H</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span>
<a name="l00023"></a>00023 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment">// We are currently providing the following functions:</span>
<a name="l00025"></a>00025 <span class="comment">// template &lt;typename Images&gt; void png_read_image(const char*,any_image&lt;Images&gt;&amp;)</span>
<a name="l00026"></a>00026 <span class="comment">// template &lt;typename Images&gt; void png_read_image(FILE*,any_image&lt;Images&gt;&amp;,std::size_t)</span>
<a name="l00027"></a>00027 <span class="comment">// template &lt;typename Views&gt; void png_write_view(const char*,const any_image_view&lt;View&gt;&amp;)</span>
<a name="l00028"></a>00028 <span class="comment">// template &lt;typename Views&gt; void png_write_view(FILE*,const any_image_view&lt;View&gt;&amp;)</span>
<a name="l00029"></a>00029
<a name="l00030"></a>00030
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;boost/mpl/bool.hpp&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;boost/shared_ptr.hpp&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "../dynamic_image/dynamic_image_all.hpp"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="io__error_8hpp.html" title="Handle input-output errors.">io_error.hpp</a>"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="png__io_8hpp.html" title="Support for reading and writing PNG files Requires libpng and zlib!">png_io.hpp</a>"</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="g_i_l_0254.html" title="Internal support for reading and writing PNG files.">png_io_private.hpp</a>"</span>
<a name="l00039"></a>00039 <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>
<a name="l00040"></a>00040
<a name="l00041"></a>00041 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil {
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="keyword">namespace </span>detail {
<a name="l00044"></a>00044
<a name="l00045"></a>00045 <span class="keyword">struct </span>png_write_is_supported {
<a name="l00046"></a>00046 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt; <span class="keyword">struct </span>apply
<a name="l00047"></a>00047 : <span class="keyword">public</span> mpl::bool_&lt;png_write_support&lt;View&gt;::is_supported&gt; {};
<a name="l00048"></a>00048 };
<a name="l00049"></a>00049
<a name="l00050"></a>00050 <span class="keyword">class </span>png_writer_dynamic : <span class="keyword">public</span> png_writer {
<a name="l00051"></a>00051 <span class="keyword">public</span>:
<a name="l00052"></a>00052 png_writer_dynamic(FILE* file ) : png_writer(file) {}
<a name="l00053"></a>00053 png_writer_dynamic(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : png_writer(filename){}
<a name="l00054"></a>00054
<a name="l00055"></a>00055 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Views&gt;
<a name="l00056"></a>00056 <span class="keywordtype">void</span> write_view(<span class="keyword">const</span> any_image_view&lt;Views&gt;&amp; runtime_view) {
<a name="l00057"></a>00057 dynamic_io_fnobj&lt;png_write_is_supported, png_writer&gt; op(<span class="keyword">this</span>);
<a name="l00058"></a>00058 <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);
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 };
<a name="l00061"></a>00061
<a name="l00062"></a>00062 <span class="keyword">class </span>png_type_format_checker {
<a name="l00063"></a>00063 <span class="keywordtype">int</span> _bit_depth;
<a name="l00064"></a>00064 <span class="keywordtype">int</span> _color_type;
<a name="l00065"></a>00065 <span class="keyword">public</span>:
<a name="l00066"></a>00066 png_type_format_checker(<span class="keywordtype">int</span> bit_depth_in,<span class="keywordtype">int</span> color_type_in) :
<a name="l00067"></a>00067 _bit_depth(bit_depth_in),_color_type(color_type_in) {}
<a name="l00068"></a>00068 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Image&gt;
<a name="l00069"></a>00069 <span class="keywordtype">bool</span> apply() {
<a name="l00070"></a>00070 <span class="keywordflow">return</span> png_read_support&lt;typename Image::view_t&gt;::bit_depth==_bit_depth &amp;&amp;
<a name="l00071"></a>00071 png_read_support&lt;typename Image::view_t&gt;::color_type==_color_type;
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 };
<a name="l00074"></a>00074
<a name="l00075"></a>00075 <span class="keyword">struct </span>png_read_is_supported {
<a name="l00076"></a>00076 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt; <span class="keyword">struct </span>apply
<a name="l00077"></a>00077 : <span class="keyword">public</span> mpl::bool_&lt;png_read_support&lt;View&gt;::is_supported&gt; {};
<a name="l00078"></a>00078 };
<a name="l00079"></a>00079
<a name="l00080"></a>00080 <span class="keyword">class </span>png_reader_dynamic : <span class="keyword">public</span> png_reader {
<a name="l00081"></a>00081 <span class="keyword">public</span>:
<a name="l00082"></a>00082 png_reader_dynamic(FILE* file) : png_reader(file) {}
<a name="l00083"></a>00083 png_reader_dynamic(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : png_reader(filename){}
<a name="l00084"></a>00084
<a name="l00085"></a>00085 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Images&gt;
<a name="l00086"></a>00086 <span class="keywordtype">void</span> read_image(any_image&lt;Images&gt;&amp; im) {
<a name="l00087"></a>00087 png_uint_32 width, height;
<a name="l00088"></a>00088 <span class="keywordtype">int</span> bit_depth, color_type, interlace_type;
<a name="l00089"></a>00089 png_get_IHDR(_png_ptr, _info_ptr,
<a name="l00090"></a>00090 &amp;width, &amp;height,&amp;bit_depth,&amp;color_type,&amp;interlace_type,
<a name="l00091"></a>00091 int_p_NULL, int_p_NULL);
<a name="l00092"></a>00092 <span class="keywordflow">if</span> (!construct_matched(im,png_type_format_checker(bit_depth,color_type))) {
<a name="l00093"></a>00093 io_error(<span class="stringliteral">"png_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file"</span>);
<a name="l00094"></a>00094 } <span class="keywordflow">else</span> {
<a name="l00095"></a>00095 im.recreate(width,height);
<a name="l00096"></a>00096 dynamic_io_fnobj&lt;png_read_is_supported, png_reader&gt; op(<span class="keyword">this</span>);
<a name="l00097"></a>00097 <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);
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 }
<a name="l00100"></a>00100 };
<a name="l00101"></a>00101
<a name="l00102"></a>00102 } <span class="comment">// namespace detail </span>
<a name="l00103"></a>00103
<a name="l00109"></a>00109 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Images&gt;
<a name="l00110"></a><a class="code" href="g_i_l_0174.html#gaa5dd1e1d7d5c9ba497d2d52ccfd6523">00110</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0174.html#ge9a35f15e2544de801e23b3c481612a9" title="Allocates a new image whose dimensions are determined by the given png image file...">png_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) {
<a name="l00111"></a>00111 detail::png_reader_dynamic m(filename);
<a name="l00112"></a>00112 m.read_image(im);
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114
<a name="l00117"></a>00117 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Images&gt;
<a name="l00118"></a><a class="code" href="g_i_l_0174.html#g920e9b7f4c8b491695ab64968a386de0">00118</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0174.html#ge9a35f15e2544de801e23b3c481612a9" title="Allocates a new image whose dimensions are determined by the given png image file...">png_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) {
<a name="l00119"></a>00119 <a class="code" href="g_i_l_0174.html#ge9a35f15e2544de801e23b3c481612a9" title="Allocates a new image whose dimensions are determined by the given png image file...">png_read_image</a>(filename.c_str(),im);
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121
<a name="l00126"></a>00126 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Views&gt;
<a name="l00127"></a><a class="code" href="g_i_l_0174.html#gaf208f891f567a13e2dc82f9b06d7858">00127</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0174.html#gb8c6c4c3b78627324ac5983e348008de" title="Saves the view to a png file specified by the given png image file name.">png_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) {
<a name="l00128"></a>00128 detail::png_writer_dynamic m(filename);
<a name="l00129"></a>00129 m.write_view(runtime_view);
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131
<a name="l00134"></a>00134 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Views&gt;
<a name="l00135"></a><a class="code" href="g_i_l_0174.html#gd2dd9992f27f2176f88b934bc8d408f5">00135</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="g_i_l_0174.html#gb8c6c4c3b78627324ac5983e348008de" title="Saves the view to a png file specified by the given png image file name.">png_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) {
<a name="l00136"></a>00136 <a class="code" href="g_i_l_0174.html#gb8c6c4c3b78627324ac5983e348008de" title="Saves the view to a png file specified by the given png image file name.">png_write_view</a>(filename.c_str(),runtime_view);
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138
<a name="l00139"></a>00139 } } <span class="comment">// namespace boost::gil</span>
<a name="l00140"></a>00140
<a name="l00141"></a>00141 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:14 2009 for Generic Image Library by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>