[gimp/goat-invasion: 80/401] app: remove the legacy brightness-contrast code and use GEGL instead



commit b5a4594af144f0671c572b2317bd272a566eed50
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 16 15:43:47 2012 +0100

    app: remove the legacy brightness-contrast code and use GEGL instead
    
    it's reasonably fast now.

 app/base/lut-funcs.c                        |   61 ------------------
 app/base/lut-funcs.h                        |    8 ---
 app/core/Makefile.am                        |    2 -
 app/core/gimpdrawable-brightness-contrast.c |   89 ---------------------------
 app/core/gimpdrawable-brightness-contrast.h |   28 --------
 app/pdb/color-cmds.c                        |   26 ++++++---
 app/tools/gimpbrightnesscontrasttool.c      |   41 ------------
 app/tools/gimpbrightnesscontrasttool.h      |    1 -
 tools/pdbgen/pdb/color.pdb                  |   26 ++++++---
 9 files changed, 36 insertions(+), 246 deletions(-)
---
diff --git a/app/base/lut-funcs.c b/app/base/lut-funcs.c
index f7a2248..ca80f8e 100644
--- a/app/base/lut-funcs.c
+++ b/app/base/lut-funcs.c
@@ -28,67 +28,6 @@
 #include "lut-funcs.h"
 
 
-/* ---------- Brightness/Contrast -----------*/
-
-typedef struct
-{
-  gdouble brightness;
-  gdouble contrast;
-} BrightnessContrastLutData;
-
-static gfloat
-brightness_contrast_lut_func (BrightnessContrastLutData *data,
-                              gint                       nchannels,
-                              gint                       channel,
-                              gfloat                     value)
-{
-  gdouble slant;
-
-  /* return the original value for the alpha channel */
-  if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
-    return value;
-
-  /* apply brightness */
-  if (data->brightness < 0.0)
-    value = value * (1.0 + data->brightness);
-  else
-    value = value + ((1.0 - value) * data->brightness);
-
-  slant = tan ((data->contrast + 1) * G_PI_4);
-  value = (value - 0.5) * slant + 0.5;
-
-  return value;
-}
-
-void
-brightness_contrast_lut_setup (GimpLut *lut,
-                               gdouble  brightness,
-                               gdouble  contrast,
-                               gint     n_channels)
-{
-  BrightnessContrastLutData data;
-
-  g_return_if_fail (lut != NULL);
-
-  data.brightness = brightness;
-  data.contrast   = contrast;
-
-  gimp_lut_setup (lut,
-                  (GimpLutFunc) brightness_contrast_lut_func, &data, n_channels);
-}
-
-GimpLut *
-brightness_contrast_lut_new (gdouble brightness,
-                             gdouble contrast,
-                             gint    n_channels)
-{
-  GimpLut *lut = gimp_lut_new ();
-
-  brightness_contrast_lut_setup (lut, brightness, contrast, n_channels);
-
-  return lut;
-}
-
 /* --------------- equalize ------------- */
 
 typedef struct
diff --git a/app/base/lut-funcs.h b/app/base/lut-funcs.h
index f3bd53d..6e89bf4 100644
--- a/app/base/lut-funcs.h
+++ b/app/base/lut-funcs.h
@@ -19,14 +19,6 @@
 #define __LUT_FUNCS_H__
 
 
-GimpLut * brightness_contrast_lut_new   (gdouble        brightness,
-                                         gdouble        contrast,
-                                         gint           n_channels);
-void      brightness_contrast_lut_setup (GimpLut       *lut,
-                                         gdouble        brightness,
-                                         gdouble        contrast,
-                                         gint           n_channels);
-
 GimpLut * equalize_lut_new              (GimpHistogram *histogram,
                                          gint           n_channels);
 
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index 05f4c26..073cab4 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -122,8 +122,6 @@ libappcore_a_sources = \
 	gimpdrawable.h				\
 	gimpdrawable-blend.c			\
 	gimpdrawable-blend.h			\
-	gimpdrawable-brightness-contrast.c	\
-	gimpdrawable-brightness-contrast.h	\
 	gimpdrawable-bucket-fill.c		\
 	gimpdrawable-bucket-fill.h		\
 	gimpdrawable-color-balance.c		\
diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c
index 63103b0..922495a 100644
--- a/app/pdb/color-cmds.c
+++ b/app/pdb/color-cmds.c
@@ -24,7 +24,6 @@
 #include "pdb-types.h"
 
 #include "base/gimphistogram.h"
-#include "core/gimpdrawable-brightness-contrast.h"
 #include "core/gimpdrawable-color-balance.h"
 #include "core/gimpdrawable-curves.h"
 #include "core/gimpdrawable-equalize.h"
@@ -34,6 +33,7 @@
 #include "core/gimpdrawable-operation.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpparamspecs.h"
+#include "gegl/gimpbrightnesscontrastconfig.h"
 #include "gegl/gimpcolorizeconfig.h"
 #include "gegl/gimpdesaturateconfig.h"
 #include "gegl/gimpposterizeconfig.h"
@@ -66,14 +66,24 @@ brightness_contrast_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) ||
-          ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) ||
-          gimp_drawable_is_indexed (drawable))
-        success = FALSE;
+      if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
+          gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
+          ! gimp_drawable_is_indexed (drawable))
+        {
+          GObject *config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG,
+                                          "brightness", brightness / 127.0,
+                                          "contrast",   contrast   / 127.0,
+                                          NULL);
 
