[gimp] app: add gimp_paint_core_get_paint_buffer()



commit 12ac0bea139ffe623a313c19bfa4174fffc3cce9
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 31 18:28:18 2012 +0200

    app: add gimp_paint_core_get_paint_buffer()
    
    which is the same as gimp_paint_core_get_paint_area() but returns a
    GeglBuffer to paint to, not a TempBuf.

 app/paint/gimpbrushcore.c |   14 ++++-
 app/paint/gimpink.c       |   29 ++++++++----
 app/paint/gimppaintcore.c |  114 +++++++++++++++++++++++++-------------------
 app/paint/gimppaintcore.h |   10 ++++
 4 files changed, 106 insertions(+), 61 deletions(-)
---
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 9670d57..1bee5f2 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -825,14 +825,22 @@ gimp_brush_core_get_paint_area (GimpPaintCore    *paint_core,
   /*  configure the canvas buffer  */
   if ((x2 - x1) && (y2 - y1))
     {
-      gint bytes;
-
-      bytes = gimp_drawable_bytes_with_alpha (drawable);
+      const Babl *format = gimp_drawable_get_format_with_alpha (drawable);
+      gint        bytes  = babl_format_get_bytes_per_pixel (format);
 
       paint_core->paint_area = temp_buf_resize (paint_core->paint_area, bytes,
                                                 x1, y1,
                                                 (x2 - x1), (y2 - y1));
 
+      paint_core->paint_buffer_x = x1;
+      paint_core->paint_buffer_y = y1;
+
+      if (paint_core->paint_buffer)
+        g_object_unref (paint_core->paint_buffer);
+
+      paint_core->paint_buffer =
+        gimp_temp_buf_create_buffer (paint_core->paint_area, format);
+
       return paint_core->paint_area;
     }
 
diff --git a/app/paint/gimpink.c b/app/paint/gimpink.c
index 9ab776f..2705ade 100644
--- a/app/paint/gimpink.c
+++ b/app/paint/gimpink.c
@@ -204,9 +204,6 @@ gimp_ink_get_paint_area (GimpPaintCore    *paint_core,
   gint     width, height;
   gint     dwidth, dheight;
   gint     x1, y1, x2, y2;
-  gint     bytes;
-
-  bytes = gimp_drawable_bytes_with_alpha (drawable);
 
   gimp_blob_bounds (ink->cur_blob, &x, &y, &width, &height);
 
@@ -220,13 +217,27 @@ gimp_ink_get_paint_area (GimpPaintCore    *paint_core,
 
   /*  configure the canvas buffer  */
   if ((x2 - x1) && (y2 - y1))
-    paint_core->paint_area = temp_buf_resize (paint_core->paint_area, bytes,
-                                              x1, y1,
-                                              (x2 - x1), (y2 - y1));
-  else
-    return NULL;
+    {
+      const Babl *format = gimp_drawable_get_format_with_alpha (drawable);
+      gint        bytes  = babl_format_get_bytes_per_pixel (format);
+
+      paint_core->paint_area = temp_buf_resize (paint_core->paint_area, bytes,
+                                                x1, y1,
+                                                (x2 - x1), (y2 - y1));
+
+      paint_core->paint_buffer_x = x1;
+      paint_core->paint_buffer_y = y1;
+
+      if (paint_core->paint_buffer)
+        g_object_unref (paint_core->paint_buffer);
+
+      paint_core->paint_buffer =
+        gimp_temp_buf_create_buffer (paint_core->paint_area, format);
+
+      return paint_core->paint_area;
+    }
 
-  return paint_core->paint_area;
+  return NULL;
 }
 
 static GimpUndo *
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index bd5915d..fa8c35f 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -553,6 +553,12 @@ gimp_paint_core_cleanup (GimpPaintCore *core)
       temp_buf_free (core->paint_area);
       core->paint_area = NULL;
     }
+
+  if (core->paint_buffer)
+    {
+      g_object_unref (core->paint_buffer);
+      core->paint_buffer = NULL;
+    }
 }
 
 void
@@ -672,6 +678,30 @@ gimp_paint_core_get_paint_area (GimpPaintCore    *core,
 }
 
 GeglBuffer *
