The JPEG patch: Index: src/ChangeLog =================================================================== RCS file: /cvsroot/emacs/emacs/src/ChangeLog,v retrieving revision 1.4462 diff -u -2 -r1.4462 ChangeLog --- src/ChangeLog 15 Jun 2005 02:30:03 -0000 1.4462 +++ src/ChangeLog 15 Jun 2005 09:32:35 -0000 @@ -1,2 +1,19 @@ +2005-06-15 Juanma Barranquero <[EMAIL PROTECTED]> + + * image.c (fn_jpeg_stdio_src): Don't define it. + (init_jpeg_functions) [HAVE_NTGUI]: Don't initialize + fn_jpeg_stdio_src. + (our_common_term_source): Rename from our_term_source. + (our_memory_init_source): Rename from our_init_source. + (our_memory_fill_input_buffer): Rename from our_fill_input_buffer. + (our_memory_skip_input_data): Rename from our_skip_input_data. + (jpeg_memory_src): Use the renamed functions. + (my_jpeg_file_src): New struct. + (my_jpeg_file_ptr): New typedef. + (JPEG_INPUT_BUF_SIZE): New constant. + (our_file_init_source, our_file_fill_input_buffer) + (our_file_skip_input_data, jpeg_file_src): New functions. + (jpeg_load): Use jpeg_file_src instead of fn_jpeg_stdio_src. + 2005-06-15 YAMAMOTO Mitsuharu <[EMAIL PROTECTED]> Index: src/image.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/image.c,v retrieving revision 1.27 diff -u -2 -r1.27 image.c --- src/image.c 11 Jun 2005 16:24:36 -0000 1.27 +++ src/image.c 15 Jun 2005 09:25:19 -0000 @@ -6295,5 +6295,4 @@ DEF_IMGLIB_FN (jpeg_read_header); DEF_IMGLIB_FN (jpeg_read_scanlines); -DEF_IMGLIB_FN (jpeg_stdio_src); DEF_IMGLIB_FN (jpeg_std_error); DEF_IMGLIB_FN (jpeg_resync_to_restart); @@ -6311,5 +6310,4 @@ LOAD_IMGLIB_FN (library, jpeg_start_decompress); LOAD_IMGLIB_FN (library, jpeg_read_header); - LOAD_IMGLIB_FN (library, jpeg_stdio_src); LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); @@ -6337,5 +6335,4 @@ #define fn_jpeg_read_header jpeg_read_header #define fn_jpeg_read_scanlines jpeg_read_scanlines -#define fn_jpeg_stdio_src jpeg_stdio_src #define fn_jpeg_std_error jpeg_std_error #define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart @@ -6359,4 +6356,15 @@ +/* Method to terminate data source. Called by + jpeg_finish_decompress() after all data has been processed. + Common to memory and file source managers. */ + +static void +our_common_term_source (cinfo) + j_decompress_ptr cinfo; +{ +} + + /* Init source method for JPEG data source manager. Called by jpeg_read_header() before any data is actually read. See @@ -6364,5 +6372,5 @@ static void -our_init_source (cinfo) +our_memory_init_source (cinfo) j_decompress_ptr cinfo; { @@ -6375,5 +6383,5 @@ static boolean -our_fill_input_buffer (cinfo) +our_memory_fill_input_buffer (cinfo) j_decompress_ptr cinfo; { @@ -6395,5 +6403,5 @@ static void -our_skip_input_data (cinfo, num_bytes) +our_memory_skip_input_data (cinfo, num_bytes) j_decompress_ptr cinfo; long num_bytes; @@ -6412,14 +6420,4 @@ -/* Method to terminate data source. Called by - jpeg_finish_decompress() after all data has been processed. */ - -static void -our_term_source (cinfo) - j_decompress_ptr cinfo; -{ -} - - /* Set up the JPEG lib for reading an image from DATA which contains LEN bytes. CINFO is the decompression info structure created for @@ -6445,9 +6443,9 @@ src = (struct jpeg_source_mgr *) cinfo->src; - src->init_source = our_init_source; - src->fill_input_buffer = our_fill_input_buffer; - src->skip_input_data = our_skip_input_data; + src->init_source = our_memory_init_source; + src->fill_input_buffer = our_memory_fill_input_buffer; + src->skip_input_data = our_memory_skip_input_data; src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ - src->term_source = our_term_source; + src->term_source = our_common_term_source; src->bytes_in_buffer = len; src->next_input_byte = data; @@ -6455,4 +6453,136 @@ +/* JPEG data source manager setup for JPEG images read from a file. + Heavily based on jdatasrc.c from the JPEG library. */ + +struct my_jpeg_file_src { + struct jpeg_source_mgr pub; /* public fields */ + + FILE *infile; /* source stream */ + JOCTET *buffer; /* start of buffer */ + boolean start_of_file; /* have we gotten any data yet? */ +}; + +typedef struct my_jpeg_file_src *my_jpeg_file_ptr; + +#define JPEG_INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ + + +/* Init source method for JPEG data source manager. + Called by jpeg_read_header() before any data is actually read. */ + +static void +our_file_init_source (j_decompress_ptr cinfo) +{ + my_jpeg_file_ptr src = (my_jpeg_file_ptr) cinfo->src; + + /* We reset the empty-input-file flag for each image, + * but we don't clear the input buffer. + * This is correct behavior for reading a series of images from one source. + */ + src->start_of_file = 1; +} + + +/* Fill input buffer method for JPEG data source manager. + Called whenever more data is needed. */ + +static boolean +our_file_fill_input_buffer (j_decompress_ptr cinfo) +{ + my_jpeg_file_ptr src = (my_jpeg_file_ptr) cinfo->src; + size_t nbytes; + + nbytes = fread (src->buffer, 1, JPEG_INPUT_BUF_SIZE, src->infile); + + if (nbytes <= 0) { + if (src->start_of_file) /* Treat empty input file as fatal error */ + ERREXIT (cinfo, JERR_INPUT_EMPTY); + WARNMS (cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + src->buffer[0] = (JOCTET) 0xFF; + src->buffer[1] = (JOCTET) JPEG_EOI; + nbytes = 2; + } + + src->pub.next_input_byte = src->buffer; + src->pub.bytes_in_buffer = nbytes; + src->start_of_file = 0; + + return 1; +} + + +/* Method to skip over NUM_BYTES bytes in the image data. + CINFO->src is the JPEG data source manager. */ + +static void +our_file_skip_input_data (j_decompress_ptr cinfo, long num_bytes) +{ + my_jpeg_file_ptr src = (my_jpeg_file_ptr) cinfo->src; + + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if (num_bytes > 0) + { + while (num_bytes > (long) src->pub.bytes_in_buffer) + { + num_bytes -= (long) src->pub.bytes_in_buffer; + (void) our_file_fill_input_buffer (cinfo); + /* note we assume that fill_file_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->pub.next_input_byte += (size_t) num_bytes; + src->pub.bytes_in_buffer -= (size_t) num_bytes; + } +} + + +/* Set up the JPEG lib for reading an image from a FILE * via + a customized function, thus avoiding FILE * conflicts between + different builds of the image library. CINFO is the + decompression info structure created for reading the image. */ + +static void +jpeg_file_src (cinfo, infile) + j_decompress_ptr cinfo; + FILE *infile; +{ + my_jpeg_file_ptr src; + + /* The source object and input buffer are made permanent so that a series + * of JPEG images can be read from the same file by calling jpeg_stdio_src + * only before the first one. (If we discarded the buffer at the end of + * one image, we'd likely lose the start of the next one.) + * This makes it unsafe to use this manager and a different source + * manager serially with the same JPEG object. Caveat programmer. + */ + if (cinfo->src == NULL) + { + /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + sizeof (struct my_jpeg_file_src)); + src = (my_jpeg_file_ptr) cinfo->src; + src->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + JPEG_INPUT_BUF_SIZE * sizeof (JOCTET)); + } + + src = (my_jpeg_file_ptr) cinfo->src; + src->pub.init_source = our_file_init_source; + src->pub.fill_input_buffer = our_file_fill_input_buffer; + src->pub.skip_input_data = our_file_skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart_wrapper; /* use default method */ + src->pub.term_source = our_common_term_source; + src->infile = infile; + src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ + src->pub.next_input_byte = NULL; /* until buffer loaded */ +} + + /* Load image IMG for use on frame F. Patterned after example.c from the JPEG lib. */ @@ -6538,5 +6668,5 @@ if (NILP (specified_data)) - fn_jpeg_stdio_src (&cinfo, (FILE *) fp); + jpeg_file_src (&cinfo, fp); else jpeg_memory_src (&cinfo, SDATA (specified_data),
_______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel