IMG_UIImage.m
changeset 188 1318044935ad
parent 187 3405ab551300
child 195 6df7a974044f
     1.1 --- a/IMG_UIImage.m	Sun Jan 04 02:09:27 2009 +0000
     1.2 +++ b/IMG_UIImage.m	Sun Jan 04 02:43:39 2009 +0000
     1.3 @@ -219,8 +219,7 @@
     1.4  	return sdl_surface;
     1.5  }
     1.6  
     1.7 -/* Since UIImage doesn't really support streams well, we should optimize for the file case. */
     1.8 -SDL_Surface *IMG_Load(const char *file)
     1.9 +static SDL_Surface* LoadImageFromFile(const char *file)
    1.10  {
    1.11  	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
    1.12  	SDL_Surface* sdl_surface = NULL;
    1.13 @@ -229,14 +228,40 @@
    1.14  	
    1.15  	ns_string = [[NSString alloc] initWithUTF8String:file];
    1.16  	ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
    1.17 -
    1.18 +	
    1.19  	sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
    1.20 -
    1.21 +	
    1.22  	[ui_image release];
    1.23  	[ns_string release];
    1.24  	
    1.25  	[autorelease_pool drain];
    1.26 +	
    1.27 +	return sdl_surface;
    1.28 +}
    1.29  
    1.30 +
    1.31 +/* Since UIImage doesn't really support streams well, we should optimize for the file case. */
    1.32 +SDL_Surface *IMG_Load(const char *file)
    1.33 +{
    1.34 +	SDL_Surface* sdl_surface = NULL;
    1.35 +
    1.36 +	sdl_surface = LoadImageFromFile(file);
    1.37 +	if(NULL == sdl_surface)
    1.38 +	{
    1.39 +		// Either the file doesn't exist or ImageIO doesn't understand the format.
    1.40 +		// For the latter case, fallback to the native SDL_image handlers.
    1.41 +
    1.42 +		SDL_RWops *src = SDL_RWFromFile(file, "rb");
    1.43 +		char *ext = strrchr(file, '.');
    1.44 +		if(ext) {
    1.45 +			ext++;
    1.46 +		}
    1.47 +		if(!src) {
    1.48 +			/* The error message has been set in SDL_RWFromFile */
    1.49 +			return NULL;
    1.50 +		}
    1.51 +		sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
    1.52 +	}
    1.53  	return sdl_surface;
    1.54  }
    1.55