8 void print_usage(const char *argv0);
10 int main(int argc, char **argv)
18 struct image img, tmpimg;
21 for(i=1; i<argc; i++) {
22 if(argv[i][0] == '-') {
47 fprintf(stderr, "%s must be followed by a filename\n", argv[i - 1]);
58 fprintf(stderr, "invalid option: %s\n", argv[i]);
63 fprintf(stderr, "invalid option: %s\n", argv[i]);
68 infiles[num_infiles++] = argv[i];
73 fprintf(stderr, "pass the filename of a PNG file\n");
76 if(load_image(&img, infiles[0]) == -1) {
77 fprintf(stderr, "failed to load PNG file: %s\n", infiles[0]);
81 for(i=1; i<num_infiles; i++) {
82 if(load_image(&tmpimg, infiles[i]) == -1) {
83 fprintf(stderr, "failed to load PNG file: %s\n", infiles[i]);
86 if(tmpimg.width != img.width || tmpimg.height != img.height) {
87 fprintf(stderr, "size mismatch: first image (%s) is %dx%d, %s is %dx%d\n",
88 infiles[0], img.width, img.height, infiles[i], tmpimg.width, tmpimg.height);
91 if(tmpimg.bpp != img.bpp) {
92 fprintf(stderr, "bpp mismatch: first image (%s) is %d bpp, %s is %d bpp\n",
93 infiles[0], img.bpp, infiles[i], img.bpp);
97 overlay_key(&tmpimg, 0, &img);
100 if(img.bpp == 4 && renibble) {
101 unsigned char *ptr = img.pixels;
102 for(i=0; i<img.width * img.height; i++) {
103 unsigned char p = *ptr;
104 *ptr++ = (p << 4) | (p >> 4);
109 if(!(out = fopen(outfname, "wb"))) {
110 fprintf(stderr, "failed to open output file: %s: %s\n", outfname, strerror(errno));
117 fwrite(img.pixels, 1, img.scansz * img.height, out);
122 for(i=0; i<img.cmap_ncolors; i++) {
123 printf("%d %d %d\n", img.cmap[i].r, img.cmap[i].g, img.cmap[i].b);
126 /*fwrite(img.cmap, sizeof img.cmap[0], img.cmap_ncolors, out);*/
127 fwrite(img.cmap, sizeof img.cmap[0], 1 << img.bpp, out);
132 printf("size: %dx%d\n", img.width, img.height);
133 printf("bit depth: %d\n", img.bpp);
134 printf("scanline size: %d bytes\n", img.scansz);
135 if(img.cmap_ncolors > 0) {
136 printf("colormap entries: %d\n", img.cmap_ncolors);
138 printf("color channels: %d\n", img.nchan);
147 void print_usage(const char *argv0)
149 printf("Usage: %s [options] <input file>\n", argv0);
150 printf("Options:\n");
151 printf(" -o <output file>: specify output file (default: stdout)\n");
152 printf(" -p: dump pixels (default)\n");
153 printf(" -c: dump colormap (palette) entries\n");
154 printf(" -i: print image information\n");
155 printf(" -t: dump as text\n");
156 printf(" -n: swap the order of nibbles (for 4bpp)\n");
157 printf(" -h: print usage and exit\n");