diff --git a/utils/gr-utils/loadpng.c b/utils/gr-utils/loadpng.c index 9190bfcc..4686f56b 100644 --- a/utils/gr-utils/loadpng.c +++ b/utils/gr-utils/loadpng.c @@ -1,4 +1,5 @@ /* Loads a 80x48 (or 40x48) PNG image into a 40x48 Apple II layout */ +/* Also supports 280x192 */ /* It's not interleaved like an actual Apple II */ /* But the top/bottom are pre-packed into a naive 40x24 array */ @@ -46,12 +47,15 @@ static int convert_color(int color, char *filename) { return c; } -/* expects a PNG where the xsize is either 40 or 80 */ +/* expects a PNG where the xsize is either 40 or 80 or 280 */ /* if it is 80, it skips every other */ +/* if 280, it skips every 7 */ /* why do that? when editing an image the aspect ratio looks better if */ /* it is an 80 wide picture */ +/* xsize, ysize is the size of the result, not size of */ +/* the input image */ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, int png_type) { @@ -106,17 +110,26 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, width = png_get_image_width(png_ptr, info_ptr); height = png_get_image_height(png_ptr, info_ptr); + /* get the xadd */ if (width==40) { *xsize=40; xadd=1; + yadd=1; } else if (width==80) { *xsize=40; xadd=2; + yadd=1; + } + else if (width==280) { + *xsize=40; + xadd=7; + yadd=4; /* FIXME: check we are 192 in ysize */ } else if (width==16) { *xsize=16; xadd=1; + yadd=1; } else { fprintf(stderr,"Unsupported width %d\n",width); @@ -126,17 +139,17 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize, if (png_type==PNG_WHOLETHING) { *ysize=height; ystart=0; - yadd=2; + yadd*=2; } else if (png_type==PNG_ODDLINES) { *ysize=height/2; ystart=1; - yadd=4; + yadd*=4; } else if (png_type==PNG_EVENLINES) { *ysize=height/2; ystart=0; - yadd=4; + yadd*=4; } else if (png_type==PNG_RAW) { /* FIXME, not working */ diff --git a/utils/gr-utils/png2gr.c b/utils/gr-utils/png2gr.c index a9230fa0..e54cb0f0 100644 --- a/utils/gr-utils/png2gr.c +++ b/utils/gr-utils/png2gr.c @@ -9,6 +9,15 @@ #include "loadpng.h" + +static short gr_offsets[]={ + 0x400,0x480,0x500,0x580,0x600,0x680,0x700,0x780, + 0x428,0x4a8,0x528,0x5a8,0x628,0x6a8,0x728,0x7a8, + 0x450,0x4d0,0x550,0x5d0,0x650,0x6d0,0x750,0x7d0, +}; + + + /* Converts a PNG to a GR file you can BLOAD to 0x400 */ /* HOWEVER you *never* want to do this in real life */ /* as it will clobber important values in the memory holes */ @@ -42,16 +51,12 @@ int main(int argc, char **argv) { fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize); - short gr_offsets[]={ - 0x400,0x480,0x500,0x580,0x600,0x680,0x700,0x780, - 0x428,0x4a8,0x528,0x5a8,0x628,0x6a8,0x728,0x7a8, - 0x450,0x4d0,0x550,0x5d0,0x650,0x6d0,0x750,0x7d0, - }; memset(out_buffer,0,1024); for(row=0;row<24;row++) { for(col=0;col<40;col++) { - out_buffer[(gr_offsets[row]-0x400)+col]=image[row*xsize+col]; + out_buffer[(gr_offsets[row]-0x400)+col]= + image[row*xsize+col]; } }