mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-02-28 22:30:09 +00:00
dither_lores: not sure if this is worth the trouble
This commit is contained in:
parent
597e5daaa1
commit
6128e55a65
25
dither_lores/Makefile
Normal file
25
dither_lores/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
include ../Makefile.inc
|
||||
|
||||
all: png_to_40x96 katahdin_40_96.inc
|
||||
|
||||
|
||||
katahdin_40_96.inc: png_to_40x96 katahdin_40_96.png
|
||||
./png_to_40x96 asm katahdin_40_96.png katahdin > katahdin_40_96.inc
|
||||
|
||||
loadpng.o: loadpng.c
|
||||
$(CC) $(CFLAGS) -c loadpng.c
|
||||
|
||||
png_to_40x96: png_to_40x96.o loadpng.o
|
||||
$(CC) $(LFLAGS) -lpng -o png_to_40x96 png_to_40x96.o loadpng.o
|
||||
|
||||
png_to_40x96.o: png_to_40x96.c loadpng.h
|
||||
$(CC) $(CFLAGS) -c png_to_40x96.c
|
||||
|
||||
|
||||
install:
|
||||
cp png_to_40x96 $(INSTALL_LOC)
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o *.inc png_to_40x96
|
||||
|
||||
|
BIN
dither_lores/apple_40_48d.png
Normal file
BIN
dither_lores/apple_40_48d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
dither_lores/apple_40_96.png
Normal file
BIN
dither_lores/apple_40_96.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
BIN
dither_lores/apple_orig.jpg
Normal file
BIN
dither_lores/apple_orig.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
66
dither_lores/genpal.c
Normal file
66
dither_lores/genpal.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int gr_colors[16][3]={
|
||||
{ 0, 0, 0},
|
||||
{227, 30, 96},
|
||||
{ 96, 78,189},
|
||||
{255, 68,253},
|
||||
{ 0,163, 96},
|
||||
{156,156,156},
|
||||
{ 20,207,253},
|
||||
{208,195,255},
|
||||
{ 96,114, 3},
|
||||
{255,106, 60},
|
||||
{157,157,157},
|
||||
{255,160,208},
|
||||
{ 20,245, 60},
|
||||
{208,221,141},
|
||||
{114,255,208},
|
||||
{255,255,255},
|
||||
};
|
||||
|
||||
int average(int col1, int col2) {
|
||||
|
||||
double c1,c2,r1;
|
||||
|
||||
c1=col1;
|
||||
c2=col2;
|
||||
|
||||
c1=c1*c1;
|
||||
c2=c2*c2;
|
||||
|
||||
r1=sqrt((c1+c2)/2.0);
|
||||
|
||||
// printf("%lfx%lf=%lf %lf %lf\n",c1,c2,c1*c2,c1*c2/2.0,r1);
|
||||
|
||||
return r1;
|
||||
|
||||
}
|
||||
|
||||
void gen_color(int col1, int col2) {
|
||||
|
||||
printf("%d\t%d\t%d\tUntitled-%d-%d\n",
|
||||
average(gr_colors[col1][0],gr_colors[col2][0]),
|
||||
average(gr_colors[col1][1],gr_colors[col2][1]),
|
||||
average(gr_colors[col1][2],gr_colors[col2][2]),col1,col2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int x,y;
|
||||
|
||||
printf("GIMP Palette\n");
|
||||
printf("Name: Apple II Lores Dither.gpl\n");
|
||||
printf("Columns: 16\n");
|
||||
printf("#\n");
|
||||
for(x=0;x<16;x++) {
|
||||
for(y=0;y<16;y++) {
|
||||
gen_color(x,y);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
dither_lores/katahdin_40_48d.png
Normal file
BIN
dither_lores/katahdin_40_48d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
dither_lores/katahdin_40_96.png
Normal file
BIN
dither_lores/katahdin_40_96.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
dither_lores/katahdin_orig.jpg
Normal file
BIN
dither_lores/katahdin_orig.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 133 KiB |
206
dither_lores/loadpng.c
Normal file
206
dither_lores/loadpng.c
Normal file
@ -0,0 +1,206 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
|
||||
static int convert_color(int color) {
|
||||
|
||||
int c=0;
|
||||
|
||||
switch(color) {
|
||||
case 0x000000: c=0; break; /* black */
|
||||
case 0xe31e60: c=1; break; /* magenta */
|
||||
case 0x604ebd: c=2; break; /* dark blue */
|
||||
case 0xff44fd: c=3; break; /* purple */
|
||||
case 0x00a360: c=4; break; /* dark green */
|
||||
case 0x9c9c9c: c=5; break; /* grey 1 */
|
||||
case 0x14cffd: c=6; break; /* medium blue */
|
||||
case 0xd0c3ff: c=7; break; /* light blue */
|
||||
case 0x607203: c=8; break; /* brown */
|
||||
case 0xff6a3c: c=9; break; /* orange */
|
||||
case 0x9d9d9d: c=10; break; /* grey 2 */
|
||||
case 0xffa0d0: c=11; break; /* pink */
|
||||
case 0x14f53c: c=12; break; /* bright green */
|
||||
case 0xd0dd8d: c=13; break; /* yellow */
|
||||
case 0x72ffd0: c=14; break; /* aqua */
|
||||
case 0xffffff: c=15; break; /* white */
|
||||
default:
|
||||
printf("Unknown color %x\n",color);
|
||||
break;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* expects a PNG where the xsize is *2 */
|
||||
int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize) {
|
||||
|
||||
int x,y;
|
||||
int color;
|
||||
FILE *infile;
|
||||
int debug=0;
|
||||
unsigned char *image,*out_ptr;
|
||||
int width, height;
|
||||
int a2_color;
|
||||
|
||||
png_byte bit_depth;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_bytep *row_pointers;
|
||||
png_byte color_type;
|
||||
// int number_of_passes;
|
||||
|
||||
unsigned char header[8];
|
||||
|
||||
/* open file and test for it being a png */
|
||||
infile = fopen(filename, "rb");
|
||||
if (infile==NULL) {
|
||||
fprintf(stderr,"Error! Could not open %s\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check the header */
|
||||
fread(header, 1, 8, infile);
|
||||
if (png_sig_cmp(header, 0, 8)) {
|
||||
fprintf(stderr,"Error! %s is not a PNG file\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* initialize stuff */
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr) {
|
||||
fprintf(stderr,"Error create_read_struct\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
fprintf(stderr,"Error png_create_info_struct\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, infile);
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
width = png_get_image_width(png_ptr, info_ptr);
|
||||
height = png_get_image_height(png_ptr, info_ptr);
|
||||
*xsize=width/2;
|
||||
*ysize=height;
|
||||
|
||||
color_type = png_get_color_type(png_ptr, info_ptr);
|
||||
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
||||
|
||||
|
||||
|
||||
if (debug) {
|
||||
printf("PNG: width=%d height=%d depth=%d\n",width,height,bit_depth);
|
||||
if (color_type==PNG_COLOR_TYPE_RGB) printf("Type RGB\n");
|
||||
else if (color_type==PNG_COLOR_TYPE_RGB_ALPHA) printf("Type RGBA\n");
|
||||
else if (color_type==PNG_COLOR_TYPE_PALETTE) printf("Type palette\n");
|
||||
}
|
||||
|
||||
// number_of_passes = png_set_interlace_handling(png_ptr);
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
||||
for (y=0; y<height; y++) {
|
||||
row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
|
||||
}
|
||||
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
fclose(infile);
|
||||
|
||||
image=calloc(width*height/2,sizeof(unsigned char));
|
||||
if (image==NULL) {
|
||||
fprintf(stderr,"Memory error!\n");
|
||||
return -1;
|
||||
}
|
||||
out_ptr=image;
|
||||
|
||||
if (color_type==PNG_COLOR_TYPE_RGB_ALPHA) {
|
||||
for(y=0;y<height;y+=2) {
|
||||
for(x=0;x<width/2;x++) {
|
||||
|
||||
/* top color */
|
||||
color= (row_pointers[y][x*2*4]<<16)+
|
||||
(row_pointers[y][x*2*4+1]<<8)+
|
||||
(row_pointers[y][x*2*4+2]);
|
||||
if (debug) {
|
||||
printf("%x ",color);
|
||||
}
|
||||
|
||||
a2_color=convert_color(color);
|
||||
|
||||
/* bottom color */
|
||||
color= (row_pointers[y+1][x*2*4]<<16)+
|
||||
(row_pointers[y+1][x*2*4+1]<<8)+
|
||||
(row_pointers[y+1][x*2*4+2]);
|
||||
if (debug) {
|
||||
printf("%x ",color);
|
||||
}
|
||||
|
||||
a2_color|=(convert_color(color)<<4);
|
||||
|
||||
*out_ptr=a2_color;
|
||||
out_ptr++;
|
||||
}
|
||||
if (debug) printf("\n");
|
||||
}
|
||||
}
|
||||
else if (color_type==PNG_COLOR_TYPE_PALETTE) {
|
||||
for(y=0;y<height;y+=2) {
|
||||
for(x=0;x<width/2;x++) {
|
||||
|
||||
/* top color */
|
||||
a2_color=row_pointers[y][x*2];
|
||||
|
||||
/* bottom color */
|
||||
color=row_pointers[y+1][x*2];
|
||||
|
||||
a2_color|=(color<<4);
|
||||
|
||||
if (debug) {
|
||||
printf("%x ",a2_color);
|
||||
}
|
||||
|
||||
*out_ptr=a2_color;
|
||||
out_ptr++;
|
||||
}
|
||||
if (debug) printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Unknown color type\n");
|
||||
}
|
||||
|
||||
/* Stripe test image */
|
||||
// for(x=0;x<40;x++) for(y=0;y<40;y++) image[(y*width)+x]=y%16;
|
||||
|
||||
/*
|
||||
Addr Row /80 %40
|
||||
$400 0 0 0 0
|
||||
$428 28 16 0
|
||||
$450 50 32 0
|
||||
$480 80 2 1
|
||||
$4A8 a8 18 1
|
||||
$4D0 d0 34 1
|
||||
$500 100 3 2
|
||||
0,0 0,1 0,2....0,39 16,0 16,1 ....16,39 32,0..32,39, X X X X X X X X
|
||||
*/
|
||||
|
||||
*image_ptr=image;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
2
dither_lores/loadpng.h
Normal file
2
dither_lores/loadpng.h
Normal file
@ -0,0 +1,2 @@
|
||||
int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize);
|
||||
|
326
dither_lores/png_to_40x96.c
Normal file
326
dither_lores/png_to_40x96.c
Normal file
@ -0,0 +1,326 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "loadpng.h"
|
||||
|
||||
#define OUTPUT_C 0
|
||||
#define OUTPUT_ASM 1
|
||||
|
||||
/* Converts a PNG to RLE compressed data */
|
||||
|
||||
int rle_original(int out_type, char *varname,
|
||||
int xsize,int ysize, unsigned char *image) {
|
||||
|
||||
int run=0;
|
||||
int x;
|
||||
|
||||
int last=-1,next;
|
||||
int size=0;
|
||||
int count=0;
|
||||
|
||||
x=0;
|
||||
|
||||
/* Write out xsize and ysize */
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
fprintf(stdout,"unsigned char %s[]={\n",varname);
|
||||
fprintf(stdout,"\t0x%X,0x%X,",xsize,ysize);
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"%s:",varname);
|
||||
fprintf(stdout,"\t.byte $%X,$%X",xsize,ysize);
|
||||
}
|
||||
|
||||
size+=2;
|
||||
|
||||
/* Get first top/bottom color pair */
|
||||
last=image[x];
|
||||
run++;
|
||||
x++;
|
||||
|
||||
while(1) {
|
||||
|
||||
/* get next top/bottom color pair */
|
||||
next=image[x];
|
||||
|
||||
/* If color change (or too big) then output our run */
|
||||
/* Note 0xff for run length is special case meaning "finished" */
|
||||
if ((next!=last) || (run>253)) {
|
||||
|
||||
/* handle new line */
|
||||
if (out_type==OUTPUT_C) {
|
||||
if (count==0) {
|
||||
printf("\n\t");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (count==0) {
|
||||
printf("\n\t.byte ");
|
||||
}
|
||||
else {
|
||||
printf(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X, ",run,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X",run,last);
|
||||
}
|
||||
size+=2;
|
||||
|
||||
count++;
|
||||
run=0;
|
||||
last=next;
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
/* If we reach the end */
|
||||
if (x>=xsize*(ysize/2)) {
|
||||
run++;
|
||||
/* print tailing value */
|
||||
if (run!=0) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X, ",run,last);
|
||||
}
|
||||
else {
|
||||
if (count==0) {
|
||||
printf("\n\t.byte ");
|
||||
}
|
||||
else {
|
||||
printf(", ");
|
||||
}
|
||||
printf("$%02X,$%02X\n",run,last);
|
||||
}
|
||||
size+=2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
run++;
|
||||
if (count>6) count=0;
|
||||
|
||||
}
|
||||
|
||||
/* Print closing marker */
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
fprintf(stdout,"0xFF,0xFF,");
|
||||
fprintf(stdout,"\t};\n");
|
||||
} else {
|
||||
fprintf(stdout,"\t.byte $FF,$FF\n");
|
||||
}
|
||||
|
||||
size+=2;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/*****************************************/
|
||||
/* \/ \/ */
|
||||
/* Converts a PNG to RLE compressed data */
|
||||
/*****************************************/
|
||||
|
||||
|
||||
static int print_run(int count, int out_type, int run, int last) {
|
||||
|
||||
int size=0;
|
||||
|
||||
if (count==0) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("\n\t");
|
||||
}
|
||||
else {
|
||||
printf("\n\t.byte ");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out_type==OUTPUT_C) {
|
||||
}
|
||||
else {
|
||||
printf(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (run==1) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,",last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X",last);
|
||||
}
|
||||
size++;
|
||||
}
|
||||
if (run==2) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X,",last,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X",last,last);
|
||||
}
|
||||
size+=2;
|
||||
}
|
||||
|
||||
if ((run>2) && (run<16)) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X,",0xA0|run,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X",0xA0|run,last);
|
||||
}
|
||||
size+=2;
|
||||
}
|
||||
|
||||
if (run>=16) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X,0x%02X,",0xA0,run,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X,$%02X",0xA0,run,last);
|
||||
}
|
||||
size+=3;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
int rle_smaller(int out_type, char *varname,
|
||||
int xsize,int ysize, unsigned char *image) {
|
||||
|
||||
int run=0;
|
||||
int x;
|
||||
|
||||
int last=-1,next;
|
||||
int size=0;
|
||||
int count=0;
|
||||
|
||||
x=0;
|
||||
|
||||
/* Write out xsize and ysize */
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
fprintf(stdout,"unsigned char %s[]={\n",varname);
|
||||
fprintf(stdout,"\t0x%X, /* ysize=%d */",xsize,ysize);
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"%s:",varname);
|
||||
fprintf(stdout,"\t.byte $%X ; ysize=%d",xsize,ysize);
|
||||
}
|
||||
|
||||
size+=2;
|
||||
|
||||
/* Get first top/bottom color pair */
|
||||
last=image[x];
|
||||
run++;
|
||||
x++;
|
||||
|
||||
while(1) {
|
||||
|
||||
/* get next top/bottom color pair */
|
||||
next=image[x];
|
||||
|
||||
if ((next&0xf0)==0xA0) {
|
||||
fprintf(stderr,"Warning! Using color A (grey2)!\n");
|
||||
next&=~0xf0;
|
||||
next|=0x50; // substitute grey1
|
||||
}
|
||||
|
||||
/* If color change (or too big) then output our run */
|
||||
/* Note 0xff for run length is special case meaning "finished" */
|
||||
if ((next!=last) || (run>254)) {
|
||||
|
||||
size+=print_run(count,out_type,run,last);
|
||||
|
||||
count++;
|
||||
run=0;
|
||||
last=next;
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
/* If we reach the end */
|
||||
if (x>=xsize*(ysize/2)) {
|
||||
run++;
|
||||
|
||||
size+=print_run(count,out_type,run,last);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
run++;
|
||||
if (count>6) count=0;
|
||||
|
||||
}
|
||||
|
||||
/* Print closing marker */
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
fprintf(stdout,"0xA1,");
|
||||
fprintf(stdout,"\t};\n");
|
||||
} else {
|
||||
fprintf(stdout,"\n\t.byte $A1\n");
|
||||
}
|
||||
|
||||
size+=1;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Converts a PNG to RLE compressed data */
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
unsigned char *image;
|
||||
int xsize,ysize;
|
||||
int size=0;
|
||||
int out_type=OUTPUT_C;
|
||||
|
||||
if (argc<4) {
|
||||
fprintf(stderr,"Usage:\t%s type INFILE varname\n\n",argv[0]);
|
||||
fprintf(stderr,"\ttype: c or asm\n");
|
||||
fprintf(stderr,"\tvarname: label for graphic\n");
|
||||
fprintf(stderr,"\n");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1],"c")) {
|
||||
out_type=OUTPUT_C;
|
||||
}
|
||||
else if (!strcmp(argv[1],"asm")) {
|
||||
out_type=OUTPUT_ASM;
|
||||
}
|
||||
|
||||
if (loadpng(argv[2],&image,&xsize,&ysize)<0) {
|
||||
fprintf(stderr,"Error loading png!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize);
|
||||
|
||||
// size=rle_original(out_type,argv[3],
|
||||
// xsize,ysize,image);
|
||||
|
||||
size=rle_smaller(out_type,argv[3],
|
||||
xsize,ysize,image);
|
||||
|
||||
fprintf(stderr,"Size %d bytes\n",size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user