[gimp/goat-invasion: 340/526] app: make gimp_paint_core_get_orig_image, proj() return GeglBuffers



commit 1c81c546b12f0cdec6721f0def60c136f778e47c
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 31 01:36:10 2012 +0200

    app: make gimp_paint_core_get_orig_image,proj() return GeglBuffers
    
    and change their users accordingly, getting rid of temp buffers and
    useless copies.

 app/paint/gimppaintcore.c        |   95 +++++++++++++++-----------------------
 app/paint/gimppaintcore.h        |   10 ++--
 app/paint/gimpperspectiveclone.c |   50 ++++++-------------
 app/paint/gimpsourcecore.c       |   25 ++++------
 4 files changed, 69 insertions(+), 111 deletions(-)
---
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index 295b5ef..0fb7361 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -550,13 +550,13 @@ gimp_paint_core_cleanup (GimpPaintCore *core)
 
   if (core->orig_buf)
     {
-      temp_buf_free (core->orig_buf);
+      g_object_unref (core->orig_buf);
       core->orig_buf = NULL;
     }
 
   if (core->orig_proj_buf)
     {
-      temp_buf_free (core->orig_proj_buf);
+      g_object_unref (core->orig_proj_buf);
       core->orig_proj_buf = NULL;
     }
 
@@ -683,7 +683,7 @@ gimp_paint_core_get_paint_area (GimpPaintCore    *core,
                                                            coords);
 }
 
