[gimp] app: use gimp_gegl_dodgeburn() in GimpDodgeBurn



commit 441120b6b55430b2e42f0516f65ad37c755c1a93
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 2 19:17:57 2012 +0200

    app: use gimp_gegl_dodgeburn() in GimpDodgeBurn

 app/paint/gimpdodgeburn.c |  278 ++++++---------------------------------------
 app/paint/gimpdodgeburn.h |    2 -
 2 files changed, 33 insertions(+), 247 deletions(-)
---
diff --git a/app/paint/gimpdodgeburn.c b/app/paint/gimpdodgeburn.c
index c0f8497..b6842f5 100644
--- a/app/paint/gimpdodgeburn.c
+++ b/app/paint/gimpdodgeburn.c
@@ -24,10 +24,7 @@
 
 #include "paint-types.h"
 
-#include "base/gimplut.h"
-#include "base/pixel-region.h"
-#include "base/temp-buf.h"
-
+#include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "core/gimp.h"
@@ -42,37 +39,16 @@
 #include "gimp-intl.h"
 
 
-static void   gimp_dodge_burn_finalize   (GObject            *object);
-
-static void   gimp_dodge_burn_paint      (GimpPaintCore      *paint_core,
-                                          GimpDrawable       *drawable,
-                                          GimpPaintOptions   *paint_options,
-                                          const GimpCoords   *coords,
-                                          GimpPaintState      paint_state,
-                                          guint32             time);
-static void   gimp_dodge_burn_motion     (GimpPaintCore      *paint_core,
-                                          GimpDrawable       *drawable,
-                                          GimpPaintOptions   *paint_options,
-                                          const GimpCoords   *coords);
-
-static void   gimp_dodge_burn_make_luts  (GimpDodgeBurn      *dodgeburn,
-                                          gdouble             db_exposure,
-                                          GimpDodgeBurnType   type,
-                                          GimpTransferMode    mode,
-                                          GimpDrawable       *drawable);
-
-static gfloat gimp_dodge_burn_highlights_lut_func (gpointer   user_data,
-                                                   gint       nchannels,
-                                                   gint       channel,
-                                                   gfloat     value);
-static gfloat gimp_dodge_burn_midtones_lut_func   (gpointer   user_data,
-                                                   gint       nchannels,
-                                                   gint       channel,
-                                                   gfloat     value);
-static gfloat gimp_dodge_burn_shadows_lut_func    (gpointer   user_data,
-                                                   gint       nchannels,
-                                                   gint       channel,
-                                                   gfloat     value);
+static void   gimp_dodge_burn_paint  (GimpPaintCore    *paint_core,
+                                      GimpDrawable     *drawable,
+                                      GimpPaintOptions *paint_options,
+                                      const GimpCoords *coords,
+                                      GimpPaintState    paint_state,
+                                      guint32           time);
+static void   gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
+                                      GimpDrawable     *drawable,
+                                      GimpPaintOptions *paint_options,
+                                      const GimpCoords *coords);
 
 
 G_DEFINE_TYPE (GimpDodgeBurn, gimp_dodge_burn, GIMP_TYPE_BRUSH_CORE)
