Robert Stein - Thu, 22 Feb 2001 14:26:19 -0600
authorSam Lantinga <slouken@lokigames.com>
Tue, 27 Feb 2001 21:29:11 +0000
changeset 21fcbcd2324998
parent 20 463951886af1
child 22 5f9c7cfd0b79
Robert Stein - Thu, 22 Feb 2001 14:26:19 -0600
* Improved the PPM loading code
CHANGES
IMG_ppm.c
     1.1 --- a/CHANGES	Tue Feb 27 20:45:58 2001 +0000
     1.2 +++ b/CHANGES	Tue Feb 27 21:29:11 2001 +0000
     1.3 @@ -3,6 +3,8 @@
     1.4  Mattias Engdegård - Tue Feb 27 12:44:43 PST 2001
     1.5   * Improved the PCX loading code
     1.6   * Modified showimage to set hardware palette for 8-bit displays
     1.7 +Robert Stein - Thu, 22 Feb 2001 14:26:19 -0600
     1.8 + * Improved the PPM loading code
     1.9  Sam Lantinga - Tue Jan 30 14:24:06 PST 2001
    1.10   * Modified showimage to accept multiple images on the command line
    1.11  Sam Lantinga - Mon Dec 18 02:49:29 PST 2000
     2.1 --- a/IMG_ppm.c	Tue Feb 27 20:45:58 2001 +0000
     2.2 +++ b/IMG_ppm.c	Tue Feb 27 21:29:11 2001 +0000
     2.3 @@ -94,13 +94,11 @@
     2.4  	SDL_Surface *surface;
     2.5  	int width, height;
     2.6  	int maxval, x, y;
     2.7 -	Uint32 *row;
     2.8 +	Uint8 *row;
     2.9  	Uint8 rgb[3];
    2.10 -	int read_error;
    2.11  
    2.12  	/* Initialize the data we will clean up when we're done */
    2.13  	surface = NULL;
    2.14 -	read_error = 0;
    2.15  
    2.16  	/* Check to make sure we have something to do */
    2.17  	if ( ! src ) {
    2.18 @@ -129,7 +127,7 @@
    2.19  	SDL_RWseek(src, -1, SEEK_CUR);
    2.20  
    2.21  	/* Create the surface of the appropriate type */
    2.22 -	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 32,
    2.23 +	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 24,
    2.24  				0x00FF0000,0x0000FF00,0x000000FF,0);
    2.25  	if ( surface == NULL ) {
    2.26  		IMG_SetError("Out of memory");
    2.27 @@ -137,25 +135,12 @@
    2.28  	}
    2.29  
    2.30  	/* Read the image into the surface */
    2.31 -	for ( y=0; y<surface->h; ++y ) {
    2.32 -		row = (Uint32 *)((Uint8 *)surface->pixels + y*surface->pitch);
    2.33 -		for ( x=0; x<surface->w; ++x ) {
    2.34 -			if ( ! SDL_RWread(src, rgb, 3, 1) ) {
    2.35 -				read_error = 1;
    2.36 -				goto done;
    2.37 -			}
    2.38 -			*row++ = ((((Uint32)rgb[0])<<16)|
    2.39 -			          (((Uint32)rgb[1])<< 8)|
    2.40 -			          (((Uint32)rgb[2])    ));
    2.41 -		}
    2.42 -	}
    2.43 -
    2.44 -done:
    2.45 -	if ( read_error ) {
    2.46 +	if(!SDL_RWread(src, surface->pixels, 3, surface->h*surface->w)){
    2.47  		SDL_FreeSurface(surface);
    2.48  		IMG_SetError("Error reading PPM data");
    2.49  		surface = NULL;
    2.50  	}
    2.51 +done:
    2.52  	return(surface);
    2.53  }
    2.54