Skip to content

Commit

Permalink
-d argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 24, 2011
1 parent 7436b18 commit c9be566
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions posterize.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include "png.h"
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c9be566

Please sign in to comment.