IMG_UIImage.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Nov 2009 15:53:24 +0000
changeset 233 fd5471011130
parent 219 de70ba5fc166
child 237 d1a4fae44bd0
permissions -rw-r--r--
Sam Lantinga - Sun Nov 8 07:52:11 PST 2009
* Fixed checking for IMG_Init() return value in image loaders
slouken@187
     1
/*
slouken@187
     2
 *  IMG_ImageIO.c
slouken@187
     3
 *  SDL_image
slouken@187
     4
 *
slouken@187
     5
 *  Created by Eric Wing on 1/2/09.
slouken@187
     6
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
slouken@187
     7
 *
slouken@187
     8
 */
slouken@187
     9
#include "SDL_image.h"
slouken@187
    10
#import <UIKit/UIKit.h>
slouken@219
    11
#import <MobileCoreServices/MobileCoreServices.h> // for UTCoreTypes.h
slouken@187
    12
slouken@187
    13
// Once we have our image, we need to get it into an SDL_Surface
slouken@187
    14
// (Copied straight from the ImageIO backend.)
slouken@187
    15
static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
slouken@187
    16
{
slouken@187
    17
	/* This code is adapted from Apple's Documentation found here:
slouken@187
    18
	 * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
slouken@187
    19
	 * Listing 9-4††Using a Quartz image as a texture source.
slouken@187
    20
	 * Unfortunately, this guide doesn't show what to do about
slouken@187
    21
	 * non-RGBA image formats so I'm making the rest up.
slouken@187
    22
	 * All this code should be scrutinized.
slouken@187
    23
	 */
slouken@187
    24
	
slouken@187
    25
	size_t the_width = CGImageGetWidth(image_ref);
slouken@187
    26
	size_t the_height = CGImageGetHeight(image_ref);
slouken@187
    27
	CGRect the_rect = {{0, 0}, {the_width, the_height}};
slouken@187
    28
	
slouken@187
    29
	size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
slouken@187
    30
	size_t bytes_per_row = CGImageGetBytesPerRow(image_ref);
slouken@187
    31
	//	size_t bits_per_component = CGImageGetBitsPerComponent(image_ref);
slouken@187
    32
	size_t bits_per_component = 8;
slouken@187
    33
	
slouken@187
    34
//	CGImageAlphaInfo alpha_info = CGImageGetAlphaInfo(image_ref);
slouken@187
    35
	
slouken@187
    36
slouken@187
    37
	SDL_Surface* sdl_surface = NULL;
slouken@187
    38
	Uint32 Rmask;
slouken@187
    39
	Uint32 Gmask;
slouken@187
    40
	Uint32 Bmask;
slouken@187
    41
	Uint32 Amask;
slouken@187
    42
slouken@187
    43
	
slouken@187
    44
	CGContextRef bitmap_context = NULL;
slouken@187
    45
	
slouken@187
    46
	CGColorSpaceRef color_space = NULL;
slouken@187
    47
	CGBitmapInfo bitmap_info = CGImageGetBitmapInfo(image_ref);
slouken@187
    48
slouken@187
    49
	
slouken@187
    50
	switch(bits_per_pixel)
slouken@187
    51
	{
slouken@187
    52
		case 8:
slouken@187
    53
		{
slouken@187
    54
			bytes_per_row = the_width*4;
slouken@187
    55
			//				color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
slouken@187
    56
			color_space = CGColorSpaceCreateDeviceRGB();
slouken@187
    57
			//				bitmap_info = kCGImageAlphaPremultipliedFirst;
slouken@187
    58
#if __BIG_ENDIAN__
slouken@187
    59
			bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big; /* XRGB Big Endian */
slouken@187
    60
#else
slouken@187
    61
			bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little; /* XRGB Little Endian */
slouken@187
    62
#endif
slouken@187
    63
slouken@187
    64
			Rmask = 0x00FF0000;
slouken@187
    65
			Gmask = 0x0000FF00;
slouken@187
    66
			Bmask = 0x000000FF;
slouken@187
    67
			Amask = 0x00000000;
slouken@187
    68
slouken@187
    69
			sdl_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
slouken@187
    70
											   the_width, the_height, 32, Rmask, Gmask, Bmask, Amask);
slouken@187
    71
slouken@187
    72
slouken@187
    73
			
slouken@187
    74
			break;
slouken@187
    75
		}
slouken@187
    76
		case 15:
slouken@187
    77
		case 16:
slouken@187
    78
		{
slouken@187
    79
			bytes_per_row = the_width*4;
slouken@187
    80
slouken@187
    81
			color_space = CGColorSpaceCreateDeviceRGB();
slouken@187
    82
slouken@187
    83
#if __BIG_ENDIAN__
slouken@187
    84
			bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big; /* XRGB Big Endian */
slouken@187
    85
#else
slouken@187
    86
			bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little; /* XRGB Little Endian */
slouken@187
    87
#endif
slouken@187
    88
			Rmask = 0x00FF0000;
slouken@187
    89
			Gmask = 0x0000FF00;
slouken@187
    90
			Bmask = 0x000000FF;
slouken@187
    91
			Amask = 0x00000000;
slouken@187
    92
slouken@187
    93
slouken@187
    94
			sdl_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
slouken@187
    95
											   the_width, the_height, 32, Rmask, Gmask, Bmask, Amask);
slouken@187
    96
slouken@187
    97
			break;
slouken@187
    98
		}
