diff options
| author | Chong Yidong | 2008-05-09 02:37:31 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-05-09 02:37:31 +0000 |
| commit | c4f13f44fbeb917916f71ac0fa9e7a100ed8b643 (patch) | |
| tree | b8ab94fd2764bf5fd280263cba02e65660efc61e /src/image.c | |
| parent | b199c436f8fc7e7cf6fcf4e54d2ba848e6059d05 (diff) | |
| download | emacs-c4f13f44fbeb917916f71ac0fa9e7a100ed8b643.tar.gz emacs-c4f13f44fbeb917916f71ac0fa9e7a100ed8b643.zip | |
(png_load): Use correct bit-depth for setting background color.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/src/image.c b/src/image.c index 48b223c6c76..3a972197293 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -6542,7 +6542,6 @@ png_load (f, img) | |||
| 6542 | png_byte channels; | 6542 | png_byte channels; |
| 6543 | png_uint_32 row_bytes; | 6543 | png_uint_32 row_bytes; |
| 6544 | int transparent_p; | 6544 | int transparent_p; |
| 6545 | double screen_gamma; | ||
| 6546 | struct png_memory_storage tbr; /* Data to be read */ | 6545 | struct png_memory_storage tbr; /* Data to be read */ |
| 6547 | 6546 | ||
| 6548 | /* Find out what file to load. */ | 6547 | /* Find out what file to load. */ |
| @@ -6684,27 +6683,6 @@ png_load (f, img) | |||
| 6684 | || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 6683 | || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
| 6685 | fn_png_set_gray_to_rgb (png_ptr); | 6684 | fn_png_set_gray_to_rgb (png_ptr); |
| 6686 | 6685 | ||
| 6687 | screen_gamma = (f->gamma ? 1 / f->gamma / 0.45455 : 2.2); | ||
| 6688 | |||
| 6689 | #if 0 /* Avoid double gamma correction for PNG images. */ | ||
| 6690 | { /* Tell the PNG lib to handle gamma correction for us. */ | ||
| 6691 | int intent; | ||
| 6692 | double image_gamma; | ||
| 6693 | #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED) | ||
| 6694 | if (png_get_sRGB (png_ptr, info_ptr, &intent)) | ||
| 6695 | /* The libpng documentation says this is right in this case. */ | ||
| 6696 | png_set_gamma (png_ptr, screen_gamma, 0.45455); | ||
| 6697 | else | ||
| 6698 | #endif | ||
| 6699 | if (png_get_gAMA (png_ptr, info_ptr, &image_gamma)) | ||
| 6700 | /* Image contains gamma information. */ | ||
| 6701 | png_set_gamma (png_ptr, screen_gamma, image_gamma); | ||
| 6702 | else | ||
| 6703 | /* Use the standard default for the image gamma. */ | ||
| 6704 | png_set_gamma (png_ptr, screen_gamma, 0.45455); | ||
| 6705 | } | ||
| 6706 | #endif /* if 0 */ | ||
| 6707 | |||
| 6708 | /* Handle alpha channel by combining the image with a background | 6686 | /* Handle alpha channel by combining the image with a background |
| 6709 | color. Do this only if a real alpha channel is supplied. For | 6687 | color. Do this only if a real alpha channel is supplied. For |
| 6710 | simple transparency, we prefer a clipping mask. */ | 6688 | simple transparency, we prefer a clipping mask. */ |
| @@ -6713,6 +6691,7 @@ png_load (f, img) | |||
| 6713 | /* png_color_16 *image_bg; */ | 6691 | /* png_color_16 *image_bg; */ |
| 6714 | Lisp_Object specified_bg | 6692 | Lisp_Object specified_bg |
| 6715 | = image_spec_value (img->spec, QCbackground, NULL); | 6693 | = image_spec_value (img->spec, QCbackground, NULL); |
| 6694 | int shift = (bit_depth == 16) ? 0 : 8; | ||
| 6716 | 6695 | ||
| 6717 | if (STRINGP (specified_bg)) | 6696 | if (STRINGP (specified_bg)) |
| 6718 | /* The user specified `:background', use that. */ | 6697 | /* The user specified `:background', use that. */ |
| @@ -6724,27 +6703,18 @@ png_load (f, img) | |||
| 6724 | png_color_16 user_bg; | 6703 | png_color_16 user_bg; |
| 6725 | 6704 | ||
| 6726 | bzero (&user_bg, sizeof user_bg); | 6705 | bzero (&user_bg, sizeof user_bg); |
| 6727 | user_bg.red = color.red >> 8; | 6706 | user_bg.red = color.red >> shift; |
| 6728 | user_bg.green = color.green >> 8; | 6707 | user_bg.green = color.green >> shift; |
| 6729 | user_bg.blue = color.blue >> 8; | 6708 | user_bg.blue = color.blue >> shift; |
| 6730 | 6709 | ||
| 6731 | fn_png_set_background (png_ptr, &user_bg, | 6710 | fn_png_set_background (png_ptr, &user_bg, |
| 6732 | PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); | 6711 | PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); |
| 6733 | } | 6712 | } |
| 6734 | } | 6713 | } |
| 6735 | /* The commented-out code checked if the png specifies a default | ||
| 6736 | background color, and uses that. Since we use the current | ||
| 6737 | frame background, it is OK for us to ignore this. | ||
| 6738 | |||
| 6739 | else if (fn_png_get_bKGD (png_ptr, info_ptr, &image_bg)) | ||
| 6740 | fn_png_set_background (png_ptr, image_bg, | ||
| 6741 | PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); | ||
| 6742 | */ | ||
| 6743 | else | 6714 | else |
| 6744 | { | 6715 | { |
| 6745 | /* Image does not contain a background color with which | 6716 | /* We use the current frame background, ignoring any default |
| 6746 | to combine the image data via an alpha channel. Use | 6717 | background color set by the image. */ |
| 6747 | the frame's background instead. */ | ||
| 6748 | #ifdef HAVE_X_WINDOWS | 6718 | #ifdef HAVE_X_WINDOWS |
| 6749 | XColor color; | 6719 | XColor color; |
| 6750 | png_color_16 frame_background; | 6720 | png_color_16 frame_background; |
| @@ -6753,9 +6723,9 @@ png_load (f, img) | |||
| 6753 | x_query_color (f, &color); | 6723 | x_query_color (f, &color); |
| 6754 | 6724 | ||
| 6755 | bzero (&frame_background, sizeof frame_background); | 6725 | bzero (&frame_background, sizeof frame_background); |
| 6756 | frame_background.red = color.red >> 8; | 6726 | frame_background.red = color.red >> shift; |
| 6757 | frame_background.green = color.green >> 8; | 6727 | frame_background.green = color.green >> shift; |
| 6758 | frame_background.blue = color.blue >> 8; | 6728 | frame_background.blue = color.blue >> shift; |
| 6759 | #endif /* HAVE_X_WINDOWS */ | 6729 | #endif /* HAVE_X_WINDOWS */ |
| 6760 | 6730 | ||
| 6761 | #ifdef HAVE_NTGUI | 6731 | #ifdef HAVE_NTGUI |