[gimp] Bug 734657 - Import as 32-bit floating-point linear by default



commit 27519fc7987bfbc9dacc8a83a6d76af0dc997e46
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jan 22 22:03:55 2017 +0100

    Bug 734657 - Import as 32-bit floating-point linear by default
    
    Optionally convert all imported (not XCFs) images to 32 bit linear
    floating point, and optionally add a little noise in order to
    distribute the colors minimally. The new options are on a new "Image
    Import & Export" prefs page that needs a new icon. Original dithering
    patch by pippin.

 app/config/gimpcoreconfig.c            |   30 ++++++++++++++++-
 app/config/gimpcoreconfig.h            |    2 +
 app/config/gimprc-blurbs.h             |    8 ++++
 app/core/gimpimage-convert-precision.c |   58 ++++++++++++++++++++++++++++++++
 app/core/gimpimage-convert-precision.h |    3 ++
 app/dialogs/preferences-dialog.c       |   24 +++++++++++++
 app/file/file-open.c                   |   23 ++++++++++++
 7 files changed, 147 insertions(+), 1 deletions(-)
---
diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c
index 5178978..b1a8310 100644
--- a/app/config/gimpcoreconfig.c
+++ b/app/config/gimpcoreconfig.c
@@ -106,6 +106,8 @@ enum
   PROP_COLOR_MANAGEMENT,
   PROP_SAVE_DOCUMENT_HISTORY,
   PROP_QUICK_MASK_COLOR,
+  PROP_IMPORT_PROMOTE_FLOAT,
+  PROP_IMPORT_PROMOTE_DITHER,
 
   /* ignored, only for backward compatibility: */
   PROP_INSTALL_COLORMAP,
@@ -591,7 +593,7 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
 
   GIMP_CONFIG_PROP_MEMSIZE (object_class, PROP_THUMBNAIL_FILESIZE_LIMIT,
                             "thumbnail-filesize-limit",
-                            "Thumbnail file size limie",
+                            "Thumbnail file size limit",
                             THUMBNAIL_FILESIZE_LIMIT_BLURB,
                             0, GIMP_MAX_MEMSIZE, 1 << 22,
                             GIMP_PARAM_STATIC_STRINGS);
@@ -611,6 +613,20 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
                             TRUE,
                             GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_IMPORT_PROMOTE_FLOAT,
