app: tag GimpBuffers with an ICC profile, if available

Set the profile when the buffer is copied from a layer, and when it's
created from a GdkPixbuf from the clipboard. The profile is not yet
used for anything.
This commit is contained in:
Michael Natterer 2015-06-16 23:16:54 +02:00
parent 56b6dbaa87
commit 26e2ccbdf3
3 changed files with 82 additions and 1 deletions

View File

@ -591,7 +591,8 @@ gimp_edit_extract (GimpImage *image,
gint offset_y;
if (cut_pixels)
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT, C_("undo-type", "Cut"));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT,
C_("undo-type", "Cut"));
/* Cut/copy the mask portion from the image */
buffer = gimp_selection_extract (GIMP_SELECTION (gimp_image_get_mask (image)),
@ -608,6 +609,19 @@ gimp_edit_extract (GimpImage *image,
offset_x, offset_y, FALSE);
g_object_unref (buffer);
if (GIMP_IS_LAYER (pickable))
{
const guint8 *icc_data;
gsize icc_len;
icc_data =
gimp_color_managed_get_icc_profile (GIMP_COLOR_MANAGED (image),
&icc_len);
if (icc_data)
gimp_buffer_set_icc_profile (gimp_buffer, icc_data, icc_len);
}
return gimp_buffer;
}

View File

@ -101,6 +101,8 @@ gimp_buffer_finalize (GObject *object)
buffer->buffer = NULL;
}
gimp_buffer_set_icc_profile (buffer, NULL, 0);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -112,6 +114,7 @@ gimp_buffer_get_memsize (GimpObject *object,
gint64 memsize = 0;
memsize += gimp_gegl_buffer_get_memsize (buffer->buffer);
memsize += buffer->icc_profile_len;
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -268,6 +271,7 @@ gimp_buffer_new_from_pixbuf (GdkPixbuf *pixbuf,
{
GimpBuffer *gimp_buffer;
GeglBuffer *buffer;
gchar *icc_base64 = NULL;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
g_return_val_if_fail (name != NULL, NULL);
@ -277,6 +281,23 @@ gimp_buffer_new_from_pixbuf (GdkPixbuf *pixbuf,
gimp_buffer = gimp_buffer_new (buffer, name,
offset_x, offset_y, FALSE);
g_object_get (pixbuf, "icc-profile", icc_base64, NULL);
if (icc_base64)
{
guint8 *icc_data;
gsize icc_len;
icc_data = g_base64_decode (icc_base64, &icc_len);
g_free (icc_base64);
if (icc_data)
{
gimp_buffer_set_icc_profile (gimp_buffer, icc_data, icc_len);
g_free (icc_data);
}
}
g_object_unref (buffer);
return gimp_buffer;
@ -313,3 +334,40 @@ gimp_buffer_get_buffer (const GimpBuffer *buffer)
return buffer->buffer;
}
void
gimp_buffer_set_icc_profile (GimpBuffer *buffer,
const guint8 *data,
gsize length)
{
g_return_if_fail (GIMP_IS_BUFFER (buffer));
g_return_if_fail (data == NULL || length != 0);
if (data != buffer->icc_profile)
{
if (buffer->icc_profile)
{
g_free (buffer->icc_profile);
buffer->icc_profile = NULL;
buffer->icc_profile_len = 0;
}
if (data)
{
buffer->icc_profile = g_memdup (data, length);
buffer->icc_profile_len = length;
}
}
}
const guint8 *
gimp_buffer_get_icc_profile (const GimpBuffer *buffer,
gsize *length)
{
g_return_val_if_fail (GIMP_IS_BUFFER (buffer), NULL);
if (length)
*length = buffer->icc_profile_len;
return buffer->icc_profile;
}

View File

@ -39,6 +39,9 @@ struct _GimpBuffer
GeglBuffer *buffer;
gint offset_x;
gint offset_y;
guint8 *icc_profile;
gsize icc_profile_len;
};
struct _GimpBufferClass
@ -65,5 +68,11 @@ const Babl * gimp_buffer_get_format (const GimpBuffer *buffer);
GeglBuffer * gimp_buffer_get_buffer (const GimpBuffer *buffer);
void gimp_buffer_set_icc_profile (GimpBuffer *buffer,
const guint8 *data,
gsize length);
const guint8 * gimp_buffer_get_icc_profile (const GimpBuffer *buffer,
gsize *length);
#endif /* __GIMP_BUFFER_H__ */