[gimp/goat-invasion] app: remove drawable->private->format, its buffer has a format already



commit 1ee48258cbe553ab63cbe5d8554db4f0083e8f36
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 29 23:19:27 2012 +0200

    app: remove drawable->private->format, its buffer has a format already
    
    Also, make group layer type conversion much less hackish by using the
    same kind of temporary states that are used for reallocating its
    projection on size change.

 app/core/gimpdrawable-private.h |    2 -
 app/core/gimpdrawable.c         |   21 ++++++----
 app/core/gimpgrouplayer.c       |   82 ++++++++++++++++++--------------------
 app/core/gimpimage-convert.c    |    6 +++
 app/text/gimptextlayer-xcf.c    |    1 -
 app/xcf/xcf-load.c              |    3 -
 6 files changed, 57 insertions(+), 58 deletions(-)
---
diff --git a/app/core/gimpdrawable-private.h b/app/core/gimpdrawable-private.h
index fe3981b..3cf2e85 100644
--- a/app/core/gimpdrawable-private.h
+++ b/app/core/gimpdrawable-private.h
@@ -20,8 +20,6 @@
 
 struct _GimpDrawablePrivate
 {
-  const Babl    *format; /* format of drawable      */
-
   GeglBuffer    *buffer; /* buffer for drawable data */
   GeglBuffer    *shadow; /* shadow buffer            */
 
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 7c56574..1466080 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -409,9 +409,6 @@ gimp_drawable_duplicate (GimpItem *item,
     {
       GimpDrawable  *drawable     = GIMP_DRAWABLE (item);
       GimpDrawable  *new_drawable = GIMP_DRAWABLE (new_item);
-      const Babl    *format       = gimp_drawable_get_format (drawable);
-
-      new_drawable->private->format = format;
 
       if (new_drawable->private->buffer)
         g_object_unref (new_drawable->private->buffer);
@@ -797,7 +794,6 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
   if (drawable->private->buffer)
     g_object_unref (drawable->private->buffer);
 
-  drawable->private->format = gegl_buffer_get_format (buffer);
   drawable->private->buffer = buffer;
 
   gimp_item_set_offset (item, offset_x, offset_y);
@@ -1131,7 +1127,6 @@ gimp_drawable_new (GType          type,
                                            offset_x, offset_y,
                                            width, height));
 
-  drawable->private->format = format;
   drawable->private->buffer = gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0,
                                                                     width, height),
                                                     format);
@@ -1649,7 +1644,7 @@ gimp_drawable_get_format (const GimpDrawable *drawable)
 {
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
 
-  return drawable->private->format;
+  return gegl_buffer_get_format (drawable->private->buffer);
 }
 
 const Babl *
@@ -1673,9 +1668,13 @@ gimp_drawable_get_format_without_alpha (const GimpDrawable *drawable)
 gboolean
 gimp_drawable_has_alpha (const GimpDrawable *drawable)
 {
+  const Babl *format;
+
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
 
-  return babl_format_has_alpha (drawable->private->format);
+  format = gegl_buffer_get_format (drawable->private->buffer);
+
+  return babl_format_has_alpha (format);
 }
 
 GimpImageType
@@ -1685,7 +1684,7 @@ gimp_drawable_type (const GimpDrawable *drawable)
 
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
 
-  format = drawable->private->format;
+  format = gegl_buffer_get_format (drawable->private->buffer);
 
   if (format == babl_format ("Y' u8"))
     return GIMP_GRAY_IMAGE;
@@ -1751,9 +1750,13 @@ gimp_drawable_is_indexed (const GimpDrawable *drawable)
 gint
 gimp_drawable_bytes (const GimpDrawable *drawable)
 {
+  const Babl *format;
+
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
 
-  return babl_format_get_bytes_per_pixel (drawable->private->format);
+  format = gegl_buffer_get_format (drawable->private->buffer);
+
+  return babl_format_get_bytes_per_pixel (format);
 }
 
 gint
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index ce977f4..b6f44e8 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -29,14 +29,11 @@
 
 #include "core-types.h"
 
-#include "base/tile-manager.h"
-
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimpgrouplayer.h"
 #include "gimpimage.h"
 #include "gimpimage-undo-push.h"
-#include "gimpdrawable-private.h" /* eek */
 #include "gimpdrawablestack.h"
 #include "gimppickable.h"
 #include "gimpprojectable.h"
@@ -57,6 +54,7 @@ struct _GimpGroupLayerPrivate
   gboolean        expanded;
 
   /*  hackish temp states to make the projection/tiles stuff work  */
+  const Babl     *convert_format;
   gboolean        reallocate_projection;
   gint            reallocate_width;
   gint            reallocate_height;
@@ -825,6 +823,25 @@ gimp_group_layer_estimate_memsize (const GimpDrawable *drawable,
                                                                          height);
 }
 
