Changing rawstudio to use exif for things like orientation and iso
proved to be harder then I expected.
The attached patch adds only the basic functionality of copying data
from the input file to the jpeg.
Cheers,
Rafael
Index: configure.in
===================================================================
--- configure.in (revision 1850)
+++ 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 <exiv2/image.hpp>
+#include <exiv2/exif.hpp>
+#include <assert.h>
+#include "exif.h"
+
+void rs_exif_write(const gchar *filename, rs_exif_data d)
+{
+ Exiv2::ExifData *orig = (Exiv2::ExifData *) d;
+ Exiv2::ExifData data(*orig);
+ std::string s = "Exif.Image.Orientation";
+ Exiv2::ExifData::iterator pos = data.findKey(Exiv2::ExifKey(s));
+ data.erase(pos);
+
+ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
+ image->setExifData(data);
+ image->writeMetadata();
+}
+
+rs_exif_data rs_exif_load(const gchar *filename)
+{
+ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
+ assert(image.get() != 0);
+ image->readMetadata();
+
+ return (rs_exif_data) new Exiv2::ExifData(image->exifData());
+}
+
+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,39 @@
+/*
+ * 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>
+
+struct rs_exif_data_;
+typedef struct rs_exif_data_* rs_exif_data;
+
+void rs_exif_write(const gchar *filename, rs_exif_data);
+rs_exif_data rs_exif_load(const gchar *filename);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: src/gtk-interface.c
===================================================================
--- src/gtk-interface.c (revision 1850)
+++ src/gtk-interface.c (working copy)
@@ -47,6 +47,7 @@
#include "rs-external-editor.h"
#include "rs-actions.h"
#include "rs-dir-selector.h"
+#include "rawfile.h"
static gchar *filenames[] = {DEFAULT_CONF_EXPORT_FILENAME, "%f", "%f_%c", "%f_output_%4c", NULL};
static GtkStatusbar *statusbar;
@@ -198,7 +199,7 @@
if (filetype->load_meta)
{
- filetype->load_meta(name, photo->metadata);
+ rs_load_meta(filetype, name, photo->metadata);
switch (photo->metadata->orientation)
{
case 90: ORIENTATION_90(photo->orientation);
Index: src/md5.c
===================================================================
--- src/md5.c (revision 1850)
+++ src/md5.c (working copy)
@@ -85,6 +85,7 @@
#include "md5.h"
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#ifdef TEST
/*
Index: src/rawstudio.c
===================================================================
--- src/rawstudio.c (revision 1850)
+++ 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;
}
@@ -528,7 +531,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),
+ photo->metadata->exif);
g_object_unref(pixbuf);
break;
case FILETYPE_PNG:
Index: src/rs-actions.c
===================================================================
--- src/rs-actions.c (revision 1850)
+++ src/rs-actions.c (working copy)
@@ -36,6 +36,7 @@
#include "rs-cache.h"
#include "rs-preview-widget.h"
#include "rs-batch.h"
+#include "rawfile.h"
static GtkActionGroup *core_action_group = NULL;
GStaticMutex rs_actions_spinlock = G_STATIC_MUTEX_INIT;
@@ -430,7 +431,7 @@
{
if (filetype->load_meta)
{
- filetype->load_meta(photo->filename, photo->metadata);
+ rs_load_meta(filetype, photo->filename, photo->metadata);
switch (photo->metadata->orientation)
{
case 90: ORIENTATION_90(photo->orientation);
Index: src/rawstudio.h
===================================================================
--- src/rawstudio.h (revision 1850)
+++ 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-batch.c
===================================================================
--- src/rs-batch.c (revision 1850)
+++ src/rs-batch.c (working copy)
@@ -32,6 +32,7 @@
#include "rs-cache.h"
#include "rs-color-transform.h"
#include "rs-image.h"
+#include "rawfile.h"
extern GtkWindow *rawstudio_window;
@@ -489,7 +490,7 @@
if (photo)
{
if (filetype->load_meta)
- filetype->load_meta(filename_in, photo->metadata);
+ rs_load_meta(filetype, filename_in, photo->metadata);
filename = g_string_new(queue->directory);
g_string_append(filename, G_DIR_SEPARATOR_S);
g_string_append(filename, queue->filename);
Index: src/rs-jpeg.c
===================================================================
--- src/rs-jpeg.c (revision 1850)
+++ 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_exif_write(filename, exif);
return(TRUE);
}
Index: src/rs-jpeg.h
===================================================================
--- src/rs-jpeg.h (revision 1850)
+++ src/rs-jpeg.h (working copy)
@@ -19,8 +19,10 @@
#ifndef RS_JPEG_H
#define RS_JPEG_H
+#include "exif.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/rawfile.c
===================================================================
--- src/rawfile.c (revision 1850)
+++ src/rawfile.c (working copy)
@@ -30,6 +30,7 @@
#endif
#include <string.h>
#include "rawfile.h"
+#include "rawstudio.h"
struct _RAWFILE {
#ifdef G_OS_WIN32
@@ -192,6 +193,13 @@
return(pixbuf);
}
+void rs_load_meta(RS_FILETYPE *f, const gchar *filename, RS_METADATA *meta)
+{
+ assert (f->load_meta);
+ f->load_meta(filename, meta);
+ meta->exif = rs_exif_load(filename);
+}
+
RAWFILE *
raw_open_file(const gchar *filename)
{
Index: src/rawfile.h
===================================================================
--- src/rawfile.h (revision 1850)
+++ src/rawfile.h (working copy)
@@ -16,6 +16,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
+#include "rawstudio.h"
#define ENDIANSWAP4(a) (((a) & 0x000000FF) << 24 | ((a) & 0x0000FF00) << 8 | ((a) & 0x00FF0000) >> 8) | (((a) & 0xFF000000) >> 24)
#define ENDIANSWAP2(a) (((a) & 0x00FF) << 8) | (((a) & 0xFF00) >> 8)
@@ -43,3 +45,4 @@
guint get_first_ifd_offset(RAWFILE *rawfile);
void *raw_get_map(RAWFILE *rawfile);
guint raw_get_filesize(RAWFILE *rawfile);
+void rs_load_meta(RS_FILETYPE *f, const gchar *filename, RS_METADATA *meta);
Index: src/Makefile.am
===================================================================
--- src/Makefile.am (revision 1850)
+++ src/Makefile.am (working copy)
@@ -8,6 +8,7 @@
AM_CFLAGS =\
-Wall\
-O4\
+ -Werror\
-DWITH_GCONF\
-DDCRAW_NOMAIN\
-DDCRAW_NOLCMS\
@@ -48,6 +49,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