#include <malloc.h>\r
#include "src/lib/modex16/16planar.h"\r
\r
-#ifndef PCXHEADER_H\r
-#define PCXHEADER_H\r
-static struct pcxHeader {\r
- byte id;\r
- byte version;\r
- byte encoding;\r
- byte bpp;\r
- word xmin;\r
- word ymin;\r
- word xmax;\r
- word ymax;\r
- word hres;\r
- word vres;\r
- byte pal16[48];\r
- byte res1;\r
- word bpplane;\r
- word palType;\r
- word hScreenSize;\r
- word vScreenSize;\r
- byte padding[54];\r
-} head;\r
-#endif /*PCXHEADER_H*/\r
+/*\r
+ *============================================================================\r
+ */\r
\r
static void loadPcxpbufStage1(FILE *file, planar_buf_t *result) {\r
int index;\r
byte count, val;\r
long int pos;\r
\r
+//word w=0;\r
+//fprintf(stderr, "\nplanarLoadPcx: ");\r
+//fprintf(stderr, "%u ", w++);\r
/* read the header */\r
fread(&head, sizeof(char), sizeof(struct pcxHeader), file);\r
-\r
+//fprintf(stderr, "%u ", w++);\r
/* get the width and height */\r
result->width = head.xmax - head.xmin + 1;\r
result->height = head.ymax - head.ymin + 1;\r
-\r
+ result->pwidth = result->width / 4 + (result->width%4 ? 1 : 0);\r
+//fprintf(stderr, "%u ", w++);\r
/* make sure this is 8bpp */\r
if(head.bpp != 8) {\r
fprintf(stderr, "I only know how to handle 8bpp pcx files!\n");\r
fclose(file);\r
- //exit(-2);\r
+ exit(-2);\r
}\r
}\r
\r
}\r
}\r
\r
+/* allocates a planar buffer with specified dimensions */\r
+static planar_buf_t\r
+pbuf_alloc(word width, word height) {\r
+ planar_buf_t p;\r
+ int i;\r
+\r
+ /* allocate the structure and populate sizes */\r
+ //p=malloc(sizeof(planar_buf_t));\r
+ p.width = width;\r
+ p.height = height;\r
+ p.pwidth = width / 4 + (width%4 ? 1 : 0);\r
+ //p.pwidth = width / 4 + (width%4 ? 1 : 0);\r
+\r
+ /* allocate the planes */\r
+ for(i=0; i<4; i++) {\r
+ p.plane[i] = _fmalloc((p.height * p.pwidth)+1);\r
+ }\r
+\r
+ return p;\r
+}\r
+\r
+/* allocates a planar buffer with specified dimensions */\r
+static void\r
+pbuf_alloc0(planar_buf_t *p, word width, word height) {\r
+ int i;\r
+\r
+ /* allocate the structure and populate sizes */\r
+ p=_fmalloc(sizeof(planar_buf_t));\r
+ p->width = width;\r
+ p->height = height;\r
+ p->pwidth = width / 4 + (width%4 ? 1 : 0);\r
+ //p.pwidth = width / 4 + (width%4 ? 1 : 0);\r
+\r
+ /* allocate the planes */\r
+ for(i=0; i<4; i++) {\r
+ p->plane[i] = _fmalloc(p->height * p->pwidth);\r
+ }\r
+}\r
+\r
/* sparky4's functions~ */\r
planar_buf_t planarLoadPcx(char *filename)\r
{\r
FILE *file;\r
planar_buf_t result;\r
dword bufSize;\r
- int index, plane, x, y;\r
+ word index[4], plane;\r
byte count, val;\r
- word q;\r
\r
+/*word w=0;\r
+fprintf(stderr, "\nplanarLoadPcx: ");\r
+fprintf(stderr, "%u ", w++);*/\r
/* open the PCX file for reading */\r
file = fopen(filename, "rb");\r
+//fprintf(stderr, "%u ", w++);\r
if(!file) {\r
fprintf(stderr, "Could not open %s for reading.\n", filename);\r
- //exit(-2);\r
+ exit(-2);\r
}\r
-\r
+//fprintf(stderr, "%u ", w++);\r
/* load the first part of the pcx file */\r
loadPcxpbufStage1(file, &result);\r
-\r
+//fprintf(stderr, "%u ", w++);\r
/* allocate the buffer */\r
- bufSize = (/*(dword)*/result.width * result.height);\r
- //result = pbuf_alloc(result.width, result.height);\r
- if(!result.plane[0]) {\r
+ bufSize = ((dword)result.width * result.height);\r
+ result = pbuf_alloc(result.width, result.height);\r
+ //pbuf_alloc0(&result, result.width, result.height);\r
+\r
+//fprintf(stderr, "%u ", w++);\r
+// printf("&bufSize=%p\n", &bufSize);\r
+// printf("&result.data=%p\n", result.plane);\r
+// printf("Size of block is %zu bytes\n", _msize(result.plane));\r
+// printf("Size of bufSize is %zu bytes\n", bufSize);\r
+// printf("Size of result.width is %zu \n", result.width);\r
+// printf("Size of result.height is %zu \n", result.height);\r
+// printf("Dimensions of result is %lu\n", (dword)result.width*result.height);\r
+// //exit(0);\r
+ if(!result.plane) {\r
fprintf(stderr, "Could not allocate memory for bitmap data.");\r
fclose(file);\r
- //exit(-1);\r
+ exit(-1);\r
}\r
-\r
+//fprintf(stderr, "read the buffer %u ", w++);\r
/* read the buffer in */\r
- index = 0;\r
+ index[0] = 0,index[1]=0,index[2]=0,index[3]=0;\r
+ /* start on the first plane */\r
+ plane=0;\r
do {\r
/* get the run length and the value */\r
count = fgetc(file);\r
count = 1;\r
}\r
\r
- // start on the first plane\r
- plane=0;\r
+// if(index[plane]==0 && plane==0) fprintf(stdout, "Val dump of %u[%u] && count=%02X:\n", index[plane], plane, count);\r
+//fprintf(stdout, "Val dump of %u[%u] && count=%02X:\n", index[plane], plane, count);\r
+// fprintf(stdout, "%02X ", val);\r
+// if(index[plane]==result.pwidth-1) fprintf(stdout, "\n");\r
+\r
/* write the pixel the specified number of times */\r
- for(; count && index < bufSize; count--,index++) {\r
+//fprintf(stderr, "\nputting in memory~ %u\n", w++);\r
+ for(; count && (index[0]+index[1]+index[2]+index[3]) < bufSize; count--,index[plane]++) {\r
+ // copy to each plane\r
+ result.plane[plane][index[plane]]=(word)val;\r
+//fprintf(stdout, "plane=%u index val=%02X val=%02X\n", plane, result.plane[plane][index[plane]], val);\r
switch (plane)\r
{\r
case 4:\r
plane=0;\r
break;\r
+ case 0:\r
+ case 1:\r
+ case 2:\r
+ plane++;\r
+ break;\r
+ default:\r
+ plane=0;\r
+ break;\r
}\r
- // copy to each plane\r
- result.plane[plane++][index]=val;\r
+//fprintf(stdout, "count=%02X index=%u plane=%u ", count, index[plane], plane);\r
}\r
- } while(index < bufSize);\r
-\r
- //++++loadPcxpbufPalette(file, &result);\r
+ //val++;\r
+// fprintf(stdout, "\nindex=%lu bufsize=%lu\n\n", (dword)(index[0]+index[1]+index[2]+index[3]), bufSize);\r
+ } while((index[0]+index[1]+index[2]+index[3]) < bufSize);\r
+ loadPcxpbufPalette(file, &result);\r
fclose(file);\r
+// fprintf(stderr, "\n\n%s count=%d index=%d plane=%d\n", filename, count, (dword)(index[0]+index[1]+index[2]+index[3]), pla);\r
return result;\r
\r
}\r