25 extern void * malloc JPP((
size_t size));
26 extern void free JPP((
void *ptr));
37 #define SIZEOF(object) ((size_t) sizeof(object))
43 #define JFREAD(file,buf,sizeofbuf) \
44 ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
45 #define JFWRITE(file,buf,sizeofbuf) \
46 ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
64 struct jpeg_error_mgr pub;
65 jmp_buf setjmp_buffer;
68 typedef my_error_mgr * my_error_ptr;
75 void my_error_exit(j_common_ptr cinfo)
78 my_error_ptr myerr = (my_error_ptr) cinfo->err;
85 longjmp(myerr->setjmp_buffer, 1);
88 typedef struct jpeg_decompress_struct my_jpeg_decompress_struct;
89 typedef struct jpeg_compress_struct my_jpeg_compress_struct;
105 struct jpeg_destination_mgr pub;
108 } slip_destination_mgr;
110 typedef slip_destination_mgr * slip_dest_ptr;
112 #define OUTPUT_BUF_SIZE 4096
119 slip_init_destination (j_compress_ptr cinfo)
121 slip_dest_ptr dest = (slip_dest_ptr) cinfo->dest;
124 dest->buffer = (JOCTET *)
125 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
126 OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
128 dest->pub.next_output_byte = dest->buffer;
129 dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
156 slip_empty_output_buffer (j_compress_ptr cinfo)
158 slip_dest_ptr dest = (slip_dest_ptr) cinfo->dest;
160 if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
161 (size_t) OUTPUT_BUF_SIZE)
162 ERREXIT(cinfo, JERR_FILE_WRITE);
164 dest->pub.next_output_byte = dest->buffer;
165 dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
180 slip_term_destination (j_compress_ptr cinfo)
182 slip_dest_ptr dest = (slip_dest_ptr) cinfo->dest;
183 size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
187 if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
188 ERREXIT(cinfo, JERR_FILE_WRITE);
190 fflush(dest->outfile);
192 if (ferror(dest->outfile))
193 ERREXIT(cinfo, JERR_FILE_WRITE);
203 slip_jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
213 if (cinfo->dest == 0) {
214 cinfo->dest = (
struct jpeg_destination_mgr *)
215 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
216 SIZEOF(slip_destination_mgr));
219 dest = (slip_dest_ptr) cinfo->dest;
220 dest->pub.init_destination = slip_init_destination;
221 dest->pub.empty_output_buffer = slip_empty_output_buffer;
222 dest->pub.term_destination = slip_term_destination;
223 dest->outfile = outfile;
239 struct jpeg_source_mgr pub;
243 boolean start_of_file;
246 typedef slip_source_mgr * slip_src_ptr;
248 #define INPUT_BUF_SIZE 4096
257 slip_init_source (j_decompress_ptr cinfo)
259 slip_src_ptr src = (slip_src_ptr) cinfo->src;
265 src->start_of_file = TRUE;
302 slip_fill_input_buffer (j_decompress_ptr cinfo)
304 slip_src_ptr src = (slip_src_ptr) cinfo->src;
307 nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
310 if (src->start_of_file)
311 ERREXIT(cinfo, JERR_INPUT_EMPTY);
312 WARNMS(cinfo, JWRN_JPEG_EOF);
314 src->buffer[0] = (JOCTET) 0xFF;
315 src->buffer[1] = (JOCTET) JPEG_EOI;
319 src->pub.next_input_byte = src->buffer;
320 src->pub.bytes_in_buffer = nbytes;
321 src->start_of_file = FALSE;
339 slip_skip_input_data (j_decompress_ptr cinfo,
long num_bytes)
341 struct jpeg_source_mgr * src = cinfo->src;
348 while (num_bytes > (
long) src->bytes_in_buffer) {
349 num_bytes -= (long) src->bytes_in_buffer;
350 (
void) (*src->fill_input_buffer) (cinfo);
355 src->next_input_byte += (size_t) num_bytes;
356 src->bytes_in_buffer -= (size_t) num_bytes;
380 slip_term_source (j_decompress_ptr cinfo)
393 slip_jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
404 if (cinfo->src == 0) {
405 cinfo->src = (
struct jpeg_source_mgr *)
406 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
407 SIZEOF(slip_source_mgr));
408 src = (slip_src_ptr) cinfo->src;
409 src->buffer = (JOCTET *)
410 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
411 INPUT_BUF_SIZE * SIZEOF(JOCTET));
414 src = (slip_src_ptr) cinfo->src;
415 src->pub.init_source = slip_init_source;
416 src->pub.fill_input_buffer = slip_fill_input_buffer;
417 src->pub.skip_input_data = slip_skip_input_data;
418 src->pub.resync_to_restart = jpeg_resync_to_restart;
419 src->pub.term_source = slip_term_source;
420 src->infile = infile;
421 src->pub.bytes_in_buffer = 0;
422 src->pub.next_input_byte = 0;