+                            "import-promote-float",
+                            "Import promote float",
+                            IMPORT_PROMOTE_FLOAT_BLURB,
+                            FALSE,
+                            GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_IMPORT_PROMOTE_DITHER,
+                            "import-promote-dither",
+                            "Import promote dither",
+                            IMPORT_PROMOTE_DITHER_BLURB,
+                            TRUE,
+                            GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_RGB (object_class, PROP_QUICK_MASK_COLOR,
                         "quick-mask-color",
                         "Quick mask color",
@@ -902,6 +918,12 @@ gimp_core_config_set_property (GObject      *object,
     case PROP_QUICK_MASK_COLOR:
       gimp_value_get_rgb (value, &core_config->quick_mask_color);
       break;
+    case PROP_IMPORT_PROMOTE_FLOAT:
+      core_config->import_promote_float = g_value_get_boolean (value);
+      break;
+    case PROP_IMPORT_PROMOTE_DITHER:
+      core_config->import_promote_dither = g_value_get_boolean (value);
+      break;
 
     case PROP_INSTALL_COLORMAP:
     case PROP_MIN_COLORS:
@@ -1077,6 +1099,12 @@ gimp_core_config_get_property (GObject    *object,
     case PROP_QUICK_MASK_COLOR:
       gimp_value_set_rgb (value, &core_config->quick_mask_color);
       break;
+    case PROP_IMPORT_PROMOTE_FLOAT:
+      g_value_set_boolean (value, core_config->import_promote_float);
+      break;
+    case PROP_IMPORT_PROMOTE_DITHER:
+      g_value_set_boolean (value, core_config->import_promote_dither);
+      break;
 
     case PROP_INSTALL_COLORMAP:
     case PROP_MIN_COLORS:
diff --git a/app/config/gimpcoreconfig.h b/app/config/gimpcoreconfig.h
index 7f9a664..d63ada2 100644
--- a/app/config/gimpcoreconfig.h
+++ b/app/config/gimpcoreconfig.h
@@ -90,6 +90,8 @@ struct _GimpCoreConfig
   GimpColorConfig        *color_management;
   gboolean                save_document_history;
   GimpRGB                 quick_mask_color;
+  gboolean                import_promote_float;
+  gboolean                import_promote_dither;
 };
 
 struct _GimpCoreConfigClass
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index f2ea019..036b4a5 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -181,6 +181,14 @@ _("Sets the text to appear in image window status bars.")
 #define IMAGE_TITLE_FORMAT_BLURB \
 _("Sets the text to appear in image window titles.")
 
+#define IMPORT_PROMOTE_FLOAT_BLURB \
+_("Promote imported images to floating point precision. Does not apply " \
+  "to indexed images.")
+
+#define IMPORT_PROMOTE_DITHER_BLURB \
+_("When promoting imported images to floating point precision, also add " \
+  "minimal noise in order do distribute color values a bit.")
+
 #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/core/gimpimage-convert-precision.c b/app/core/gimpimage-convert-precision.c
index 5f6a2ad..0b41f74 100644
--- a/app/core/gimpimage-convert-precision.c
+++ b/app/core/gimpimage-convert-precision.c
@@ -31,6 +31,7 @@
 #include "gegl/gimp-babl.h"
 
 #include "gimpdrawable.h"
+#include "gimpdrawable-operation.h"
 #include "gimpimage.h"
 #include "gimpimage-color-profile.h"
 #include "gimpimage-convert-precision.h"
@@ -247,3 +248,60 @@ gimp_image_convert_precision (GimpImage        *image,
   if (progress)
     gimp_progress_end (progress);
 }
+
+void
+gimp_image_convert_dither_u8 (GimpImage    *image,
+                              GimpProgress *progress)
+{
+  GeglNode *dither;
+
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
+
+  dither = gegl_node_new_child (NULL,
+                                "operation", "gegl:noise-rgb",
+                                "red",      1.0 / 256.0,
+                                "green",    1.0 / 256.0,
+                                "blue",     1.0 / 256.0,
+                                "alpha",    1.0 / 256.0,
+                                "linear",   FALSE,
+                                "gaussian", FALSE,
+                                NULL);
+
+  if (dither)
+    {
+      GList *drawables;
+      GList *list;
+
+      drawables = gimp_image_get_layer_list (image);
+
+      for (list = drawables; list; list = g_list_next (list))
+        {
+          if (! gimp_viewable_get_children (list->data) &&
+              ! gimp_item_is_text_layer (list->data))
+            {
+              gimp_drawable_apply_operation (list->data, progress,
+                                             _("Dithering"),
+                                             dither);
+            }
+        }
+
+      g_list_free (drawables);
+
+      drawables = gimp_image_get_channel_list (image);
+
+      for (list = drawables; list; list = g_list_next (list))
+        {
+          if (! gimp_viewable_get_children (list->data))
+            {
+              gimp_drawable_apply_operation (list->data, progress,
+                                             _("Dithering"),
+                                             dither);
+            }
+        }
+
+      g_list_free (drawables);
+
+      g_object_unref (dither);
+    }
+}
diff --git a/app/core/gimpimage-convert-precision.h b/app/core/gimpimage-convert-precision.h
index 6fc988c..2afa526 100644
--- a/app/core/gimpimage-convert-precision.h
+++ b/app/core/gimpimage-convert-precision.h
@@ -29,5 +29,8 @@ void   gimp_image_convert_precision (GimpImage        *image,
                                      GeglDitherMethod  mask_dither_type,
                                      GimpProgress     *progress);
 
+void   gimp_image_convert_dither_u8 (GimpImage        *image,
+                                     GimpProgress     *progress);
+
 
 #endif  /*  __GIMP_IMAGE_CONVERT_PRECISION_H__  */
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 36fe715..d25e59a 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1277,6 +1277,30 @@ prefs_dialog_new (Gimp       *gimp,
   }
 
 
+  /***************************/
+  /*  Image Import / Export  */
+  /***************************/
+  vbox = gimp_prefs_box_add_page (GIMP_PREFS_BOX (prefs_box),
+                                  "gimp-prefs-import-export",
+                                  _("Image Import & Export"),
+                                  _("Image Import"),
+                                  GIMP_HELP_PREFS_DIALOG,
+                                  NULL,
+                                  &top_iter);
+
+  vbox2 = prefs_frame_new (_("Import Policies"),
+                           GTK_CONTAINER (vbox), TRUE);
+
+  button = prefs_check_button_add (object, "import-promote-float",
+                                   _("Promote imported images to "
+                                     "_floating point precition"),
+                                   GTK_BOX (vbox2));
+  button = prefs_check_button_add (object, "import-promote-dither",
+                                   _("Dither images when promoting to "
+                                     "floating point"),
+                                   GTK_BOX (vbox2));
+
+
   /****************/
   /*  Playground  */
   /****************/
diff --git a/app/file/file-open.c b/app/file/file-open.c
index 8fccdd6..d683d72 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -37,6 +37,7 @@
 #include "core/gimpdocumentlist.h"
 #include "core/gimpimage.h"
 #include "core/gimpimage-color-profile.h"
+#include "core/gimpimage-convert-precision.h"
 #include "core/gimpimage-merge.h"
 #include "core/gimpimage-undo.h"
 #include "core/gimpimagefile.h"
@@ -278,6 +279,28 @@ file_open_image (Gimp                *gimp,
     {
       gimp_image_undo_disable (image);
 
+      if (run_mode == GIMP_RUN_INTERACTIVE   &&
+          gimp->config->import_promote_float &&
+          file_open_file_proc_is_import (file_proc))
+        {
+          GimpPrecision old_precision = gimp_image_get_precision (image);
+
+          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 (gimp->config->import_promote_dither &&
+                  old_precision == GIMP_PRECISION_U8_GAMMA)
+                {
+                  gimp_image_convert_dither_u8 (image, progress);
+                }
+            }
+        }
+
       gimp_image_import_color_profile (image, context, progress,
                                        run_mode == GIMP_RUN_INTERACTIVE ?
                                        TRUE : FALSE);


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