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.









Obligation games

Written by David Frampton @ 12:45 am, May 3, 2010

As a user I have stayed away from all these games. I’ve still never played Farmville, and I didn’t play ‘We Rule’ for ages. I could see what they were about, and knew they were just a drug.

But as a developer, I should have looked at them a lot earlier. I have spent hours over the past few days using We Rule and GodFinger. It has been a real eye opener, so I thought I would share some thoughts on them.

I’m going to call them “obligation games”. I’ve heard the words “social obligation” thrown around about these types of game in the past, and while it does apply, I think the genre is better defined by the word “obligation” alone.

The main obligation is to come back and stay a while. They prey on the deeply rooted human need to care for things so they grow, and to not let things die. Stuff grows quicker if you spend more time in the game, and If you don’t start up the game within a certain period of time, things die.

The user part of me, who gave up smoking a year ago, sees this as another smoking habit. It’s a bit nasty to start with, then once you get the hang of it, you feel unfulfilled without it. At a level below the conscious and reasoning mind, you simply have no choice other than to start up the game to harvest the onions you sowed 1 hour ago. Imagine the horror if those onions went bad. You’d lose like 7 fields worth. And that would be 1050 gold, shit, then I wouldn’t be able to sow another 40 fields of onions.

So you spend hours a day looking after your virtual farm. That is the “killing yourself” part of smoking. You are spending hours a day accomplishing absolutely nothing. That farm will not teach you useful skills, it will not help you to create meaningful new relationships, or put food on the table. The hours a day you spent harvesting virtual onions could in fact have been used in the real world achieving all of the above.

But as a developer, I think it’s brilliant. People are hopeless at seeing the real world. People smoke even though it kills them, they gamble even though they will lose over time, they get insurance even though on average they pay more than they get, and they buy on hire purchase even though in the long run they’ll get less stuff as a result.

It’s perfect. Hook people by praying on their most primitive urges, offering them primal candy and punishing them if they don’t come back when they said they would. Make the gaps between the candy slightly larger each time, so just like a real drug the user plays for longer and longer to search for that elusive first buzz. Then once you’ve got them completely and utterly addicted, start charging them.

I’m sure most people who know me would expect I am about to take the moral high ground here and dismiss the whole obligation game genre as evil.

Well I’m not going to.

People have to take responsibility for their own lives. If you’re an alcoholic gambling smoker with insurance playing ‘We Rule” on your credit-card bought iPad, you deserve the consequences. Now all ngmoco have to do is make the games actually fun (they’ve got the addictive part nailed, but the gameplay is poor), and we’ll all be doomed.