X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fpngdump%2Fmain.c;fp=tools%2Fpngdump%2Fmain.c;h=71bcd7c3716f67f0ca57d1e6d2449adf0006613f;hb=c4c558a9a9117b47aa6527767656c6f2c2c7afc1;hp=edbbba5cb1c731926e241a23f97f2c176573c7f9;hpb=b8ce2cf8b8329cf8b8bdd6aba8831bfbc93d56e3;p=gbajam21 diff --git a/tools/pngdump/main.c b/tools/pngdump/main.c index edbbba5..71bcd7c 100644 --- a/tools/pngdump/main.c +++ b/tools/pngdump/main.c @@ -12,6 +12,7 @@ enum { MODE_INFO }; +void dump_colormap(struct image *img, int text, FILE *fp); void print_usage(const char *argv0); int main(int argc, char **argv) @@ -20,16 +21,17 @@ int main(int argc, char **argv) int text = 0; int renibble = 0; char *outfname = 0; - char *slut_fname = 0; + char *slut_fname = 0, *cmap_fname = 0; char *infiles[256]; int num_infiles = 0; struct image img, tmpimg; FILE *out = stdout; - FILE *slut_out = 0; + FILE *aux_out; int *shade_lut = 0; int *lutptr; int shade_levels = 8; int maxcol = 0; + int lvl; for(i=1; i 8) { + fprintf(stderr, "colormap output works only for indexed color images\n"); + return 1; + } + if(!(aux_out = fopen(cmap_fname, "wb"))) { + fprintf(stderr, "failed to open colormap output file: %s: %s\n", cmap_fname, strerror(errno)); + return 1; + } + dump_colormap(&img, text, aux_out); + fclose(aux_out); + } + if(img.bpp == 4 && renibble) { unsigned char *ptr = img.pixels; for(i=0; icmap_ncolors; i++) { + fprintf(fp, "%d %d %d\n", img->cmap[i].r, img->cmap[i].g, img->cmap[i].b); + } + } else { + fwrite(img->cmap, sizeof img->cmap[0], 1 << img->bpp, fp); + } +} + void print_usage(const char *argv0) { printf("Usage: %s [options] \n", argv0); printf("Options:\n"); printf(" -o : specify output file (default: stdout)\n"); + printf(" -oc : output colormap to separate file\n"); + printf(" -os : generate and output shading LUT\n"); printf(" -p: dump pixels (default)\n"); printf(" -P: output in PNG format\n"); printf(" -c: dump colormap (palette) entries\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(" -s : used in conjunction with -os (default: 8)\n"); printf(" -i: print image information\n"); printf(" -t: output as text when possible\n"); printf(" -n: swap the order of nibbles (for 4bpp)\n");