gamma correction per color
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 13 Sep 2024 09:23:50 +0000 (11:23 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 13 Sep 2024 09:23:50 +0000 (11:23 +0200)
display.c

index 61dad57209411e1274137ee5feed552c382ce08e..5586260ed10cf5c332ecab723742508f275f4889 100644 (file)
--- a/display.c
+++ b/display.c
 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);
 
@@ -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");