slouken@187
    99
		case 24:
slouken@187
   100
		{
slouken@187
   101
			bytes_per_row = the_width*4;
slouken@187
   102
			//			color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
slouken@187
   103
			color_space = CGColorSpaceCreateDeviceRGB();
slouken@187
   104
			//			bitmap_info = kCGImageAlphaNone;
slouken@187
   105
#if __BIG_ENDIAN__
slouken@187
   106
			bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big; /* XRGB Big Endian */
slouken@187
   107
#else
slouken@187
   108
			bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little; /* XRGB Little Endian */
slouken@187
   109
#endif
slouken@187
   110
			Rmask = 0x00FF0000;
slouken@187
   111
			Gmask = 0x0000FF00;
slouken@187
   112
			Bmask = 0x000000FF;
slouken@187
   113
			Amask = 0x00000000;
slouken@187
   114
slouken@187
   115
			sdl_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
slouken@187
   116
											   the_width, the_height, 32, Rmask, Gmask, Bmask, Amask);
slouken@187
   117
slouken@187
   118
			break;
slouken@187
   119
		}
slouken@187
   120
		case 32:
slouken@187
   121
		{
slouken@187
   122
						
slouken@187
   123
			bytes_per_row = the_width*4;
slouken@187
   124
			//			color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
slouken@187
   125
			color_space = CGColorSpaceCreateDeviceRGB();
slouken@187
   126
			//			bitmap_info = kCGImageAlphaPremultipliedFirst;
slouken@187
   127
#if __BIG_ENDIAN__
slouken@187
   128
			bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big; /* XRGB Big Endian */
slouken@187
   129
#else
slouken@187
   130
			bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little; /* XRGB Little Endian */
slouken@187
   131
#endif 
slouken@187
   132
			Amask = 0xFF000000;
slouken@187
   133
			Rmask = 0x00FF0000;
slouken@187
   134
			Gmask = 0x0000FF00;
slouken@187
   135
			Bmask = 0x000000FF;
slouken@187
   136
slouken@187
   137
			sdl_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
slouken@187
   138
											   the_width, the_height, 32, Rmask, Gmask, Bmask, Amask);
slouken@187
   139
			break;
slouken@187
   140
		}
slouken@187
   141
		default:
slouken@187
   142
		{
slouken@187
   143
            sdl_surface = NULL;
slouken@187
   144
            break;
slouken@187
   145
		}
slouken@187
   146
			
slouken@187
   147
	}
slouken@187
   148
slouken@187
   149
	if(NULL == sdl_surface)
slouken@187
   150
	{
slouken@187
   151
		if(color_space != NULL)
slouken@187
   152
		{
slouken@187
   153
			CGColorSpaceRelease(color_space);			
slouken@187
   154
		}
slouken@187
   155
		return NULL;
slouken@187
   156
	}
slouken@187
   157
slouken@187
   158
slouken@187
   159
	// Sets up a context to be drawn to with sdl_surface->pixels as the area to be drawn to
