[gimp/goat-invasion: 233/412] app: change GimpDrawable::replace_region() by ::replace_buffer()



commit e101d71430b16f7582b9334e9bc0ecadfcb6e584
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 23 12:31:21 2012 +0100

    app: change GimpDrawable::replace_region() by ::replace_buffer()

 app/core/gimpchannel.c          |   27 ++++++++++++----------
 app/core/gimpdrawable-combine.c |   47 +++++++++++++++++++++++++++-----------
 app/core/gimpdrawable-combine.h |    5 ++-
 app/core/gimpdrawable.c         |   24 ++++++++++---------
 app/core/gimpdrawable.h         |   10 +++++---
 app/paint/gimppaintcore.c       |   16 ++++++++-----
 6 files changed, 80 insertions(+), 49 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 3a7641e..fdee4cd 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -149,8 +149,9 @@ static void      gimp_channel_apply_buffer   (GimpDrawable        *drawable,
                                               PixelRegion         *destPR,
                                               gint                 x,
                                               gint                 y);
-static void      gimp_channel_replace_region (GimpDrawable        *drawable,
-                                              PixelRegion         *src2PR,
+static void      gimp_channel_replace_buffer (GimpDrawable        *drawable,
+                                              GeglBuffer          *buffer,
+                                              const GeglRectangle *buffer_region,
                                               gboolean             push_undo,
                                               const gchar         *undo_desc,
                                               gdouble              opacity,
@@ -289,7 +290,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
   drawable_class->invalidate_boundary   = gimp_channel_invalidate_boundary;
   drawable_class->get_active_components = gimp_channel_get_active_components;
   drawable_class->apply_buffer          = gimp_channel_apply_buffer;
-  drawable_class->replace_region        = gimp_channel_replace_region;
+  drawable_class->replace_buffer        = gimp_channel_replace_buffer;
   drawable_class->project_region        = gimp_channel_project_region;
   drawable_class->set_buffer            = gimp_channel_set_buffer;
   drawable_class->swap_pixels           = gimp_channel_swap_pixels;
@@ -831,18 +832,20 @@ gimp_channel_apply_buffer (GimpDrawable         *drawable,
 }
 
 static void
-gimp_channel_replace_region (GimpDrawable *drawable,
-                             PixelRegion  *src2PR,
-                             gboolean      push_undo,
-                             const gchar  *undo_desc,
-                             gdouble       opacity,
-                             PixelRegion  *maskPR,
-                             gint          x,
-                             gint          y)
+gimp_channel_replace_buffer (GimpDrawable        *drawable,
+                             GeglBuffer          *buffer,
+                             const GeglRectangle *buffer_region,
+                             gboolean             push_undo,
+                             const gchar         *undo_desc,
+                             gdouble              opacity,
+                             PixelRegion         *maskPR,
+                             gint                 x,
+                             gint                 y)
 {
   gimp_drawable_invalidate_boundary (drawable);
 
-  GIMP_DRAWABLE_CLASS (parent_class)->replace_region (drawable, src2PR,
+  GIMP_DRAWABLE_CLASS (parent_class)->replace_buffer (drawable, buffer,
+                                                      buffer_region,
                                                       push_undo, undo_desc,
                                                       opacity,
                                                       maskPR,
diff --git a/app/core/gimpdrawable-combine.c b/app/core/gimpdrawable-combine.c
index eba30d3..56512b9 100644
--- a/app/core/gimpdrawable-combine.c
+++ b/app/core/gimpdrawable-combine.c
@@ -206,24 +206,43 @@ gimp_drawable_real_apply_buffer (GimpDrawable         *drawable,
  * Takes an additional mask pixel region as well.
  */
 void
-gimp_drawable_real_replace_region (GimpDrawable *drawable,
-                                   PixelRegion  *src2PR,
-                                   gboolean      push_undo,
-                                   const gchar  *undo_desc,
-                                   gdouble       opacity,
-                                   PixelRegion  *maskPR,
-                                   gint          dest_x,
-                                   gint          dest_y)
+gimp_drawable_real_replace_buffer (GimpDrawable        *drawable,
+                                   GeglBuffer          *buffer,
+                                   const GeglRectangle *buffer_region,
+                                   gboolean             push_undo,
+                                   const gchar         *undo_desc,
+                                   gdouble              opacity,
+                                   PixelRegion         *maskPR,
+                                   gint                 dest_x,
+                                   gint                 dest_y)
 {
   GimpItem        *item  = GIMP_ITEM (drawable);
   GimpImage       *image = gimp_item_get_image (item);
   GimpChannel     *mask  = gimp_image_get_mask (image);
+  TempBuf         *temp_buf;
+  PixelRegion      src2PR;
   gint             x, y, width, height;
   gint             offset_x, offset_y;
   PixelRegion      src1PR, destPR;
   CombinationMode  operation;
   gboolean         active_components[MAX_CHANNELS];
 
+  temp_buf = gimp_gegl_buffer_get_temp_buf (buffer);
+
+  if (temp_buf)
+    {
+      pixel_region_init_temp_buf (&src2PR, temp_buf,
+                                  buffer_region->x, buffer_region->y,
+                                  buffer_region->width, buffer_region->height);
+    }
+  else
+    {
+      pixel_region_init (&src2PR, gimp_gegl_buffer_get_tiles (buffer),
+                         buffer_region->x, buffer_region->y,
+                         buffer_region->width, buffer_region->height,
+                         FALSE);
+    }
+
   /*  don't apply the mask to itself and don't apply an empty mask  */
   if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask))
     mask = NULL;
@@ -235,7 +254,7 @@ gimp_drawable_real_replace_region (GimpDrawable *drawable,
    *  if it's actually legal...
    */
   operation = gimp_image_get_combination_mode (gimp_drawable_type (drawable),
-                                               src2PR->bytes);
+                                               src2PR.bytes);
   if (operation == -1)
     {
       g_warning ("%s: illegal parameters.", G_STRFUNC);
@@ -246,7 +265,7 @@ gimp_drawable_real_replace_region (GimpDrawable *drawable,
   gimp_item_get_offset (item, &offset_x, &offset_y);
 
   /*  make sure the image application coordinates are within drawable bounds  */
-  gimp_rectangle_intersect (dest_x, dest_y, src2PR->w, src2PR->h,
+  gimp_rectangle_intersect (dest_x, dest_y, src2PR.w, src2PR.h,
                             0, 0,
                             gimp_item_get_width  (item),
                             gimp_item_get_height (item),
@@ -279,8 +298,8 @@ gimp_drawable_real_replace_region (GimpDrawable *drawable,
   pixel_region_init (&destPR, gimp_drawable_get_tiles (drawable),
                      x, y, width, height,
                      TRUE);
-  pixel_region_resize (src2PR,
-                       src2PR->x + (x - dest_x), src2PR->y + (y - dest_y),
+  pixel_region_resize (&src2PR,
+                       src2PR.x + (x - dest_x), src2PR.y + (y - dest_y),
                        width, height);
 
   if (mask)
@@ -308,7 +327,7 @@ gimp_drawable_real_replace_region (GimpDrawable *drawable,
       pixel_region_init_data (&tempPR, temp_data, 1, width,
                               0, 0, width, height);
 
-      combine_regions_replace (&src1PR, src2PR, &destPR, &tempPR, NULL,
+      combine_regions_replace (&src1PR, &src2PR, &destPR, &tempPR, NULL,
                                opacity * 255.999,
                                active_components,
                                operation);
@@ -317,7 +336,7 @@ gimp_drawable_real_replace_region (GimpDrawable *drawable,
     }
   else
     {
-      combine_regions_replace (&src1PR, src2PR, &destPR, maskPR, NULL,
+      combine_regions_replace (&src1PR, &src2PR, &destPR, maskPR, NULL,
                                opacity * 255.999,
                                active_components,
                                operation);
diff --git a/app/core/gimpdrawable-combine.h b/app/core/gimpdrawable-combine.h
index 27a40e8..25e39a7 100644
--- a/app/core/gimpdrawable-combine.h
+++ b/app/core/gimpdrawable-combine.h
@@ -32,8 +32,9 @@ void   gimp_drawable_real_apply_buffer   (GimpDrawable         *drawable,
                                           PixelRegion          *destPR,
                                           gint                  x,
                                           gint                  y);
-void   gimp_drawable_real_replace_region (GimpDrawable         *drawable,
-                                          PixelRegion          *src2PR,
+void   gimp_drawable_real_replace_buffer (GimpDrawable         *drawable,
+                                          GeglBuffer           *buffer,
+                                          const GeglRectangle  *buffer_region,
                                           gboolean              push_undo,
                                           const gchar          *undo_desc,
                                           gdouble               opacity,
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 3cd2fe9..d5f6cbd 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -240,7 +240,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
   klass->get_active_components       = NULL;
   klass->convert_type                = gimp_drawable_real_convert_type;
   klass->apply_buffer                = gimp_drawable_real_apply_buffer;
-  klass->replace_region              = gimp_drawable_real_replace_region;
+  klass->replace_buffer              = gimp_drawable_real_replace_buffer;
   klass->get_buffer                  = gimp_drawable_real_get_buffer;
   klass->set_buffer                  = gimp_drawable_real_set_buffer;
   klass->push_undo                   = gimp_drawable_real_push_undo;
@@ -1263,21 +1263,23 @@ gimp_drawable_apply_buffer (GimpDrawable         *drawable,
 }
 
 void
-gimp_drawable_replace_region (GimpDrawable *drawable,
-                              PixelRegion  *src2PR,
-                              gboolean      push_undo,
-                              const gchar  *undo_desc,
-                              gdouble       opacity,
-                              PixelRegion  *maskPR,
-                              gint          x,
-                              gint          y)
+gimp_drawable_replace_buffer (GimpDrawable        *drawable,
+                              GeglBuffer          *buffer,
+                              const GeglRectangle *buffer_region,
+                              gboolean             push_undo,
+                              const gchar         *undo_desc,
+                              gdouble              opacity,
+                              PixelRegion         *maskPR,
+                              gint                 x,
+                              gint                 y)
 {
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
-  g_return_if_fail (src2PR != NULL);
+  g_return_if_fail (GEGL_IS_BUFFER (buffer));
   g_return_if_fail (maskPR != NULL);
 
-  GIMP_DRAWABLE_GET_CLASS (drawable)->replace_region (drawable, src2PR,
+  GIMP_DRAWABLE_GET_CLASS (drawable)->replace_buffer (drawable, buffer,
+                                                      buffer_region,
                                                       push_undo, undo_desc,
                                                       opacity, maskPR,
                                                       x, y);
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 4745459..f20b7a8 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -74,8 +74,9 @@ struct _GimpDrawableClass
                                            PixelRegion          *destPR,
                                            gint                  x,
                                            gint                  y);
-  void          (* replace_region)        (GimpDrawable         *drawable,
-                                           PixelRegion          *src2PR,
+  void          (* replace_buffer)        (GimpDrawable         *drawable,
+                                           GeglBuffer           *buffer,
+                                           const GeglRectangle  *buffer_region,
                                            gboolean              push_undo,
                                            const gchar          *undo_desc,
                                            gdouble               opacity,
@@ -152,8 +153,9 @@ void            gimp_drawable_apply_buffer       (GimpDrawable       *drawable,
                                                   PixelRegion        *destPR,
                                                   gint                x,
                                                   gint                y);
-void            gimp_drawable_replace_region     (GimpDrawable       *drawable,
-                                                  PixelRegion        *src2PR,
+void            gimp_drawable_replace_buffer     (GimpDrawable       *drawable,
+                                                  GeglBuffer         *buffer,
+                                                  const GeglRectangle *buffer_region,
                                                   gboolean            push_undo,
                                                   const gchar        *undo_desc,
                                                   gdouble             opacity,
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index da6f1c1..99d3a08 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -969,7 +969,7 @@ gimp_paint_core_replace (GimpPaintCore            *core,
                          gdouble                   image_opacity,
                          GimpPaintApplicationMode  mode)
 {
-  PixelRegion  srcPR;
+  GeglBuffer *canvas_buffer;
 
   if (! gimp_drawable_has_alpha (drawable))
     {
@@ -1012,19 +1012,23 @@ gimp_paint_core_replace (GimpPaintCore            *core,
     }
 
   /*  intialize canvas buf source pixel regions  */
-  pixel_region_init_temp_buf (&srcPR, core->canvas_buf,
-                              0, 0,
-                              core->canvas_buf->width,
-                              core->canvas_buf->height);
+  canvas_buffer =
+    gimp_temp_buf_create_buffer (core->canvas_buf,
+                                 gimp_drawable_get_format_with_alpha (drawable));
 
   /*  apply the paint area to the image  */
-  gimp_drawable_replace_region (drawable, &srcPR,
+  gimp_drawable_replace_buffer (drawable, canvas_buffer,
+                                GIMP_GEGL_RECT (0, 0,
+                                                core->canvas_buf->width,
+                                                core->canvas_buf->height),
                                 FALSE, NULL,
                                 image_opacity,
                                 paint_maskPR,
                                 core->canvas_buf->x,
                                 core->canvas_buf->y);
 
+  g_object_unref (canvas_buffer);
+
   /*  Update the undo extents  */
   core->x1 = MIN (core->x1, core->canvas_buf->x);
   core->y1 = MIN (core->y1, core->canvas_buf->y);



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