From 6665bae6310e4a60853e838569f450f20ac5ef80 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 27 Oct 2020 16:45:11 -0400 Subject: [PATCH] gr-utils: add png2sixrle --- appleiibot/Makefile | 7 +++- gr-utils/Makefile | 15 ++++++-- gr-utils/png2sixrle.c | 80 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 gr-utils/png2sixrle.c diff --git a/appleiibot/Makefile b/appleiibot/Makefile index e93c3e02..27f7ee03 100644 --- a/appleiibot/Makefile +++ b/appleiibot/Makefile @@ -9,7 +9,7 @@ appleiibot.dsk: E2.BAS FLAME.BAS FLAME2.BAS \ CIRCLES.BAS AUTUMN.BAS QKUMBA.BAS ASTEROID.BAS PERSON.BAS SHIP.BAS \ CONCERT.BAS NYAN.BAS RASTER.BAS RASTER2.BAS RASTER3.BAS LOTS.BAS LOAD \ RASTER4.BAS RASTER5.BAS PUMPKIN.BAS PUMPKIN_SMALL.BAS LADY.BAS \ - A2.BAS FOURAM.BAS FLOPPY.BAS QR.BAS A2_4EVER.BAS + A2.BAS FOURAM.BAS FLOPPY.BAS QR.BAS A2_4EVER.BAS RLE.BAS cp empty.dsk appleiibot.dsk $(DOS33) -y appleiibot.dsk BSAVE -a 0x0300 LOAD $(DOS33) -y appleiibot.dsk SAVE A E2.BAS @@ -37,6 +37,7 @@ appleiibot.dsk: E2.BAS FLAME.BAS FLAME2.BAS \ $(DOS33) -y appleiibot.dsk SAVE A FLOPPY.BAS $(DOS33) -y appleiibot.dsk SAVE A QR.BAS $(DOS33) -y appleiibot.dsk SAVE A A2_4EVER.BAS + $(DOS33) -y appleiibot.dsk SAVE A RLE.BAS ### @@ -215,6 +216,10 @@ FLOPPY.BAS: floppy.bas QR.BAS: qr.bas $(TOKENIZE) < qr.bas > QR.BAS +#### + +RLE.BAS: rle.bas + $(TOKENIZE) < rle.bas > RLE.BAS #### diff --git a/gr-utils/Makefile b/gr-utils/Makefile index cc7638fb..3367145e 100644 --- a/gr-utils/Makefile +++ b/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 + png2sixbitmap png2six80 png2sixrle ### @@ -47,6 +47,15 @@ png2sixbitmap.o: png2sixbitmap.c loadpng.h ### +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 + + +### + png2six80: png2six80.o loadpng.o $(CC) $(LFLAGS) -o png2six80 png2six80.o loadpng.o -lpng @@ -93,8 +102,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 png2six80 $(INSTALL_LOC) + cp png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2six80 $(INSTALL_LOC) clean: - rm -f *~ *.o png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2six80 + rm -f *~ *.o png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2six80 diff --git a/gr-utils/png2sixrle.c b/gr-utils/png2sixrle.c new file mode 100644 index 00000000..8db1455a --- /dev/null +++ b/gr-utils/png2sixrle.c @@ -0,0 +1,80 @@ +#include +#include + +#include +#include +#include +#include +#include + +#include "loadpng.h" + +static int print_rle(int color, int run) { + + int ret=0; + + if ((color&0xf)!=((color>>4)&0xf)) { + fprintf(stderr,"color not match! %x\n",color); + ret=1; + } + if (run>63) { + fprintf(stderr,"Run too big %x\n",run); + ret=1; + } + printf("%c%c",(color&0xf)+' ',run+' '); +// fprintf(stderr,"c=%x run=%x\n",color,run); + + return ret; +} + +/* Converts a PNG to a 6-bit RLE encoding */ + +int main(int argc, char **argv) { + + int row=0; + int col=0; + int color=0,oldcolor=0; + int run=0; + + unsigned char *image; + int xsize,ysize; + + if (argc<2) { + fprintf(stderr,"Usage:\t%s INFILE\n\n",argv[0]); + exit(-1); + } + + if (loadpng(argv[1],&image,&xsize,&ysize,PNG_WHOLETHING)<0) { + fprintf(stderr,"Error loading png!\n"); + exit(-1); + } + + fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize); + + oldcolor=image[0]; + for(row=0;row<24;row++) { + for(col=0;col<40;col++) { + color=image[row*xsize+col]; + if (color!=oldcolor) { + if (print_rle(oldcolor,run)) { + fprintf(stderr,"at %d, %d\n",col,row); + } + oldcolor=color; + run=0; + } + if (run>62) { + if (print_rle(oldcolor,run)) { + fprintf(stderr,"at %d, %d\n",col,row); + } + oldcolor=color; + run=0; + } + + run++; + } + } + print_rle(oldcolor,run); + printf("\n"); + + return 0; +}