Subject: Re: bug#37153: 26.1; some png images scrambled

From: Paul Eggert <[email-masked]>
Date: Sun, 25 Aug 2019 16:39:11 -0700

YAMAMOTO Mitsuharu wrote:

> At least, your patch misses the case of non-paletted transparent PNGs
> (tb???c?? in http://www.schaik.com/pngsuite2011/pngsuite_trn_png.html).

Thanks for catching my mistake. I installed the attached patch, which is closer 
to the code you originally suggested. With it, displaying one of the images you 
suggested looks like the attached image; hope it's what you're looking for. (I 
disabled font-lock-mode as you also suggested.)
>From d3b17dd5f5e3805342dbe4ae20706e9520c48179 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sun, 25 Aug 2019 16:35:43 -0700
Subject: [PATCH] Fix bug with non-paletted transparent PNGs

Adapted from a fix by YAMAMOTO Mitsuharu (Bug#37153#77).
* src/image.c (png_load_body): Fix bug with non-paletted
transparent images.
---
 src/image.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/image.c b/src/image.c
index 18495612e9..fe7bd90b05 100644
--- a/src/image.c
+++ b/src/image.c
@@ -6598,15 +6598,16 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
 # 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)
+  if (png_get_tRNS (png_ptr, info_ptr, &trans_alpha, &num_trans, NULL))
     {
-      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;
+      transparent_p = true;
+      if (trans_alpha)
+	for (int i = 0; i < num_trans; i++)
+	  if (0 < trans_alpha[i] && trans_alpha[i] < 255)
+	    {
+	      transparent_p = false;
+	      break;
+	    }
     }
 # endif
 
-- 
2.17.1