[gimp/pippin/linear-is-the-new-black: 3/11] operations: make brightness-contrast, levels and curves operate on linear data



commit 7a551849838e58033d1449987242d3edd1a2ea97
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Dec 14 06:03:15 2016 +0100

    operations: make brightness-contrast, levels and curves operate on linear data
    
    Part of the blunt way to resolve bug #757444

 app/operations/gimpbrightnesscontrastconfig.c    |   16 ++++++++--------
 app/operations/gimpoperationbrightnesscontrast.c |   13 ++++++++++++-
 app/operations/gimpoperationcurves.c             |   11 +++++++++++
 app/operations/gimpoperationlevels.c             |   12 ++++++++++++
 4 files changed, 43 insertions(+), 9 deletions(-)
---
diff --git a/app/operations/gimpbrightnesscontrastconfig.c b/app/operations/gimpbrightnesscontrastconfig.c
index d3b3110..78b59be 100644
--- a/app/operations/gimpbrightnesscontrastconfig.c
+++ b/app/operations/gimpbrightnesscontrastconfig.c
@@ -185,7 +185,7 @@ gimp_brightness_contrast_config_to_levels_config (GimpBrightnessContrastConfig *
 
   if (config->brightness >= 0)
     {
-      value = -0.5 * slant + brightness * slant + 0.5;
+      value = -0.18 * slant + brightness * slant + 0.18;
 
       if (value < 0.0)
         {
@@ -195,45 +195,45 @@ gimp_brightness_contrast_config_to_levels_config (GimpBrightnessContrastConfig *
            * calculation of the brightness/contrast LUT in base/lut-funcs.h */
 
           levels->low_input[GIMP_HISTOGRAM_VALUE] =
-            (- brightness * slant + 0.5 * slant - 0.5) / (slant - brightness * slant);
+            (- brightness * slant + 0.18 * slant - 0.18) / (slant - brightness * slant);
         }
 
       levels->low_output[GIMP_HISTOGRAM_VALUE] = value;
 
-      value = 0.5 * slant + 0.5;
+      value = 0.82 * slant + 0.18;
 
       if (value > 1.0)
         {
           value = 1.0;
 
           levels->high_input[GIMP_HISTOGRAM_VALUE] =
-            (- brightness * slant + 0.5 * slant + 0.5) / (slant - brightness * slant);
+            (- brightness * slant + 0.18 * slant + 0.82) / (slant - brightness * slant);
         }
 
       levels->high_output[GIMP_HISTOGRAM_VALUE] = value;
     }
   else
     {
-      value = 0.5 - 0.5 * slant;
+      value = 0.18 - 0.18 * slant;
 
       if (value < 0.0)
         {
           value = 0.0;
 
           levels->low_input[GIMP_HISTOGRAM_VALUE] =
-            (0.5 * slant - 0.5) / (slant + brightness * slant);
+            (0.18 * slant - 0.18) / (slant + brightness * slant);
         }
 
       levels->low_output[GIMP_HISTOGRAM_VALUE] = value;
 
-      value = slant * brightness + slant * 0.5 + 0.5;
+      value = slant * brightness + slant * 0.82 + 0.18;
 
       if (value > 1.0)
         {
           value = 1.0;
 
           levels->high_input[GIMP_HISTOGRAM_VALUE] =
-            (0.5 * slant + 0.5) / (slant + brightness * slant);
+            (0.18 * slant + 0.82) / (slant + brightness * slant);
         }
 
       levels->high_output[GIMP_HISTOGRAM_VALUE] = value;
diff --git a/app/operations/gimpoperationbrightnesscontrast.c 
b/app/operations/gimpoperationbrightnesscontrast.c
index e21f149..656624c 100644
--- a/app/operations/gimpoperationbrightnesscontrast.c
+++ b/app/operations/gimpoperationbrightnesscontrast.c
@@ -41,6 +41,7 @@ static gboolean gimp_operation_brightness_contrast_process (GeglOperation
                                                             gint                 level);
 
 
+static void gimp_operation_brightness_contrast_prepare (GeglOperation *operation);
 G_DEFINE_TYPE (GimpOperationBrightnessContrast, gimp_operation_brightness_contrast,
                GIMP_TYPE_OPERATION_POINT_FILTER)
 
@@ -64,6 +65,7 @@ gimp_operation_brightness_contrast_class_init (GimpOperationBrightnessContrastCl
                                  NULL);
 
   point_class->process         = gimp_operation_brightness_contrast_process;
+  operation_class->prepare = gimp_operation_brightness_contrast_prepare;
 
   g_object_class_install_property (object_class,
                                    GIMP_OPERATION_POINT_FILTER_PROP_CONFIG,
@@ -80,6 +82,15 @@ gimp_operation_brightness_contrast_init (GimpOperationBrightnessContrast *self)
 {
 }
 
+static void
+gimp_operation_brightness_contrast_prepare (GeglOperation *operation)
+{
+  const Babl *format = babl_format ("RGBA float");
+
+  gegl_operation_set_format (operation, "input",  format);
+  gegl_operation_set_format (operation, "output", format);
+}
+
 static inline gfloat
 gimp_operation_brightness_contrast_map (gfloat  value,
                                         gdouble brightness,
@@ -91,7 +102,7 @@ gimp_operation_brightness_contrast_map (gfloat  value,
   else
     value = value + ((1.0 - value) * brightness);
 
-  value = (value - 0.5) * slant + 0.5;
+  value = (value - 0.18) * slant + 0.18;
 
   return value;
 }
diff --git a/app/operations/gimpoperationcurves.c b/app/operations/gimpoperationcurves.c
index 87eed55..781c667 100644
--- a/app/operations/gimpoperationcurves.c
+++ b/app/operations/gimpoperationcurves.c
@@ -42,6 +42,7 @@ static gboolean gimp_operation_curves_process (GeglOperation       *operation,
                                                const GeglRectangle *roi,
                                                gint                 level);
 
+static void gimp_operation_curves_prepare (GeglOperation *operation);
 
 G_DEFINE_TYPE (GimpOperationCurves, gimp_operation_curves,
                GIMP_TYPE_OPERATION_POINT_FILTER)
@@ -66,6 +67,7 @@ gimp_operation_curves_class_init (GimpOperationCurvesClass *klass)
                                  NULL);
 
   point_class->process = gimp_operation_curves_process;
+  operation_class->prepare = gimp_operation_curves_prepare;
 
   g_object_class_install_property (object_class,
                                    GIMP_OPERATION_POINT_FILTER_PROP_CONFIG,
@@ -78,6 +80,15 @@ gimp_operation_curves_class_init (GimpOperationCurvesClass *klass)
 }
 
 static void
+gimp_operation_curves_prepare (GeglOperation *operation)
+{
+  const Babl *format = babl_format ("RGBA float");
+
+  gegl_operation_set_format (operation, "input",  format);
+  gegl_operation_set_format (operation, "output", format);
+}
+
+static void
 gimp_operation_curves_init (GimpOperationCurves *self)
 {
 }
diff --git a/app/operations/gimpoperationlevels.c b/app/operations/gimpoperationlevels.c
index 415a9da..cc3ecdc 100644
--- a/app/operations/gimpoperationlevels.c
+++ b/app/operations/gimpoperationlevels.c
@@ -38,6 +38,7 @@ static gboolean gimp_operation_levels_process (GeglOperation       *operation,
                                                glong                samples,
                                                const GeglRectangle *roi,
                                                gint                 level);
+static void gimp_operation_levels_prepare (GeglOperation *operation);
 
 
 G_DEFINE_TYPE (GimpOperationLevels, gimp_operation_levels,
@@ -46,6 +47,7 @@ G_DEFINE_TYPE (GimpOperationLevels, gimp_operation_levels,
 #define parent_class gimp_operation_levels_parent_class
 
 
+
 static void
 gimp_operation_levels_class_init (GimpOperationLevelsClass *klass)
 {
@@ -62,6 +64,7 @@ gimp_operation_levels_class_init (GimpOperationLevelsClass *klass)
                                  "description", "GIMP Levels operation",
                                  NULL);
 
+  operation_class->prepare = gimp_operation_levels_prepare;
   point_class->process = gimp_operation_levels_process;
 
   g_object_class_install_property (object_class,
@@ -75,6 +78,15 @@ gimp_operation_levels_class_init (GimpOperationLevelsClass *klass)
 }
 
 static void
+gimp_operation_levels_prepare (GeglOperation *operation)
+{
+  const Babl *format = babl_format ("RGBA float");
+
+  gegl_operation_set_format (operation, "input",  format);
+  gegl_operation_set_format (operation, "output", format);
+}
+
+static void
 gimp_operation_levels_init (GimpOperationLevels *self)
 {
 }


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