[gimp/goat-invasion: 103/608] app: require a Babl for all buffers created on top of tiles



commit 43ba3e73fe6f24f1f3e1dd207ba97a6a5be1bb0b
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 17 21:21:36 2012 +0100

    app: require a Babl for all buffers created on top of tiles
    
    Fixes quite some introduced glitches with indexed mode because
    the buffers use the right pixel format now.

 app/core/gimp-edit.c                |   13 ++++++++---
 app/core/gimpchannel.c              |    9 +++----
 app/core/gimpdrawable-convert.c     |    4 +-
 app/core/gimpdrawable-offset.c      |    4 ++-
 app/core/gimpdrawable-operation.c   |    5 +++-
 app/core/gimpdrawable-stroke.c      |    2 +-
 app/core/gimpdrawable.c             |   39 ++++++++++++++++++++++++++++++++--
 app/core/gimpdrawable.h             |    2 +
 app/core/gimpimagemap.c             |   14 +++++++++---
 app/core/gimplayer.c                |   13 +++++++----
 app/core/gimpprojection-construct.c |    2 +-
 app/core/gimpprojection.c           |    6 ++--
 app/gegl/gimp-gegl-utils.c          |   34 +-----------------------------
 app/gegl/gimp-gegl-utils.h          |    8 +-----
 14 files changed, 86 insertions(+), 69 deletions(-)
