8 void print_usage(const char *argv0);
10 int main(int argc, char **argv)
15 char *fname = 0, *outfname = 0;
19 for(i=1; i<argc; i++) {
20 if(argv[i][0] == '-') {
45 fprintf(stderr, "%s must be followed by a filename\n", argv[i - 1]);
56 fprintf(stderr, "invalid option: %s\n", argv[i]);
61 fprintf(stderr, "invalid option: %s\n", argv[i]);
67 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
76 fprintf(stderr, "pass the filename of a PNG file\n");
79 if(load_image(&img, fname) == -1) {
80 fprintf(stderr, "failed to load PNG file: %s\n", fname);
84 if(img.bpp == 4 && renibble) {
85 unsigned char *ptr = img.pixels;
86 for(i=0; i<img.width * img.height; i++) {
87 unsigned char p = *ptr;
88 *ptr++ = (p << 4) | (p >> 4);
93 if(!(out = fopen(outfname, "wb"))) {
94 fprintf(stderr, "failed to open output file: %s: %s\n", outfname, strerror(errno));
101 fwrite(img.pixels, 1, img.scansz * img.height, out);
106 for(i=0; i<img.cmap_ncolors; i++) {
107 printf("%d %d %d\n", img.cmap[i].r, img.cmap[i].g, img.cmap[i].b);
110 fwrite(img.cmap, sizeof img.cmap[0], img.cmap_ncolors, out);
115 printf("size: %dx%d\n", img.width, img.height);
116 printf("bit depth: %d\n", img.bpp);
117 printf("scanline size: %d bytes\n", img.scansz);
118 if(img.cmap_ncolors > 0) {
119 printf("colormap entries: %d\n", img.cmap_ncolors);
121 printf("color channels: %d\n", img.nchan);
130 void print_usage(const char *argv0)
132 printf("Usage: %s [options] <input file>\n", argv0);
133 printf("Options:\n");
134 printf(" -o <output file>: specify output file (default: stdout)\n");
135 printf(" -p: dump pixels (default)\n");
136 printf(" -c: dump colormap (palette) entries\n");
137 printf(" -i: print image information\n");
138 printf(" -t: dump as text\n");
139 printf(" -n: swap the order of nibbles (for 4bpp)\n");
140 printf(" -h: print usage and exit\n");