From 182260bf970d56e056a8c0c580ad61302d21ab0f Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 2 Dec 1998 20:43:01 +0100 Subject: [PATCH] rnd-19981202-3 --- src/image.c | 1 + src/image.h | 8 --- src/init.c | 1 + src/msdos.c | 1 + src/pcx.c | 144 ++++++++++++++++++++++++++-------------------------- src/pcx.h | 29 +++++++++++ 6 files changed, 103 insertions(+), 81 deletions(-) create mode 100644 src/pcx.h diff --git a/src/image.c b/src/image.c index c2785a24..3938823a 100644 --- a/src/image.c +++ b/src/image.c @@ -12,6 +12,7 @@ ***********************************************************/ #include "image.h" +#include "pcx.h" #include "misc.h" /* exclude all except newImage() and freeImage() */ diff --git a/src/image.h b/src/image.h index ac046dd1..6315340e 100644 --- a/src/image.h +++ b/src/image.h @@ -49,16 +49,8 @@ typedef struct byte *data; /* image data */ } Image; -#define PCX_Success 0 -#define PCX_OpenFailed -1 -#define PCX_ReadFailed -2 -#define PCX_FileInvalid -3 -#define PCX_NoMemory -4 -#define PCX_ColorFailed -5 - int Read_PCX_to_Pixmap(Display *, Window, GC, char *, Pixmap *, Pixmap *); -Image *Read_PCX_to_Image(char *); Image *newImage(unsigned int, unsigned int, unsigned int); void freeImage(Image *); void freeXImage(Image *, XImageInfo *); diff --git a/src/init.c b/src/init.c index 25cc7e04..4ff449d9 100644 --- a/src/init.c +++ b/src/init.c @@ -21,6 +21,7 @@ #include "files.h" #include "joystick.h" #include "image.h" +#include "pcx.h" #include "network.h" #include "netserv.h" diff --git a/src/msdos.c b/src/msdos.c index 6c6c525c..ebc83195 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -21,6 +21,7 @@ #include "files.h" #include "joystick.h" #include "image.h" +#include "pcx.h" /* allegro driver declarations */ DECLARE_GFX_DRIVER_LIST(GFX_DRIVER_VBEAF GFX_DRIVER_VESA2L GFX_DRIVER_VESA1) diff --git a/src/pcx.c b/src/pcx.c index f2dac1d9..514d30de 100644 --- a/src/pcx.c +++ b/src/pcx.c @@ -11,6 +11,7 @@ * pcx.c * ***********************************************************/ +#include "pcx.h" #include "image.h" #include "misc.h" @@ -44,8 +45,76 @@ struct PCX_Header unsigned char filler[58]; /* fill to struct size of 128 */ }; -static byte *PCX_ReadBitmap(Image *, byte *, byte *); -static byte *PCX_ReadColormap(Image *, byte *, byte *); +static byte *PCX_ReadBitmap(Image *image, byte *buffer_ptr, byte *buffer_last) +{ + /* Run Length Encoding: If the two high bits are set, + * then the low 6 bits contain a repeat count, and the byte to + * repeat is the next byte in the file. If the two high bits are + * not set, then this is the byte to write. + */ + + unsigned int bytes_per_pixel = (image->depth + 7) / 8; + register byte *bitmap_ptr, *bitmap_last; + register byte value, count; + + bitmap_ptr = image->data; + bitmap_last = bitmap_ptr + (image->width * image->height * bytes_per_pixel); + + while (bitmap_ptr < bitmap_last && buffer_ptr < buffer_last) + { + value = *buffer_ptr++; + + if ((value & 0xc0) == 0xc0) /* this is a repeat count byte */ + { + count = value & 0x3f; /* extract repeat count from byte */ + value = *buffer_ptr++; /* next byte is value to repeat */ + + for (; count && bitmap_ptr < bitmap_last; count--) + *bitmap_ptr++ = value; + + if (count) /* repeat count spans end of bitmap */ + return NULL; + } + else + *bitmap_ptr++ = value; + + image->rgb.color_used[value] = TRUE; + } + + /* check if end of buffer was reached before end of bitmap */ + if (bitmap_ptr < bitmap_last) + return NULL; + + /* return current buffer position for next decoding function */ + return buffer_ptr; +} + +static byte *PCX_ReadColormap(Image *image,byte *buffer_ptr, byte *buffer_last) +{ + int i, magic; + + /* read colormap magic byte */ + magic = *buffer_ptr++; + + /* check magic colormap header byte */ + if (magic != PCX_256COLORS_MAGIC) + return NULL; + + /* check if enough bytes left for a complete colormap */ + if (buffer_ptr + PCX_COLORMAP_SIZE > 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; + image->rgb.blue[i] = *buffer_ptr++ << 8; + } + + /* return current buffer position for next decoding function */ + return buffer_ptr; +} Image *Read_PCX_to_Image(char *filename) { @@ -157,74 +226,3 @@ Image *Read_PCX_to_Image(char *filename) return image; } - -static byte *PCX_ReadBitmap(Image *image, byte *buffer_ptr, byte *buffer_last) -{ - /* Run Length Encoding: If the two high bits are set, - * then the low 6 bits contain a repeat count, and the byte to - * repeat is the next byte in the file. If the two high bits are - * not set, then this is the byte to write. - */ - - unsigned int bytes_per_pixel = (image->depth + 7) / 8; - register byte *bitmap_ptr, *bitmap_last; - register byte value, count; - - bitmap_ptr = image->data; - bitmap_last = bitmap_ptr + (image->width * image->height * bytes_per_pixel); - - while (bitmap_ptr < bitmap_last && buffer_ptr < buffer_last) - { - value = *buffer_ptr++; - - if ((value & 0xc0) == 0xc0) /* this is a repeat count byte */ - { - count = value & 0x3f; /* extract repeat count from byte */ - value = *buffer_ptr++; /* next byte is value to repeat */ - - for (; count && bitmap_ptr < bitmap_last; count--) - *bitmap_ptr++ = value; - - if (count) /* repeat count spans end of bitmap */ - return NULL; - } - else - *bitmap_ptr++ = value; - - image->rgb.color_used[value] = TRUE; - } - - /* check if end of buffer was reached before end of bitmap */ - if (bitmap_ptr < bitmap_last) - return NULL; - - /* return current buffer position for next decoding function */ - return buffer_ptr; -} - -static byte *PCX_ReadColormap(Image *image,byte *buffer_ptr, byte *buffer_last) -{ - int i, magic; - - /* read colormap magic byte */ - magic = *buffer_ptr++; - - /* check magic colormap header byte */ - if (magic != PCX_256COLORS_MAGIC) - return NULL; - - /* check if enough bytes left for a complete colormap */ - if (buffer_ptr + PCX_COLORMAP_SIZE > 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; - image->rgb.blue[i] = *buffer_ptr++ << 8; - } - - /* return current buffer position for next decoding function */ - return buffer_ptr; -} diff --git a/src/pcx.h b/src/pcx.h new file mode 100644 index 00000000..b1fa1c63 --- /dev/null +++ b/src/pcx.h @@ -0,0 +1,29 @@ +/*********************************************************** +* Rocks'n'Diamonds -- McDuffin Strikes Back! * +*----------------------------------------------------------* +* (c) 1995-98 Artsoft Entertainment * +* Holger Schemel * +* Oststrasse 11a * +* 33604 Bielefeld * +* phone: ++49 +521 290471 * +* email: aeglos@valinor.owl.de * +*----------------------------------------------------------* +* pcx.h * +***********************************************************/ + +#ifndef PCX_H +#define PCX_H + +#include "main.h" +#include "image.h" + +#define PCX_Success 0 +#define PCX_OpenFailed -1 +#define PCX_ReadFailed -2 +#define PCX_FileInvalid -3 +#define PCX_NoMemory -4 +#define PCX_ColorFailed -5 + +Image *Read_PCX_to_Image(char *); + +#endif /* PCX_H */ -- 2.34.1