5 * Created by Eric Wing on 1/1/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
10 #if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND)
12 #include "SDL_image.h"
14 // Used because CGDataProviderCreate became deprecated in 10.5
15 #include <AvailabilityMacros.h>
16 #include <TargetConditionals.h>
17 #include <Foundation/Foundation.h>
19 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
20 #ifdef ALLOW_UIIMAGE_FALLBACK
21 #define USE_UIIMAGE_BACKEND() ([UIImage instancesRespondToSelector:@selector(initWithCGImage:scale:orientation:)] == NO)
23 #define USE_UIIMAGE_BACKEND() (Internal_checkImageIOisAvailable())
25 #import <MobileCoreServices/MobileCoreServices.h> // for UTCoreTypes.h
26 #import <ImageIO/ImageIO.h>
27 #import <UIKit/UIImage.h>
29 // For ImageIO framework and also LaunchServices framework (for UTIs)
30 #include <ApplicationServices/ApplicationServices.h>
33 /**************************************************************
34 ***** Begin Callback functions for block reading *************
35 **************************************************************/
37 // This callback reads some bytes from an SDL_rwops and copies it
38 // to a Quartz buffer (supplied by Apple framework).
39 static size_t MyProviderGetBytesCallback(void* rwops_userdata, void* quartz_buffer, size_t the_count)
41 return (size_t)SDL_RWread((struct SDL_RWops *)rwops_userdata, quartz_buffer, 1, the_count);
44 // This callback is triggered when the data provider is released
45 // so you can clean up any resources.
46 static void MyProviderReleaseInfoCallback(void* rwops_userdata)
48 // What should I put here?
49 // I think the user and SDL_RWops controls closing, so I don't do anything.
52 static void MyProviderRewindCallback(void* rwops_userdata)
54 SDL_RWseek((struct SDL_RWops *)rwops_userdata, 0, RW_SEEK_SET);
57 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
58 off_t MyProviderSkipForwardBytesCallback(void* rwops_userdata, off_t the_count)
60 off_t start_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
61 SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
62 off_t end_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
63 return (end_position - start_position);
65 #else // CGDataProviderCreate was deprecated in 10.5
66 static void MyProviderSkipBytesCallback(void* rwops_userdata, size_t the_count)
68 SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
72 /**************************************************************
73 ***** End Callback functions for block reading ***************
74 **************************************************************/
76 // This creates a CGImageSourceRef which is a handle to an image that can be used to examine information
77 // about the image or load the actual image data.
78 static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options)
80 CGImageSourceRef source_ref;
82 // Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams.
84 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
85 CGDataProviderSequentialCallbacks provider_callbacks =
88 MyProviderGetBytesCallback,
89 MyProviderSkipForwardBytesCallback,
90 MyProviderRewindCallback,
91 MyProviderReleaseInfoCallback
94 CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks);
97 #else // CGDataProviderCreate was deprecated in 10.5
99 CGDataProviderCallbacks provider_callbacks =
101 MyProviderGetBytesCallback,
102 MyProviderSkipBytesCallback,
103 MyProviderRewindCallback,
104 MyProviderReleaseInfoCallback
107 CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks);
109 // Get the CGImageSourceRef.
110 // The dictionary can be NULL or contain hints to help ImageIO figure out the image type.
111 source_ref = CGImageSourceCreateWithDataProvider(data_provider, hints_and_options);
112 CGDataProviderRelease(data_provider);
116 /* Create a CGImageSourceRef from a file. */
117 /* Remember to CFRelease the created source when done. */
118 static CGImageSourceRef CreateCGImageSourceFromFile(const char* the_path)
120 CFURLRef the_url = NULL;
121 CGImageSourceRef source_ref = NULL;
122 CFStringRef cf_string = NULL;
124 /* Create a CFString from a C string */
125 cf_string = CFStringCreateWithCString(NULL, the_path, kCFStringEncodingUTF8);
130 /* Create a CFURL from a CFString */
131 the_url = CFURLCreateWithFileSystemPath(NULL, cf_string, kCFURLPOSIXPathStyle, false);
133 /* Don't need the CFString any more (error or not) */
134 CFRelease(cf_string);
142 source_ref = CGImageSourceCreateWithURL(the_url, NULL);
143 /* Don't need the URL any more (error or not) */
149 static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source)
151 CGImageRef image_ref = NULL;
153 if(NULL == image_source)
158 // Get the first item in the image source (some image formats may
159 // contain multiple items).
160 image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
161 if(NULL == image_ref)
163 IMG_SetError("CGImageSourceCreateImageAtIndex() failed");
168 static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
170 CFDictionaryRef hint_dictionary = NULL;
172 if(uti_string_hint != NULL)
174 // Do a bunch of work to setup a CFDictionary containing the jpeg compression properties.
175 CFStringRef the_keys[1];
176 CFStringRef the_values[1];
178 the_keys[0] = kCGImageSourceTypeIdentifierHint;
179 the_values[0] = uti_string_hint;
181 // kCFTypeDictionaryKeyCallBacks or kCFCopyStringDictionaryKeyCallBacks?
182 hint_dictionary = CFDictionaryCreate(NULL, (const void**)&the_keys, (const void**)&the_values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
184 return hint_dictionary;
187 // Once we have our image, we need to get it into an SDL_Surface
188 static SDL_Surface* Create_SDL_Surface_From_CGImage_RGB(CGImageRef image_ref)
190 /* This code is adapted from Apple's Documentation found here:
191 * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
192 * Listing 9-4††Using a Quartz image as a texture source.
193 * Unfortunately, this guide doesn't show what to do about
194 * non-RGBA image formats so I'm making the rest up.
195 * All this code should be scrutinized.
198 size_t w = CGImageGetWidth(image_ref);
199 size_t h = CGImageGetHeight(image_ref);
200 CGRect rect = {{0, 0}, {w, h}};
202 CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
203 //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
204 size_t bits_per_component = 8;
206 SDL_Surface* surface;
212 CGContextRef bitmap_context;
213 CGBitmapInfo bitmap_info;
215 /* This sets up a color space that results in identical values
216 * as the image data itself, which is the same as the standalone
218 * Thanks to Allegro. :)
220 CGFloat whitePoint[3] = { 0.950, 1.000, 1.089 };
221 CGFloat blackPoint[3] = { 0.000, 0.000, 0.000 };
222 CGFloat gamma[3] = { 2.2, 2.2, 2.2 };
223 CGFloat matrix[9] = {
228 CGColorSpaceRef color_space =
229 CGColorSpaceCreateCalibratedRGB(
230 whitePoint, blackPoint, gamma, matrix
233 if (alpha == kCGImageAlphaNone ||
234 alpha == kCGImageAlphaNoneSkipFirst ||
235 alpha == kCGImageAlphaNoneSkipLast) {
236 bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
239 /* kCGImageAlphaFirst isn't supported */
240 //bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
241 bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
249 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
252 // Sets up a context to be drawn to with surface->pixels as the area to be drawn to
253 bitmap_context = CGBitmapContextCreate(
263 // Draws the image into the context's image_data
264 CGContextDrawImage(bitmap_context, rect, image_ref);
266 CGContextRelease(bitmap_context);
268 // FIXME: Reverse the premultiplied alpha
269 if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
271 Uint8 *p = (Uint8 *)surface->pixels;
272 for (i = surface->h * surface->pitch/4; i--; ) {
273 #if __LITTLE_ENDIAN__
276 for (j = 0; j < 3; ++j) {
277 p[j] = (p[j] * 255) / A;
283 for (j = 1; j < 4; ++j) {
284 p[j] = (p[j] * 255) / A;
295 CGColorSpaceRelease(color_space);
300 static SDL_Surface* Create_SDL_Surface_From_CGImage_Index(CGImageRef image_ref)
302 size_t w = CGImageGetWidth(image_ref);
303 size_t h = CGImageGetHeight(image_ref);
304 size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
305 size_t bytes_per_row = CGImageGetBytesPerRow(image_ref);
307 SDL_Surface* surface;
308 SDL_Palette* palette;
309 CGColorSpaceRef color_space = CGImageGetColorSpace(image_ref);
310 CGColorSpaceRef base_color_space = CGColorSpaceGetBaseColorSpace(color_space);
311 size_t num_components = CGColorSpaceGetNumberOfComponents(base_color_space);
312 size_t num_entries = CGColorSpaceGetColorTableCount(color_space);
313 uint8_t *entry, entries[num_components * num_entries];
315 /* What do we do if it's not RGB? */
316 if (num_components != 3) {
317 SDL_SetError("Unknown colorspace components %lu", num_components);
320 if (bits_per_pixel != 8) {
321 SDL_SetError("Unknown bits_per_pixel %lu", bits_per_pixel);
325 CGColorSpaceGetColorTable(color_space, entries);
326 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, bits_per_pixel, 0, 0, 0, 0);
328 uint8_t* pixels = (uint8_t*)surface->pixels;
329 CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
330 NSData* data = (id)CGDataProviderCopyData(provider);
332 const uint8_t* bytes = [data bytes];
335 palette = surface->format->palette;
336 for (i = 0, entry = entries; i < num_entries; ++i) {
337 palette->colors[i].r = entry[0];
338 palette->colors[i].g = entry[1];
339 palette->colors[i].b = entry[2];
340 entry += num_components;
343 for (i = 0; i < h; ++i) {
344 SDL_memcpy(pixels, bytes, w);
345 pixels += surface->pitch;
346 bytes += bytes_per_row;
351 static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
353 CGColorSpaceRef color_space = CGImageGetColorSpace(image_ref);
354 if (CGColorSpaceGetModel(color_space) == kCGColorSpaceModelIndexed) {
355 return Create_SDL_Surface_From_CGImage_Index(image_ref);
357 return Create_SDL_Surface_From_CGImage_RGB(image_ref);
363 #pragma mark IMG_Init stubs
364 #if !defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
365 static int Internal_checkImageIOisAvailable() {
366 // just check if we are running on ios 4 or more, else throw exception
367 if ([UIImage instancesRespondToSelector:@selector(initWithCGImage:scale:orientation:)])
369 [NSException raise:@"UIImage fallback not enabled at compile time"
370 format:@"ImageIO is not available on your platform, please recompile SDL_Image with ALLOW_UIIMAGE_FALLBACK."];
403 #pragma mark Get type of image
404 static int Internal_isType_UIImage (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
408 #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
409 int start = SDL_RWtell(rw_ops);
410 if ((0 == CFStringCompare(uti_string_to_test, kUTTypeICO, 0)) ||
411 (0 == CFStringCompare(uti_string_to_test, CFSTR("com.microsoft.cur"), 0))) {
413 // The Win32 ICO file header (14 bytes)
417 int type = (0 == CFStringCompare(uti_string_to_test, kUTTypeICO, 0)) ? 1 : 2;
419 bfReserved = SDL_ReadLE16(rw_ops);
420 bfType = SDL_ReadLE16(rw_ops);
421 bfCount = SDL_ReadLE16(rw_ops);
422 if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
424 } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeBMP, 0)) {
427 if ( SDL_RWread(rw_ops, magic, sizeof(magic), 1) ) {
428 if ( strncmp(magic, "BM", 2) == 0 ) {
432 } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeGIF, 0)) {
435 if ( SDL_RWread(rw_ops, magic, sizeof(magic), 1) ) {
436 if ( (strncmp(magic, "GIF", 3) == 0) &&
437 ((memcmp(magic + 3, "87a", 3) == 0) ||
438 (memcmp(magic + 3, "89a", 3) == 0)) ) {
442 } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeJPEG, 0)) {
446 // This detection code is by Steaphan Greene <stea@cs.binghamton.edu>
447 // Blame me, not Sam, if this doesn't work right. */
448 // And don't forget to report the problem to the the sdl list too! */
450 if ( SDL_RWread(rw_ops, magic, 2, 1) ) {
451 if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
453 while (is_type == 1) {
454 if(SDL_RWread(rw_ops, magic, 1, 2) != 2) {
456 } else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
458 } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
459 /* Extra padding in JPEG (legal) */
460 /* or this is data and we are scanning */
461 SDL_RWseek(rw_ops, -1, SEEK_CUR);
462 } else if(magic[1] == 0xD9) {
463 /* Got to end of good JPEG */
465 } else if( (in_scan == 1) && (magic[1] == 0x00) ) {
466 /* This is an encoded 0xFF within the data */
467 } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
468 /* These have nothing else */
469 } else if(SDL_RWread(rw_ops, magic+2, 1, 2) != 2) {
472 /* Yes, it's big-endian */
476 start = SDL_RWtell(rw_ops);
477 size = (magic[2] << 8) + magic[3];
478 end = SDL_RWseek(rw_ops, size-2, SEEK_CUR);
479 if ( end != start + size - 2 ) is_type = 0;
480 if ( magic[1] == 0xDA ) {
481 /* Now comes the actual JPEG meat */
483 /* Ok, I'm convinced. It is a JPEG. */
486 /* I'm not convinced. Prove it! */
494 } else if (0 == CFStringCompare(uti_string_to_test, kUTTypePNG, 0)) {
497 if ( SDL_RWread(rw_ops, magic, 1, sizeof(magic)) == sizeof(magic) ) {
498 if ( magic[0] == 0x89 &&
505 } else if (0 == CFStringCompare(uti_string_to_test, CFSTR("com.truevision.tga-image"), 0)) {
507 } else if (0 == CFStringCompare(uti_string_to_test, kUTTypeTIFF, 0)) {
510 if ( SDL_RWread(rw_ops, magic, 1, sizeof(magic)) == sizeof(magic) ) {
511 if ( (magic[0] == 'I' &&
518 magic[3] == 0x2a) ) {
524 // reset the file descption pointer
525 SDL_RWseek(rw_ops, start, SEEK_SET);
527 #endif /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
531 static int Internal_isType_ImageIO (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
535 CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_to_test);
536 CGImageSourceRef image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
538 if (hint_dictionary != NULL) {
539 CFRelease(hint_dictionary);
542 if (NULL == image_source) {
546 // This will get the UTI of the container, not the image itself.
547 // Under most cases, this won't be a problem.
548 // But if a person passes an icon file which contains a bmp,
549 // the format will be of the icon file.
550 // But I think the main SDL_image codebase has this same problem so I'm not going to worry about it.
551 CFStringRef uti_type = CGImageSourceGetType(image_source);
554 // Unsure if we really want conformance or equality
555 is_type = (int)UTTypeConformsTo(uti_string_to_test, uti_type);
557 CFRelease(image_source);
561 static int Internal_isType (SDL_RWops *rw_ops, CFStringRef uti_string_to_test)
566 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
567 if (USE_UIIMAGE_BACKEND())
568 return Internal_isType_UIImage(rw_ops, uti_string_to_test);
571 return Internal_isType_ImageIO(rw_ops, uti_string_to_test);
574 #ifdef BMP_USES_IMAGEIO
576 int IMG_isCUR(SDL_RWops *src)
578 /* FIXME: Is this a supported type? */
579 return Internal_isType(src, CFSTR("com.microsoft.cur"));
582 int IMG_isICO(SDL_RWops *src)
584 return Internal_isType(src, kUTTypeICO);
587 int IMG_isBMP(SDL_RWops *src)
589 return Internal_isType(src, kUTTypeBMP);
592 #endif /* BMP_USES_IMAGEIO */
594 int IMG_isGIF(SDL_RWops *src)
596 return Internal_isType(src, kUTTypeGIF);
599 // Note: JPEG 2000 is kUTTypeJPEG2000
600 int IMG_isJPG(SDL_RWops *src)
602 return Internal_isType(src, kUTTypeJPEG);
605 int IMG_isPNG(SDL_RWops *src)
607 return Internal_isType(src, kUTTypePNG);
610 // This isn't a public API function. Apple seems to be able to identify tga's.
611 int IMG_isTGA(SDL_RWops *src)
613 return Internal_isType(src, CFSTR("com.truevision.tga-image"));
616 int IMG_isTIF(SDL_RWops *src)
618 return Internal_isType(src, kUTTypeTIFF);
622 #pragma mark Load image engine
623 static SDL_Surface *LoadImageFromRWops_UIImage (SDL_RWops* rw_ops, CFStringRef uti_string_hint)
625 SDL_Surface *sdl_surface = NULL;
627 #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
628 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
631 // I don't know what a good size is.
632 // Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
633 const int block_size = 1024*4;
634 char temp_buffer[block_size];
636 NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
638 bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
639 [ns_data appendBytes:temp_buffer length:bytes_read];
640 } while (bytes_read > 0);
642 ui_image = [[UIImage alloc] initWithData:ns_data];
644 sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
647 [autorelease_pool drain];
649 #endif /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
653 static SDL_Surface *LoadImageFromRWops_ImageIO (SDL_RWops *rw_ops, CFStringRef uti_string_hint)
655 CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_hint);
656 CGImageSourceRef image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
658 if (hint_dictionary != NULL)
659 CFRelease(hint_dictionary);
661 if (NULL == image_source)
664 CGImageRef image_ref = CreateCGImageFromCGImageSource(image_source);
665 CFRelease(image_source);
667 if (NULL == image_ref)
669 SDL_Surface *sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
670 CFRelease(image_ref);
675 static SDL_Surface *LoadImageFromRWops (SDL_RWops *rw_ops, CFStringRef uti_string_hint)
677 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
678 if (USE_UIIMAGE_BACKEND())
679 return LoadImageFromRWops_UIImage(rw_ops, uti_string_hint);
682 return LoadImageFromRWops_ImageIO(rw_ops, uti_string_hint);
685 static SDL_Surface* LoadImageFromFile_UIImage (const char *file)
687 SDL_Surface *sdl_surface = NULL;
689 #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1))
690 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
691 NSString *ns_string = [[NSString alloc] initWithUTF8String:file];
692 UIImage *ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
694 sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
697 [autorelease_pool drain];
699 #endif /* #if defined(ALLOW_UIIMAGE_FALLBACK) && ((TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)) */
703 static SDL_Surface* LoadImageFromFile_ImageIO (const char *file)
705 CGImageSourceRef image_source = NULL;
707 image_source = CreateCGImageSourceFromFile(file);
709 if(NULL == image_source)
712 CGImageRef image_ref = CreateCGImageFromCGImageSource(image_source);
713 CFRelease(image_source);
715 if (NULL == image_ref)
717 SDL_Surface *sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
718 CFRelease(image_ref);
722 static SDL_Surface* LoadImageFromFile (const char *file)
724 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
725 if (USE_UIIMAGE_BACKEND())
726 return LoadImageFromFile_UIImage(file);
729 return LoadImageFromFile_ImageIO(file);
732 #ifdef BMP_USES_IMAGEIO
734 SDL_Surface* IMG_LoadCUR_RW (SDL_RWops *src)
736 /* FIXME: Is this a supported type? */
737 return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
740 SDL_Surface* IMG_LoadICO_RW (SDL_RWops *src)
742 return LoadImageFromRWops(src, kUTTypeICO);
745 SDL_Surface* IMG_LoadBMP_RW (SDL_RWops *src)
747 return LoadImageFromRWops(src, kUTTypeBMP);
750 #endif /* BMP_USES_IMAGEIO */
752 SDL_Surface* IMG_LoadGIF_RW (SDL_RWops *src)
754 return LoadImageFromRWops (src, kUTTypeGIF);
757 SDL_Surface* IMG_LoadJPG_RW (SDL_RWops *src)
759 return LoadImageFromRWops (src, kUTTypeJPEG);
762 SDL_Surface* IMG_LoadPNG_RW (SDL_RWops *src)
764 return LoadImageFromRWops (src, kUTTypePNG);
767 SDL_Surface* IMG_LoadTGA_RW (SDL_RWops *src)
769 return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
772 SDL_Surface* IMG_LoadTIF_RW (SDL_RWops *src)
774 return LoadImageFromRWops(src, kUTTypeTIFF);
777 // Since UIImage doesn't really support streams well, we should optimize for the file case.
778 // Apple provides both stream and file loading functions in ImageIO.
779 // Potentially, Apple can optimize for either case.
780 SDL_Surface* IMG_Load (const char *file)
782 SDL_Surface* sdl_surface = NULL;
784 sdl_surface = LoadImageFromFile(file);
785 if(NULL == sdl_surface)
787 // Either the file doesn't exist or ImageIO doesn't understand the format.
788 // For the latter case, fallback to the native SDL_image handlers.
789 SDL_RWops *src = SDL_RWFromFile(file, "rb");
790 char *ext = strrchr(file, '.');
795 /* The error message has been set in SDL_RWFromFile */
798 sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
803 #endif /* defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) */