IMG_tga.c
changeset 343 5bf0f0d6a74e
parent 322 92e073f230d0
child 347 ad5034cad524
     1.1 --- a/IMG_tga.c	Sun Jan 27 15:55:03 2013 -0800
     1.2 +++ b/IMG_tga.c	Sun Feb 03 08:37:28 2013 -0800
     1.3 @@ -87,7 +87,7 @@
     1.4  /* Load a TGA type image from an SDL datasource */
     1.5  SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
     1.6  {
     1.7 -    int start;
     1.8 +    Sint64 start;
     1.9      const char *error = NULL;
    1.10      struct TGAheader hdr;
    1.11      int rle = 0;
    1.12 @@ -169,18 +169,20 @@
    1.13  	alpha = 1;
    1.14  	/* fallthrough */
    1.15      case 24:
    1.16 -	if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
    1.17 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
    1.18 +		{
    1.19  	    int s = alpha ? 0 : 8;
    1.20  	    amask = 0x000000ff >> s;
    1.21  	    rmask = 0x0000ff00 >> s;
    1.22  	    gmask = 0x00ff0000 >> s;
    1.23  	    bmask = 0xff000000 >> s;
    1.24 -	} else {
    1.25 +		}
    1.26 +#else
    1.27  	    amask = alpha ? 0xff000000 : 0;
    1.28  	    rmask = 0x00ff0000;
    1.29  	    gmask = 0x0000ff00;
    1.30  	    bmask = 0x000000ff;
    1.31 -	}
    1.32 +#endif
    1.33  	break;
    1.34  
    1.35      default:
    1.36 @@ -207,7 +209,7 @@
    1.37      if(hdr.has_cmap) {
    1.38  	int palsiz = ncols * ((hdr.cmap_bits + 7) >> 3);
    1.39  	if(indexed && !grey) {
    1.40 -	    Uint8 *pal = malloc(palsiz), *p = pal;
    1.41 +	    Uint8 *pal = (Uint8 *)SDL_malloc(palsiz), *p = pal;
    1.42  	    SDL_Color *colors = img->format->palette->colors;
    1.43  	    img->format->palette->ncolors = ncols;
    1.44  	    SDL_RWread(src, pal, palsiz, 1);
    1.45 @@ -233,7 +235,7 @@
    1.46  		    break;
    1.47  		}
    1.48  	    }
    1.49 -	    free(pal);
    1.50 +	    SDL_free(pal);
    1.51  	    if(ckey >= 0)
    1.52  		SDL_SetColorKey(img, SDL_TRUE, ckey);
    1.53  	} else {
    1.54 @@ -250,11 +252,11 @@
    1.55      }
    1.56  
    1.57      if(hdr.flags & TGA_ORIGIN_UPPER) {
    1.58 -	lstep = img->pitch;
    1.59 -	dst = img->pixels;
    1.60 +		lstep = img->pitch;
    1.61 +		dst = (Uint8 *)img->pixels;
    1.62      } else {
    1.63 -	lstep = -img->pitch;
    1.64 -	dst = (Uint8 *)img->pixels + (h - 1) * img->pitch;
    1.65 +		lstep = -img->pitch;
    1.66 +		dst = (Uint8 *)img->pixels + (h - 1) * img->pitch;
    1.67      }
    1.68  
    1.69      /* The RLE decoding code is slightly convoluted since we can't rely on
    1.70 @@ -281,7 +283,7 @@
    1.71  			n = w - x;
    1.72  		    rep -= n;
    1.73  		    while(n--) {
    1.74 -			memcpy(dst + x * bpp, &pixel, bpp);
    1.75 +			SDL_memcpy(dst + x * bpp, &pixel, bpp);
    1.76  			x++;
    1.77  		    }
    1.78  		    if(x == w)
    1.79 @@ -300,13 +302,15 @@
    1.80  	} else {
    1.81  	    SDL_RWread(src, dst, w * bpp, 1);
    1.82  	}
    1.83 -	if(SDL_BYTEORDER == SDL_BIG_ENDIAN && bpp == 2) {
    1.84 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
    1.85 +	if (bpp == 2) {
    1.86  	    /* swap byte order */
    1.87  	    int x;
    1.88  	    Uint16 *p = (Uint16 *)dst;
    1.89  	    for(x = 0; x < w; x++)
    1.90  		p[x] = SDL_Swap16(p[x]);
    1.91  	}
    1.92 +#endif
    1.93  	dst += lstep;
    1.94      }
    1.95      return img;