IMG_tif.c
branchSDL-1.2
changeset 607 1a1189c2978f
parent 280 ec4ae96c100c
     1.1 --- a/IMG_tif.c	Tue Oct 16 10:50:15 2018 +0300
     1.2 +++ b/IMG_tif.c	Tue Oct 16 20:02:02 2018 +0300
     1.3 @@ -37,7 +37,7 @@
     1.4  	TIFF* (*TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
     1.5  	void (*TIFFClose)(TIFF*);
     1.6  	int (*TIFFGetField)(TIFF*, ttag_t, ...);
     1.7 -	int (*TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
     1.8 +	int (*TIFFReadRGBAImageOriented)(TIFF*, uint32, uint32, uint32*, int, int);
     1.9  	TIFFErrorHandler (*TIFFSetErrorHandler)(TIFFErrorHandler);
    1.10  } lib;
    1.11  
    1.12 @@ -70,10 +70,10 @@
    1.13  			SDL_UnloadObject(lib.handle);
    1.14  			return -1;
    1.15  		}
    1.16 -		lib.TIFFReadRGBAImage =
    1.17 -			(int (*)(TIFF*, uint32, uint32, uint32*, int))
    1.18 -			SDL_LoadFunction(lib.handle, "TIFFReadRGBAImage");
    1.19 -		if ( lib.TIFFReadRGBAImage == NULL ) {
    1.20 +		lib.TIFFReadRGBAImageOriented =
    1.21 +			(int (*)(TIFF*, uint32, uint32, uint32*, int, int))
    1.22 +			SDL_LoadFunction(lib.handle, "TIFFReadRGBAImageOriented");
    1.23 +		if ( lib.TIFFReadRGBAImageOriented == NULL ) {
    1.24  			SDL_UnloadObject(lib.handle);
    1.25  			return -1;
    1.26  		}
    1.27 @@ -106,7 +106,7 @@
    1.28  		lib.TIFFClientOpen = TIFFClientOpen;
    1.29  		lib.TIFFClose = TIFFClose;
    1.30  		lib.TIFFGetField = TIFFGetField;
    1.31 -		lib.TIFFReadRGBAImage = TIFFReadRGBAImage;
    1.32 +		lib.TIFFReadRGBAImageOriented = TIFFReadRGBAImageOriented;
    1.33  		lib.TIFFSetErrorHandler = TIFFSetErrorHandler;
    1.34  	}
    1.35  	++lib.loaded;
    1.36 @@ -165,7 +165,7 @@
    1.37  
    1.38  static toff_t tiff_size(thandle_t fd)
    1.39  {
    1.40 -	Uint32 save_pos;
    1.41 +	Sint32 save_pos;
    1.42  	toff_t size;
    1.43  
    1.44  	save_pos = SDL_RWtell((SDL_RWops*)fd);
    1.45 @@ -204,7 +204,7 @@
    1.46  SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)
    1.47  {
    1.48  	int start;
    1.49 -	TIFF* tiff;
    1.50 +	TIFF* tiff = NULL;
    1.51  	SDL_Surface* surface = NULL;
    1.52  	Uint32 img_width, img_height;
    1.53  	Uint32 Rmask, Gmask, Bmask, Amask;
    1.54 @@ -217,7 +217,7 @@
    1.55  	}
    1.56  	start = SDL_RWtell(src);
    1.57  
    1.58 -	if ( !IMG_Init(IMG_INIT_TIF) ) {
    1.59 +	if ( (IMG_Init(IMG_INIT_TIF) & IMG_INIT_TIF) == 0 ) {
    1.60  		return NULL;
    1.61  	}
    1.62  
    1.63 @@ -240,32 +240,21 @@
    1.64  	if(!surface)
    1.65  		goto error;
    1.66  	
    1.67 -	if(!lib.TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0))
    1.68 +	if(!lib.TIFFReadRGBAImageOriented(tiff, img_width, img_height, (uint32 *)surface->pixels, ORIENTATION_TOPLEFT, 0))
    1.69  		goto error;
    1.70  
    1.71 -	/* libtiff loads the image upside-down, flip it back */
    1.72 -	half = img_height / 2;
    1.73 -	for(y = 0; y < half; y++)
    1.74 -	{
    1.75 -	        Uint32 *top = (Uint32 *)surface->pixels + y * surface->pitch/4;
    1.76 -	        Uint32 *bot = (Uint32 *)surface->pixels
    1.77 -		              + (img_height - y - 1) * surface->pitch/4;
    1.78 -		for(x = 0; x < img_width; x++)
    1.79 -		{
    1.80 -		        Uint32 tmp = top[x];
    1.81 -			top[x] = bot[x];
    1.82 -			bot[x] = tmp;
    1.83 -		}
    1.84 -	}
    1.85  	lib.TIFFClose(tiff);
    1.86  	
    1.87  	return surface;
    1.88  
    1.89  error:
    1.90  	SDL_RWseek(src, start, RW_SEEK_SET);
    1.91 -	if ( surface ) {
    1.92 +	if (surface) {
    1.93  		SDL_FreeSurface(surface);
    1.94  	}
    1.95 +	if (tiff) {
    1.96 +		lib.TIFFClose(tiff);
    1.97 +	}
    1.98  	return NULL;
    1.99  }
   1.100