summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2008-07-07 09:31:49 +0000
committerYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>2008-07-07 09:31:49 +0000
commit7321dc0ca850eedb19ac0d431c9a17301449bc97 (patch)
tree798e97b530f9504934542d254f8399561d4cde04
parent5922fd0ee09f51cfc4f3aa160d9bd4a7b23493e4 (diff)
downloademacs-7321dc0ca850eedb19ac0d431c9a17301449bc97.tar.gz
(png_load): Use correct bit-depth for setting background color.
-rw-r--r--src/ChangeLog5
-rw-r--r--src/image.c48
2 files changed, 14 insertions, 39 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d7826d013aa..0a9f3ec9a67 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2008-07-07 Chong Yidong <cyd@stupidchicken.com>
+
+ * image.c (png_load): Use correct bit-depth for setting background
+ color.
+
2008-05-15 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
* macterm.c (x_draw_relief_rect): Remove unused variable `dpy'.
diff --git a/src/image.c b/src/image.c
index 9981b21365a..f2dc1ae30ca 100644
--- a/src/image.c
+++ b/src/image.c
@@ -6517,7 +6517,6 @@ png_load (f, img)
png_byte channels;
png_uint_32 row_bytes;
int transparent_p;
- double screen_gamma;
struct png_memory_storage tbr; /* Data to be read */
/* Find out what file to load. */
@@ -6659,27 +6658,6 @@ png_load (f, img)
|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
fn_png_set_gray_to_rgb (png_ptr);
- screen_gamma = (f->gamma ? 1 / f->gamma / 0.45455 : 2.2);
-
-#if 0 /* Avoid double gamma correction for PNG images. */
- { /* Tell the PNG lib to handle gamma correction for us. */
- int intent;
- double image_gamma;
-#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
- if (png_get_sRGB (png_ptr, info_ptr, &intent))
- /* The libpng documentation says this is right in this case. */
- png_set_gamma (png_ptr, screen_gamma, 0.45455);
- else
-#endif
- if (png_get_gAMA (png_ptr, info_ptr, &image_gamma))
- /* Image contains gamma information. */
- png_set_gamma (png_ptr, screen_gamma, image_gamma);
- else
- /* Use the standard default for the image gamma. */
- png_set_gamma (png_ptr, screen_gamma, 0.45455);
- }
-#endif /* if 0 */
-
/* Handle alpha channel by combining the image with a background
color. Do this only if a real alpha channel is supplied. For
simple transparency, we prefer a clipping mask. */
@@ -6688,6 +6666,7 @@ png_load (f, img)
png_color_16 *image_bg;
Lisp_Object specified_bg
= image_spec_value (img->spec, QCbackground, NULL);
+ int shift = (bit_depth == 16) ? 0 : 8;
if (STRINGP (specified_bg))
/* The user specified `:background', use that. */
@@ -6699,27 +6678,18 @@ png_load (f, img)
png_color_16 user_bg;
bzero (&user_bg, sizeof user_bg);
- user_bg.red = color.red >> 8;
- user_bg.green = color.green >> 8;
- user_bg.blue = color.blue >> 8;
+ user_bg.red = color.red >> shift;
+ user_bg.green = color.green >> shift;
+ user_bg.blue = color.blue >> shift;
fn_png_set_background (png_ptr, &user_bg,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
}
}
- /* The commented-out code checked if the png specifies a default
- background color, and uses that. Since we use the current
- frame background, it is OK for us to ignore this.
-
- else if (fn_png_get_bKGD (png_ptr, info_ptr, &image_bg))
- fn_png_set_background (png_ptr, image_bg,
- PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
- */
else
{
- /* Image does not contain a background color with which
- to combine the image data via an alpha channel. Use
- the frame's background instead. */
+ /* We use the current frame background, ignoring any default
+ background color set by the image. */
#ifdef HAVE_X_WINDOWS
XColor color;
png_color_16 frame_background;
@@ -6728,9 +6698,9 @@ png_load (f, img)
x_query_color (f, &color);
bzero (&frame_background, sizeof frame_background);
- frame_background.red = color.red >> 8;
- frame_background.green = color.green >> 8;
- frame_background.blue = color.blue >> 8;
+ frame_background.red = color.red >> shift;
+ frame_background.green = color.green >> shift;
+ frame_background.blue = color.blue >> shift;
#endif /* HAVE_X_WINDOWS */
#ifdef HAVE_NTGUI