@@ -95,12 +71,9 @@ gimp_dodge_burn_register (Gimp                      *gimp,
 static void
 gimp_dodge_burn_class_init (GimpDodgeBurnClass *klass)
 {
-  GObjectClass       *object_class     = G_OBJECT_CLASS (klass);
   GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
   GimpBrushCoreClass *brush_core_class = GIMP_BRUSH_CORE_CLASS (klass);
 
-  object_class->finalize  = gimp_dodge_burn_finalize;
-
   paint_core_class->paint = gimp_dodge_burn_paint;
 
   brush_core_class->handles_changing_brush = TRUE;
@@ -112,20 +85,6 @@ gimp_dodge_burn_init (GimpDodgeBurn *dodgeburn)
 }
 
 static void
-gimp_dodge_burn_finalize (GObject *object)
-{
-  GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (object);
-
-  if (dodgeburn->lut)
-    {
-      gimp_lut_free (dodgeburn->lut);
-      dodgeburn->lut = NULL;
-    }
-
-  G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
 gimp_dodge_burn_paint (GimpPaintCore    *paint_core,
                        GimpDrawable     *drawable,
                        GimpPaintOptions *paint_options,
@@ -133,19 +92,9 @@ gimp_dodge_burn_paint (GimpPaintCore    *paint_core,
                        GimpPaintState    paint_state,
                        guint32           time)
 {
-  GimpDodgeBurn        *dodgeburn = GIMP_DODGE_BURN (paint_core);
-  GimpDodgeBurnOptions *options   = GIMP_DODGE_BURN_OPTIONS (paint_options);
-
   switch (paint_state)
     {
     case GIMP_PAINT_STATE_INIT:
-      dodgeburn->lut = gimp_lut_new ();
-
-      gimp_dodge_burn_make_luts (dodgeburn,
-                                 options->exposure,
-                                 options->type,
-                                 options->mode,
-                                 drawable);
       break;
 
     case GIMP_PAINT_STATE_MOTION:
@@ -153,11 +102,6 @@ gimp_dodge_burn_paint (GimpPaintCore    *paint_core,
       break;
 
     case GIMP_PAINT_STATE_FINISH:
-      if (dodgeburn->lut)
-        {
-          gimp_lut_free (dodgeburn->lut);
-          dodgeburn->lut = NULL;
-        }
       break;
     }
 }
@@ -168,25 +112,18 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
                         GimpPaintOptions *paint_options,
                         const GimpCoords *coords)
 {
-  GimpDodgeBurn      *dodgeburn = GIMP_DODGE_BURN (paint_core);
-  GimpContext        *context   = GIMP_CONTEXT (paint_options);
-  GimpDynamics       *dynamics  = GIMP_BRUSH_CORE (paint_core)->dynamics;
-  GimpDynamicsOutput *opacity_output;
-  GimpDynamicsOutput *hardness_output;
-  GimpImage          *image;
-  GeglBuffer         *paint_buffer;
-  gint                paint_buffer_x;
-  gint                paint_buffer_y;
-  const Babl         *orig_format;
-  TempBuf            *orig_temp;
-  GeglBuffer         *orig_buffer;
-  GeglRectangle       orig_rect;
-  PixelRegion         srcPR, tempPR;
-  TempBuf            *db_temp;
-  GeglBuffer         *db_buffer;
-  gdouble             fade_point;
-  gdouble             opacity;
-  gdouble             hardness;
+  GimpDodgeBurnOptions *options   = GIMP_DODGE_BURN_OPTIONS (paint_options);
+  GimpContext          *context   = GIMP_CONTEXT (paint_options);
+  GimpDynamics         *dynamics  = GIMP_BRUSH_CORE (paint_core)->dynamics;
+  GimpDynamicsOutput   *opacity_output;
+  GimpDynamicsOutput   *hardness_output;
+  GimpImage            *image;
+  GeglBuffer           *paint_buffer;
+  gint                  paint_buffer_x;
+  gint                  paint_buffer_y;
+  gdouble               fade_point;
+  gdouble               opacity;
+  gdouble               hardness;
 
   if (gimp_drawable_is_indexed (drawable))
     return;
@@ -213,57 +150,17 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
   if (! paint_buffer)
     return;
 
-  /* Constant painting --get a copy of the orig drawable (with no
-   * paint from this stroke yet)
-   */
-  if (! gimp_rectangle_intersect (paint_buffer_x,
-                                  paint_buffer_y,
-                                  gegl_buffer_get_width  (paint_buffer),
-                                  gegl_buffer_get_height (paint_buffer),
-                                  0, 0,
-                                  gimp_item_get_width  (GIMP_ITEM (drawable)),
-                                  gimp_item_get_height (GIMP_ITEM (drawable)),
-                                  &orig_rect.x,
-                                  &orig_rect.y,
-                                  &orig_rect.width,
-                                  &orig_rect.height))
-    {
-      return;
-    }
-
-  /*  get the original untouched image  */
-  orig_format = gimp_drawable_get_format (drawable);
-
-  orig_temp = temp_buf_new (orig_rect.width, orig_rect.height,
-                            babl_format_get_bytes_per_pixel (orig_format),
-                            0, 0, NULL);
-
-  orig_buffer = gimp_temp_buf_create_buffer (orig_temp, orig_format, TRUE);
-
-  gegl_buffer_copy (gimp_paint_core_get_orig_image (paint_core),
-                    &orig_rect,
-                    orig_buffer,
-                    GEGL_RECTANGLE (0, 0, 0, 0));
-
-  pixel_region_init_temp_buf (&srcPR, orig_temp,
-                              0, 0, orig_rect.width, orig_rect.height);
-
-  /* tempPR will hold the dodgeburned region */
-  db_temp = temp_buf_new (orig_rect.width, orig_rect.height,
-                          babl_format_get_bytes_per_pixel (orig_format),
-                          0, 0, NULL);
-  db_buffer = gimp_temp_buf_create_buffer (db_temp, orig_format, TRUE);
-
-  pixel_region_init_temp_buf (&tempPR, db_temp,
-                              0, 0, db_temp->width, db_temp->height);
-
   /*  DodgeBurn the region  */
-  gimp_lut_process (dodgeburn->lut, &srcPR, &tempPR);
-
-  g_object_unref (orig_buffer);
-
-  gegl_buffer_copy (db_buffer, NULL, paint_buffer, NULL);
-  g_object_unref (db_buffer);
+  gimp_gegl_dodgeburn (gimp_paint_core_get_orig_image (paint_core),
+                       GEGL_RECTANGLE (paint_buffer_x,
+                                       paint_buffer_y,
+                                       gegl_buffer_get_width  (paint_buffer),
+                                       gegl_buffer_get_height (paint_buffer)),
+                       paint_buffer,
+                       GEGL_RECTANGLE (0, 0, 0, 0),
+                       options->exposure / 100.0,
+                       options->type,
+                       options->mode);
 
   hardness_output = gimp_dynamics_get_output (dynamics,
                                               GIMP_DYNAMICS_OUTPUT_HARDNESS);
@@ -282,112 +179,3 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
                                   hardness,
                                   GIMP_PAINT_CONSTANT);
 }
-
-static void
-gimp_dodge_burn_make_luts (GimpDodgeBurn     *dodgeburn,
-                           gdouble            db_exposure,
-                           GimpDodgeBurnType  type,
-                           GimpTransferMode   mode,
-                           GimpDrawable      *drawable)
-{
-  GimpLutFunc   lut_func;
-  gint          nchannels = gimp_drawable_bytes (drawable);
-  static gfloat exposure;
-
-  exposure = db_exposure / 100.0;
-
-  /* make the exposure negative if burn for luts*/
-  if (type == GIMP_BURN)
-    exposure = -exposure;
-
-  switch (mode)
-    {
-    case GIMP_HIGHLIGHTS:
-      lut_func = gimp_dodge_burn_highlights_lut_func;
-      break;
-    case GIMP_MIDTONES:
-      lut_func = gimp_dodge_burn_midtones_lut_func;
-      break;
-    case GIMP_SHADOWS:
-      lut_func = gimp_dodge_burn_shadows_lut_func;
-      break;
-    default:
-      lut_func = NULL;
-      break;
-    }
-
-  gimp_lut_setup_exact (dodgeburn->lut,
-                        lut_func, (gpointer) &exposure,
-                        nchannels);
-}
-
-static gfloat
-gimp_dodge_burn_highlights_lut_func (gpointer  user_data,
-                                     gint      nchannels,
-                                     gint      channel,
-                                     gfloat    value)
-{
-  gfloat *exposure_ptr = (gfloat *) user_data;
-  gfloat  exposure     = *exposure_ptr;
-  gfloat  factor       = 1.0 + exposure * (.333333);
-
-  if ((nchannels == 2 && channel == 1) ||
-      (nchannels == 4 && channel == 3))
-    return value;
-
-  return factor * value;
-}
-
-static gfloat
-gimp_dodge_burn_midtones_lut_func (gpointer  user_data,
-                                   gint      nchannels,
-                                   gint      channel,
-                                   gfloat    value)
-{
-  gfloat *exposure_ptr = (gfloat *) user_data;
-  gfloat  exposure     = *exposure_ptr;
-  gfloat  factor;
-
-  if ((nchannels == 2 && channel == 1) ||
-      (nchannels == 4 && channel == 3))
-    return value;
-
-  if (exposure < 0)
-    factor = 1.0 - exposure * (.333333);
-  else
-    factor = 1 / (1.0 + exposure);
-
-  return pow (value, factor);
-}
-
-static gfloat
-gimp_dodge_burn_shadows_lut_func (gpointer  user_data,
-                                  gint      nchannels,
-                                  gint      channel,
-                                  gfloat    value)
-{
-  gfloat *exposure_ptr = (gfloat *) user_data;
-  gfloat  exposure     = *exposure_ptr;
-  gfloat  new_value;
-  gfloat  factor;
-
-  if ((nchannels == 2 && channel == 1) ||
-      (nchannels == 4 && channel == 3))
-    return value;
-
-  if (exposure >= 0)
-    {
-      factor = 0.333333 * exposure;
-      new_value =  factor + value - factor * value;
-    }
-  else /* exposure < 0 */
-    {
-      factor = -0.333333 * exposure;
-      if (value < factor)
-        new_value = 0;
-      else /*factor <= value <=1*/
-        new_value = (value - factor)/(1 - factor);
-    }
-
-  return new_value;
-}
diff --git a/app/paint/gimpdodgeburn.h b/app/paint/gimpdodgeburn.h
index 854a4f5..9e877eb 100644
--- a/app/paint/gimpdodgeburn.h
+++ b/app/paint/gimpdodgeburn.h
@@ -34,8 +34,6 @@ typedef struct _GimpDodgeBurnClass GimpDodgeBurnClass;
 struct _GimpDodgeBurn
 {
   GimpBrushCore  parent_instance;
-
-  GimpLut       *lut;
 };
 
 struct _GimpDodgeBurnClass



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