54 (j_compress_ptr cinfo)
92 : m_output(os), m_buffer_size(1024)
94 m_buffer =
new JOCTET[m_buffer_size];
95 pub.next_output_byte = m_buffer;
96 pub.free_in_buffer = m_buffer_size;
114 m_output.write((
char*)m_buffer, m_buffer_size);
116 pub.next_output_byte = m_buffer;
117 pub.free_in_buffer = m_buffer_size;
127 m_output.write((
char*)m_buffer, m_buffer_size - pub.free_in_buffer);
138 : quality(75), progressive(false)
151 (
unsigned char quality_,
bool progressive_ )
152 : quality(quality_), progressive(progressive_)
161 const unsigned int claw::graphic::jpeg::writer::s_rgb_pixel_size = 3;
200 jpeg_compress_struct cinfo;
203 cinfo.err = jpeg_std_error(&jerr.
pub);
209 create_compress_info( cinfo, outfile );
213 set_options( cinfo, opt );
215 jpeg_destroy_compress(&cinfo);
219 jpeg_abort_compress(&cinfo);
220 jpeg_destroy_compress(&cinfo);
231 void claw::graphic::jpeg::writer::set_options
232 ( jpeg_compress_struct& cinfo,
const options& opt )
const
234 cinfo.image_width = m_image.width();
235 cinfo.image_height = m_image.height();
236 cinfo.input_components = s_rgb_pixel_size;
237 cinfo.in_color_space = JCS_RGB;
239 jpeg_set_defaults(&cinfo);
241 if (opt.quality > 100)
242 jpeg_set_quality(&cinfo, 100, TRUE);
244 jpeg_set_quality(&cinfo, opt.quality, TRUE);
247 jpeg_simple_progression(&cinfo);
256 claw::graphic::jpeg::writer::save_image( jpeg_compress_struct& cinfo )
const
258 JSAMPLE* data =
new JSAMPLE[ m_image.width() * s_rgb_pixel_size ];
261 jpeg_error_mgr* jerr_saved = cinfo.err;
263 cinfo.err = jpeg_std_error(&jerr.pub);
266 if ( setjmp(jerr.setjmp_buffer) )
269 jpeg_abort_compress(&cinfo);
273 jpeg_start_compress( &cinfo, TRUE );
275 while (cinfo.next_scanline < cinfo.image_height)
277 copy_pixel_line( data, cinfo.next_scanline );
278 jpeg_write_scanlines( &cinfo, &data, 1 );
282 jpeg_finish_compress(&cinfo);
284 cinfo.err = jerr_saved;
294 void claw::graphic::jpeg::writer::copy_pixel_line
295 ( JSAMPLE* data,
unsigned int y )
const
301 for (
unsigned int x=0; x!=m_image.width(); ++x, data+=s_rgb_pixel_size)
303 data[0] = m_image[y][x].components.red;
304 data[1] = m_image[y][x].components.green;
305 data[2] = m_image[y][x].components.blue;
315 void claw::graphic::jpeg::writer::create_compress_info
316 ( jpeg_compress_struct& cinfo, destination_manager& outfile )
const
318 jpeg_create_compress(&cinfo);
320 cinfo.dest = &outfile.pub;
321 cinfo.client_data = &outfile;
323 outfile.pub.init_destination =
325 outfile.pub.empty_output_buffer =
327 outfile.pub.term_destination =