X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fpcx.c;h=5fdf6f3ecb56d7a53e3272c8b6d88e7df2a604fa;hb=6890bb7cb72e140f4b82f35217655ae6c5213fec;hp=9792331422cbb919763f6d13a45eee7dc90201ed;hpb=a750ba6776fdfb711f5da2e6094c8010cd19645a;p=rocksndiamonds.git diff --git a/src/libgame/pcx.c b/src/libgame/pcx.c index 97923314..5fdf6f3e 100644 --- a/src/libgame/pcx.c +++ b/src/libgame/pcx.c @@ -19,7 +19,7 @@ #include "misc.h" -#define PCX_DEBUG FALSE +#define PCX_DEBUG 0 #define PCX_MAGIC 0x0a /* first byte in a PCX image file */ #define PCX_SUPPORTED_VERSION 5 /* last acceptable version number */ @@ -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 @@ -160,6 +169,9 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) { byte bit = (value >> j) & 1; + if (i * 8 + j >= width) /* skip padding bits */ + continue; + bitmap_ptr[x++] |= bit << plane; } } @@ -186,6 +198,8 @@ static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) bitmap_ptr += image->bytes_per_row; } + free(row_buffer); + return TRUE; } @@ -206,7 +220,7 @@ static byte *PCX_ReadColormap(Image *image,byte *buffer_ptr, byte *buffer_last) return NULL; /* read 256 colors from PCX colormap */ - for (i=0; irgb.red[i] = *buffer_ptr++ << 8; image->rgb.green[i] = *buffer_ptr++ << 8; @@ -242,7 +256,7 @@ static boolean PCX_ReadColormap(FILE *file,struct PCX_Header *pcx,Image *image) while (value != PCX_256COLORS_MAGIC); /* read 256 colors from PCX colormap */ - for(i = 0; i < PCX_MAXCOLORS; i++) + for (i = 0; i < PCX_MAXCOLORS; i++) { image->rgb.red[i] = (byte)fgetc(file) << 8; image->rgb.green[i] = (byte)fgetc(file) << 8; @@ -251,7 +265,7 @@ static boolean PCX_ReadColormap(FILE *file,struct PCX_Header *pcx,Image *image) } else { - for(i = 0; i < num_colors; i++) + for (i = 0; i < num_colors; i++) { image->rgb.red[i] = pcx->palette[i][0] << 8; image->rgb.green[i] = pcx->palette[i][1] << 8; @@ -321,6 +335,7 @@ Image *Read_PCX_to_Image(char *filename) #if PCX_DEBUG if (options.verbose) { + printf("\n"); printf("%s is a %dx%d PC Paintbrush image\n", filename, width, height); printf("depth: %d\n", depth); printf("bits_per_pixel: %d\n", pcx.bits_per_pixel); @@ -360,15 +375,14 @@ Image *Read_PCX_to_Image(char *filename) if (pcx_depth == 8) { /* determine number of used colormap entries for 8-bit PCX images */ - image->rgb.used = 0; - for (i=0; irgb.color_used[i]) image->rgb.used++; } #if PCX_DEBUG if (options.verbose) - printf("Read_PCX_to_Image: %d colors found\n", image->rgb.used); + printf("Read_PCX_to_Image: %d colors in colormap\n", image->rgb.used); #endif return image;