[gthumb] Fixed tiff image corruption when saving the metadata



commit e63199806aac5a5cf454ec1d396e0be0ecead445
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jun 29 20:20:22 2010 +0200

    Fixed tiff image corruption when saving the metadata
    
    Clear all the metadata,  and use the setExifData, setIptcData and
    setXmpData functions to avoid tiff files corruptions.  This only works when
    using exiv2 version 0.20 or greater, so disable metadata writing when
    using earlier versions.

 configure.ac                           |    3 +++
 extensions/exiv2_tools/exiv2-utils.cpp |   28 ++++++++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4af3790..34d05de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -143,6 +143,9 @@ if test x$enable_exiv2 = xyes ; then
 			  exiv2 >= $EXIV2_REQUIRED,
 			  [enable_exiv2=yes],
 			  [enable_exiv2=no])
+	PKG_CHECK_MODULES(EXIV2_020,
+			  exiv2 >= 0.20,
+			  [AC_DEFINE(HAVE_EXIV2_020, 1, [Have exiv2 0.20 or greater])],)
 fi
 AC_SUBST(EXIV2_LIBS)
 AC_SUBST(EXIV2_CFLAGS)
diff --git a/extensions/exiv2_tools/exiv2-utils.cpp b/extensions/exiv2_tools/exiv2-utils.cpp
index 28e5445..6dc0995 100644
--- a/extensions/exiv2_tools/exiv2-utils.cpp
+++ b/extensions/exiv2_tools/exiv2-utils.cpp
@@ -629,11 +629,11 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr  image,
 	char **attributes;
 	int    i;
 
-	image->readMetadata();
+	image->clearMetadata();
 
 	// EXIF Data
 
-	Exiv2::ExifData &ed = image->exifData();
+	Exiv2::ExifData ed;
 	attributes = g_file_info_list_attributes (info, "Exif");
 	for (i = 0; attributes[i] != NULL; i++) {
 		GthMetadata *metadatum;
@@ -707,7 +707,7 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr  image,
 
 	// Update the thumbnail
 
-	Exiv2::ExifThumb thumb(image->exifData());
+	Exiv2::ExifThumb thumb(ed);
 	if ((pixbuf != NULL) && (width > 0) && (height > 0)) {
 		GdkPixbuf *thumb_pixbuf;
 		char      *buffer;
@@ -742,7 +742,7 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr  image,
 
 	// IPTC Data
 
-	Exiv2::IptcData &id = image->iptcData();
+	Exiv2::IptcData id;
 	attributes = g_file_info_list_attributes (info, "Iptc");
 	for (i = 0; attributes[i] != NULL; i++) {
 		GthMetadata *metadatum = (GthMetadata *) g_file_info_get_attribute_object (info, attributes[i]);
@@ -771,7 +771,7 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr  image,
 
 	// XMP Data
 
-	Exiv2::XmpData &xd = image->xmpData();
+	Exiv2::XmpData xd;
 	attributes = g_file_info_list_attributes (info, "Xmp");
 	for (i = 0; attributes[i] != NULL; i++) {
 		GthMetadata *metadatum = (GthMetadata *) g_file_info_get_attribute_object (info, attributes[i]);
@@ -805,7 +805,16 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr  image,
 	}
 	g_strfreev (attributes);
 
-	image->writeMetadata();
+	try {
+		image->setExifData(ed);
+		image->setIptcData(id);
+		image->setXmpData(xd);
+		image->writeMetadata();
+	}
+	catch (Exiv2::AnyError& e) {
+		g_warning ("%s", e.what());
+	}
+
 	Exiv2::BasicIo &io = image->io();
 	io.open();
 
@@ -817,8 +826,11 @@ extern "C"
 gboolean
 exiv2_supports_writes (const char *mime_type)
 {
-	return (_g_content_type_is_a (mime_type, "image/jpeg") ||
-		_g_content_type_is_a (mime_type, "image/png"));
+	return (g_content_type_equals (mime_type, "image/jpeg")
+#if HAVE_EXIV2_020
+		|| g_content_type_equals (mime_type, "image/tiff")
+#endif
+		|| g_content_type_equals (mime_type, "image/png"));
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]