Page 1 of 1

Question about PNG 8-bit format with alpha

Posted: 2014-02-26T15:48:33-07:00
by fmw42
Does PNG actually support an 8-bit format with 8-bit alpha or just 1-bit alpha? If the latter, then IM has a bug.

Consider:

convert logo: -transparent white -alpha on -channel a -blur 0x1 +channel -type palettematte logo1.png
or
convert logo: -transparent white -alpha on -channel a -blur 0x1 +channel -type palettealpha logo1.png

Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 640x480+0+0
Units: Undefined
Type: PaletteAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit

vs

convert logo: -transparent white -alpha on -channel a -blur 0x1 +channel PNG8:logo2.png

Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 640x480+0+0
Units: Undefined
Type: PaletteAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit

Both display, although the former does not look as good as the latter --- the former has lots of black spots.


IM 6.8.8.7 Q16 Mac OSX Snow Leopard

Re: Question about PNG 8-bit format with alpha

Posted: 2014-02-27T10:09:01-07:00
by glennrp
It's not a bug it's a design choice. There is no approved definition of PNG8 so I defined it for
ImageMagick purposes. Type "convert -list format | grep PNG8". The main purpose
of the subformat is to write files to be read by a commonly used browser that didn't support
indexed PNG with alpha other than 0 and 255.

Re: Question about PNG 8-bit format with alpha

Posted: 2014-02-27T10:23:57-07:00
by fmw42
glennrp wrote:It's not a bug it's a design choice. There is no approved definition of PNG8 so I defined it for
ImageMagick purposes. Type "convert -list format | grep PNG8". The main purpose
of the subformat is to write files to be read by a commonly used browser that didn't support
indexed PNG with alpha other than 0 and 255.

Glenn,

Thanks. But why is the -type palettematte approach giving black spots rather than either partial transparency or solid colors?

Fred

Re: Question about PNG 8-bit format with alpha

Posted: 2014-02-28T10:32:20-07:00
by glennrp
fmw42 wrote:[why is the -type palettematte approach giving black spots rather than either partial transparency or solid colors?
I don't know. The "pngquant" program does a nicer job:

Code: Select all

convert logo: -transparent white -alpha on -channel a -blur 0x1 \
          +channel logo.png
pngquant logo.png
Result is in logo-fs8.png; it is an indexed PNG with lots of different
values of alpha contained in the tRNS chunk. I have been considering
defining a "PNG88" that would be like "PNG8" but would allow
semitransparency.

Our png reader seems to have trouble with reading these, though,
so first I'll see about fixing that bug.

Re: Question about PNG 8-bit format with alpha

Posted: 2014-02-28T11:13:24-07:00
by fmw42
Thanks Glenn. I did not mean to put you to a lot of work. I was just curious, since I did not think IM allowed 8-bit color and 8-bit alpha in PNG.

But this would be nice additional feature.

Re: Question about PNG 8-bit format with alpha

Posted: 2014-02-28T18:02:06-07:00
by glennrp
fmw42 wrote:Thanks Glenn. I did not mean to put you to a lot of work. I was just curious, since I did not think IM allowed 8-bit color and 8-bit alpha in PNG.
IM allows 8-bit color and 8-bit alpha, but it's not called "PNG8" if there is full alpha. It's currently not 100% convenient to write them from IM, though. You have to
quantize the image down to 255 or fewer different RGBA pixel values (-colors 255), and you have to worry about RGB vs sRGB issues, and whether to dither or not.