mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-12-27 17:29:49 +00:00
gr-utils: add a png to 16x16 util
This commit is contained in:
parent
b09b6953d0
commit
d2c476115b
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
95
utils/gr-utils/png_16x16.c
Normal file
95
utils/gr-utils/png_16x16.c
Normal file
@ -0,0 +1,95 @@
|
||||
/* Convert 16x16 PNGs to 8+128 text for use in AppleII Basic bot loader */
|
||||
|
||||
#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 color_count=0;
|
||||
static int colors[16];
|
||||
|
||||
static int find_color(int which) {
|
||||
int i;
|
||||
|
||||
for(i=0;i<color_count;i++) {
|
||||
if (colors[i]==which) {
|
||||
// printf("Found %d at %d\n",which,i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/* not found */
|
||||
colors[color_count]=which;
|
||||
// printf("New %d at %d\n",which,color_count);
|
||||
color_count++;
|
||||
|
||||
return color_count-1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int i = 0, row,col;
|
||||
unsigned char in[1024];
|
||||
int op=0;
|
||||
int color;
|
||||
|
||||
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);
|
||||
|
||||
memset(in,0,sizeof(in));
|
||||
|
||||
memset(colors,0,sizeof(colors));
|
||||
|
||||
for(row=0;row<ysize;row+=2) {
|
||||
for(i=0;i<2;i++) {
|
||||
for(col=0;col<xsize;col++) {
|
||||
if (i==0) {
|
||||
color=find_color(image[row/2*xsize+col]&0xf);
|
||||
}
|
||||
else {
|
||||
color=find_color(image[row/2*xsize+col]>>4);
|
||||
}
|
||||
in[op]=color;
|
||||
op++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Raw Image was %d bytes, %d colors\n",op,color_count);
|
||||
|
||||
#if 0
|
||||
for(i=0;i<color_count;i++) {
|
||||
printf("Color %d = %d (%c)\n",i,colors[i],colors[i]+35);
|
||||
}
|
||||
|
||||
for(i=0;i<op;i++) {
|
||||
printf("%d,",in[i]);
|
||||
if (i%16==15) printf("\n");
|
||||
}
|
||||
#endif
|
||||
for(i=0;i<8;i++) printf("%c",colors[i]+35);
|
||||
|
||||
for(i=0;i<op;i+=2) printf("%c",((in[i+1]<<3)+in[i])+35);
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user