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;
claw__graphic__jpeg__source_manager__fill_input_buffer(j_decompress_ptr cinfo)
Fill the input buffer with new data.
void load(std::istream &f)
Load an image from a jpeg file.
boolean fill_input_buffer()
Fill the input buffer with new data.
source_manager(std::istream &is)
Constructor.
claw__graphic__jpeg__source_manager__term_source(j_decompress_ptr cinfo)
Close the input stream.
A class for jpeg pictures.
#define CLAW_EXCEPTION(m)
Create an exception and add the name of the current function to the message.
struct jpeg_error_mgr pub
"public" fields, needed by the jpeg library.
claw__graphic__jpeg__source_manager__skip_input_data(j_decompress_ptr cinfo, long num_bytes)
Skip some bytes in the input buffer.
std::string error_string
A comprehensive description of the error.
struct claw::graphic::rgba_pixel::@15::@17 components
Component by component representation.
void jpeg__error_manager__error_exit(j_common_ptr cinfo)
Throw an exception when an error occurs in an internal jpeg processing.
jmp_buf setjmp_buffer
For return to caller.
struct jpeg_source_mgr pub
"public" fields, needed by the jpeg library.
Error handler that throw an exception instead of exiting the program.
A simple class to use as exception with string message.
Source manager that allow us to read from a std::istream.
Some assert macros to strengthen you code.
claw__graphic__jpeg__source_manager__init_source(j_decompress_ptr cinfo)
Initialize the input stream.
A class to deal with images.
Methods for the claw::graphic::jpeg::error_manager class.
~source_manager()
Destructor.
reader(image &img)
Constructor.
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
void skip_input_data(long num_bytes)
Skip some bytes in the input buffer.