X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16%2F16planar.c;h=f29c92d52c00db0ff5ca4e1881f0308f78590d7d;hb=781dba2e4095d0e72af3f0c38d2de7bafc21c57d;hp=4c5c2578b0b3bf53966bab7a1724ff18c5ee897d;hpb=f084f970ed1e8f06dfffd67bd924918a18a9ce50;p=16.git diff --git a/src/lib/modex16/16planar.c b/src/lib/modex16/16planar.c index 4c5c2578..f29c92d5 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 * * This file is part of Project 16. * @@ -25,46 +25,31 @@ #include #include "src/lib/modex16/16planar.h" -#ifndef PCXHEADER_H -#define PCXHEADER_H -static struct pcxHeader { - byte id; - byte version; - byte encoding; - byte bpp; - word xmin; - word ymin; - word xmax; - word ymax; - word hres; - word vres; - byte pal16[48]; - byte res1; - word bpplane; - word palType; - word hScreenSize; - word vScreenSize; - byte padding[54]; -} head; -#endif /*PCXHEADER_H*/ +/* + *============================================================================ + */ static void loadPcxpbufStage1(FILE *file, planar_buf_t *result) { int index; byte count, val; long int pos; +//word w=0; +//fprintf(stderr, "\nplanarLoadPcx: "); +//fprintf(stderr, "%u ", w++); /* read the header */ fread(&head, sizeof(char), sizeof(struct pcxHeader), file); - +//fprintf(stderr, "%u ", w++); /* get the width and height */ result->width = head.xmax - head.xmin + 1; result->height = head.ymax - head.ymin + 1; - + result->pwidth = result->width / 4 + (result->width%4 ? 1 : 0); +//fprintf(stderr, "%u ", w++); /* make sure this is 8bpp */ if(head.bpp != 8) { fprintf(stderr, "I only know how to handle 8bpp pcx files!\n"); fclose(file); - //exit(-2); + exit(-2); } } @@ -90,37 +75,92 @@ static void loadPcxpbufPalette(FILE *file, planar_buf_t *result) { } } +/* allocates a planar buffer with specified dimensions */ +static planar_buf_t +pbuf_alloc(word width, word height) { + planar_buf_t p; + int i; + + /* allocate the structure and populate sizes */ + //p=malloc(sizeof(planar_buf_t)); + p.width = width; + p.height = height; + p.pwidth = width / 4 + (width%4 ? 1 : 0); + //p.pwidth = width / 4 + (width%4 ? 1 : 0); + + /* allocate the planes */ + for(i=0; i<4; i++) { + p.plane[i] = _fmalloc((p.height * p.pwidth)+1); + } + + return p; +} + +/* allocates a planar buffer with specified dimensions */ +static void +pbuf_alloc0(planar_buf_t *p, word width, word height) { + int i; + + /* allocate the structure and populate sizes */ + p=_fmalloc(sizeof(planar_buf_t)); + p->width = width; + p->height = height; + p->pwidth = width / 4 + (width%4 ? 1 : 0); + //p.pwidth = width / 4 + (width%4 ? 1 : 0); + + /* allocate the planes */ + for(i=0; i<4; i++) { + p->plane[i] = _fmalloc(p->height * p->pwidth); + } +} + /* sparky4's functions~ */ planar_buf_t planarLoadPcx(char *filename) { FILE *file; planar_buf_t result; dword bufSize; - int index, plane, x, y; + word index[4], plane; byte count, val; - word q; +/*word w=0; +fprintf(stderr, "\nplanarLoadPcx: "); +fprintf(stderr, "%u ", w++);*/ /* open the PCX file for reading */ file = fopen(filename, "rb"); +//fprintf(stderr, "%u ", w++); if(!file) { fprintf(stderr, "Could not open %s for reading.\n", filename); - //exit(-2); + exit(-2); } - +//fprintf(stderr, "%u ", w++); /* load the first part of the pcx file */ loadPcxpbufStage1(file, &result); - +//fprintf(stderr, "%u ", w++); /* allocate the buffer */ - bufSize = (/*(dword)*/result.width * result.height); - //result = pbuf_alloc(result.width, result.height); - if(!result.plane[0]) { + 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); + if(!result.plane) { fprintf(stderr, "Could not allocate memory for bitmap data."); fclose(file); - //exit(-1); + exit(-1); } - +//fprintf(stderr, "read the buffer %u ", w++); /* read the buffer in */ - index = 0; + index[0] = 0,index[1]=0,index[2]=0,index[3]=0; + /* start on the first plane */ + plane=0; do { /* get the run length and the value */ count = fgetc(file); @@ -132,23 +172,39 @@ planar_buf_t planarLoadPcx(char *filename) count = 1; } - // start on the first plane - plane=0; +// 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 */ - for(; count && index < bufSize; count--,index++) { +//fprintf(stderr, "\nputting in memory~ %u\n", w++); + for(; count && (index[0]+index[1]+index[2]+index[3]) < bufSize; 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: plane=0; break; + case 0: + case 1: + case 2: + plane++; + break; + default: + plane=0; + break; } - // copy to each plane - result.plane[plane++][index]=val; +//fprintf(stdout, "count=%02X index=%u plane=%u ", count, index[plane], plane); } - } while(index < bufSize); - - //++++loadPcxpbufPalette(file, &result); + //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); + 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; }