IMG_tif.c
changeset 118 c5e736a47ad2
parent 117 e613cf987897
child 121 1bf9c0c87374
     1.1 --- a/IMG_tif.c	Sat Feb 04 20:37:17 2006 +0000
     1.2 +++ b/IMG_tif.c	Sat Feb 04 22:26:04 2006 +0000
     1.3 @@ -109,6 +109,7 @@
     1.4  
     1.5  SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)
     1.6  {
     1.7 +	int start;
     1.8  	TIFF* tiff;
     1.9  	SDL_Surface* surface = NULL;
    1.10  	Uint32 img_width, img_height;
    1.11 @@ -120,12 +121,13 @@
    1.12  		/* The error message has been set in SDL_RWFromFile */
    1.13  		return NULL;
    1.14  	}
    1.15 +	start = SDL_RWtell(src);
    1.16  
    1.17  	/* turn off memory mapped access with the m flag */
    1.18  	tiff = TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
    1.19  		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);
    1.20  	if(!tiff)
    1.21 -		return NULL;
    1.22 +		goto error;
    1.23  
    1.24  	/* Retrieve the dimensions of the image from the TIFF tags */
    1.25  	TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
    1.26 @@ -138,10 +140,10 @@
    1.27  	surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32,
    1.28  		Rmask, Gmask, Bmask, Amask);
    1.29  	if(!surface)
    1.30 -		return NULL;
    1.31 +		goto error;
    1.32  	
    1.33  	if(!TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0))
    1.34 -		return NULL;
    1.35 +		goto error;
    1.36  
    1.37  	/* libtiff loads the image upside-down, flip it back */
    1.38  	half = img_height / 2;
    1.39 @@ -160,6 +162,13 @@
    1.40  	TIFFClose(tiff);
    1.41  	
    1.42  	return surface;
    1.43 +
    1.44 +error:
    1.45 +	SDL_RWseek(src, start, SEEK_SET);
    1.46 +	if ( surface ) {
    1.47 +		SDL_FreeSurface(surface);
    1.48 +	}
    1.49 +	return NULL;
    1.50  }
    1.51  
    1.52  #else