UIImage doesn't support as wide a range of file types as NSImage does in Cocoa . It's understandable, given the different natures of the devices they run on, however there are times when you will want to load data in a format that's not directly supported by UIImage. This happened recently while experimenting with creating a Milkshape 3D model loader for use in iPhone game development. Milkshape uses Targa and PCX files for the texture, and neither of these formats is supported by UIImage.
I haven't tackled PCX files, but I wrote a category on UIImage to let you instantiate a UIImage object from Targa data stored in a TGA file. This version doesn't support RLE encoded files, but generally for game models, RLE isn't encoded. If you need to save size in your image executable, zipping the uncompressed TGA data will save about the same amount of room. If you're looking at doing a game, I probably wouldn't recommend compressing the images at all unless you're very close to that ten meg limit that prevents people from downloading your game over 3G & Edge, since you'll have to expend processing cycles to decompress at launch or load time.
You can find the category and an Xcode project that shows how it can be used in the iPhone Bits repository over at Google Code.
This is a first draft and there is likely room for improvement. There are some known inefficiencies in this class. For example, the iPhone's native byte ordering is BGRA, and so is Targa's, This code, however, converts the Targa data to RGB, and likely under the hood, UIImage is converting back to BGRA. I'm pretty sure Core Graphics provides a way to avoid this conversion, but don't have time to research it right now. Also, if your only use of the Targa image is going to be in OpenGL, you probably want to skip this category altogether and just load the bitmap data into OpenGL directly. This category combined with the Texture2D from Apple's sample code certainly gives an easy way to setup a scaffold environment for early development.
UIImage-Targa.h
UIImage-Targa.m
I haven't tackled PCX files, but I wrote a category on UIImage to let you instantiate a UIImage object from Targa data stored in a TGA file. This version doesn't support RLE encoded files, but generally for game models, RLE isn't encoded. If you need to save size in your image executable, zipping the uncompressed TGA data will save about the same amount of room. If you're looking at doing a game, I probably wouldn't recommend compressing the images at all unless you're very close to that ten meg limit that prevents people from downloading your game over 3G & Edge, since you'll have to expend processing cycles to decompress at launch or load time.
You can find the category and an Xcode project that shows how it can be used in the iPhone Bits repository over at Google Code.
This is a first draft and there is likely room for improvement. There are some known inefficiencies in this class. For example, the iPhone's native byte ordering is BGRA, and so is Targa's, This code, however, converts the Targa data to RGB, and likely under the hood, UIImage is converting back to BGRA. I'm pretty sure Core Graphics provides a way to avoid this conversion, but don't have time to research it right now. Also, if your only use of the Targa image is going to be in OpenGL, you probably want to skip this category altogether and just load the bitmap data into OpenGL directly. This category combined with the Texture2D from Apple's sample code certainly gives an easy way to setup a scaffold environment for early development.
UIImage-Targa.h
UIImage-Targa.m
void
Nice post. Thanks for sharing.
ReplyDeletehttps://onlineconvertfree.com/convert/wps/
Awesome work, so if you have any tga, avi, jpg file and want to convert it on another file then use this converter;
ReplyDeleteFile Spinner
That spinner has support various formats like these;
ReplyDeleteTga to Jpg
3gp to mp3
Wav to Wma
Png to Tga
Swf to Mp3