---
diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c
index 68a5bd9..040a3af 100644
--- a/app/core/gimp-edit.c
+++ b/app/core/gimp-edit.c
@@ -520,7 +520,7 @@ gimp_edit_extract (GimpImage     *image,
       GeglBuffer *temp;
       GimpBuffer *buffer;
 
-      temp = gimp_tile_manager_create_buffer (tiles, TRUE);
+      temp = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
       tile_manager_unref (tiles);
 
       buffer = gimp_buffer_new (temp, _("Global Buffer"),
@@ -549,6 +549,7 @@ gimp_edit_fill_internal (GimpImage            *image,
   gint           x, y, width, height;
   GimpImageType  drawable_type;
   gint           tiles_bytes;
+  const Babl    *format;
   guchar         col[MAX_CHANNELS];
   TempBuf       *pat_buf = NULL;
   gboolean       new_buf;
@@ -558,6 +559,7 @@ gimp_edit_fill_internal (GimpImage            *image,
 
   drawable_type = gimp_drawable_type (drawable);
   tiles_bytes   = gimp_drawable_bytes (drawable);
+  format        = gimp_drawable_get_babl_format (drawable);
 
   switch (fill_type)
     {
@@ -588,7 +590,10 @@ gimp_edit_fill_internal (GimpImage            *image,
 
         if (! gimp_drawable_has_alpha (drawable) &&
             (pat_buf->bytes == 2 || pat_buf->bytes == 4))
-          tiles_bytes++;
+          {
+            tiles_bytes++;
+            format = gimp_drawable_get_babl_format_with_alpha (drawable);
+          }
       }
       break;
 
@@ -598,7 +603,7 @@ gimp_edit_fill_internal (GimpImage            *image,
 
   buf_tiles = tile_manager_new (width, height, tiles_bytes);
 
-  dest_buffer = gimp_tile_manager_create_buffer (buf_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (buf_tiles, format, TRUE);
 
   if (pat_buf)
     {
@@ -609,7 +614,7 @@ gimp_edit_fill_internal (GimpImage            *image,
       rect.height = pat_buf->height;
 
       src_buffer = gegl_buffer_linear_new_from_data (temp_buf_get_data (pat_buf),
-                                                     gimp_bpp_to_babl_format (tiles_bytes, TRUE),
+                                                     format,
                                                      &rect,
                                                      rect.width * pat_buf->bytes,
                                                      NULL, NULL);
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 3dc2d7e..d66429f 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -1660,9 +1660,9 @@ gimp_channel_new_from_alpha (GimpImage     *image,
   gimp_channel_clear (channel, NULL, FALSE);
 
   dest_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (channel));
-  dest_buffer = gimp_tile_manager_create_buffer_with_format (dest_tiles,
-                                                             babl_format ("A u8"),
-                                                             TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (dest_tiles,
+                                                 babl_format ("A u8"),
+                                                 TRUE);
 
   gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
                     dest_buffer, NULL);
@@ -1706,8 +1706,7 @@ gimp_channel_new_from_component (GimpImage       *image,
   channel = gimp_channel_new (image, width, height, name, color);
 
   dest_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (channel));
-  dest_buffer = gimp_tile_manager_create_buffer_with_format (dest_tiles,
-                                                             format, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (dest_tiles, format, TRUE);
 
   gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
 
diff --git a/app/core/gimpdrawable-convert.c b/app/core/gimpdrawable-convert.c
index 96a7e7e..babdac6 100644
--- a/app/core/gimpdrawable-convert.c
+++ b/app/core/gimpdrawable-convert.c
@@ -101,7 +101,7 @@ gimp_drawable_convert_tiles_rgb (GimpDrawable *drawable,
 
   g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 4 : 3));
 
-  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, NULL, TRUE);
 
   gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
                     dest_buffer, NULL);
@@ -124,7 +124,7 @@ gimp_drawable_convert_tiles_grayscale (GimpDrawable *drawable,
 
   g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 2 : 1));
 
-  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, NULL, TRUE);
 
   gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
                     dest_buffer, NULL);
diff --git a/app/core/gimpdrawable-offset.c b/app/core/gimpdrawable-offset.c
index 19ff529..c8cc30d 100644
--- a/app/core/gimpdrawable-offset.c
+++ b/app/core/gimpdrawable-offset.c
@@ -89,7 +89,9 @@ gimp_drawable_offset (GimpDrawable   *drawable,
   new_tiles = tile_manager_new (width, height, gimp_drawable_bytes (drawable));
 
   src_buffer  = gimp_drawable_get_read_buffer (drawable);
-  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (new_tiles,
+                                                 gimp_drawable_get_babl_format (drawable),
+                                                 TRUE);
 
   if (! wrap_around)
     {
diff --git a/app/core/gimpdrawable-operation.c b/app/core/gimpdrawable-operation.c
index c26c2f9..4d4a996 100644
--- a/app/core/gimpdrawable-operation.c
+++ b/app/core/gimpdrawable-operation.c
@@ -63,6 +63,7 @@ gimp_drawable_apply_operation (GimpDrawable *drawable,
 
   dest_buffer =
     gimp_tile_manager_create_buffer (gimp_drawable_get_shadow_tiles (drawable),
+                                     gimp_drawable_get_babl_format (drawable),
                                      TRUE);
 
   gimp_apply_operation (gimp_drawable_get_read_buffer (drawable),
@@ -149,7 +150,9 @@ gimp_drawable_apply_operation_to_tiles (GimpDrawable *drawable,
   g_return_if_fail (GEGL_IS_NODE (operation));
   g_return_if_fail (dest_tiles != NULL);
 
-  dest_buffer = gimp_tile_manager_create_buffer (dest_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (dest_tiles,
+                                                 gimp_drawable_get_babl_format (drawable),
+                                                 TRUE);
 
   gimp_drawable_apply_operation_to_buffer (drawable,
                                            progress,
diff --git a/app/core/gimpdrawable-stroke.c b/app/core/gimpdrawable-stroke.c
index 25cc9d1..a63330e 100644
--- a/app/core/gimpdrawable-stroke.c
+++ b/app/core/gimpdrawable-stroke.c
@@ -346,7 +346,7 @@ gimp_drawable_stroke_scan_convert (GimpDrawable    *drawable,
    */
   mask = tile_manager_new (w, h, 1);
 
-  tmp_buffer = gimp_tile_manager_create_buffer (mask, TRUE);
+  tmp_buffer = gimp_tile_manager_create_buffer (mask, NULL, TRUE);
   gegl_buffer_clear (tmp_buffer, NULL);
   g_object_unref (tmp_buffer);
 
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 5e249b0..e9acf46 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -576,7 +576,9 @@ gimp_drawable_resize (GimpItem    *item,
   new_tiles = tile_manager_new (new_width, new_height,
                                 gimp_drawable_bytes (drawable));
 
-  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (new_tiles,
+                                                 gimp_drawable_get_babl_format (drawable),
+                                                 TRUE);
 
   if (copy_width  != new_width ||
       copy_height != new_height)
@@ -924,7 +926,9 @@ gimp_drawable_real_push_undo (GimpDrawable *drawable,
 
       tiles = tile_manager_new (width, height, gimp_drawable_bytes (drawable));
 
-      dest_buffer = gimp_tile_manager_create_buffer (tiles, TRUE);
+      dest_buffer = gimp_tile_manager_create_buffer (tiles,
+                                                     gimp_drawable_get_babl_format (drawable),
+                                                     TRUE);
 
       src_rect.x      = x;
       src_rect.y      = y;
@@ -1503,7 +1507,7 @@ gimp_drawable_create_buffer (GimpDrawable *drawable,
   TileManager *tiles  = gimp_drawable_get_tiles (drawable);
   const Babl  *format = gimp_drawable_get_babl_format (drawable);
 
-  return gimp_tile_manager_create_buffer_with_format (tiles, format, write);
+  return gimp_tile_manager_create_buffer (tiles, format, write);
 }
 
 GeglBuffer *
@@ -1877,6 +1881,35 @@ gimp_drawable_get_babl_format (const GimpDrawable *drawable)
   return NULL;
 }
 
+const Babl *
+gimp_drawable_get_babl_format_with_alpha (const GimpDrawable *drawable)
+{
+  GimpImageType type;
+
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+
+  type = gimp_drawable_type (drawable);
+
+  switch (type)
+    {
+    case GIMP_RGB_IMAGE:
+    case GIMP_RGBA_IMAGE:   return babl_format ("RGBA u8");
+    case GIMP_GRAY_IMAGE:
+    case GIMP_GRAYA_IMAGE:  return babl_format ("YA u8");
+    case GIMP_INDEXED_IMAGE:
+    case GIMP_INDEXEDA_IMAGE:
+      {
+        GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
+
+        return gimp_image_colormap_get_rgba_format (image);
+      }
+    }
+
+  g_warn_if_reached ();
+
+  return NULL;
+}
+
 gboolean
 gimp_drawable_has_alpha (const GimpDrawable *drawable)
 {
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index c99ff43..6fd6662 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -226,6 +226,8 @@ void            gimp_drawable_fill_by_type       (GimpDrawable       *drawable,
                                                   GimpFillType        fill_type);
 
 const Babl    * gimp_drawable_get_babl_format    (const GimpDrawable *drawable);
+const Babl    * gimp_drawable_get_babl_format_with_alpha
+                                                 (const GimpDrawable *drawable);
 gboolean        gimp_drawable_has_alpha          (const GimpDrawable *drawable);
 GimpImageType   gimp_drawable_type               (const GimpDrawable *drawable);
 GimpImageType   gimp_drawable_type_with_alpha    (const GimpDrawable *drawable);
diff --git a/app/core/gimpimagemap.c b/app/core/gimpimagemap.c
index 2295a15..ed8ad18 100644
--- a/app/core/gimpimagemap.c
+++ b/app/core/gimpimagemap.c
@@ -298,6 +298,7 @@ gimp_image_map_get_buffer (GimpPickable *pickable)
       if (! image_map->undo_buffer)
         image_map->undo_buffer =
           gimp_tile_manager_create_buffer (image_map->undo_tiles,
+                                           gimp_drawable_get_babl_format (image_map->drawable),
                                            FALSE);
 
       return image_map->undo_buffer;
@@ -415,13 +416,14 @@ gimp_image_map_apply (GimpImageMap        *image_map,
 
   if (image_map->operation)
     {
+      const Babl *format = gimp_drawable_get_babl_format (image_map->drawable);
       GeglBuffer *input_buffer;
       GeglBuffer *output_buffer;
 
       input_buffer =
-        gimp_tile_manager_create_buffer (image_map->undo_tiles, FALSE);
+        gimp_tile_manager_create_buffer (image_map->undo_tiles, format, FALSE);
       output_buffer =
-        gimp_tile_manager_create_buffer (gimp_drawable_get_shadow_tiles (image_map->drawable), TRUE);
+        gimp_tile_manager_create_buffer (gimp_drawable_get_shadow_tiles (image_map->drawable), format, TRUE);
 
       if (! image_map->gegl)
         {
@@ -710,7 +712,9 @@ gimp_image_map_update_undo_tiles (GimpImageMap        *image_map,
 
       /*  Copy from the image to the new tiles  */
       src = gimp_drawable_get_read_buffer (image_map->drawable);
-      dest = gimp_tile_manager_create_buffer (image_map->undo_tiles, TRUE);
+      dest = gimp_tile_manager_create_buffer (image_map->undo_tiles,
+                                              gimp_drawable_get_babl_format (image_map->drawable),
+                                              TRUE);
 
       gegl_buffer_copy (src, rect, dest, &dest_rect);
 
@@ -870,7 +874,9 @@ gimp_image_map_data_written (GObject             *operation,
       GeglRectangle  src_rect;
       GeglRectangle  dest_rect;
 
-      src = gimp_tile_manager_create_buffer (image_map->undo_tiles, FALSE);
+      src = gimp_tile_manager_create_buffer (image_map->undo_tiles,
+                                             gimp_drawable_get_babl_format (image_map->drawable),
+                                             FALSE);
       dest = gimp_drawable_get_write_buffer (image_map->drawable);
 
       src_rect.x      = extent->x - image_map->undo_offset_x;
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 64f54e8..5fc0168 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -1647,9 +1647,9 @@ gimp_layer_create_mask (const GimpLayer *layer,
           GeglBuffer  *dest_buffer;
 
           dest_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (mask));
-          dest_buffer = gimp_tile_manager_create_buffer_with_format (dest_tiles,
-                                                                     babl_format ("A u8"),
-                                                                     TRUE);
+          dest_buffer = gimp_tile_manager_create_buffer (dest_tiles,
+                                                         babl_format ("A u8"),
+                                                         TRUE);
 
           gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
                             dest_buffer, NULL);
@@ -1756,7 +1756,8 @@ gimp_layer_create_mask (const GimpLayer *layer,
 
             gimp_drawable_convert_tiles_grayscale (drawable, copy_tiles);
 
-            src_buffer = gimp_tile_manager_create_buffer (copy_tiles, FALSE);
+            src_buffer = gimp_tile_manager_create_buffer (copy_tiles, NULL,
+                                                          FALSE);
           }
         else
           {
@@ -2032,7 +2033,9 @@ gimp_layer_add_alpha (GimpLayer *layer)
                                 gimp_item_get_height (item),
                                 GIMP_IMAGE_TYPE_BYTES (new_type));
 
-  dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
+  dest_buffer = gimp_tile_manager_create_buffer (new_tiles,
+                                                 gimp_drawable_get_babl_format_with_alpha (GIMP_DRAWABLE (layer)),
+                                                 TRUE);
 
   gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
                     dest_buffer, NULL);
diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c
index 27ed9d1..ead45d9 100644
--- a/app/core/gimpprojection-construct.c
+++ b/app/core/gimpprojection-construct.c
@@ -264,7 +264,7 @@ gimp_projection_initialize (GimpProjection *proj,
         {
           TileManager *tiles = gimp_pickable_get_tiles (GIMP_PICKABLE (proj));
 
-          buffer = gimp_tile_manager_create_buffer (tiles, TRUE);
+          buffer = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
         }
 
       gegl_buffer_clear (buffer, &rect);
diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c
index 1f1863c..2de3323 100644
--- a/app/core/gimpprojection.c
+++ b/app/core/gimpprojection.c
@@ -355,7 +355,7 @@ gimp_projection_get_buffer (GimpPickable *pickable)
     {
       TileManager *tiles = gimp_projection_get_tiles (pickable);
 
-      proj->buffer = gimp_tile_manager_create_buffer (tiles, FALSE);
+      proj->buffer = gimp_tile_manager_create_buffer (tiles, NULL, FALSE);
     }
 
   return proj->buffer;
@@ -442,7 +442,7 @@ gimp_projection_get_sink_node (GimpProjection *proj)
   gegl_node_add_child (proj->graph, graph);
 
   tiles  = gimp_projection_get_tiles (GIMP_PICKABLE (proj));
-  buffer = gimp_tile_manager_create_buffer (tiles, TRUE);
+  buffer = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
 
   proj->sink_node =
     gegl_node_new_child (proj->graph,
@@ -485,7 +485,7 @@ gimp_projection_get_tiles_at_level (GimpProjection *proj,
           GeglBuffer  *buffer;
 
           tiles = tile_pyramid_get_tiles (proj->pyramid, 0, NULL);
-          buffer = gimp_tile_manager_create_buffer (tiles, TRUE);
+          buffer = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
 
           gegl_node_set (proj->sink_node,
                          "buffer", buffer,
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 3b2b5d7..02f667d 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -78,31 +78,6 @@ gimp_bpp_to_babl_format (guint    bpp,
   return NULL;
 }
 
-static gint
-gimp_babl_format_to_legacy_bpp (const Babl *format)
-{
-  return babl_format_get_n_components (format);
-}
-
-TileManager *
-gimp_buffer_to_tiles (GeglBuffer *buffer)
-{
-  TileManager *new_tiles;
-  GeglBuffer  *temp;
-  gint         width  = gegl_buffer_get_width (buffer);
-  gint         height = gegl_buffer_get_height (buffer);
-  const Babl  *format = gegl_buffer_get_format (buffer);
-
-  new_tiles = tile_manager_new (width, height,
-                                gimp_babl_format_to_legacy_bpp (format));
-
-  temp = gimp_tile_manager_create_buffer (new_tiles, TRUE);
-  gegl_buffer_copy (buffer, NULL, temp, NULL);
-  g_object_unref (temp);
-
-  return new_tiles;
-}
-
 const gchar *
 gimp_layer_mode_to_gegl_operation (GimpLayerModeEffects mode)
 {
@@ -159,16 +134,9 @@ gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
 
 GeglBuffer *
 gimp_tile_manager_create_buffer (TileManager *tm,
+                                 const Babl  *format,
                                  gboolean     write)
 {
-  return gimp_tile_manager_create_buffer_with_format (tm, NULL, write);
-}
-
-GeglBuffer *
-gimp_tile_manager_create_buffer_with_format (TileManager *tm,
-                                             const Babl  *format,
-                                             gboolean     write)
-{
   GeglTileBackend *backend;
   GeglBuffer      *buffer;
 
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index cb5dd99..95be309 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -25,16 +25,12 @@
 const Babl  * gimp_bpp_to_babl_format           (guint                  bpp,
                                                  gboolean               linear) G_GNUC_CONST;
 
-TileManager * gimp_buffer_to_tiles              (GeglBuffer            *buffer);
-
 const gchar * gimp_layer_mode_to_gegl_operation (GimpLayerModeEffects   mode) G_GNUC_CONST;
 const gchar * gimp_interpolation_to_gegl_filter (GimpInterpolationType  interpolation) G_GNUC_CONST;
 
-GeglBuffer  * gimp_tile_manager_create_buffer   (TileManager           *tm,
+GeglBuffer *  gimp_tile_manager_create_buffer   (TileManager           *tm,
+                                                 const Babl            *format,
                                                  gboolean               write);
-GeglBuffer *  gimp_tile_manager_create_buffer_with_format (TileManager *tm,
-                                                           const Babl  *format,
-                                                           gboolean     write);
 
 void          gimp_gegl_buffer_refetch_tiles    (GeglBuffer            *buffer);
 



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