X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fpcx.c;h=7756b240f1831041170475fd12a52277043d3ee1;hb=2ff21518535f914abaacf8ffc72bfbd2f319dcd5;hp=58c19bd3caac8e9616244c474b7b456642ebbc55;hpb=322297d68005c08b35e7c309a841553b73259a9c;p=rocksndiamonds.git diff --git a/src/libgame/pcx.c b/src/libgame/pcx.c index 58c19bd3..7756b240 100644 --- a/src/libgame/pcx.c +++ b/src/libgame/pcx.c @@ -1,7 +1,7 @@ /*********************************************************** * Artsoft Retro-Game Library * *----------------------------------------------------------* -* (c) 1994-2001 Artsoft Entertainment * +* (c) 1994-2002 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -19,7 +19,7 @@ #include "misc.h" -#define PCX_DEBUG TRUE +#define PCX_DEBUG FALSE #define PCX_MAGIC 0x0a /* first byte in a PCX image file */ #define PCX_SUPPORTED_VERSION 5 /* last acceptable version number */ @@ -112,7 +112,7 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) for (y = 0; y < height; y++) { /* decode a scan line into a temporary buffer first */ - byte *dst_ptr = (pcx_depth == 8) ? bitmap_ptr : row_buffer; + byte *dst_ptr = (pcx_depth == 8 ? bitmap_ptr : row_buffer); byte value = 0, count = 0; int value_int; int i; @@ -122,14 +122,23 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) if (count == 0) { if ((value_int = fgetc(file)) == EOF) + { + free(row_buffer); return FALSE; + } + value = (byte)value_int; if ((value & 0xc0) == 0xc0) /* this is a repeat count byte */ { count = value & 0x3f; /* extract repeat count from byte */ + if ((value_int = fgetc(file)) == EOF) + { + free(row_buffer); return FALSE; + } + value = (byte)value_int; } else @@ -152,11 +161,11 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) { int i, j, x = 0; - for(i = 0; i < pcx->bytes_per_line; i++) + for (i = 0; i < pcx->bytes_per_line; i++) { byte value = *src_ptr++; - for(j = 7; j >= 0; j--) + for (j = 7; j >= 0; j--) { byte bit = (value >> j) & 1; @@ -170,12 +179,12 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) byte *src_ptr = row_buffer; int plane; - for(plane = 0; plane < pcx->color_planes; plane++) + for (plane = 0; plane < pcx->color_planes; plane++) { int x; dst_ptr = bitmap_ptr + plane; - for(x = 0; x < width; x++) + for (x = 0; x < width; x++) { *dst_ptr = *src_ptr++; dst_ptr += pcx->color_planes; @@ -186,6 +195,8 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) bitmap_ptr += image->bytes_per_row; } + free(row_buffer); + return TRUE; }