IMG_tif.c
changeset 167 338c85983115
parent 154 201cc5c1b373
child 186 5fbbeabf647f
     1.1 --- a/IMG_tif.c	Wed Jul 18 07:06:32 2007 +0000
     1.2 +++ b/IMG_tif.c	Wed Jul 18 07:32:56 2007 +0000
     1.3 @@ -152,6 +152,16 @@
     1.4  	return 0;
     1.5  }
     1.6  
     1.7 +static int tiff_map(thandle_t fd, tdata_t* pbase, toff_t* psize)
     1.8 +{
     1.9 +	return (0);
    1.10 +}
    1.11 +
    1.12 +static void tiff_unmap(thandle_t fd, tdata_t base, toff_t size)
    1.13 +{
    1.14 +	return;
    1.15 +}
    1.16 +
    1.17  static toff_t tiff_size(thandle_t fd)
    1.18  {
    1.19  	Uint32 save_pos;
    1.20 @@ -168,37 +178,25 @@
    1.21  {
    1.22  	int start;
    1.23  	int is_TIF;
    1.24 -	TIFF* tiff;
    1.25 -	TIFFErrorHandler prev_handler;
    1.26 +	Uint8 magic[4];
    1.27  
    1.28 -	if ( IMG_InitTIF() < 0 ) {
    1.29 -		return 0;
    1.30 -	}
    1.31  	if ( !src )
    1.32  		return 0;
    1.33  	start = SDL_RWtell(src);
    1.34  	is_TIF = 0;
    1.35 -
    1.36 -	/* Suppress output from libtiff */
    1.37 -	prev_handler = lib.TIFFSetErrorHandler(NULL);
    1.38 -	
    1.39 -	/* Attempt to process the given file data */
    1.40 -	/* turn off memory mapped access with the m flag */
    1.41 -	tiff = lib.TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
    1.42 -		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);
    1.43 -
    1.44 -	/* Reset the default error handler, since it can be useful for info */
    1.45 -	lib.TIFFSetErrorHandler(prev_handler);
    1.46 -
    1.47 -	/* If it's not a TIFF, then tiff will be NULL. */
    1.48 -	if ( tiff ) {
    1.49 -		is_TIF = 1;
    1.50 -
    1.51 -		/* Free up any dynamically allocated memory libtiff uses */
    1.52 -		lib.TIFFClose(tiff);
    1.53 +	if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
    1.54 +		if ( (magic[0] == 'I' &&
    1.55 +                      magic[1] == 'I' &&
    1.56 +		      magic[2] == 0x2a &&
    1.57 +                      magic[3] == 0x00) ||
    1.58 +		     (magic[0] == 'M' &&
    1.59 +                      magic[1] == 'M' &&
    1.60 +		      magic[2] == 0x00 &&
    1.61 +                      magic[3] == 0x2a) ) {
    1.62 +			is_TIF = 1;
    1.63 +		}
    1.64  	}
    1.65  	SDL_RWseek(src, start, SEEK_SET);
    1.66 -	IMG_QuitTIF();
    1.67  	return(is_TIF);
    1.68  }
    1.69  
    1.70 @@ -224,7 +222,7 @@
    1.71  
    1.72  	/* turn off memory mapped access with the m flag */
    1.73  	tiff = lib.TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
    1.74 -		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);
    1.75 +		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, tiff_map, tiff_unmap);
    1.76  	if(!tiff)
    1.77  		goto error;
    1.78