-TempBuf *
+GeglBuffer *
 gimp_paint_core_get_orig_image (GimpPaintCore *core,
                                 GimpDrawable  *drawable,
                                 gint           x,
@@ -691,51 +691,43 @@ gimp_paint_core_get_orig_image (GimpPaintCore *core,
                                 gint           width,
                                 gint           height)
 {
-  GeglBuffer *orig_buffer;
-  gint        drawable_width;
-  gint        drawable_height;
+  gint orig_x = x;
+  gint orig_y = 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 (GEGL_IS_BUFFER (core->undo_buffer), NULL);
+  g_return_val_if_fail (core->undo_buffer != NULL, NULL);
 
-  core->orig_buf = temp_buf_resize (core->orig_buf,
-                                    gimp_drawable_bytes (drawable),
-                                    x, y, width, height);
+  if (core->orig_buf &&
+      (gegl_buffer_get_width  (core->orig_buf) != width ||
+       gegl_buffer_get_height (core->orig_buf) != height))
+    {
+      g_object_unref (core->orig_buf);
+      core->orig_buf = NULL;
+    }
 
-  drawable_width  = gimp_item_get_width  (GIMP_ITEM (drawable));
-  drawable_height = gimp_item_get_height (GIMP_ITEM (drawable));
+  if (! core->orig_buf)
+    core->orig_buf = gegl_buffer_new (GIMP_GEGL_RECT (0, 0, width, height),
+                                      gimp_drawable_get_format (drawable));
 
   gimp_rectangle_intersect (x, y,
                             width, height,
                             0, 0,
-                            drawable_width, drawable_height,
+                            gimp_item_get_width  (GIMP_ITEM (drawable)),
+                            gimp_item_get_height (GIMP_ITEM (drawable)),
                             &x, &y,
                             &width, &height);
 
-  orig_buffer =
-    gegl_buffer_linear_new_from_data (core->orig_buf->data,
-                                      gimp_drawable_get_format (drawable),
-                                      GIMP_GEGL_RECT (x - core->orig_buf->x,
-                                                      y - core->orig_buf->y,
-                                                      width, height),
-                                      core->orig_buf->width *
-                                      core->orig_buf->bytes,
-                                      NULL, NULL);
-
   gegl_buffer_copy (core->undo_buffer,
                     GIMP_GEGL_RECT (x, y, width, height),
-                    orig_buffer,
-                    GIMP_GEGL_RECT (x - core->orig_buf->x,
-                                    y - core->orig_buf->y,
+                    core->orig_buf,
+                    GIMP_GEGL_RECT (x - orig_x, y - orig_y,
                                     width, height));
 
-  g_object_unref (orig_buffer);
-
   return core->orig_buf;
 }
 
-TempBuf *
+GeglBuffer *
 gimp_paint_core_get_orig_proj (GimpPaintCore *core,
                                GimpPickable  *pickable,
                                gint           x,
@@ -743,53 +735,42 @@ gimp_paint_core_get_orig_proj (GimpPaintCore *core,
                                gint           width,
                                gint           height)
 {
-  GeglBuffer   *pickable_buffer;
-  GeglBuffer   *orig_buffer;
-  const Babl   *pickable_format;
-  gint          pickable_width;
-  gint          pickable_height;
+  GeglBuffer *pickable_buffer;
+  gint        orig_x = x;
+  gint        orig_y = y;
 
   g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL);
   g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), NULL);
   g_return_val_if_fail (core->saved_proj_buffer != NULL, NULL);
 
-  pickable_format = gimp_pickable_get_format (pickable);
+  if (core->orig_proj_buf &&
+      (gegl_buffer_get_width  (core->orig_proj_buf) != width ||
+       gegl_buffer_get_height (core->orig_proj_buf) != height))
+    {
+      g_object_unref (core->orig_proj_buf);
+      core->orig_proj_buf = NULL;
+    }
 
-  core->orig_proj_buf = temp_buf_resize (core->orig_proj_buf,
-                                         babl_format_get_bytes_per_pixel (pickable_format),
-                                         x, y, width, height);
+  if (! core->orig_proj_buf)
+    core->orig_proj_buf = gegl_buffer_new (GIMP_GEGL_RECT (0, 0, width, height),
+                                           gimp_pickable_get_format (pickable));
 
   pickable_buffer = gimp_pickable_get_buffer (pickable);
 
-  pickable_width  = gegl_buffer_get_width  (pickable_buffer);
-  pickable_height = gegl_buffer_get_height (pickable_buffer);
-
   gimp_rectangle_intersect (x, y,
                             width, height,
                             0, 0,
-                            pickable_width, pickable_height,
+                            gegl_buffer_get_width  (pickable_buffer),
+                            gegl_buffer_get_height (pickable_buffer),
                             &x, &y,
                             &width, &height);
 
-  orig_buffer =
-    gegl_buffer_linear_new_from_data (core->orig_proj_buf->data,
-                                      gimp_pickable_get_format (pickable),
-                                      GIMP_GEGL_RECT (x - core->orig_proj_buf->x,
-                                                      y - core->orig_proj_buf->y,
-                                                      width, height),
-                                      core->orig_proj_buf->width *
-                                      core->orig_proj_buf->bytes,
-                                      NULL, NULL);
-
   gegl_buffer_copy (core->saved_proj_buffer,
                     GIMP_GEGL_RECT (x, y, width, height),
-                    orig_buffer,
-                    GIMP_GEGL_RECT (x - core->orig_proj_buf->x,
-                                    y - core->orig_proj_buf->y,
+                    core->orig_proj_buf,
+                    GIMP_GEGL_RECT (x - orig_x, y - orig_y,
                                     width, height));
 
-  g_object_unref (orig_buffer);
-
   return core->orig_proj_buf;
 }
 
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index cbdb2d1..b99349c 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -59,8 +59,8 @@ struct _GimpPaintCore
   GeglBuffer  *saved_proj_buffer; /*  proj tiles which have been modified */
   GeglBuffer  *canvas_buffer;     /*  the buffer to paint the mask to     */
 
-  TempBuf     *orig_buf;          /*  the unmodified drawable pixels      */
-  TempBuf     *orig_proj_buf;     /*  the unmodified projection pixels    */
+  GeglBuffer  *orig_buf;          /*  the unmodified drawable pixels      */
+  GeglBuffer  *orig_proj_buf;     /*  the unmodified projection pixels    */
   TempBuf     *canvas_buf;        /*  the buffer to paint pixels to       */
 
   GArray      *stroke_buffer;
@@ -153,17 +153,17 @@ void      gimp_paint_core_round_line                (GimpPaintCore    *core,
 
 /*  protected functions  */
 
-TempBuf * gimp_paint_core_get_paint_area            (GimpPaintCore    *core,
+TempBuf    * gimp_paint_core_get_paint_area         (GimpPaintCore    *core,
                                                      GimpDrawable     *drawable,
                                                      GimpPaintOptions *options,
                                                      const GimpCoords *coords);
-TempBuf * gimp_paint_core_get_orig_image            (GimpPaintCore    *core,
+GeglBuffer * gimp_paint_core_get_orig_image         (GimpPaintCore    *core,
                                                      GimpDrawable     *drawable,
                                                      gint              x,
                                                      gint              y,
                                                      gint              width,
                                                      gint              height);
-TempBuf * gimp_paint_core_get_orig_proj             (GimpPaintCore    *core,
+GeglBuffer * gimp_paint_core_get_orig_proj          (GimpPaintCore    *core,
                                                      GimpPickable     *pickable,
                                                      gint              x,
                                                      gint              y,
diff --git a/app/paint/gimpperspectiveclone.c b/app/paint/gimpperspectiveclone.c
index f3acc10..8e6da15 100644
--- a/app/paint/gimpperspectiveclone.c
+++ b/app/paint/gimpperspectiveclone.c
@@ -316,12 +316,6 @@ gimp_perspective_clone_get_source (GimpSourceCore   *source_core,
   if (!(xmax - xmin) || !(ymax - ymin))
     return FALSE;
 
-  /*  copy the original image to a buffer, adding alpha if needed  */
-
-  orig_buffer = gegl_buffer_new (GIMP_GEGL_RECT (0, 0,
-                                                 xmax - xmin, ymax - ymin),
-                                 src_format_alpha);
-
   /*  If the source image is different from the destination,
    *  then we should copy straight from the source image
    *  to the canvas.
@@ -331,6 +325,10 @@ gimp_perspective_clone_get_source (GimpSourceCore   *source_core,
   if ((  options->sample_merged && (src_image                 != image)) ||
       (! options->sample_merged && (source_core->src_drawable != drawable)))
     {
+      orig_buffer = gegl_buffer_new (GIMP_GEGL_RECT (0, 0,
+                                                     xmax - xmin, ymax - ymin),
+                                     src_format_alpha);
+
       gegl_buffer_copy (src_buffer,
                         GIMP_GEGL_RECT (xmin, ymin,
                                         xmax - xmin, ymax - ymin),
@@ -339,42 +337,26 @@ gimp_perspective_clone_get_source (GimpSourceCore   *source_core,
     }
   else
     {
-      TempBuf    *orig;
-      GeglBuffer *temp_buffer;
-
       /*  get the original image  */
       if (options->sample_merged)
-        orig = gimp_paint_core_get_orig_proj (paint_core,
-                                              src_pickable,
-                                              xmin, ymin,
-                                              xmax - xmin,
-                                              ymax - ymin);
+        orig_buffer = gimp_paint_core_get_orig_proj (paint_core,
+                                                     src_pickable,
+                                                     xmin, ymin,
+                                                     xmax - xmin,
+                                                     ymax - ymin);
       else
-        orig = gimp_paint_core_get_orig_image (paint_core,
-                                               GIMP_DRAWABLE (src_pickable),
-                                               xmin, ymin,
-                                               xmax - xmin,
-                                               ymax - ymin);
-
-      temp_buffer =
-        gegl_buffer_linear_new_from_data (temp_buf_get_data (orig),
-                                          gimp_bpp_to_babl_format (orig->bytes),
-                                          GIMP_GEGL_RECT (0, 0,
-                                                          orig->width,
-                                                          orig->height),
-                                          orig->width * orig->bytes,
-                                          NULL, NULL);
-
-      gegl_buffer_copy (temp_buffer,
-                        GIMP_GEGL_RECT (0, 0, xmax - xmin, ymax - ymin),
-                        orig_buffer,
-                        NULL);
+        orig_buffer = gimp_paint_core_get_orig_image (paint_core,
+                                                      GIMP_DRAWABLE (src_pickable),
+                                                      xmin, ymin,
+                                                      xmax - xmin,
+                                                      ymax - ymin);
 
-      g_object_unref (temp_buffer);
+      g_object_ref (orig_buffer);
     }
 
   dest_buffer = gegl_buffer_new (GIMP_GEGL_RECT (0, 0, x2d - x1d, y2d - y1d),
                                  src_format_alpha);
+  gegl_buffer_clear (dest_buffer, NULL);
 
   gimp_perspective_clone_get_matrix (clone, &matrix);
 
diff --git a/app/paint/gimpsourcecore.c b/app/paint/gimpsourcecore.c
index a7e7311..288077e 100644
--- a/app/paint/gimpsourcecore.c
+++ b/app/paint/gimpsourcecore.c
@@ -504,24 +504,19 @@ gimp_source_core_real_get_source (GimpSourceCore   *source_core,
     }
   else
     {
-      TempBuf *orig;
-
       /*  get the original image  */
       if (options->sample_merged)
-        orig = gimp_paint_core_get_orig_proj (GIMP_PAINT_CORE (source_core),
-                                              src_pickable,
-                                              x, y, width, height);
+        dest_buffer =
+          gimp_paint_core_get_orig_proj (GIMP_PAINT_CORE (source_core),
+                                         src_pickable,
+                                         x, y, width, height);
       else
-        orig = gimp_paint_core_get_orig_image (GIMP_PAINT_CORE (source_core),
-                                               GIMP_DRAWABLE (src_pickable),
-                                               x, y, width, height);
-
-      dest_buffer =
-        gegl_buffer_linear_new_from_data (temp_buf_get_data (orig),
-                                          gimp_pickable_get_format (src_pickable),
-                                          GIMP_GEGL_RECT (0, 0, width, height),
-                                          orig->width * orig->bytes,
-                                          NULL, NULL);
+        dest_buffer =
+          gimp_paint_core_get_orig_image (GIMP_PAINT_CORE (source_core),
+                                          GIMP_DRAWABLE (src_pickable),
+                                          x, y, width, height);
+
+      g_object_ref (dest_buffer);
     }
 
   *paint_area_offset_x = x - (paint_area->x + src_offset_x);



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