[gimp] Bug 780065 - Change default way to desaturate to Luminance



commit 48e40446729534a43f6673429018296e30cf9cd5
Author: Elle Stone <ellestone ninedegreesbelow com>
Date:   Fri Mar 17 16:20:40 2017 -0400

    Bug 780065 - Change default way to desaturate to Luminance
    
    which unlike HSL Lightness is actually physically meaningful and
    also generally speaking much more useful than HSL Lightness.
    
    Change "Lightness" to "Lightness (HSL)" to make it clear that
    the "Lightness" in the Colors/Desaturate/Desaturate menu is not the
    same as "Lightness" in LAB/LCH.
    
    For completeness add the option to desaturate to "Value (HSV)".
    
    Add links in app/operations/gimpoperationdesaturate.c
    to the Wikipedia article with definitions of L/I/V in HSL/HSI/HSV.

 app/operations/gimpoperationdesaturate.c |   29 ++++++++++++++++++++++++++++-
 libgimpbase/gimpbaseenums.c              |    6 ++++--
 libgimpbase/gimpbaseenums.h              |    9 +++++----
 tools/pdbgen/enums.pl                    |    6 ++++--
 4 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/app/operations/gimpoperationdesaturate.c b/app/operations/gimpoperationdesaturate.c
index 612a93a..9be82fd 100644
--- a/app/operations/gimpoperationdesaturate.c
+++ b/app/operations/gimpoperationdesaturate.c
@@ -90,7 +90,7 @@ gimp_operation_desaturate_class_init (GimpOperationDesaturateClass *klass)
                          _("Mode"),
                          _("Choose shade of gray based on"),
                          GIMP_TYPE_DESATURATE_MODE,
-                         GIMP_DESATURATE_LIGHTNESS,
+                         GIMP_DESATURATE_LUMINANCE,
                          GIMP_PARAM_STATIC_STRINGS);
 }
 