+static const Babl *
+get_projection_format (GimpProjectable   *projectable,
+                       GimpImageBaseType  base_type)
+{
+  switch (base_type)
+    {
+    case GIMP_RGB:
+    case GIMP_INDEXED:
+      return babl_format ("R'G'B'A u8");
+
+    case GIMP_GRAY:
+      return babl_format ("Y'A u8");
+    }
+
+  g_assert_not_reached ();
+
+  return NULL;
+}
+
 static void
 gimp_group_layer_convert_type (GimpDrawable      *drawable,
                                GimpImage         *dest_image,
@@ -833,9 +850,7 @@ gimp_group_layer_convert_type (GimpDrawable      *drawable,
 {
   GimpGroupLayer        *group   = GIMP_GROUP_LAYER (drawable);
   GimpGroupLayerPrivate *private = GET_PRIVATE (drawable);
-  TileManager           *tiles;
   GeglBuffer            *buffer;
-  GimpImageType          new_type;
 
   if (push_undo)
     {
@@ -844,24 +859,15 @@ gimp_group_layer_convert_type (GimpDrawable      *drawable,
       gimp_image_undo_push_group_layer_convert (image, NULL, group);
     }
 
-  new_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_base_type);
-
-  if (gimp_drawable_has_alpha (drawable))
-    new_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_type);
-
-  /*  FIXME: find a better way to do this: need to set the drawable's
-   *  format to the new values so the projection will create its tiles
-   *  with the right depth
+  /*  Need to temporarily set the projectable's format to the new
+   *  values so the projection will create its tiles with the right
+   *  depth
    */
-  drawable->private->format = gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
-                                                     new_type);
-
+  private->convert_format = get_projection_format (GIMP_PROJECTABLE (drawable),
+                                                   new_base_type);
   gimp_projectable_structure_changed (GIMP_PROJECTABLE (drawable));
 
-  tiles = gimp_projection_get_tiles_at_level (private->projection,
-                                              0, NULL);
-
-  buffer = gimp_tile_manager_create_buffer (tiles, gimp_drawable_get_format (drawable));
+  buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (private->projection));
 
   gimp_drawable_set_buffer_full (drawable,
                                  FALSE, NULL,
@@ -869,27 +875,22 @@ gimp_group_layer_convert_type (GimpDrawable      *drawable,
                                  gimp_item_get_offset_x (GIMP_ITEM (drawable)),
                                  gimp_item_get_offset_y (GIMP_ITEM (drawable)));
 
-  g_object_unref (buffer);
+  /*  reset, the actual format is right now  */
+  private->convert_format = NULL;
 }
 
 static const Babl *
 gimp_group_layer_get_format (GimpProjectable *projectable)
 {
-  GimpDrawable *drawable = GIMP_DRAWABLE (projectable);
+  GimpGroupLayerPrivate *private = GET_PRIVATE (projectable);
+  GimpImageBaseType      base_type;
 
-  switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
-    {
-    case GIMP_RGB:
-    case GIMP_INDEXED:
-      return babl_format ("R'G'B'A u8");
+  if (private->convert_format)
+    return private->convert_format;
 
-    case GIMP_GRAY:
-      return babl_format ("Y'A u8");
-    }
+  base_type = GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (projectable)));
 
-  g_assert_not_reached ();
-
-  return NULL;
+  return get_projection_format (projectable, base_type);
 }
 
 static GeglNode *
@@ -1126,8 +1127,7 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
           width  != old_width            ||
           height != old_height)
         {
-          TileManager *tiles;
-          GeglBuffer  *buffer;
+          GeglBuffer *buffer;
 
           private->reallocate_projection = FALSE;
 
@@ -1139,20 +1139,16 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
 
           gimp_projectable_structure_changed (GIMP_PROJECTABLE (group));
 
-          tiles = gimp_projection_get_tiles_at_level (private->projection,
-                                                      0, NULL);
-
-          private->reallocate_width  = 0;
-          private->reallocate_height = 0;
-
-          buffer = gimp_tile_manager_create_buffer (tiles, gimp_drawable_get_format (GIMP_DRAWABLE (group)));
+          buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (private->projection));
 
           gimp_drawable_set_buffer_full (GIMP_DRAWABLE (group),
                                          FALSE, NULL,
                                          buffer,
                                          x, y);
 
-          g_object_unref (buffer);
+          /*  reset, the actual size is correct now  */
+          private->reallocate_width  = 0;
+          private->reallocate_height = 0;
         }
       else
         {
diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c
index f157cea..152c80f 100644
--- a/app/core/gimpimage-convert.c
+++ b/app/core/gimpimage-convert.c
@@ -1004,6 +1004,12 @@ gimp_image_convert (GimpImage               *image,
             else
               new_format = gimp_image_get_format (image, GIMP_INDEXED_IMAGE);
 
+            g_printerr ("old: %s %d   new: %s %d\n",
+                        babl_get_name (gimp_drawable_get_format (GIMP_DRAWABLE (layer))),
+                        babl_format_has_alpha (gimp_drawable_get_format (GIMP_DRAWABLE (layer))),
+                        babl_get_name (new_format),
+                        babl_format_has_alpha (new_format));
+
             new_buffer =
               gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0,
                                                     gimp_item_get_width  (GIMP_ITEM (layer)),
diff --git a/app/text/gimptextlayer-xcf.c b/app/text/gimptextlayer-xcf.c
index 47882cd..75a14f2 100644
--- a/app/text/gimptextlayer-xcf.c
+++ b/app/text/gimptextlayer-xcf.c
@@ -194,7 +194,6 @@ gimp_text_layer_from_layer (GimpLayer *layer,
 
   drawable = GIMP_DRAWABLE (text_layer);
 
-  drawable->private->format = gimp_drawable_get_format (GIMP_DRAWABLE (layer));
   drawable->private->buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
   GIMP_DRAWABLE (layer)->private->buffer = NULL;
 
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 3c54014..956874b 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -865,9 +865,6 @@ xcf_load_layer_props (XcfInfo    *info,
             gimp_object_set_name (GIMP_OBJECT (group),
                                   gimp_object_get_name (*layer));
 
-            GIMP_DRAWABLE (group)->private->format =
-              gimp_drawable_get_format (GIMP_DRAWABLE (*layer));
-
             g_object_ref_sink (*layer);
             g_object_unref (*layer);
             *layer = group;



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