X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16%2F16planar.c;h=cd528e46fd3675f8fde171dc74365a4278ef0281;hb=f140a355c36fae1da7e962c9828983e1fa131ad1;hp=833db3f888cbb3716cebf0016e6a819726e63f14;hpb=ef6299431f115ac663324d55ffb64570a2e66258;p=16.git diff --git a/src/lib/modex16/16planar.c b/src/lib/modex16/16planar.c index 833db3f8..cd528e46 100755 --- a/src/lib/modex16/16planar.c +++ b/src/lib/modex16/16planar.c @@ -1,5 +1,5 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669 + * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * * This file is part of Project 16. * @@ -76,7 +76,7 @@ static void loadPcxpbufPalette(FILE *file, planar_buf_t *result) { } /* allocates a planar buffer with specified dimensions */ -planar_buf_t +static planar_buf_t pbuf_alloc(word width, word height) { planar_buf_t p; int i; @@ -90,19 +90,19 @@ pbuf_alloc(word width, word height) { /* allocate the planes */ for(i=0; i<4; i++) { - p.plane[i] = _fmalloc(p.height * p.pwidth); + p.plane[i] = _fmalloc((p.height * p.pwidth)+1); } return p; } /* allocates a planar buffer with specified dimensions */ -void +static void pbuf_alloc0(planar_buf_t *p, word width, word height) { int i; /* allocate the structure and populate sizes */ - //p=malloc(sizeof(planar_buf_t)); + p=_fmalloc(sizeof(planar_buf_t)); p->width = width; p->height = height; p->pwidth = width / 4 + (width%4 ? 1 : 0); @@ -110,7 +110,7 @@ pbuf_alloc0(planar_buf_t *p, word width, word height) { /* allocate the planes */ for(i=0; i<4; i++) { - p->plane[i] = _fmalloc(p->height * p->pwidth); + p->plane[i] = _fmalloc(p->height * p->pwidth); } } @@ -120,12 +120,12 @@ planar_buf_t planarLoadPcx(char *filename) FILE *file; planar_buf_t result; dword bufSize; - int index[4], plane; + word index[4], plane; byte count, val; -word w=0; +/*word w=0; fprintf(stderr, "\nplanarLoadPcx: "); -fprintf(stderr, "%u ", w++); +fprintf(stderr, "%u ", w++);*/ /* open the PCX file for reading */ file = fopen(filename, "rb"); //fprintf(stderr, "%u ", w++); @@ -138,25 +138,25 @@ fprintf(stderr, "%u ", w++); loadPcxpbufStage1(file, &result); //fprintf(stderr, "%u ", w++); /* allocate the buffer */ - bufSize = (/*(dword)*/result.width * result.height); + bufSize = ((dword)result.width * result.height); result = pbuf_alloc(result.width, result.height); //pbuf_alloc0(&result, result.width, result.height); + //fprintf(stderr, "%u ", w++); - printf("&bufSize=%p\n", &bufSize); - printf("&result.data=%p\n", result.plane); - printf("Size of block is %zu bytes\n", _msize(result.plane)); - printf("Size of bufSize is %zu bytes\n", bufSize); - printf("Size of result.width is %zu \n", result.width); - printf("Size of result.height is %zu \n", result.height); - printf("Dimensions of result is %lu\n", (dword)result.width*result.height); - //exit(0); +// printf("&bufSize=%p\n", &bufSize); +// printf("&result.data=%p\n", result.plane); +// printf("Size of block is %zu bytes\n", _msize(result.plane)); +// printf("Size of bufSize is %zu bytes\n", bufSize); +// printf("Size of result.width is %zu \n", result.width); +// printf("Size of result.height is %zu \n", result.height); +// printf("Dimensions of result is %lu\n", (dword)result.width*result.height); +// //exit(0); if(!result.plane) { fprintf(stderr, "Could not allocate memory for bitmap data."); fclose(file); exit(-1); } -fprintf(stderr, "read the buffer? %u ", w++); -getch(); +//fprintf(stderr, "read the buffer %u ", w++); /* read the buffer in */ index[0] = 0,index[1]=0,index[2]=0,index[3]=0; /* start on the first plane */ @@ -172,11 +172,17 @@ getch(); count = 1; } +// if(index[plane]==0 && plane==0) fprintf(stdout, "Val dump of %u[%u] && count=%02X:\n", index[plane], plane, count); +//fprintf(stdout, "Val dump of %u[%u] && count=%02X:\n", index[plane], plane, count); +// fprintf(stdout, "%02X ", val); +// if(index[plane]==result.pwidth-1) fprintf(stdout, "\n"); + /* write the pixel the specified number of times */ //fprintf(stderr, "\nputting in memory~ %u\n", w++); -//if(index>=49152) getch(); for(; count && (index[0]+index[1]+index[2]+index[3]) < bufSize; count--,index[plane]++) { -//fprintf(stderr, "count=%d index=%d plane=%d\n", count, index, plane); + // copy to each plane + result.plane[plane][index[plane]]=(word)val; +//fprintf(stdout, "plane=%u index val=%02X val=%02X\n", plane, result.plane[plane][index[plane]], val); switch (plane) { case 4: @@ -187,15 +193,18 @@ getch(); case 2: plane++; break; + default: + plane=0; + break; } - //fprintf(stderr, "%d ", result.plane[plane][(index[0]+index[1]+index[2]+index[3])]); - // copy to each plane - result.plane[plane++][index[plane]]=val; +//fprintf(stdout, "count=%02X index=%u plane=%u ", count, index[plane], plane); } + //val++; +// fprintf(stdout, "\nindex=%lu bufsize=%lu\n\n", (dword)(index[0]+index[1]+index[2]+index[3]), bufSize); } while((index[0]+index[1]+index[2]+index[3]) < bufSize); - getch(); - //++++loadPcxpbufPalette(file, &result); + loadPcxpbufPalette(file, &result); fclose(file); +// fprintf(stderr, "\n\n%s count=%d index=%d plane=%d\n", filename, count, (dword)(index[0]+index[1]+index[2]+index[3]), pla); return result; }