+gimp_paint_core_get_paint_buffer (GimpPaintCore    *core,
+                                  GimpDrawable     *drawable,
+                                  GimpPaintOptions *paint_options,
+                                  const GimpCoords *coords,
+                                  gint             *paint_buffer_x,
+                                  gint             *paint_buffer_y)
+{
+  g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL);
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+  g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
+  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), NULL);
+  g_return_val_if_fail (coords != NULL, NULL);
+  g_return_val_if_fail (paint_buffer_x != NULL, NULL);
+  g_return_val_if_fail (paint_buffer_y != NULL, NULL);
+
+  gimp_paint_core_get_paint_area (core, drawable, paint_options, coords);
+
+  *paint_buffer_x = core->paint_buffer_x;
+  *paint_buffer_y = core->paint_buffer_y;
+
+  return core->paint_buffer;
+}
+
+GeglBuffer *
 gimp_paint_core_get_orig_image (GimpPaintCore *core)
 {
   g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL);
@@ -699,7 +729,7 @@ gimp_paint_core_paste (GimpPaintCore            *core,
                        GimpPaintApplicationMode  mode)
 {
   GeglBuffer *base_buffer = NULL;
-  GeglBuffer *canvas_buffer;
+  gint        width, height;
 
   /*  If the mode is CONSTANT:
    *   combine the canvas buf, the paint mask to the canvas buffer
@@ -727,39 +757,33 @@ gimp_paint_core_paste (GimpPaintCore            *core,
       paint_mask_to_paint_area (core, paint_maskPR, paint_opacity);
     }
 
-  /*  intialize canvas buf source pixel regions  */
-  canvas_buffer =
-    gimp_temp_buf_create_buffer (core->paint_area,
-                                 gimp_drawable_get_format_with_alpha (drawable));
+  width  = gegl_buffer_get_width  (core->paint_buffer);
+  height = gegl_buffer_get_height (core->paint_buffer);
 
   /*  apply the paint area to the image  */
-  gimp_drawable_apply_buffer (drawable, canvas_buffer,
-                              GIMP_GEGL_RECT (0, 0,
-                                              core->paint_area->width,
-                                              core->paint_area->height),
+  gimp_drawable_apply_buffer (drawable,
+                              core->paint_buffer,
+                              GIMP_GEGL_RECT (0, 0, width, height),
                               FALSE, NULL,
                               image_opacity, paint_mode,
                               base_buffer, /*  specify an alternative src1  */
-                              core->paint_area->x,
-                              core->paint_area->y,
+                              core->paint_buffer_x,
+                              core->paint_buffer_y,
                               NULL,
-                              core->paint_area->x,
-                              core->paint_area->y);
-
-  g_object_unref (canvas_buffer);
+                              core->paint_buffer_x,
+                              core->paint_buffer_y);
 
   /*  Update the undo extents  */
-  core->x1 = MIN (core->x1, core->paint_area->x);
-  core->y1 = MIN (core->y1, core->paint_area->y);
-  core->x2 = MAX (core->x2, core->paint_area->x + core->paint_area->width);
-  core->y2 = MAX (core->y2, core->paint_area->y + core->paint_area->height);
+  core->x1 = MIN (core->x1, core->paint_buffer_x);
+  core->y1 = MIN (core->y1, core->paint_buffer_y);
+  core->x2 = MAX (core->x2, core->paint_buffer_x + width);
+  core->y2 = MAX (core->y2, core->paint_buffer_y + height);
 
   /*  Update the drawable  */
   gimp_drawable_update (drawable,
-                        core->paint_area->x,
-                        core->paint_area->y,
-                        core->paint_area->width,
-                        core->paint_area->height);
+                        core->paint_buffer_x,
+                        core->paint_buffer_y,
+                        width, height);
 }
 
 /* This works similarly to gimp_paint_core_paste. However, instead of
@@ -778,7 +802,7 @@ gimp_paint_core_replace (GimpPaintCore            *core,
                          gdouble                   image_opacity,
                          GimpPaintApplicationMode  mode)
 {
-  GeglBuffer *canvas_buffer;
+  gint width, height;
 
   if (! gimp_drawable_has_alpha (drawable))
     {
@@ -789,6 +813,9 @@ gimp_paint_core_replace (GimpPaintCore            *core,
       return;
     }
 
+  width  = gegl_buffer_get_width  (core->paint_buffer);
+  height = gegl_buffer_get_height (core->paint_buffer);
+
   if (mode == GIMP_PAINT_CONSTANT)
     {
       /* Some tools (ink) paint the mask to paint_core->canvas_buffer
@@ -803,10 +830,9 @@ gimp_paint_core_replace (GimpPaintCore            *core,
           /* initialize the maskPR from the canvas buffer */
           pixel_region_init (paint_maskPR,
                              gimp_gegl_buffer_get_tiles (core->canvas_buffer),
-                             core->paint_area->x,
-                             core->paint_area->y,
-                             core->paint_area->width,
-                             core->paint_area->height,
+                             core->paint_buffer_x,
+                             core->paint_buffer_y,
+                             width, height,
                              FALSE);
         }
     }
