From: Robert Lowe Date: Sun, 28 Sep 2014 03:00:58 +0000 (-0400) Subject: working divided version of pcx files. Used in pcxtest.exe X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=f911a5a8eeaf8fdc9732eaf438fcd02a1e6c1528;hp=dfaa5ddeb4ea4e1edaf1dbaa6c2a3773ea8a918d;p=16.git working divided version of pcx files. Used in pcxtest.exe --- diff --git a/16/modex16/BITMAP.C b/16/modex16/BITMAP.C index 108d8c30..b1521526 100644 --- a/16/modex16/BITMAP.C +++ b/16/modex16/BITMAP.C @@ -21,11 +21,10 @@ static struct pcxHeader { word hScreenSize; word vScreenSize; byte padding[54]; -}; +} head; static void loadPcxStage1(FILE *file, bitmap_t *result) { - struct pcxHeader head; long bufSize; int index; byte count, val; @@ -34,26 +33,22 @@ static void loadPcxStage1(FILE *file, bitmap_t *result) { /* read the header */ fread(&head, sizeof(char), sizeof(struct pcxHeader), file); + /* get the width and height */ + result->width = head.xmax - head.xmin + 1; + result->height = head.ymax - head.ymin + 1; + /* make sure this is 8bpp */ if(head.bpp != 8) { printf("I only know how to handle 8bpp pcx files!\n"); fclose(file); exit(-2); } +} - /* allocate the buffer */ - result->width = head.xmax - head.xmin + 1; - result->height = head.ymax - head.ymin + 1; - bufSize = result->width * result->height; - result->data = malloc(bufSize); - if(!result->data) { - printf("Could not allocate memory for bitmap data."); - fclose(file); - exit(-1); - } - /* save the position of the pixel data */ - pos = ftell(file); +static void loadPcxPalette(FILE *file, bitmap_t *result) { + byte val; + int index; /* handle the palette */ fseek(file, -769, SEEK_END); @@ -71,9 +66,6 @@ static void loadPcxStage1(FILE *file, bitmap_t *result) { result->palette[index] = head.pal16[index]; } } - - /* go back to the pixel data */ - fseek(file, -pos, SEEK_END); } @@ -81,7 +73,6 @@ bitmap_t bitmapLoadPcx(char *filename) { FILE *file; bitmap_t result; - struct pcxHeader head; long bufSize; int index; byte count, val; @@ -96,6 +87,15 @@ bitmapLoadPcx(char *filename) { /* load the first part of the pcx file */ loadPcxStage1(file, &result); + /* allocate the buffer */ + bufSize = result.width * result.height; + result.data = malloc(bufSize); + if(!result.data) { + printf("Could not allocate memory for bitmap data."); + fclose(file); + exit(-1); + } + /* read the buffer in */ index = 0; do { @@ -115,6 +115,7 @@ bitmapLoadPcx(char *filename) { } } while(index < bufSize); + loadPcxPalette(file, &result); fclose(file); diff --git a/16/modex16/pcxtest.c b/16/modex16/pcxtest.c index 51b8427b..7373e885 100644 --- a/16/modex16/pcxtest.c +++ b/16/modex16/pcxtest.c @@ -33,7 +33,7 @@ void main() { page=modexDefaultPage(); - bmp = modexLoadPcx("46113319.pcx"); + bmp = bitmapLoadPcx("46113319.pcx"); modexEnter(); /* fix up the palette and everything */ diff --git a/16/modex16/pcxtest.exe b/16/modex16/pcxtest.exe index a57b981c..2ae847e5 100644 Binary files a/16/modex16/pcxtest.exe and b/16/modex16/pcxtest.exe differ diff --git a/16/modex16/scroll.exe b/16/modex16/scroll.exe index a259aeed..5e87bdc4 100755 Binary files a/16/modex16/scroll.exe and b/16/modex16/scroll.exe differ diff --git a/16/modex16/test.exe b/16/modex16/test.exe index 507cd456..8efde54e 100644 Binary files a/16/modex16/test.exe and b/16/modex16/test.exe differ diff --git a/16/modex16/test2.exe b/16/modex16/test2.exe index 0aa470b9..ab461641 100644 Binary files a/16/modex16/test2.exe and b/16/modex16/test2.exe differ