]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/modex16/16planar.c
fixed ^^ still buggy but it works better now~
[16.git] / src / lib / modex16 / 16planar.c
index 833db3f888cbb3716cebf0016e6a819726e63f14..c8d3b54e5dd19e88c4df1f6b6ddc7f6b9ba49030 100755 (executable)
@@ -76,7 +76,7 @@ static void loadPcxpbufPalette(FILE *file, planar_buf_t *result) {
 }\r
 \r
 /* allocates a planar buffer with specified dimensions */\r
-planar_buf_t\r
+static planar_buf_t\r
 pbuf_alloc(word width, word height) {\r
        planar_buf_t p;\r
        int i;\r
@@ -90,19 +90,19 @@ pbuf_alloc(word width, word height) {
 \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
 }\r
 \r
 /* allocates a planar buffer with specified dimensions */\r
-void\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=malloc(sizeof(planar_buf_t));\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
@@ -110,7 +110,7 @@ pbuf_alloc0(planar_buf_t *p, word width, word height) {
 \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);\r
        }\r
 }\r
 \r
@@ -120,12 +120,12 @@ planar_buf_t planarLoadPcx(char *filename)
        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 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
@@ -138,25 +138,25 @@ fprintf(stderr, "%u ", w++);
        loadPcxpbufStage1(file, &result);\r
 //fprintf(stderr, "%u ", w++);\r
        /* allocate the buffer */\r
-       bufSize = (/*(dword)*/result.width * result.height);\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
+//     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
@@ -172,11 +172,17 @@ getch();
                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
@@ -187,15 +193,18 @@ getch();
                        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
+//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
-       getch();\r
-       //++++loadPcxpbufPalette(file, &result);\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