SDL_image uses ImageIO for ios4 and osx and UIImage on ios3
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Dec 2011 16:14:00 -0500
changeset 279e2fa9ff13b5d
parent 278 2fd74c55f313
child 280 ec4ae96c100c
SDL_image uses ImageIO for ios4 and osx and UIImage on ios3

Vittorio Giovara

>> The second one is a feature request to make it so that when the
>> ImageIO framework is not present the library would fallback to the
>> UIImage backend; although it would perhaps make backporting a little
>> difficult I am sure that there is still a lot of software targeting
>> pre-ios 4 that could make use of it.
>
> It's possible, and not entirely unreasonable, but iOS moves so fast
> that I haven't felt it really merited the extra effort to do so. My
> experience is that there isn't a lot of interest in 3.x. I have a
> 3.1.3 device and there are actually very few apps (that I would be
> interested in getting) that support 3.x any more and I have to be very
> careful to no upgrade my existing apps because the new versions don't
> work on my device any more. I think the percentage of devices 3.x is
> less than 10% now. Testing old devices is another difficulty. And if
> you need to start weak linking frameworks in the Xcode project, you go
> into areas most non Apple developers don't know about.
>
> -Eric

I see your point, iOS is a much faster platform than OSX and a lot of
applications are dropping support for 3.* devices, however I feel that
as SDL is a compatibility layer between architectures it should be as
compatible as possible, until major api change or build system make it
impossible/unbearable to keep it updated.
Having said that I am proposing a solution that should keep SDL_image
compatible with both the newer ImageIO for ios4 and osx and allow us
to use uiimage on ios3: what I am linking is a merge of
IMG_UIImage.m and IMG_ImageIO.c and the small changes that need to be
applied to the related xcode project files).
IMG_ImageIO.c
IMG_ImageIO.m
Makefile.am
Xcode/SDL_image.xcodeproj/project.pbxproj
Xcode/showimage/showimage.xcodeproj/project.pbxproj
Xcode_iPhone/SDL_image.xcodeproj/project.pbxproj
configure.in
     1.1 --- a/IMG_ImageIO.c	Fri Dec 30 15:57:44 2011 -0500
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,523 +0,0 @@
     1.4 -/*
     1.5 - *  IMG_ImageIO.c
     1.6 - *  SDL_image
     1.7 - *
     1.8 - *  Created by Eric Wing on 1/1/09.
     1.9 - *  Copyright 2009 __MyCompanyName__. All rights reserved.
    1.10 - *
    1.11 - */
    1.12 -
    1.13 -#if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND)
    1.14 -
    1.15 -#include "SDL_image.h"
    1.16 -
    1.17 -// Used because CGDataProviderCreate became deprecated in 10.5
    1.18 -#include <AvailabilityMacros.h>
    1.19 -#include <TargetConditionals.h>
    1.20 -
    1.21 -#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
    1.22 -#import <MobileCoreServices/MobileCoreServices.h> // for UTCoreTypes.h
    1.23 -#import <ImageIO/ImageIO.h>
    1.24 -#else
    1.25 -// For ImageIO framework and also LaunchServices framework (for UTIs)
    1.26 -#include <ApplicationServices/ApplicationServices.h>
    1.27 -#endif
    1.28 -
    1.29 -/**************************************************************
    1.30 - ***** Begin Callback functions for block reading *************
    1.31 - **************************************************************/
    1.32 -
    1.33 -// This callback reads some bytes from an SDL_rwops and copies it
    1.34 -// to a Quartz buffer (supplied by Apple framework).
    1.35 -static size_t MyProviderGetBytesCallback(void* rwops_userdata, void* quartz_buffer, size_t the_count)
    1.36 -{
    1.37 -	return (size_t)SDL_RWread((struct SDL_RWops *)rwops_userdata, quartz_buffer, 1, the_count);
    1.38 -}
    1.39 -
    1.40 -// This callback is triggered when the data provider is released
    1.41 -// so you can clean up any resources.
    1.42 -static void MyProviderReleaseInfoCallback(void* rwops_userdata)
    1.43 -{
    1.44 -	// What should I put here? 
    1.45 -	// I think the user and SDL_RWops controls closing, so I don't do anything.
    1.46 -}
    1.47 -
    1.48 -static void MyProviderRewindCallback(void* rwops_userdata)
    1.49 -{
    1.50 -	SDL_RWseek((struct SDL_RWops *)rwops_userdata, 0, RW_SEEK_SET);
    1.51 -}
    1.52 -
    1.53 -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
    1.54 -off_t MyProviderSkipForwardBytesCallback(void* rwops_userdata, off_t the_count)
    1.55 -{
    1.56 -	off_t start_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
    1.57 -	SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
    1.58 -    off_t end_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
    1.59 -    return (end_position - start_position);	
    1.60 -}
    1.61 -#else // CGDataProviderCreate was deprecated in 10.5
    1.62 -static void MyProviderSkipBytesCallback(void* rwops_userdata, size_t the_count)
    1.63 -{
    1.64 -	SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
    1.65 -}
    1.66 -#endif
    1.67 -
    1.68 -
    1.69 -/**************************************************************
    1.70 - ***** End Callback functions for block reading ***************
    1.71 - **************************************************************/
    1.72 -
    1.73 -// This creates a CGImageSourceRef which is a handle to an image that can be used to examine information
    1.74 -// about the image or load the actual image data.
    1.75 -static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options)
    1.76 -{
    1.77 -	CGImageSourceRef source_ref;
    1.78 -
    1.79 -	// Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams.
    1.80 -	
    1.81 -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
    1.82 -	CGDataProviderSequentialCallbacks provider_callbacks =
    1.83 -	{
    1.84 -        0,
    1.85 -		MyProviderGetBytesCallback,
    1.86 -		MyProviderSkipForwardBytesCallback,
    1.87 -		MyProviderRewindCallback,
    1.88 -		MyProviderReleaseInfoCallback
    1.89 -	};
    1.90 -	
    1.91 -	CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks);
    1.92 -	
    1.93 -	
    1.94 -#else // CGDataProviderCreate was deprecated in 10.5
    1.95 -	
    1.96 -	CGDataProviderCallbacks provider_callbacks =
    1.97 -	{
    1.98 -		MyProviderGetBytesCallback,
    1.99 -		MyProviderSkipBytesCallback,
   1.100 -		MyProviderRewindCallback,
   1.101 -		MyProviderReleaseInfoCallback
   1.102 -	};
   1.103 -	
   1.104 -	CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks);
   1.105 -#endif
   1.106 -	// Get the CGImageSourceRef.
   1.107 -	// The dictionary can be NULL or contain hints to help ImageIO figure out the image type.
   1.108 -	source_ref = CGImageSourceCreateWithDataProvider(data_provider, hints_and_options);
   1.109 -	return source_ref;
   1.110 -}
   1.111 -
   1.112 -
   1.113 -/* Create a CGImageSourceRef from a file. */
   1.114 -/* Remember to CFRelease the created source when done. */
   1.115 -static CGImageSourceRef CreateCGImageSourceFromFile(const char* the_path)
   1.116 -{
   1.117 -    CFURLRef the_url = NULL;
   1.118 -    CGImageSourceRef source_ref = NULL;
   1.119 -	CFStringRef cf_string = NULL;
   1.120 -	
   1.121 -	/* Create a CFString from a C string */
   1.122 -	cf_string = CFStringCreateWithCString(
   1.123 -										  NULL,
   1.124 -										  the_path,
   1.125 -										  kCFStringEncodingUTF8
   1.126 -										  );
   1.127 -	if(!cf_string)
   1.128 -	{
   1.129 -		return NULL;
   1.130 -	}
   1.131 -	
   1.132 -	/* Create a CFURL from a CFString */
   1.133 -    the_url = CFURLCreateWithFileSystemPath(
   1.134 -											NULL, 
   1.135 -											cf_string,
   1.136 -											kCFURLPOSIXPathStyle,
   1.137 -											false
   1.138 -											);
   1.139 -	
   1.140 -	/* Don't need the CFString any more (error or not) */
   1.141 -	CFRelease(cf_string);
   1.142 -	
   1.143 -	if(!the_url)
   1.144 -	{
   1.145 -		return NULL;
   1.146 -	}
   1.147 -	
   1.148 -	
   1.149 -    source_ref = CGImageSourceCreateWithURL(the_url, NULL);
   1.150 -	/* Don't need the URL any more (error or not) */
   1.151 -	CFRelease(the_url);
   1.152 -	
   1.153 -	return source_ref;
   1.154 -}
   1.155 -
   1.156 -
   1.157 -
   1.158 -static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source)
   1.159 -{
   1.160 -	CGImageRef image_ref = NULL;
   1.161 -	
   1.162 -	if(NULL == image_source)
   1.163 -	{
   1.164 -		return NULL;
   1.165 -	}
   1.166 -	
   1.167 -	// Get the first item in the image source (some image formats may
   1.168 -	// contain multiple items).
   1.169 -	image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
   1.170 -	if(NULL == image_ref)
   1.171 -	{
   1.172 -		IMG_SetError("CGImageSourceCreateImageAtIndex() failed");
   1.173 -	}
   1.174 -	return image_ref;
   1.175 -}
   1.176 -
   1.177 -static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
   1.178 -{
   1.179 -	CFDictionaryRef hint_dictionary = NULL;
   1.180 -
   1.181 -	if(uti_string_hint != NULL)
   1.182 -	{
   1.183 -		// Do a bunch of work to setup a CFDictionary containing the jpeg compression properties.
   1.184 -		CFStringRef the_keys[1];
   1.185 -		CFStringRef the_values[1];
   1.186 -		
   1.187 -		the_keys[0] = kCGImageSourceTypeIdentifierHint;
   1.188 -		the_values[0] = uti_string_hint;
   1.189 -		
   1.190 -		// kCFTypeDictionaryKeyCallBacks or kCFCopyStringDictionaryKeyCallBacks?
   1.191 -		hint_dictionary = CFDictionaryCreate(NULL, (const void**)&the_keys, (const void**)&the_values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
   1.192 -	}
   1.193 -	return hint_dictionary;
   1.194 -}
   1.195 -
   1.196 -
   1.197 -
   1.198 -
   1.199 -static int Internal_isType(SDL_RWops* rw_ops, CFStringRef uti_string_to_test)
   1.200 -{
   1.201 -	CGImageSourceRef image_source;
   1.202 -	CFStringRef uti_type;
   1.203 -	Boolean is_type;
   1.204 -	
   1.205 -	CFDictionaryRef hint_dictionary = NULL;
   1.206 -	
   1.207 -	hint_dictionary = CreateHintDictionary(uti_string_to_test);	
   1.208 -	image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
   1.209 -	
   1.210 -	if(hint_dictionary != NULL)
   1.211 -	{
   1.212 -		CFRelease(hint_dictionary);		
   1.213 -	}
   1.214 -	
   1.215 -	if(NULL == image_source)
   1.216 -	{
   1.217 -		return 0;
   1.218 -	}
   1.219 -	
   1.220 -	// This will get the UTI of the container, not the image itself.
   1.221 -	// Under most cases, this won't be a problem.
   1.222 -	// But if a person passes an icon file which contains a bmp,
   1.223 -	// the format will be of the icon file.
   1.224 -	// But I think the main SDL_image codebase has this same problem so I'm not going to worry about it.	
   1.225 -	uti_type = CGImageSourceGetType(image_source);
   1.226 -	//	CFShow(uti_type);
   1.227 -	
   1.228 -	// Unsure if we really want conformance or equality
   1.229 -	is_type = UTTypeConformsTo(uti_string_to_test, uti_type);
   1.230 -	
   1.231 -	CFRelease(image_source);
   1.232 -	
   1.233 -	return (int)is_type;
   1.234 -}
   1.235 -
   1.236 -// Once we have our image, we need to get it into an SDL_Surface
   1.237 -static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
   1.238 -{
   1.239 -	/* This code is adapted from Apple's Documentation found here:
   1.240 -	 * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
   1.241 -	 * Listing 9-4††Using a Quartz image as a texture source.
   1.242 -	 * Unfortunately, this guide doesn't show what to do about
   1.243 -	 * non-RGBA image formats so I'm making the rest up.
   1.244 -	 * All this code should be scrutinized.
   1.245 -	 */
   1.246 -
   1.247 -	size_t w = CGImageGetWidth(image_ref);
   1.248 -	size_t h = CGImageGetHeight(image_ref);
   1.249 -	CGRect rect = {{0, 0}, {w, h}};
   1.250 -
   1.251 -	CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
   1.252 -	//size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
   1.253 -	size_t bits_per_component = 8;
   1.254 -
   1.255 -	SDL_Surface* surface;
   1.256 -	Uint32 Amask;
   1.257 -	Uint32 Rmask;
   1.258 -	Uint32 Gmask;
   1.259 -	Uint32 Bmask;
   1.260 -
   1.261 -	CGContextRef bitmap_context;
   1.262 -	CGBitmapInfo bitmap_info;
   1.263 -	CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
   1.264 -
   1.265 -	if (alpha == kCGImageAlphaNone ||
   1.266 -	    alpha == kCGImageAlphaNoneSkipFirst ||
   1.267 -	    alpha == kCGImageAlphaNoneSkipLast) {
   1.268 -		bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
   1.269 -		Amask = 0x00000000;
   1.270 -	} else {
   1.271 -		/* kCGImageAlphaFirst isn't supported */
   1.272 -		//bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
   1.273 -		bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
   1.274 -		Amask = 0xFF000000;
   1.275 -	}
   1.276 -
   1.277 -	Rmask = 0x00FF0000;
   1.278 -	Gmask = 0x0000FF00;
   1.279 -	Bmask = 0x000000FF;
   1.280 -
   1.281 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
   1.282 -	if (surface)
   1.283 -	{
   1.284 -		// Sets up a context to be drawn to with surface->pixels as the area to be drawn to
   1.285 -		bitmap_context = CGBitmapContextCreate(
   1.286 -															surface->pixels,
   1.287 -															surface->w,
   1.288 -															surface->h,
   1.289 -															bits_per_component,
   1.290 -															surface->pitch,
   1.291 -															color_space,
   1.292 -															bitmap_info
   1.293 -															);
   1.294 -
   1.295 -		// Draws the image into the context's image_data
   1.296 -		CGContextDrawImage(bitmap_context, rect, image_ref);
   1.297 -
   1.298 -		CGContextRelease(bitmap_context);
   1.299 -
   1.300 -		// FIXME: Reverse the premultiplied alpha
   1.301 -		if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
   1.302 -			int i, j;
   1.303 -			Uint8 *p = (Uint8 *)surface->pixels;
   1.304 -			for (i = surface->h * surface->pitch/4; i--; ) {
   1.305 -#if __LITTLE_ENDIAN__
   1.306 -				Uint8 A = p[3];
   1.307 -				if (A) {
   1.308 -					for (j = 0; j < 3; ++j) {
   1.309 -						p[j] = (p[j] * 255) / A;
   1.310 -					}
   1.311 -				}
   1.312 -#else
   1.313 -				Uint8 A = p[0];
   1.314 -				if (A) {
   1.315 -					for (j = 1; j < 4; ++j) {
   1.316 -						p[j] = (p[j] * 255) / A;
   1.317 -					}
   1.318 -				}
   1.319 -#endif /* ENDIAN */
   1.320 -				p += 4;
   1.321 -			}
   1.322 -		}
   1.323 -	}
   1.324 -
   1.325 -	if (color_space)
   1.326 -	{
   1.327 -		CGColorSpaceRelease(color_space);			
   1.328 -	}
   1.329 -
   1.330 -	return surface;
   1.331 -}
   1.332 -
   1.333 -
   1.334 -static SDL_Surface* LoadImageFromRWops(SDL_RWops* rw_ops, CFStringRef uti_string_hint)
   1.335 -{
   1.336 -	SDL_Surface* sdl_surface;
   1.337 -	CGImageSourceRef image_source;
   1.338 -	CGImageRef image_ref = NULL;
   1.339 -	CFDictionaryRef hint_dictionary = NULL;
   1.340 -
   1.341 -	hint_dictionary = CreateHintDictionary(uti_string_hint);
   1.342 -	image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
   1.343 -
   1.344 -	if(hint_dictionary != NULL)
   1.345 -	{
   1.346 -		CFRelease(hint_dictionary);		
   1.347 -	}
   1.348 -	
   1.349 -	if(NULL == image_source)
   1.350 -	{
   1.351 -		return NULL;
   1.352 -	}
   1.353 -	
   1.354 -	image_ref = CreateCGImageFromCGImageSource(image_source);
   1.355 -	CFRelease(image_source);
   1.356 -
   1.357 -	if(NULL == image_ref)
   1.358 -	{
   1.359 -		return NULL;
   1.360 -	}
   1.361 -	
   1.362 -	sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
   1.363 -	CFRelease(image_ref);
   1.364 -	return sdl_surface;
   1.365 -	
   1.366 -}
   1.367 -
   1.368 -
   1.369 -
   1.370 -static SDL_Surface* LoadImageFromFile(const char* file)
   1.371 -{
   1.372 -	SDL_Surface* sdl_surface = NULL;
   1.373 -	CGImageSourceRef image_source = NULL;
   1.374 -	CGImageRef image_ref = NULL;
   1.375 -	
   1.376 -	// First ImageIO
   1.377 -	image_source = CreateCGImageSourceFromFile(file);
   1.378 -	
   1.379 -	if(NULL == image_source)
   1.380 -	{
   1.381 -		return NULL;
   1.382 -	}
   1.383 -	
   1.384 -	image_ref = CreateCGImageFromCGImageSource(image_source);
   1.385 -	CFRelease(image_source);
   1.386 -	
   1.387 -	if(NULL == image_ref)
   1.388 -	{
   1.389 -		return NULL;
   1.390 -	}
   1.391 -	
   1.392 -	sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
   1.393 -	CFRelease(image_ref);
   1.394 -	return sdl_surface;	
   1.395 -}
   1.396 -
   1.397 -int IMG_InitJPG()
   1.398 -{
   1.399 -	return 0;
   1.400 -}
   1.401 -
   1.402 -void IMG_QuitJPG()
   1.403 -{
   1.404 -}
   1.405 -
   1.406 -int IMG_InitPNG()
   1.407 -{
   1.408 -	return 0;
   1.409 -}
   1.410 -
   1.411 -void IMG_QuitPNG()
   1.412 -{
   1.413 -}
   1.414 -
   1.415 -int IMG_InitTIF()
   1.416 -{
   1.417 -	return 0;
   1.418 -}
   1.419 -
   1.420 -void IMG_QuitTIF()
   1.421 -{
   1.422 -}
   1.423 -
   1.424 -int IMG_isCUR(SDL_RWops *src)
   1.425 -{
   1.426 -	/* FIXME: Is this a supported type? */
   1.427 -	return Internal_isType(src, CFSTR("com.microsoft.cur"));
   1.428 -}
   1.429 -
   1.430 -int IMG_isICO(SDL_RWops *src)
   1.431 -{
   1.432 -	return Internal_isType(src, kUTTypeICO);
   1.433 -}
   1.434 -
   1.435 -int IMG_isBMP(SDL_RWops *src)
   1.436 -{
   1.437 -	return Internal_isType(src, kUTTypeBMP);
   1.438 -}
   1.439 -
   1.440 -int IMG_isGIF(SDL_RWops *src)
   1.441 -{
   1.442 -	return Internal_isType(src, kUTTypeGIF);
   1.443 -}
   1.444 -
   1.445 -// Note: JPEG 2000 is kUTTypeJPEG2000
   1.446 -int IMG_isJPG(SDL_RWops *src)
   1.447 -{
   1.448 -	return Internal_isType(src, kUTTypeJPEG);
   1.449 -}
   1.450 -
   1.451 -int IMG_isPNG(SDL_RWops *src)
   1.452 -{
   1.453 -	return Internal_isType(src, kUTTypePNG);
   1.454 -}
   1.455 -
   1.456 -// This isn't a public API function. Apple seems to be able to identify tga's.
   1.457 -int IMG_isTGA(SDL_RWops *src)
   1.458 -{
   1.459 -	return Internal_isType(src, CFSTR("com.truevision.tga-image"));
   1.460 -}
   1.461 -
   1.462 -int IMG_isTIF(SDL_RWops *src)
   1.463 -{
   1.464 -	return Internal_isType(src, kUTTypeTIFF);
   1.465 -}
   1.466 -
   1.467 -SDL_Surface* IMG_LoadCUR_RW(SDL_RWops *src)
   1.468 -{
   1.469 -	/* FIXME: Is this a supported type? */
   1.470 -	return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
   1.471 -}
   1.472 -SDL_Surface* IMG_LoadICO_RW(SDL_RWops *src)
   1.473 -{
   1.474 -	return LoadImageFromRWops(src, kUTTypeICO);
   1.475 -}
   1.476 -SDL_Surface* IMG_LoadBMP_RW(SDL_RWops *src)
   1.477 -{
   1.478 -	return LoadImageFromRWops(src, kUTTypeBMP);
   1.479 -}
   1.480 -SDL_Surface* IMG_LoadGIF_RW(SDL_RWops *src)
   1.481 -{
   1.482 -	return LoadImageFromRWops(src, kUTTypeGIF);
   1.483 -}
   1.484 -SDL_Surface* IMG_LoadJPG_RW(SDL_RWops *src)
   1.485 -{
   1.486 -	return LoadImageFromRWops(src, kUTTypeJPEG);
   1.487 -}
   1.488 -SDL_Surface* IMG_LoadPNG_RW(SDL_RWops *src)
   1.489 -{
   1.490 -	return LoadImageFromRWops(src, kUTTypePNG);
   1.491 -}
   1.492 -SDL_Surface* IMG_LoadTGA_RW(SDL_RWops *src)
   1.493 -{
   1.494 -	return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
   1.495 -}
   1.496 -SDL_Surface* IMG_LoadTIF_RW(SDL_RWops *src)
   1.497 -{
   1.498 -	return LoadImageFromRWops(src, kUTTypeTIFF);
   1.499 -}
   1.500 -
   1.501 -// Apple provides both stream and file loading functions in ImageIO.
   1.502 -// Potentially, Apple can optimize for either case.
   1.503 -SDL_Surface* IMG_Load(const char *file)
   1.504 -{
   1.505 -	SDL_Surface* sdl_surface = NULL;
   1.506 -
   1.507 -	sdl_surface = LoadImageFromFile(file);
   1.508 -	if(NULL == sdl_surface)
   1.509 -	{
   1.510 -		// Either the file doesn't exist or ImageIO doesn't understand the format.
   1.511 -		// For the latter case, fallback to the native SDL_image handlers.
   1.512 -		SDL_RWops *src = SDL_RWFromFile(file, "rb");
   1.513 -		char *ext = strrchr(file, '.');
   1.514 -		if(ext) {
   1.515 -			ext++;
   1.516 -		}
   1.517 -		if(!src) {
   1.518 -			/* The error message has been set in SDL_RWFromFile */
   1.519 -			return NULL;
   1.520 -		}
   1.521 -		sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
   1.522 -	}
   1.523 -	return sdl_surface;
   1.524 -}
   1.525 -
   1.526 -#endif /* defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/IMG_ImageIO.m	Fri Dec 30 16:14:00 2011 -0500
     2.3 @@ -0,0 +1,718 @@
     2.4 +/*
     2.5 + *  IMG_ImageIO.c
     2.6 + *  SDL_image
     2.7 + *
     2.8 + *  Created by Eric Wing on 1/1/09.
     2.9 + *  Copyright 2009 __MyCompanyName__. All rights reserved.
    2.10 + *
    2.11 + */
    2.12 +
    2.13 +#if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND)
    2.14 +
    2.15 +#include "SDL_image.h"
    2.16 +
    2.17 +// Used because CGDataProviderCreate became deprecated in 10.5
    2.18 +#include <AvailabilityMacros.h>
    2.19 +#include <TargetConditionals.h>
    2.20 +#include <Foundation/Foundation.h>
    2.21 +
    2.22 +#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
    2.23 +#ifdef ALLOW_UIIMAGE_FALLBACK
    2.24 +#define USE_UIIMAGE_BACKEND() ([UIImage instancesRespondToSelector:@selector(initWithCGImage:scale:orientation:)] == NO)
    2.25 +#else
    2.26 +#define USE_UIIMAGE_BACKEND() (Internal_checkImageIOisAvailable())
    2.27 +#endif
    2.28 +#import <MobileCoreServices/MobileCoreServices.h> // for UTCoreTypes.h
    2.29 +#import <ImageIO/ImageIO.h>
    2.30 +#import <UIKit/UIImage.h>
    2.31 +#else
    2.32 +// For ImageIO framework and also LaunchServices framework (for UTIs)
    2.33 +#include <ApplicationServices/ApplicationServices.h>
    2.34 +#endif
    2.35 +
    2.36 +/**************************************************************
    2.37 + ***** Begin Callback functions for block reading *************
    2.38 + **************************************************************/
    2.39 +
    2.40 +// This callback reads some bytes from an SDL_rwops and copies it
    2.41 +// to a Quartz buffer (supplied by Apple framework).
    2.42 +static size_t MyProviderGetBytesCallback(void* rwops_userdata, void* quartz_buffer, size_t the_count)
    2.43 +{
    2.44 +    return (size_t)SDL_RWread((struct SDL_RWops *)rwops_userdata, quartz_buffer, 1, the_count);
    2.45 +}
    2.46 +
    2.47 +// This callback is triggered when the data provider is released
    2.48 +// so you can clean up any resources.
    2.49 +static void MyProviderReleaseInfoCallback(void* rwops_userdata)
    2.50 +{
    2.51 +    // What should I put here? 
    2.52 +    // I think the user and SDL_RWops controls closing, so I don't do anything.
    2.53 +}
    2.54 +
    2.55 +static void MyProviderRewindCallback(void* rwops_userdata)
    2.56 +{
    2.57 +    SDL_RWseek((struct SDL_RWops *)rwops_userdata, 0, RW_SEEK_SET);
    2.58 +}
    2.59 +
    2.60 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
    2.61 +off_t MyProviderSkipForwardBytesCallback(void* rwops_userdata, off_t the_count)
    2.62 +{
    2.63 +    off_t start_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
    2.64 +    SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
    2.65 +    off_t end_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
    2.66 +    return (end_position - start_position);	
    2.67 +}
    2.68 +#else // CGDataProviderCreate was deprecated in 10.5
    2.69 +static void MyProviderSkipBytesCallback(void* rwops_userdata, size_t the_count)
    2.70 +{
    2.71 +    SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
    2.72 +}
    2.73 +#endif
    2.74 +
    2.75 +/**************************************************************
    2.76 + ***** End Callback functions for block reading ***************
    2.77 + **************************************************************/
    2.78 +
    2.79 +// This creates a CGImageSourceRef which is a handle to an image that can be used to examine information
    2.80 +// about the image or load the actual image data.
    2.81 +static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options)
    2.82 +{
    2.83 +    CGImageSourceRef source_ref;
    2.84 +    
    2.85 +    // Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams.
    2.86 +    
    2.87 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
    2.88 +    CGDataProviderSequentialCallbacks provider_callbacks =
    2.89 +    {
    2.90 +        0,
    2.91 +        MyProviderGetBytesCallback,
    2.92 +        MyProviderSkipForwardBytesCallback,
    2.93 +        MyProviderRewindCallback,
    2.94 +        MyProviderReleaseInfoCallback
    2.95 +    };
    2.96 +    
    2.97 +    CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks);
    2.98 +    
    2.99 +    
   2.100 +#else // CGDataProviderCreate was deprecated in 10.5
   2.101 +    
   2.102 +    CGDataProviderCallbacks provider_callbacks =
   2.103 +    {
   2.104 +        MyProviderGetBytesCallback,
   2.105 +        MyProviderSkipBytesCallback,
   2.106 +        MyProviderRewindCallback,
   2.107 +        MyProviderReleaseInfoCallback
   2.108 +    };
   2.109 +    
   2.110 +    CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks);
   2.111 +#endif
   2.112 +    // Get the CGImageSourceRef.
   2.113 +    // The dictionary can be NULL or contain hints to help ImageIO figure out the image type.
   2.114 +    source_ref = CGImageSourceCreateWithDataProvider(data_provider, hints_and_options);
   2.115 +    return source_ref;
   2.116 +}
   2.117 +
   2.118 +/* Create a CGImageSourceRef from a file. */
   2.119 +/* Remember to CFRelease the created source when done. */
   2.120 +static CGImageSourceRef CreateCGImageSourceFromFile(const char* the_path)
   2.121 +{
   2.122 +    CFURLRef the_url = NULL;
   2.123 +    CGImageSourceRef source_ref = NULL;
   2.124 +    CFStringRef cf_string = NULL;
   2.125 +    
   2.126 +    /* Create a CFString from a C string */
   2.127 +    cf_string = CFStringCreateWithCString(NULL, the_path, kCFStringEncodingUTF8);
   2.128 +    if (!cf_string) {
   2.129 +        return NULL;
   2.130 +    }
   2.131 +    
   2.132 +    /* Create a CFURL from a CFString */
   2.133 +    the_url = CFURLCreateWithFileSystemPath(NULL, cf_string, kCFURLPOSIXPathStyle, false);
   2.134 +    
   2.135 +    /* Don't need the CFString any more (error or not) */
   2.136 +    CFRelease(cf_string);
   2.137 +    
   2.138 +    if(!the_url)
   2.139 +    {
   2.140 +        return NULL;
   2.141 +    }
   2.142 +    
   2.143 +    
   2.144 +    source_ref = CGImageSourceCreateWithURL(the_url, NULL);
   2.145 +    /* Don't need the URL any more (error or not) */
   2.146 +    CFRelease(the_url);
   2.147 +    
   2.148 +    return source_ref;
   2.149 +}
   2.150 +
   2.151 +static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source)
   2.152 +{
   2.153 +    CGImageRef image_ref = NULL;
   2.154 +    
   2.155 +    if(NULL == image_source)
   2.156 +    {
   2.157 +        return NULL;
   2.158 +    }
   2.159 +    
   2.160 +    // Get the first item in the image source (some image formats may
   2.161 +    // contain multiple items).
   2.162 +    image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
   2.163 +    if(NULL == image_ref)
   2.164 +    {
   2.165 +        IMG_SetError("CGImageSourceCreateImageAtIndex() failed");
   2.166 +    }
   2.167 +    return image_ref;
   2.168 +}
   2.169 +
   2.170 +static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
   2.171 +{
   2.172 +    CFDictionaryRef hint_dictionary = NULL;
   2.173 +    
   2.174 +    if(uti_string_hint != NULL)
   2.175 +    {
   2.176 +        // Do a bunch of work to setup a CFDictionary containing the jpeg compression properties.
   2.177 +        CFStringRef the_keys[1];
   2.178 +        CFStringRef the_values[1];
   2.179 +        
   2.180 +        the_keys[0] = kCGImageSourceTypeIdentifierHint;
   2.181 +        the_values[0] = uti_string_hint;
   2.182 +        
   2.183 +        // kCFTypeDictionaryKeyCallBacks or kCFCopyStringDictionaryKeyCallBacks?
   2.184 +        hint_dictionary = CFDictionaryCreate(NULL, (const void**)&the_keys, (const void**)&the_values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
   2.185 +    }
   2.186 +    return hint_dictionary;
   2.187 +}
   2.188 +
   2.189 +
   2.190 +// Once we have our image, we need to get it into an SDL_Surface
   2.191 +static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
   2.192 +{
   2.193 +    /* This code is adapted from Apple's Documentation found here:
   2.194 +     * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
   2.195 +     * Listing 9-4††Using a Quartz image as a texture source.
   2.196 +     * Unfortunately, this guide doesn't show what to do about
   2.197 +     * non-RGBA image formats so I'm making the rest up.
   2.198 +     * All this code should be scrutinized.
   2.199 +     */
   2.200 +    
   2.201 +    size_t w = CGImageGetWidth(image_ref);
   2.202 +    size_t h = CGImageGetHeight(image_ref);
   2.203 +    CGRect rect = {{0, 0}, {w, h}};
   2.204 +    
   2.205 +    CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
   2.206 +    //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
   2.207 +    size_t bits_per_component = 8;
   2.208 +    
   2.209 +    SDL_Surface* surface;
   2.210 +    Uint32 Amask;
   2.211 +    Uint32 Rmask;
   2.212 +    Uint32 Gmask;
   2.213 +    Uint32 Bmask;
   2.214 +    
   2.215 +    CGContextRef bitmap_context;
   2.216 +    CGBitmapInfo bitmap_info;
   2.217 +    CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
   2.218 +    
   2.219 +    if (alpha == kCGImageAlphaNone ||
   2.220 +        alpha == kCGImageAlphaNoneSkipFirst ||
   2.221 +        alpha == kCGImageAlphaNoneSkipLast) {
   2.222 +        bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
   2.223 +        Amask = 0x00000000;
   2.224 +    } else {
   2.225 +        /* kCGImageAlphaFirst isn't supported */
   2.226 +        //bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
   2.227 +        bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
   2.228 +        Amask = 0xFF000000;
   2.229 +    }
   2.230 +    
   2.231 +    Rmask = 0x00FF0000;
   2.232 +    Gmask = 0x0000FF00;
   2.233 +    Bmask = 0x000000FF;
   2.234 +    
   2.235 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
   2.236 +    if (surface)
   2.237 +    {
   2.238 +        // Sets up a context to be drawn to with surface->pixels as the area to be drawn to
   2.239 +        bitmap_context = CGBitmapContextCreate(
   2.240 +                                               surface->pixels,
   2.241 +                                               surface->w,
   2.242 +                                               surface->h,
   2.243 +                                               bits_per_component,
   2.244 +                                               surface->pitch,
   2.245 +                                               color_space,
   2.246 +                                               bitmap_info
   2.247 +                                               );
   2.248 +        
   2.249 +        // Draws the image into the context's image_data
   2.250 +        CGContextDrawImage(bitmap_context, rect, image_ref);
   2.251 +        
   2.252 +        CGContextRelease(bitmap_context);
   2.253 +        
   2.254 +        // FIXME: Reverse the premultiplied alpha
   2.255 +        if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
   2.256 +            int i, j;
   2.257 +            Uint8 *p = (Uint8 *)surface->pixels;
   2.258 +            for (i = surface->h * surface->pitch/4; i--; ) {
   2.259 +#if __LITTLE_ENDIAN__
   2.260 +                Uint8 A = p[3];
   2.261 +                if (A) {
   2.262 +                    for (j = 0; j < 3; ++j) {
   2.263 +                        p[j] = (p[j] * 255) / A;
   2.264 +                    }
   2.265 +                }
   2.266 +#else
   2.267 +                Uint8 A = p[0];
   2.268 +                if (A) {
   2.269 +                    for (j = 1; j < 4; ++j) {
   2.270 +                        p[j] = (p[j] * 255) / A;
   2.271 +                    }
   2.272 +                }
   2.273 +#endif /* ENDIAN */
   2.274 +                p += 4;
   2.275 +            }
   2.276 +        }
   2.277 +    }
   2.278 +    
   2.279 +    if (color_space)
   2.280 +    {
   2.281 +        CGColorSpaceRelease(color_space);			
   2.282 +    }
   2.283 +    
   2.284 +    return surface;
   2.285 +}
   2.286 +
   2.287 +
   2.288 +#pragma mark -
   2.289 +#pragma mark IMG_Init stubs
   2.290 +#if !defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
   2.291 +static int Internal_checkImageIOisAvailable() {
   2.292 +    // just check if we are running on ios 4 or more, else throw exception
   2.293 +    if ([UIImage instancesRespondToSelector:@selector(initWithCGImage:scale:orientation:)])
   2.294 +        return 0;
   2.295 +    [NSException raise:@"UIImage fallback not enabled at compile time"
   2.296 +                format:@"ImageIO is not available on your platform, please recompile SDL_Image with ALLOW_UIIMAGE_FALLBACK."];
   2.297 +    return -1;
   2.298 +}
   2.299 +#endif
   2.300 +
   2.301 +int IMG_InitJPG()
   2.302 +{
   2.303 +    return 0;
   2.304 +}
   2.305 +
   2.306 +void IMG_QuitJPG()
   2.307 +{
   2.308 +}
   2.309 +
   2.310 +int IMG_InitPNG()
   2.311 +{
   2.312 +    return 0;
   2.313 +}
   2.314 +
   2.315 +void IMG_QuitPNG()
   2.316 +{
   2.317 +}
   2.318 +
   2.319 +int IMG_InitTIF()
   2.320 +{
   2.321 +    return 0;
   2.322 +}
   2.323 +
   2.324 +void IMG_QuitTIF()
   2.325 +{
   2.326 +}
   2.327 +
   2.328 +#pragma mark -
   2.329 +#pragma mark Get type of image
   2.330 +static int Internal_isType_UIImage (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
   2.331 +{
   2.332 +    int is_type = 0;
   2.333 +    
   2.334 +#if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
   2.335 +    int start = SDL_RWtell(rw_ops);
   2.336 +    if ((0 == CFStringCompare(uti_string_to_test, kUTTypeICO, 0)) ||
   2.337 +        (0 == CFStringCompare(uti_string_to_test, CFSTR("com.microsoft.cur"), 0))) {
   2.338 +        
   2.339 +        // The Win32 ICO file header (14 bytes)
   2.340 +        Uint16 bfReserved;
   2.341 +        Uint16 bfType;
   2.342 +        Uint16 bfCount;
   2.343 +        int type = (0 == CFStringCompare(uti_string_to_test, kUTTypeICO, 0)) ? 1 : 2;
   2.344 +        
   2.345 +        bfReserved = SDL_ReadLE16(rw_ops);
   2.346 +        bfType = SDL_ReadLE16(rw_ops);
   2.347 +        bfCount = SDL_ReadLE16(rw_ops);
   2.348 +        if ((bfReserved == 0) && (bfType == type) && (bfCount != 0)) 
   2.349 +            is_type = 1;
   2.350 +    } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeBMP, 0)) {
   2.351 +        char magic[2];
   2.352 +        
   2.353 +        if ( SDL_RWread(rw_ops, magic, sizeof(magic), 1) ) {
   2.354 +            if ( strncmp(magic, "BM", 2) == 0 ) {
   2.355 +                is_type = 1;
   2.356 +            }
   2.357 +        }
   2.358 +    } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeGIF, 0)) {
   2.359 +        char magic[6];
   2.360 +        
   2.361 +        if ( SDL_RWread(rw_ops, magic, sizeof(magic), 1) ) {
   2.362 +            if ( (strncmp(magic, "GIF", 3) == 0) &&
   2.363 +                ((memcmp(magic + 3, "87a", 3) == 0) ||
   2.364 +                 (memcmp(magic + 3, "89a", 3) == 0)) ) {
   2.365 +                    is_type = 1;
   2.366 +                }
   2.367 +        }
   2.368 +    } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeJPEG, 0)) {
   2.369 +        int in_scan = 0;
   2.370 +        Uint8 magic[4];
   2.371 +        
   2.372 +        // This detection code is by Steaphan Greene <stea@cs.binghamton.edu>
   2.373 +        // Blame me, not Sam, if this doesn't work right. */
   2.374 +        // And don't forget to report the problem to the the sdl list too! */
   2.375 +        
   2.376 +        if ( SDL_RWread(rw_ops, magic, 2, 1) ) {
   2.377 +            if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
   2.378 +                is_type = 1;
   2.379 +                while (is_type == 1) {
   2.380 +                    if(SDL_RWread(rw_ops, magic, 1, 2) != 2) {
   2.381 +                        is_type = 0;
   2.382 +                    } else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
   2.383 +                        is_type = 0;
   2.384 +                    } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
   2.385 +                        /* Extra padding in JPEG (legal) */
   2.386 +                        /* or this is data and we are scanning */
   2.387 +                        SDL_RWseek(rw_ops, -1, SEEK_CUR);
   2.388 +                    } else if(magic[1] == 0xD9) {
   2.389 +                        /* Got to end of good JPEG */
   2.390 +                        break;
   2.391 +                    } else if( (in_scan == 1) && (magic[1] == 0x00) ) {
   2.392 +                        /* This is an encoded 0xFF within the data */
   2.393 +                    } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
   2.394 +                        /* These have nothing else */
   2.395 +                    } else if(SDL_RWread(rw_ops, magic+2, 1, 2) != 2) {
   2.396 +                        is_type = 0;
   2.397 +                    } else {
   2.398 +                        /* Yes, it's big-endian */
   2.399 +                        Uint32 start;
   2.400 +                        Uint32 size;
   2.401 +                        Uint32 end;
   2.402 +                        start = SDL_RWtell(rw_ops);
   2.403 +                        size = (magic[2] << 8) + magic[3];
   2.404 +                        end = SDL_RWseek(rw_ops, size-2, SEEK_CUR);
   2.405 +                        if ( end != start + size - 2 ) is_type = 0;
   2.406 +                        if ( magic[1] == 0xDA ) {
   2.407 +                            /* Now comes the actual JPEG meat */
   2.408 +#ifdef	FAST_IS_JPEG
   2.409 +                            /* Ok, I'm convinced.  It is a JPEG. */
   2.410 +                            break;
   2.411 +#else
   2.412 +                            /* I'm not convinced.  Prove it! */
   2.413 +                            in_scan = 1;
   2.414 +#endif
   2.415 +                        }
   2.416 +                    }
   2.417 +                }
   2.418 +            }
   2.419 +        }
   2.420 +    } else if (0 == CFStringCompare(uti_string_to_test, kUTTypePNG, 0)) {
   2.421 +        Uint8 magic[4];
   2.422 +        
   2.423 +        if ( SDL_RWread(rw_ops, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   2.424 +            if ( magic[0] == 0x89 &&
   2.425 +                magic[1] == 'P' &&
   2.426 +                magic[2] == 'N' &&
   2.427 +                magic[3] == 'G' ) {
   2.428 +                is_type = 1;
   2.429 +            }
   2.430 +        }
   2.431 +    } else if (0 == CFStringCompare(uti_string_to_test, CFSTR("com.truevision.tga-image"), 0)) {
   2.432 +        //TODO: fill me!
   2.433 +    } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeTIFF, 0)) {
   2.434 +        Uint8 magic[4];
   2.435 +        
   2.436 +        if ( SDL_RWread(rw_ops, magic, 1, sizeof(magic)) == sizeof(magic) ) {
   2.437 +            if ( (magic[0] == 'I' &&
   2.438 +                  magic[1] == 'I' &&
   2.439 +                  magic[2] == 0x2a &&
   2.440 +                  magic[3] == 0x00) ||
   2.441 +                (magic[0] == 'M' &&
   2.442 +                 magic[1] == 'M' &&
   2.443 +                 magic[2] == 0x00 &&
   2.444 +                 magic[3] == 0x2a) ) {
   2.445 +                    is_type = 1;
   2.446 +                }
   2.447 +        }
   2.448 +    }
   2.449 +    
   2.450 +    // reset the file descption pointer
   2.451 +    SDL_RWseek(rw_ops, start, SEEK_SET);
   2.452 +
   2.453 +#endif  /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
   2.454 +    return is_type;
   2.455 +}
   2.456 +
   2.457 +static int Internal_isType_ImageIO (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
   2.458 +{
   2.459 +    int is_type = 0;
   2.460 +    
   2.461 +    CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_to_test);	
   2.462 +    CGImageSourceRef image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
   2.463 +    
   2.464 +    if (hint_dictionary != NULL) {
   2.465 +        CFRelease(hint_dictionary);		
   2.466 +    }
   2.467 +    
   2.468 +    if (NULL == image_source) {
   2.469 +        return 0;
   2.470 +    }
   2.471 +    
   2.472 +    // This will get the UTI of the container, not the image itself.
   2.473 +    // Under most cases, this won't be a problem.
   2.474 +    // But if a person passes an icon file which contains a bmp,
   2.475 +    // the format will be of the icon file.
   2.476 +    // But I think the main SDL_image codebase has this same problem so I'm not going to worry about it.	
   2.477 +    CFStringRef uti_type = CGImageSourceGetType(image_source);
   2.478 +    //	CFShow(uti_type);
   2.479 +    
   2.480 +    // Unsure if we really want conformance or equality
   2.481 +    is_type = (int)UTTypeConformsTo(uti_string_to_test, uti_type);
   2.482 +    
   2.483 +    CFRelease(image_source);
   2.484 +    return is_type;
   2.485 +}
   2.486 +
   2.487 +static int Internal_isType (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
   2.488 +{
   2.489 +    if (rw_ops == NULL)
   2.490 +        return 0;
   2.491 +    
   2.492 +#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
   2.493 +    if (USE_UIIMAGE_BACKEND())
   2.494 +        return Internal_isType_UIImage(rw_ops, uti_string_to_test);
   2.495 +    else
   2.496 +#endif
   2.497 +        return Internal_isType_ImageIO(rw_ops, uti_string_to_test);
   2.498 +}
   2.499 +
   2.500 +int IMG_isCUR(SDL_RWops *src)
   2.501 +{
   2.502 +    /* FIXME: Is this a supported type? */
   2.503 +    return Internal_isType(src, CFSTR("com.microsoft.cur"));
   2.504 +}
   2.505 +
   2.506 +int IMG_isICO(SDL_RWops *src)
   2.507 +{
   2.508 +    return Internal_isType(src, kUTTypeICO);
   2.509 +}
   2.510 +
   2.511 +int IMG_isBMP(SDL_RWops *src)
   2.512 +{
   2.513 +    return Internal_isType(src, kUTTypeBMP);
   2.514 +}
   2.515 +
   2.516 +int IMG_isGIF(SDL_RWops *src)
   2.517 +{
   2.518 +    return Internal_isType(src, kUTTypeGIF);
   2.519 +}
   2.520 +
   2.521 +// Note: JPEG 2000 is kUTTypeJPEG2000
   2.522 +int IMG_isJPG(SDL_RWops *src)
   2.523 +{
   2.524 +    return Internal_isType(src, kUTTypeJPEG);
   2.525 +}
   2.526 +
   2.527 +int IMG_isPNG(SDL_RWops *src)
   2.528 +{
   2.529 +    return Internal_isType(src, kUTTypePNG);
   2.530 +}
   2.531 +
   2.532 +// This isn't a public API function. Apple seems to be able to identify tga's.
   2.533 +int IMG_isTGA(SDL_RWops *src)
   2.534 +{
   2.535 +    return Internal_isType(src, CFSTR("com.truevision.tga-image"));
   2.536 +}
   2.537 +
   2.538 +int IMG_isTIF(SDL_RWops *src)
   2.539 +{
   2.540 +    return Internal_isType(src, kUTTypeTIFF);
   2.541 +}
   2.542 +
   2.543 +#pragma mark -
   2.544 +#pragma mark Load image engine
   2.545 +static SDL_Surface *LoadImageFromRWops_UIImage (SDL_RWops* rw_ops, CFStringRef uti_string_hint)
   2.546 +{
   2.547 +    SDL_Surface *sdl_surface = NULL;
   2.548 +
   2.549 +#if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
   2.550 +    NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   2.551 +    UIImage *ui_image;
   2.552 +    int bytes_read = 0;
   2.553 +    // I don't know what a good size is. 
   2.554 +    // Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
   2.555 +    const int block_size = 1024*4;
   2.556 +    char temp_buffer[block_size];
   2.557 +    
   2.558 +    NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
   2.559 +    do {
   2.560 +        bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
   2.561 +        [ns_data appendBytes:temp_buffer length:bytes_read];
   2.562 +    } while (bytes_read > 0);
   2.563 +    
   2.564 +    ui_image = [[UIImage alloc] initWithData:ns_data];
   2.565 +    if (ui_image != nil)
   2.566 +        sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   2.567 +    [ui_image release];
   2.568 +    [ns_data release];          
   2.569 +    [autorelease_pool drain];
   2.570 +
   2.571 +#endif  /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
   2.572 +    return sdl_surface;
   2.573 +}
   2.574 +
   2.575 +static SDL_Surface *LoadImageFromRWops_ImageIO (SDL_RWops *rw_ops, CFStringRef uti_string_hint)
   2.576 +{
   2.577 +    CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_hint);
   2.578 +    CGImageSourceRef image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
   2.579 +
   2.580 +    if (hint_dictionary != NULL)
   2.581 +        CFRelease(hint_dictionary);		
   2.582 +
   2.583 +    if (NULL == image_source)
   2.584 +        return NULL;
   2.585 +    
   2.586 +    CGImageRef image_ref = CreateCGImageFromCGImageSource(image_source);
   2.587 +    CFRelease(image_source);
   2.588 +
   2.589 +    if (NULL == image_ref)
   2.590 +        return NULL;
   2.591 +    SDL_Surface *sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
   2.592 +    CFRelease(image_ref);
   2.593 +
   2.594 +    return sdl_surface;
   2.595 +}
   2.596 +
   2.597 +static SDL_Surface *LoadImageFromRWops (SDL_RWops *rw_ops, CFStringRef uti_string_hint)
   2.598 +{
   2.599 +#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
   2.600 +    if (USE_UIIMAGE_BACKEND()) 
   2.601 +        return LoadImageFromRWops_UIImage(rw_ops, uti_string_hint);
   2.602 +    else
   2.603 +#endif
   2.604 +        return LoadImageFromRWops_ImageIO(rw_ops, uti_string_hint);
   2.605 +}
   2.606 +
   2.607 +static SDL_Surface* LoadImageFromFile_UIImage (const char *file)
   2.608 +{
   2.609 +    SDL_Surface *sdl_surface = NULL;
   2.610 +
   2.611 +#if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
   2.612 +    NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   2.613 +    NSString *ns_string = [[NSString alloc] initWithUTF8String:file];
   2.614 +    UIImage *ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
   2.615 +    if (ui_image != nil)
   2.616 +        sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
   2.617 +    [ui_image release];
   2.618 +    [ns_string release];
   2.619 +    [autorelease_pool drain];
   2.620 +
   2.621 +#endif  /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
   2.622 +    return sdl_surface;	
   2.623 +}
   2.624 +
   2.625 +static SDL_Surface* LoadImageFromFile_ImageIO (const char *file)
   2.626 +{
   2.627 +    CGImageSourceRef image_source = NULL;
   2.628 +
   2.629 +    image_source = CreateCGImageSourceFromFile(file);
   2.630 +
   2.631 +    if(NULL == image_source)
   2.632 +        return NULL;
   2.633 +    
   2.634 +    CGImageRef image_ref = CreateCGImageFromCGImageSource(image_source);
   2.635 +    CFRelease(image_source);
   2.636 +
   2.637 +    if (NULL == image_ref)
   2.638 +        return NULL;
   2.639 +    SDL_Surface *sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
   2.640 +    CFRelease(image_ref);
   2.641 +    return sdl_surface;	
   2.642 +}
   2.643 +
   2.644 +static SDL_Surface* LoadImageFromFile (const char *file)
   2.645 +{
   2.646 +#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
   2.647 +    if (USE_UIIMAGE_BACKEND())
   2.648 +        return LoadImageFromFile_UIImage(file);
   2.649 +    else
   2.650 +#endif
   2.651 +        return LoadImageFromFile_ImageIO(file);
   2.652 +}
   2.653 +
   2.654 +SDL_Surface* IMG_LoadCUR_RW (SDL_RWops *src)
   2.655 +{
   2.656 +    /* FIXME: Is this a supported type? */
   2.657 +    return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
   2.658 +}
   2.659 +
   2.660 +SDL_Surface* IMG_LoadICO_RW (SDL_RWops *src)
   2.661 +{
   2.662 +    return LoadImageFromRWops(src, kUTTypeICO);
   2.663 +}
   2.664 +
   2.665 +SDL_Surface* IMG_LoadBMP_RW (SDL_RWops *src)
   2.666 +{
   2.667 +    return LoadImageFromRWops(src, kUTTypeBMP);
   2.668 +}
   2.669 +
   2.670 +SDL_Surface* IMG_LoadGIF_RW (SDL_RWops *src)
   2.671 +{
   2.672 +    return LoadImageFromRWops (src, kUTTypeGIF);
   2.673 +}
   2.674 +
   2.675 +SDL_Surface* IMG_LoadJPG_RW (SDL_RWops *src)
   2.676 +{
   2.677 +    return LoadImageFromRWops (src, kUTTypeJPEG);
   2.678 +}
   2.679 +
   2.680 +SDL_Surface* IMG_LoadPNG_RW (SDL_RWops *src)
   2.681 +{
   2.682 +    return LoadImageFromRWops (src, kUTTypePNG);
   2.683 +}
   2.684 +
   2.685 +SDL_Surface* IMG_LoadTGA_RW (SDL_RWops *src)
   2.686 +{
   2.687 +    return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
   2.688 +}
   2.689 +
   2.690 +SDL_Surface* IMG_LoadTIF_RW (SDL_RWops *src)
   2.691 +{
   2.692 +    return LoadImageFromRWops(src, kUTTypeTIFF);
   2.693 +}
   2.694 +
   2.695 +// Since UIImage doesn't really support streams well, we should optimize for the file case.
   2.696 +// Apple provides both stream and file loading functions in ImageIO.
   2.697 +// Potentially, Apple can optimize for either case.
   2.698 +SDL_Surface* IMG_Load (const char *file)
   2.699 +{
   2.700 +    SDL_Surface* sdl_surface = NULL;
   2.701 +    
   2.702 +    sdl_surface = LoadImageFromFile(file);
   2.703 +    if(NULL == sdl_surface)
   2.704 +    {
   2.705 +        // Either the file doesn't exist or ImageIO doesn't understand the format.
   2.706 +        // For the latter case, fallback to the native SDL_image handlers.
   2.707 +        SDL_RWops *src = SDL_RWFromFile(file, "rb");
   2.708 +        char *ext = strrchr(file, '.');
   2.709 +        if (ext) {
   2.710 +            ext++;
   2.711 +        }
   2.712 +        if (!src) {
   2.713 +            /* The error message has been set in SDL_RWFromFile */
   2.714 +            return NULL;
   2.715 +        }
   2.716 +        sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
   2.717 +    }
   2.718 +    return sdl_surface;
   2.719 +}
   2.720 +
   2.721 +#endif /* defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) */
     3.1 --- a/Makefile.am	Fri Dec 30 15:57:44 2011 -0500
     3.2 +++ b/Makefile.am	Fri Dec 30 16:14:00 2011 -0500
     3.3 @@ -21,7 +21,7 @@
     3.4  	IMG_xpm.c		\
     3.5  	IMG_xv.c		\
     3.6  	IMG_webp.c	\
     3.7 -	IMG_ImageIO.c
     3.8 +	IMG_ImageIO.m
     3.9  
    3.10  EXTRA_DIST =			\
    3.11  	Android.mk		\
     4.1 --- a/Xcode/SDL_image.xcodeproj/project.pbxproj	Fri Dec 30 15:57:44 2011 -0500
     4.2 +++ b/Xcode/SDL_image.xcodeproj/project.pbxproj	Fri Dec 30 16:14:00 2011 -0500
     4.3 @@ -8,8 +8,8 @@
     4.4  
     4.5  /* Begin PBXBuildFile section */
     4.6  		005DF5E90A140CA2006B0BD5 /* IMG_xv.c in Sources */ = {isa = PBXBuildFile; fileRef = 005DF5E70A140CA2006B0BD5 /* IMG_xv.c */; };
     4.7 -		007287E40F0D997300C302A9 /* IMG_ImageIO.c in Sources */ = {isa = PBXBuildFile; fileRef = 007287E30F0D997300C302A9 /* IMG_ImageIO.c */; };
     4.8 -		007287E50F0D997300C302A9 /* IMG_ImageIO.c in Sources */ = {isa = PBXBuildFile; fileRef = 007287E30F0D997300C302A9 /* IMG_ImageIO.c */; };
     4.9 +		007287E40F0D997300C302A9 /* IMG_ImageIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 007287E30F0D997300C302A9 /* IMG_ImageIO.m */; };
    4.10 +		007287E50F0D997300C302A9 /* IMG_ImageIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 007287E30F0D997300C302A9 /* IMG_ImageIO.m */; };
    4.11  		007288A70F0DA79800C302A9 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007288A60F0DA79800C302A9 /* ApplicationServices.framework */; };
    4.12  		007288A80F0DA79800C302A9 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007288A60F0DA79800C302A9 /* ApplicationServices.framework */; };
    4.13  		007289690F0DC29B00C302A9 /* IMG_lbm.c in Sources */ = {isa = PBXBuildFile; fileRef = F5FB1F0001CD818601FAFB42 /* IMG_lbm.c */; };
    4.14 @@ -19,6 +19,7 @@
    4.15  		0072897B0F0DC2D100C302A9 /* IMG_xpm.c in Sources */ = {isa = PBXBuildFile; fileRef = 3BB4C062012FAC847F000001 /* IMG_xpm.c */; };
    4.16  		0072897C0F0DC2D300C302A9 /* IMG_xv.c in Sources */ = {isa = PBXBuildFile; fileRef = 005DF5E70A140CA2006B0BD5 /* IMG_xv.c */; };
    4.17  		0072897D0F0DC2D400C302A9 /* IMG_xxx.c in Sources */ = {isa = PBXBuildFile; fileRef = B2D7A06503FAB42200A8000A /* IMG_xxx.c */; };
    4.18 +		61F8544A145A19BC002CA294 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61F85449145A19BC002CA294 /* Foundation.framework */; };
    4.19  		BE1FA71A07AF4C44004B6283 /* SDL_image.h in Headers */ = {isa = PBXBuildFile; fileRef = 1014BAEA010A4B677F000001 /* SDL_image.h */; settings = {ATTRIBUTES = (Public, ); }; };
    4.20  		BE1FA71D07AF4C44004B6283 /* IMG.c in Sources */ = {isa = PBXBuildFile; fileRef = 3BB4C058012FAC847F000001 /* IMG.c */; };
    4.21  		BE1FA73207AF4C45004B6283 /* IMG.c in Sources */ = {isa = PBXBuildFile; fileRef = 3BB4C058012FAC847F000001 /* IMG.c */; };
    4.22 @@ -43,7 +44,7 @@
    4.23  
    4.24  /* Begin PBXFileReference section */
    4.25  		005DF5E70A140CA2006B0BD5 /* IMG_xv.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG_xv.c; path = ../IMG_xv.c; sourceTree = SOURCE_ROOT; };
    4.26 -		007287E30F0D997300C302A9 /* IMG_ImageIO.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = IMG_ImageIO.c; path = ../IMG_ImageIO.c; sourceTree = "<group>"; };
    4.27 +		007287E30F0D997300C302A9 /* IMG_ImageIO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IMG_ImageIO.m; path = ../IMG_ImageIO.m; sourceTree = "<group>"; };
    4.28  		007288A60F0DA79800C302A9 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; };
    4.29  		1014BAEA010A4B677F000001 /* SDL_image.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_image.h; path = ../SDL_image.h; sourceTree = SOURCE_ROOT; };
    4.30  		3BB4C058012FAC847F000001 /* IMG.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG.c; path = ../IMG.c; sourceTree = SOURCE_ROOT; };
    4.31 @@ -57,6 +58,7 @@
    4.32  		3BB4C060012FAC847F000001 /* IMG_tif.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG_tif.c; path = ../IMG_tif.c; sourceTree = SOURCE_ROOT; };
    4.33  		3BB4C061012FAC847F000001 /* IMG_xcf.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG_xcf.c; path = ../IMG_xcf.c; sourceTree = SOURCE_ROOT; };
    4.34  		3BB4C062012FAC847F000001 /* IMG_xpm.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG_xpm.c; path = ../IMG_xpm.c; sourceTree = SOURCE_ROOT; };
    4.35 +		61F85449145A19BC002CA294 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
    4.36  		B2D7A06503FAB42200A8000A /* IMG_xxx.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG_xxx.c; path = ../IMG_xxx.c; sourceTree = SOURCE_ROOT; };
    4.37  		BE1FA72D07AF4C44004B6283 /* Info-Framework__Upgraded_.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-Framework__Upgraded_.plist"; sourceTree = "<group>"; };
    4.38  		BE1FA72E07AF4C45004B6283 /* SDL_image.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDL_image.framework; sourceTree = BUILT_PRODUCTS_DIR; };
    4.39 @@ -76,6 +78,7 @@
    4.40  			files = (
    4.41  				BE1FA76307AF7335004B6283 /* SDL.framework in Frameworks */,
    4.42  				007288A70F0DA79800C302A9 /* ApplicationServices.framework in Frameworks */,
    4.43 +				61F8544A145A19BC002CA294 /* Foundation.framework in Frameworks */,
    4.44  			);
    4.45  			runOnlyForDeploymentPostprocessing = 0;
    4.46  		};
    4.47 @@ -146,7 +149,7 @@
    4.48  				3BB4C062012FAC847F000001 /* IMG_xpm.c */,
    4.49  				005DF5E70A140CA2006B0BD5 /* IMG_xv.c */,
    4.50  				B2D7A06503FAB42200A8000A /* IMG_xxx.c */,
    4.51 -				007287E30F0D997300C302A9 /* IMG_ImageIO.c */,
    4.52 +				007287E30F0D997300C302A9 /* IMG_ImageIO.m */,
    4.53  			);
    4.54  			name = "Library Source";
    4.55  			sourceTree = "<group>";
    4.56 @@ -164,6 +167,7 @@
    4.57  			isa = PBXGroup;
    4.58  			children = (
    4.59  				BE1FA76007AF72B1004B6283 /* Linked Frameworks */,
    4.60 +				61F85449145A19BC002CA294 /* Foundation.framework */,
    4.61  			);
    4.62  			name = Frameworks;
    4.63  			sourceTree = "<group>";
    4.64 @@ -271,7 +275,14 @@
    4.65  			isa = PBXProject;
    4.66  			buildConfigurationList = 00B7E3B6097EB73D00826121 /* Build configuration list for PBXProject "SDL_image" */;
    4.67  			compatibilityVersion = "Xcode 2.4";
    4.68 +			developmentRegion = English;
    4.69  			hasScannedForEncodings = 1;
    4.70 +			knownRegions = (
    4.71 +				English,
    4.72 +				Japanese,
    4.73 +				French,
    4.74 +				German,
    4.75 +			);
    4.76  			mainGroup = 0867D691FE84028FC02AAC07 /* SDL_imageFramework */;
    4.77  			productRefGroup = 034768DDFF38A45A11DB9C8B /* Products */;
    4.78  			projectDirPath = "";
    4.79 @@ -329,7 +340,7 @@
    4.80  			buildActionMask = 2147483647;
    4.81  			files = (
    4.82  				BE1FA71D07AF4C44004B6283 /* IMG.c in Sources */,
    4.83 -				007287E40F0D997300C302A9 /* IMG_ImageIO.c in Sources */,
    4.84 +				007287E40F0D997300C302A9 /* IMG_ImageIO.m in Sources */,
    4.85  				007289690F0DC29B00C302A9 /* IMG_lbm.c in Sources */,
    4.86  				0072896A0F0DC29F00C302A9 /* IMG_pcx.c in Sources */,
    4.87  				007289720F0DC2BD00C302A9 /* IMG_pnm.c in Sources */,
    4.88 @@ -352,7 +363,7 @@
    4.89  				BE1FA73D07AF4C45004B6283 /* IMG_lbm.c in Sources */,
    4.90  				BE1FA73E07AF4C45004B6283 /* IMG_xxx.c in Sources */,
    4.91  				005DF5E90A140CA2006B0BD5 /* IMG_xv.c in Sources */,
    4.92 -				007287E50F0D997300C302A9 /* IMG_ImageIO.c in Sources */,
    4.93 +				007287E50F0D997300C302A9 /* IMG_ImageIO.m in Sources */,
    4.94  			);
    4.95  			runOnlyForDeploymentPostprocessing = 0;
    4.96  		};
     5.1 --- a/Xcode/showimage/showimage.xcodeproj/project.pbxproj	Fri Dec 30 15:57:44 2011 -0500
     5.2 +++ b/Xcode/showimage/showimage.xcodeproj/project.pbxproj	Fri Dec 30 16:14:00 2011 -0500
     5.3 @@ -158,7 +158,14 @@
     5.4  			isa = PBXProject;
     5.5  			buildConfigurationList = 00B7E563097EF9A500826121 /* Build configuration list for PBXProject "showimage" */;
     5.6  			compatibilityVersion = "Xcode 2.4";
     5.7 +			developmentRegion = English;
     5.8  			hasScannedForEncodings = 0;
     5.9 +			knownRegions = (
    5.10 +				English,
    5.11 +				Japanese,
    5.12 +				French,
    5.13 +				German,
    5.14 +			);
    5.15  			mainGroup = 29B97314FDCFA39411CA2CEA /* SDL App */;
    5.16  			projectDirPath = "";
    5.17  			projectRoot = "";
     6.1 --- a/Xcode_iPhone/SDL_image.xcodeproj/project.pbxproj	Fri Dec 30 15:57:44 2011 -0500
     6.2 +++ b/Xcode_iPhone/SDL_image.xcodeproj/project.pbxproj	Fri Dec 30 16:14:00 2011 -0500
     6.3 @@ -11,7 +11,7 @@
     6.4  		007288A80F0DA79800C302A9 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007288A60F0DA79800C302A9 /* ApplicationServices.framework */; };
     6.5  		00728B2A0F0E004C00C302A9 /* IMG_tga.c in Sources */ = {isa = PBXBuildFile; fileRef = 3BB4C05F012FAC847F000001 /* IMG_tga.c */; };
     6.6  		00A06D7812FFBFD5009F1A11 /* SDL_image.h in Headers */ = {isa = PBXBuildFile; fileRef = 1014BAEA010A4B677F000001 /* SDL_image.h */; };
     6.7 -		00A6250312F4E9CC00577F68 /* IMG_ImageIO.c in Sources */ = {isa = PBXBuildFile; fileRef = 00A624FD12F4E99800577F68 /* IMG_ImageIO.c */; };
     6.8 +		00A6250312F4E9CC00577F68 /* IMG_ImageIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 00A624FD12F4E99800577F68 /* IMG_ImageIO.m */; };
     6.9  		00A625CF12F544F400577F68 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00A625CE12F544F400577F68 /* ImageIO.framework */; };
    6.10  		BE1FA73207AF4C45004B6283 /* IMG.c in Sources */ = {isa = PBXBuildFile; fileRef = 3BB4C058012FAC847F000001 /* IMG.c */; };
    6.11  		BE1FA73607AF4C45004B6283 /* IMG_pcx.c in Sources */ = {isa = PBXBuildFile; fileRef = 3BB4C05C012FAC847F000001 /* IMG_pcx.c */; };
    6.12 @@ -27,23 +27,16 @@
    6.13  			isa = PBXContainerItemProxy;
    6.14  			containerPortal = 00A06D6A12FFBF9F009F1A11 /* SDLiPhoneOS.xcodeproj */;
    6.15  			proxyType = 2;
    6.16 -			remoteGlobalIDString = FD6526630DE8FCCB002AD96B /* libSDL.a */;
    6.17 +			remoteGlobalIDString = FD6526630DE8FCCB002AD96B;
    6.18  			remoteInfo = libSDL;
    6.19  		};
    6.20  		00A06D7412FFBF9F009F1A11 /* PBXContainerItemProxy */ = {
    6.21  			isa = PBXContainerItemProxy;
    6.22  			containerPortal = 00A06D6A12FFBF9F009F1A11 /* SDLiPhoneOS.xcodeproj */;
    6.23  			proxyType = 2;
    6.24 -			remoteGlobalIDString = 006E982211955059001DE610 /* testsdl.app */;
    6.25 +			remoteGlobalIDString = 006E982211955059001DE610;
    6.26  			remoteInfo = testsdl;
    6.27  		};
    6.28 -		00A06D7612FFBFB4009F1A11 /* PBXContainerItemProxy */ = {
    6.29 -			isa = PBXContainerItemProxy;
    6.30 -			containerPortal = 00A06D6A12FFBF9F009F1A11 /* SDLiPhoneOS.xcodeproj */;
    6.31 -			proxyType = 1;
    6.32 -			remoteGlobalIDString = 0064653F107E3D7400183915 /* Generate Header Files */;
    6.33 -			remoteInfo = "Generate Header Files";
    6.34 -		};
    6.35  /* End PBXContainerItemProxy section */
    6.36  
    6.37  /* Begin PBXFileReference section */
    6.38 @@ -51,7 +44,7 @@
    6.39  		007288A60F0DA79800C302A9 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; };
    6.40  		00728B3F0F0E008100C302A9 /* IMG_UIImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IMG_UIImage.m; path = ../IMG_UIImage.m; sourceTree = SOURCE_ROOT; };
    6.41  		00A06D6A12FFBF9F009F1A11 /* SDLiPhoneOS.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDLiPhoneOS.xcodeproj; path = "../../SDL/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj"; sourceTree = SOURCE_ROOT; };
    6.42 -		00A624FD12F4E99800577F68 /* IMG_ImageIO.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = IMG_ImageIO.c; path = ../IMG_ImageIO.c; sourceTree = SOURCE_ROOT; };
    6.43 +		00A624FD12F4E99800577F68 /* IMG_ImageIO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IMG_ImageIO.m; path = ../IMG_ImageIO.m; sourceTree = SOURCE_ROOT; };
    6.44  		00A625CE12F544F400577F68 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
    6.45  		1014BAEA010A4B677F000001 /* SDL_image.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_image.h; path = ../SDL_image.h; sourceTree = SOURCE_ROOT; };
    6.46  		3BB4C058012FAC847F000001 /* IMG.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = IMG.c; path = ../IMG.c; sourceTree = SOURCE_ROOT; };
    6.47 @@ -136,7 +129,7 @@
    6.48  		08FB77ACFE841707C02AAC07 /* Library Source */ = {
    6.49  			isa = PBXGroup;
    6.50  			children = (
    6.51 -				00A624FD12F4E99800577F68 /* IMG_ImageIO.c */,
    6.52 +				00A624FD12F4E99800577F68 /* IMG_ImageIO.m */,
    6.53  				3BB4C058012FAC847F000001 /* IMG.c */,
    6.54  				3BB4C059012FAC847F000001 /* IMG_bmp.c */,
    6.55  				3BB4C05A012FAC847F000001 /* IMG_gif.c */,
    6.56 @@ -218,7 +211,6 @@
    6.57  			buildRules = (
    6.58  			);
    6.59  			dependencies = (
    6.60 -				00A06D7712FFBFB4009F1A11 /* PBXTargetDependency */,
    6.61  			);
    6.62  			name = libSDL_image;
    6.63  			productInstallPath = /usr/local/lib;
    6.64 @@ -298,20 +290,12 @@
    6.65  				BE1FA73E07AF4C45004B6283 /* IMG_xxx.c in Sources */,
    6.66  				005DF5E90A140CA2006B0BD5 /* IMG_xv.c in Sources */,
    6.67  				00728B2A0F0E004C00C302A9 /* IMG_tga.c in Sources */,
    6.68 -				00A6250312F4E9CC00577F68 /* IMG_ImageIO.c in Sources */,
    6.69 +				00A6250312F4E9CC00577F68 /* IMG_ImageIO.m in Sources */,
    6.70  			);
    6.71  			runOnlyForDeploymentPostprocessing = 0;
    6.72  		};
    6.73  /* End PBXSourcesBuildPhase section */
    6.74  
    6.75 -/* Begin PBXTargetDependency section */
    6.76 -		00A06D7712FFBFB4009F1A11 /* PBXTargetDependency */ = {
    6.77 -			isa = PBXTargetDependency;
    6.78 -			name = "Generate Header Files";
    6.79 -			targetProxy = 00A06D7612FFBFB4009F1A11 /* PBXContainerItemProxy */;
    6.80 -		};
    6.81 -/* End PBXTargetDependency section */
    6.82 -
    6.83  /* Begin XCBuildConfiguration section */
    6.84  		007288110F0DA5BA00C302A9 /* Debug */ = {
    6.85  			isa = XCBuildConfiguration;
     7.1 --- a/configure.in	Fri Dec 30 15:57:44 2011 -0500
     7.2 +++ b/configure.in	Fri Dec 30 16:14:00 2011 -0500
     7.3 @@ -47,6 +47,7 @@
     7.4  dnl Check for tools
     7.5  AC_PROG_LIBTOOL
     7.6  AC_PROG_CC
     7.7 +AC_PROG_OBJC
     7.8  AC_C_INLINE
     7.9  AC_PROG_INSTALL
    7.10  AC_PROG_MAKE_SET
    7.11 @@ -370,6 +371,8 @@
    7.12  AC_SUBST([WINDRES])
    7.13  AC_SUBST([IMG_LIBS])
    7.14  
    7.15 +OBJCFLAGS=$CFLAGS
    7.16 +
    7.17  # Finally create all the generated files
    7.18  AC_OUTPUT([
    7.19  Makefile