Native Mac OS X and iPhone back-ends for SDL_image

sdl_logoThis holiday break was much like revisiting my roots. I did OpenGL, OpenAL, and now SDL.

I finally got around to finishing one of the zillion things in my queue. With SDL getting closer to its 1.3 release, I felt compelled to get this one done. I have implemented and submitted a new native Mac OS X and also iPhone backend for SDL_image.

SDL_image currently depends on libgif, libjpeg, libpng, and libtiff to load these formats. For the official Mac OS X framework distribution, we have been statically linking these libraries into the framework. This has been a pain to build and maintain, particularly since none of these libraries have Universal Binary friendly build systems.

This submission utilizes native OS X frameworks to load the images so we no longer have to bundle these libraries. 


Details:

The Mac OS X implementation relies on ImageIO, which is Apple's fundamental image framework on the platform introduced in 10.4 (Tiger). This code is actually based on another submission I made to OpenSceneGraph quite awhile back to provide an ImageIO based loader as a replacement to the legacy QuickTime based loader (the latter of which is not 64-bit compatible). (Sadly osgdb_ImageIO.cpp continues to sit on the sideline because finishing the OSG/CMake build system is still stuck in my zillion item to-do list.)

The iPhone implementation relies on UIImage to do the image loading. Unfortunately, ImageIO is not on the iPhone, so I had to write another implementation based on UIImage.


Issues:

One problem with the UIImage API is that it doesn't have support for reading from streams. The SDL_Image implementation is written to funnel everything through SDL_RWops (streams). My only work-around for this is to read the entire stream into a buffer and then feed it to UIImage in one shot as NSData. I doubt this is efficient, so I decoupled the file and stream loading implementations so at least the file loading case will work well (which will hopefully be the dominant usage case).


Analysis:

I did a quick file size comparison of the old SDL_image framework and the ImageIO based SDL_image framework. The old one was about 1000k while the new one was 100k. That is a pretty nice size savings. And I think the old SDL_framework only had libjpeg and libpng linked in.


Links:

The repositories (which now have been merged to contain the same stuff) are here:

http://www.assembla.com/spaces/SDL_Image_ImageIO
http://www.assembla.com/spaces/SDL_Image_UIImage

Update: My patch has been officially added to SDL_image's repository.
http://svn.libsdl.org/trunk/SDL_image


Copyright © PlayControl Software, LLC / Eric Wing