gr-utils: add png2sixrle

This commit is contained in:
Vince Weaver 2020-10-27 16:45:11 -04:00
parent ecf106a7fa
commit 6665bae631
3 changed files with 98 additions and 4 deletions

View File

@ -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
####

View File

@ -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

80
gr-utils/png2sixrle.c Normal file
View File

@ -0,0 +1,80 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#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;
}