views:

2457

answers:

4

Is it possible to set an iPhone XCode project to skip the 'CompressResources' build step?

Specifically, I want to skip the stage where it runs pngcrush on all of my .png files, many of which don't survive the experience in a form which my app can read.

Edit: the version of pngcrush used creates png files which contain a non-standard 'mandatory, private' chunk which explicitly prevents decoding. I've modified my png reader to handle these files, but I'd still like a per-project method of skipping this step. One of the other side effects of pngcrush is that it doesn't save the colour value of transparent pixels, so alpha-ed textures show fringing at smaller mip levels.

The iphone png format is described here: http://modmyi.com/wiki/index.php/Iphone_PNG_images. In short,

  • Skip the CgBI chunk
  • Skip the zlib headers
  • Swap BGR to RGB channel order

Edit: It appears it also premultiplies the alpha, so:

  • Divide by alpha
+1  A: 

If you look at the build output you'll see that the CompressResources step runs the script /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/iphoneos-optimize. This appears to be just a shell script that runs pngcrush and compiles plists into binary format. You could probably modify this script to not run pngcrush.

Note that someone in this thread noticed that if they did not run their icon file through pngcrush it wasn't showing up on the phone.

Interestingly, the version of pngcrush in the directory of the script has a -iphone argument. Anybody know if this is standard or something Apple just ships with their build of it?

jblocksom
The iPhone uses a nonstandard PNG format which is optimized for faster display on the hardware. There are a pair of scripts somewhere out on the web that will "unoptimize" PNGs recovered from iPhone apps.
benzado
+6  A: 

The iphoneos-optimize script converts PNG files into a nonstandard format that is optimized for display on the iPhone. The script will convert any files with the png extension that it finds inside your app bundle.

I had a similar problem, and solved it by giving my file the extension _png (i.e., prefixed an underscore). iphoneos-optimize ignored it and left it a regular PNG file. If you can deal with it that way, it's probably a lot safer than mucking about with the build scripts.

benzado
This worked great thanks! Note that when I tried this I still saw (minor) gradient banding (the problem I was trying to fix) in the simulator but not on the phone.
MrDatabase
+4  A: 

You can add "IPHONE_OPTIMIZE_OPTIONS=-skip-PNGs" to your project settings to prevent the png mangling, but be careful with it, you might need to optimize the icon and Default.png separately then.

scoopr
+1  A: 

That might be another issue all together. In many cases the problem has to do with naming and can be solved very easily.

read this: http://cocoapi.wordpress.com/2009/03/22/iphone-images-not-appearing-in-real-iphone-this-is-why/

Shai Wininger