Apple’s 2-bit PNG fail

2009-04-08

It turns out that Apple Preview displays 2-bit greyscale PNG images incorrectly. I presume this is true of more or less any other application running on Mac OS X, because they all use the same imaging framework.
ramp3-b8-50

ramp3-50

ramp3-faux-50

The middle image is a 2-bit greyscale PNG. It’s supposed to look like the top image, maybe it does for you. For me, on OS X 10.4 using Safari 3.2.1, it looks like the bottom image. The top and bottom images are 8-bit PNGs, and I trust those to be rendered correctly.

A 2-bit greyscale image can have pixel values of 0, 1, 2, or 3. These represent 0/3, 1/3, 2/3, 3/3 in some (grey) colour space that goes from 0 to 1. Clearly when being displayed on an 8-bit device the colours to use should be #000000 #555555 #AAAAAA #FFFFFF (in the absence of attempts to do colour management).

Apple’s OS X uses the 4 colours #000000 #555555 #777777 #FFFFFF when displaying a 2-bit greyscale PNG. There’s nothing special about the PNG I created. Apple get it wrong for any 2-bit greyscale PNG. 0x77 is not even a slightly wrong version of 0xAA. It’s just stupid and wrong. The only possible explanation I have is that 2-bit PNGs are handled with a hard-coded 4-entry palette, and someone typed “77” instead of “AA” when typing the palette in.

Word of warning if you’re viewing the PngSuite image:
PngSuite 2-bit grey image

The PngSuite images generally have gAMA chunks. This one does, specifying a gamma of 1.0. Observe that, when rounded to an integer hex value, 255*(0x77/255.0)**(1/1.8) is 0xA7, which is the value that Apple uses, not the correct value of 0xCB.

When one is writing articles about dithering down to 2-bit greyscale images, this is not what one needs.

PS: Apple’s DigitalColor Meter rocks. And so many people have yet to discover it, lurking in the Utilities folder.

About these ads

4 Responses to “Apple’s 2-bit PNG fail”


  1. Safari (3.0.4) does the same for me (under MacOS 10.4), but Firefox (3.0.8) displays it correctly, for what it’s worth.

  2. Nick Barnes Says:

    Seems like a pretty serious cock-up on Apple’s part, and also a bit mysterious. What did they think they were doing?

  3. Isaac Morland Says:

    It looks right to me in FireFox 3.0.8. When I dragged the images into Preview, they looked fine there too. This is under Mac OS X 10.5.6.

    Safari 3.2.1, however, displays it wrong.

  4. mjb67 Says:

    Safari 4 Public Beta displays it wrong (ie. ramp3-50 looks the same as ramp3-faux-50) on Windows.

    I assumed the problem was probably in QuickTime but it looks like QuickTime Player 7.6 on Windows displays ramp3-50 the same as ramp3-b8-50.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: