From 1c6ef2ead67b4c4e957e2e155f3ab3fe662e77f6 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 4 Sep 2019 16:04:49 -0400 Subject: [PATCH] gr-sim: update 40x96 maker to the now common code --- gr-utils/Makefile | 6 +- gr-utils/loadpng.c | 4 +- gr-utils/png_to_40x96.c | 176 ++-------------------------------------- gr-utils/rle_common.c | 8 +- 4 files changed, 14 insertions(+), 180 deletions(-) diff --git a/gr-utils/Makefile b/gr-utils/Makefile index 552dbd8c..9d706dad 100644 --- a/gr-utils/Makefile +++ b/gr-utils/Makefile @@ -58,10 +58,10 @@ png_to_40x48d.o: png_to_40x48d.c ### -png_to_40x96: png_to_40x96.o loadpng.o - $(CC) $(LFLAGS) -o png_to_40x96 png_to_40x96.o loadpng.o -lpng +png_to_40x96: png_to_40x96.o loadpng.o rle_common.o + $(CC) $(LFLAGS) -o png_to_40x96 png_to_40x96.o loadpng.o rle_common.o -lpng -png_to_40x96.o: png_to_40x96.c loadpng.h +png_to_40x96.o: png_to_40x96.c loadpng.h rle_common.h $(CC) $(CFLAGS) -c png_to_40x96.c diff --git a/gr-utils/loadpng.c b/gr-utils/loadpng.c index fa9f005c..d8a2965f 100644 --- a/gr-utils/loadpng.c +++ b/gr-utils/loadpng.c @@ -222,14 +222,14 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, else if (bit_depth==4) { /* top color */ a2_color=row_pointers[y][x/2]; - if (x%2) { + if (x%2==0) { a2_color=(a2_color>>4); } a2_color&=0xf; /* bottom color */ color=row_pointers[y+(yadd/2)][x/2]; - if (x%2) { + if (x%2==0) { color=(color>>4); } color&=0xf; diff --git a/gr-utils/png_to_40x96.c b/gr-utils/png_to_40x96.c index b0ff2dd6..d3590f1a 100644 --- a/gr-utils/png_to_40x96.c +++ b/gr-utils/png_to_40x96.c @@ -13,164 +13,7 @@ #include #include "loadpng.h" - -#define OUTPUT_C 0 -#define OUTPUT_ASM 1 -#define OUTPUT_RAW 2 - -/*****************************************/ -/* \/ \/ */ -/* Converts a PNG to RLE compressed data */ -/*****************************************/ - - -static int print_run(int count, int out_type, int run, int last) { - - int size=0; - - if (count==0) { - if (out_type==OUTPUT_C) { - printf("\n\t"); - } - else { - printf("\n\t.byte "); - } - } - else { - if (out_type==OUTPUT_C) { - } - else { - printf(", "); - } - } - - if (run==1) { - if (out_type==OUTPUT_C) { - printf("0x%02X,",last); - } - else { - printf("$%02X",last); - } - size++; - } - if (run==2) { - if (out_type==OUTPUT_C) { - printf("0x%02X,0x%02X,",last,last); - } - else { - printf("$%02X,$%02X",last,last); - } - size+=2; - } - - if ((run>2) && (run<16)) { - if (out_type==OUTPUT_C) { - printf("0x%02X,0x%02X,",0xA0|run,last); - } - else { - printf("$%02X,$%02X",0xA0|run,last); - } - size+=2; - } - - if (run>=16) { - if (out_type==OUTPUT_C) { - printf("0x%02X,0x%02X,0x%02X,",0xA0,run,last); - } - else { - printf("$%02X,$%02X,$%02X",0xA0,run,last); - } - size+=3; - } - - return size; -} - -int rle_smaller(int out_type, char *varname, - int xsize,int ysize, unsigned char *image,int high) { - - int run=0; - int x; - - int last=-1,next; - int size=0; - int count=0; - - x=0; - - /* Write out xsize and ysize */ - - if (out_type==OUTPUT_C) { - fprintf(stdout,"unsigned char %s_%s[]={\n",varname, - high?"high":"low"); - fprintf(stdout,"\t0x%X, /* ysize=%d */",xsize,ysize); - } - else { - fprintf(stdout,"%s_%s:",varname,high?"high":"low"); - fprintf(stdout,"\t.byte $%X ; ysize=%d",xsize,ysize); - } - - size+=2; - - /* Get first top/bottom color pair */ - last=image[x]; - run++; - x++; - - while(1) { - - /* get next top/bottom color pair */ - next=image[x]; - - if ((next&0xf0)==0xA0) { - fprintf(stderr,"Warning! Using color A (grey2)!\n"); - next&=~0xf0; - next|=0x50; // substitute grey1 - } - - /* If color change (or too big) then output our run */ - /* Note 0xff for run length is special case meaning "finished" */ - if ((next!=last) || (run>254)) { - - size+=print_run(count,out_type,run,last); - - count++; - run=0; - last=next; - } - - x++; - - /* If we reach the end */ - if (x>=xsize*(ysize/2)) { - run++; - - size+=print_run(count,out_type,run,last); - - break; - - } - - run++; - if (count>6) count=0; - - } - - /* Print closing marker */ - - if (out_type==OUTPUT_C) { - fprintf(stdout,"0xA1,"); - fprintf(stdout,"\t};\n"); - } else { - fprintf(stdout,"\n\t.byte $A1\n"); - } - - size+=1; - - return size; -} - - +#include "rle_common.h" /* Converts a PNG to RLE compressed data */ @@ -180,6 +23,7 @@ int main(int argc, char **argv) { int xsize,ysize; int size=0; int out_type=OUTPUT_C; + char output_name[BUFSIZ]; if (argc<4) { fprintf(stderr,"Usage:\t%s type INFILE varname\n\n",argv[0]); @@ -204,11 +48,9 @@ int main(int argc, char **argv) { fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize); -// size=rle_original(out_type,argv[3], -// xsize,ysize,image); - - size=rle_smaller(out_type,argv[3], - xsize,ysize,image,0); + sprintf(output_name,"%s_low",argv[3]); + size=rle_smaller(out_type,output_name, + xsize,ysize,image); fprintf(stderr,"Size %d bytes\n",size); @@ -219,11 +61,9 @@ int main(int argc, char **argv) { fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize); -// size=rle_original(out_type,argv[3], -// xsize,ysize,image); - - size=rle_smaller(out_type,argv[3], - xsize,ysize,image,1); + sprintf(output_name,"%s_high",argv[3]); + size=rle_smaller(out_type,output_name, + xsize,ysize,image); fprintf(stderr,"Size %d bytes\n",size); diff --git a/gr-utils/rle_common.c b/gr-utils/rle_common.c index 589b81a4..7fa13ea7 100644 --- a/gr-utils/rle_common.c +++ b/gr-utils/rle_common.c @@ -7,13 +7,7 @@ #include #include -//#include "loadpng.h" - -#define OUTPUT_C 0 -#define OUTPUT_ASM 1 -#define OUTPUT_RAW 2 - - +#include "rle_common.h" /*****************************************/ /* \/ \/ */