char *progname = NULL;
char *version = "0.1";
-float fgamma = 1.0;
+float gf[3] = { 1.0, 1.0, 1.0 };
/* help message */
int usage (int ret)
{
FILE *fd = ret ? stderr : stdout;
fprintf (fd, "usage: %s [-g gamma] [-h] <file>\n", progname);
- fprintf (fd, " -g: gamma correction (%.1f)\n", fgamma);
+ fprintf (fd, " -g: gamma correction (%.1f:%.1f:%.1f)\n", gf[0], gf[1], gf[2]);
fprintf (fd, " -h: help message\n");
fprintf (fd, "%s version %s\n", progname, version);
/* process argument */
while (argc-- > 1) {
+ char *pt = NULL;
char *arg = *(++argv);
if (arg[0] != '-') {
filename = arg;
VERBOSE (ERROR, fprintf (stderr, "%s: no gamma specified\n", progname));
return usage (1);
}
- fgamma = strtof (arg, NULL);
+ gf[0] = strtof (arg, &pt);
+ if (*pt == '\0') {
+ gf[1] = gf[2] = gf[0];
+ } else if (*pt == ':') {
+ gf[1] = strtof (pt + 1, &pt);
+ if (*pt == ':') {
+ gf[2] = strtof (pt + 1, &pt);
+ } else {
+ gf[2] = 0;
+ }
+ } else {
+ gf[1] = gf[2] = 0;
+ }
break;
case 'h':
default:
}
/* check */
- if (fgamma <= 0) {
- VERBOSE (ERROR, fprintf (stderr, "incorrect gamma (%.1f)\n", fgamma));
+ if ((gf[0] <= 0) || (gf[1] <= 0) || (gf[2] <= 0)) {
+ VERBOSE (ERROR, fprintf (stderr, "incorrect gamma (%.1f:%.1f;%.1f)\n", gf[0], gf[1], gf[2]));
return 1;
}
if (filename == NULL) {
for (l = 0; l < image->height; l++) {
for (k = 0; k < image->width; k++) {
int ind = k + image->width * l;
- color_t *color = findcolor (correction (image->red[ind], fgamma), correction (image->green[ind], fgamma), correction (image->blue[ind], fgamma));
+ color_t *color = findcolor (correction (image->red[ind], gf[0]), correction (image->green[ind], gf[1]), correction (image->blue[ind], gf[2]));
cprint (color, " ");
}
printf ("\n");