Question about PNG 8-bit format with alpha

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Question about PNG 8-bit format with alpha

Post 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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Question about PNG 8-bit format with alpha

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about PNG 8-bit format with alpha

Post 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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Question about PNG 8-bit format with alpha

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about PNG 8-bit format with alpha

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Question about PNG 8-bit format with alpha

Post 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.
Post Reply