]>
Commit | Line | Data |
---|---|---|
1 | <!-- Copyright 2008 Lubomir Bourdev and Hailin Jin | |
2 | ||
3 | Distributed under the Boost Software License, Version 1.0. | |
4 | (See accompanying file LICENSE_1_0.txt or copy at | |
5 | http://www.boost.org/LICENSE_1_0.txt) | |
6 | --> | |
7 | ||
8 | <!-- | |
9 | Copyright 2005-2007 Adobe Systems Incorporated | |
10 | Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt | |
11 | or a copy at http://stlab.adobe.com/licenses.html) | |
12 | ||
13 | Some files are held under additional license. | |
14 | Please see "http://stlab.adobe.com/licenses.html" for more information. | |
15 | --> | |
16 | ||
17 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
18 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
19 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
20 | ||
21 | <head> | |
22 | <TITLE>Generic Image Library: jpeg_io_private.hpp Source File</TITLE> | |
23 | <META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/> | |
24 | <LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/> | |
25 | </head> | |
26 | <body> | |
27 | <table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr> | |
28 | <td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'> | |
29 | <div class="qindex"><a class="qindex" href="index.html">Modules</a> | |
30 | | <a class="qindex" href="classes.html">Alphabetical List</a> | |
31 | | <a class="qindex" href="annotated.html">Class List</a> | |
32 | | <a class="qindex" href="dirs.html">Directories</a> | |
33 | | <a class="qindex" href="files.html">File List</a> | |
34 | | <a class="qindex" href="../index.html">GIL Home Page</a> | |
35 | </div> | |
36 | <!-- End Header --> | |
37 | <!-- Generated by Doxygen 1.5.6 --> | |
38 | <div class="navpath"><a class="el" href="g_i_l_0076.html">boost</a> » <a class="el" href="g_i_l_0079.html">gil</a> » <a class="el" href="g_i_l_0078.html">extension</a> » <a class="el" href="g_i_l_0077.html">io</a> | |
39 | </div> | |
40 | <div class="contents"> | |
41 | <h1>jpeg_io_private.hpp</h1><a href="g_i_l_0235.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> | |
42 | <a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span> | |
43 | <a name="l00003"></a>00003 <span class="comment"> </span> | |
44 | <a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span> | |
45 | <a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span> | |
46 | <a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span> | |
47 | <a name="l00007"></a>00007 <span class="comment"></span> | |
48 | <a name="l00008"></a>00008 <span class="comment"> See http://opensource.adobe.com/gil for most recent version including documentation.</span> | |
49 | <a name="l00009"></a>00009 <span class="comment">*/</span> | |
50 | <a name="l00010"></a>00010 | |
51 | <a name="l00011"></a>00011 <span class="comment">/*************************************************************************************************/</span> | |
52 | <a name="l00012"></a>00012 | |
53 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef GIL_JPEG_IO_PRIVATE_H</span> | |
54 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define GIL_JPEG_IO_PRIVATE_H</span> | |
55 | <a name="l00015"></a>00015 <span class="preprocessor"></span> | |
56 | <a name="l00021"></a>00021 | |
57 | <a name="l00022"></a>00022 <span class="preprocessor">#include <stdio.h></span> | |
58 | <a name="l00023"></a>00023 <span class="preprocessor">#include <boost/static_assert.hpp></span> | |
59 | <a name="l00024"></a>00024 <span class="preprocessor">#include <vector></span> | |
60 | <a name="l00025"></a>00025 <span class="preprocessor">#include "../../gil_all.hpp"</span> | |
61 | <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="io__error_8hpp.html" title="Handle input-output errors.">io_error.hpp</a>"</span> | |
62 | <a name="l00027"></a>00027 <span class="preprocessor">#include <jpeglib.h></span> | |
63 | <a name="l00028"></a>00028 | |
64 | <a name="l00029"></a>00029 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil { | |
65 | <a name="l00030"></a>00030 | |
66 | <a name="l00031"></a>00031 <span class="keyword">namespace </span>detail { | |
67 | <a name="l00032"></a>00032 | |
68 | <a name="l00033"></a>00033 <span class="comment">// lbourdev: What is the advantage of having channel and colorspace together? Are there cases where they are interrelated?</span> | |
69 | <a name="l00034"></a>00034 | |
70 | <a name="l00035"></a>00035 <span class="keyword">template</span> <<span class="keyword">typename</span> Channel,<span class="keyword">typename</span> ColorSpace> | |
71 | <a name="l00036"></a>00036 <span class="keyword">struct </span>jpeg_read_support_private { | |
72 | <a name="l00037"></a>00037 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">false</span>); | |
73 | <a name="l00038"></a>00038 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_UNKNOWN); | |
74 | <a name="l00039"></a>00039 }; | |
75 | <a name="l00040"></a>00040 <span class="keyword">template</span> <> | |
76 | <a name="l00041"></a>00041 <span class="keyword">struct </span>jpeg_read_support_private<bits8,gray_t> { | |
77 | <a name="l00042"></a>00042 BOOST_STATIC_ASSERT(BITS_IN_JSAMPLE==8); | |
78 | <a name="l00043"></a>00043 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">true</span>); | |
79 | <a name="l00044"></a>00044 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_GRAYSCALE); | |
80 | <a name="l00045"></a>00045 }; | |
81 | <a name="l00046"></a>00046 <span class="keyword">template</span> <> | |
82 | <a name="l00047"></a>00047 <span class="keyword">struct </span>jpeg_read_support_private<bits8,rgb_t> { | |
83 | <a name="l00048"></a>00048 BOOST_STATIC_ASSERT(BITS_IN_JSAMPLE==8); | |
84 | <a name="l00049"></a>00049 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">true</span>); | |
85 | <a name="l00050"></a>00050 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_RGB); | |
86 | <a name="l00051"></a>00051 }; | |
87 | <a name="l00052"></a>00052 <span class="keyword">template</span> <> | |
88 | <a name="l00053"></a>00053 <span class="keyword">struct </span>jpeg_read_support_private<bits8,cmyk_t> { | |
89 | <a name="l00054"></a>00054 BOOST_STATIC_ASSERT(BITS_IN_JSAMPLE==8); | |
90 | <a name="l00055"></a>00055 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">true</span>); | |
91 | <a name="l00056"></a>00056 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_CMYK); | |
92 | <a name="l00057"></a>00057 }; | |
93 | <a name="l00058"></a>00058 <span class="keyword">template</span> <<span class="keyword">typename</span> Channel,<span class="keyword">typename</span> ColorSpace> | |
94 | <a name="l00059"></a>00059 <span class="keyword">struct </span>jpeg_write_support_private { | |
95 | <a name="l00060"></a>00060 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">false</span>); | |
96 | <a name="l00061"></a>00061 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_UNKNOWN); | |
97 | <a name="l00062"></a>00062 }; | |
98 | <a name="l00063"></a>00063 <span class="keyword">template</span> <> | |
99 | <a name="l00064"></a>00064 <span class="keyword">struct </span>jpeg_write_support_private<bits8,gray_t> { | |
100 | <a name="l00065"></a>00065 BOOST_STATIC_ASSERT(BITS_IN_JSAMPLE==8); | |
101 | <a name="l00066"></a>00066 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">true</span>); | |
102 | <a name="l00067"></a>00067 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_GRAYSCALE); | |
103 | <a name="l00068"></a>00068 }; | |
104 | <a name="l00069"></a>00069 <span class="keyword">template</span> <> | |
105 | <a name="l00070"></a>00070 <span class="keyword">struct </span>jpeg_write_support_private<bits8,rgb_t> { | |
106 | <a name="l00071"></a>00071 BOOST_STATIC_ASSERT(BITS_IN_JSAMPLE==8); | |
107 | <a name="l00072"></a>00072 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">true</span>); | |
108 | <a name="l00073"></a>00073 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_RGB); | |
109 | <a name="l00074"></a>00074 }; | |
110 | <a name="l00075"></a>00075 <span class="keyword">template</span> <> | |
111 | <a name="l00076"></a>00076 <span class="keyword">struct </span>jpeg_write_support_private<bits8,cmyk_t> { | |
112 | <a name="l00077"></a>00077 BOOST_STATIC_ASSERT(BITS_IN_JSAMPLE==8); | |
113 | <a name="l00078"></a>00078 BOOST_STATIC_CONSTANT(<span class="keywordtype">bool</span>,is_supported=<span class="keyword">true</span>); | |
114 | <a name="l00079"></a>00079 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=JCS_CMYK); | |
115 | <a name="l00080"></a>00080 }; | |
116 | <a name="l00081"></a>00081 | |
117 | <a name="l00082"></a>00082 | |
118 | <a name="l00083"></a>00083 <span class="keyword">class </span>jpeg_reader : <span class="keyword">public</span> file_mgr { | |
119 | <a name="l00084"></a>00084 <span class="keyword">protected</span>: | |
120 | <a name="l00085"></a>00085 jpeg_decompress_struct _cinfo; | |
121 | <a name="l00086"></a>00086 jpeg_error_mgr _jerr; | |
122 | <a name="l00087"></a>00087 | |
123 | <a name="l00088"></a>00088 <span class="keywordtype">void</span> init() { | |
124 | <a name="l00089"></a>00089 _cinfo.err=jpeg_std_error(&_jerr); | |
125 | <a name="l00090"></a>00090 jpeg_create_decompress(&_cinfo); | |
126 | <a name="l00091"></a>00091 jpeg_stdio_src(&_cinfo,_fp.get()); | |
127 | <a name="l00092"></a>00092 jpeg_read_header(&_cinfo,TRUE); | |
128 | <a name="l00093"></a>00093 } | |
129 | <a name="l00094"></a>00094 <span class="keyword">public</span>: | |
130 | <a name="l00095"></a>00095 jpeg_reader(FILE* file) : file_mgr(file) { init(); } | |
131 | <a name="l00096"></a>00096 jpeg_reader(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : file_mgr(filename, <span class="stringliteral">"rb"</span>) { init(); } | |
132 | <a name="l00097"></a>00097 | |
133 | <a name="l00098"></a>00098 ~jpeg_reader() { jpeg_destroy_decompress(&_cinfo); } | |
134 | <a name="l00099"></a>00099 | |
135 | <a name="l00100"></a>00100 <span class="keyword">template</span> <<span class="keyword">typename</span> View> | |
136 | <a name="l00101"></a>00101 <span class="keywordtype">void</span> apply(<span class="keyword">const</span> View& <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>) { | |
137 | <a name="l00102"></a>00102 jpeg_start_decompress(&_cinfo); <span class="comment">// lbourdev: Can this return an error? You need to check and throw. Check all other library methods that can return an error state...</span> | |
138 | <a name="l00103"></a>00103 io_error_if(_cinfo.data_precision!=8,<span class="stringliteral">"jpeg_reader::apply(): this image file is not supported"</span>); | |
139 | <a name="l00104"></a>00104 io_error_if(_cinfo.out_color_space!=jpeg_read_support_private<<span class="keyword">typename</span> channel_type<View>::type, | |
140 | <a name="l00105"></a>00105 <span class="keyword">typename</span> color_space_type<View>::type>::color_type, | |
141 | <a name="l00106"></a>00106 <span class="stringliteral">"jpeg_reader::apply(): input view type does not match the image file"</span>); | |
142 | <a name="l00107"></a>00107 io_error_if(view.dimensions() != get_dimensions(), <span class="stringliteral">"jpeg_reader::apply(): input view dimensions do not match the image file"</span>); | |
143 | <a name="l00108"></a>00108 std::vector<pixel<bits8,layout<typename color_space_type<View>::type> > > row(view.width()); | |
144 | <a name="l00109"></a>00109 JSAMPLE* row_address=(JSAMPLE*)&row.front(); | |
145 | <a name="l00110"></a>00110 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> y=0;y<view.height();++y) { | |
146 | <a name="l00111"></a>00111 io_error_if(jpeg_read_scanlines(&_cinfo,(JSAMPARRAY)&row_address,1)!=1, | |
147 | <a name="l00112"></a>00112 <span class="stringliteral">"jpeg_reader::apply(): fail to read JPEG file"</span>); | |
148 | <a name="l00113"></a>00113 <a class="code" href="g_i_l_0214.html#g4e8a9e1bb08e76c93dc56a4626231ee1" title="Copy when both src and dst are planar pointers is copy for each channel.">std::copy</a>(row.begin(),row.end(),view.row_begin(y)); | |
149 | <a name="l00114"></a>00114 } | |
150 | <a name="l00115"></a>00115 jpeg_finish_decompress(&_cinfo); | |
151 | <a name="l00116"></a>00116 } | |
152 | <a name="l00117"></a>00117 | |
153 | <a name="l00118"></a>00118 <span class="keyword">template</span> <<span class="keyword">typename</span> Image> | |
154 | <a name="l00119"></a>00119 <span class="keywordtype">void</span> read_image(Image& im) { | |
155 | <a name="l00120"></a>00120 im.recreate(get_dimensions()); | |
156 | <a name="l00121"></a>00121 apply(<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)); | |
157 | <a name="l00122"></a>00122 } | |
158 | <a name="l00123"></a>00123 | |
159 | <a name="l00124"></a>00124 point2<std::ptrdiff_t> get_dimensions()<span class="keyword"> const </span>{ | |
160 | <a name="l00125"></a>00125 <span class="keywordflow">return</span> point2<std::ptrdiff_t>(_cinfo.image_width,_cinfo.image_height); | |
161 | <a name="l00126"></a>00126 } | |
162 | <a name="l00127"></a>00127 }; | |
163 | <a name="l00128"></a>00128 | |
164 | <a name="l00129"></a>00129 <span class="comment">// This code will be simplified...</span> | |
165 | <a name="l00130"></a>00130 <span class="keyword">template</span> <<span class="keyword">typename</span> CC> | |
166 | <a name="l00131"></a>00131 <span class="keyword">class </span>jpeg_reader_color_convert : <span class="keyword">public</span> jpeg_reader { | |
167 | <a name="l00132"></a>00132 <span class="keyword">private</span>: | |
168 | <a name="l00133"></a>00133 CC _cc; | |
169 | <a name="l00134"></a>00134 <span class="keyword">public</span>: | |
170 | <a name="l00135"></a>00135 jpeg_reader_color_convert(FILE* file,CC cc_in) : jpeg_reader(file),_cc(cc_in) {} | |
171 | <a name="l00136"></a>00136 jpeg_reader_color_convert(FILE* file) : jpeg_reader(file) {} | |
172 | <a name="l00137"></a>00137 jpeg_reader_color_convert(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename,CC cc_in) : jpeg_reader(filename),_cc(cc_in) {} | |
173 | <a name="l00138"></a>00138 jpeg_reader_color_convert(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : jpeg_reader(filename) {} | |
174 | <a name="l00139"></a>00139 <span class="keyword">template</span> <<span class="keyword">typename</span> View> | |
175 | <a name="l00140"></a>00140 <span class="keywordtype">void</span> apply(<span class="keyword">const</span> View& view) { | |
176 | <a name="l00141"></a>00141 jpeg_start_decompress(&_cinfo); <span class="comment">// lbourdev: Can this return an error? You need to check and throw. Check all other library methods that can return an error state...</span> | |
177 | <a name="l00142"></a>00142 io_error_if(_cinfo.data_precision!=8,<span class="stringliteral">"jpeg_reader_color_covert::apply(): this image file is not supported"</span>); | |
178 | <a name="l00143"></a>00143 io_error_if(view.dimensions() != get_dimensions(), <span class="stringliteral">"jpeg_reader_color_covert::apply(): input view dimensions don't match the image file"</span>); | |
179 | <a name="l00144"></a>00144 <span class="keywordflow">switch</span> (_cinfo.out_color_space) { | |
180 | <a name="l00145"></a>00145 <span class="keywordflow">case</span> JCS_GRAYSCALE: { | |
181 | <a name="l00146"></a>00146 std::vector<gray8_pixel_t> row(view.width()); | |
182 | <a name="l00147"></a>00147 JSAMPLE* row_address=(JSAMPLE*)&row.front(); | |
183 | <a name="l00148"></a>00148 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> y=0;y<view.height();++y) { | |
184 | <a name="l00149"></a>00149 io_error_if(jpeg_read_scanlines(&_cinfo,(JSAMPARRAY)&row_address,1)!=1, | |
185 | <a name="l00150"></a>00150 <span class="stringliteral">"jpeg_reader_color_covert::apply(): fail to read JPEG file"</span>); | |
186 | <a name="l00151"></a>00151 std::transform(row.begin(),row.end(),view.row_begin(y),color_convert_deref_fn<gray8_ref_t, typename View::value_type,CC>(_cc)); | |
187 | <a name="l00152"></a>00152 } | |
188 | <a name="l00153"></a>00153 <span class="keywordflow">break</span>; | |
189 | <a name="l00154"></a>00154 } | |
190 | <a name="l00155"></a>00155 <span class="keywordflow">case</span> JCS_RGB: { | |
191 | <a name="l00156"></a>00156 std::vector<rgb8_pixel_t> row(view.width()); | |
192 | <a name="l00157"></a>00157 JSAMPLE* row_address=(JSAMPLE*)&row.front(); | |
193 | <a name="l00158"></a>00158 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> y=0;y<view.height();++y) { | |
194 | <a name="l00159"></a>00159 io_error_if(jpeg_read_scanlines(&_cinfo,(JSAMPARRAY)&row_address,1)!=1, | |
195 | <a name="l00160"></a>00160 <span class="stringliteral">"jpeg_reader_color_covert::apply(): fail to read JPEG file"</span>); | |
196 | <a name="l00161"></a>00161 std::transform(row.begin(),row.end(),view.row_begin(y),color_convert_deref_fn<rgb8_ref_t, typename View::value_type,CC>(_cc)); | |
197 | <a name="l00162"></a>00162 } | |
198 | <a name="l00163"></a>00163 <span class="keywordflow">break</span>; | |
199 | <a name="l00164"></a>00164 } | |
200 | <a name="l00165"></a>00165 <span class="keywordflow">case</span> JCS_CMYK: { | |
201 | <a name="l00166"></a>00166 std::vector<cmyk8_pixel_t> row(view.width()); | |
202 | <a name="l00167"></a>00167 JSAMPLE* row_address=(JSAMPLE*)&row.front(); | |
203 | <a name="l00168"></a>00168 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> y=0;y<view.height();++y) { | |
204 | <a name="l00169"></a>00169 io_error_if(jpeg_read_scanlines(&_cinfo,(JSAMPARRAY)&row_address,1)!=1, | |
205 | <a name="l00170"></a>00170 <span class="stringliteral">"jpeg_reader_color_covert::apply(): fail to read JPEG file"</span>); | |
206 | <a name="l00171"></a>00171 std::transform(row.begin(),row.end(),view.row_begin(y),color_convert_deref_fn<cmyk8_ref_t, typename View::value_type,CC>(_cc)); | |
207 | <a name="l00172"></a>00172 } | |
208 | <a name="l00173"></a>00173 <span class="keywordflow">break</span>; | |
209 | <a name="l00174"></a>00174 } | |
210 | <a name="l00175"></a>00175 <span class="keywordflow">default</span>: | |
211 | <a name="l00176"></a>00176 io_error(<span class="stringliteral">"jpeg_reader_color_covert::apply(): unknown color type"</span>); | |
212 | <a name="l00177"></a>00177 } | |
213 | <a name="l00178"></a>00178 jpeg_finish_decompress(&_cinfo); | |
214 | <a name="l00179"></a>00179 } | |
215 | <a name="l00180"></a>00180 <span class="keyword">template</span> <<span class="keyword">typename</span> Image> | |
216 | <a name="l00181"></a>00181 <span class="keywordtype">void</span> read_image(Image& im) { | |
217 | <a name="l00182"></a>00182 im.recreate(get_dimensions()); | |
218 | <a name="l00183"></a>00183 apply(<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)); | |
219 | <a name="l00184"></a>00184 } | |
220 | <a name="l00185"></a>00185 }; | |
221 | <a name="l00186"></a>00186 | |
222 | <a name="l00187"></a>00187 <span class="keyword">class </span>jpeg_writer : <span class="keyword">public</span> file_mgr { | |
223 | <a name="l00188"></a>00188 jpeg_compress_struct _cinfo; | |
224 | <a name="l00189"></a>00189 jpeg_error_mgr _jerr; | |
225 | <a name="l00190"></a>00190 | |
226 | <a name="l00191"></a>00191 <span class="keywordtype">void</span> init() { | |
227 | <a name="l00192"></a>00192 _cinfo.err=jpeg_std_error(&_jerr); | |
228 | <a name="l00193"></a>00193 jpeg_create_compress(&_cinfo); | |
229 | <a name="l00194"></a>00194 jpeg_stdio_dest(&_cinfo,_fp.get()); | |
230 | <a name="l00195"></a>00195 } | |
231 | <a name="l00196"></a>00196 <span class="keyword">public</span>: | |
232 | <a name="l00197"></a>00197 jpeg_writer(FILE* file) : file_mgr(file) { init(); } | |
233 | <a name="l00198"></a>00198 jpeg_writer(<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) : file_mgr(filename, <span class="stringliteral">"wb"</span>) { init(); } | |
234 | <a name="l00199"></a>00199 ~jpeg_writer() { jpeg_destroy_compress(&_cinfo); } | |
235 | <a name="l00200"></a>00200 | |
236 | <a name="l00201"></a>00201 <span class="keyword">template</span> <<span class="keyword">typename</span> View> | |
237 | <a name="l00202"></a>00202 <span class="keywordtype">void</span> apply(<span class="keyword">const</span> View& view,<span class="keywordtype">int</span> quality=100) { | |
238 | <a name="l00203"></a>00203 _cinfo.image_width = (JDIMENSION)view.width(); | |
239 | <a name="l00204"></a>00204 _cinfo.image_height = (JDIMENSION)view.height(); | |
240 | <a name="l00205"></a>00205 _cinfo.input_components=num_channels<View>::value; | |
241 | <a name="l00206"></a>00206 _cinfo.in_color_space = jpeg_write_support_private<typename channel_type<View>::type, | |
242 | <a name="l00207"></a>00207 <span class="keyword">typename</span> color_space_type<View>::type>::color_type; | |
243 | <a name="l00208"></a>00208 jpeg_set_defaults(&_cinfo); | |
244 | <a name="l00209"></a>00209 jpeg_set_quality(&_cinfo, quality, TRUE); | |
245 | <a name="l00210"></a>00210 jpeg_start_compress(&_cinfo, TRUE); | |
246 | <a name="l00211"></a>00211 std::vector<pixel<bits8,layout<typename color_space_type<View>::type> > > row(view.width()); | |
247 | <a name="l00212"></a>00212 JSAMPLE* row_address=(JSAMPLE*)&row.front(); | |
248 | <a name="l00213"></a>00213 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y=0;y<view.height(); ++y) { | |
249 | <a name="l00214"></a>00214 <a class="code" href="g_i_l_0214.html#g4e8a9e1bb08e76c93dc56a4626231ee1" title="Copy when both src and dst are planar pointers is copy for each channel.">std::copy</a>(view.row_begin(y),view.row_end(y),row.begin()); | |
250 | <a name="l00215"></a>00215 io_error_if(jpeg_write_scanlines(&_cinfo,(JSAMPARRAY)&row_address,1) != 1, | |
251 | <a name="l00216"></a>00216 <span class="stringliteral">"jpeg_writer::apply(): fail to write file"</span>); | |
252 | <a name="l00217"></a>00217 } | |
253 | <a name="l00218"></a>00218 jpeg_finish_compress(&_cinfo); | |
254 | <a name="l00219"></a>00219 } | |
255 | <a name="l00220"></a>00220 }; | |
256 | <a name="l00221"></a>00221 | |
257 | <a name="l00222"></a>00222 } <span class="comment">// namespace detail</span> | |
258 | <a name="l00223"></a>00223 | |
259 | <a name="l00224"></a>00224 } } <span class="comment">// namespace boost::gil</span> | |
260 | <a name="l00225"></a>00225 | |
261 | <a name="l00226"></a>00226 <span class="preprocessor">#endif</span> | |
262 | </pre></div></div> | |
263 | <hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:14 2009 for Generic Image Library by | |
264 | <a href="http://www.doxygen.org/index.html"> | |
265 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> | |
266 | </body> | |
267 | </html> |