96 , m_stream_position(0)
98 std::istream::pos_type pos = is.tellg();
100 is.seekg(0, std::ios_base::end);
101 m_stream_size = is.tellg();
103 is.seekg(pos, std::ios_base::beg);
105 m_buffer =
new JOCTET[m_buffer_size];
106 pub.bytes_in_buffer = 0;
122 unsigned int n = std::min(m_buffer_size, m_stream_size - m_stream_position);
123 m_input.read((
char*)m_buffer, n);
125 pub.next_input_byte = m_buffer;
126 pub.bytes_in_buffer = n;
128 m_stream_position += n;
145 if((
size_t)num_bytes <=
pub.bytes_in_buffer)
147 pub.next_input_byte += num_bytes;
148 pub.bytes_in_buffer -= num_bytes;
152 num_bytes -=
pub.bytes_in_buffer;
154 long div = num_bytes / m_buffer_size;
155 long rest = num_bytes % m_buffer_size;
157 for(
long i = 0; i != (div + 1); ++i)
160 pub.next_input_byte += rest;
161 pub.bytes_in_buffer -= rest;
169claw::graphic::jpeg::reader::RGB_to_pixel32::operator()(
170 const JSAMPLE* pixel)
const
186claw::graphic::jpeg::reader::grayscale_to_pixel32::operator()(
187 const JSAMPLE* pixel)
const
227 std::istream::pos_type init_pos = f.tellg();
236 f.seekg(init_pos, std::ios_base::beg);
245void claw::graphic::jpeg::reader::read_from_file(std::istream& f)
247 source_manager infile(f);
248 jpeg_decompress_struct cinfo;
251 cinfo.err = jpeg_std_error(&jerr.
pub);
256 create_decompress_info(cinfo, infile);
261 decompress(f, cinfo);
262 jpeg_destroy_decompress(&cinfo);
266 jpeg_destroy_decompress(&cinfo);
276void claw::graphic::jpeg::reader::decompress(std::istream& f,
277 jpeg_decompress_struct& cinfo)
280 jpeg_error_mgr* jerr_saved = cinfo.err;
282 cinfo.err = jpeg_std_error(&jerr.pub);
285 if(setjmp(jerr.setjmp_buffer))
287 jpeg_abort_decompress(&cinfo);
291 jpeg_read_header(&cinfo, TRUE);
292 jpeg_start_decompress(&cinfo);
296 m_image.set_size(cinfo.image_width, cinfo.image_height);
298 if(cinfo.out_color_components == 3)
299 read_data(cinfo, RGB_to_pixel32());
300 else if(cinfo.out_color_components == 1)
301 read_data(cinfo, grayscale_to_pixel32());
305 jpeg_finish_decompress(&cinfo);
309 jpeg_abort_decompress(&cinfo);
313 cinfo.err = jerr_saved;
321void claw::graphic::jpeg::reader::create_decompress_info(
322 jpeg_decompress_struct& cinfo, source_manager& infile)
const
324 jpeg_create_decompress(&cinfo);
326 cinfo.src = &infile.pub;
327 cinfo.client_data = &infile;
329 infile.pub.fill_input_buffer
331 infile.pub.skip_input_data
334 infile.pub.resync_to_restart = jpeg_resync_to_restart;
Some assert macros to strengthen you code.
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
image()
Constructor. Creates an image without datas.
void load(std::istream &f)
Load an image from a jpeg file.
reader(image &img)
Constructor.
A simple class to use as exception with string message.
#define CLAW_EXCEPTION(m)
Create an exception and add the name of the current function to the message.
A class for jpeg pictures.
Methods for the claw::graphic::jpeg::error_manager class.
claw__graphic__jpeg__source_manager__init_source(j_decompress_ptr cinfo)
Initialize the input stream.
claw__graphic__jpeg__source_manager__term_source(j_decompress_ptr cinfo)
Close the input stream.
claw__graphic__jpeg__source_manager__fill_input_buffer(j_decompress_ptr cinfo)
Fill the input buffer with new data.
claw__graphic__jpeg__source_manager__skip_input_data(j_decompress_ptr cinfo, long num_bytes)
Skip some bytes in the input buffer.
rgba_pixel rgba_pixel_8
A color with 8 bits per component and an alpha channel.
void jpeg__error_manager__error_exit(j_common_ptr cinfo)
Throw an exception when an error occurs in an internal jpeg processing.
Error handler that throw an exception instead of exiting the program.
std::string error_string
A comprehensive description of the error.
struct jpeg_error_mgr pub
"public" fields, needed by the jpeg library.
jmp_buf setjmp_buffer
For return to caller.
Source manager that allow us to read from a std::istream.
void skip_input_data(long num_bytes)
Skip some bytes in the input buffer.
boolean fill_input_buffer()
Fill the input buffer with new data.
source_manager(std::istream &is)
Constructor.
~source_manager()
Destructor.
struct jpeg_source_mgr pub
"public" fields, needed by the jpeg library.
component_type red
Red component.
struct claw::graphic::rgba_pixel::@243011111317154221214371326113376113353054140240::@062221254366262347154034240363361326201063204322 components
Component by component representation.
component_type alpha
Translucy.
component_type green
Green component.
component_type blue
Blue component.