/* * A simple wrapper of JPEG decoder. * * Copyright (C) Hidenori TAKESHIMA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include #include #include #include "ijgdec.h" #if defined(HAVE_LIBJPEG) && defined(HAVE_JPEGLIB_H) #include #include #include typedef struct IJGSrcImpl IJGSrcImpl; typedef struct IJGErrImpl IJGErrImpl; struct IJGSrcImpl { struct jpeg_source_mgr pub; /* must be first */ const char** ppsrcs; const int* plenofsrcs; int srccount; int srcindex; }; struct IJGErrImpl { struct jpeg_error_mgr err; jmp_buf env; }; /* for the jpeg decompressor source manager. */ static void IJGDec_init_source(j_decompress_ptr cinfo) {} static boolean IJGDec_fill_input_buffer(j_decompress_ptr cinfo) { IJGSrcImpl* pImpl = (IJGSrcImpl*)cinfo->src; if ( pImpl->srcindex >= pImpl->srccount ) { ERREXIT(cinfo, JERR_INPUT_EMPTY); } pImpl->pub.next_input_byte = pImpl->ppsrcs[pImpl->srcindex]; pImpl->pub.bytes_in_buffer = pImpl->plenofsrcs[pImpl->srcindex]; pImpl->srcindex ++; return TRUE; } static void IJGDec_skip_input_data(j_decompress_ptr cinfo,long num_bytes) { IJGSrcImpl* pImpl = (IJGSrcImpl*)cinfo->src; if ( num_bytes <= 0 ) return; while ( num_bytes > pImpl->pub.bytes_in_buffer ) { num_bytes -= pImpl->pub.bytes_in_buffer; if ( !IJGDec_fill_input_buffer(cinfo) ) { ERREXIT(cinfo, JERR_INPUT_EMPTY); } } pImpl->pub.next_input_byte += num_bytes; pImpl->pub.bytes_in_buffer -= num_bytes; } static void IJGDec_term_source(j_decompress_ptr cinfo) { } static void IJGDec_error_exit(j_common_ptr cinfo) { IJGErrImpl* pImpl = (IJGErrImpl*)cinfo->err; longjmp(pImpl->env,1); } static void rgb_to_bgr(char* pdata,int width) { int x; char c; for(x=0;x