summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pnmcurve.c38
1 files changed, 27 insertions, 11 deletions
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 <curve>\n"
+ " -r apply curve to red channel.\n"
+ " -g apply curve to green channel.\n"
+ " -b apply curve to blue channel.\n"
+ " -c <curve> curve to apply. <curve> 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);