[gimp/goat-invasion: 217/401] app: add gimp_drawable_apply_buffer() and port edit, bucket fill, stroke



commit e672b57ba0292386ee13355e2d2bef733e58cf98
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 22 18:40:40 2012 +0100

    app: add gimp_drawable_apply_buffer() and port edit, bucket fill, stroke

 app/core/gimp-edit.c                |   26 +++++++--------------
 app/core/gimpdrawable-bucket-fill.c |   19 ++++-----------
 app/core/gimpdrawable-stroke.c      |   42 ++++++++++++----------------------
 app/core/gimpdrawable.c             |   32 ++++++++++++++++++++++++++
 app/core/gimpdrawable.h             |   11 +++++++++
 5 files changed, 72 insertions(+), 58 deletions(-)
---
diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c
index d28ad81..106534b 100644
--- a/app/core/gimp-edit.c
+++ b/app/core/gimp-edit.c
@@ -458,12 +458,9 @@ gimp_edit_fill_full (GimpImage            *image,
                      GimpLayerModeEffects  paint_mode,
                      const gchar          *undo_desc)
 {
-  TileManager *buf_tiles;
-  GeglBuffer  *dest_buffer;
-  PixelRegion  bufPR;
-  gint         x, y, width, height;
-  gint         tiles_bytes;
-  const Babl  *format;
+  GeglBuffer *dest_buffer;
+  const Babl *format;
+  gint        x, y, width, height;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
@@ -474,22 +471,19 @@ gimp_edit_fill_full (GimpImage            *image,
   if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     return TRUE;  /*  nothing to do, but the fill succeded  */
 
-  tiles_bytes = gimp_drawable_bytes (drawable);
-  format      = gimp_drawable_get_format (drawable);
+  format = gimp_drawable_get_format (drawable);
 
   if (pattern)
     {
       if (! gimp_drawable_has_alpha (drawable) &&
           (pattern->mask->bytes == 2 || pattern->mask->bytes == 4))
         {
-          tiles_bytes++;
           format = gimp_drawable_get_format_with_alpha (drawable);
         }
     }
 
-  buf_tiles = tile_manager_new (width, height, tiles_bytes);
-
-  dest_buffer = gimp_tile_manager_create_buffer (buf_tiles, format);
+  dest_buffer = gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0, width, height),
+                                      format);
 
   if (pattern)
     {
@@ -506,15 +500,13 @@ gimp_edit_fill_full (GimpImage            *image,
       g_object_unref (gegl_color);
     }
 
-  g_object_unref (dest_buffer);
-
-  pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, FALSE);
-  gimp_drawable_apply_region (drawable, &bufPR,
+  gimp_drawable_apply_buffer (drawable, dest_buffer,
+                              GIMP_GEGL_RECT (0, 0, width, height),
                               TRUE, undo_desc,
                               opacity, paint_mode,
                               NULL, NULL, x, y);
 
-  tile_manager_unref (buf_tiles);
+  g_object_unref (dest_buffer);
 
   gimp_drawable_update (drawable, x, y, width, height);
 
diff --git a/app/core/gimpdrawable-bucket-fill.c b/app/core/gimpdrawable-bucket-fill.c
index 0603882..7939a10 100644
--- a/app/core/gimpdrawable-bucket-fill.c
+++ b/app/core/gimpdrawable-bucket-fill.c
@@ -26,9 +26,6 @@
 
 #include "core-types.h"
 
-#include "base/pixel-region.h"
-#include "base/tile-manager.h"
-
 #include "gegl/gimp-gegl-nodes.h"
 #include "gegl/gimp-gegl-utils.h"
 
@@ -140,11 +137,9 @@ gimp_drawable_bucket_fill_internal (GimpDrawable        *drawable,
 {
   GimpImage   *image;
   GimpChannel *mask;
-  TileManager *tiles;
   GeglBuffer  *buffer;
   GeglBuffer  *mask_buffer;
   GeglNode    *apply_opacity;
-  PixelRegion  bufPR;
   gint         x1, y1, x2, y2;
   gint         mask_offset_x = 0;
   gint         mask_offset_y = 0;
@@ -225,10 +220,8 @@ gimp_drawable_bucket_fill_internal (GimpDrawable        *drawable,
       mask_offset_y = y1;
     }
 
-  tiles = tile_manager_new ((x2 - x1), (y2 - y1),
-                            gimp_drawable_bytes_with_alpha (drawable));
-  buffer = gimp_tile_manager_create_buffer (tiles,
-                                            gimp_drawable_get_format_with_alpha (drawable));
+  buffer = gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0, x2 - x1, y2 - y1),
+                                 gimp_drawable_get_format_with_alpha (drawable));
 
   switch (fill_mode)
     {
@@ -261,18 +254,16 @@ gimp_drawable_bucket_fill_internal (GimpDrawable        *drawable,
                         buffer, NULL);
 
   g_object_unref (apply_opacity);
-
-  g_object_unref (buffer);
   g_object_unref (mask);
 
   /*  Apply it to the image  */
-  pixel_region_init (&bufPR, tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE);
-  gimp_drawable_apply_region (drawable, &bufPR,
+  gimp_drawable_apply_buffer (drawable, buffer,
+                              GIMP_GEGL_RECT (0, 0, x2 - x1, y2 - y1),
                               TRUE, C_("undo-type", "Bucket Fill"),
                               opacity, paint_mode,
                               NULL, NULL, x1, y1);
 
-  tile_manager_unref (tiles);
+  g_object_unref (buffer);
 
   gimp_drawable_update (drawable, x1, y1, x2 - x1, y2 - y1);
 
diff --git a/app/core/gimpdrawable-stroke.c b/app/core/gimpdrawable-stroke.c
index 39a6073..43bd3df 100644
--- a/app/core/gimpdrawable-stroke.c
+++ b/app/core/gimpdrawable-stroke.c
@@ -29,9 +29,6 @@
 
 #include "core-types.h"
 
-#include "base/pixel-region.h"
-#include "base/tile-manager.h"
-
 #include "gegl/gimp-gegl-nodes.h"
 #include "gegl/gimp-gegl-utils.h"
 
@@ -284,18 +281,14 @@ gimp_drawable_stroke_scan_convert (GimpDrawable    *drawable,
                                    gboolean         do_stroke,
                                    gboolean         push_undo)
 {
-  GimpContext   *context = GIMP_CONTEXT (options);
-  GimpImage     *image   = gimp_item_get_image (GIMP_ITEM (drawable));
-  TileManager   *base;
-  GeglBuffer    *base_buffer;
-  GeglBuffer    *mask_buffer;
-  GeglNode      *apply_opacity;
-  GeglRectangle  rect = { 0, };
-  gint           x, y, w, h;
-  gint           bytes;
-  gint           off_x;
-  gint           off_y;
-  PixelRegion    basePR;
+  GimpContext *context = GIMP_CONTEXT (options);
+  GimpImage   *image   = gimp_item_get_image (GIMP_ITEM (drawable));
+  GeglBuffer  *base_buffer;
+  GeglBuffer  *mask_buffer;
+  GeglNode    *apply_opacity;
+  gint         x, y, w, h;
+  gint         off_x;
+  gint         off_y;
 
   /*  must call gimp_channel_is_empty() instead of relying on
    *  gimp_item_mask_intersect() because the selection pretends to
@@ -345,9 +338,8 @@ gimp_drawable_stroke_scan_convert (GimpDrawable    *drawable,
   /* fill a 1-bpp GeglBuffer with black, this will describe the shape
    * of the stroke.
    */
-  rect.width  = w;
-  rect.height = h;
-  mask_buffer = gegl_buffer_new (&rect, babl_format ("Y u8"));
+  mask_buffer = gegl_buffer_new (GIMP_GEGL_RECT (0, 0, w, h),
+                                 babl_format ("Y u8"));
 
   gegl_buffer_clear (mask_buffer, NULL);
 
@@ -358,11 +350,8 @@ gimp_drawable_stroke_scan_convert (GimpDrawable    *drawable,
                             x + off_x, y + off_y,
                             gimp_fill_options_get_antialias (options));
 
-  bytes = gimp_drawable_bytes_with_alpha (drawable);
-
-  base = tile_manager_new (w, h, bytes);
-  base_buffer = gimp_tile_manager_create_buffer (base,
-                                                 gimp_drawable_get_format_with_alpha (drawable));
+  base_buffer = gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0, w, h),
+                                      gimp_drawable_get_format_with_alpha (drawable));
 
   switch (gimp_fill_options_get_style (options))
     {
@@ -400,18 +389,17 @@ gimp_drawable_stroke_scan_convert (GimpDrawable    *drawable,
 
   g_object_unref (apply_opacity);
 
-  g_object_unref (base_buffer);
   g_object_unref (mask_buffer);
 
   /* Apply to drawable */
-  pixel_region_init (&basePR, base, 0, 0, w, h, FALSE);
-  gimp_drawable_apply_region (drawable, &basePR,
+  gimp_drawable_apply_buffer (drawable, base_buffer,
+                              GIMP_GEGL_RECT (0, 0, w, h),
                               push_undo, C_("undo-type", "Render Stroke"),
                               gimp_context_get_opacity (context),
                               gimp_context_get_paint_mode (context),
                               NULL, NULL, x, y);
 
-  tile_manager_unref (base);
+  g_object_unref (base_buffer);
 
   gimp_drawable_update (drawable, x, y, w, h);
 }
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 6029b7c..e4b68aa 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -1235,6 +1235,38 @@ gimp_drawable_convert_type (GimpDrawable      *drawable,
 }
 
 void
+gimp_drawable_apply_buffer (GimpDrawable         *drawable,
+                            GeglBuffer           *buffer,
+                            const GeglRectangle  *buffer_rect,
+                            gboolean              push_undo,
+                            const gchar          *undo_desc,
+                            gdouble               opacity,
+                            GimpLayerModeEffects  mode,
+                            TileManager          *src1_tiles,
+                            PixelRegion          *destPR,
+                            gint                  x,
+                            gint                  y)
+{
+  PixelRegion src2PR;
+
+  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+  g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
+  g_return_if_fail (GEGL_IS_BUFFER (buffer));
+  g_return_if_fail (buffer_rect != NULL);
+
+  pixel_region_init (&src2PR, gimp_gegl_buffer_get_tiles (buffer),
+                     buffer_rect->x, buffer_rect->y,
+                     buffer_rect->width, buffer_rect->height,
+                     FALSE);
+
+  GIMP_DRAWABLE_GET_CLASS (drawable)->apply_region (drawable,& src2PR,
+                                                    push_undo, undo_desc,
+                                                    opacity, mode,
+                                                    src1_tiles, destPR,
+                                                    x, y);
+}
+
+void
 gimp_drawable_apply_region (GimpDrawable         *drawable,
                             PixelRegion          *src2PR,
                             gboolean              push_undo,
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index d268446..5131612 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -140,6 +140,17 @@ void            gimp_drawable_convert_type       (GimpDrawable       *drawable,
                                                   GimpImageBaseType   new_base_type,
                                                   gboolean            push_undo);
 
+void            gimp_drawable_apply_buffer       (GimpDrawable       *drawable,
+                                                  GeglBuffer         *buffer,
+                                                  const GeglRectangle *buffer_rect,
+                                                  gboolean            push_undo,
+                                                  const gchar        *undo_desc,
+                                                  gdouble             opacity,
+                                                  GimpLayerModeEffects  mode,
+                                                  TileManager        *src1_tiles,
+                                                  PixelRegion        *destPR,
+                                                  gint                x,
+                                                  gint                y);
 void            gimp_drawable_apply_region       (GimpDrawable       *drawable,
                                                   PixelRegion        *src2PR,
                                                   gboolean            push_undo,



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