summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-tiff.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2009-12-21 08:53:28 +0000
committerRichard Hughes <richard@hughsie.com>2009-12-21 08:53:28 +0000
commit60e0183ac9a56fa0d05971a8cf90798053b430c7 (patch)
tree524b0f49faf6a27ebd8b001876d1acdeacacb0f8 /gdk-pixbuf/io-tiff.c
parent25e3329215a11190a4846dada95d8fd305ac74f8 (diff)
downloadgtk+-60e0183ac9a56fa0d05971a8cf90798053b430c7.tar.gz
Add icc-profile option to gdk-pixbuf for the TIFF image format
Diffstat (limited to 'gdk-pixbuf/io-tiff.c')
-rw-r--r--gdk-pixbuf/io-tiff.c59
1 files changed, 40 insertions, 19 deletions
diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c
index 7f8b79318e..221bcac626 100644
--- a/gdk-pixbuf/io-tiff.c
+++ b/gdk-pixbuf/io-tiff.c
@@ -150,6 +150,10 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
uint16 orientation = 0;
uint16 transform = 0;
uint16 codec;
+ gchar *icc_profile_base64;
+ const gchar *icc_profile;
+ guint icc_profile_size;
+ gint retval;
/* We're called with the lock held. */
@@ -274,6 +278,14 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
gdk_pixbuf_set_option (pixbuf, "compression", str);
}
+ /* Extract embedded ICC profile */
+ retval = TIFFGetField (tiff, TIFFTAG_ICCPROFILE, &icc_profile_size, &icc_profile);
+ if (retval == 1) {
+ icc_profile_base64 = g_base64_encode ((const guchar *) icc_profile, icc_profile_size);
+ gdk_pixbuf_set_option (pixbuf, "icc-profile", icc_profile_base64);
+ g_free (icc_profile_base64);
+ }
+
if (context && context->prepare_func)
(* context->prepare_func) (pixbuf, NULL, context->user_data);
@@ -662,6 +674,8 @@ gdk_pixbuf__tiff_image_save_to_callback (GdkPixbufSaveFunc save_func,
int y;
TiffSaveContext *context;
gboolean retval;
+ guchar *icc_profile = NULL;
+ gsize icc_profile_size = 0;
tiff_push_handlers ();
@@ -710,13 +724,22 @@ gdk_pixbuf__tiff_image_save_to_callback (GdkPixbufSaveFunc save_func,
else {
tiff_set_error (error,
GDK_PIXBUF_ERROR_FAILED,
- _("TIFF compression doesn't refer to a valid codec."));
-
- tiff_pop_handlers ();
-
- free_save_context (context);
- return FALSE;
+ _("TIFF compression doesn't refer to a valid codec."));
+ retval = FALSE;
+ goto cleanup;
}
+ } else if (g_str_equal (keys[i], "icc-profile")) {
+ /* decode from base64 */
+ icc_profile = g_base64_decode (values[i], &icc_profile_size);
+ if (icc_profile_size < 127) {
+ g_set_error (error,
+ GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_BAD_OPTION,
+ _("Color profile has invalid length '%d'."),
+ icc_profile_size);
+ retval = FALSE;
+ goto cleanup;
+ }
}
i++;
}
@@ -729,6 +752,9 @@ gdk_pixbuf__tiff_image_save_to_callback (GdkPixbufSaveFunc save_func,
TIFFSetField (tiff, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ if (icc_profile != NULL)
+ TIFFSetField (tiff, TIFFTAG_ICCPROFILE, icc_profile_size, icc_profile);
+
for (y = 0; y < height; y++) {
if (TIFFWriteScanline (tiff, pixels + y * rowstride, y, 0) == -1 ||
global_error)
@@ -741,11 +767,8 @@ gdk_pixbuf__tiff_image_save_to_callback (GdkPixbufSaveFunc save_func,
_("Failed to write TIFF data"));
TIFFClose (tiff);
-
- free_save_context (context);
- tiff_pop_handlers ();
-
- return FALSE;
+ retval = FALSE;
+ goto cleanup;
}
TIFFClose (tiff);
@@ -753,20 +776,18 @@ gdk_pixbuf__tiff_image_save_to_callback (GdkPixbufSaveFunc save_func,
tiff_set_error (error,
GDK_PIXBUF_ERROR_FAILED,
_("TIFFClose operation failed"));
-
- free_save_context (context);
- tiff_pop_handlers ();
-
- return FALSE;
+ retval = FALSE;
+ goto cleanup;
}
- tiff_pop_handlers ();
/* Now call the callback */
retval = save_func (context->buffer, context->used, error, user_data);
- free_save_context (context);
-
+cleanup:
+ g_free (icc_profile);
+ tiff_pop_handlers ();
+ free_save_context (context);
return retval;
}