00001 /*********************************************************************** 00002 filename: SILLYJPGImageContext.cpp 00003 created: 11 Jun 2006 00004 author: Olivier Delannoy 00005 00006 purpose: Definition of the JPGImageContext class methods 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifdef HAVE_CONFIG_H 00031 #include <config.h> 00032 #endif 00033 00034 #include "loaders/SILLYJPGImageContext.h" 00035 00036 #ifndef SILLY_OPT_INLINE 00037 #define inline 00038 #include "loaders/SILLYJPGImageContext.icpp" 00039 #undef inline 00040 #endif 00041 00042 #include <jpeglib.h> 00043 00044 // Start section of namespace SILLY 00045 namespace SILLY 00046 { 00047 00048 00049 void JPG_init_source(j_decompress_ptr cinfo) 00050 { 00051 // Nothing to do 00052 } 00053 00054 boolean JPG_fill_input_buffer(j_decompress_ptr cinfo) 00055 { 00056 JPGImageContext* jpg = reinterpret_cast<JPGImageContext*>(cinfo->client_data); 00057 cinfo->src->next_input_byte = jpg->d_source->getDataPtr(); 00058 cinfo->src->bytes_in_buffer = jpg->d_source->getSize(); 00059 return TRUE; 00060 } 00061 00062 void JPG_skip_input_data(j_decompress_ptr cinfo, long num_bytes) 00063 { 00064 if (num_bytes > 0) 00065 { 00066 cinfo->src->next_input_byte += (size_t)num_bytes; 00067 cinfo->src->bytes_in_buffer -= (size_t)num_bytes; 00068 } 00069 } 00070 00071 void JPG_term_source(j_decompress_ptr cinfo) 00072 { 00073 // Nothing to do 00074 } 00075 00076 void JPG_error_exit(j_common_ptr cinfo) 00077 { 00078 JPGImageContext* jpg = reinterpret_cast<JPGImageContext*>(cinfo->client_data); 00079 // TODO 00080 longjmp(jpg->setjmp_buffer, 1); 00081 00082 } 00083 00084 void JPG_emit_message(j_common_ptr cinfo, int msg_level) 00085 { 00086 // Ignore 00087 } 00088 00089 00090 JPGImageContext::JPGImageContext() 00091 : ImageContext(0, 0) 00092 { 00093 src_mgr.bytes_in_buffer = 0; 00094 src_mgr.next_input_byte = 0; 00095 src_mgr.init_source = JPG_init_source; 00096 src_mgr.fill_input_buffer = JPG_fill_input_buffer; 00097 src_mgr.skip_input_data = JPG_skip_input_data; 00098 src_mgr.resync_to_restart = jpeg_resync_to_restart; 00099 src_mgr.term_source = JPG_term_source; 00100 jpeg_create_decompress(&cinfo); 00101 cinfo.src = &src_mgr; 00102 cinfo.client_data = this; 00103 cinfo.err = jpeg_std_error(&d_error_mgr); 00104 d_error_mgr.error_exit = JPG_error_exit; 00105 00106 } 00107 00108 00109 JPGImageContext::~JPGImageContext() 00110 { 00111 jpeg_destroy_decompress(&cinfo); 00112 } 00113 00114 00115 void JPGImageContext::setImageSize() 00116 { 00117 setWidth(cinfo.output_width); 00118 setHeight(cinfo.output_height); 00119 } 00120 00121 } // End section of namespace SILLY