7 void print_usage(const char *argv0);
9 int main(int argc, char **argv)
13 char *fname = 0, *outfname = 0;
17 for(i=1; i<argc; i++) {
18 if(argv[i][0] == '-') {
39 fprintf(stderr, "%s must be followed by a filename\n", argv[i - 1]);
50 fprintf(stderr, "invalid option: %s\n", argv[i]);
55 fprintf(stderr, "invalid option: %s\n", argv[i]);
61 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
70 fprintf(stderr, "pass the filename of a PNG file\n");
73 if(load_image(&img, fname) == -1) {
74 fprintf(stderr, "failed to load PNG file: %s\n", fname);
79 if(!(out = fopen(outfname, "wb"))) {
80 fprintf(stderr, "failed to open output file: %s: %s\n", outfname, strerror(errno));
87 fwrite(img.pixels, 1, img.scansz * img.height, out);
92 for(i=0; i<img.cmap_ncolors; i++) {
93 printf("%d %d %d\n", img.cmap[i].r, img.cmap[i].g, img.cmap[i].b);
96 fwrite(img.cmap, sizeof img.cmap[0], img.cmap_ncolors, out);
101 printf("size: %dx%d\n", img.width, img.height);
102 printf("bit depth: %d\n", img.bpp);
103 printf("scanline size: %d bytes\n", img.scansz);
104 if(img.cmap_ncolors > 0) {
105 printf("colormap entries: %d\n", img.cmap_ncolors);
107 printf("color channels: %d\n", img.nchan);
116 void print_usage(const char *argv0)
118 printf("Usage: %s [options] <input file>\n", argv0);
119 printf("Options:\n");
120 printf(" -p: dump pixels (default)\n");
121 printf(" -c: dump colormap (palette) entries\n");
122 printf(" -i: print image information\n");
123 printf(" -t: dump as text\n");
124 printf(" -h: print usage and exit\n");