jpeg_reader.tpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
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 } // jpeg::reader::read_data()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1