all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>,
	Roland Winkler <winkler@gnu.org>
Cc: 37153@debbugs.gnu.org
Subject: bug#37153: 26.1; some png images scrambled
Date: Sun, 25 Aug 2019 11:38:07 -0700	[thread overview]
Message-ID: <4a893dc7-659a-be76-01d3-3f0a4de57ba4@cs.ucla.edu> (raw)
In-Reply-To: <wlwof1ive4.wl-mituharu@math.s.chiba-u.ac.jp>

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

YAMAMOTO Mitsuharu wrote:

> It seems to be necessary to look into the tRNS chunk data for paletted
> images.  Again, W32 would need some more work.

Thanks, I confirmed that this fixes the misdisplay for me as well. I attempted 
to port it to w32 (as well as to unusual libpng builds that do not define 
PNG_tRNS_SUPPORTED) and installed the attached into master.

With this patch on Ubuntu 18.04.3 I always see the first image shown in your 
tRNS.pg screenshot <https://bugs.gnu.org/37153#56>. So it may be that more work 
needs to be done to support other faces. Still, this patch is an improvement so 
it's worth going in.

[-- Attachment #2: 0001-Fix-misdisplay-of-PNG-paletted-images.patch --]
[-- Type: text/x-patch, Size: 3729 bytes --]

From 64aa756cfa5943c8b3494ac1fbb4db712c50ae64 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 25 Aug 2019 10:01:46 -0700
Subject: [PATCH] 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.
---
 src/image.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/image.c b/src/image.c
index 81d8cb4e2b..18495612e9 100644
--- a/src/image.c
+++ b/src/image.c
@@ -6234,7 +6234,10 @@ DEF_DLL_FN (void, png_read_info, (png_structp, png_infop));
 DEF_DLL_FN (png_uint_32, png_get_IHDR,
 	    (png_structp, png_infop, png_uint_32 *, png_uint_32 *,
 	     int *, int *, int *, int *, int *));
-DEF_DLL_FN (png_uint_32, png_get_valid, (png_structp, png_infop, png_uint_32));
+#  ifdef PNG_tRNS_SUPPORTED
+DEF_DLL_FN (png_uint_32, png_get_tRNS, (png_structp, png_infop, png_bytep *,
+					int *, png_color_16p *));
+#  endif
 DEF_DLL_FN (void, png_set_strip_16, (png_structp));
 DEF_DLL_FN (void, png_set_expand, (png_structp));
 DEF_DLL_FN (void, png_set_gray_to_rgb, (png_structp));
@@ -6273,7 +6276,9 @@ init_png_functions (void)
   LOAD_DLL_FN (library, png_set_sig_bytes);
   LOAD_DLL_FN (library, png_read_info);
   LOAD_DLL_FN (library, png_get_IHDR);
-  LOAD_DLL_FN (library, png_get_valid);
+#  ifdef PNG_tRNS_SUPPORTED
+  LOAD_DLL_FN (library, png_get_tRNS);
+#  endif
   LOAD_DLL_FN (library, png_set_strip_16);
   LOAD_DLL_FN (library, png_set_expand);
   LOAD_DLL_FN (library, png_set_gray_to_rgb);
@@ -6304,7 +6309,7 @@ init_png_functions (void)
 #  undef png_get_IHDR
 #  undef png_get_io_ptr
 #  undef png_get_rowbytes
-#  undef png_get_valid
+#  undef png_get_tRNS
 #  undef png_longjmp
 #  undef png_read_end
 #  undef png_read_image
@@ -6329,7 +6334,7 @@ init_png_functions (void)
 #  define png_get_IHDR fn_png_get_IHDR
 #  define png_get_io_ptr fn_png_get_io_ptr
 #  define png_get_rowbytes fn_png_get_rowbytes
-#  define png_get_valid fn_png_get_valid
+#  define png_get_tRNS fn_png_get_tRNS
 #  define png_longjmp fn_png_longjmp
 #  define png_read_end fn_png_read_end
 #  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)
 
   /* If image contains simply transparency data, we prefer to
      construct a clipping mask.  */
-  if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
-    transparent_p = 1;
-  else
-    transparent_p = 0;
+  transparent_p = false;
+# ifdef PNG_tRNS_SUPPORTED
+  png_bytep trans_alpha;
+  int num_trans;
+  if (png_get_tRNS (png_ptr, info_ptr, &trans_alpha, &num_trans, NULL)
+      && trans_alpha)
+    {
+      int i;
+      for (i = 0; i < num_trans; i++)
+	if (0 < trans_alpha[i] && trans_alpha[i] < 255)
+	  break;
+      if (! (i < num_trans))
+	transparent_p = true;
+    }
+# endif
 
   /* This function is easier to write if we only have to handle
      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)
   /* Create an image and pixmap serving as mask if the PNG image
      contains an alpha channel.  */
   if (channels == 4
-      && !transparent_p
+      && transparent_p
       && !image_create_x_image_and_pixmap (f, img, width, height, 1,
 					   &mask_img, 1))
     {
-- 
2.17.1


  parent reply	other threads:[~2019-08-25 18:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23  4:49 bug#37153: 26.1; some png images scrambled Roland Winkler
2019-08-23  8:47 ` Eli Zaretskii
2019-08-23 11:39   ` Roland Winkler
2019-08-23 12:22     ` Eli Zaretskii
2019-08-23 15:07       ` Roland Winkler
2019-08-23 15:34         ` Eli Zaretskii
2019-08-23 19:37 ` Paul Eggert
2019-08-23 20:11   ` Eli Zaretskii
2019-08-23 20:33     ` Paul Eggert
2019-08-24  5:51       ` Eli Zaretskii
2019-08-24  3:17   ` Roland Winkler
2019-08-24  3:39     ` Paul Eggert
2019-08-24  4:19       ` Roland Winkler
2019-08-24  6:26       ` Eli Zaretskii
2019-08-24  6:22     ` Eli Zaretskii
2019-08-24  9:01     ` mituharu
2019-08-24 10:17       ` Eli Zaretskii
2019-08-25  4:19         ` YAMAMOTO Mitsuharu
2019-08-25  7:24           ` Eli Zaretskii
2019-08-25  4:52       ` Roland Winkler
2019-08-25  6:58         ` YAMAMOTO Mitsuharu
2019-08-25 12:19           ` Roland Winkler
2019-08-25 18:38           ` Paul Eggert [this message]
2019-08-25 18:56             ` Eli Zaretskii
2019-08-25 23:02             ` YAMAMOTO Mitsuharu
2019-08-25 23:06               ` YAMAMOTO Mitsuharu
2019-08-25 23:39               ` Paul Eggert
2019-09-24 16:23                 ` Lars Ingebrigtsen
2019-09-24 17:14                   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a893dc7-659a-be76-01d3-3f0a4de57ba4@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=37153@debbugs.gnu.org \
    --cc=mituharu@math.s.chiba-u.ac.jp \
    --cc=winkler@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.