diff options
| author | Paul Eggert | 2019-08-25 10:01:46 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-25 11:11:28 -0700 |
| commit | 8826beaf00660eaaeff28016e022af1d9bf40b7c (patch) | |
| tree | 4e968a294c480a9d549bb0f9fca58a80ea6f04ef /src/image.c | |
| parent | ae7ab3b6ee5237b202d6104aadc2b3f3742f2bf7 (diff) | |
| download | emacs-8826beaf00660eaaeff28016e022af1d9bf40b7c.tar.gz emacs-8826beaf00660eaaeff28016e022af1d9bf40b7c.zip | |
Fix misdisplay of PNG paletted images
Problem reported by Roland Winkler (Bug#37153).
Derived from a patch suggested by YAMAMOTO Mitsuharu (Bug#37153#62).
* src/image.c (png_get_valid) [WINDOWSNT]:
Do not dynamically link this function.
(png_get_tRNS) [WINDOWSNT && PNG_tRNS_SUPPORTED]:
Dynamically link this function instead.
(png_load_body): Do not assume that every paletted image supplies
only transparency data. Fix typo in use of transparent_p.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/image.c b/src/image.c index 81d8cb4e2b2..18495612e98 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -6234,7 +6234,10 @@ DEF_DLL_FN (void, png_read_info, (png_structp, png_infop)); | |||
| 6234 | DEF_DLL_FN (png_uint_32, png_get_IHDR, | 6234 | DEF_DLL_FN (png_uint_32, png_get_IHDR, |
| 6235 | (png_structp, png_infop, png_uint_32 *, png_uint_32 *, | 6235 | (png_structp, png_infop, png_uint_32 *, png_uint_32 *, |
| 6236 | int *, int *, int *, int *, int *)); | 6236 | int *, int *, int *, int *, int *)); |
| 6237 | DEF_DLL_FN (png_uint_32, png_get_valid, (png_structp, png_infop, png_uint_32)); | 6237 | # ifdef PNG_tRNS_SUPPORTED |
| 6238 | DEF_DLL_FN (png_uint_32, png_get_tRNS, (png_structp, png_infop, png_bytep *, | ||
| 6239 | int *, png_color_16p *)); | ||
| 6240 | # endif | ||
| 6238 | DEF_DLL_FN (void, png_set_strip_16, (png_structp)); | 6241 | DEF_DLL_FN (void, png_set_strip_16, (png_structp)); |
| 6239 | DEF_DLL_FN (void, png_set_expand, (png_structp)); | 6242 | DEF_DLL_FN (void, png_set_expand, (png_structp)); |
| 6240 | DEF_DLL_FN (void, png_set_gray_to_rgb, (png_structp)); | 6243 | DEF_DLL_FN (void, png_set_gray_to_rgb, (png_structp)); |
| @@ -6273,7 +6276,9 @@ init_png_functions (void) | |||
| 6273 | LOAD_DLL_FN (library, png_set_sig_bytes); | 6276 | LOAD_DLL_FN (library, png_set_sig_bytes); |
| 6274 | LOAD_DLL_FN (library, png_read_info); | 6277 | LOAD_DLL_FN (library, png_read_info); |
| 6275 | LOAD_DLL_FN (library, png_get_IHDR); | 6278 | LOAD_DLL_FN (library, png_get_IHDR); |
| 6276 | LOAD_DLL_FN (library, png_get_valid); | 6279 | # ifdef PNG_tRNS_SUPPORTED |
| 6280 | LOAD_DLL_FN (library, png_get_tRNS); | ||
| 6281 | # endif | ||
| 6277 | LOAD_DLL_FN (library, png_set_strip_16); | 6282 | LOAD_DLL_FN (library, png_set_strip_16); |
| 6278 | LOAD_DLL_FN (library, png_set_expand); | 6283 | LOAD_DLL_FN (library, png_set_expand); |
| 6279 | LOAD_DLL_FN (library, png_set_gray_to_rgb); | 6284 | LOAD_DLL_FN (library, png_set_gray_to_rgb); |
| @@ -6304,7 +6309,7 @@ init_png_functions (void) | |||
| 6304 | # undef png_get_IHDR | 6309 | # undef png_get_IHDR |
| 6305 | # undef png_get_io_ptr | 6310 | # undef png_get_io_ptr |
| 6306 | # undef png_get_rowbytes | 6311 | # undef png_get_rowbytes |
| 6307 | # undef png_get_valid | 6312 | # undef png_get_tRNS |
| 6308 | # undef png_longjmp | 6313 | # undef png_longjmp |
| 6309 | # undef png_read_end | 6314 | # undef png_read_end |
| 6310 | # undef png_read_image | 6315 | # undef png_read_image |
| @@ -6329,7 +6334,7 @@ init_png_functions (void) | |||
| 6329 | # define png_get_IHDR fn_png_get_IHDR | 6334 | # define png_get_IHDR fn_png_get_IHDR |
| 6330 | # define png_get_io_ptr fn_png_get_io_ptr | 6335 | # define png_get_io_ptr fn_png_get_io_ptr |
| 6331 | # define png_get_rowbytes fn_png_get_rowbytes | 6336 | # define png_get_rowbytes fn_png_get_rowbytes |
| 6332 | # define png_get_valid fn_png_get_valid | 6337 | # define png_get_tRNS fn_png_get_tRNS |
| 6333 | # define png_longjmp fn_png_longjmp | 6338 | # define png_longjmp fn_png_longjmp |
| 6334 | # define png_read_end fn_png_read_end | 6339 | # define png_read_end fn_png_read_end |
| 6335 | # define png_read_image fn_png_read_image | 6340 | # define png_read_image fn_png_read_image |
| @@ -6589,10 +6594,21 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) | |||
| 6589 | 6594 | ||
| 6590 | /* If image contains simply transparency data, we prefer to | 6595 | /* If image contains simply transparency data, we prefer to |
| 6591 | construct a clipping mask. */ | 6596 | construct a clipping mask. */ |
| 6592 | if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) | 6597 | transparent_p = false; |
| 6593 | transparent_p = 1; | 6598 | # ifdef PNG_tRNS_SUPPORTED |
| 6594 | else | 6599 | png_bytep trans_alpha; |
| 6595 | transparent_p = 0; | 6600 | int num_trans; |
| 6601 | if (png_get_tRNS (png_ptr, info_ptr, &trans_alpha, &num_trans, NULL) | ||
| 6602 | && trans_alpha) | ||
| 6603 | { | ||
| 6604 | int i; | ||
| 6605 | for (i = 0; i < num_trans; i++) | ||
| 6606 | if (0 < trans_alpha[i] && trans_alpha[i] < 255) | ||
| 6607 | break; | ||
| 6608 | if (! (i < num_trans)) | ||
| 6609 | transparent_p = true; | ||
| 6610 | } | ||
| 6611 | # endif | ||
| 6596 | 6612 | ||
| 6597 | /* This function is easier to write if we only have to handle | 6613 | /* This function is easier to write if we only have to handle |
| 6598 | one data format: RGB or RGBA with 8 bits per channel. Let's | 6614 | one data format: RGB or RGBA with 8 bits per channel. Let's |
| @@ -6680,7 +6696,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) | |||
| 6680 | /* Create an image and pixmap serving as mask if the PNG image | 6696 | /* Create an image and pixmap serving as mask if the PNG image |
| 6681 | contains an alpha channel. */ | 6697 | contains an alpha channel. */ |
| 6682 | if (channels == 4 | 6698 | if (channels == 4 |
| 6683 | && !transparent_p | 6699 | && transparent_p |
| 6684 | && !image_create_x_image_and_pixmap (f, img, width, height, 1, | 6700 | && !image_create_x_image_and_pixmap (f, img, width, height, 1, |
| 6685 | &mask_img, 1)) | 6701 | &mask_img, 1)) |
| 6686 | { | 6702 | { |