From 6f107fb00bbd6daaaf7a7cca3eec6a66c028ed23 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 27 Feb 2001 21:29:11 +0000 Subject: [PATCH] Robert Stein - Thu, 22 Feb 2001 14:26:19 -0600 * Improved the PPM loading code --- CHANGES | 2 ++ IMG_ppm.c | 23 ++++------------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 6e0b0785..cf136e9a 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ Mattias Engdegård - Tue Feb 27 12:44:43 PST 2001 * Improved the PCX loading code * Modified showimage to set hardware palette for 8-bit displays +Robert Stein - Thu, 22 Feb 2001 14:26:19 -0600 + * Improved the PPM loading code Sam Lantinga - Tue Jan 30 14:24:06 PST 2001 * Modified showimage to accept multiple images on the command line Sam Lantinga - Mon Dec 18 02:49:29 PST 2000 diff --git a/IMG_ppm.c b/IMG_ppm.c index b08d25b4..bbef19bd 100644 --- a/IMG_ppm.c +++ b/IMG_ppm.c @@ -94,13 +94,11 @@ SDL_Surface *IMG_LoadPPM_RW(SDL_RWops *src) SDL_Surface *surface; int width, height; int maxval, x, y; - Uint32 *row; + Uint8 *row; Uint8 rgb[3]; - int read_error; /* Initialize the data we will clean up when we're done */ surface = NULL; - read_error = 0; /* Check to make sure we have something to do */ if ( ! src ) { @@ -129,7 +127,7 @@ SDL_Surface *IMG_LoadPPM_RW(SDL_RWops *src) SDL_RWseek(src, -1, SEEK_CUR); /* Create the surface of the appropriate type */ - surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 32, + surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 24, 0x00FF0000,0x0000FF00,0x000000FF,0); if ( surface == NULL ) { IMG_SetError("Out of memory"); @@ -137,25 +135,12 @@ SDL_Surface *IMG_LoadPPM_RW(SDL_RWops *src) } /* Read the image into the surface */ - for ( y=0; yh; ++y ) { - row = (Uint32 *)((Uint8 *)surface->pixels + y*surface->pitch); - for ( x=0; xw; ++x ) { - if ( ! SDL_RWread(src, rgb, 3, 1) ) { - read_error = 1; - goto done; - } - *row++ = ((((Uint32)rgb[0])<<16)| - (((Uint32)rgb[1])<< 8)| - (((Uint32)rgb[2]) )); - } - } - -done: - if ( read_error ) { + if(!SDL_RWread(src, surface->pixels, 3, surface->h*surface->w)){ SDL_FreeSurface(surface); IMG_SetError("Error reading PPM data"); surface = NULL; } +done: return(surface); }