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.
This commit is contained in:
Michael Natterer 2017-01-22 22:03:55 +01:00
parent 6c8985daf6
commit 27519fc798
7 changed files with 147 additions and 1 deletions

View File

@ -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:

View File

@ -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

View File

@ -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.")

View File

@ -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);
}
}

View File

@ -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__ */

View File

@ -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 */
/****************/

View File

@ -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);