[gimp] app: implement GimpPickable::get_pixel_average() in various classes



commit 25490b0251835daf37989f7e1307613e17ed862a
Author: Ell <ell_se yahoo com>
Date:   Fri May 18 14:57:19 2018 -0400

    app: implement GimpPickable::get_pixel_average() in various classes
    
    Implement GimpPickable::get_pixel_average(), added in the previous
    commit, in GimpDrawable, GimpImage, and GimpProjection, using
    gimp_gegl_average_color(), added in the commit before last.  This
    is significantly faster than the default implementation.

 app/core/gimpdrawable.c   |   19 +++++++++++++++++++
 app/core/gimpimage.c      |   17 +++++++++++++++++
 app/core/gimpprojection.c |   18 ++++++++++++++++++
 3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index ac07d0a..7a134b3 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -29,6 +29,7 @@
 
 #include "gegl/gimp-babl.h"
 #include "gegl/gimp-gegl-apply-operation.h"
+#include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimp-memsize.h"
@@ -149,6 +150,11 @@ static gboolean   gimp_drawable_get_pixel_at       (GimpPickable      *pickable,
                                                     gint               y,
                                                     const Babl        *format,
                                                     gpointer           pixel);
+static void       gimp_drawable_get_pixel_average  (GimpPickable      *pickable,
+                                                    const GeglRectangle *rect,
+                                                    const Babl        *format,
+                                                    gpointer           pixel);
+
 static void       gimp_drawable_real_update        (GimpDrawable      *drawable,
                                                     gint               x,
                                                     gint               y,
@@ -302,6 +308,7 @@ gimp_pickable_iface_init (GimpPickableInterface *iface)
   iface->get_format_with_alpha = (const Babl    * (*) (GimpPickable *pickable)) 
gimp_drawable_get_format_with_alpha;
   iface->get_buffer            = (GeglBuffer    * (*) (GimpPickable *pickable)) gimp_drawable_get_buffer;
   iface->get_pixel_at          = gimp_drawable_get_pixel_at;
+  iface->get_pixel_average     = gimp_drawable_get_pixel_average;
 }
 
 static void
@@ -711,6 +718,18 @@ gimp_drawable_get_pixel_at (GimpPickable *pickable,
 }
 
 static void
+gimp_drawable_get_pixel_average (GimpPickable        *pickable,
+                                 const GeglRectangle *rect,
+                                 const Babl          *format,
+                                 gpointer             pixel)
+{
+  GimpDrawable *drawable = GIMP_DRAWABLE (pickable);
+
+  return gimp_gegl_average_color (gimp_drawable_get_buffer (drawable),
+                                  rect, TRUE, GEGL_ABYSS_NONE, format, pixel);
+}
+
+static void
 gimp_drawable_real_update (GimpDrawable *drawable,
                            gint          x,
                            gint          y,
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 894eb19..2af10d8 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -207,6 +207,10 @@ static gboolean     gimp_image_get_pixel_at      (GimpPickable      *pickable,
 static gdouble      gimp_image_get_opacity_at    (GimpPickable      *pickable,
                                                   gint               x,
                                                   gint               y);
+static void         gimp_image_get_pixel_average (GimpPickable      *pickable,
+                                                  const GeglRectangle *rect,
+                                                  const Babl        *format,
+                                                  gpointer           pixel);
 static void         gimp_image_pixel_to_srgb     (GimpPickable      *pickable,
                                                   const Babl        *format,
                                                   gpointer           pixel,
@@ -679,6 +683,7 @@ gimp_pickable_iface_init (GimpPickableInterface *iface)
   iface->get_buffer            = gimp_image_get_buffer;
   iface->get_pixel_at          = gimp_image_get_pixel_at;
   iface->get_opacity_at        = gimp_image_get_opacity_at;
+  iface->get_pixel_average     = gimp_image_get_pixel_average;
   iface->pixel_to_srgb         = gimp_image_pixel_to_srgb;
   iface->srgb_to_pixel         = gimp_image_srgb_to_pixel;
 }
@@ -1492,6 +1497,18 @@ gimp_image_get_opacity_at (GimpPickable *pickable,
 }
 
 static void
+gimp_image_get_pixel_average (GimpPickable        *pickable,
+                              const GeglRectangle *rect,
+                              const Babl          *format,
+                              gpointer             pixel)
+{
+  GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (pickable);
+
+  return gimp_pickable_get_pixel_average (GIMP_PICKABLE (private->projection),
+                                          rect, format, pixel);
+}
+
+static void
 gimp_image_pixel_to_srgb (GimpPickable *pickable,
                           const Babl   *format,
                           gpointer      pixel,
diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c
index fcf330a..b3d1004 100644
--- a/app/core/gimpprojection.c
+++ b/app/core/gimpprojection.c
@@ -30,6 +30,7 @@
 #include "core-types.h"
 
 #include "gegl/gimp-babl.h"
+#include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimp.h"
@@ -135,6 +136,10 @@ static gboolean    gimp_projection_get_pixel_at          (GimpPickable    *picka
 static gdouble     gimp_projection_get_opacity_at        (GimpPickable    *pickable,
                                                           gint             x,
                                                           gint             y);
+static void        gimp_projection_get_pixel_average     (GimpPickable    *pickable,
+                                                          const GeglRectangle *rect,
+                                                          const Babl      *format,
+                                                          gpointer         pixel);
 static void        gimp_projection_pixel_to_srgb         (GimpPickable    *pickable,
                                                           const Babl      *format,
                                                           gpointer         pixel,
@@ -255,6 +260,7 @@ gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
   iface->get_buffer            = gimp_projection_get_buffer;
   iface->get_pixel_at          = gimp_projection_get_pixel_at;
   iface->get_opacity_at        = gimp_projection_get_opacity_at;
+  iface->get_pixel_average     = gimp_projection_get_pixel_average;
   iface->pixel_to_srgb         = gimp_projection_pixel_to_srgb;
   iface->srgb_to_pixel         = gimp_projection_srgb_to_pixel;
 }
@@ -460,6 +466,18 @@ gimp_projection_get_opacity_at (GimpPickable *pickable,
 }
 
 static void
+gimp_projection_get_pixel_average (GimpPickable        *pickable,
+                                   const GeglRectangle *rect,
+                                   const Babl          *format,
+                                   gpointer             pixel)
+{
+  GeglBuffer *buffer = gimp_projection_get_buffer (pickable);
+
+  return gimp_gegl_average_color (buffer, rect, TRUE, GEGL_ABYSS_NONE, format,
+                                  pixel);
+}
+
+static void
 gimp_projection_pixel_to_srgb (GimpPickable *pickable,
                                const Babl   *format,
                                gpointer      pixel,


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