Skipping the 'CompressResources' build step for Xcode iPhone apps - iphone

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: https://web.archive.org/web/20110519164905/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

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.

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.

Open build settings
Under "packaging" choose Compress PNG files
Choose "NO"

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?

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/

Related

ImageOptim breaks png files

I would like to compress png files on my site. I found ImageOptim program. For jpeg files it works great, but when I compressed png files it displayed incorrectly on the site (part of the picture is cut off).
My question is how to make it work in browsers? I see that ImageOptim uses several tools for png compressing(PNGOUT,OPTIpng etc).Maybe I should set some specific tool?
I recommend using JPEG & PNG Stripper.
You can either drag and drop your image files to the GUI or use it as a command line tool.

Using .jp2 images in an array

I am using images in my app which need to have transparency. They are currently .png files, but converting them to .jp2 (JPEG 2000) reduces the file size considerably. I added them to the Xcode project, but they are not loading when I run the app. Does this mean Xcode/Objective C does not support .jp2 files?
You have there files supported by apple, and i can't see jp2. So my answer is: no, jp2 is not supported.
Here you can find what images are supported by iOS UIImage. .jp2 format isn't on that list. So it's not supported.

How can I use tesseract from command line to read inside an opened window?

I'm trying to use tesseract from command line to run OCR on the content of an opened window. In particular I'm willing to read the text typed into a current opened Notepad window.
I've read the documentation and the wiki here: http://code.google.com/p/tesseract-ocr/w/list
but I didn't find anything that helped me in this project, further more I've also searched here for similar questions ( there are many about OCR) but nothing seems to work/ be applicable in my case.
Is it feasible?
I'm mainly a PHP coder (coding just for fun) and have no experience in non-web languages.
Thanks in advance.
Tesseract is designed to take a TIFF image as input and know nothing about the Windows or screen Device Contexts. So you would need to add code to locate the windows handle for the Notepad window , perform a screen capture and clip the window based on the current window size reported by Windows and save the resulting image to a file. This image will most likely be black and white which will make it easier to OCR as I suspect Tesseract 2.0 only works with B/W Images. The next problem will be Tesseract gving poor results due to the low DPI (resolution) of the source image.
To evaluate the suitability of your approach I would perform some manual tests by opening Notepad, taking screenshots, opening the screenshots in MSPaint, clipping the text you want to OCR, save the clipped image to a TIFF or BMP and send this file to Tesseract. This could save you a lot of time and effort if the results are not as good as you need or expect.

Why does png format get changed when on iPhone or iPad Device

Interesting one this. I did do a bit Googling on the it but here we go. I have this png file. What I want to do is have it on my iPhone and send it to a server application on Windows. I use something like this:
NSString *filePath = [[NSBundle mainBundle] pathForResource:IconFile ofType:#"png"];
NSData *icon = [[NSData alloc ] initWithContentsOfFile:filePath];
NSLog(#"File path is %#",filePath);
NSLog(#" Bytes to send in Icon File %d",icon.length);
Now this works just fine when I am on the iPhone simulator. When I go to the device though the png format grows in size. For example I had one that was 2514 bytes and went up to 2652 bytes. When I transmit this file - its not able to be read by the Windows app.
So I assume that when a png file gets copied over in the resource bundle - it must get optimised or something. I can get round it by changing the extension to say .txt - then the file doesnt change.
Does anyone know why that is ? And can you prevent it being changed as I'd rather keep the correct extension. I have seen that png formats need to be converted when you get them from the iPhone but I dont know why this would happen when you upload one and it doesn't work in the simulator mode. Happens with both iPhone and iPad at iOS 5.
The modifying of the png images can be prevented in the build settings - under Packaging there is an option to compress PNG files:
Setting this to NO should solve your problem.
What happens is documented within this document: Viewing iPhone-Optimized PNGs
In short, Apple is using their patched version of pngcrush (note, this one differs from the one available through sourceforge).Their optimizing includes premultiplying the alpha values to speed up the loading process.
You may, as described by the linked document, revert this optimizing if needed (e.g. when reversing existing apps).
The easiest way to prevent this optimizing is to change/remove the file-extension when adding those images to your project.
PNG's are converted to a format "optimized for iPhone". Now this is just what I've read and I'm unsure what the optimization is and if it's actually an optimization, but that's what Apple has chosen to do. Maybe the iPhone GPU is quicker in loading their own format because of hardware support.
In any case, this happens to all PNG images when you deploy a project, and there is no way to prevent it that I know.
If your app downloads a PNG from a remote server this optimization will not occur and you can freely work with the file.
Yes, Apple optimizes all PNGs for display on the iPhone. For example, if you go to iOS .app in the Finder and view its "contents", you will see that all PNGs do not display correctly on Mac OS X.
The solution is to import your file as a "file" rather than an "image". One easy way to do this is to remove the extension then drag it into your project. Another way is to select the image in Xcode and change the File Type under the Identity and Type section in the assistant editor.

Default-Portrait.png for iPad: any way to make the file size smaller?

I'm making a Universal App using MonoTouch, and I'm adding my Default-Portrait.png file. That file alone (a 768x1004 .png file) is adding 711k to the size of the app. My app itself is only about 7 megs, so it's adding 10% just for the splash screen.
I could easily make this thing an 80k jpg file instead of a png, but the device doesn't seem to look for a .jpg file. Does anyone have tips for reducing the size of this launch art?
At this point, I'm thinking I might just leave the launch art out and load my own jpg and display it as soon as I have the ability to. That'll keep my app size down, but it's not as nice as having the launch art scale in immediately like most apps do.
Hmmm...given the screen of the iPad and the visual quality users are expecting, I'd just leave it like that.
But if you do want to reduce the disk space, try going to Project > Edit Project Settings > Build (tab at top), and searching for a parameter called "Compress PNG Files." Make sure that's checked. It'll run the pngcrush utility before loading the file onto disk (check the size of your IPA archive after to see if it had any effect).
pngcrush is nice as well, however that will not reduce the quality of you image. If reducing the quality of the image is an option for you, then you might try this tool: http://www.punypng.com/ - or just use an image editing tool to "optimize" the image ...
I recommend pngout if you want to really squeeze those PNGs down, and this won't cost you any quality. It simply removes unnecessary metadata (like pngcrush) and uses its own compression algorithm which is compatible with the regular decompressor used in PNG (zlib). It's really slow, though.
A simpler option is to try "Save for web" in your image manipulation program of choice. Exporting from Acorn (not just the regular save) sometimes gives me vastly smaller files. This is especially true for default images which have large, uniform areas in one colour (screenshots, a small logo in the middle of a black screen).
Is there any reason why you want to reduce the file size that badly? I don't think it matters in your case. I just checked 3 of my apps and the Default.png (of various portrait/landscape varieties) is between 29KB and 422KB, so whilst yours do seem a little heavy, your still way under the 3G download limit.
Are you positive it's adding that much to the size of the app? Did you compare a before and after?
Xcode uses pngcrush on the images for you. I know because I just tried to substitue jpegs for pngs and got the following result:
So, in short, there's not a lot to be done except simplify the image beforehand. Xcode will handle the rest.