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().
This commit is contained in:
@ -108,6 +108,7 @@ enum
|
|||||||
PROP_QUICK_MASK_COLOR,
|
PROP_QUICK_MASK_COLOR,
|
||||||
PROP_IMPORT_PROMOTE_FLOAT,
|
PROP_IMPORT_PROMOTE_FLOAT,
|
||||||
PROP_IMPORT_PROMOTE_DITHER,
|
PROP_IMPORT_PROMOTE_DITHER,
|
||||||
|
PROP_IMPORT_ADD_ALPHA,
|
||||||
|
|
||||||
/* ignored, only for backward compatibility: */
|
/* ignored, only for backward compatibility: */
|
||||||
PROP_INSTALL_COLORMAP,
|
PROP_INSTALL_COLORMAP,
|
||||||
@ -634,6 +635,13 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
|
|||||||
TRUE,
|
TRUE,
|
||||||
GIMP_PARAM_STATIC_STRINGS);
|
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: */
|
/* only for backward compatibility: */
|
||||||
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_INSTALL_COLORMAP,
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_INSTALL_COLORMAP,
|
||||||
"install-colormap",
|
"install-colormap",
|
||||||
@ -924,6 +932,9 @@ gimp_core_config_set_property (GObject *object,
|
|||||||
case PROP_IMPORT_PROMOTE_DITHER:
|
case PROP_IMPORT_PROMOTE_DITHER:
|
||||||
core_config->import_promote_dither = g_value_get_boolean (value);
|
core_config->import_promote_dither = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_IMPORT_ADD_ALPHA:
|
||||||
|
core_config->import_add_alpha = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_INSTALL_COLORMAP:
|
case PROP_INSTALL_COLORMAP:
|
||||||
case PROP_MIN_COLORS:
|
case PROP_MIN_COLORS:
|
||||||
@ -1105,6 +1116,9 @@ gimp_core_config_get_property (GObject *object,
|
|||||||
case PROP_IMPORT_PROMOTE_DITHER:
|
case PROP_IMPORT_PROMOTE_DITHER:
|
||||||
g_value_set_boolean (value, core_config->import_promote_dither);
|
g_value_set_boolean (value, core_config->import_promote_dither);
|
||||||
break;
|
break;
|
||||||
|
case PROP_IMPORT_ADD_ALPHA:
|
||||||
|
g_value_set_boolean (value, core_config->import_add_alpha);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_INSTALL_COLORMAP:
|
case PROP_INSTALL_COLORMAP:
|
||||||
case PROP_MIN_COLORS:
|
case PROP_MIN_COLORS:
|
||||||
|
@ -93,6 +93,7 @@ struct _GimpCoreConfig
|
|||||||
GimpRGB quick_mask_color;
|
GimpRGB quick_mask_color;
|
||||||
gboolean import_promote_float;
|
gboolean import_promote_float;
|
||||||
gboolean import_promote_dither;
|
gboolean import_promote_dither;
|
||||||
|
gboolean import_add_alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpCoreConfigClass
|
struct _GimpCoreConfigClass
|
||||||
|
@ -189,6 +189,9 @@ _("Promote imported images to floating point precision. Does not apply " \
|
|||||||
_("When promoting imported images to floating point precision, also add " \
|
_("When promoting imported images to floating point precision, also add " \
|
||||||
"minimal noise in order do distribute color values a bit.")
|
"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 \
|
#define INITIAL_ZOOM_TO_FIT_BLURB \
|
||||||
_("When enabled, this will ensure that the full image is visible after a " \
|
_("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.")
|
"file is opened, otherwise it will be displayed with a scale of 1:1.")
|
||||||
|
@ -1300,6 +1300,10 @@ prefs_dialog_new (Gimp *gimp,
|
|||||||
"floating point"),
|
"floating point"),
|
||||||
GTK_BOX (vbox2));
|
GTK_BOX (vbox2));
|
||||||
|
|
||||||
|
button = prefs_check_button_add (object, "import-add-alpha",
|
||||||
|
_("Add an alpha channel to imported images"),
|
||||||
|
GTK_BOX (vbox2));
|
||||||
|
|
||||||
|
|
||||||
/****************/
|
/****************/
|
||||||
/* Playground */
|
/* Playground */
|
||||||
|
@ -31,11 +31,16 @@
|
|||||||
#include "core/gimpimage.h"
|
#include "core/gimpimage.h"
|
||||||
#include "core/gimpimage-color-profile.h"
|
#include "core/gimpimage-color-profile.h"
|
||||||
#include "core/gimpimage-convert-precision.h"
|
#include "core/gimpimage-convert-precision.h"
|
||||||
|
#include "core/gimplayer.h"
|
||||||
#include "core/gimpprogress.h"
|
#include "core/gimpprogress.h"
|
||||||
|
|
||||||
|
#include "text/gimptextlayer.h"
|
||||||
|
|
||||||
#include "file-import.h"
|
#include "file-import.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* public functions */
|
||||||
|
|
||||||
void
|
void
|
||||||
file_import_image (GimpImage *image,
|
file_import_image (GimpImage *image,
|
||||||
GimpContext *context,
|
GimpContext *context,
|
||||||
@ -52,26 +57,46 @@ file_import_image (GimpImage *image,
|
|||||||
|
|
||||||
config = image->gimp->config;
|
config = image->gimp->config;
|
||||||
|
|
||||||
if (interactive &&
|
if (interactive && gimp_image_get_base_type (image) != GIMP_INDEXED)
|
||||||
config->import_promote_float &&
|
|
||||||
gimp_image_get_base_type (image) != GIMP_INDEXED)
|
|
||||||
{
|
{
|
||||||
GimpPrecision old_precision = gimp_image_get_precision (image);
|
if (config->import_promote_float)
|
||||||
|
|
||||||
if (old_precision != GIMP_PRECISION_FLOAT_LINEAR)
|
|
||||||
{
|
{
|
||||||
gimp_image_convert_precision (image, GIMP_PRECISION_FLOAT_LINEAR,
|
GimpPrecision old_precision = gimp_image_get_precision (image);
|
||||||
GEGL_DITHER_NONE,
|
|
||||||
GEGL_DITHER_NONE,
|
|
||||||
GEGL_DITHER_NONE,
|
|
||||||
progress);
|
|
||||||
|
|
||||||
if (config->import_promote_dither &&
|
if (old_precision != GIMP_PRECISION_FLOAT_LINEAR)
|
||||||
old_precision == GIMP_PRECISION_U8_GAMMA)
|
|
||||||
{
|
{
|
||||||
gimp_image_convert_dither_u8 (image, progress);
|
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)
|
||||||
|
{
|
||||||
|
GList *layers = gimp_image_get_layer_list (image);
|
||||||
|
GList *list;
|
||||||
|
|
||||||
|
for (list = layers; list; list = g_list_next (list))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gimp_image_import_color_profile (image, context, progress, interactive);
|
gimp_image_import_color_profile (image, context, progress, interactive);
|
||||||
|
Reference in New Issue
Block a user