[gimp] app: add "const Babl *new_format" to GimpDrawable::convert_type()



commit 60305c11d5d44e4c2386c799753da06b29c13b6b
Author: Michael Natterer <mitch gimp org>
Date:   Sat Oct 13 22:56:32 2012 +0200

    app: add "const Babl *new_format" to GimpDrawable::convert_type()
    
    but only to the virtual function, not the public API. Implement it in
    GimpSelection and GimpLayerMask, and pass the correct mask format down
    to the parent class which does the actual conversion.

 app/core/gimpchannel.c    |   14 ++++-------
 app/core/gimpdrawable.c   |   10 ++++++++
 app/core/gimpdrawable.h   |    1 +
 app/core/gimpgrouplayer.c |    2 +
 app/core/gimplayer.c      |   14 ++++-------
 app/core/gimplayermask.c  |   53 +++++++++++++++++++++++++++++++++++++-------
 app/core/gimpselection.c  |   31 ++++++++++++++++++++++++++
 7 files changed, 98 insertions(+), 27 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 85364d1..7d09366 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -131,6 +131,7 @@ static void       gimp_channel_to_selection  (GimpItem          *item,
 
 static void       gimp_channel_convert_type  (GimpDrawable      *drawable,
                                               GimpImage         *dest_image,
+                                              const Babl        *new_format,
                                               GimpImageBaseType  new_base_type,
                                               GimpPrecision      new_precision,
                                               gint               layer_dither_type,
@@ -798,6 +799,7 @@ gimp_channel_to_selection (GimpItem       *item,
 static void
 gimp_channel_convert_type (GimpDrawable      *drawable,
                            GimpImage         *dest_image,
+                           const Babl        *new_format,
                            GimpImageBaseType  new_base_type,
                            GimpPrecision      new_precision,
                            gint               layer_dither_type,
@@ -805,18 +807,12 @@ gimp_channel_convert_type (GimpDrawable      *drawable,
                            gboolean           push_undo)
 {
   GeglBuffer *dest_buffer;
-  const Babl *format;
-
-  format = gimp_image_get_format (dest_image,
-                                  new_base_type,
-                                  new_precision,
-                                  gimp_drawable_has_alpha (drawable));
 
   dest_buffer =
     gegl_buffer_new (GEGL_RECTANGLE (0, 0,
                                      gimp_item_get_width  (GIMP_ITEM (drawable)),
                                      gimp_item_get_height (GIMP_ITEM (drawable))),
-                     format);
+                     new_format);
 
   if (mask_dither_type == 0)
     {
@@ -828,8 +824,8 @@ gimp_channel_convert_type (GimpDrawable      *drawable,
       GeglNode *dither;
       gint      bits;
 
-      bits = (babl_format_get_bytes_per_pixel (format) * 8 /
-              babl_format_get_n_components (format));
+      bits = (babl_format_get_bytes_per_pixel (new_format) * 8 /
+              babl_format_get_n_components (new_format));
 
       dither = gegl_node_new_child (NULL,
                                     "operation",       "gegl:color-reduction",
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 5423fbf..6810858 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -130,6 +130,7 @@ static gint64  gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable
 
 static void       gimp_drawable_real_convert_type  (GimpDrawable      *drawable,
                                                     GimpImage         *dest_image,
+                                                    const Babl        *new_format,
                                                     GimpImageBaseType  new_base_type,
                                                     GimpPrecision      new_precision,
                                                     gint               layer_dither_type,
@@ -679,6 +680,7 @@ gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable,
 static void
 gimp_drawable_real_convert_type (GimpDrawable      *drawable,
                                  GimpImage         *dest_image,
+                                 const Babl        *new_format,
                                  GimpImageBaseType  new_base_type,
                                  GimpPrecision      new_precision,
                                  gint               layer_dither_type,
@@ -1149,6 +1151,8 @@ gimp_drawable_convert_type (GimpDrawable      *drawable,
                             gint               mask_dither_type,
                             gboolean           push_undo)
 {
+  const Babl *new_format;
+
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (GIMP_IS_IMAGE (dest_image));
   g_return_if_fail (new_base_type != gimp_drawable_get_base_type (drawable) ||
@@ -1157,7 +1161,13 @@ gimp_drawable_convert_type (GimpDrawable      *drawable,
   if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
     push_undo = FALSE;
 
+  new_format = gimp_image_get_format (dest_image,
+                                      new_base_type,
+                                      new_precision,
+                                      gimp_drawable_has_alpha (drawable));
+
   GIMP_DRAWABLE_GET_CLASS (drawable)->convert_type (drawable, dest_image,
+                                                    new_format,
                                                     new_base_type,
                                                     new_precision,
                                                     layer_dither_type,
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index eb2236a..06485cb 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -62,6 +62,7 @@ struct _GimpDrawableClass
   GimpComponentMask (* get_active_mask)   (const GimpDrawable   *drawable);
   void          (* convert_type)          (GimpDrawable         *drawable,
                                            GimpImage            *dest_image,
+                                           const Babl           *new_format,
                                            GimpImageBaseType     new_base_type,
                                            GimpPrecision         new_precision,
                                            gint                  layer_dither_type,
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index 70b0600..f9f25e7 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -133,6 +133,7 @@ static gint64      gimp_group_layer_estimate_memsize (const GimpDrawable *drawab
                                                       gint             height);
 static void            gimp_group_layer_convert_type (GimpDrawable      *drawable,
                                                       GimpImage         *dest_image,
+                                                      const Babl        *new_format,
                                                       GimpImageBaseType  new_base_type,
                                                       GimpPrecision      new_precision,
                                                       gint               layer_dither_type,
@@ -847,6 +848,7 @@ get_projection_format (GimpProjectable   *projectable,
 static void
 gimp_group_layer_convert_type (GimpDrawable      *drawable,
                                GimpImage         *dest_image,
+                               const Babl        *new_format /* unused */,
                                GimpImageBaseType  new_base_type,
                                GimpPrecision      new_precision,
                                gint               layer_dither_type,
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 652a1cb..e97793c 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -157,6 +157,7 @@ static gint64  gimp_layer_estimate_memsize      (const GimpDrawable *drawable,
                                                  gint                height);
 static void    gimp_layer_convert_type          (GimpDrawable       *drawable,
                                                  GimpImage          *dest_image,
+                                                 const Babl         *new_format,
                                                  GimpImageBaseType   new_base_type,
                                                  GimpPrecision       new_precision,
                                                  gint                layer_dither_type,
@@ -951,6 +952,7 @@ gimp_layer_estimate_memsize (const GimpDrawable *drawable,
 static void
 gimp_layer_convert_type (GimpDrawable      *drawable,
                          GimpImage         *dest_image,
+                         const Babl        *new_format,
                          GimpImageBaseType  new_base_type,
                          GimpPrecision      new_precision,
                          gint               layer_dither_type,
@@ -959,18 +961,12 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
 {
   GimpLayer  *layer = GIMP_LAYER (drawable);
   GeglBuffer *dest_buffer;
-  const Babl *format;
-
-  format = gimp_image_get_format (dest_image,
-                                  new_base_type,
-                                  new_precision,
-                                  gimp_drawable_has_alpha (drawable));
 
   dest_buffer =
     gegl_buffer_new (GEGL_RECTANGLE (0, 0,
                                      gimp_item_get_width  (GIMP_ITEM (drawable)),
                                      gimp_item_get_height (GIMP_ITEM (drawable))),
-                     format);
+                     new_format);
 
   if (layer_dither_type == 0)
     {
@@ -982,8 +978,8 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
       GeglNode *dither;
       gint      bits;
 
-      bits = (babl_format_get_bytes_per_pixel (format) * 8 /
-              babl_format_get_n_components (format));
+      bits = (babl_format_get_bytes_per_pixel (new_format) * 8 /
+              babl_format_get_n_components (new_format));
 
       dither = gegl_node_new_child (NULL,
                                     "operation",       "gegl:color-reduction",
diff --git a/app/core/gimplayermask.c b/app/core/gimplayermask.c
index d604196..4ebf07f 100644
--- a/app/core/gimplayermask.c
+++ b/app/core/gimplayermask.c
@@ -26,6 +26,8 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-babl.h"
+
 #include "gimperror.h"
 #include "gimpimage.h"
 #include "gimpimage-undo-push.h"
@@ -35,15 +37,24 @@
 #include "gimp-intl.h"
 
 
-static gboolean        gimp_layer_mask_is_attached       (const GimpItem *item);
-static gboolean        gimp_layer_mask_is_content_locked (const GimpItem *item);
-static GimpItemTree  * gimp_layer_mask_get_tree          (GimpItem       *item);
-static GimpItem      * gimp_layer_mask_duplicate         (GimpItem       *item,
-                                                          GType           new_type);
-static gboolean        gimp_layer_mask_rename            (GimpItem       *item,
-                                                          const gchar    *new_name,
-                                                          const gchar    *undo_desc,
-                                                          GError        **error);
+static gboolean        gimp_layer_mask_is_attached       (const GimpItem    *item);
+static gboolean        gimp_layer_mask_is_content_locked (const GimpItem    *item);
+static GimpItemTree  * gimp_layer_mask_get_tree          (GimpItem          *item);
+static GimpItem      * gimp_layer_mask_duplicate         (GimpItem          *item,
+                                                          GType              new_type);
+static gboolean        gimp_layer_mask_rename            (GimpItem          *item,
+                                                          const gchar       *new_name,
+                                                          const gchar       *undo_desc,
+                                                          GError           **error);
+
+static void            gimp_layer_mask_convert_type      (GimpDrawable      *drawable,
+                                                          GimpImage         *dest_image,
+                                                          const Babl        *new_format,
+                                                          GimpImageBaseType  new_base_type,
+                                                          GimpPrecision      new_precision,
+                                                          gint               layer_dither_type,
+                                                          gint               mask_dither_type,
+                                                          gboolean           push_undo);
 
 
 G_DEFINE_TYPE (GimpLayerMask, gimp_layer_mask, GIMP_TYPE_CHANNEL)
@@ -56,6 +67,7 @@ gimp_layer_mask_class_init (GimpLayerMaskClass *klass)
 {
   GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
   GimpItemClass     *item_class     = GIMP_ITEM_CLASS (klass);
+  GimpDrawableClass *drawable_class = GIMP_DRAWABLE_CLASS (klass);
 
   viewable_class->default_stock_id = "gimp-layer-mask";
 
@@ -66,6 +78,8 @@ gimp_layer_mask_class_init (GimpLayerMaskClass *klass)
   item_class->rename            = gimp_layer_mask_rename;
   item_class->translate_desc    = C_("undo-type", "Move Layer Mask");
   item_class->to_selection_desc = C_("undo-type", "Layer Mask to Selection");
+
+  drawable_class->convert_type  = gimp_layer_mask_convert_type;
 }
 
 static void
@@ -131,6 +145,27 @@ gimp_layer_mask_rename (GimpItem     *item,
   return FALSE;
 }
 
+static void
+gimp_layer_mask_convert_type (GimpDrawable      *drawable,
+                              GimpImage         *dest_image,
+                              const Babl        *new_format,
+                              GimpImageBaseType  new_base_type,
+                              GimpPrecision      new_precision,
+                              gint               layer_dither_type,
+                              gint               mask_dither_type,
+                              gboolean           push_undo)
+{
+  new_format = gimp_babl_mask_format (new_precision);
+
+  GIMP_DRAWABLE_CLASS (parent_class)->convert_type (drawable, dest_image,
+                                                    new_format,
+                                                    new_base_type,
+                                                    new_precision,
+                                                    layer_dither_type,
+                                                    mask_dither_type,
+                                                    push_undo);
+}
+
 GimpLayerMask *
 gimp_layer_mask_new (GimpImage     *image,
                      gint           width,
diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c
index ec981d7..2555c72 100644
--- a/app/core/gimpselection.c
+++ b/app/core/gimpselection.c
@@ -23,6 +23,7 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-babl.h"
 #include "gegl/gimp-gegl-nodes.h"
 #include "gegl/gimp-gegl-utils.h"
 
@@ -80,6 +81,14 @@ static gboolean   gimp_selection_stroke        (GimpItem            *item,
                                                 gboolean             push_undo,
                                                 GimpProgress        *progress,
                                                 GError             **error);
+static void       gimp_selection_convert_type  (GimpDrawable        *drawable,
+                                                GimpImage           *dest_image,
+                                                const Babl          *new_format,
+                                                GimpImageBaseType    new_base_type,
+                                                GimpPrecision        new_precision,
+                                                gint                 layer_dither_type,
+                                                gint                 mask_dither_type,
+                                                gboolean             push_undo);
 static void gimp_selection_invalidate_boundary (GimpDrawable        *drawable);
 
 static gboolean   gimp_selection_boundary      (GimpChannel         *channel,
@@ -154,6 +163,7 @@ gimp_selection_class_init (GimpSelectionClass *klass)
   item_class->translate_desc          = C_("undo-type", "Move Selection");
   item_class->stroke_desc             = C_("undo-type", "Stroke Selection");
 
+  drawable_class->convert_type        = gimp_selection_convert_type;
   drawable_class->invalidate_boundary = gimp_selection_invalidate_boundary;
 
   channel_class->boundary             = gimp_selection_boundary;
@@ -298,6 +308,27 @@ gimp_selection_stroke (GimpItem           *item,
 }
 
 static void
+gimp_selection_convert_type (GimpDrawable      *drawable,
+                             GimpImage         *dest_image,
+                             const Babl        *new_format,
+                             GimpImageBaseType  new_base_type,
+                             GimpPrecision      new_precision,
+                             gint               layer_dither_type,
+                             gint               mask_dither_type,
+                             gboolean           push_undo)
+{
+  new_format = gimp_babl_mask_format (new_precision);
+
+  GIMP_DRAWABLE_CLASS (parent_class)->convert_type (drawable, dest_image,
+                                                    new_format,
+                                                    new_base_type,
+                                                    new_precision,
+                                                    layer_dither_type,
+                                                    mask_dither_type,
+                                                    push_undo);
+}
+
+static void
 gimp_selection_invalidate_boundary (GimpDrawable *drawable)
 {
   GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));



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