If there's an error loading an image, seek back to the start of the image.
authorSam Lantinga <slouken@libsdl.org>
Sat, 04 Feb 2006 22:26:04 +0000
changeset 118c5e736a47ad2
parent 117 e613cf987897
child 119 336c49447e0d
If there's an error loading an image, seek back to the start of the image.
IMG_bmp.c
IMG_gif.c
IMG_jpg.c
IMG_lbm.c
IMG_pcx.c
IMG_png.c
IMG_pnm.c
IMG_tga.c
IMG_tif.c
IMG_xcf.c
IMG_xpm.c
IMG_xxx.c
     1.1 --- a/IMG_bmp.c	Sat Feb 04 20:37:17 2006 +0000
     1.2 +++ b/IMG_bmp.c	Sat Feb 04 22:26:04 2006 +0000
     1.3 @@ -422,6 +422,9 @@
     1.4  	}
     1.5  done:
     1.6  	if ( was_error ) {
     1.7 +		if ( src ) {
     1.8 +			SDL_RWseek(src, fp_offset, SEEK_SET);
     1.9 +		}
    1.10  		if ( surface ) {
    1.11  			SDL_FreeSurface(surface);
    1.12  		}
     2.1 --- a/IMG_gif.c	Sat Feb 04 20:37:17 2006 +0000
     2.2 +++ b/IMG_gif.c	Sat Feb 04 22:26:04 2006 +0000
     2.3 @@ -151,6 +151,7 @@
     2.4  Image *
     2.5  IMG_LoadGIF_RW(SDL_RWops *src)
     2.6  {
     2.7 +    int start;
     2.8      unsigned char buf[16];
     2.9      unsigned char c;
    2.10      unsigned char localColorMap[3][MAXCOLORMAPSIZE];
    2.11 @@ -163,8 +164,10 @@
    2.12      Image *image = NULL;
    2.13  
    2.14      if ( src == NULL ) {
    2.15 -        goto done;
    2.16 +	return NULL;
    2.17      }
    2.18 +    start = SDL_RWtell(src);
    2.19 +
    2.20      if (!ReadOK(src, buf, 6)) {
    2.21  	RWSetMsg("error reading magic number");
    2.22          goto done;
    2.23 @@ -262,6 +265,9 @@
    2.24  #endif
    2.25  
    2.26  done:
    2.27 +    if ( image == NULL ) {
    2.28 +        SDL_RWseek(src, start, SEEK_SET);
    2.29 +    }
    2.30      return image;
    2.31  }
    2.32  
     3.1 --- a/IMG_jpg.c	Sat Feb 04 20:37:17 2006 +0000
     3.2 +++ b/IMG_jpg.c	Sat Feb 04 22:26:04 2006 +0000
     3.3 @@ -202,6 +202,7 @@
     3.4  /* Load a JPEG type image from an SDL datasource */
     3.5  SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
     3.6  {
     3.7 +	int start;
     3.8  	struct jpeg_decompress_struct cinfo;
     3.9  	JSAMPROW rowptr[1];
    3.10  	SDL_Surface *volatile surface = NULL;
    3.11 @@ -211,6 +212,7 @@
    3.12  		/* The error message has been set in SDL_RWFromFile */
    3.13  		return NULL;
    3.14  	}
    3.15 +	start = SDL_RWtell(src);
    3.16  
    3.17  	/* Create a decompression structure and load the JPEG header */
    3.18  	cinfo.err = jpeg_std_error(&jerr.errmgr);
    3.19 @@ -219,8 +221,11 @@
    3.20  	if(setjmp(jerr.escape)) {
    3.21  		/* If we get here, libjpeg found an error */
    3.22  		jpeg_destroy_decompress(&cinfo);
    3.23 +		if ( surface != NULL ) {
    3.24 +			SDL_FreeSurface(surface);
    3.25 +		}
    3.26 +		SDL_RWseek(src, start, SEEK_SET);
    3.27  		IMG_SetError("JPEG loading error");
    3.28 -		SDL_FreeSurface(surface);
    3.29  		return NULL;
    3.30  	}
    3.31  
    3.32 @@ -249,8 +254,10 @@
    3.33  #endif
    3.34  				   0);
    3.35  	if ( surface == NULL ) {
    3.36 +		jpeg_destroy_decompress(&cinfo);
    3.37 +		SDL_RWseek(src, start, SEEK_SET);
    3.38  		IMG_SetError("Out of memory");
    3.39 -		goto done;
    3.40 +		return NULL;
    3.41  	}
    3.42  
    3.43  	/* Decompress the image */
    3.44 @@ -261,10 +268,8 @@
    3.45  		jpeg_read_scanlines(&cinfo, rowptr, (JDIMENSION) 1);
    3.46  	}
    3.47  	jpeg_finish_decompress(&cinfo);
    3.48 +	jpeg_destroy_decompress(&cinfo);
    3.49  
    3.50 -	/* Clean up and return */
    3.51 -done:
    3.52 -	jpeg_destroy_decompress(&cinfo);
    3.53  	return(surface);
    3.54  }
    3.55  
     4.1 --- a/IMG_lbm.c	Sat Feb 04 20:37:17 2006 +0000
     4.2 +++ b/IMG_lbm.c	Sat Feb 04 22:26:04 2006 +0000
     4.3 @@ -84,6 +84,7 @@
     4.4  
     4.5  SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
     4.6  {
     4.7 +	int start;
     4.8  	SDL_Surface *Image;
     4.9  	Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
    4.10  	Uint32      size, bytesloaded, nbcolors;
    4.11 @@ -102,6 +103,8 @@
    4.12  		/* The error message has been set in SDL_RWFromFile */
    4.13  		return NULL;
    4.14  	}
    4.15 +	start = SDL_RWtell(src);
    4.16 +
    4.17  	if ( !SDL_RWread( src, id, 4, 1 ) )
    4.18  	{
    4.19  		error="error reading IFF chunk";
    4.20 @@ -469,9 +472,12 @@
    4.21  
    4.22  	if ( error )
    4.23  	{
    4.24 +		SDL_RWseek(src, start, SEEK_SET);
    4.25 +		if ( Image ) {
    4.26 +			SDL_FreeSurface( Image );
    4.27 +			Image = NULL;
    4.28 +		}
    4.29  		IMG_SetError( error );
    4.30 -		SDL_FreeSurface( Image );
    4.31 -		Image = NULL;
    4.32  	}
    4.33  
    4.34  	return( Image );
     5.1 --- a/IMG_pcx.c	Sat Feb 04 20:37:17 2006 +0000
     5.2 +++ b/IMG_pcx.c	Sat Feb 04 22:26:04 2006 +0000
     5.3 @@ -87,6 +87,7 @@
     5.4  /* Load a PCX type image from an SDL datasource */
     5.5  SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
     5.6  {
     5.7 +	int start;
     5.8  	struct PCXheader pcxh;
     5.9  	Uint32 Rmask;
    5.10  	Uint32 Gmask;
    5.11 @@ -103,6 +104,8 @@
    5.12  		/* The error message has been set in SDL_RWFromFile */
    5.13  		return NULL;
    5.14  	}
    5.15 +	start = SDL_RWtell(src);
    5.16 +
    5.17  	if ( ! SDL_RWread(src, &pcxh, sizeof(pcxh), 1) ) {
    5.18  		error = "file truncated";
    5.19  		goto done;
    5.20 @@ -235,9 +238,12 @@
    5.21  done:
    5.22  	free(buf);
    5.23  	if ( error ) {
    5.24 -		SDL_FreeSurface(surface);
    5.25 +		SDL_RWseek(src, start, SEEK_SET);
    5.26 +		if ( surface ) {
    5.27 +			SDL_FreeSurface(surface);
    5.28 +			surface = NULL;
    5.29 +		}
    5.30  		IMG_SetError(error);
    5.31 -		surface = NULL;
    5.32  	}
    5.33  	return(surface);
    5.34  }
     6.1 --- a/IMG_png.c	Sat Feb 04 20:37:17 2006 +0000
     6.2 +++ b/IMG_png.c	Sat Feb 04 22:26:04 2006 +0000
     6.3 @@ -99,6 +99,8 @@
     6.4  }
     6.5  SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
     6.6  {
     6.7 +	int start;
     6.8 +	const char *error;
     6.9  	SDL_Surface *volatile surface;
    6.10  	png_structp png_ptr;
    6.11  	png_infop info_ptr;
    6.12 @@ -118,22 +120,24 @@
    6.13  		/* The error message has been set in SDL_RWFromFile */
    6.14  		return NULL;
    6.15  	}
    6.16 +	start = SDL_RWtell(src);
    6.17  
    6.18  	/* Initialize the data we will clean up when we're done */
    6.19 +	error = NULL;
    6.20  	png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL;
    6.21  
    6.22  	/* Create the PNG loading context structure */
    6.23  	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
    6.24  					  NULL,NULL,NULL);
    6.25  	if (png_ptr == NULL){
    6.26 -		IMG_SetError("Couldn't allocate memory for PNG file or incompatible PNG dll");
    6.27 +		error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
    6.28  		goto done;
    6.29  	}
    6.30  
    6.31  	 /* Allocate/initialize the memory for image information.  REQUIRED. */
    6.32  	info_ptr = png_create_info_struct(png_ptr);
    6.33  	if (info_ptr == NULL) {
    6.34 -		IMG_SetError("Couldn't create image information for PNG file");
    6.35 +		error = "Couldn't create image information for PNG file";
    6.36  		goto done;
    6.37  	}
    6.38  
    6.39 @@ -142,7 +146,7 @@
    6.40  	 * set up your own error handlers in png_create_read_struct() earlier.
    6.41  	 */
    6.42  	if ( setjmp(png_ptr->jmpbuf) ) {
    6.43 -		IMG_SetError("Error reading the PNG file.");
    6.44 +		error = "Error reading the PNG file.";
    6.45  		goto done;
    6.46  	}
    6.47  
    6.48 @@ -222,7 +226,7 @@
    6.49  	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
    6.50  			bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
    6.51  	if ( surface == NULL ) {
    6.52 -		IMG_SetError("Out of memory");
    6.53 +		error = "Out of memory";
    6.54  		goto done;
    6.55  	}
    6.56  
    6.57 @@ -239,9 +243,7 @@
    6.58  	/* Create the array of pointers to image data */
    6.59  	row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*height);
    6.60  	if ( (row_pointers == NULL) ) {
    6.61 -		IMG_SetError("Out of memory");
    6.62 -		SDL_FreeSurface(surface);
    6.63 -		surface = NULL;
    6.64 +		error = "Out of memory";
    6.65  		goto done;
    6.66  	}
    6.67  	for (row = 0; row < (int)height; row++) {
    6.68 @@ -281,11 +283,22 @@
    6.69  	}
    6.70  
    6.71  done:	/* Clean up and return */
    6.72 -	png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0,
    6.73 +	if ( png_ptr ) {
    6.74 +		png_destroy_read_struct(&png_ptr,
    6.75 +		                        info_ptr ? &info_ptr : (png_infopp)0,
    6.76  								(png_infopp)0);
    6.77 +	}
    6.78  	if ( row_pointers ) {
    6.79  		free(row_pointers);
    6.80  	}
    6.81 +	if ( error ) {
    6.82 +		SDL_RWseek(src, start, SEEK_SET);
    6.83 +		if ( surface ) {
    6.84 +			SDL_FreeSurface(surface);
    6.85 +			surface = NULL;
    6.86 +		}
    6.87 +		IMG_SetError(error);
    6.88 +	}
    6.89  	return(surface); 
    6.90  }
    6.91  
     7.1 --- a/IMG_pnm.c	Sat Feb 04 20:37:17 2006 +0000
     7.2 +++ b/IMG_pnm.c	Sat Feb 04 22:26:04 2006 +0000
     7.3 @@ -105,6 +105,7 @@
     7.4  
     7.5  SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
     7.6  {
     7.7 +	int start;
     7.8  	SDL_Surface *surface = NULL;
     7.9  	int width, height;
    7.10  	int maxval, y, bpl;
    7.11 @@ -121,6 +122,7 @@
    7.12  		/* The error message has been set in SDL_RWFromFile */
    7.13  		return NULL;
    7.14  	}
    7.15 +	start = SDL_RWtell(src);
    7.16  
    7.17  	SDL_RWread(src, magic, 2, 1);
    7.18  	kind = magic[1] - '1';
    7.19 @@ -229,9 +231,12 @@
    7.20  done:
    7.21  	free(buf);
    7.22  	if(error) {
    7.23 -		SDL_FreeSurface(surface);
    7.24 +		SDL_RWseek(src, start, SEEK_SET);
    7.25 +		if ( surface ) {
    7.26 +			SDL_FreeSurface(surface);
    7.27 +			surface = NULL;
    7.28 +		}
    7.29  		IMG_SetError(error);
    7.30 -		surface = NULL;
    7.31  	}
    7.32  	return(surface);
    7.33  }
     8.1 --- a/IMG_tga.c	Sat Feb 04 20:37:17 2006 +0000
     8.2 +++ b/IMG_tga.c	Sat Feb 04 22:26:04 2006 +0000
     8.3 @@ -87,6 +87,7 @@
     8.4  SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
     8.5  {
     8.6      int start;
     8.7 +    const char *error = NULL;
     8.8      struct TGAheader hdr;
     8.9      int rle = 0;
    8.10      int alpha = 0;
    8.11 @@ -94,7 +95,7 @@
    8.12      int grey = 0;
    8.13      int ckey = -1;
    8.14      int ncols, w, h;
    8.15 -    SDL_Surface *img;
    8.16 +    SDL_Surface *img = NULL;
    8.17      Uint32 rmask, gmask, bmask, amask;
    8.18      Uint8 *dst;
    8.19      int i;
    8.20 @@ -107,10 +108,12 @@
    8.21          /* The error message has been set in SDL_RWFromFile */
    8.22          return NULL;
    8.23      }
    8.24 +    start = SDL_RWtell(src);
    8.25  
    8.26 -    start = SDL_RWtell(src);
    8.27 -    if(!SDL_RWread(src, &hdr, sizeof(hdr), 1))
    8.28 +    if(!SDL_RWread(src, &hdr, sizeof(hdr), 1)) {
    8.29 +        error = "Error reading TGA data";
    8.30  	goto error;
    8.31 +    }
    8.32      ncols = LE16(hdr.cmap_len);
    8.33      switch(hdr.type) {
    8.34      case TGA_TYPE_RLE_INDEXED:
    8.35 @@ -118,7 +121,7 @@
    8.36  	/* fallthrough */
    8.37      case TGA_TYPE_INDEXED:
    8.38  	if(!hdr.has_cmap || hdr.pixel_bits != 8 || ncols > 256)
    8.39 -	    goto error;
    8.40 +	    goto unsupported;
    8.41  	indexed = 1;
    8.42  	break;
    8.43  
    8.44 @@ -134,7 +137,7 @@
    8.45  	/* fallthrough */
    8.46      case TGA_TYPE_BW:
    8.47  	if(hdr.pixel_bits != 8)
    8.48 -	    goto error;
    8.49 +	    goto unsupported;
    8.50  	/* Treat greyscale as 8bpp indexed images */
    8.51  	indexed = grey = 1;
    8.52  	break;
    8.53 @@ -195,6 +198,10 @@
    8.54      img = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
    8.55  			       bpp * 8,
    8.56  			       rmask, gmask, bmask, amask);
    8.57 +    if(img == NULL) {
    8.58 +        error = "Out of memory";
    8.59 +        goto error;
    8.60 +    }
    8.61  
    8.62      if(hdr.has_cmap) {
    8.63  	int palsiz = ncols * ((hdr.cmap_bits + 7) >> 3);
    8.64 @@ -303,14 +310,15 @@
    8.65      }
    8.66      return img;
    8.67  
    8.68 +unsupported:
    8.69 +    error = "Unsupported TGA format";
    8.70 +
    8.71  error:
    8.72      SDL_RWseek(src, start, SEEK_SET);
    8.73 -    IMG_SetError("Error reading TGA data");
    8.74 -    return NULL;
    8.75 -
    8.76 -unsupported:
    8.77 -    SDL_RWseek(src, start, SEEK_SET);
    8.78 -    IMG_SetError("unsupported TGA format");
    8.79 +    if ( img ) {
    8.80 +        SDL_FreeSurface(img);
    8.81 +    }
    8.82 +    IMG_SetError(error);
    8.83      return NULL;
    8.84  }
    8.85  
     9.1 --- a/IMG_tif.c	Sat Feb 04 20:37:17 2006 +0000
     9.2 +++ b/IMG_tif.c	Sat Feb 04 22:26:04 2006 +0000
     9.3 @@ -109,6 +109,7 @@
     9.4  
     9.5  SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)
     9.6  {
     9.7 +	int start;
     9.8  	TIFF* tiff;
     9.9  	SDL_Surface* surface = NULL;
    9.10  	Uint32 img_width, img_height;
    9.11 @@ -120,12 +121,13 @@
    9.12  		/* The error message has been set in SDL_RWFromFile */
    9.13  		return NULL;
    9.14  	}
    9.15 +	start = SDL_RWtell(src);
    9.16  
    9.17  	/* turn off memory mapped access with the m flag */
    9.18  	tiff = TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
    9.19  		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);
    9.20  	if(!tiff)
    9.21 -		return NULL;
    9.22 +		goto error;
    9.23  
    9.24  	/* Retrieve the dimensions of the image from the TIFF tags */
    9.25  	TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
    9.26 @@ -138,10 +140,10 @@
    9.27  	surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32,
    9.28  		Rmask, Gmask, Bmask, Amask);
    9.29  	if(!surface)
    9.30 -		return NULL;
    9.31 +		goto error;
    9.32  	
    9.33  	if(!TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0))
    9.34 -		return NULL;
    9.35 +		goto error;
    9.36  
    9.37  	/* libtiff loads the image upside-down, flip it back */
    9.38  	half = img_height / 2;
    9.39 @@ -160,6 +162,13 @@
    9.40  	TIFFClose(tiff);
    9.41  	
    9.42  	return surface;
    9.43 +
    9.44 +error:
    9.45 +	SDL_RWseek(src, start, SEEK_SET);
    9.46 +	if ( surface ) {
    9.47 +		SDL_FreeSurface(surface);
    9.48 +	}
    9.49 +	return NULL;
    9.50  }
    9.51  
    9.52  #else
    10.1 --- a/IMG_xcf.c	Sat Feb 04 20:37:17 2006 +0000
    10.2 +++ b/IMG_xcf.c	Sat Feb 04 22:26:04 2006 +0000
    10.3 @@ -671,12 +671,15 @@
    10.4    return 0;
    10.5  }
    10.6  
    10.7 -SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) {
    10.8 +SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src)
    10.9 +{
   10.10 +  int start;
   10.11 +  const char *error = NULL;
   10.12    SDL_Surface *surface, *lays;
   10.13    xcf_header * head;
   10.14    xcf_layer  * layer;
   10.15    xcf_channel ** channel;
   10.16 -  int read_error, chnls, i, offsets;
   10.17 +  int chnls, i, offsets;
   10.18    Uint32 offset, fp;
   10.19  
   10.20    unsigned char * (* load_tile) (SDL_RWops *, Uint32, int, int, int);
   10.21 @@ -685,10 +688,10 @@
   10.22      /* The error message has been set in SDL_RWFromFile */
   10.23      return NULL;
   10.24    }
   10.25 +  start = SDL_RWtell(src);
   10.26  
   10.27    /* Initialize the data we will clean up when we're done */
   10.28    surface = NULL;
   10.29 -  read_error = 0;
   10.30  
   10.31    head = read_xcf_header (src);
   10.32  
   10.33 @@ -710,7 +713,7 @@
   10.34  			     0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   10.35  
   10.36    if ( surface == NULL ) {
   10.37 -    IMG_SetError("Out of memory");
   10.38 +    error = "Out of memory";
   10.39      goto done;
   10.40    }
   10.41  
   10.42 @@ -728,7 +731,7 @@
   10.43  			  0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   10.44  
   10.45    if ( lays == NULL ) {
   10.46 -    IMG_SetError("Out of memory");
   10.47 +    error = "Out of memory";
   10.48      goto done;
   10.49    }
   10.50  
   10.51 @@ -775,7 +778,7 @@
   10.52  			   0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   10.53  
   10.54      if (chs == NULL) {
   10.55 -      IMG_SetError("Out of memory");
   10.56 +      error = "Out of memory";
   10.57        goto done;
   10.58      }
   10.59      for (i = 0; i < chnls; i++) {
   10.60 @@ -790,12 +793,15 @@
   10.61      SDL_FreeSurface (chs);
   10.62    }
   10.63  
   10.64 - done:
   10.65 +done:
   10.66    free_xcf_header (head);
   10.67 -  if ( read_error ) {
   10.68 -    SDL_FreeSurface(surface);
   10.69 -    IMG_SetError("Error reading XCF data");
   10.70 -    surface = NULL;
   10.71 +  if ( error ) {
   10.72 +    SDL_RWseek(src, start, SEEK_SET);
   10.73 +    if ( surface ) {
   10.74 +      SDL_FreeSurface(surface);
   10.75 +      surface = NULL;
   10.76 +    }
   10.77 +    IMG_SetError(error);
   10.78    }
   10.79  
   10.80    return(surface);
    11.1 --- a/IMG_xpm.c	Sat Feb 04 20:37:17 2006 +0000
    11.2 +++ b/IMG_xpm.c	Sat Feb 04 22:26:04 2006 +0000
    11.3 @@ -310,6 +310,7 @@
    11.4  /* read XPM from either array or RWops */
    11.5  static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src)
    11.6  {
    11.7 +	int start;
    11.8  	SDL_Surface *image = NULL;
    11.9  	int index;
   11.10  	int x, y;
   11.11 @@ -327,6 +328,8 @@
   11.12  	linebuf = NULL;
   11.13  	buflen = 0;
   11.14  
   11.15 +	start = SDL_RWtell(src);
   11.16 +
   11.17  	if(xpm)
   11.18  		xpmlines = &xpm;
   11.19  
   11.20 @@ -452,8 +455,11 @@
   11.21  
   11.22  done:
   11.23  	if(error) {
   11.24 -		SDL_FreeSurface(image);
   11.25 -		image = NULL;
   11.26 +		SDL_RWseek(src, start, SEEK_SET);
   11.27 +		if ( image ) {
   11.28 +			SDL_FreeSurface(image);
   11.29 +			image = NULL;
   11.30 +		}
   11.31  		IMG_SetError(error);
   11.32  	}
   11.33  	free(keystrings);
    12.1 --- a/IMG_xxx.c	Sat Feb 04 20:37:17 2006 +0000
    12.2 +++ b/IMG_xxx.c	Sat Feb 04 22:26:04 2006 +0000
    12.3 @@ -38,6 +38,9 @@
    12.4  
    12.5  	start = SDL_RWtell(src);
    12.6  	is_XXX = 0;
    12.7 +
    12.8 +	/* Detect the image here */
    12.9 +
   12.10  	SDL_RWseek(src, start, SEEK_SET);
   12.11  	return(is_XXX);
   12.12  }
   12.13 @@ -45,11 +48,27 @@
   12.14  /* Load a XXX type image from an SDL datasource */
   12.15  SDL_Surface *IMG_LoadXXX_RW(SDL_RWops *src)
   12.16  {
   12.17 +	int start;
   12.18 +	const char *error = NULL;
   12.19 +	SDL_Surface *surface = NULL;
   12.20 +
   12.21  	if ( !src ) {
   12.22  		/* The error message has been set in SDL_RWFromFile */
   12.23  		return NULL;
   12.24  	}
   12.25 -	return(NULL);
   12.26 +	start = SDL_RWtell(src);
   12.27 +
   12.28 +	/* Load the image here */
   12.29 +
   12.30 +	if ( error ) {
   12.31 +		SDL_RWseek(src, start, SEEK_SET);
   12.32 +		if ( surface ) {
   12.33 +			SDL_FreeSurface(surface);
   12.34 +			surface = NULL;
   12.35 +		}
   12.36 +		IMG_SetError(error);
   12.37 +	}
   12.38 +	return surface;
   12.39  }
   12.40  
   12.41  #else