From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.bugs Subject: bug#37153: 26.1; some png images scrambled Date: Sun, 25 Aug 2019 15:58:27 +0900 Organization: Faculty of Science, Chiba University Message-ID: 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 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="269988"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 37153@debbugs.gnu.org, Paul Eggert To: "Roland Winkler" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 25 08:59: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 1i1mUZ-0002H8-Gh for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Aug 2019 08:59:11 +0200 Original-Received: from localhost ([::1]:41058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1mUX-0007Jb-QC for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Aug 2019 02:59:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59397) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1mUR-0007JU-V8 for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 02:59:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1mUQ-0003pA-MX for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 02:59:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34693) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i1mUQ-0003ox-JC for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 02:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i1mUQ-0003wS-Gi for bug-gnu-emacs@gnu.org; Sun, 25 Aug 2019 02:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: YAMAMOTO Mitsuharu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Aug 2019 06:59:02 +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.156671631015111 (code B ref 37153); Sun, 25 Aug 2019 06:59:02 +0000 Original-Received: (at 37153) by debbugs.gnu.org; 25 Aug 2019 06:58:30 +0000 Original-Received: from localhost ([127.0.0.1]:43514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i1mTu-0003ve-FK for submit@debbugs.gnu.org; Sun, 25 Aug 2019 02:58:30 -0400 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:62823) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i1mTs-0003vS-Or for 37153@debbugs.gnu.org; Sun, 25 Aug 2019 02:58:29 -0400 Original-Received: from mathent.math.s.chiba-u.ac.jp (mathent [192.168.32.5]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 467DFF0902; Sun, 25 Aug 2019 15:58:27 +0900 (JST) (envelope-from mituharu@math.s.chiba-u.ac.jp) In-Reply-To: <5136.20784.40920.23906@gargle.gargle.HOWL> 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:173340 On Sun, 25 Aug 2019 13:52:32 +0900, Roland Winkler wrote: > > On Sat Aug 24 2019 mituharu@math.s.chiba-u.ac.jp wrote: > > I suspect there is a longstanding typo (or thinko) in PNG > > transparency handling code. > > It may be helpful to check the "official" test-suite for PNG > > http://www.schaik.com/pngsuite2011/pngsuite.html > > which contains also png files with transparency > > http://www.schaik.com/pngsuite2011/pngsuite_trn_png.html > > Somehow emacs ignores the transparency for image type png, see for > example the file tm3n3p02.png with multiple levels of transparency. > > Transparency is honored for these images when emacs uses imagemagick. It seems to be necessary to look into the tRNS chunk data for paletted images. Again, W32 would need some more work. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp diff --git a/src/image.c b/src/image.c index 81d8cb4e2b2..7f1561d7a68 100644 --- a/src/image.c +++ b/src/image.c @@ -6589,10 +6589,28 @@ 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. */ + transparent_p = false; if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) - transparent_p = 1; - else - transparent_p = 0; + { + if (color_type != PNG_COLOR_TYPE_PALETTE) + transparent_p = true; + else + { + /* Paletted images can specify transparency levels. */ + png_bytep trans; + int i, num_trans; + + if (png_get_tRNS (png_ptr, info_ptr, &trans, &num_trans, NULL) + == PNG_INFO_tRNS) + { + for (i = 0; i < num_trans; i++) + if (!(trans[i] == 0 || trans[i] == 255)) + break; + if (i == num_trans) + transparent_p = true; + } + } + } /* 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 +6698,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)) {