From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#37153: 26.1; some png images scrambled Date: Sun, 25 Aug 2019 11:38:07 -0700 Organization: UCLA Computer Science Department Message-ID: <4a893dc7-659a-be76-01d3-3f0a4de57ba4@cs.ucla.edu> References: <5b006777-5e97-a641-6f93-83a437ca9ca7@cs.ucla.edu> <44134.15891.158963.23904@gargle.gargle.HOWL> <9c4c68ebe20cbcc44763be8e72bd25eb.squirrel@weber.math.s.chiba-u.ac.jp> <5136.20784.40920.23906@gargle.gargle.HOWL> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2DC646F745174DCE19A5F135" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="115983"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Cc: 37153@debbugs.gnu.org To: YAMAMOTO Mitsuharu , Roland Winkler Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 25 20:39:11 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i1xPz-000U1j-HG for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Aug 2019 20:39:11 +0200 Original-Received: from localhost ([::1]:45636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1xPy-0007St-1Y for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Aug 2019 14:39:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56362) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1xPr-0007Sn-CX for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 14:39:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1xPq-0000Q0-0o for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 14:39:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36266) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i1xPp-0000Ps-Sq for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 14:39:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i1xPp-0007UR-Mh for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 14:39:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Aug 2019 18:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37153 X-GNU-PR-Package: emacs Original-Received: via spool by 37153-submit@debbugs.gnu.org id=B37153.156675829828707 (code B ref 37153); Sun, 25 Aug 2019 18:39:01 +0000 Original-Received: (at 37153) by debbugs.gnu.org; 25 Aug 2019 18:38:18 +0000 Original-Received: from localhost ([127.0.0.1]:45087 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i1xP7-0007Sv-Rl for submit@debbugs.gnu.org; Sun, 25 Aug 2019 14:38:18 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:57602) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i1xP5-0007Sb-8X for 37153@debbugs.gnu.org; Sun, 25 Aug 2019 14:38:16 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 95D45160057; Sun, 25 Aug 2019 11:38:09 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 45g1Bm6LDQDf; Sun, 25 Aug 2019 11:38:08 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 77524160079; Sun, 25 Aug 2019 11:38:08 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LRYnDilTserY; Sun, 25 Aug 2019 11:38:08 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 44C9C160057; Sun, 25 Aug 2019 11:38:08 -0700 (PDT) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:165850 Archived-At: This is a multi-part message in MIME format. --------------2DC646F745174DCE19A5F135 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 . 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. --------------2DC646F745174DCE19A5F135 Content-Type: text/x-patch; name="0001-Fix-misdisplay-of-PNG-paletted-images.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-misdisplay-of-PNG-paletted-images.patch" >From 64aa756cfa5943c8b3494ac1fbb4db712c50ae64 Mon Sep 17 00:00:00 2001 From: Paul Eggert 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 --------------2DC646F745174DCE19A5F135--