gthumb r2237 - in trunk: . libgthumb src
- From: mjc svn gnome org
- To: svn-commits-list gnome org
- Subject: gthumb r2237 - in trunk: . libgthumb src
- Date: Thu, 31 Jan 2008 18:11:53 +0000 (GMT)
Author: mjc
Date: Thu Jan 31 18:11:53 2008
New Revision: 2237
URL: http://svn.gnome.org/viewvc/gthumb?rev=2237&view=rev
Log:
2008-01-31 Michael J. Chudobiak <mjc svn gnome org>
* libgthumb/gth-exif-utils.c: (update_and_save_metadata):
* libgthumb/gth-exif-utils.h:
* libgthumb/gth-exiv2-utils.cpp:
* libgthumb/gth-exiv2-utils.hpp:
* src/catalog-web-exporter.c:
(copy_exif_from_orig_and_reset_orientation):
Added a new exiv2-based function, update_and_save_metadata, which
lets you copy metadata from one file to another, while updating
zero or one tags.
Modified:
trunk/ChangeLog
trunk/libgthumb/gth-exif-utils.c
trunk/libgthumb/gth-exif-utils.h
trunk/libgthumb/gth-exiv2-utils.cpp
trunk/libgthumb/gth-exiv2-utils.hpp
trunk/src/catalog-web-exporter.c
Modified: trunk/libgthumb/gth-exif-utils.c
==============================================================================
--- trunk/libgthumb/gth-exif-utils.c (original)
+++ trunk/libgthumb/gth-exif-utils.c Thu Jan 31 18:11:53 2008
@@ -299,20 +299,23 @@
void
-copy_exif_data (const char *uri_src,
- const char *uri_dest)
+update_and_save_metadata (const char *uri_src,
+ const char *uri_dest,
+ const char *tag_name,
+ const char *tag_value)
{
- ExifData *edata;
+ char *from_local_file;
+ char *to_local_file;
- if (! image_is_jpeg (uri_src) || ! image_is_jpeg (uri_dest))
- return;
+ from_local_file = get_cache_filename_from_uri (uri_src);
+ to_local_file = get_cache_filename_from_uri (uri_dest);
- edata = gth_exif_data_new_from_uri (uri_src);
- if (edata == NULL)
- return;
- save_exif_data_to_uri (uri_dest, edata);
+ write_metadata (from_local_file, to_local_file, tag_name, tag_value);
+
+ /* to do: update non-local uri_dest */
- exif_data_unref (edata);
+ g_free (from_local_file);
+ g_free (to_local_file);
}
Modified: trunk/libgthumb/gth-exif-utils.h
==============================================================================
--- trunk/libgthumb/gth-exif-utils.h (original)
+++ trunk/libgthumb/gth-exif-utils.h Thu Jan 31 18:11:53 2008
@@ -101,8 +101,10 @@
const char *tagnames[]);
void save_exif_data_to_uri (const char *filename,
ExifData *edata);
-void copy_exif_data (const char *src,
- const char *dest);
+void update_and_save_metadata (const char *uri_src,
+ const char *uri_dest,
+ const char *tag_name,
+ const char *tag_value);
int gth_minimal_exif_tag_write (const char *filename,
ExifTag etag,
void *data,
Modified: trunk/libgthumb/gth-exiv2-utils.cpp
==============================================================================
--- trunk/libgthumb/gth-exiv2-utils.cpp (original)
+++ trunk/libgthumb/gth-exiv2-utils.cpp Thu Jan 31 18:11:53 2008
@@ -26,6 +26,7 @@
#include <exiv2/error.hpp>
#include <exiv2/image.hpp>
#include <exiv2/exif.hpp>
+
#include <iostream>
#include <string>
#include <sstream>
@@ -524,3 +525,58 @@
return metadata;
}
}
+
+
+extern "C"
+void
+write_metadata (const char *from_file,
+ const char *to_file,
+ const char *key,
+ const char *value)
+{
+ //Open first image
+ Exiv2::Image::AutoPtr image1 = Exiv2::ImageFactory::open (from_file);
+ g_assert (image1.get() != 0);
+
+ // Load existing metadata
+ image1->readMetadata();
+
+ // Update the requested tag
+ if (key != NULL) {
+ if (g_str_has_prefix (key, "Exif")) {
+ Exiv2::ExifKey ek (key);
+ Exiv2::ExifData &md = image1->exifData();
+ Exiv2::ExifData::iterator pos = md.findKey(ek);
+ if (pos != md.end())
+ pos->setValue(value);
+ }
+ else if (g_str_has_prefix (key, "Iptc")) {
+ Exiv2::IptcKey ek (key);
+ Exiv2::IptcData &md = image1->iptcData();
+ Exiv2::IptcData::iterator pos = md.findKey(ek);
+ if (pos != md.end())
+ pos->setValue(value);
+ }
+ else if (g_str_has_prefix (key, "Xmp")) {
+ Exiv2::XmpKey ek (key);
+ Exiv2::XmpData &md = image1->xmpData();
+ Exiv2::XmpData::iterator pos = md.findKey(ek);
+ if (pos != md.end())
+ pos->setValue(value);
+ }
+ }
+
+ // Open second image
+ Exiv2::Image::AutoPtr image2 = Exiv2::ImageFactory::open (to_file);
+ g_assert (image2.get() != 0);
+
+ // TODO: delete IFD1 here
+
+ image2->setExifData (image1->exifData());
+ image2->setIptcData (image1->iptcData());
+ image2->setXmpData (image1->xmpData());
+
+ // overwrite existing metadata with new metadata
+ image2->writeMetadata();
+}
+
Modified: trunk/libgthumb/gth-exiv2-utils.hpp
==============================================================================
--- trunk/libgthumb/gth-exiv2-utils.hpp (original)
+++ trunk/libgthumb/gth-exiv2-utils.hpp Thu Jan 31 18:11:53 2008
@@ -26,10 +26,17 @@
#include "gth-exif-utils.h"
extern "C" GList *
-read_exiv2_file (const char *uri, GList *metadata);
+read_exiv2_file (const char *uri,
+ GList *metadata);
extern "C" GList *
-read_exiv2_sidecar (const char *uri, GList *metadata);
+read_exiv2_sidecar (const char *uri,
+ GList *metadata);
+extern "C" void
+write_metadata (const char *from_file,
+ const char *to_file,
+ const char *key,
+ const char *value);
#endif
Modified: trunk/src/catalog-web-exporter.c
==============================================================================
--- trunk/src/catalog-web-exporter.c (original)
+++ trunk/src/catalog-web-exporter.c Thu Jan 31 18:11:53 2008
@@ -2090,33 +2090,7 @@
copy_exif_from_orig_and_reset_orientation (FileData *file,
const char *dest_uri)
{
- char *local_src_file = NULL;
- char *local_dest_file = NULL;
- JPEGData *jdata_src;
- JPEGData *jdata_dest;
- ExifData *edata_src;
-
- local_src_file = get_cache_filename_from_uri (file->path);
- local_dest_file = get_cache_filename_from_uri (dest_uri);
-
- jdata_src = jpeg_data_new_from_file (local_src_file);
- if (jdata_src != NULL) {
- edata_src = jpeg_data_get_exif_data (jdata_src);
- if (edata_src != NULL) {
- jdata_dest = jpeg_data_new_from_file (local_dest_file);
- if (jdata_dest != NULL) {
- set_exif_orientation_to_top_left (edata_src);
- jpeg_data_set_exif_data (jdata_dest, edata_src);
- jpeg_data_save_file (jdata_dest, local_dest_file);
- jpeg_data_unref (jdata_dest);
- }
- exif_data_unref (edata_src);
- }
- jpeg_data_unref (jdata_src);
- }
-
- g_free (local_src_file);
- g_free (local_dest_file);
+ update_and_save_metadata (file->path, dest_uri, "Exif.Image.Orientation", "1");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]