slouken@187
   160
	bitmap_context = CGBitmapContextCreate(
slouken@187
   161
														sdl_surface->pixels,
slouken@187
   162
														the_width,
slouken@187
   163
														the_height,
slouken@187
   164
														bits_per_component,
slouken@187
   165
														bytes_per_row,
slouken@187
   166
														color_space,
slouken@187
   167
														bitmap_info
slouken@187
   168
														);
slouken@187
   169
	
slouken@187
   170
	// Draws the image into the context's image_data
slouken@187
   171
	CGContextDrawImage(bitmap_context, the_rect, image_ref);
slouken@187
   172
	
slouken@187
   173
	CGContextRelease(bitmap_context);
slouken@187
   174
	CGColorSpaceRelease(color_space);
slouken@187
   175
	
slouken@187
   176
	return sdl_surface;
slouken@187
   177
	
slouken@187
   178
	
slouken@187
   179
	
slouken@187
   180
}
slouken@187
   181
slouken@187
   182
static SDL_Surface* LoadImageFromRWops(SDL_RWops* rw_ops, CFStringRef uti_string_hint)
slouken@187
   183
{
slouken@187
   184
	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
slouken@187
   185
	SDL_Surface* sdl_surface;
slouken@187
   186
	UIImage* ui_image;
slouken@187
   187
slouken@187
   188
	CGImageRef image_ref = NULL;
slouken@187
   189
	int bytes_read = 0;
slouken@187
   190
	// I don't know what a good size is. 
slouken@187
   191
	// Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
slouken@187
   192
	const int block_size = 1024*4;
slouken@187
   193
	char temp_buffer[block_size];
slouken@187
   194
	
slouken@187
   195
	NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
slouken@187
   196
slouken@187
   197
	
slouken@187
   198
	do
slouken@187
   199
	{
slouken@187
   200
		bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
slouken@187
   201
		[ns_data appendBytes:temp_buffer length:bytes_read];
slouken@187
   202
	} while(bytes_read > 0);
slouken@187
   203
slouken@187
   204
	if(NULL == image_ref)
slouken@187
   205
	{
slouken@187
   206
		return NULL;
slouken@187
   207
	}
slouken@187
   208
slouken@187
   209
	ui_image = [[UIImage alloc] initWithData:ns_data];
slouken@187
   210
	
slouken@187
   211
	sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
slouken@187
   212
slouken@187
   213
	[ui_image release];
slouken@187
   214
	[ns_data release];
slouken@187
   215
slouken@187
   216
	[autorelease_pool drain];
slouken@187
   217
slouken@187
   218
	return sdl_surface;
slouken@187
   219
}
slouken@187
   220
slouken@188
   221
static SDL_Surface* LoadImageFromFile(const char *file)
slouken@187
   222
{
slouken@187
   223
	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
slouken@187
   224
	SDL_Surface* sdl_surface = NULL;
slouken@187
   225
	UIImage* ui_image;
slouken@187
   226
	NSString* ns_string;
slouken@187
   227
	
slouken@187
   228
	ns_string = [[NSString alloc] initWithUTF8String:file];
slouken@187
   229
	ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
slouken@188
   230
	
slouken@187
   231
	sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
slouken@188
   232
	
slouken@187
   233
	[ui_image release];
slouken@187
   234
	[ns_string release];
slouken@187
   235
	
slouken@187
   236
	[autorelease_pool drain];
slouken@188
   237
	
slouken@188
   238
	return sdl_surface;
slouken@188
   239
}
slouken@187
   240
slouken@188
   241
slouken@188
   242
/* Since UIImage doesn't really support streams well, we should optimize for the file case. */
slouken@188
   243
SDL_Surface *IMG_Load(const char *file)
slouken@188
   244
{
slouken@188
   245
	SDL_Surface* sdl_surface = NULL;
slouken@188
   246
slouken@188
   247
	sdl_surface = LoadImageFromFile(file);
slouken@188
   248
	if(NULL == sdl_surface)
slouken@188
   249
	{
slouken@188
   250
		// Either the file doesn't exist or ImageIO doesn't understand the format.
slouken@188
   251
		// For the latter case, fallback to the native SDL_image handlers.
slouken@188
   252
slouken@188
   253
		SDL_RWops *src = SDL_RWFromFile(file, "rb");
slouken@188
   254
		char *ext = strrchr(file, '.');
slouken@188
   255
		if(ext) {
slouken@188
   256
			ext++;
slouken@188
   257
		}
slouken@188
   258
		if(!src) {
slouken@188
   259
			/* The error message has been set in SDL_RWFromFile */
slouken@188
   260
			return NULL;
slouken@188
   261
		}
slouken@188
   262
		sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
slouken@188
   263
	}
slouken@187
   264
	return sdl_surface;
slouken@187
   265
}
slouken@187
   266
