60 return self->fill_input_buffer();
78 return self->skip_input_data(num_bytes);
98 : m_input(is), m_buffer_size(1024), m_stream_position(0)
100 std::istream::pos_type pos = is.tellg();
102 is.seekg( 0 , std::ios_base::end );
103 m_stream_size = is.tellg() ;
105 is.seekg( pos, std::ios_base::beg ) ;
107 m_buffer =
new JOCTET[m_buffer_size];
108 pub.bytes_in_buffer = 0;
127 unsigned int n = std::min( m_buffer_size, m_stream_size - m_stream_position );
128 m_input.read( (
char*)m_buffer, n );
130 pub.next_input_byte = m_buffer;
131 pub.bytes_in_buffer = n;
133 m_stream_position += n;
151 if ( (
size_t)num_bytes <= pub.bytes_in_buffer )
153 pub.next_input_byte += num_bytes;
154 pub.bytes_in_buffer -= num_bytes;
158 num_bytes -= pub.bytes_in_buffer;
160 long div = num_bytes / m_buffer_size;
161 long rest = num_bytes % m_buffer_size;
163 for (
long i=0; i!=(div+1); ++i)
166 pub.next_input_byte += rest;
167 pub.bytes_in_buffer -= rest;
179 claw::graphic::jpeg::reader::RGB_to_pixel32::operator()
180 (
const JSAMPLE* pixel )
const
197 claw::graphic::jpeg::reader::grayscale_to_pixel32::operator()
198 (
const JSAMPLE* pixel )
const
246 std::istream::pos_type init_pos = f.tellg();
255 f.seekg( init_pos, std::ios_base::beg );
265 void claw::graphic::jpeg::reader::read_from_file( std::istream& f )
267 source_manager infile(f);
268 jpeg_decompress_struct cinfo;
271 cinfo.err = jpeg_std_error(&jerr.
pub);
276 create_decompress_info( cinfo, infile );
281 decompress(f, cinfo);
282 jpeg_destroy_decompress(&cinfo);
286 jpeg_destroy_decompress(&cinfo);
297 void claw::graphic::jpeg::reader::decompress
298 ( std::istream& f, jpeg_decompress_struct& cinfo )
301 jpeg_error_mgr* jerr_saved = cinfo.err;
303 cinfo.err = jpeg_std_error(&jerr.pub);
306 if ( setjmp(jerr.setjmp_buffer) )
308 jpeg_abort_decompress(&cinfo);
312 jpeg_read_header(&cinfo, TRUE);
313 jpeg_start_decompress( &cinfo );
317 m_image.set_size( cinfo.image_width, cinfo.image_height );
319 if ( cinfo.out_color_components == 3 )
320 read_data( cinfo, RGB_to_pixel32() );
321 else if ( cinfo.out_color_components == 1 )
322 read_data( cinfo, grayscale_to_pixel32() );
326 jpeg_finish_decompress(&cinfo);
330 jpeg_abort_decompress(&cinfo);
334 cinfo.err = jerr_saved;
343 void claw::graphic::jpeg::reader::create_decompress_info
344 ( jpeg_decompress_struct& cinfo, source_manager& infile )
const
346 jpeg_create_decompress(&cinfo);
348 cinfo.src = &infile.pub;
349 cinfo.client_data = &infile;
351 infile.pub.fill_input_buffer =
353 infile.pub.skip_input_data =
356 infile.pub.resync_to_restart = jpeg_resync_to_restart;