/* Project 16 Source Code~\r
- * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123\r
*\r
* This file is part of Project 16.\r
*\r
\r
/* allocate the planes */\r
for(i=0; i<4; i++) {\r
- p.plane[i] = _fmalloc(p.height * p.pwidth);\r
+ p.plane[i] = _fmalloc((p.height * p.pwidth)+1);\r
}\r
\r
return p;\r
FILE *file;\r
planar_buf_t result;\r
dword bufSize;\r
- int index[4], plane;\r
+ word index[4], plane;\r
byte count, val;\r
\r
- word px,py,i,pla;\r
-\r
-word w=0;\r
+/*word w=0;\r
fprintf(stderr, "\nplanarLoadPcx: ");\r
-fprintf(stderr, "%u ", w++);\r
+fprintf(stderr, "%u ", w++);*/\r
/* open the PCX file for reading */\r
file = fopen(filename, "rb");\r
//fprintf(stderr, "%u ", w++);\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
- pbuf_alloc0(&result, 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
+// 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
}\r
-fprintf(stderr, "read the buffer? %u ", w++);\r
-//getch();\r
+//fprintf(stderr, "read the buffer %u ", w++);\r
/* read the buffer in */\r
index[0] = 0,index[1]=0,index[2]=0,index[3]=0;\r
/* start on the first plane */\r
count = 1;\r
}\r
\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
//fprintf(stderr, "\nputting in memory~ %u\n", w++);\r
-//if(index>=49152) getch();\r
for(; count && (index[0]+index[1]+index[2]+index[3]) < bufSize; count--,index[plane]++) {\r
-//fprintf(stderr, "count=%d index=%d plane=%d\n", 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
case 2:\r
plane++;\r
break;\r
+ default:\r
+ plane=0;\r
+ break;\r
}\r
- //fprintf(stderr, "%d ", result.plane[plane][(index[0]+index[1]+index[2]+index[3])]);\r
- // copy to each plane\r
- result.plane[plane][index[plane]]=val;\r
- plane++;\r
+//fprintf(stdout, "count=%02X index=%u plane=%u ", count, index[plane], plane);\r
}\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
+ loadPcxpbufPalette(file, &result);\r
fclose(file);\r
-\r
- //dump value!!\r
- for(pla=0; pla < 4; pla++) {\r
- i=0;\r
- printf("Plane %d\n", pla);\r
- for(py=0; py < result.height; py++) {\r
- for(px=0; px < result.pwidth; px++) {\r
- printf("%02X ", (int) result.plane[pla][i++]);\r
- }\r
- printf("\n");\r
- }\r
- }\r
- printf("\n\n%s\n", *filename);\r
-fprintf(stdout, "count=%d index=%d plane=%d\n", count, index, pla);\r
- exit(0);\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