From 62b0678ebcbeda157a0f338b2dec02ad685b8dc4 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 19 Jan 2008 18:45:43 +0100 Subject: add usage --- src/pnmcurve.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/pnmcurve.c b/src/pnmcurve.c index 7f22ba5..49adad2 100644 --- a/src/pnmcurve.c +++ b/src/pnmcurve.c @@ -23,6 +23,19 @@ buildCurve(const char *ctrl_points, int resolution, int maxval); #define GREEN 0x2 #define BLUE 0x4 +static void +usage() { + fprintf(stderr, + "usage: pnmcurve [-rgb] -c \n" + " -r apply curve to red channel.\n" + " -g apply curve to green channel.\n" + " -b apply curve to blue channel.\n" + " -c curve to apply. must be\n" + " of the form x1:y1,x2,y2,x3,y3 where xi,yi are\n" + " control points of a cubic spline curve.\n" + " xi,yi must be in the range [0.0,1.0].\n"); +} + int main(int argc, char **argv) { int c, i; @@ -51,6 +64,11 @@ main(int argc, char **argv) { } } + if (!curve) { + usage(); + exit(1); + } + if (readPnmHeader(stdin, &in_pnm) != 0) { fprintf(stderr, "failed to read PNM file\n"); exit(1); @@ -61,21 +79,19 @@ main(int argc, char **argv) { exit(1); } - if (curve) { - if (channels == 0) channels = RED | GREEN | BLUE; + if (channels == 0) channels = RED | GREEN | BLUE; - table = buildCurve(curve, in_pnm.maxval + 1, in_pnm.maxval); + table = buildCurve(curve, in_pnm.maxval + 1, in_pnm.maxval); - if (!table) { - fprintf(stderr, "could not build table.\n"); - exit(1); - } - - gTable[0] = channels & RED ? table : NULL; - gTable[1] = channels & GREEN ? table : NULL; - gTable[2] = channels & BLUE ? table : NULL; + if (!table) { + fprintf(stderr, "could not build table.\n"); + exit(1); } + gTable[0] = channels & RED ? table : NULL; + gTable[1] = channels & GREEN ? table : NULL; + gTable[2] = channels & BLUE ? table : NULL; + writePnmHeader(stdout, &in_pnm); pam_transform(stdin, stdout, &in_pnm, gTable); -- cgit v1.2.3