[gimp] Bug 778523 - Optionally add alpha to layers of imported images



commit b3f802a0b750852397a545e56413a3a4a4edd3f5
Author: Michael Natterer <mitch gimp org>
Date:   Fri Feb 17 22:07:43 2017 +0100

    Bug 778523 - Optionally add alpha to layers of imported images
    
    Add "Add alpha to all layers of imported images" to prefs -> import
    and honor the setting in file_import_image().

 app/config/gimpcoreconfig.c      |   14 ++++++++++
 app/config/gimpcoreconfig.h      |    1 +
 app/config/gimprc-blurbs.h       |    3 ++
 app/dialogs/preferences-dialog.c |    4 +++
 app/file/file-import.c           |   53 ++++++++++++++++++++++++++++----------
 5 files changed, 61 insertions(+), 14 deletions(-)
---
diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c
index bcc5bc1..86f1def 100644
--- a/app/config/gimpcoreconfig.c
+++ b/app/config/gimpcoreconfig.c
@@ -108,6 +108,7 @@ enum
   PROP_QUICK_MASK_COLOR,
   PROP_IMPORT_PROMOTE_FLOAT,
   PROP_IMPORT_PROMOTE_DITHER,
+  PROP_IMPORT_ADD_ALPHA,
 
   /* ignored, only for backward compatibility: */
   PROP_INSTALL_COLORMAP,
@@ -634,6 +635,13 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
                             TRUE,
                             GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_IMPORT_ADD_ALPHA,
+                            "import-add-alpha",
+                            "Import add alpha",
+                            IMPORT_ADD_ALPHA_BLURB,
+                            FALSE,
+                            GIMP_PARAM_STATIC_STRINGS);
+
   /*  only for backward compatibility:  */
   GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_INSTALL_COLORMAP,
                             "install-colormap",
@@ -924,6 +932,9 @@ gimp_core_config_set_property (GObject      *object,
     case PROP_IMPORT_PROMOTE_DITHER:
       core_config->import_promote_dither = g_value_get_boolean (value);
       break;
+    case PROP_IMPORT_ADD_ALPHA:
+      core_config->import_add_alpha = g_value_get_boolean (value);
+      break;
 
     case PROP_INSTALL_COLORMAP:
     case PROP_MIN_COLORS:
@@ -1105,6 +1116,9 @@ gimp_core_config_get_property (GObject    *object,
     case PROP_IMPORT_PROMOTE_DITHER:
       g_value_set_boolean (value, core_config->import_promote_dither);
       break;
+    case PROP_IMPORT_ADD_ALPHA:
+      g_value_set_boolean (value, core_config->import_add_alpha);
+      break;
 
     case PROP_INSTALL_COLORMAP:
     case PROP_MIN_COLORS:
diff --git a/app/config/gimpcoreconfig.h b/app/config/gimpcoreconfig.h
index 3ccbf12..870edad 100644
--- a/app/config/gimpcoreconfig.h
+++ b/app/config/gimpcoreconfig.h
@@ -93,6 +93,7 @@ struct _GimpCoreConfig
   GimpRGB                 quick_mask_color;
   gboolean                import_promote_float;
   gboolean                import_promote_dither;
+  gboolean                import_add_alpha;
 };
 
 struct _GimpCoreConfigClass
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 0c2788f..5a3975f 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -189,6 +189,9 @@ _("Promote imported images to floating point precision. Does not apply " \
 _("When promoting imported images to floating point precision, also add " \
   "minimal noise in order do distribute color values a bit.")
 
+#define IMPORT_ADD_ALPHA_BLURB \
+_("Add an alpha channel to all layers of imported images.")
+
 #define INITIAL_ZOOM_TO_FIT_BLURB \
 _("When enabled, this will ensure that the full image is visible after a " \
   "file is opened, otherwise it will be displayed with a scale of 1:1.")
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 00feb97..4ccffdb 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1300,6 +1300,10 @@ prefs_dialog_new (Gimp       *gimp,
                                      "floating point"),
                                    GTK_BOX (vbox2));
 
+  button = prefs_check_button_add (object, "import-add-alpha",
+                                   _("Add an alpha channel to imported images"),
+                                   GTK_BOX (vbox2));
+
 
   /****************/
   /*  Playground  */
diff --git a/app/file/file-import.c b/app/file/file-import.c
index f79b8af..f15c7ef 100644
--- a/app/file/file-import.c
+++ b/app/file/file-import.c
@@ -31,11 +31,16 @@
 #include "core/gimpimage.h"
 #include "core/gimpimage-color-profile.h"
 #include "core/gimpimage-convert-precision.h"
+#include "core/gimplayer.h"
 #include "core/gimpprogress.h"
 
+#include "text/gimptextlayer.h"
+
 #include "file-import.h"
 
 
+/*  public functions  */
+
 void
 file_import_image (GimpImage    *image,
                    GimpContext  *context,
@@ -52,25 +57,45 @@ file_import_image (GimpImage    *image,
 
   config = image->gimp->config;
 
-  if (interactive                  &&
-      config->import_promote_float &&
-      gimp_image_get_base_type (image) != GIMP_INDEXED)
+  if (interactive && gimp_image_get_base_type (image) != GIMP_INDEXED)
     {
-      GimpPrecision old_precision = gimp_image_get_precision (image);
+      if (config->import_promote_float)
+        {
+          GimpPrecision old_precision = gimp_image_get_precision (image);
 
-      if (old_precision != GIMP_PRECISION_FLOAT_LINEAR)
+          if (old_precision != GIMP_PRECISION_FLOAT_LINEAR)
+            {
+              gimp_image_convert_precision (image,
+                                            GIMP_PRECISION_FLOAT_LINEAR,
+                                            GEGL_DITHER_NONE,
+                                            GEGL_DITHER_NONE,
+                                            GEGL_DITHER_NONE,
+                                            progress);
+
+              if (config->import_promote_dither &&
+                  old_precision == GIMP_PRECISION_U8_GAMMA)
+                {
+                  gimp_image_convert_dither_u8 (image, progress);
+                }
+            }
+        }
+
+      if (config->import_add_alpha)
         {
-          gimp_image_convert_precision (image, GIMP_PRECISION_FLOAT_LINEAR,
-                                        GEGL_DITHER_NONE,
-                                        GEGL_DITHER_NONE,
-                                        GEGL_DITHER_NONE,
-                                        progress);
-
-          if (config->import_promote_dither &&
-              old_precision == GIMP_PRECISION_U8_GAMMA)
+          GList *layers = gimp_image_get_layer_list (image);
+          GList *list;
+
+          for (list = layers; list; list = g_list_next (list))
             {
-              gimp_image_convert_dither_u8 (image, progress);
+              if (! gimp_viewable_get_children (list->data) &&
+                  ! gimp_item_is_text_layer (list->data)    &&
+                  ! gimp_drawable_has_alpha (list->data))
+                {
+                  gimp_layer_add_alpha (list->data);
+                }
             }
+
+          g_list_free (layers);
         }
     }
 


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