[gimp/goat-invasion: 34/401] app: replace some copy_region() by gegl_buffer_copy()



commit 0352f9a73282bc24d5812a69ce8177aa059d8378
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 15 00:03:07 2012 +0100

    app: replace some copy_region() by gegl_buffer_copy()

 app/core/gimpdrawable-offset.c |  131 ++++++++++++++++++++++------------------
 app/core/gimpdrawable.c        |   23 +++----
 2 files changed, 81 insertions(+), 73 deletions(-)
---
diff --git a/app/core/gimpdrawable-offset.c b/app/core/gimpdrawable-offset.c
index fcd5c51..5a24d34 100644
--- a/app/core/gimpdrawable-offset.c
+++ b/app/core/gimpdrawable-offset.c
@@ -32,6 +32,8 @@
 
 #include "paint-funcs/paint-funcs.h"
 
+#include "gegl/gimp-gegl-utils.h"
+
 #include "gimp.h"
 #include "gimpcontext.h"
 #include "gimpdrawable.h"
@@ -49,13 +51,17 @@ gimp_drawable_offset (GimpDrawable   *drawable,
                       gint            offset_x,
                       gint            offset_y)
 {
-  GimpItem    *item;
-  PixelRegion  srcPR, destPR;
-  TileManager *new_tiles;
-  gint         width, height;
-  gint         src_x, src_y;
-  gint         dest_x, dest_y;
-  guchar       fill[MAX_CHANNELS] = { 0 };
+  GimpItem      *item;
+  PixelRegion    destPR;
+  TileManager   *new_tiles;
+  GeglBuffer    *src_buffer;
+  GeglBuffer    *dest_buffer;
+  GeglRectangle  src_rect;
+  GeglRectangle  dest_rect;
+  gint           width, height;
+  gint           src_x, src_y;
+  gint           dest_x, dest_y;
+  guchar         fill[MAX_CHANNELS] = { 0 };
 
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (GIMP_IS_CONTEXT (context));
@@ -86,6 +92,10 @@ gimp_drawable_offset (GimpDrawable   *drawable,
     return;
 
   new_tiles = tile_manager_new (width, height, gimp_drawable_bytes (drawable));
+
+  src_buffer  = gimp_drawable_get_buffer (drawable, FALSE);
+  dest_buffer = gimp_tile_manager_get_gegl_buffer (new_tiles, TRUE);
+
   if (offset_x >= 0)
     {
       src_x = 0;
@@ -115,17 +125,21 @@ gimp_drawable_offset (GimpDrawable   *drawable,
   /*  Copy the center region  */
   if (width && height)
     {
-      pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                         src_x, src_y, width, height, FALSE);
-      pixel_region_init (&destPR, new_tiles,
-                         dest_x, dest_y, width, height, TRUE);
+      src_rect.x      = src_x;
+      src_rect.y      = src_y;
+      src_rect.width  = width;
+      src_rect.height = height;
+
+      dest_rect.x = dest_x;
+      dest_rect.y = dest_y;
 
-      copy_region (&srcPR, &destPR);
+      gegl_buffer_copy (src_buffer, &src_rect, dest_buffer, &dest_rect);
     }
 
-  /*  Copy appropriately for wrap around  */
-  if (wrap_around == TRUE)
+  if (wrap_around)
     {
+      /*  Copy appropriately for wrap around  */
+
       if (offset_x >= 0 && offset_y >= 0)
         {
           src_x = gimp_item_get_width  (item) - offset_x;
@@ -158,15 +172,15 @@ gimp_drawable_offset (GimpDrawable   *drawable,
       /*  intersecting region  */
       if (offset_x != 0 && offset_y != 0)
         {
-          pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                             src_x, src_y,
-                             ABS (offset_x), ABS (offset_y),
-                             FALSE);
-          pixel_region_init (&destPR, new_tiles,
-                             dest_x, dest_y,
-                             ABS (offset_x), ABS (offset_y),
-                             TRUE);
-          copy_region (&srcPR, &destPR);
+          src_rect.x      = src_x;
+          src_rect.y      = src_y;
+          src_rect.width  = ABS (offset_x);
+          src_rect.height = ABS (offset_y);
+
+          dest_rect.x = dest_x;
+          dest_rect.y = dest_y;
+
+          gegl_buffer_copy (src_buffer, &src_rect, dest_buffer, &dest_rect);
         }
 
       /*  X offset  */
@@ -174,31 +188,26 @@ gimp_drawable_offset (GimpDrawable   *drawable,
         {
           if (offset_y >= 0)
             {
-              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                                 src_x, 0, ABS (offset_x),
-                                 gimp_item_get_height (item) - ABS (offset_y),
-                                 FALSE);
-              pixel_region_init (&destPR, new_tiles,
-                                 dest_x, dest_y + offset_y,
-                                 ABS (offset_x),
-                                 gimp_item_get_height (item) - ABS (offset_y),
-                                 TRUE);
+              src_rect.x      = src_x;
+              src_rect.y      = 0;
+              src_rect.width  = ABS (offset_x);
+              src_rect.height = gimp_item_get_height (item) - ABS (offset_y);
+
+              dest_rect.x = dest_x;
+              dest_rect.y = dest_y + offset_y;
             }
           else if (offset_y < 0)
             {
-              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                                 src_x, src_y - offset_y,
-                                 ABS (offset_x),
-                                 gimp_item_get_height (item) - ABS (offset_y),
-                                 FALSE);
-              pixel_region_init (&destPR, new_tiles,
-                                 dest_x, 0,
-                                 ABS (offset_x),
-                                 gimp_item_get_height (item) - ABS (offset_y),
-                                 TRUE);
+              src_rect.x      = src_x;
+              src_rect.y      = src_y - offset_y;
+              src_rect.width  = ABS (offset_x);
+              src_rect.height = gimp_item_get_height (item) - ABS (offset_y);
+
+              dest_rect.x = dest_x;
+              dest_rect.y = 0;
             }
 
-          copy_region (&srcPR, &destPR);
+          gegl_buffer_copy (src_buffer, &src_rect, dest_buffer, &dest_rect);
         }
 
       /*  X offset  */
@@ -206,31 +215,32 @@ gimp_drawable_offset (GimpDrawable   *drawable,
         {
           if (offset_x >= 0)
             {
-              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                                 0, src_y,
-                                 gimp_item_get_width (item) - ABS (offset_x),
-                                 ABS (offset_y), FALSE);
-              pixel_region_init (&destPR, new_tiles, dest_x + offset_x, dest_y,
-                                 gimp_item_get_width (item) - ABS (offset_x),
-                                 ABS (offset_y), TRUE);
+              src_rect.x      = 0;
+              src_rect.y      = src_y;
+              src_rect.width  = gimp_item_get_width (item) - ABS (offset_x);
+              src_rect.height = ABS (offset_y);
+
+              dest_rect.x = dest_x + offset_x;
+              dest_rect.y = dest_y;
             }
           else if (offset_x < 0)
             {
-              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                                 src_x - offset_x, src_y,
-                                 gimp_item_get_width (item) - ABS (offset_x),
-                                 ABS (offset_y), FALSE);
-              pixel_region_init (&destPR, new_tiles, 0, dest_y,
-                                 gimp_item_get_width (item) - ABS (offset_x),
-                                 ABS (offset_y), TRUE);
+              src_rect.x      = src_x - offset_x;
+              src_rect.y      = src_y;
+              src_rect.width  = gimp_item_get_width (item) - ABS (offset_x);
+              src_rect.height = ABS (offset_y);
+
+              dest_rect.x = 0;
+              dest_rect.y = dest_y;
             }
 
-          copy_region (&srcPR, &destPR);
+          gegl_buffer_copy (src_buffer, &src_rect, dest_buffer, &dest_rect);
         }
     }
-  /*  Otherwise, fill the vacated regions  */
   else
     {
+      /*  Otherwise, fill the vacated regions  */
+
       if (fill_type == GIMP_OFFSET_BACKGROUND)
         {
           GimpRGB color;
@@ -312,6 +322,9 @@ gimp_drawable_offset (GimpDrawable   *drawable,
         }
     }
 
+  g_object_unref (src_buffer);
+  g_object_unref (dest_buffer);
+
   gimp_drawable_set_tiles (drawable, gimp_item_is_attached (item),
                            C_("undo-type", "Offset Drawable"), new_tiles,
                            gimp_drawable_type (drawable));
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 19e2f88..008c88c 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -422,8 +422,8 @@ gimp_drawable_duplicate (GimpItem *item,
       GimpDrawable  *drawable     = GIMP_DRAWABLE (item);
       GimpDrawable  *new_drawable = GIMP_DRAWABLE (new_item);
       GimpImageType  image_type   = gimp_drawable_type (drawable);
-      PixelRegion    srcPR;
-      PixelRegion    destPR;
+      GeglBuffer    *src;
+      GeglBuffer    *dest;
 
       new_drawable->private->type = image_type;
 
@@ -435,18 +435,13 @@ gimp_drawable_duplicate (GimpItem *item,
                           gimp_item_get_height (new_item),
                           gimp_drawable_bytes (new_drawable));
 
-      pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                         0, 0,
-                         gimp_item_get_width  (item),
-                         gimp_item_get_height (item),
-                         FALSE);
-      pixel_region_init (&destPR, gimp_drawable_get_tiles (new_drawable),
-                         0, 0,
-                         gimp_item_get_width  (new_item),
-                         gimp_item_get_height (new_item),
-                         TRUE);
+      src  = gimp_drawable_get_buffer (drawable, FALSE);
+      dest = gimp_drawable_get_buffer (new_drawable, TRUE);
 
-      copy_region (&srcPR, &destPR);
+      gegl_buffer_copy (src, NULL, dest, NULL);
+
+      g_object_unref (src);
+      g_object_unref (dest);
     }
 
   return new_item;



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