-      if (success)
-        gimp_drawable_brightness_contrast (drawable, progress,
-                                           brightness, contrast);
+          gimp_drawable_apply_operation_by_name (drawable, progress,
+                                                 C_("undo-type", "Brightness-Contrast"),
+                                                 "gimp:brightness-contrast",
+                                                 config, TRUE);
+
+          g_object_unref (config);
+        }
+      else
+        success = FALSE;
     }
 
   return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c
index d372dbc..277f4a2 100644
--- a/app/tools/gimpbrightnesscontrasttool.c
+++ b/app/tools/gimpbrightnesscontrasttool.c
@@ -27,9 +27,6 @@
 
 #include "tools-types.h"
 
-#include "base/gimplut.h"
-#include "base/lut-funcs.h"
-
 #include "gegl/gimpbrightnesscontrastconfig.h"
 
 #include "core/gimpdrawable.h"
@@ -51,8 +48,6 @@
 #define SLIDER_WIDTH 200
 
 
-static void   gimp_brightness_contrast_tool_finalize       (GObject               *object);
-
 static gboolean gimp_brightness_contrast_tool_initialize   (GimpTool              *tool,
                                                             GimpDisplay           *display,
                                                             GError               **error);
@@ -78,7 +73,6 @@ static void   gimp_brightness_contrast_tool_motion         (GimpTool
 static GeglNode *
               gimp_brightness_contrast_tool_get_operation  (GimpImageMapTool      *image_map_tool,
                                                             GObject              **config);
-static void   gimp_brightness_contrast_tool_map            (GimpImageMapTool      *image_map_tool);
 static void   gimp_brightness_contrast_tool_dialog         (GimpImageMapTool      *image_map_tool);
 
 static void   brightness_contrast_config_notify            (GObject                    *object,
@@ -119,12 +113,9 @@ gimp_brightness_contrast_tool_register (GimpToolRegisterCallback  callback,
 static void
 gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *klass)
 {
-  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
   GimpToolClass         *tool_class    = GIMP_TOOL_CLASS (klass);
   GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
 
-  object_class->finalize             = gimp_brightness_contrast_tool_finalize;
-
   tool_class->initialize             = gimp_brightness_contrast_tool_initialize;
   tool_class->button_press           = gimp_brightness_contrast_tool_button_press;
   tool_class->button_release         = gimp_brightness_contrast_tool_button_release;
@@ -136,33 +127,12 @@ gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *klass
   im_tool_class->export_dialog_title = _("Export Brightness-Contrast settings");
 
   im_tool_class->get_operation       = gimp_brightness_contrast_tool_get_operation;
-  im_tool_class->map                 = gimp_brightness_contrast_tool_map;
   im_tool_class->dialog              = gimp_brightness_contrast_tool_dialog;
 }
 
 static void
 gimp_brightness_contrast_tool_init (GimpBrightnessContrastTool *bc_tool)
 {
-  GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (bc_tool);
-
-  bc_tool->lut = gimp_lut_new ();
-
-  im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
-  im_tool->apply_data = bc_tool->lut;
-}
-
-static void
-gimp_brightness_contrast_tool_finalize (GObject *object)
-{
-  GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (object);
-
-  if (bc_tool->lut)
-    {
-      gimp_lut_free (bc_tool->lut);
-      bc_tool->lut = NULL;
-    }
-
-  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static gboolean
@@ -217,17 +187,6 @@ gimp_brightness_contrast_tool_get_operation (GimpImageMapTool  *im_tool,
 }
 
 static void
-gimp_brightness_contrast_tool_map (GimpImageMapTool *im_tool)
-{
-  GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool);
-
-  brightness_contrast_lut_setup (bc_tool->lut,
-                                 bc_tool->config->brightness / 2.0,
-                                 bc_tool->config->contrast,
-                                 gimp_drawable_bytes (im_tool->drawable));
-}
-
-static void
 gimp_brightness_contrast_tool_button_press (GimpTool            *tool,
                                             const GimpCoords    *coords,
                                             guint32              time,
diff --git a/app/tools/gimpbrightnesscontrasttool.h b/app/tools/gimpbrightnesscontrasttool.h
index 5d5b51e..9425c59 100644
--- a/app/tools/gimpbrightnesscontrasttool.h
+++ b/app/tools/gimpbrightnesscontrasttool.h
@@ -38,7 +38,6 @@ struct _GimpBrightnessContrastTool
   GimpImageMapTool              parent_instance;
 
   GimpBrightnessContrastConfig *config;
-  GimpLut                      *lut;
 
   gdouble                       x, y;
   gdouble                       dx, dy;
diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb
index e0417ae..c45cb84 100644
--- a/tools/pdbgen/pdb/color.pdb
+++ b/tools/pdbgen/pdb/color.pdb
@@ -38,17 +38,27 @@ HELP
     );
 
     %invoke = (
-        headers => [ qw("core/gimpdrawable-brightness-contrast.h") ],
+        headers => [ qw("gegl/gimpbrightnesscontrastconfig.h") ],
 	code => <<'CODE'
 {
-  if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) ||
-      ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) ||
-      gimp_drawable_is_indexed (drawable))
-    success = FALSE;
+  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
+      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
+      ! gimp_drawable_is_indexed (drawable))
+    {
+      GObject *config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG,
+                                      "brightness", brightness / 127.0,
+                                      "contrast",   contrast   / 127.0,
+                                      NULL);
 
-  if (success)
-    gimp_drawable_brightness_contrast (drawable, progress,
-                                       brightness, contrast);
+      gimp_drawable_apply_operation_by_name (drawable, progress,
+                                             C_("undo-type", "Brightness-Contrast"),
+                                             "gimp:brightness-contrast",
+                                             config, TRUE);
+
+      g_object_unref (config);
+    }
+  else
+    success = FALSE;
 }
 CODE
     );



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