X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fpngdump%2Fmain.c;h=2d1922e1118af2a1f4cadda6f898dbfb35ab2d06;hb=7cc6746ff112ccd3fafef1be1a4843a5d972a49c;hp=9f281cc695481f3e7333f2db0c82ad6fd394c374;hpb=95693de3106b0304fe8e5c705c37e633f91a4ad5;p=gbajam21 diff --git a/tools/pngdump/main.c b/tools/pngdump/main.c index 9f281cc..2d1922e 100644 --- a/tools/pngdump/main.c +++ b/tools/pngdump/main.c @@ -6,33 +6,39 @@ #include "image.h" enum { + MODE_PNG, MODE_PIXELS, MODE_CMAP, - MODE_INFO, - MODE_SHADE_CMAP, - MODE_SHADE_LUT + MODE_INFO }; void print_usage(const char *argv0); int main(int argc, char **argv) { - int i, mode = 0; + int i, j, mode = 0; int text = 0; int renibble = 0; char *outfname = 0; + char *slut_fname = 0; char *infiles[256]; int num_infiles = 0; struct image img, tmpimg; FILE *out = stdout; - struct cmapent shade_cmap[256] = {0}; + FILE *slut_out = 0; int *shade_lut = 0; + int *lutptr; int shade_levels = 8; + int maxcol = 0; for(i=1; i 256) { + fprintf(stderr, "-C must be followed by the number of colors to reduce down to\n"); + return 1; + } break; case 's': @@ -76,6 +81,14 @@ int main(int argc, char **argv) outfname = argv[i]; break; + case 'S': + if(!argv[++i]) { + fprintf(stderr, "-S must be followed by a filename\n"); + return 1; + } + slut_fname = argv[i]; + break; + case 'h': print_usage(argv[0]); return 0; @@ -123,6 +136,47 @@ int main(int argc, char **argv) overlay_key(&tmpimg, 0, &img); } + /* generate shading LUT and quantize image as necessary */ + if(slut_fname) { + if(img.bpp > 8) { + fprintf(stderr, "shading LUT generation is only supported for indexed color images\n"); + return 1; + } + if(!(slut_out = fopen(slut_fname, "wb"))) { + fprintf(stderr, "failed to open shading LUT output file: %s: %s\n", slut_fname, strerror(errno)); + return 1; + } + + if(!maxcol) maxcol = 256; + + if(!(shade_lut = malloc(maxcol * shade_levels * sizeof *shade_lut))) { + fprintf(stderr, "failed to allocate shading look-up table\n"); + return 1; + } + + gen_shades(&img, shade_levels, maxcol, shade_lut); + + lutptr = shade_lut; + for(i=0; i: specify output file (default: stdout)\n"); printf(" -p: dump pixels (default)\n"); + printf(" -P: output in PNG format\n"); printf(" -c: dump colormap (palette) entries\n"); - printf(" -C: generate shading colormap\n"); - printf(" -S: generate shading LUT\n"); + printf(" -C : reduce image down to specified number of colors\n"); + printf(" -S : generate and output shading LUT\n"); printf(" -s : used in conjunction with -C or -S (default: 8)\n"); printf(" -i: print image information\n"); - printf(" -t: dump as text\n"); + printf(" -t: output as text when possible\n"); printf(" -n: swap the order of nibbles (for 4bpp)\n"); printf(" -h: print usage and exit\n"); }