6 static struct pcxHeader {
\r
27 static void loadPcxStage1(FILE *file, bitmap_t *result) {
\r
33 /* read the header */
\r
34 fread(&head, sizeof(char), sizeof(struct pcxHeader), file);
\r
36 /* get the width and height */
\r
37 result->width = head.xmax - head.xmin + 1;
\r
38 result->height = head.ymax - head.ymin + 1;
\r
40 /* make sure this is 8bpp */
\r
42 printf("I only know how to handle 8bpp pcx files!\n");
\r
49 static void loadPcxPalette(FILE *file, bitmap_t *result) {
\r
53 /* handle the palette */
\r
54 fseek(file, -769, SEEK_END);
\r
56 result->palette = modexNewPal();
\r
57 if(head.version == 5 && val == 12) {
\r
58 /* use the vga palette */
\r
59 for(index=0; !feof(file) && index < PAL_SIZE; index++) {
\r
61 result->palette[index] = val >> 2;
\r
64 /* use the 16 color palette */
\r
65 for(index=0; index<48; index++) {
\r
66 result->palette[index] = head.pal16[index];
\r
73 bitmapLoadPcx(char *filename) {
\r
80 /* open the PCX file for reading */
\r
81 file = fopen(filename, "rb");
\r
83 printf("Could not open %s for reading.\n", filename);
\r
87 /* load the first part of the pcx file */
\r
88 loadPcxStage1(file, &result);
\r
90 /* allocate the buffer */
\r
91 bufSize = result.width * result.height;
\r
92 result.data = malloc(bufSize);
\r
94 printf("Could not allocate memory for bitmap data.");
\r
99 /* read the buffer in */
\r
102 /* get the run length and the value */
\r
103 count = fgetc(file);
\r
104 if(0xC0 == (count & 0xC0)) { /* this is the run count */
\r
112 /* write the pixel the specified number of times */
\r
113 for(; count && index < bufSize; count--,index++) {
\r
114 result.data[index] = val;
\r
116 } while(index < bufSize);
\r
118 loadPcxPalette(file, &result);
\r
127 bitmapLoadPcxTiles(char *filename, word twidth, word theight) {
\r