Color profiles and pngcrush

Written by David Frampton @ 10:13 pm, May 23, 2010

I’ve wanted to do this blog post for some time, but have been a bit hesitant, because it’s a complicated subject, and I’m not 100% certain on all the details. But I have had enough frustration and learned enough from it that I should be able to pass on some useful knowledge. If I do make a mistake, please point it out in the comments.

So first up, here is the problem. The PNG file format stores color profile information in its header.

What this means is that when you create a PNG, there is a chance that the software you use to create it may store information about the color profile you have your monitor set to, or the settings of your camera, or the settings you are using in Photoshop in the image file itself.

It is particularly worth noting here that different software and different devices will create and store different profile settings. Some won’t store anything. As well as this, different software or devices will also display the image differently. Some will apply all or parts of the embedded profile to the image before displaying it, some will ignore it completely. Notably, when you build for iPhone, the default build procedure completely strips this information from any PNGs.

You might already see the problem here, but I’ll spell it out with an example I encountered just yesterday.

I have a Mac based level editor for Chopper 2. I also have a few custom or 3rd party tools that I use to generate images for the environments. One of these tools created a PNG for the terrain. One of them created a PNG for the sky box. In the editor, they looked great next to each other, the horizon of the terrain matched the horizon of the skybox perfectly. However on an iPhone, the terrain was much darker, producing an ugly contrast.

Why? Because the tool that created the terrain image saved my color profile information, the tool that created the skybox didn’t, the editor observed the profile information, and the iPhone didn’t.
This image shows part of the terrain file, the left side is the original, how it looked in my editor and Photoshop. The right is after running pngcrush and stripping out the color profile information. It is also how the original looked on an iPhone.

This kind of error (and it’s always a little bit different) usually costs me a couple of hours every time it happens, and it happens about once every couple of months or so. It’s frustrating, and I totally blame the fundamentally flawed concept of storing color profile information in files. I understand the intention and theory behind it, but in practice it’s a stupid idea that never properly achieves the desired effect and causes more harm than good.

ANYWAY… luckily I have found a partial solution. There is a tool that strips the color profile information from PNG files during the iPhone build process. When you come across this problem (or if you’re more organized than me, every time you use software to create a PNG file), you can use this tool to pre-strip it. This is the tool and command to strip all color profile information:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush -rem alla infile.png outfile.png

Luckily, in my experience anyway, Photoshop will not add color profile information to an existing file, but only when you initially create one. So from that point on it should be safe. I can’t vouch for all other software though. I have seen software that re-applies the profile every load, thus making the image incrementally darker every time I saved and re-opened. Such is the state of affairs with color profiles. Also, unfortunately H .264 movies (and other formats) have all the same issues. I’ve seen Quicktime do some truly horrific things to the colors of my movies, and I have no idea how to tell it to just leave the colors alone.

One note of caution, I believe that pngcrush command may also destructively compress the image. You should probably do it only once if possible, however in practice I’ve never seen any artifacts worth worrying about.









2 Comments

  1. Keith Lang

    That’s brilliant David,

    As UI person, I’ve struggled with colour profiles — I still don’t think Fireworks/Photoshop is set up optimally, but you can set it to always open with, without, or asking everytime for a colour profile.

    Comment by Keith Lang — May 24, 2010 @ 12:21 am


  2. Seedyh

    Git workin dude ! I can’t wait fer yer next issue ! I just knew these apps were a pain in the arse for the devloperz !
    I read Crybaby reviews wit kNOw thought to you’all !
    Well , keep-up yer majic.

    Comment by Seedyh — May 31, 2010 @ 9:59 am


RSS feed for comments on this post.

Sorry, the comment form is closed at this time.