00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00045 namespace SILLY
00046 {
00047
00048
00049 void JPG_init_source(j_decompress_ptr cinfo)
00050 {
00051
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
00074 }
00075
00076 void JPG_error_exit(j_common_ptr cinfo)
00077 {
00078 JPGImageContext* jpg = reinterpret_cast<JPGImageContext*>(cinfo->client_data);
00079
00080 longjmp(jpg->setjmp_buffer, 1);
00081
00082 }
00083
00084 void JPG_emit_message(j_common_ptr cinfo, int msg_level)
00085 {
00086
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 }