[gimp] Optionally make a copy of the drawable's tiles in GimpDrawableModUndo



commit 8688037a58c86f928b91689056953d7452bb4efa
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 18 10:25:18 2010 +0100

    Optionally make a copy of the drawable's tiles in GimpDrawableModUndo
    
    instead of simply reffing drawable->tiles. Add boolean property "copy-tiles"
    and a boolean parameter to gimp_image_undo_push_drawable_mod() to control
    the new feature. However, pass FALSE in gimp_drawable_real_set_tiles() (which
    currently is the undo's only user)

 app/core/gimpdrawable.c        |    2 +-
 app/core/gimpdrawablemodundo.c |  121 ++++++++++++++++++++++++++++++++++-----
 app/core/gimpdrawablemodundo.h |    1 +
 app/core/gimpimage-undo-push.c |    6 +-
 app/core/gimpimage-undo-push.h |    3 +-
 5 files changed, 113 insertions(+), 20 deletions(-)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 75e01be..887769c 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -783,7 +783,7 @@ gimp_drawable_real_set_tiles (GimpDrawable *drawable,
 
   if (push_undo)
     gimp_image_undo_push_drawable_mod (gimp_item_get_image (item), undo_desc,
-                                       drawable);
+                                       drawable, FALSE);
 
   /*  ref new before unrefing old, they might be the same  */
   tile_manager_ref (tiles);
diff --git a/app/core/gimpdrawablemodundo.c b/app/core/gimpdrawablemodundo.c
index 3615592..a416790 100644
--- a/app/core/gimpdrawablemodundo.c
+++ b/app/core/gimpdrawablemodundo.c
@@ -21,25 +21,44 @@
 
 #include "core-types.h"
 
+#include "base/pixel-region.h"
 #include "base/tile-manager.h"
 
+#include "paint-funcs/paint-funcs.h"
+
 #include "gimpimage.h"
 #include "gimpdrawable.h"
 #include "gimpdrawablemodundo.h"
 
 
-static GObject * gimp_drawable_mod_undo_constructor (GType                  type,
-                                                     guint                  n_params,
-                                                     GObjectConstructParam *params);
+enum
+{
+  PROP_0,
+  PROP_COPY_TILES
+};
+
+
+static GObject * gimp_drawable_mod_undo_constructor  (GType                  type,
+                                                      guint                  n_params,
+                                                      GObjectConstructParam *params);
+static void      gimp_drawable_mod_undo_set_property (GObject               *object,
+                                                      guint                  property_id,
+                                                      const GValue          *value,
+                                                      GParamSpec            *pspec);
+static void      gimp_drawable_mod_undo_get_property (GObject               *object,
+                                                      guint                  property_id,
+                                                      GValue                *value,
+                                                      GParamSpec            *pspec);
 
-static gint64    gimp_drawable_mod_undo_get_memsize (GimpObject            *object,
-                                                     gint64                *gui_size);
 
-static void      gimp_drawable_mod_undo_pop         (GimpUndo              *undo,
-                                                     GimpUndoMode           undo_mode,
-                                                     GimpUndoAccumulator   *accum);
-static void      gimp_drawable_mod_undo_free        (GimpUndo              *undo,
-                                                     GimpUndoMode           undo_mode);
+static gint64    gimp_drawable_mod_undo_get_memsize  (GimpObject            *object,
+                                                      gint64                *gui_size);
+
+static void      gimp_drawable_mod_undo_pop          (GimpUndo              *undo,
+                                                      GimpUndoMode           undo_mode,
+                                                      GimpUndoAccumulator   *accum);
+static void      gimp_drawable_mod_undo_free         (GimpUndo              *undo,
+                                                      GimpUndoMode           undo_mode);
 
 
 G_DEFINE_TYPE (GimpDrawableModUndo, gimp_drawable_mod_undo, GIMP_TYPE_ITEM_UNDO)
@@ -55,11 +74,19 @@ gimp_drawable_mod_undo_class_init (GimpDrawableModUndoClass *klass)
   GimpUndoClass   *undo_class        = GIMP_UNDO_CLASS (klass);
 
   object_class->constructor      = gimp_drawable_mod_undo_constructor;
+  object_class->set_property     = gimp_drawable_mod_undo_set_property;
+  object_class->get_property     = gimp_drawable_mod_undo_get_property;
 
   gimp_object_class->get_memsize = gimp_drawable_mod_undo_get_memsize;
 
   undo_class->pop                = gimp_drawable_mod_undo_pop;
   undo_class->free               = gimp_drawable_mod_undo_free;
+
+  g_object_class_install_property (object_class, PROP_COPY_TILES,
+                                   g_param_spec_boolean ("copy-tiles", NULL, NULL,
+                                                         FALSE,
+                                                         GIMP_PARAM_READWRITE |
+                                                         G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -67,6 +94,46 @@ gimp_drawable_mod_undo_init (GimpDrawableModUndo *undo)
 {
 }
 
+static void
+gimp_drawable_mod_undo_set_property (GObject      *object,
+                                     guint         property_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  GimpDrawableModUndo *drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (object);
+
+  switch (property_id)
+    {
+    case PROP_COPY_TILES:
+      drawable_mod_undo->copy_tiles = g_value_get_boolean (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_drawable_mod_undo_get_property (GObject    *object,
+                                     guint       property_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
+{
+  GimpDrawableModUndo *drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (object);
+
+  switch (property_id)
+    {
+    case PROP_COPY_TILES:
+      g_value_set_boolean (value, drawable_mod_undo->copy_tiles);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
 static GObject *
 gimp_drawable_mod_undo_constructor (GType                  type,
                                     guint                  n_params,
@@ -74,6 +141,7 @@ gimp_drawable_mod_undo_constructor (GType                  type,
 {
   GObject             *object;
   GimpDrawableModUndo *drawable_mod_undo;
+  GimpItem            *item;
   GimpDrawable        *drawable;
 
   object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
@@ -82,12 +150,33 @@ gimp_drawable_mod_undo_constructor (GType                  type,
 
   g_assert (GIMP_IS_DRAWABLE (GIMP_ITEM_UNDO (object)->item));
 
-  drawable = GIMP_DRAWABLE (GIMP_ITEM_UNDO (object)->item);
+  item     = GIMP_ITEM_UNDO (object)->item;
+  drawable = GIMP_DRAWABLE (item);
 
-  drawable_mod_undo->tiles = tile_manager_ref (gimp_drawable_get_tiles (drawable));
-  drawable_mod_undo->type  = gimp_drawable_type (drawable);
+  if (drawable_mod_undo->copy_tiles)
+    {
+      PixelRegion srcPR, destPR;
+      gint        width  = gimp_item_get_width (item);
+      gint        height = gimp_item_get_height (item);
+
+      drawable_mod_undo->tiles =
+        tile_manager_new (width, height,
+                          gimp_drawable_bytes (drawable));
+      pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
+                         0, 0, width, height, FALSE);
+      pixel_region_init (&destPR, drawable_mod_undo->tiles,
+                         0, 0, width, height, TRUE);
+      copy_region (&srcPR, &destPR);
+    }
+  else
+    {
+      drawable_mod_undo->tiles =
+        tile_manager_ref (gimp_drawable_get_tiles (drawable));
+    }
 
-  gimp_item_get_offset (GIMP_ITEM (drawable),
+  drawable_mod_undo->type = gimp_drawable_type (drawable);
+
+  gimp_item_get_offset (item,
                         &drawable_mod_undo->offset_x,
                         &drawable_mod_undo->offset_y);
 
diff --git a/app/core/gimpdrawablemodundo.h b/app/core/gimpdrawablemodundo.h
index a4617ab..1a9ed27 100644
--- a/app/core/gimpdrawablemodundo.h
+++ b/app/core/gimpdrawablemodundo.h
@@ -37,6 +37,7 @@ struct _GimpDrawableModUndo
   GimpItemUndo   parent_instance;
 
   TileManager   *tiles;
+  gboolean       copy_tiles;
   GimpImageType  type;
   gint           offset_x;
   gint           offset_y;
diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c
index 5b5e157..ec071f1 100644
--- a/app/core/gimpimage-undo-push.c
+++ b/app/core/gimpimage-undo-push.c
@@ -254,7 +254,8 @@ gimp_image_undo_push_drawable (GimpImage    *image,
 GimpUndo *
 gimp_image_undo_push_drawable_mod (GimpImage    *image,
                                    const gchar  *undo_desc,
-                                   GimpDrawable *drawable)
+                                   GimpDrawable *drawable,
+                                   gboolean      copy_tiles)
 {
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
@@ -263,7 +264,8 @@ gimp_image_undo_push_drawable_mod (GimpImage    *image,
   return gimp_image_undo_push (image, GIMP_TYPE_DRAWABLE_MOD_UNDO,
                                GIMP_UNDO_DRAWABLE_MOD, undo_desc,
                                GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE,
-                               "item", drawable,
+                               "item",       drawable,
+                               "copy-tiles", copy_tiles,
                                NULL);
 }
 
diff --git a/app/core/gimpimage-undo-push.h b/app/core/gimpimage-undo-push.h
index 5ff1ec2..8baea0c 100644
--- a/app/core/gimpimage-undo-push.h
+++ b/app/core/gimpimage-undo-push.h
@@ -67,7 +67,8 @@ GimpUndo * gimp_image_undo_push_drawable            (GimpImage     *image,
                                                      gint           height);
 GimpUndo * gimp_image_undo_push_drawable_mod        (GimpImage     *image,
                                                      const gchar   *undo_desc,
-                                                     GimpDrawable  *drawable);
+                                                     GimpDrawable  *drawable,
+                                                     gboolean       copy_tiles);
 
 
 /*  mask undo  */



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