Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

-d argument

  • Loading branch information...
commit c9be566a1a13f85814171f8b4c694c5b3e788acc 1 parent 7436b18
Kornel authored September 24, 2011

Showing 1 changed file with 24 additions and 3 deletions. Show diff stats Hide diff stats

  1. 27  posterize.c
27  posterize.c
... ...
@@ -1,6 +1,7 @@
1 1
 
2 2
 #include <stdio.h>
3 3
 #include <stdlib.h>
  4
+#include <string.h>
4 5
 #include <assert.h>
5 6
 #include <math.h>
6 7
 #include "png.h"
@@ -167,13 +168,33 @@ void dither_palette(int* palette, int* palette2, int dither)
167 168
     }
168 169
 }
169 170
 
  171
+void usage(const char *exepath)
  172
+{
  173
+    const char *name = strrchr(exepath, '/');
  174
+    if (name) name++; else name = exepath;
  175
+    fprintf(stderr, "Median Cut PNG Posterizer 1.1 (2011).\n" \
  176
+            "Usage: %s [-d] levels\n\n" \
  177
+            "Specify number of levels 2-255 as an argument. -d enables dithering\n" \
  178
+            "Image is always read from stdin and written to stdout.\n"
  179
+            "%s -d 16 < in.png > out.png\n", name, name);
  180
+}
  181
+
170 182
 int main(int argc, char *argv[])
171 183
 {
172  
-    int maxcolors = argc == 2 ? atoi(argv[1]) : 0;
  184
+    int argn=1;
173 185
     int dither=0;
  186
+    if (argc==3 && 0==strcmp("-d", argv[1])) {
  187
+        dither=1;
  188
+        argn++;
  189
+    }
  190
+    int maxcolors=0;
  191
+    if (argc==(argn+1)) {
  192
+        maxcolors=atoi(argv[argn]);
  193
+        argn++;
  194
+    }
174 195
 
175  
-    if (argc != 2 || maxcolors < 2 || maxcolors > 255) {
176  
-        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]);
  196
+    if (argc != argn || maxcolors < 2 || maxcolors > 255) {
  197
+        usage(argv[0]);
177 198
         return 1;
178 199
     }
179 200
 

0 notes on commit c9be566

Please sign in to comment.
Something went wrong with that request. Please try again.