Author: post
Date: 2010-10-12 19:46:17 +0200 (Tue, 12 Oct 2010)
New Revision: 3549
Modified:
trunk/librawstudio/rs-exif.cc
trunk/librawstudio/rs-exif.h
trunk/plugins/output-jpegfile/output-jpegfile.c
trunk/plugins/output-pngfile/output-pngfile.c
Log:
Change colorspace in exported jpeg files, and add tags to files in exif and
iptc.
Modified: trunk/librawstudio/rs-exif.cc
===================================================================
--- trunk/librawstudio/rs-exif.cc 2010-10-12 17:39:58 UTC (rev 3548)
+++ trunk/librawstudio/rs-exif.cc 2010-10-12 17:46:17 UTC (rev 3549)
@@ -23,12 +23,14 @@
#include <exiv2/exif.hpp>
#include "rs-exif.h"
#include <assert.h>
+#include "rs-library.h"
#ifndef EXIV2_TEST_VERSION
# define EXIV2_TEST_VERSION(major,minor,patch) \
( EXIV2_VERSION >= EXIV2_MAKE_VERSION((major),(minor),(patch)) )
#endif
+
extern "C" {
#include <rawstudio.h>
#include "config.h"
@@ -52,6 +54,11 @@
"Exif.Image.PlanarConfiguration",
"Exif.Image.ResolutionUnit",
+ /* Delete colorspace information - we add our own */
+ "Exif.Photo.ColorSpace",
+ "Exif.Iop.InteroperabilityIndex",
+ "Exif.Iop.InteroperabilityVersion",
+
/* Delete various MakerNote fields only applicable to the raw file */
// Nikon thumbnail data
@@ -158,7 +165,7 @@
}
void
-rs_exif_add_to_file(RS_EXIF_DATA *d, const gchar *filename)
+rs_exif_add_to_file(RS_EXIF_DATA *d, Exiv2::IptcData &iptc_data, const gchar
*filename)
{
if (!d)
return;
@@ -169,6 +176,7 @@
Exiv2::Image::AutoPtr image =
Exiv2::ImageFactory::open(filename);
image->setExifData(*data);
+ image->setIptcData(iptc_data);
image->writeMetadata();
}
catch (Exiv2::AnyError& e)
@@ -184,15 +192,108 @@
delete data;
}
+static void
+rs_add_cs_to_exif(RS_EXIF_DATA *d, const gchar *cs)
+{
+ if (!cs)
+ return;
+
+ Exiv2::ExifData *data = (Exiv2::ExifData *) d;
+
+ if (g_str_equal(cs, "RSSrgb"))
+ {
+ (*data)["Exif.Photo.ColorSpace"] = 1;
+ (*data)["Exif.Iop.InteroperabilityIndex"] = "R98";
+ (*data)["Exif.Iop.InteroperabilityVersion"] = "0100";
+ }
+ else if (g_str_equal(cs, "RSAdobeRGB"))
+ {
+ (*data)["Exif.Photo.ColorSpace"] = 65535;
+ (*data)["Exif.Iop.InteroperabilityIndex"] = "R03";
+ (*data)["Exif.Iop.InteroperabilityVersion"] = "0100";
+ }
+ else
+ (*data)["Exif.Photo.ColorSpace"] = 65535;
+}
+
+static void
+rs_add_tags_exif(RS_EXIF_DATA *d, const gchar *input_filename)
+{
+ Exiv2::ExifData *data = (Exiv2::ExifData *) d;
+ RSLibrary *lib = rs_library_get_singleton();
+ GList *tags = rs_library_photo_tags(lib, input_filename, FALSE);
+ if (!tags || g_list_length (tags) == 0)
+ return;
+
+ GString *usercomment = g_string_new("charset=\"Undefined\" ");
+ GString *xpkeyw = g_string_new("");
+ GList *c = tags;
+ do
+ {
+ g_string_append(usercomment, (gchar*)(c->data));
+ g_string_append(xpkeyw, (gchar*)(c->data));
+ if (c->next)
+ {
+ g_string_append(xpkeyw, ",");
+ g_string_append(usercomment, " ");
+ }
+ g_free(c->data);
+ } while (c = c->next);
+
+ g_list_free(tags);
+ Exiv2::CommentValue comment(usercomment->str);
+ (*data)["Exif.Photo.UserComment"] = comment;
+
+ glong items_written;
+ gunichar2 *w = g_utf8_to_utf16(xpkeyw->str, -1, NULL, &items_written,
NULL);
+ Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::unsignedByte);
+ v->read((const Exiv2::byte*)w, items_written * sizeof(gunichar2),
Exiv2::invalidByteOrder);
+ Exiv2::ExifKey key = Exiv2::ExifKey("Exif.Image.XPKeywords");
+ data->add(key, v.get());
+
+ g_free(w);
+ g_string_free(usercomment, TRUE);
+ g_string_free(xpkeyw, TRUE);
+}
+
+static void
+rs_add_tags_iptc(Exiv2::IptcData &iptc_data, const gchar *input_filename,
uint16_t format)
+{
+ RSLibrary *lib = rs_library_get_singleton();
+ GList *tags = rs_library_photo_tags(lib, input_filename, FALSE);
+ if (!tags || g_list_length(tags) == 0)
+ return;
+
+ do
+ {
+ Exiv2::StringValue *v = new
Exiv2::StringValue((char*)tags->data);
+ iptc_data.add(Exiv2::IptcKey("Iptc.Application2.Keywords"), v);
+ delete v;
+ g_free(tags->data);
+ } while (tags = tags->next);
+
+ iptc_data["Iptc.Envelope.CharacterSet"] = "UTF-8";
+ iptc_data["Iptc.Application2.Program"] = "Rawstudio";
+ iptc_data["Iptc.Application2.ProgramVersion"] = VERSION;
+ iptc_data["Iptc.Envelope.ModelVersion"] = 42;
+ iptc_data["Iptc.Envelope.FileFormat"] = format;
+}
+
gboolean
-rs_exif_copy(const gchar *input_filename, const gchar *output_filename)
+rs_exif_copy(const gchar *input_filename, const gchar *output_filename, const
gchar *color_space)
{
if (input_filename && output_filename)
{
RS_EXIF_DATA *exif;
-
+ Exiv2::IptcData iptc_data;
exif = rs_exif_load_from_file(input_filename);
- rs_exif_add_to_file(exif, output_filename);
+ rs_add_cs_to_exif(exif, cs);
+ rs_add_tags_exif(exif, input_filename);
+ if (g_str_has_suffix(output_filename, "jpg"))
+ rs_add_tags_iptc(iptc_data, input_filename, 11);
+ if (g_str_has_suffix(output_filename, "tiff") ||
g_str_has_suffix(output_filename, "tif"))
+ rs_add_tags_iptc(iptc_data, input_filename, 3);
+ rs_exif_add_to_file(exif, iptc_data, output_filename);
rs_exif_free(exif);
}
}
Modified: trunk/librawstudio/rs-exif.h
===================================================================
--- trunk/librawstudio/rs-exif.h 2010-10-12 17:39:58 UTC (rev 3548)
+++ trunk/librawstudio/rs-exif.h 2010-10-12 17:46:17 UTC (rev 3549)
@@ -28,12 +28,13 @@
#include <rawstudio.h>
typedef void RS_EXIF_DATA;
+typedef void RS_IPTC_DATA;
extern RS_EXIF_DATA *rs_exif_load_from_file(const gchar *);
extern RS_EXIF_DATA *rs_exif_load_from_rawfile(RAWFILE *rawfile);
extern void rs_exif_add_to_file(RS_EXIF_DATA *d, const gchar *filename);
extern void rs_exif_free(RS_EXIF_DATA *d);
-extern gboolean rs_exif_copy(const gchar *input_filename, const gchar
*output_filename);
+extern gboolean rs_exif_copy(const gchar *input_filename, const gchar
*output_filename, const gchar *color_space);
#ifdef __cplusplus
}
Modified: trunk/plugins/output-jpegfile/output-jpegfile.c
===================================================================
--- trunk/plugins/output-jpegfile/output-jpegfile.c 2010-10-12 17:39:58 UTC
(rev 3548)
+++ trunk/plugins/output-jpegfile/output-jpegfile.c 2010-10-12 17:46:17 UTC
(rev 3549)
@@ -278,7 +278,7 @@
gchar *input_filename = NULL;
rs_filter_get_recursive(filter, "filename", &input_filename, NULL);
- rs_exif_copy(input_filename, jpegfile->filename);
+ rs_exif_copy(input_filename, jpegfile->filename,
G_OBJECT_TYPE_NAME(jpegfile->color_space));
g_free(input_filename);
return(TRUE);
Modified: trunk/plugins/output-pngfile/output-pngfile.c
===================================================================
--- trunk/plugins/output-pngfile/output-pngfile.c 2010-10-12 17:39:58 UTC
(rev 3548)
+++ trunk/plugins/output-pngfile/output-pngfile.c 2010-10-12 17:46:17 UTC
(rev 3549)
@@ -260,7 +260,7 @@
gchar *input_filename = NULL;
rs_filter_get_recursive(filter, "filename", &input_filename, NULL);
- rs_exif_copy(input_filename, pngfile->filename);
+ rs_exif_copy(input_filename, pngfile->filename,
G_OBJECT_TYPE_NAME(pngfile->color_space));
g_free(input_filename);
return TRUE;
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit