return ret;
}
+static gboolean
+save_image_tiff (const gchar *filename, GdkPixbuf *pixbuf, GError **error)
+{
+ gchar *contents = NULL;
+ gchar *contents_encode = NULL;
+ gsize length;
+ gboolean ret;
+ gint len;
+
+ /* get icc file */
+ ret = g_file_get_contents (ICC_PROFILE, &contents, &length, error);
+ if (!ret)
+ goto out;
+ contents_encode = g_base64_encode ((const guchar *) contents, length);
+ ret = gdk_pixbuf_save (pixbuf, filename, "tiff", error,
+ "icc-profile", contents_encode,
+ NULL);
+ len = strlen (contents_encode);
+ g_debug ("ICC profile was %i bytes", len);
+out:
+ g_free (contents);
+ g_free (contents_encode);
+ return ret;
+}
+
static gboolean
save_image_verify (const gchar *filename, GError **error)
{
goto out;
}
+ /* PASS */
+ g_debug ("try to save TIFF with a profile");
+ ret = save_image_tiff ("icc-profile.tiff", pixbuf, &error);
+ if (!ret) {
+ g_warning ("FAILED: did not save image: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
/* PASS */
g_debug ("try to load PNG and get color attributes");
ret = save_image_verify ("icc-profile.png", &error);
goto out;
}
+ /* PASS */
+ g_debug ("try to load TIFF and get color attributes");
+ ret = save_image_verify ("icc-profile.tiff", &error);
+ if (!ret) {
+ g_warning ("FAILED: did not load image: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
/* success */
retval = 0;
g_debug ("ALL OKAY!");
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. */
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);
int y;
TiffSaveContext *context;
gboolean retval;
+ guchar *icc_profile = NULL;
+ gsize icc_profile_size = 0;
tiff_push_handlers ();
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++;
}
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)
_("Failed to write TIFF data"));
TIFFClose (tiff);
-
- free_save_context (context);
- tiff_pop_handlers ();
-
- return FALSE;
+ retval = FALSE;
+ goto cleanup;
}
TIFFClose (tiff);
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;
}