@@ -815,36 +841,26 @@ gimp_paint_core_replace (GimpPaintCore            *core,
       /* The mask is just the paint_maskPR */
     }
 
-  /*  intialize canvas buf source pixel regions  */
-  canvas_buffer =
-    gimp_temp_buf_create_buffer (core->paint_area,
-                                 gimp_drawable_get_format_with_alpha (drawable));
-
   /*  apply the paint area to the image  */
-  gimp_drawable_replace_buffer (drawable, canvas_buffer,
-                                GIMP_GEGL_RECT (0, 0,
-                                                core->paint_area->width,
-                                                core->paint_area->height),
+  gimp_drawable_replace_buffer (drawable, core->paint_buffer,
+                                GIMP_GEGL_RECT (0, 0, width, height),
                                 FALSE, NULL,
                                 image_opacity,
                                 paint_maskPR,
-                                core->paint_area->x,
-                                core->paint_area->y);
-
-  g_object_unref (canvas_buffer);
+                                core->paint_buffer_x,
+                                core->paint_buffer_y);
 
   /*  Update the undo extents  */
-  core->x1 = MIN (core->x1, core->paint_area->x);
-  core->y1 = MIN (core->y1, core->paint_area->y);
-  core->x2 = MAX (core->x2, core->paint_area->x + core->paint_area->width) ;
-  core->y2 = MAX (core->y2, core->paint_area->y + core->paint_area->height) ;
+  core->x1 = MIN (core->x1, core->paint_buffer_x);
+  core->y1 = MIN (core->y1, core->paint_buffer_y);
+  core->x2 = MAX (core->x2, core->paint_buffer_x + width);
+  core->y2 = MAX (core->y2, core->paint_buffer_y + height);
 
   /*  Update the drawable  */
   gimp_drawable_update (drawable,
-                        core->paint_area->x,
-                        core->paint_area->y,
-                        core->paint_area->width,
-                        core->paint_area->height);
+                        core->paint_buffer_x,
+                        core->paint_buffer_y,
+                        width, height);
 }
 
 /**
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index 163910b..9761bea 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -60,6 +60,9 @@ struct _GimpPaintCore
   GeglBuffer  *canvas_buffer;     /*  the buffer to paint the mask to     */
 
   TempBuf     *paint_area;        /*  the buffer to paint pixels to       */
+  GeglBuffer  *paint_buffer;      /*  for now proxies paint_area          */
+  gint         paint_buffer_x;
+  gint         paint_buffer_y;
 
   GArray      *stroke_buffer;
 };
@@ -155,6 +158,13 @@ TempBuf    * gimp_paint_core_get_paint_area         (GimpPaintCore    *core,
                                                      GimpDrawable     *drawable,
                                                      GimpPaintOptions *options,
                                                      const GimpCoords *coords);
+GeglBuffer * gimp_paint_core_get_paint_buffer       (GimpPaintCore    *core,
+                                                     GimpDrawable     *drawable,
+                                                     GimpPaintOptions *options,
+                                                     const GimpCoords *coords,
+                                                     gint             *paint_buffer_x,
+                                                     gint             *paint_buffer_y);
+
 GeglBuffer * gimp_paint_core_get_orig_image         (GimpPaintCore    *core);
 GeglBuffer * gimp_paint_core_get_orig_proj          (GimpPaintCore    *core);
 



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