slouken@187
   267
slouken@233
   268
int IMG_InitJPG()
slouken@233
   269
{
slouken@233
   270
	return 0;
slouken@233
   271
}
slouken@233
   272
slouken@233
   273
void IMG_QuitJPG()
slouken@233
   274
{
slouken@233
   275
}
slouken@233
   276
slouken@233
   277
int IMG_InitPNG()
slouken@233
   278
{
slouken@233
   279
	return 0;
slouken@233
   280
}
slouken@233
   281
slouken@233
   282
void IMG_QuitPNG()
slouken@233
   283
{
slouken@233
   284
}
slouken@233
   285
slouken@233
   286
int IMG_InitTIF()
slouken@233
   287
{
slouken@233
   288
	return 0;
slouken@233
   289
}
slouken@233
   290
slouken@233
   291
void IMG_QuitTIF()
slouken@233
   292
{
slouken@233
   293
}
slouken@187
   294
slouken@187
   295
/* Copied straight from other files so I don't have to alter them. */
slouken@195
   296
static int IMG_isICOCUR(SDL_RWops *src, int type)
slouken@195
   297
{
slouken@195
   298
	int start;
slouken@195
   299
	int is_ICOCUR;
slouken@195
   300
slouken@195
   301
	/* The Win32 ICO file header (14 bytes) */
slouken@195
   302
    Uint16 bfReserved;
slouken@195
   303
    Uint16 bfType;
slouken@195
   304
    Uint16 bfCount;
slouken@195
   305
slouken@195
   306
	if ( !src )
slouken@195
   307
		return 0;
slouken@195
   308
	start = SDL_RWtell(src);
slouken@195
   309
	is_ICOCUR = 0;
slouken@195
   310
    bfReserved = SDL_ReadLE16(src);
slouken@195
   311
    bfType = SDL_ReadLE16(src);
slouken@195
   312
    bfCount = SDL_ReadLE16(src);
slouken@195
   313
    if ((bfReserved == 0) && (bfType == type) && (bfCount != 0)) 
slouken@195
   314
    	is_ICOCUR = 1;
slouken@195
   315
	SDL_RWseek(src, start, SEEK_SET);
slouken@195
   316
slouken@195
   317
	return (is_ICOCUR);
slouken@195
   318
}
slouken@195
   319
slouken@195
   320
int IMG_isICO(SDL_RWops *src)
slouken@195
   321
{
slouken@195
   322
	return IMG_isICOCUR(src, 1);
slouken@195
   323
}
slouken@195
   324
slouken@195
   325
int IMG_isCUR(SDL_RWops *src)
slouken@195
   326
{
slouken@195
   327
	return IMG_isICOCUR(src, 2);
slouken@195
   328
}
slouken@195
   329
slouken@187
   330
int IMG_isBMP(SDL_RWops *src)
slouken@187
   331
{
slouken@187
   332
	int start;
slouken@187
   333
	int is_BMP;
slouken@187
   334
	char magic[2];
slouken@187
   335
	
slouken@187
   336
	if ( !src )
slouken@187
   337
		return 0;
slouken@187
   338
	start = SDL_RWtell(src);
slouken@187
   339
	is_BMP = 0;
slouken@187
   340
	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
slouken@187
   341
		if ( strncmp(magic, "BM", 2) == 0 ) {
slouken@187
   342
			is_BMP = 1;
slouken@187
   343
		}
slouken@187
   344
	}
slouken@187
   345
	SDL_RWseek(src, start, SEEK_SET);
slouken@187
   346
	return(is_BMP);
slouken@187
   347
}
slouken@187
   348
slouken@187
   349
