[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#37153: 26.1; some png images scrambled
From: |
YAMAMOTO Mitsuharu |
Subject: |
bug#37153: 26.1; some png images scrambled |
Date: |
Sun, 25 Aug 2019 15:58:27 +0900 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (Gojō) APEL/10.8 EasyPG/1.0.0 Emacs/25.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
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))
{
- bug#37153: 26.1; some png images scrambled, (continued)
- bug#37153: 26.1; some png images scrambled, Roland Winkler, 2019/08/23
- bug#37153: 26.1; some png images scrambled, Eli Zaretskii, 2019/08/24
- bug#37153: 26.1; some png images scrambled, mituharu, 2019/08/24
- bug#37153: 26.1; some png images scrambled, Eli Zaretskii, 2019/08/24
- bug#37153: 26.1; some png images scrambled, YAMAMOTO Mitsuharu, 2019/08/25
- bug#37153: 26.1; some png images scrambled, Eli Zaretskii, 2019/08/25
- bug#37153: 26.1; some png images scrambled, Roland Winkler, 2019/08/25
- bug#37153: 26.1; some png images scrambled,
YAMAMOTO Mitsuharu <=
- bug#37153: 26.1; some png images scrambled, Roland Winkler, 2019/08/25
- bug#37153: 26.1; some png images scrambled, Paul Eggert, 2019/08/25
- bug#37153: 26.1; some png images scrambled, Eli Zaretskii, 2019/08/25
- bug#37153: 26.1; some png images scrambled, YAMAMOTO Mitsuharu, 2019/08/25
- bug#37153: 26.1; some png images scrambled, YAMAMOTO Mitsuharu, 2019/08/25
- bug#37153: 26.1; some png images scrambled, Paul Eggert, 2019/08/25