From 7f0abdeb470ee65ddcb706d673f1850b6331e647 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Fri, 13 Sep 2024 11:23:50 +0200 Subject: [PATCH] gamma correction per color --- display.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/display.c b/display.c index 61dad57..5586260 100644 --- a/display.c +++ b/display.c @@ -18,14 +18,14 @@ 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] \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); @@ -53,6 +53,7 @@ int main (int argc, char *argv[]) /* process argument */ while (argc-- > 1) { + char *pt = NULL; char *arg = *(++argv); if (arg[0] != '-') { filename = arg; @@ -66,7 +67,19 @@ int main (int argc, char *argv[]) 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: @@ -75,8 +88,8 @@ int main (int argc, char *argv[]) } /* 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) { @@ -91,7 +104,7 @@ int main (int argc, char *argv[]) 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"); -- 2.30.2