Page 1 of 1

Black pixels in some PNG images become transparent

Posted: 2010-12-28T18:54:27-07:00
by Jason S
Start with an 8-bit RGBA PNG image in which all the pixels are fully opaque, and all the pixels are shades of gray, some of which are black. Run it through 'convert':
convert in.png out.png

My result: The output image is an 8-bit grayscale image with no alpha channel, and with a 'tRNS' chunk that makes the black pixels transparent.
Expected result: The output image should have no transparent pixels.
ImageMagick version: 6.6.6-7

Re: Black pixels in some PNG images become transparent

Posted: 2010-12-28T19:59:58-07:00
by fmw42
this also shows a similar problem on IM 6.6.6.7 Q16 (hdri) Mac OSX Tiger:

convert -size 256x256 gradient: grad256.png
identify -verbose grad256.png

Image: grad256.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 256x256+0+0
Resolution: 72x72
Print size: 3.55556x3.55556
Units: Undefined
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 255 (1)
mean: 127.5 (0.5)
standard deviation: 73.9003 (0.289805)
kurtosis: -1.20004
skewness: 1.26355e-12
Histogram:
256: ( 0, 0, 0) #000000 black
256: ( 1, 1, 1) #010101 rgb(1,1,1)
256: ( 2, 2, 2) #020202 rgb(2,2,2)
256: ( 3, 3, 3) #030303 grey1
256: ( 4, 4, 4) #040404 rgb(4,4,4)
256: ( 5, 5, 5) #050505 grey2
256: ( 6, 6, 6) #060606 rgb(6,6,6)
256: ( 7, 7, 7) #070707 rgb(7,7,7)


convert grad256.png -alpha opaque grad256op.png
identify -verbose grad256op.png

Image: grad256op.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 256x256+0+0
Resolution: 72x72
Print size: 3.55556x3.55556
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 255 (1)
mean: 127.5 (0.5)
standard deviation: 73.9003 (0.289805)
kurtosis: -1.20004
skewness: 1.26355e-12
Alpha:
min: 0 (0)
max: 255 (1)

mean: 254.004 (0.996094)
standard deviation: 15.9063 (0.0623778)
kurtosis: 251.004
skewness: 15.9061
Alpha: none #00000000
Histogram:
256: ( 0, 0, 0, 0) #00000000 none
256: ( 1, 1, 1,255) #010101 graya(1,1,1,1)
256: ( 2, 2, 2,255) #020202 graya(2,2,2,1)
256: ( 3, 3, 3,255) #030303 grey1
256: ( 4, 4, 4,255) #040404 graya(4,4,4,1)
256: ( 5, 5, 5,255) #050505 grey2
256: ( 6, 6, 6,255) #060606 graya(6,6,6,1)
256: ( 7, 7, 7,255) #070707 graya(7,7,7,1)

Re: Black pixels in some PNG images become transparent

Posted: 2010-12-28T23:09:34-07:00
by anthony
This is an on going problem with the new PNG coder for the automatic handling of images with less than 256 colors in the image.

One temporary solution is to force it into a non indexed PNG format using png32:filename.png

Re: Black pixels in some PNG images become transparent

Posted: 2010-12-30T10:18:55-07:00
by glennrp
The PNG decoder sets image->matte to True when it reads an RGBA image, regardless of whether any transparent pixel is actually present. The PNG encoder writes a tRNS chunk when it inherits a grayscale or truecolor image with image->matte==MagickTrue. I'm working on a fix for this.

Re: Black pixels in some PNG images become transparent

Posted: 2010-12-30T11:26:43-07:00
by macias
I can confirm this with such info about IM versions:

IM 6.6.5-4 -- didn't happen for me
IM 6.6.6-4 -- I spotted this issue for the first time
IM 6.6.6-8 -- bug still exists

Re: Black pixels in some PNG images become transparent

Posted: 2010-12-31T17:15:11-07:00
by glennrp
Works in SVN head and should work soon in IM-6.6.6-9. The problem was that the input image was RGBA without any transparent pixels. Now the decoder detects this situation and doesn't set image->matte.

Re: Black pixels in some PNG images become transparent

Posted: 2010-12-31T20:57:52-07:00
by fmw42
Glenn,

This is still not working in IM 6.6.6.9 Q16 (hdri) Mac OSX Tiger. Perhaps it is not really in this release, but will be in the next.


convert grad256.png -alpha opaque grad256op.png
identify -verbose grad256op.png

Image: grad256op.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 256x256+0+0
Resolution: 72x72
Print size: 3.55556x3.55556
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 255 (1)
mean: 127.5 (0.5)
standard deviation: 73.9003 (0.289805)
kurtosis: -1.20004
skewness: 1.26355e-12
Alpha:
min: 0 (0)

max: 255 (1)
mean: 254.004 (0.996094)
standard deviation: 15.9063 (0.0623778)
kurtosis: 251.004
skewness: 15.9061
Alpha: none #00000000
Histogram:
256: ( 0, 0, 0, 0) #00000000 none
256: ( 1, 1, 1,255) #010101 graya(1,1,1,1)
256: ( 2, 2, 2,255) #020202 graya(2,2,2,1)
256: ( 3, 3, 3,255) #030303 grey1
256: ( 4, 4, 4,255) #040404 graya(4,4,4,1)
256: ( 5, 5, 5,255) #050505 grey2

Re: Black pixels in some PNG images become transparent

Posted: 2011-01-01T14:01:22-07:00
by glennrp
fmw42 wrote: This is still not working in IM 6.6.6.9 Q16 (hdri) Mac OSX Tiger. Perhaps it is not really in this release, but will be in the next.
Right. 6-9 was created shortly before I checked in the fix. Try again with 6-10.

Re: Black pixels in some PNG images become transparent

Posted: 2011-01-01T21:12:59-07:00
by fmw42
glennrp wrote:
fmw42 wrote: This is still not working in IM 6.6.6.9 Q16 (hdri) Mac OSX Tiger. Perhaps it is not really in this release, but will be in the next.
Right. 6-9 was created shortly before I checked in the fix. Try again with 6-10.

Still does not work correctly in 6.6.6.10 Q16 (hdri) Mac OSX Tiger

(note it may be related to viewtopic.php?f=3&t=17771 )


convert -size 256x256 gradient: grad256.png
convert grad256.png -alpha opaque grad256op.png
identify -verbose grad256op.png

Image: grad256op.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 256x256+0+0
Resolution: 72x72
Print size: 3.55556x3.55556
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 255 (1)
mean: 127.5 (0.5)
standard deviation: 73.9003 (0.289805)
kurtosis: -1.20004
skewness: 1.26355e-12
Alpha:
min: 0 (0)
max: 255 (1)
mean: 254.004 (0.996094)
standard deviation: 15.9063 (0.0623778)
kurtosis: 251.004
skewness: 15.9061
Alpha: none #00000000
Histogram:
256: ( 0, 0, 0, 0) #00000000 none
256: ( 1, 1, 1,255) #010101 graya(1,1,1,1)
256: ( 2, 2, 2,255) #020202 graya(2,2,2,1)
256: ( 3, 3, 3,255) #030303 grey1
256: ( 4, 4, 4,255) #040404 graya(4,4,4,1)
256: ( 5, 5, 5,255) #050505 grey2