diff options
| author | Paul Eggert | 2012-09-12 14:34:24 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-09-12 14:34:24 -0700 |
| commit | 40bce90baad677cd631c27819b32cca9c5d3a1ab (patch) | |
| tree | 7c096868112d49bbe3066739bdf007c67a1919e3 /src | |
| parent | a9f9d9de77e246af750ce5304320b0f66a085ea9 (diff) | |
| download | emacs-40bce90baad677cd631c27819b32cca9c5d3a1ab.tar.gz emacs-40bce90baad677cd631c27819b32cca9c5d3a1ab.zip | |
More fixes for 'volatile' and setjmp/longjmp.
* eval.c (Fdefvar, Fcondition_case): Remove unnecessary 'volatile's.
* image.c (struct png_load_context) [HAVE_PNG]: New type.
(png_load_body) [HAVE_PNG]:
(jpeg_load_body) [HAVE_JPEG]:
New function, with most of the old parent function's body.
(png_load) [HAVE_PNG]:
(jpeg_load) [HAVE_JPEG]:
Invoke the new function, to avoid longjmp munging our locals.
(struct my_jpeg_error_mgr) [HAVE_JPEG]: New members cinfo, failure_code.
(my_error_exit) [HAVE_JPEG]: Don't trust 'setjmp' to return 2 when
longjmp is passed 2, as the C standard doesn't guarantee this.
Instead, store the failure code into mgr->failure_code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 16 | ||||
| -rw-r--r-- | src/eval.c | 11 | ||||
| -rw-r--r-- | src/image.c | 196 |
3 files changed, 144 insertions, 79 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 8b47c52c23f..c0d3316bea1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2012-09-12 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | More fixes for 'volatile' and setjmp/longjmp. | ||
| 4 | * eval.c (Fdefvar, Fcondition_case): Remove unnecessary 'volatile's. | ||
| 5 | * image.c (struct png_load_context) [HAVE_PNG]: New type. | ||
| 6 | (png_load_body) [HAVE_PNG]: | ||
| 7 | (jpeg_load_body) [HAVE_JPEG]: | ||
| 8 | New function, with most of the old parent function's body. | ||
| 9 | (png_load) [HAVE_PNG]: | ||
| 10 | (jpeg_load) [HAVE_JPEG]: | ||
| 11 | Invoke the new function, to avoid longjmp munging our locals. | ||
| 12 | (struct my_jpeg_error_mgr) [HAVE_JPEG]: New members cinfo, failure_code. | ||
| 13 | (my_error_exit) [HAVE_JPEG]: Don't trust 'setjmp' to return 2 when | ||
| 14 | longjmp is passed 2, as the C standard doesn't guarantee this. | ||
| 15 | Instead, store the failure code into mgr->failure_code. | ||
| 16 | |||
| 1 | 2012-09-12 Stefan Monnier <monnier@iro.umontreal.ca> | 17 | 2012-09-12 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 18 | ||
| 3 | * keyboard.c (read_char, requeued_events_pending_p, Finput_pending_p) | 19 | * keyboard.c (read_char, requeued_events_pending_p, Finput_pending_p) |
diff --git a/src/eval.c b/src/eval.c index 8a8a507a1b6..3c0c65e9366 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -707,7 +707,7 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | |||
| 707 | else | 707 | else |
| 708 | { /* Check if there is really a global binding rather than just a let | 708 | { /* Check if there is really a global binding rather than just a let |
| 709 | binding that shadows the global unboundness of the var. */ | 709 | binding that shadows the global unboundness of the var. */ |
| 710 | volatile struct specbinding *pdl = specpdl_ptr; | 710 | struct specbinding *pdl = specpdl_ptr; |
| 711 | while (pdl > specpdl) | 711 | while (pdl > specpdl) |
| 712 | { | 712 | { |
| 713 | if (EQ ((--pdl)->symbol, sym) && !pdl->func | 713 | if (EQ ((--pdl)->symbol, sym) && !pdl->func |
| @@ -1204,12 +1204,9 @@ See also the function `signal' for more info. | |||
| 1204 | usage: (condition-case VAR BODYFORM &rest HANDLERS) */) | 1204 | usage: (condition-case VAR BODYFORM &rest HANDLERS) */) |
| 1205 | (Lisp_Object args) | 1205 | (Lisp_Object args) |
| 1206 | { | 1206 | { |
| 1207 | register Lisp_Object bodyform, handlers; | 1207 | Lisp_Object var = Fcar (args); |
| 1208 | volatile Lisp_Object var; | 1208 | Lisp_Object bodyform = Fcar (Fcdr (args)); |
| 1209 | 1209 | Lisp_Object handlers = Fcdr (Fcdr (args)); | |
| 1210 | var = Fcar (args); | ||
| 1211 | bodyform = Fcar (Fcdr (args)); | ||
| 1212 | handlers = Fcdr (Fcdr (args)); | ||
| 1213 | 1210 | ||
| 1214 | return internal_lisp_condition_case (var, bodyform, handlers); | 1211 | return internal_lisp_condition_case (var, bodyform, handlers); |
| 1215 | } | 1212 | } |
diff --git a/src/image.c b/src/image.c index cf01602050f..cd5df99ef57 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -5591,20 +5591,31 @@ png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length) | |||
| 5591 | /* Load PNG image IMG for use on frame F. Value is non-zero if | 5591 | /* Load PNG image IMG for use on frame F. Value is non-zero if |
| 5592 | successful. */ | 5592 | successful. */ |
| 5593 | 5593 | ||
| 5594 | struct png_load_context | ||
| 5595 | { | ||
| 5596 | /* These are members so that _longjmp doesn't munge local variables. */ | ||
| 5597 | png_struct *png_ptr; | ||
| 5598 | png_info *info_ptr; | ||
| 5599 | png_info *end_info; | ||
| 5600 | FILE *fp; | ||
| 5601 | png_byte *pixels; | ||
| 5602 | png_byte **rows; | ||
| 5603 | }; | ||
| 5604 | |||
| 5594 | static int | 5605 | static int |
| 5595 | png_load (struct frame *f, struct image *img) | 5606 | png_load_body (struct frame *f, struct image *img, struct png_load_context *c) |
| 5596 | { | 5607 | { |
| 5597 | Lisp_Object file, specified_file; | 5608 | Lisp_Object file, specified_file; |
| 5598 | Lisp_Object specified_data; | 5609 | Lisp_Object specified_data; |
| 5599 | int x, y; | 5610 | int x, y; |
| 5600 | ptrdiff_t i; | 5611 | ptrdiff_t i; |
| 5601 | XImagePtr ximg, mask_img = NULL; | 5612 | XImagePtr ximg, mask_img = NULL; |
| 5602 | png_struct *png_ptr = NULL; | 5613 | png_struct *png_ptr; |
| 5603 | png_info *info_ptr = NULL, *end_info = NULL; | 5614 | png_info *info_ptr = NULL, *end_info = NULL; |
| 5604 | FILE *volatile fp = NULL; | 5615 | FILE *fp = NULL; |
| 5605 | png_byte sig[8]; | 5616 | png_byte sig[8]; |
| 5606 | png_byte * volatile pixels = NULL; | 5617 | png_byte *pixels = NULL; |
| 5607 | png_byte ** volatile rows = NULL; | 5618 | png_byte **rows = NULL; |
| 5608 | png_uint_32 width, height; | 5619 | png_uint_32 width, height; |
| 5609 | int bit_depth, color_type, interlace_type; | 5620 | int bit_depth, color_type, interlace_type; |
| 5610 | png_byte channels; | 5621 | png_byte channels; |
| @@ -5671,24 +5682,26 @@ png_load (struct frame *f, struct image *img) | |||
| 5671 | png_ptr = fn_png_create_read_struct (PNG_LIBPNG_VER_STRING, | 5682 | png_ptr = fn_png_create_read_struct (PNG_LIBPNG_VER_STRING, |
| 5672 | NULL, my_png_error, | 5683 | NULL, my_png_error, |
| 5673 | my_png_warning); | 5684 | my_png_warning); |
| 5674 | if (!png_ptr) | 5685 | if (png_ptr) |
| 5675 | { | 5686 | { |
| 5676 | if (fp) fclose (fp); | 5687 | info_ptr = fn_png_create_info_struct (png_ptr); |
| 5677 | return 0; | 5688 | end_info = fn_png_create_info_struct (png_ptr); |
| 5678 | } | 5689 | } |
| 5679 | 5690 | ||
| 5680 | info_ptr = fn_png_create_info_struct (png_ptr); | 5691 | c->png_ptr = png_ptr; |
| 5681 | if (!info_ptr) | 5692 | c->info_ptr = info_ptr; |
| 5693 | c->end_info = end_info; | ||
| 5694 | c->fp = fp; | ||
| 5695 | c->pixels = pixels; | ||
| 5696 | c->rows = rows; | ||
| 5697 | |||
| 5698 | if (! (info_ptr && end_info)) | ||
| 5682 | { | 5699 | { |
| 5683 | fn_png_destroy_read_struct (&png_ptr, NULL, NULL); | 5700 | fn_png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); |
| 5684 | if (fp) fclose (fp); | 5701 | png_ptr = 0; |
| 5685 | return 0; | ||
| 5686 | } | 5702 | } |
| 5687 | 5703 | if (! png_ptr) | |
| 5688 | end_info = fn_png_create_info_struct (png_ptr); | ||
| 5689 | if (!end_info) | ||
| 5690 | { | 5704 | { |
| 5691 | fn_png_destroy_read_struct (&png_ptr, &info_ptr, NULL); | ||
| 5692 | if (fp) fclose (fp); | 5705 | if (fp) fclose (fp); |
| 5693 | return 0; | 5706 | return 0; |
| 5694 | } | 5707 | } |
| @@ -5698,14 +5711,18 @@ png_load (struct frame *f, struct image *img) | |||
| 5698 | if (_setjmp (PNG_JMPBUF (png_ptr))) | 5711 | if (_setjmp (PNG_JMPBUF (png_ptr))) |
| 5699 | { | 5712 | { |
| 5700 | error: | 5713 | error: |
| 5701 | if (png_ptr) | 5714 | if (c->png_ptr) |
| 5702 | fn_png_destroy_read_struct (&png_ptr, &info_ptr, &end_info); | 5715 | fn_png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); |
| 5703 | xfree (pixels); | 5716 | xfree (c->pixels); |
| 5704 | xfree (rows); | 5717 | xfree (c->rows); |
| 5705 | if (fp) fclose (fp); | 5718 | if (c->fp) |
| 5719 | fclose (c->fp); | ||
| 5706 | return 0; | 5720 | return 0; |
| 5707 | } | 5721 | } |
| 5708 | 5722 | ||
| 5723 | /* Silence a bogus diagnostic; see GCC bug 54561. */ | ||
| 5724 | IF_LINT (fp = c->fp); | ||
| 5725 | |||
| 5709 | /* Read image info. */ | 5726 | /* Read image info. */ |
| 5710 | if (!NILP (specified_data)) | 5727 | if (!NILP (specified_data)) |
| 5711 | fn_png_set_read_fn (png_ptr, (void *) &tbr, png_read_from_memory); | 5728 | fn_png_set_read_fn (png_ptr, (void *) &tbr, png_read_from_memory); |
| @@ -5821,8 +5838,8 @@ png_load (struct frame *f, struct image *img) | |||
| 5821 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height | 5838 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height |
| 5822 | || min (PTRDIFF_MAX, SIZE_MAX) / sizeof *pixels / height < row_bytes) | 5839 | || min (PTRDIFF_MAX, SIZE_MAX) / sizeof *pixels / height < row_bytes) |
| 5823 | memory_full (SIZE_MAX); | 5840 | memory_full (SIZE_MAX); |
| 5824 | pixels = xmalloc (sizeof *pixels * row_bytes * height); | 5841 | c->pixels = pixels = xmalloc (sizeof *pixels * row_bytes * height); |
| 5825 | rows = xmalloc (height * sizeof *rows); | 5842 | c->rows = rows = xmalloc (height * sizeof *rows); |
| 5826 | for (i = 0; i < height; ++i) | 5843 | for (i = 0; i < height; ++i) |
| 5827 | rows[i] = pixels + i * row_bytes; | 5844 | rows[i] = pixels + i * row_bytes; |
| 5828 | 5845 | ||
| @@ -5832,7 +5849,7 @@ png_load (struct frame *f, struct image *img) | |||
| 5832 | if (fp) | 5849 | if (fp) |
| 5833 | { | 5850 | { |
| 5834 | fclose (fp); | 5851 | fclose (fp); |
| 5835 | fp = NULL; | 5852 | c->fp = NULL; |
| 5836 | } | 5853 | } |
| 5837 | 5854 | ||
| 5838 | /* Create an image and pixmap serving as mask if the PNG image | 5855 | /* Create an image and pixmap serving as mask if the PNG image |
| @@ -5907,7 +5924,7 @@ png_load (struct frame *f, struct image *img) | |||
| 5907 | #endif /* COLOR_TABLE_SUPPORT */ | 5924 | #endif /* COLOR_TABLE_SUPPORT */ |
| 5908 | 5925 | ||
| 5909 | /* Clean up. */ | 5926 | /* Clean up. */ |
| 5910 | fn_png_destroy_read_struct (&png_ptr, &info_ptr, &end_info); | 5927 | fn_png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); |
| 5911 | xfree (rows); | 5928 | xfree (rows); |
| 5912 | xfree (pixels); | 5929 | xfree (pixels); |
| 5913 | 5930 | ||
| @@ -5936,6 +5953,13 @@ png_load (struct frame *f, struct image *img) | |||
| 5936 | return 1; | 5953 | return 1; |
| 5937 | } | 5954 | } |
| 5938 | 5955 | ||
| 5956 | static int | ||
| 5957 | png_load (struct frame *f, struct image *img) | ||
| 5958 | { | ||
| 5959 | struct png_load_context c; | ||
| 5960 | return png_load_body (f, img, &c); | ||
| 5961 | } | ||
| 5962 | |||
| 5939 | #else /* HAVE_PNG */ | 5963 | #else /* HAVE_PNG */ |
| 5940 | 5964 | ||
| 5941 | #ifdef HAVE_NS | 5965 | #ifdef HAVE_NS |
| @@ -6106,6 +6130,16 @@ struct my_jpeg_error_mgr | |||
| 6106 | { | 6130 | { |
| 6107 | struct jpeg_error_mgr pub; | 6131 | struct jpeg_error_mgr pub; |
| 6108 | jmp_buf setjmp_buffer; | 6132 | jmp_buf setjmp_buffer; |
| 6133 | |||
| 6134 | /* The remaining members are so that _longjmp doesn't munge local | ||
| 6135 | variables. */ | ||
| 6136 | struct jpeg_decompress_struct cinfo; | ||
| 6137 | enum | ||
| 6138 | { | ||
| 6139 | MY_JPEG_ERROR_EXIT, | ||
| 6140 | MY_JPEG_INVALID_IMAGE_SIZE, | ||
| 6141 | MY_JPEG_CANNOT_CREATE_X | ||
| 6142 | } failure_code; | ||
| 6109 | }; | 6143 | }; |
| 6110 | 6144 | ||
| 6111 | 6145 | ||
| @@ -6113,6 +6147,7 @@ static _Noreturn void | |||
| 6113 | my_error_exit (j_common_ptr cinfo) | 6147 | my_error_exit (j_common_ptr cinfo) |
| 6114 | { | 6148 | { |
| 6115 | struct my_jpeg_error_mgr *mgr = (struct my_jpeg_error_mgr *) cinfo->err; | 6149 | struct my_jpeg_error_mgr *mgr = (struct my_jpeg_error_mgr *) cinfo->err; |
| 6150 | mgr->failure_code = MY_JPEG_ERROR_EXIT; | ||
| 6116 | _longjmp (mgr->setjmp_buffer, 1); | 6151 | _longjmp (mgr->setjmp_buffer, 1); |
| 6117 | } | 6152 | } |
| 6118 | 6153 | ||
| @@ -6319,17 +6354,15 @@ jpeg_file_src (j_decompress_ptr cinfo, FILE *fp) | |||
| 6319 | from the JPEG lib. */ | 6354 | from the JPEG lib. */ |
| 6320 | 6355 | ||
| 6321 | static int | 6356 | static int |
| 6322 | jpeg_load (struct frame *f, struct image *img) | 6357 | jpeg_load_body (struct frame *f, struct image *img, |
| 6358 | struct my_jpeg_error_mgr *mgr) | ||
| 6323 | { | 6359 | { |
| 6324 | struct jpeg_decompress_struct cinfo; | ||
| 6325 | struct my_jpeg_error_mgr mgr; | ||
| 6326 | Lisp_Object file, specified_file; | 6360 | Lisp_Object file, specified_file; |
| 6327 | Lisp_Object specified_data; | 6361 | Lisp_Object specified_data; |
| 6328 | FILE * volatile fp = NULL; | 6362 | FILE *fp = NULL; |
| 6329 | JSAMPARRAY buffer; | 6363 | JSAMPARRAY buffer; |
| 6330 | int row_stride, x, y; | 6364 | int row_stride, x, y; |
| 6331 | XImagePtr ximg = NULL; | 6365 | XImagePtr ximg = NULL; |
| 6332 | int rc; | ||
| 6333 | unsigned long *colors; | 6366 | unsigned long *colors; |
| 6334 | int width, height; | 6367 | int width, height; |
| 6335 | 6368 | ||
| @@ -6361,24 +6394,33 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 6361 | 6394 | ||
| 6362 | /* Customize libjpeg's error handling to call my_error_exit when an | 6395 | /* Customize libjpeg's error handling to call my_error_exit when an |
| 6363 | error is detected. This function will perform a longjmp. */ | 6396 | error is detected. This function will perform a longjmp. */ |
| 6364 | cinfo.err = fn_jpeg_std_error (&mgr.pub); | 6397 | mgr->cinfo.err = fn_jpeg_std_error (&mgr->pub); |
| 6365 | mgr.pub.error_exit = my_error_exit; | 6398 | mgr->pub.error_exit = my_error_exit; |
| 6366 | 6399 | if (_setjmp (mgr->setjmp_buffer)) | |
| 6367 | if ((rc = _setjmp (mgr.setjmp_buffer)) != 0) | ||
| 6368 | { | 6400 | { |
| 6369 | if (rc == 1) | 6401 | switch (mgr->failure_code) |
| 6370 | { | 6402 | { |
| 6371 | /* Called from my_error_exit. Display a JPEG error. */ | 6403 | case MY_JPEG_ERROR_EXIT: |
| 6372 | char buf[JMSG_LENGTH_MAX]; | 6404 | { |
| 6373 | cinfo.err->format_message ((j_common_ptr) &cinfo, buf); | 6405 | char buf[JMSG_LENGTH_MAX]; |
| 6374 | image_error ("Error reading JPEG image `%s': %s", img->spec, | 6406 | mgr->cinfo.err->format_message ((j_common_ptr) &mgr->cinfo, buf); |
| 6375 | build_string (buf)); | 6407 | image_error ("Error reading JPEG image `%s': %s", img->spec, |
| 6408 | build_string (buf)); | ||
| 6409 | break; | ||
| 6410 | } | ||
| 6411 | |||
| 6412 | case MY_JPEG_INVALID_IMAGE_SIZE: | ||
| 6413 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); | ||
| 6414 | break; | ||
| 6415 | |||
| 6416 | case MY_JPEG_CANNOT_CREATE_X: | ||
| 6417 | break; | ||
| 6376 | } | 6418 | } |
| 6377 | 6419 | ||
| 6378 | /* Close the input file and destroy the JPEG object. */ | 6420 | /* Close the input file and destroy the JPEG object. */ |
| 6379 | if (fp) | 6421 | if (fp) |
| 6380 | fclose ((FILE *) fp); | 6422 | fclose (fp); |
| 6381 | fn_jpeg_destroy_decompress (&cinfo); | 6423 | fn_jpeg_destroy_decompress (&mgr->cinfo); |
| 6382 | 6424 | ||
| 6383 | /* If we already have an XImage, free that. */ | 6425 | /* If we already have an XImage, free that. */ |
| 6384 | x_destroy_x_image (ximg); | 6426 | x_destroy_x_image (ximg); |
| @@ -6390,44 +6432,47 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 6390 | 6432 | ||
| 6391 | /* Create the JPEG decompression object. Let it read from fp. | 6433 | /* Create the JPEG decompression object. Let it read from fp. |
| 6392 | Read the JPEG image header. */ | 6434 | Read the JPEG image header. */ |
| 6393 | fn_jpeg_CreateDecompress (&cinfo, JPEG_LIB_VERSION, sizeof (cinfo)); | 6435 | fn_jpeg_CreateDecompress (&mgr->cinfo, JPEG_LIB_VERSION, sizeof *&mgr->cinfo); |
| 6394 | 6436 | ||
| 6395 | if (NILP (specified_data)) | 6437 | if (NILP (specified_data)) |
| 6396 | jpeg_file_src (&cinfo, (FILE *) fp); | 6438 | jpeg_file_src (&mgr->cinfo, fp); |
| 6397 | else | 6439 | else |
| 6398 | jpeg_memory_src (&cinfo, SDATA (specified_data), | 6440 | jpeg_memory_src (&mgr->cinfo, SDATA (specified_data), |
| 6399 | SBYTES (specified_data)); | 6441 | SBYTES (specified_data)); |
| 6400 | 6442 | ||
| 6401 | fn_jpeg_read_header (&cinfo, 1); | 6443 | fn_jpeg_read_header (&mgr->cinfo, 1); |
| 6402 | 6444 | ||
| 6403 | /* Customize decompression so that color quantization will be used. | 6445 | /* Customize decompression so that color quantization will be used. |
| 6404 | Start decompression. */ | 6446 | Start decompression. */ |
| 6405 | cinfo.quantize_colors = 1; | 6447 | mgr->cinfo.quantize_colors = 1; |
| 6406 | fn_jpeg_start_decompress (&cinfo); | 6448 | fn_jpeg_start_decompress (&mgr->cinfo); |
| 6407 | width = img->width = cinfo.output_width; | 6449 | width = img->width = mgr->cinfo.output_width; |
| 6408 | height = img->height = cinfo.output_height; | 6450 | height = img->height = mgr->cinfo.output_height; |
| 6409 | 6451 | ||
| 6410 | if (!check_image_size (f, width, height)) | 6452 | if (!check_image_size (f, width, height)) |
| 6411 | { | 6453 | { |
| 6412 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); | 6454 | mgr->failure_code = MY_JPEG_INVALID_IMAGE_SIZE; |
| 6413 | _longjmp (mgr.setjmp_buffer, 2); | 6455 | _longjmp (mgr->setjmp_buffer, 1); |
| 6414 | } | 6456 | } |
| 6415 | 6457 | ||
| 6416 | /* Create X image and pixmap. */ | 6458 | /* Create X image and pixmap. */ |
| 6417 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) | 6459 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) |
| 6418 | _longjmp (mgr.setjmp_buffer, 2); | 6460 | { |
| 6461 | mgr->failure_code = MY_JPEG_CANNOT_CREATE_X; | ||
| 6462 | _longjmp (mgr->setjmp_buffer, 1); | ||
| 6463 | } | ||
| 6419 | 6464 | ||
| 6420 | /* Allocate colors. When color quantization is used, | 6465 | /* Allocate colors. When color quantization is used, |
| 6421 | cinfo.actual_number_of_colors has been set with the number of | 6466 | mgr->cinfo.actual_number_of_colors has been set with the number of |
| 6422 | colors generated, and cinfo.colormap is a two-dimensional array | 6467 | colors generated, and mgr->cinfo.colormap is a two-dimensional array |
| 6423 | of color indices in the range 0..cinfo.actual_number_of_colors. | 6468 | of color indices in the range 0..mgr->cinfo.actual_number_of_colors. |
| 6424 | No more than 255 colors will be generated. */ | 6469 | No more than 255 colors will be generated. */ |
| 6425 | { | 6470 | { |
| 6426 | int i, ir, ig, ib; | 6471 | int i, ir, ig, ib; |
| 6427 | 6472 | ||
| 6428 | if (cinfo.out_color_components > 2) | 6473 | if (mgr->cinfo.out_color_components > 2) |
| 6429 | ir = 0, ig = 1, ib = 2; | 6474 | ir = 0, ig = 1, ib = 2; |
| 6430 | else if (cinfo.out_color_components > 1) | 6475 | else if (mgr->cinfo.out_color_components > 1) |
| 6431 | ir = 0, ig = 1, ib = 0; | 6476 | ir = 0, ig = 1, ib = 0; |
| 6432 | else | 6477 | else |
| 6433 | ir = 0, ig = 0, ib = 0; | 6478 | ir = 0, ig = 0, ib = 0; |
| @@ -6437,15 +6482,15 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 6437 | a default color, and we don't have to care about which colors | 6482 | a default color, and we don't have to care about which colors |
| 6438 | can be freed safely, and which can't. */ | 6483 | can be freed safely, and which can't. */ |
| 6439 | init_color_table (); | 6484 | init_color_table (); |
| 6440 | colors = alloca (cinfo.actual_number_of_colors * sizeof *colors); | 6485 | colors = alloca (mgr->cinfo.actual_number_of_colors * sizeof *colors); |
| 6441 | 6486 | ||
| 6442 | for (i = 0; i < cinfo.actual_number_of_colors; ++i) | 6487 | for (i = 0; i < mgr->cinfo.actual_number_of_colors; ++i) |
| 6443 | { | 6488 | { |
| 6444 | /* Multiply RGB values with 255 because X expects RGB values | 6489 | /* Multiply RGB values with 255 because X expects RGB values |
| 6445 | in the range 0..0xffff. */ | 6490 | in the range 0..0xffff. */ |
| 6446 | int r = cinfo.colormap[ir][i] << 8; | 6491 | int r = mgr->cinfo.colormap[ir][i] << 8; |
| 6447 | int g = cinfo.colormap[ig][i] << 8; | 6492 | int g = mgr->cinfo.colormap[ig][i] << 8; |
| 6448 | int b = cinfo.colormap[ib][i] << 8; | 6493 | int b = mgr->cinfo.colormap[ib][i] << 8; |
| 6449 | colors[i] = lookup_rgb_color (f, r, g, b); | 6494 | colors[i] = lookup_rgb_color (f, r, g, b); |
| 6450 | } | 6495 | } |
| 6451 | 6496 | ||
| @@ -6457,21 +6502,21 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 6457 | } | 6502 | } |
| 6458 | 6503 | ||
| 6459 | /* Read pixels. */ | 6504 | /* Read pixels. */ |
| 6460 | row_stride = width * cinfo.output_components; | 6505 | row_stride = width * mgr->cinfo.output_components; |
| 6461 | buffer = cinfo.mem->alloc_sarray ((j_common_ptr) &cinfo, JPOOL_IMAGE, | 6506 | buffer = mgr->cinfo.mem->alloc_sarray ((j_common_ptr) &mgr->cinfo, |
| 6462 | row_stride, 1); | 6507 | JPOOL_IMAGE, row_stride, 1); |
| 6463 | for (y = 0; y < height; ++y) | 6508 | for (y = 0; y < height; ++y) |
| 6464 | { | 6509 | { |
| 6465 | fn_jpeg_read_scanlines (&cinfo, buffer, 1); | 6510 | fn_jpeg_read_scanlines (&mgr->cinfo, buffer, 1); |
| 6466 | for (x = 0; x < cinfo.output_width; ++x) | 6511 | for (x = 0; x < mgr->cinfo.output_width; ++x) |
| 6467 | XPutPixel (ximg, x, y, colors[buffer[0][x]]); | 6512 | XPutPixel (ximg, x, y, colors[buffer[0][x]]); |
| 6468 | } | 6513 | } |
| 6469 | 6514 | ||
| 6470 | /* Clean up. */ | 6515 | /* Clean up. */ |
| 6471 | fn_jpeg_finish_decompress (&cinfo); | 6516 | fn_jpeg_finish_decompress (&mgr->cinfo); |
| 6472 | fn_jpeg_destroy_decompress (&cinfo); | 6517 | fn_jpeg_destroy_decompress (&mgr->cinfo); |
| 6473 | if (fp) | 6518 | if (fp) |
| 6474 | fclose ((FILE *) fp); | 6519 | fclose (fp); |
| 6475 | 6520 | ||
| 6476 | /* Maybe fill in the background field while we have ximg handy. */ | 6521 | /* Maybe fill in the background field while we have ximg handy. */ |
| 6477 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | 6522 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) |
| @@ -6484,6 +6529,13 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 6484 | return 1; | 6529 | return 1; |
| 6485 | } | 6530 | } |
| 6486 | 6531 | ||
| 6532 | static int | ||
| 6533 | jpeg_load (struct frame *f, struct image *img) | ||
| 6534 | { | ||
| 6535 | struct my_jpeg_error_mgr mgr; | ||
| 6536 | return jpeg_load_body (f, img, &mgr); | ||
| 6537 | } | ||
| 6538 | |||
| 6487 | #else /* HAVE_JPEG */ | 6539 | #else /* HAVE_JPEG */ |
| 6488 | 6540 | ||
| 6489 | #ifdef HAVE_NS | 6541 | #ifdef HAVE_NS |