From d2c476115b0fdac9152e29385748bc066905ca9e Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 22 Mar 2021 21:29:27 -0400 Subject: [PATCH] gr-utils: add a png to 16x16 util --- utils/gr-utils/Makefile | 21 ++++++--- utils/gr-utils/loadpng.c | 10 ++++ utils/gr-utils/loadpng.h | 1 + utils/gr-utils/png_16x16.c | 95 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 utils/gr-utils/png_16x16.c diff --git a/utils/gr-utils/Makefile b/utils/gr-utils/Makefile index 3d7a3411..cc449197 100644 --- a/utils/gr-utils/Makefile +++ b/utils/gr-utils/Makefile @@ -3,7 +3,7 @@ include ../../Makefile.inc CFLAGS = -g -Wall -O2 all: text2gr png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 \ - png2sixbitmap png2six80 png2sixrle png2fourrle png2sixrle2 + png2sixbitmap png2six80 png2sixrle png2fourrle png2sixrle2 png_16x16 ### @@ -47,11 +47,11 @@ png2sixbitmap.o: png2sixbitmap.c loadpng.h ### -png2sixrle: png2sixrle.o loadpng.o - $(CC) $(LFLAGS) -o png2sixrle png2sixrle.o loadpng.o -lpng +png_16x16: png_16x16.o loadpng.o + $(CC) $(LFLAGS) -o png_16x16 png_16x16.o loadpng.o -lpng -png2sixrle.o: png2sixrle.c loadpng.h - $(CC) $(CFLAGS) -c png2sixrle.c +png_16x16.o: png_16x16.c loadpng.h + $(CC) $(CFLAGS) -c png_16x16.c ### @@ -61,6 +61,13 @@ png2fourrle: png2fourrle.o loadpng.o png2fourrle.o: png2fourrle.c loadpng.h $(CC) $(CFLAGS) -c png2fourrle.c +### + +png2sixrle: png2sixrle.o loadpng.o + $(CC) $(LFLAGS) -o png2sixrle png2sixrle.o loadpng.o -lpng + +png2sixrle.o: png2sixrle.c loadpng.h + $(CC) $(CFLAGS) -c png2sixrle.c ### @@ -120,8 +127,8 @@ png_to_40x96.o: png_to_40x96.c loadpng.h rle_common.h ### install: - cp png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2sixrle2 png2fourrle png2six80 $(INSTALL_LOC) + cp png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2sixrle2 png2fourrle png2six80 png_16x16 $(INSTALL_LOC) clean: - rm -f *~ *.o png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2fourrle png2sixrle2 png2six80 text2gr pnglarge2rle + rm -f *~ *.o png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2fourrle png2sixrle2 png2six80 text2gr pnglarge2rle png_16x16 diff --git a/utils/gr-utils/loadpng.c b/utils/gr-utils/loadpng.c index 737fcb96..9190bfcc 100644 --- a/utils/gr-utils/loadpng.c +++ b/utils/gr-utils/loadpng.c @@ -114,6 +114,10 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, *xsize=40; xadd=2; } + else if (width==16) { + *xsize=16; + xadd=1; + } else { fprintf(stderr,"Unsupported width %d\n",width); return -1; @@ -134,6 +138,12 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, ystart=0; yadd=4; } + else if (png_type==PNG_RAW) { + /* FIXME, not working */ + *ysize=height; + ystart=0; + yadd=1; + } else { fprintf(stderr,"Unknown PNG type\n"); return -1; diff --git a/utils/gr-utils/loadpng.h b/utils/gr-utils/loadpng.h index 51882f61..e4728866 100644 --- a/utils/gr-utils/loadpng.h +++ b/utils/gr-utils/loadpng.h @@ -1,6 +1,7 @@ #define PNG_WHOLETHING 0 #define PNG_ODDLINES 1 #define PNG_EVENLINES 2 +#define PNG_RAW 3 int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, int png_type); diff --git a/utils/gr-utils/png_16x16.c b/utils/gr-utils/png_16x16.c new file mode 100644 index 00000000..3d74139b --- /dev/null +++ b/utils/gr-utils/png_16x16.c @@ -0,0 +1,95 @@ +/* Convert 16x16 PNGs to 8+128 text for use in AppleII Basic bot loader */ + +#include +#include + +#include +#include +#include +#include +#include + +#include "loadpng.h" + +static int color_count=0; +static int colors[16]; + +static int find_color(int which) { + int i; + + for(i=0;i>4); + } + in[op]=color; + op++; + } + } + } + + printf("Raw Image was %d bytes, %d colors\n",op,color_count); + +#if 0 + for(i=0;i