int IMG_isGIF(SDL_RWops *src)
slouken@187
   350
{
slouken@187
   351
	int start;
slouken@187
   352
	int is_GIF;
slouken@187
   353
	char magic[6];
slouken@187
   354
	
slouken@187
   355
	if ( !src )
slouken@187
   356
		return 0;
slouken@187
   357
	start = SDL_RWtell(src);
slouken@187
   358
	is_GIF = 0;
slouken@187
   359
	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
slouken@187
   360
		if ( (strncmp(magic, "GIF", 3) == 0) &&
slouken@187
   361
			((memcmp(magic + 3, "87a", 3) == 0) ||
slouken@187
   362
			 (memcmp(magic + 3, "89a", 3) == 0)) ) {
slouken@187
   363
			is_GIF = 1;
slouken@187
   364
		}
slouken@187
   365
	}
slouken@187
   366
	SDL_RWseek(src, start, SEEK_SET);
slouken@187
   367
	return(is_GIF);
slouken@187
   368
}
slouken@187
   369
slouken@187
   370
int IMG_isJPG(SDL_RWops *src)
slouken@187
   371
{
slouken@187
   372
	int start;
slouken@187
   373
	int is_JPG;
slouken@187
   374
	int in_scan;
slouken@187
   375
	Uint8 magic[4];
slouken@187
   376
	
slouken@187
   377
	/* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
slouken@187
   378
	/* Blame me, not Sam, if this doesn't work right. */
slouken@187
   379
	/* And don't forget to report the problem to the the sdl list too! */
slouken@187
   380
	
slouken@187
   381
	if ( !src )
slouken@187
   382
		return 0;
slouken@187
   383
	start = SDL_RWtell(src);
slouken@187
   384
	is_JPG = 0;
slouken@187
   385
	in_scan = 0;
slouken@187
   386
	if ( SDL_RWread(src, magic, 2, 1) ) {
slouken@187
   387
		if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
slouken@187
   388
			is_JPG = 1;
slouken@187
   389
			while (is_JPG == 1) {
slouken@187
   390
				if(SDL_RWread(src, magic, 1, 2) != 2) {
slouken@187
   391
					is_JPG = 0;
slouken@187
   392
				} else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
slouken@187
   393
					is_JPG = 0;
slouken@187
   394
				} else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
slouken@187
   395
					/* Extra padding in JPEG (legal) */
slouken@187
   396
					/* or this is data and we are scanning */
slouken@187
   397
					SDL_RWseek(src, -1, SEEK_CUR);
slouken@187
   398
				} else if(magic[1] == 0xD9) {
slouken@187
   399
					/* Got to end of good JPEG */
slouken@187
   400
					break;
slouken@187
   401
				} else if( (in_scan == 1) && (magic[1] == 0x00) ) {
slouken@187
   402
					/* This is an encoded 0xFF within the data */
slouken@187
   403
				} else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
slouken@187
   404
					/* These have nothing else */
slouken@187
   405
				} else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
slouken@187
   406
					is_JPG = 0;
slouken@187
   407
				} else {
slouken@187
   408
					/* Yes, it's big-endian */
slouken@187
   409
					Uint32 start;
slouken@187
   410
					Uint32 size;
slouken@187
   411
					Uint32 end;
slouken@187
   412
					start = SDL_RWtell(src);
slouken@187
   413
					size = (magic[2] << 8) + magic[3];
slouken@187
   414
					end = SDL_RWseek(src, size-2, SEEK_CUR);
slouken@187
   415
					if ( end != start + size - 2 ) is_JPG = 0;
slouken@187
   416
					if ( magic[1] == 0xDA ) {
slouken@187
   417
						/* Now comes the actual JPEG meat */
slouken@187
   418
#ifdef	FAST_IS_JPEG
slouken@187
   419
						/* Ok, I'm convinced.  It is a JPEG. */
slouken@187
   420
						break;
slouken@187
   421
#else
slouken@187
   422
						/* I'm not convinced.  Prove it! */
slouken@187
   423
						in_scan = 1;
slouken@187
   424
#endif
slouken@187
   425
					}
slouken@187
   426
				}
slouken@187
   427
			}
slouken@187
   428
		}
slouken@187
   429
	}
slouken@187
   430
	SDL_RWseek(src, start, SEEK_SET);
slouken@187
   431
	return(is_JPG);
slouken@187
   432
}
slouken@187
   433
slouken@187
   434