@@ -173,6 +173,9 @@ gimp_operation_desaturate_process (GeglOperation       *operation,
   switch (desaturate->mode)
     {
     case GIMP_DESATURATE_LIGHTNESS:
+      /* This is the formula for Lightness in the HSL "bi-hexcone"
+       * model: https://en.wikipedia.org/wiki/HSL_and_HSV
+       */
       while (samples--)
         {
           gfloat min, max, value;
@@ -211,6 +214,9 @@ gimp_operation_desaturate_process (GeglOperation       *operation,
       break;
 
     case GIMP_DESATURATE_AVERAGE:
+      /* This is the formula for Intensity in the HSI model:
+       * https://en.wikipedia.org/wiki/HSL_and_HSV
+       */
       while (samples--)
         {
           gfloat value = (src[0] + src[1] + src[2]) / 3;
@@ -224,6 +230,27 @@ gimp_operation_desaturate_process (GeglOperation       *operation,
           dest += 4;
         }
       break;
+
+    case GIMP_DESATURATE_VALUE:
+      /* This is the formula for Value in the HSV model:
+       * https://en.wikipedia.org/wiki/HSL_and_HSV
+       */
+      while (samples--)
+        {
+          gfloat value;
+
+          value = MAX (src[0], src[1]);
+          value = MAX (value, src[2]);
+
+          dest[0] = value;
+          dest[1] = value;
+          dest[2] = value;
+          dest[3] = src[3];
+
+          src  += 4;
+          dest += 4;
+        }
+      break;
     }
 
   return TRUE;
diff --git a/libgimpbase/gimpbaseenums.c b/libgimpbase/gimpbaseenums.c
index 6cd34ce..4acfd75 100644
--- a/libgimpbase/gimpbaseenums.c
+++ b/libgimpbase/gimpbaseenums.c
@@ -505,15 +505,17 @@ gimp_desaturate_mode_get_type (void)
     { GIMP_DESATURATE_LUMA, "GIMP_DESATURATE_LUMA", "luma" },
     { GIMP_DESATURATE_AVERAGE, "GIMP_DESATURATE_AVERAGE", "average" },
     { GIMP_DESATURATE_LUMINANCE, "GIMP_DESATURATE_LUMINANCE", "luminance" },
+    { GIMP_DESATURATE_VALUE, "GIMP_DESATURATE_VALUE", "value" },
     { 0, NULL, NULL }
   };
 
   static const GimpEnumDesc descs[] =
   {
-    { GIMP_DESATURATE_LIGHTNESS, NC_("desaturate-mode", "Lightness"), NULL },
+    { GIMP_DESATURATE_LIGHTNESS, NC_("desaturate-mode", "Lightness (HSL)"), NULL },
     { GIMP_DESATURATE_LUMA, NC_("desaturate-mode", "Luma"), NULL },
-    { GIMP_DESATURATE_AVERAGE, NC_("desaturate-mode", "Average"), NULL },
+    { GIMP_DESATURATE_AVERAGE, NC_("desaturate-mode", "Average (HSI Intensity)"), NULL },
     { GIMP_DESATURATE_LUMINANCE, NC_("desaturate-mode", "Luminance"), NULL },
+    { GIMP_DESATURATE_VALUE, NC_("desaturate-mode", "Value (HSV)"), NULL },
     { 0, NULL, NULL }
   };
 
diff --git a/libgimpbase/gimpbaseenums.h b/libgimpbase/gimpbaseenums.h
index 2959408..745db15 100644
--- a/libgimpbase/gimpbaseenums.h
+++ b/libgimpbase/gimpbaseenums.h
@@ -279,10 +279,11 @@ GType gimp_desaturate_mode_get_type (void) G_GNUC_CONST;
 
 typedef enum
 {
-  GIMP_DESATURATE_LIGHTNESS,   /*< desc="Lightness"  >*/
-  GIMP_DESATURATE_LUMA,        /*< desc="Luma"       >*/
-  GIMP_DESATURATE_AVERAGE,     /*< desc="Average"    >*/
-  GIMP_DESATURATE_LUMINANCE,   /*< desc="Luminance"  >*/
+  GIMP_DESATURATE_LIGHTNESS,   /*< desc="Lightness (HSL)"          >*/
+  GIMP_DESATURATE_LUMA,        /*< desc="Luma"                     >*/
+  GIMP_DESATURATE_AVERAGE,     /*< desc="Average (HSI Intensity)"  >*/
+  GIMP_DESATURATE_LUMINANCE,   /*< desc="Luminance"                >*/
+  GIMP_DESATURATE_VALUE,       /*< desc="Value (HSV)"              >*/
 
 #ifndef GIMP_DISABLE_DEPRECATED
   GIMP_DESATURATE_LUMINOSITY = GIMP_DESATURATE_LUMA /*< skip, pdb-skip >*/
diff --git a/tools/pdbgen/enums.pl b/tools/pdbgen/enums.pl
index 688c6d3..6273438 100644
--- a/tools/pdbgen/enums.pl
+++ b/tools/pdbgen/enums.pl
@@ -157,11 +157,13 @@ package Gimp::CodeGen::enums;
        { contig => 1,
          header => 'libgimpbase/gimpbaseenums.h',
          symbols => [ qw(GIMP_DESATURATE_LIGHTNESS GIMP_DESATURATE_LUMA
-                         GIMP_DESATURATE_AVERAGE GIMP_DESATURATE_LUMINANCE) ],
+                         GIMP_DESATURATE_AVERAGE GIMP_DESATURATE_LUMINANCE
+                         GIMP_DESATURATE_VALUE) ],
          mapping => { GIMP_DESATURATE_LIGHTNESS => '0',
                       GIMP_DESATURATE_LUMA => '1',
                       GIMP_DESATURATE_AVERAGE => '2',
-                      GIMP_DESATURATE_LUMINANCE => '3' }
+                      GIMP_DESATURATE_LUMINANCE => '3',
+                      GIMP_DESATURATE_VALUE => '4' }
        },
     GimpDodgeBurnType =>
        { contig => 1,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]