[gimp/goat-invasion] app: use gimp_image_get_layer_format() instead of dealing with image_type



commit 48b623a6087dae831b5fffebaf1b1a442d61ac58
Author: Michael Natterer <mitch gimp org>
Date:   Sat Apr 7 00:46:59 2012 +0200

    app: use gimp_image_get_layer_format() instead of dealing with image_type

 app/actions/debug-commands.c       |    4 ++--
 app/actions/edit-commands.c        |    6 +++---
 app/actions/layers-commands.c      |   23 +++++++----------------
 app/core/gimp-edit.c               |   12 ++----------
 app/core/gimpgrouplayer.c          |    7 +++----
 app/core/gimpimage-convert.c       |   16 ++++------------
 app/core/gimpimage-merge.c         |    9 +++------
 app/display/gimpdisplayshell-dnd.c |    8 +++-----
 app/pdb/layer-cmds.c               |    8 +++-----
 app/tests/gimp-app-test-utils.c    |    2 +-
 app/tests/test-ui.c                |    2 +-
 app/text/gimptextlayer.c           |   14 ++++++--------
 app/widgets/gimplayertreeview.c    |   12 +++---------
 tools/pdbgen/pdb/layer.pdb         |    8 +++-----
 14 files changed, 44 insertions(+), 87 deletions(-)
---
diff --git a/app/actions/debug-commands.c b/app/actions/debug-commands.c
index 85f9381..00ee000 100644
--- a/app/actions/debug-commands.c
+++ b/app/actions/debug-commands.c
@@ -358,8 +358,8 @@ debug_show_image_graph (GimpImage *source_image)
   gimp_image_set_uri (new_image, new_name);
   layer = gimp_layer_new_from_buffer (buffer,
                                       new_image,
-                                      gimp_image_get_format (new_image,
-                                                             GIMP_RGBA_IMAGE),
+                                      gimp_image_get_layer_format (new_image,
+                                                                   TRUE),
                                       new_name,
                                       1.0,
                                       GIMP_NORMAL_MODE);
diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c
index a13f7ee..04df3ee 100644
--- a/app/actions/edit-commands.c
+++ b/app/actions/edit-commands.c
@@ -340,12 +340,12 @@ edit_paste_as_new_layer_cmd_callback (GtkAction *action,
 
   if (buffer)
     {
-      GimpLayer     *layer;
-      GimpImageType  type = gimp_image_base_type_with_alpha (image);
+      GimpLayer *layer;
 
       layer = gimp_layer_new_from_buffer (gimp_buffer_get_buffer (buffer),
                                           image,
-                                          gimp_image_get_format (image, type),
+                                          gimp_image_get_layer_format (image,
+                                                                       TRUE),
                                           _("Clipboard"),
                                           GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
       g_object_unref (buffer);
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index d0ddeb5..3b59012 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -272,7 +272,6 @@ layers_new_last_vals_cmd_callback (GtkAction *action,
   GimpLayer            *new_layer;
   gint                  width, height;
   gint                  off_x, off_y;
-  GimpImageType         type;
   gdouble               opacity;
   GimpLayerModeEffects  mode;
   return_if_no_image (image, data);
@@ -320,10 +319,8 @@ layers_new_last_vals_cmd_callback (GtkAction *action,
   gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
                                _("New Layer"));
 
-  type = gimp_image_base_type_with_alpha (image);
-
   new_layer = gimp_layer_new (image, width, height,
-                              gimp_image_get_format (image, type),
+                              gimp_image_get_layer_format (image, TRUE),
                               layer_name,
                               opacity, mode);
 
@@ -344,21 +341,18 @@ void
 layers_new_from_visible_cmd_callback (GtkAction *action,
                                       gpointer   data)
 {
-  GimpImage     *image;
-  GimpLayer     *layer;
-  GimpPickable  *pickable;
-  GimpImageType  type;
+  GimpImage    *image;
+  GimpLayer    *layer;
+  GimpPickable *pickable;
   return_if_no_image (image, data);
 
   pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
 
   gimp_pickable_flush (pickable);
 
-  type = gimp_image_base_type_with_alpha (image);
-
   layer = gimp_layer_new_from_buffer (gimp_pickable_get_buffer (pickable),
                                       image,
-                                      gimp_image_get_format (image, type),
+                                      gimp_image_get_layer_format (image, TRUE),
                                       _("Visible"),
                                       GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
@@ -979,8 +973,7 @@ layers_new_layer_response (GtkWidget          *widget,
 {
   if (response_id == GTK_RESPONSE_OK)
     {
-      GimpLayer     *layer;
-      GimpImageType  type;
+      GimpLayer *layer;
 
       if (layer_name)
         g_free (layer_name);
@@ -997,12 +990,10 @@ layers_new_layer_response (GtkWidget          *widget,
         RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (dialog->size_se),
                                           1));
 
-      type = gimp_image_base_type_with_alpha (dialog->image);
-
       layer = gimp_layer_new (dialog->image,
                               dialog->xsize,
                               dialog->ysize,
-                              gimp_image_get_format (dialog->image, type),
+                              gimp_image_get_layer_format (dialog->image, TRUE),
                               layer_name,
                               GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c
index 1e571c7..3524740 100644
--- a/app/core/gimp-edit.c
+++ b/app/core/gimp-edit.c
@@ -174,17 +174,9 @@ gimp_edit_paste (GimpImage    *image,
    */
 
   if (drawable)
-    {
-      format = gimp_drawable_get_format_with_alpha (drawable);
-    }
+    format = gimp_drawable_get_format_with_alpha (drawable);
   else
-    {
-      GimpImageType  type;
-
-      type = gimp_image_base_type_with_alpha (image);
-
-      format = gimp_image_get_format (image, type);
-    }
+    format = gimp_image_get_layer_format (image, TRUE);
 
   layer = gimp_layer_new_from_buffer (gimp_buffer_get_buffer (paste),
                                       image,
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index b6f44e8..ae700dc 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -956,17 +956,16 @@ GimpLayer *
 gimp_group_layer_new (GimpImage *image)
 {
   GimpGroupLayer *group;
-  GimpImageType   type;
+  const Babl     *format;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
-  type = gimp_image_base_type_with_alpha (image);
+  format = gimp_image_get_layer_format (image, TRUE);
 
   group = GIMP_GROUP_LAYER (gimp_drawable_new (GIMP_TYPE_GROUP_LAYER,
                                                image, NULL,
                                                0, 0, 1, 1,
-                                               gimp_image_get_format (image,
-                                                                      type)));
+                                               format));
 
   if (gimp_image_get_projection (image)->use_gegl)
     GET_PRIVATE (group)->projection->use_gegl = TRUE;
diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c
index 5c59733..3687089 100644
--- a/app/core/gimpimage-convert.c
+++ b/app/core/gimpimage-convert.c
@@ -997,24 +997,16 @@ gimp_image_convert (GimpImage               *image,
         case GIMP_INDEXED:
           {
             GeglBuffer *new_buffer;
-            const Babl *new_format;
+            gboolean    has_alpha;
 
-            if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
-              new_format = gimp_image_get_format (image, GIMP_INDEXEDA_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));
+            has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
 
             new_buffer =
               gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0,
                                                     gimp_item_get_width  (GIMP_ITEM (layer)),
                                                     gimp_item_get_height (GIMP_ITEM (layer))),
-                                    new_format);
+                                    gimp_image_get_layer_format (image,
+                                                                 has_alpha));
 
             quantobj->nth_layer = nth_layer;
             quantobj->second_pass (quantobj, layer, new_buffer);
diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c
index 9fe0ccc..3267a09 100644
--- a/app/core/gimpimage-merge.c
+++ b/app/core/gimpimage-merge.c
@@ -520,14 +520,11 @@ gimp_image_merge_layers (GimpImage     *image,
   if (merge_type == GIMP_FLATTEN_IMAGE ||
       gimp_drawable_type (GIMP_DRAWABLE (layer)) == GIMP_INDEXED_IMAGE)
     {
-      GeglColor     *color;
-      GimpImageType  type;
-      GimpRGB        bg;
-
-      type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (image));
+      GeglColor *color;
+      GimpRGB    bg;
 
       merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1),
-                                    gimp_image_get_format (image, type),
+                                    gimp_image_get_layer_format (image, FALSE),
                                     gimp_object_get_name (layer),
                                     GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
       if (! merge_layer)
diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c
index 6187b39..259553e 100644
--- a/app/display/gimpdisplayshell-dnd.c
+++ b/app/display/gimpdisplayshell-dnd.c
@@ -651,7 +651,7 @@ gimp_display_shell_drop_pixbuf (GtkWidget *widget,
   GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
   GimpImage        *image = gimp_display_get_image (shell->display);
   GimpLayer        *new_layer;
-  GimpImageType     image_type;
+  gboolean          has_alpha = FALSE;
 
   GIMP_LOG (DND, NULL);
 
@@ -668,17 +668,15 @@ gimp_display_shell_drop_pixbuf (GtkWidget *widget,
       return;
     }
 
-  image_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (image));
-
   if (gdk_pixbuf_get_n_channels (pixbuf) == 2 ||
       gdk_pixbuf_get_n_channels (pixbuf) == 4)
     {
-      image_type = GIMP_IMAGE_TYPE_WITH_ALPHA (image_type);
+      has_alpha = TRUE;
     }
 
   new_layer =
     gimp_layer_new_from_pixbuf (pixbuf, image,
-                                gimp_image_get_format (image, image_type),
+                                gimp_image_get_layer_format (image, has_alpha),
                                 _("Dropped Buffer"),
                                 GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
diff --git a/app/pdb/layer-cmds.c b/app/pdb/layer-cmds.c
index 596676a..bf98ce6 100644
--- a/app/pdb/layer-cmds.c
+++ b/app/pdb/layer-cmds.c
@@ -113,16 +113,14 @@ layer_new_from_visible_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      GimpPickable  *pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
-      GimpImageType  type;
+      GimpPickable *pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
 
       gimp_pickable_flush (pickable);
 
-      type = gimp_image_base_type_with_alpha (dest_image);
-
       layer = gimp_layer_new_from_buffer (gimp_pickable_get_buffer (pickable),
                                           dest_image,
-                                          gimp_image_get_format (dest_image, type),
+                                          gimp_image_get_layer_format (dest_image,
+                                                                       TRUE),
                                           name,
                                           GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
     }
diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c
index 4b123b3..a98d675 100644
--- a/app/tests/gimp-app-test-utils.c
+++ b/app/tests/gimp-app-test-utils.c
@@ -126,7 +126,7 @@ gimp_test_utils_create_image (Gimp *gimp,
   layer = gimp_layer_new (image,
                           width,
                           height,
-                          gimp_image_get_format (image, GIMP_RGBA_IMAGE),
+                          gimp_image_get_layer_format (image, TRUE),
                           "layer1",
                           1.0,
                           GIMP_NORMAL_MODE);
diff --git a/app/tests/test-ui.c b/app/tests/test-ui.c
index df604b6..e6971ce 100644
--- a/app/tests/test-ui.c
+++ b/app/tests/test-ui.c
@@ -229,7 +229,7 @@ create_new_image_via_dialog (gconstpointer data)
   layer = gimp_layer_new (image,
                           gimp_image_get_width (image),
                           gimp_image_get_height (image),
-                          gimp_image_base_type_with_alpha (image),
+                          gimp_image_get_layer_format (image, TRUE),
                           "Layer for testing",
                           GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 756eeff..c0aff8d 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -376,7 +376,6 @@ gimp_text_layer_new (GimpImage *image,
                      GimpText  *text)
 {
   GimpTextLayer *layer;
-  GimpImageType  type;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
   g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
@@ -384,13 +383,12 @@ gimp_text_layer_new (GimpImage *image,
   if (! text->text && ! text->markup)
     return NULL;
 
-  type = gimp_image_base_type_with_alpha (image);
-
-  layer = GIMP_TEXT_LAYER (gimp_drawable_new (GIMP_TYPE_TEXT_LAYER,
-                                              image, NULL,
-                                              0, 0, 1, 1,
-                                              gimp_image_get_format (image,
-                                                                     type)));
+  layer =
+    GIMP_TEXT_LAYER (gimp_drawable_new (GIMP_TYPE_TEXT_LAYER,
+                                        image, NULL,
+                                        0, 0, 1, 1,
+                                        gimp_image_get_layer_format (image,
+                                                                     TRUE)));
 
   gimp_text_layer_set_text (layer, text);
 
diff --git a/app/widgets/gimplayertreeview.c b/app/widgets/gimplayertreeview.c
index 1e7f158..6946a32 100644
--- a/app/widgets/gimplayertreeview.c
+++ b/app/widgets/gimplayertreeview.c
@@ -790,18 +790,15 @@ gimp_layer_tree_view_drop_pixbuf (GimpContainerTreeView   *tree_view,
   GimpImage        *image     = gimp_item_tree_view_get_image (item_view);
   GimpLayer        *new_layer;
   GimpLayer        *parent;
-  GimpImageType     type;
   gint              index;
 
-  type = gimp_image_base_type_with_alpha (image);
-
   index = gimp_item_tree_view_get_drop_index (item_view, dest_viewable,
                                               drop_pos,
                                               (GimpViewable **) &parent);
 
   new_layer =
     gimp_layer_new_from_pixbuf (pixbuf, image,
-                                gimp_image_get_format (image, type),
+                                gimp_image_get_layer_format (image, TRUE),
                                 _("Dropped Buffer"),
                                 GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
@@ -834,18 +831,15 @@ gimp_layer_tree_view_set_image (GimpItemTreeView *view,
 static GimpItem *
 gimp_layer_tree_view_item_new (GimpImage *image)
 {
-  GimpLayer     *new_layer;
-  GimpImageType  type;
+  GimpLayer *new_layer;
 
   gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
                                _("New Layer"));
 
-  type = gimp_image_base_type_with_alpha (image);
-
   new_layer = gimp_layer_new (image,
                               gimp_image_get_width (image),
                               gimp_image_get_height (image),
-                              gimp_image_get_format (image, type),
+                              gimp_image_get_layer_format (image, TRUE),
                               NULL, 1.0, GIMP_NORMAL_MODE);
 
   gimp_image_add_layer (image, new_layer,
diff --git a/tools/pdbgen/pdb/layer.pdb b/tools/pdbgen/pdb/layer.pdb
index 9cac746..8aef442 100644
--- a/tools/pdbgen/pdb/layer.pdb
+++ b/tools/pdbgen/pdb/layer.pdb
@@ -96,16 +96,14 @@ HELP
     %invoke = (
 	code => <<'CODE'
 {
-  GimpPickable  *pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
-  GimpImageType  type;
+  GimpPickable *pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
 
   gimp_pickable_flush (pickable);
 
-  type = gimp_image_base_type_with_alpha (dest_image);
-
   layer = gimp_layer_new_from_buffer (gimp_pickable_get_buffer (pickable),
                                       dest_image,
-                                      gimp_image_get_format (dest_image, type),
+                                      gimp_image_get_layer_format (dest_image,
+                                                                   TRUE),
                                       name,
                                       GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 }



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