IMG_tga.c
changeset 117 e613cf987897
parent 98 9f94c4674cc9
child 118 c5e736a47ad2
     1.1 --- a/IMG_tga.c	Sat Feb 04 04:53:36 2006 +0000
     1.2 +++ b/IMG_tga.c	Sat Feb 04 20:37:17 2006 +0000
     1.3 @@ -83,14 +83,10 @@
     1.4  #define LE16(p) ((p)[0] + ((p)[1] << 8))
     1.5  #define SETLE16(p, v) ((p)[0] = (v), (p)[1] = (v) >> 8)
     1.6  
     1.7 -static void unsupported(void)
     1.8 -{
     1.9 -    IMG_SetError("unsupported TGA format");
    1.10 -}
    1.11 -
    1.12  /* Load a TGA type image from an SDL datasource */
    1.13  SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
    1.14  {
    1.15 +    int start;
    1.16      struct TGAheader hdr;
    1.17      int rle = 0;
    1.18      int alpha = 0;
    1.19 @@ -112,6 +108,7 @@
    1.20          return NULL;
    1.21      }
    1.22  
    1.23 +    start = SDL_RWtell(src);
    1.24      if(!SDL_RWread(src, &hdr, sizeof(hdr), 1))
    1.25  	goto error;
    1.26      ncols = LE16(hdr.cmap_len);
    1.27 @@ -143,8 +140,7 @@
    1.28  	break;
    1.29  
    1.30      default:
    1.31 -        unsupported();
    1.32 -	return NULL;
    1.33 +        goto unsupported;
    1.34      }
    1.35  
    1.36      bpp = (hdr.pixel_bits + 7) >> 3;
    1.37 @@ -152,8 +148,7 @@
    1.38      switch(hdr.pixel_bits) {
    1.39      case 8:
    1.40  	if(!indexed) {
    1.41 -	    unsupported();
    1.42 -	    return NULL;
    1.43 +            goto unsupported;
    1.44  	}
    1.45  	break;
    1.46  
    1.47 @@ -185,14 +180,12 @@
    1.48  	break;
    1.49  
    1.50      default:
    1.51 -	unsupported();
    1.52 -	return NULL;
    1.53 +        goto unsupported;
    1.54      }
    1.55  
    1.56      if((hdr.flags & TGA_INTERLEAVE_MASK) != TGA_INTERLEAVE_NONE
    1.57         || hdr.flags & TGA_ORIGIN_RIGHT) {
    1.58 -	unsupported();
    1.59 -	return NULL;
    1.60 +        goto unsupported;
    1.61      }
    1.62      
    1.63      SDL_RWseek(src, hdr.infolen, SEEK_CUR); /* skip info field */
    1.64 @@ -311,8 +304,14 @@
    1.65      return img;
    1.66  
    1.67  error:
    1.68 +    SDL_RWseek(src, start, SEEK_SET);
    1.69      IMG_SetError("Error reading TGA data");
    1.70      return NULL;
    1.71 +
    1.72 +unsupported:
    1.73 +    SDL_RWseek(src, start, SEEK_SET);
    1.74 +    IMG_SetError("unsupported TGA format");
    1.75 +    return NULL;
    1.76  }
    1.77  
    1.78  #else