The attached patch adds support for copying exif data to the jpg.

It is very basic. Things that still have to be done:

*) Implement a white list of tags to copy (or a black list)
*) There is some redundant code now, as rawstudio was already able to
parse some exif
*) Don't open the input and output file twice :-)

Cheers,
Rafael
Index: configure.in
===================================================================
--- configure.in	(revision 1849)
+++ configure.in	(working copy)
@@ -54,7 +54,8 @@
 fi
 AC_SUBST(LIBTIFF)
 
-pkg_modules="gtk+-2.0 >= 2.8.0 libxml-2.0 >= 2.4 gconf-2.0 >= 2.0 lcms dbus-1"
+pkg_modules="gtk+-2.0 >= 2.8.0 libxml-2.0 >= 2.4 gconf-2.0 >= 2.0 lcms dbus-1 \	
+		      exiv2"
 PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
 AC_SUBST(PACKAGE_CFLAGS)
 AC_SUBST(PACKAGE_LIBS)
Index: src/exif.cc
===================================================================
--- src/exif.cc	(revision 0)
+++ src/exif.cc	(revision 0)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2006-2008 Anders Brander <[EMAIL PROTECTED]> and 
+ * Anders Kvist <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include <iostream>
+#include <iomanip>
+#include <exiv2/image.hpp>
+#include <exiv2/exif.hpp>
+#include "exif.h"
+#include <assert.h>
+
+extern "C" {
+
+rs_exif_data rs_exif_load(const gchar *filename)
+{
+	Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
+	assert(image.get() != 0);
+	image->readMetadata();
+
+	return new Exiv2::ExifData(image->exifData());
+}
+
+void rs_add_exif(const gchar *filename, rs_exif_data d)
+{
+	Exiv2::ExifData *data = (Exiv2::ExifData *) d;
+	Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
+	image->setExifData(*data);
+	image->writeMetadata();
+}
+
+void rs_exif_free(rs_exif_data d)
+{
+	Exiv2::ExifData *data = (Exiv2::ExifData *) d;
+	delete data;
+}
+
+}
Index: src/exif.h
===================================================================
--- src/exif.h	(revision 0)
+++ src/exif.h	(revision 0)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2006-2008 Anders Brander <[EMAIL PROTECTED]> and 
+ * Anders Kvist <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef EXIF_H
+#define EXIF_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+#include <glib.h>
+
+typedef void* rs_exif_data;
+
+rs_exif_data rs_exif_load(const gchar *);
+void rs_add_exif(const gchar *filename, rs_exif_data);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
Index: src/rawstudio.c
===================================================================
--- src/rawstudio.c	(revision 1849)
+++ src/rawstudio.c	(working copy)
@@ -449,6 +449,7 @@
 		metadata->cam_mul[i] = 1.0f;
 	matrix4_identity(&metadata->adobe_coeff);
 	metadata->data = NULL;
+	metadata->exif = NULL;
 	return(metadata);
 }
 
@@ -459,6 +460,8 @@
 		g_free(metadata->make_ascii);
 	if (metadata->model_ascii)
 		g_free(metadata->model_ascii);
+	if (metadata->exif)
+		rs_exif_free(metadata->exif);
 	g_free(metadata);
 	return;
 }
@@ -489,6 +492,7 @@
 	gboolean uncompressed_tiff = FALSE;
 	RS_COLOR_TRANSFORM *rct;
 	void *transform = NULL;
+	rs_exif_data exif = photo->metadata->exif;
 
 	g_assert(RS_IS_PHOTO(photo));
 	g_assert(filename != NULL);
@@ -528,7 +532,9 @@
 			else if (quality < 0)
 				quality = 0;
 
-			rs_jpeg_save(pixbuf, filename, quality, rs_cms_get_profile_filename(cms, PROFILE_EXPORT));
+			rs_jpeg_save(pixbuf, filename, quality,
+				     rs_cms_get_profile_filename(cms, PROFILE_EXPORT),
+				     exif);
 			g_object_unref(pixbuf);
 			break;
 		case FILETYPE_PNG:
Index: src/rawstudio.h
===================================================================
--- src/rawstudio.h	(revision 1849)
+++ src/rawstudio.h	(working copy)
@@ -25,6 +25,7 @@
 #include "dcraw_api.h"
 #include "rs-arch.h"
 #include "rs-cms.h"
+#include "exif.h"
 
 #define BUH printf("%s:%d\n", __FILE__, __LINE__);
 
@@ -191,6 +192,7 @@
 	gshort focallength;
 	RS_MATRIX4 adobe_coeff;
 	gpointer data;
+	rs_exif_data exif;
 } RS_METADATA;
 
 typedef struct _photo {
Index: src/rs-jpeg.c
===================================================================
--- src/rs-jpeg.c	(revision 1849)
+++ src/rs-jpeg.c	(working copy)
@@ -77,7 +77,7 @@
 
 gboolean
 rs_jpeg_save(GdkPixbuf *pixbuf, const gchar *filename, const gint quality,
-	const gchar *profile_filename)
+	     const gchar *profile_filename, rs_exif_data exif)
 {
 	struct jpeg_compress_struct cinfo;
 	struct jpeg_error_mgr jerr;
@@ -124,5 +124,7 @@
 	jpeg_finish_compress(&cinfo);
 	fclose(outfile);
 	jpeg_destroy_compress(&cinfo);
+
+	rs_add_exif(filename, exif);
 	return(TRUE);
 }
Index: src/rs-jpeg.h
===================================================================
--- src/rs-jpeg.h	(revision 1849)
+++ src/rs-jpeg.h	(working copy)
@@ -21,6 +21,7 @@
 #define RS_JPEG_H
 
 extern gboolean rs_jpeg_save(GdkPixbuf *pixbuf, const gchar *filename,
-	const gint quality, const gchar *profile_filename);
+			     const gint quality, const gchar *profile_filename,
+			     rs_exif_data exif);
 
 #endif
Index: src/tiff-meta.c
===================================================================
--- src/tiff-meta.c	(revision 1849)
+++ src/tiff-meta.c	(working copy)
@@ -23,6 +23,7 @@
 #include "rawfile.h"
 #include "tiff-meta.h"
 #include "adobe-coeff.h"
+#include "exif.h"
 
 /* It is required having some arbitrary maximum exposure time to prevent borked
  * shutter speed values being interpreted from the tiff.
@@ -600,6 +601,8 @@
 	adobe_coeff_set(&meta->adobe_coeff, meta->make_ascii, meta->model_ascii);
 
 	raw_close_file(rawfile);
+
+	meta->exif = rs_exif_load(filename);
 }
 
 GdkPixbuf *
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 1849)
+++ src/Makefile.am	(working copy)
@@ -48,6 +48,7 @@
 	panasonic.c panasonic.h \
 	rs-image.c rs-image.h \
 	rs-photo.c rs-photo.h \
+	exif.cc exif.h \
 	dcraw_api.cc dcraw_api.h \
 	dcraw.cc dcraw.h \
 	rs-jpeg.c rs-jpeg.h \
_______________________________________________
Rawstudio-dev mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-dev

Reply via email to