Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #include <claw/jpeg_error_manager.hpp>
00032 #include <claw/exception.hpp>
00033
00034
00040 template<class Convert>
00041 void claw::graphic::jpeg::reader::read_data
00042 ( jpeg_decompress_struct& cinfo, const Convert& pixel_convert )
00043 {
00044 const unsigned int pixel_size = cinfo.output_components;
00045 JSAMPLE* buffer = new JSAMPLE[cinfo.output_width * pixel_size];
00046
00047 error_manager jerr;
00048 jpeg_error_mgr* jerr_saved = cinfo.err;
00049
00050 cinfo.err = jpeg_std_error(&jerr.pub);
00051 jerr.pub.error_exit = jpeg__error_manager__error_exit;
00052
00053 if ( setjmp(jerr.setjmp_buffer) )
00054 {
00055 delete[] buffer;
00056 throw CLAW_EXCEPTION(jerr.error_string);
00057 }
00058
00059 while (cinfo.output_scanline < cinfo.output_height)
00060 {
00061 jpeg_read_scanlines(&cinfo, &buffer, 1);
00062
00063 scanline::iterator pixel = m_image[cinfo.output_scanline-1].begin();
00064
00065 for ( unsigned int i=0; i!=pixel_size*m_image.width();
00066 i+=pixel_size, ++pixel )
00067 *pixel = pixel_convert( &buffer[i] );
00068 }
00069
00070 delete[] buffer;
00071 cinfo.err = jerr_saved;
00072 }