IMG_pcx.c
changeset 343 5bf0f0d6a74e
parent 320 aa5d55b11751
child 347 ad5034cad524
     1.1 --- a/IMG_pcx.c	Sun Jan 27 15:55:03 2013 -0800
     1.2 +++ b/IMG_pcx.c	Sun Feb 03 08:37:28 2013 -0800
     1.3 @@ -61,7 +61,7 @@
     1.4  /* See if an image is contained in a data source */
     1.5  int IMG_isPCX(SDL_RWops *src)
     1.6  {
     1.7 -	int start;
     1.8 +	Sint64 start;
     1.9  	int is_PCX;
    1.10  	const int ZSoft_Manufacturer = 10;
    1.11  	const int PC_Paintbrush_Version = 5;
    1.12 @@ -88,7 +88,7 @@
    1.13  /* Load a PCX type image from an SDL datasource */
    1.14  SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
    1.15  {
    1.16 -	int start;
    1.17 +	Sint64 start;
    1.18  	struct PCXheader pcxh;
    1.19  	Uint32 Rmask;
    1.20  	Uint32 Gmask;
    1.21 @@ -127,15 +127,15 @@
    1.22  		bits = 8;
    1.23  	} else if(pcxh.BitsPerPixel == 8 && pcxh.NPlanes == 3) {
    1.24  		bits = 24;
    1.25 -		if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) {
    1.26 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
    1.27  			Rmask = 0x000000FF;
    1.28  			Gmask = 0x0000FF00;
    1.29  			Bmask = 0x00FF0000;
    1.30 -		} else {
    1.31 +#else
    1.32  			Rmask = 0xFF0000;
    1.33  			Gmask = 0x00FF00;
    1.34  			Bmask = 0x0000FF;
    1.35 -		}
    1.36 +#endif
    1.37  	} else {
    1.38  		error = "unsupported PCX format";
    1.39  		goto done;
    1.40 @@ -149,8 +149,8 @@
    1.41  	if (bpl > surface->pitch) {
    1.42  		error = "bytes per line is too large (corrupt?)";
    1.43  	}
    1.44 -	buf = malloc(bpl);
    1.45 -	row = surface->pixels;
    1.46 +	buf = (Uint8 *)malloc(bpl);
    1.47 +	row = (Uint8 *)surface->pixels;
    1.48  	for ( y=0; y<surface->h; ++y ) {
    1.49  		/* decode a scan line to a temporary buffer first */
    1.50  		int i, count = 0;
    1.51 @@ -184,16 +184,16 @@
    1.52  
    1.53  		if(src_bits <= 4) {
    1.54  			/* expand planes to 1 byte/pixel */
    1.55 -			Uint8 *src = buf;
    1.56 +			Uint8 *innerSrc = buf;
    1.57  			int plane;
    1.58  			for(plane = 0; plane < pcxh.NPlanes; plane++) {
    1.59 -				int i, j, x = 0;
    1.60 -				for(i = 0; i < pcxh.BytesPerLine; i++) {
    1.61 -					Uint8 byte = *src++;
    1.62 -					for(j = 7; j >= 0; j--) {
    1.63 -						unsigned bit = (byte >> j) & 1;
    1.64 +				int j, k, x = 0;
    1.65 +				for(j = 0; j < pcxh.BytesPerLine; j++) {
    1.66 +					Uint8 byte = *innerSrc++;
    1.67 +					for(k = 7; k >= 0; k--) {
    1.68 +						unsigned bit = (byte >> k) & 1;
    1.69  						/* skip padding bits */
    1.70 -						if (i * 8 + j >= width)
    1.71 +						if (j * 8 + k >= width)
    1.72  							continue;
    1.73  						row[x++] |= bit << plane;
    1.74  					}
    1.75 @@ -201,13 +201,13 @@
    1.76  			}
    1.77   		} else if(src_bits == 24) {
    1.78  			/* de-interlace planes */
    1.79 -			Uint8 *src = buf;
    1.80 +			Uint8 *innerSrc = buf;
    1.81  			int plane;
    1.82  			for(plane = 0; plane < pcxh.NPlanes; plane++) {
    1.83  				int x;
    1.84  				dst = row + plane;
    1.85  				for(x = 0; x < width; x++) {
    1.86 -					*dst = *src++;
    1.87 +					*dst = *innerSrc++;
    1.88  					dst += pcxh.NPlanes;
    1.89  				}
    1.90  			}