Commit 76782e62 authored by Michael Natterer's avatar Michael Natterer 😴

app: add "gboolean convert_profile" to GimpDrawable::convert_type()

also add "GType old_type" to GimpItem::convert() so implementations
can do things depending on the type of the original item.

In gimp_layer_convert(), if the original item is also a layer, and
color management is not off (with a FIXME because this is the wrong
check), pass convert_profile = TRUE to gimp_drawable_convert_type().

There is no color profile conversion anywhere behind this, this is
just an API change commit.
parent e8a5f285
......@@ -85,7 +85,8 @@ static gboolean gimp_channel_bounds (GimpItem *item,
static GimpItem * gimp_channel_duplicate (GimpItem *item,
GType new_type);
static void gimp_channel_convert (GimpItem *item,
GimpImage *dest_image);
GimpImage *dest_image,
GType old_type);
static void gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
......@@ -141,6 +142,7 @@ static void gimp_channel_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
static void gimp_channel_invalidate_boundary (GimpDrawable *drawable);
static void gimp_channel_get_active_components (const GimpDrawable *drawable,
......@@ -543,7 +545,8 @@ gimp_channel_duplicate (GimpItem *item,
static void
gimp_channel_convert (GimpItem *item,
GimpImage *dest_image)
GimpImage *dest_image,
GType old_type)
{
GimpChannel *channel = GIMP_CHANNEL (item);
GimpDrawable *drawable = GIMP_DRAWABLE (item);
......@@ -552,7 +555,7 @@ gimp_channel_convert (GimpItem *item,
{
gimp_drawable_convert_type (drawable, dest_image, GIMP_GRAY,
gimp_image_get_precision (dest_image),
0, 0,
0, 0, FALSE,
FALSE);
}
......@@ -598,7 +601,7 @@ gimp_channel_convert (GimpItem *item,
}
}
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image);
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image, old_type);
}
static void
......@@ -895,6 +898,7 @@ gimp_channel_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
GeglBuffer *dest_buffer;
......
......@@ -154,6 +154,7 @@ static void gimp_drawable_real_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
static GeglBuffer * gimp_drawable_real_get_buffer (GimpDrawable *drawable);
......@@ -789,21 +790,16 @@ gimp_drawable_real_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_type,
gboolean push_undo)
{
GeglBuffer *dest_buffer;
const Babl *format;
format = gimp_image_get_format (dest_image,
new_base_type,
new_precision,
gimp_drawable_has_alpha (drawable));
dest_buffer =
gegl_buffer_new (GEGL_RECTANGLE (0, 0,
gimp_item_get_width (GIMP_ITEM (drawable)),
gimp_item_get_height (GIMP_ITEM (drawable))),
format);
new_format);
gegl_buffer_copy (gimp_drawable_get_buffer (drawable), NULL, GEGL_ABYSS_NONE,
dest_buffer, NULL);
......@@ -1262,6 +1258,7 @@ gimp_drawable_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
const Babl *new_format;
......@@ -1269,7 +1266,8 @@ gimp_drawable_convert_type (GimpDrawable *drawable,
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GIMP_IS_IMAGE (dest_image));
g_return_if_fail (new_base_type != gimp_drawable_get_base_type (drawable) ||
new_precision != gimp_drawable_get_precision (drawable));
new_precision != gimp_drawable_get_precision (drawable) ||
convert_profile);
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
push_undo = FALSE;
......@@ -1285,6 +1283,7 @@ gimp_drawable_convert_type (GimpDrawable *drawable,
new_precision,
layer_dither_type,
mask_dither_type,
convert_profile,
push_undo);
}
......
......@@ -68,6 +68,7 @@ struct _GimpDrawableClass
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
void (* apply_buffer) (GimpDrawable *drawable,
GeglBuffer *buffer,
......@@ -144,6 +145,7 @@ void gimp_drawable_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
void gimp_drawable_apply_buffer (GimpDrawable *drawable,
......
......@@ -94,7 +94,8 @@ static gboolean gimp_group_layer_is_position_locked (const GimpItem *item);
static GimpItem * gimp_group_layer_duplicate (GimpItem *item,
GType new_type);
static void gimp_group_layer_convert (GimpItem *item,
GimpImage *dest_image);
GimpImage *dest_image,
GType old_type);
static void gimp_group_layer_translate (GimpItem *item,
gint offset_x,
gint offset_y,
......@@ -142,6 +143,7 @@ static void gimp_group_layer_convert_type (GimpDrawable *drawabl
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
static const Babl * gimp_group_layer_get_format (GimpProjectable *projectable);
......@@ -493,7 +495,8 @@ gimp_group_layer_duplicate (GimpItem *item,
static void
gimp_group_layer_convert (GimpItem *item,
GimpImage *dest_image)
GimpImage *dest_image,
GType old_type)
{
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GList *list;
......@@ -504,10 +507,11 @@ gimp_group_layer_convert (GimpItem *item,
{
GimpItem *child = list->data;
GIMP_ITEM_GET_CLASS (child)->convert (child, dest_image);
GIMP_ITEM_GET_CLASS (child)->convert (child, dest_image,
G_TYPE_FROM_INSTANCE (child));
}
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image);
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image, old_type);
}
static void
......@@ -878,6 +882,7 @@ gimp_group_layer_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (drawable);
......@@ -921,6 +926,7 @@ gimp_group_layer_convert_type (GimpDrawable *drawable,
gimp_drawable_convert_type (GIMP_DRAWABLE (mask), dest_image,
GIMP_GRAY, new_precision,
layer_dither_type, mask_dither_type,
convert_profile,
push_undo);
}
}
......
......@@ -128,7 +128,7 @@ gimp_group_layer_undo_pop (GimpUndo *undo,
gimp_item_get_image (GIMP_ITEM (group)),
group_layer_undo->prev_type,
group_layer_undo->prev_precision,
0, 0,
0, 0, FALSE,
FALSE);
group_layer_undo->prev_type = type;
......
......@@ -134,6 +134,7 @@ gimp_image_convert_precision (GimpImage *image,
precision,
dither_type,
mask_dither_type,
FALSE,
TRUE);
if (progress)
......
......@@ -1021,7 +1021,7 @@ gimp_image_convert_type (GimpImage *image,
{
gimp_drawable_convert_type (GIMP_DRAWABLE (layer), image, new_type,
gimp_drawable_get_precision (GIMP_DRAWABLE (layer)),
0, 0,
0, 0, FALSE,
TRUE);
}
}
......
......@@ -133,7 +133,8 @@ static gboolean gimp_item_real_bounds (GimpItem *item,
static GimpItem * gimp_item_real_duplicate (GimpItem *item,
GType new_type);
static void gimp_item_real_convert (GimpItem *item,
GimpImage *dest_image);
GimpImage *dest_image,
GType old_type);
static gboolean gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
......@@ -583,7 +584,8 @@ gimp_item_real_duplicate (GimpItem *item,
static void
gimp_item_real_convert (GimpItem *item,
GimpImage *dest_image)
GimpImage *dest_image,
GType old_type)
{
gimp_item_set_image (item, dest_image);
}
......@@ -990,16 +992,19 @@ gimp_item_convert (GimpItem *item,
GType new_type)
{
GimpItem *new_item;
GType old_type;
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (GET_PRIVATE (item)->image), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_ITEM), NULL);
old_type = G_TYPE_FROM_INSTANCE (item);
new_item = gimp_item_duplicate (item, new_type);
if (new_item)
GIMP_ITEM_GET_CLASS (new_item)->convert (new_item, dest_image);
GIMP_ITEM_GET_CLASS (new_item)->convert (new_item, dest_image, old_type);
return new_item;
}
......
......@@ -62,7 +62,8 @@ struct _GimpItemClass
GimpItem * (* duplicate) (GimpItem *item,
GType new_type);
void (* convert) (GimpItem *item,
GimpImage *dest_image);
GimpImage *dest_image,
GType old_type);
gboolean (* rename) (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
......
......@@ -26,13 +26,17 @@
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpmath/gimpmath.h"
#include "core-types.h"
#include "config/gimpcoreconfig.h" /* FIXME profile convert config */
#include "gegl/gimp-gegl-apply-operation.h"
#include "gegl/gimp-gegl-nodes.h"
#include "gimp.h" /* FIXME profile convert config */
#include "gimpboundary.h"
#include "gimpchannel-select.h"
#include "gimpcontext.h"
......@@ -105,7 +109,8 @@ static GimpItemTree * gimp_layer_get_tree (GimpItem *item);
static GimpItem * gimp_layer_duplicate (GimpItem *item,
GType new_type);
static void gimp_layer_convert (GimpItem *item,
GimpImage *dest_image);
GimpImage *dest_image,
GType old_type);
static gboolean gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc,
......@@ -163,6 +168,7 @@ static void gimp_layer_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_type,
gboolean push_undo);
static void gimp_layer_invalidate_boundary (GimpDrawable *drawable);
static void gimp_layer_get_active_components (const GimpDrawable *drawable,
......@@ -743,14 +749,18 @@ gimp_layer_duplicate (GimpItem *item,
static void
gimp_layer_convert (GimpItem *item,
GimpImage *dest_image)
GimpImage *dest_image,
GType old_type)
{
GimpLayer *layer = GIMP_LAYER (item);
GimpDrawable *drawable = GIMP_DRAWABLE (item);
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
GimpColorConfig *config = image->gimp->config->color_management;
GimpImageBaseType old_base_type;
GimpImageBaseType new_base_type;
GimpPrecision old_precision;
GimpPrecision new_precision;
gboolean convert_profile;
old_base_type = gimp_drawable_get_base_type (drawable);
new_base_type = gimp_image_get_base_type (dest_image);
......@@ -758,19 +768,27 @@ gimp_layer_convert (GimpItem *item,
old_precision = gimp_drawable_get_precision (drawable);
new_precision = gimp_image_get_precision (dest_image);
convert_profile = (g_type_is_a (old_type, GIMP_TYPE_LAYER) &&
/* FIXME: this is the wrong check, need
* something like file import conversion config
*/
(config->mode != GIMP_COLOR_MANAGEMENT_OFF));
if (old_base_type != new_base_type ||
old_precision != new_precision)
old_precision != new_precision ||
convert_profile)
{
gimp_drawable_convert_type (drawable, dest_image,
new_base_type, new_precision,
0, 0,
convert_profile,
FALSE);
}
if (layer->mask)
gimp_item_set_image (GIMP_ITEM (layer->mask), dest_image);
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image);
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image, old_type);
}
static gboolean
......@@ -1005,6 +1023,7 @@ gimp_layer_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
GimpLayer *layer = GIMP_LAYER (drawable);
......@@ -1043,6 +1062,7 @@ gimp_layer_convert_type (GimpDrawable *drawable,
gimp_drawable_convert_type (GIMP_DRAWABLE (layer->mask), dest_image,
GIMP_GRAY, new_precision,
layer_dither_type, mask_dither_type,
convert_profile,
push_undo);
}
}
......
......@@ -56,6 +56,7 @@ static void gimp_layer_mask_convert_type (GimpDrawable *dr
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
......@@ -168,6 +169,7 @@ gimp_layer_mask_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
new_format = gimp_babl_mask_format (new_precision);
......@@ -178,6 +180,7 @@ gimp_layer_mask_convert_type (GimpDrawable *drawable,
new_precision,
layer_dither_type,
mask_dither_type,
convert_profile,
push_undo);
}
......
......@@ -88,6 +88,7 @@ static void gimp_selection_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
static void gimp_selection_invalidate_boundary (GimpDrawable *drawable);
......@@ -309,6 +310,7 @@ gimp_selection_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
new_format = gimp_babl_mask_format (new_precision);
......@@ -319,6 +321,7 @@ gimp_selection_convert_type (GimpDrawable *drawable,
new_precision,
layer_dither_type,
mask_dither_type,
convert_profile,
push_undo);
}
......
......@@ -91,6 +91,7 @@ static void gimp_text_layer_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo);
static void gimp_text_layer_set_buffer (GimpDrawable *drawable,
gboolean push_undo,
......@@ -318,6 +319,7 @@ gimp_text_layer_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_profile,
gboolean push_undo)
{
GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
......@@ -331,6 +333,7 @@ gimp_text_layer_convert_type (GimpDrawable *drawable,
new_precision,
layer_dither_type,
mask_dither_type,
convert_profile,
push_undo);
}
else
......
......@@ -273,7 +273,8 @@ gimp_text_undo_pop (GimpUndo *undo,
gimp_item_get_image (GIMP_ITEM (layer)),
gimp_babl_format_get_base_type (text_undo->format),
gimp_babl_format_get_precision (text_undo->format),
0, 0, FALSE);
0, 0, FALSE,
FALSE);
text_undo->format = format;
}
break;
......
......@@ -77,7 +77,8 @@ static gboolean gimp_vectors_bounds (GimpItem *item,
static GimpItem * gimp_vectors_duplicate (GimpItem *item,
GType new_type);
static void gimp_vectors_convert (GimpItem *item,
GimpImage *dest_image);
GimpImage *dest_image,
GType old_type);
static void gimp_vectors_translate (GimpItem *item,
gint offset_x,
gint offset_y,
......@@ -411,13 +412,14 @@ gimp_vectors_duplicate (GimpItem *item,
static void
gimp_vectors_convert (GimpItem *item,
GimpImage *dest_image)
GimpImage *dest_image,
GType old_type)
{
gimp_item_set_size (item,
gimp_image_get_width (dest_image),
gimp_image_get_height (dest_image));
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image);
GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image, old_type);
}
static void
......
......@@ -269,7 +269,8 @@ gimp_channel_tree_view_drop_component (GimpContainerTreeView *tree_view,
g_free (name);
if (src_image != image)
GIMP_ITEM_GET_CLASS (new_item)->convert (new_item, image);
GIMP_ITEM_GET_CLASS (new_item)->convert (new_item, image,
GIMP_TYPE_CHANNEL);
gimp_image_add_channel (image, GIMP_CHANNEL (new_item), parent, index, TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment