Claw  1.7.3
jpeg_reader.tpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
32 #include <claw/exception.hpp>
33 
34 /*----------------------------------------------------------------------------*/
40 template<class Convert>
41 void claw::graphic::jpeg::reader::read_data
42 ( jpeg_decompress_struct& cinfo, const Convert& pixel_convert )
43 {
44  const unsigned int pixel_size = cinfo.output_components;
45  JSAMPLE* buffer = new JSAMPLE[cinfo.output_width * pixel_size];
46 
47  error_manager jerr;
48  jpeg_error_mgr* jerr_saved = cinfo.err;
49 
50  cinfo.err = jpeg_std_error(&jerr.pub);
51  jerr.pub.error_exit = jpeg__error_manager__error_exit;
52 
53  if ( setjmp(jerr.setjmp_buffer) )
54  {
55  delete[] buffer;
56  throw CLAW_EXCEPTION(jerr.error_string);
57  }
58 
59  while (cinfo.output_scanline < cinfo.output_height)
60  {
61  jpeg_read_scanlines(&cinfo, &buffer, 1);
62 
63  scanline::iterator pixel = m_image[cinfo.output_scanline-1].begin();
64 
65  for ( unsigned int i=0; i!=pixel_size*m_image.width();
66  i+=pixel_size, ++pixel )
67  *pixel = pixel_convert( &buffer[i] );
68  }
69 
70  delete[] buffer;
71  cinfo.err = jerr_saved;
72 } // jpeg::reader::read_data()
unsigned int width() const
Gets image's width.
Definition: image.cpp:147
void jpeg__error_manager__error_exit(j_common_ptr cinfo)
Throw an exception when an error occurs in an internal jpeg processing.
super::iterator iterator
Iterator in the line.
Definition: image.hpp:78
A simple class to use as exception with string message.
iterator begin()
Get an iterator pointing on the first pixel.
Definition: image.cpp:168
Methods for the claw::graphic::jpeg::error_manager class.
#define CLAW_EXCEPTION(m)
Create an exception and add the name of the current function to the message.
Definition: exception.hpp:90