mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-08-12 12:29:04 +00:00
gr-utils: add png2rle
This commit is contained in:
parent
554913e927
commit
6fb8ad2143
@ -2,21 +2,36 @@ include ../Makefile.inc
|
|||||||
|
|
||||||
CFLAGS = -g -Wall -O2
|
CFLAGS = -g -Wall -O2
|
||||||
|
|
||||||
all: png2gr
|
all: png2gr png2rle
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
loadpng.o: loadpng.c loadpng.h
|
loadpng.o: loadpng.c loadpng.h
|
||||||
$(CC) $(CFLAGS) -c loadpng.c
|
$(CC) $(CFLAGS) -c loadpng.c
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
png2gr: png2gr.o loadpng.o
|
png2gr: png2gr.o loadpng.o
|
||||||
$(CC) $(LFLAGS) -lpng -o png2gr png2gr.o loadpng.o
|
$(CC) $(LFLAGS) -lpng -o png2gr png2gr.o loadpng.o
|
||||||
|
|
||||||
png2gr.o: png2gr.c loadpng.h
|
png2gr.o: png2gr.c loadpng.h
|
||||||
$(CC) $(CFLAGS) -c png2gr.c
|
$(CC) $(CFLAGS) -c png2gr.c
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
png2rle: png2rle.o loadpng.o
|
||||||
|
$(CC) $(LFLAGS) -lpng -o png2rle png2rle.o loadpng.o
|
||||||
|
|
||||||
|
png2rle.o: png2rle.c loadpng.h
|
||||||
|
$(CC) $(CFLAGS) -c png2rle.c
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp png2gr $(INSTALL_LOC)
|
cp png2gr png2rle $(INSTALL_LOC)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *~ *.o png2gr
|
rm -f *~ *.o png2gr png2rle
|
||||||
|
|
||||||
|
74
gr-utils/png2rle.c
Normal file
74
gr-utils/png2rle.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "loadpng.h"
|
||||||
|
|
||||||
|
/* Converts a PNG to RLE compressed data */
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
int enough=0,run=0;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
unsigned char *image;
|
||||||
|
int xsize,ysize,last=-1,next;
|
||||||
|
FILE *outfile;
|
||||||
|
|
||||||
|
if (argc<3) {
|
||||||
|
fprintf(stderr,"Usage:\t%s INFILE OUTFILE\n\n",argv[0]);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
outfile=fopen(argv[2],"w");
|
||||||
|
if (outfile==NULL) {
|
||||||
|
fprintf(stderr,"Error! Could not open %s\n",argv[2]);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loadpng(argv[1],&image,&xsize,&ysize)<0) {
|
||||||
|
fprintf(stderr,"Error loading png!\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Loaded image %d by %d\n",xsize,ysize);
|
||||||
|
|
||||||
|
x=0;
|
||||||
|
enough=0;
|
||||||
|
fprintf(outfile,"0x%X,0x%x,\n",xsize,ysize);
|
||||||
|
last=image[x] | (image[x+xsize]<<4);
|
||||||
|
run++;
|
||||||
|
x++;
|
||||||
|
while(1) {
|
||||||
|
next=image[x] | (image[x+xsize]<<4);
|
||||||
|
|
||||||
|
if (next!=last) {
|
||||||
|
fprintf(outfile,"0x%02X,0x%02X,\n",run,last);
|
||||||
|
run=0;
|
||||||
|
last=next;
|
||||||
|
}
|
||||||
|
|
||||||
|
run++;
|
||||||
|
|
||||||
|
|
||||||
|
x++;
|
||||||
|
enough++;
|
||||||
|
if (enough>=xsize) {
|
||||||
|
enough=0;
|
||||||
|
x+=xsize;
|
||||||
|
fprintf(outfile," ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (x>xsize*ysize) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(outfile);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user