int IMG_isPNG(SDL_RWops *src)
slouken@187
   435
{
slouken@187
   436
	int start;
slouken@187
   437
	int is_PNG;
slouken@187
   438
	Uint8 magic[4];
slouken@187
   439
	
slouken@187
   440
	if ( !src )
slouken@187
   441
		return 0;
slouken@187
   442
	start = SDL_RWtell(src);
slouken@187
   443
	is_PNG = 0;
slouken@187
   444
	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
slouken@187
   445
		if ( magic[0] == 0x89 &&
slouken@187
   446
			magic[1] == 'P' &&
slouken@187
   447
			magic[2] == 'N' &&
slouken@187
   448
			magic[3] == 'G' ) {
slouken@187
   449
			is_PNG = 1;
slouken@187
   450
		}
slouken@187
   451
	}
slouken@187
   452
	SDL_RWseek(src, start, SEEK_SET);
slouken@187
   453
	return(is_PNG);
slouken@187
   454
}
slouken@187
   455
slouken@187
   456
int IMG_isTIF(SDL_RWops* src)
slouken@187
   457
{
slouken@187
   458
	int start;
slouken@187
   459
	int is_TIF;
slouken@187
   460
	Uint8 magic[4];
slouken@187
   461
	
slouken@187
   462
	if ( !src )
slouken@187
   463
		return 0;
slouken@187
   464
	start = SDL_RWtell(src);
slouken@187
   465
	is_TIF = 0;
slouken@187
   466
	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
slouken@187
   467
		if ( (magic[0] == 'I' &&
slouken@187
   468
			  magic[1] == 'I' &&
slouken@187
   469
		      magic[2] == 0x2a &&
slouken@187
   470
			  magic[3] == 0x00) ||
slouken@187
   471
			(magic[0] == 'M' &&
slouken@187
   472
			 magic[1] == 'M' &&
slouken@187
   473
			 magic[2] == 0x00 &&
slouken@187
   474
			 magic[3] == 0x2a) ) {
slouken@187
   475
			is_TIF = 1;
slouken@187
   476
		}
slouken@187
   477
	}
slouken@187
   478
	SDL_RWseek(src, start, SEEK_SET);
slouken@187
   479
	return(is_TIF);
slouken@187
   480
}
slouken@187
   481
slouken@195
   482
SDL_Surface* IMG_LoadCUR_RW(SDL_RWops *src)
slouken@195
   483
{
slouken@195
   484
	/* FIXME: Is this a supported type? */
slouken@195
   485
	return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
slouken@195
   486
}
slouken@195
   487
SDL_Surface* IMG_LoadICO_RW(SDL_RWops *src)
slouken@195
   488
{
slouken@195
   489
	return LoadImageFromRWops(src, kUTTypeICO);
slouken@195
   490
}
slouken@187
   491
SDL_Surface* IMG_LoadBMP_RW(SDL_RWops *src)
slouken@187
   492
{
slouken@187
   493
	return LoadImageFromRWops(src, kUTTypeBMP);
slouken@187
   494
}
slouken@187
   495
SDL_Surface* IMG_LoadGIF_RW(SDL_RWops *src)
slouken@187
   496
{
slouken@187
   497
	return LoadImageFromRWops(src, kUTTypeGIF);
slouken@187
   498
}
slouken@187
   499
SDL_Surface* IMG_LoadJPG_RW(SDL_RWops *src)
slouken@187
   500
{
slouken@187
   501
	return LoadImageFromRWops(src, kUTTypeJPEG);
slouken@187
   502
}
slouken@187
   503
SDL_Surface* IMG_LoadPNG_RW(SDL_RWops *src)
slouken@187
   504
{
slouken@187
   505
	return LoadImageFromRWops(src, kUTTypePNG);
slouken@187
   506
}
slouken@195
   507
SDL_Surface* IMG_LoadTGA_RW(SDL_RWops *src)
slouken@195
   508
{
slouken@195
   509
	return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
slouken@195
   510
}
slouken@187
   511
SDL_Surface* IMG_LoadTIF_RW(SDL_RWops *src)
slouken@187
   512
{
slouken@187
   513
	return LoadImageFromRWops(src, kUTTypeTIFF);
slouken@187
   514
}
slouken@187
   515