Permalink
Browse files

-d argument

  • Loading branch information...
kornelski committed Sep 24, 2011
1 parent 7436b18 commit c9be566a1a13f85814171f8b4c694c5b3e788acc
Showing with 24 additions and 3 deletions.
  1. +24 −3 posterize.c
View
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#include <math.h>
#include "png.h"
@@ -167,13 +168,33 @@ void dither_palette(int* palette, int* palette2, int dither)
}
}
+void usage(const char *exepath)
+{
+ const char *name = strrchr(exepath, '/');
+ if (name) name++; else name = exepath;
+ fprintf(stderr, "Median Cut PNG Posterizer 1.1 (2011).\n" \
+ "Usage: %s [-d] levels\n\n" \
+ "Specify number of levels 2-255 as an argument. -d enables dithering\n" \
+ "Image is always read from stdin and written to stdout.\n"
+ "%s -d 16 < in.png > out.png\n", name, name);
+}
+
int main(int argc, char *argv[])
{
- int maxcolors = argc == 2 ? atoi(argv[1]) : 0;
+ int argn=1;
int dither=0;
+ if (argc==3 && 0==strcmp("-d", argv[1])) {
+ dither=1;
+ argn++;
+ }
+ int maxcolors=0;
+ if (argc==(argn+1)) {
+ maxcolors=atoi(argv[argn]);
+ argn++;
+ }
- if (argc != 2 || maxcolors < 2 || maxcolors > 255) {
- fprintf(stderr, "Median Cut PNG Posterizer 1.0 (2011).\n\nSpecify number of levels 2-255 as an argument.\nImage is read from stdin and written to stdout\n\n%s 16 < in.png > out.png\n", argv[0]);
+ if (argc != argn || maxcolors < 2 || maxcolors > 255) {
+ usage(argv[0]);
return 1;
}

0 comments on commit c9be566

Please sign in to comment.