Author: post
Date: 2011-02-19 20:14:55 +0100 (Sat, 19 Feb 2011)
New Revision: 3821

Added:
   trunk/plugins/meta-exiv2/
   trunk/plugins/meta-exiv2/Makefile.am
   trunk/plugins/meta-exiv2/exiv2-meta.c
   trunk/plugins/meta-exiv2/exiv2-metadata.cpp
   trunk/plugins/meta-exiv2/exiv2-metadata.h
Modified:
   trunk/configure.in
   trunk/librawstudio/rs-metadata.c
   trunk/plugins/Makefile.am
   trunk/plugins/load-gdk/load-gdk.c
Log:
Add support for loading metadata from JPG, PNG and TIFF files.

Modified: trunk/configure.in
===================================================================
--- trunk/configure.in  2011-02-19 17:50:20 UTC (rev 3820)
+++ trunk/configure.in  2011-02-19 19:14:55 UTC (rev 3821)
@@ -180,6 +180,7 @@
 plugins/load-gdk/Makefile
 plugins/load-rawspeed/Makefile
 plugins/meta-ciff/Makefile
+plugins/meta-exiv2/Makefile
 plugins/meta-mrw/Makefile
 plugins/meta-raf/Makefile
 plugins/meta-tiff/Makefile

Modified: trunk/librawstudio/rs-metadata.c
===================================================================
--- trunk/librawstudio/rs-metadata.c    2011-02-19 17:50:20 UTC (rev 3820)
+++ trunk/librawstudio/rs-metadata.c    2011-02-19 19:14:55 UTC (rev 3821)
@@ -116,7 +116,7 @@
        return g_object_new (RS_TYPE_METADATA, NULL);
 }
 
-#define METACACHEVERSION 6
+#define METACACHEVERSION 7
 void
 rs_metadata_cache_save(RSMetadata *metadata, const gchar *filename)
 {

Modified: trunk/plugins/Makefile.am
===================================================================
--- trunk/plugins/Makefile.am   2011-02-19 17:50:20 UTC (rev 3820)
+++ trunk/plugins/Makefile.am   2011-02-19 19:14:55 UTC (rev 3821)
@@ -17,6 +17,7 @@
        load-gdk \
        load-rawspeed \
        meta-ciff \
+       meta-exiv2 \
        meta-mrw \
        meta-raf \
        meta-tiff \

Modified: trunk/plugins/load-gdk/load-gdk.c
===================================================================
--- trunk/plugins/load-gdk/load-gdk.c   2011-02-19 17:50:20 UTC (rev 3820)
+++ trunk/plugins/load-gdk/load-gdk.c   2011-02-19 19:14:55 UTC (rev 3821)
@@ -75,12 +75,12 @@
        return response;
 }
 
-/* We don't load actual metadata, but we will keep this as a low priority 
fallback */
+/* We don't load actual metadata, but we will load thumbnail and return FALSE 
to pass these on */
 static gboolean
 rs_gdk_load_meta(const gchar *service, RAWFILE *rawfile, guint offset, 
RSMetadata *meta)
 {
        meta->thumbnail = gdk_pixbuf_new_from_file_at_size(service, 128, 128, 
NULL);
-       return TRUE;
+       return FALSE;
 }
 
 G_MODULE_EXPORT void
@@ -104,9 +104,9 @@
        rs_filetype_register_loader(".tiff", "JPEG", load_gdk, 20, 
RS_LOADER_FLAGS_8BIT);
 
        /* Take care of thumbnailing too */
-       rs_filetype_register_meta_loader(".jpg", "Sigma", rs_gdk_load_meta, 10, 
RS_LOADER_FLAGS_8BIT);
-       rs_filetype_register_meta_loader(".jpeg", "Sigma", rs_gdk_load_meta, 
10, RS_LOADER_FLAGS_8BIT);
-       rs_filetype_register_meta_loader(".png", "Sigma", rs_gdk_load_meta, 10, 
RS_LOADER_FLAGS_8BIT);
-       rs_filetype_register_meta_loader(".tif", "Sigma", rs_gdk_load_meta, 20, 
RS_LOADER_FLAGS_8BIT);
-       rs_filetype_register_meta_loader(".tiff", "Sigma", rs_gdk_load_meta, 
20, RS_LOADER_FLAGS_8BIT);
+       rs_filetype_register_meta_loader(".jpg", "JPEG", rs_gdk_load_meta, 10, 
RS_LOADER_FLAGS_8BIT);
+       rs_filetype_register_meta_loader(".jpeg", "JPEG", rs_gdk_load_meta, 10, 
RS_LOADER_FLAGS_8BIT);
+       rs_filetype_register_meta_loader(".png", "PNG", rs_gdk_load_meta, 10, 
RS_LOADER_FLAGS_8BIT);
+       rs_filetype_register_meta_loader(".tif", "TIFF", rs_gdk_load_meta, 20, 
RS_LOADER_FLAGS_8BIT);
+       rs_filetype_register_meta_loader(".tiff", "TIFF", rs_gdk_load_meta, 20, 
RS_LOADER_FLAGS_8BIT);
 }

Added: trunk/plugins/meta-exiv2/Makefile.am
===================================================================
--- trunk/plugins/meta-exiv2/Makefile.am                                (rev 0)
+++ trunk/plugins/meta-exiv2/Makefile.am        2011-02-19 19:14:55 UTC (rev 
3821)
@@ -0,0 +1,22 @@
+plugindir = $(libdir)/rawstudio/plugins
+
+AM_CFLAGS =\
+       -Wall\
+       -O4
+
+AM_CXXFLAGS = $(AM_CFLAGS)
+
+INCLUDES = \
+       -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+       -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+       @PACKAGE_CFLAGS@ \
+       -I$(top_srcdir)/librawstudio/ \
+       -I$(top_srcdir)/
+
+lib_LTLIBRARIES = meta_exiv2.la
+
+libdir = $(datadir)/rawstudio/plugins/
+
+meta_exiv2_la_LIBADD = @PACKAGE_LIBS@
+meta_exiv2_la_LDFLAGS = -module -avoid-version
+meta_exiv2_la_SOURCES =  exiv2-meta.c exiv2-metadata.cpp

Added: trunk/plugins/meta-exiv2/exiv2-meta.c
===================================================================
--- trunk/plugins/meta-exiv2/exiv2-meta.c                               (rev 0)
+++ trunk/plugins/meta-exiv2/exiv2-meta.c       2011-02-19 19:14:55 UTC (rev 
3821)
@@ -0,0 +1,37 @@
+/*
+ * * Copyright (C) 2006-2011 Anders Brander <[email protected]>, 
+ * * Anders Kvist <[email protected]> and Klaus Post <[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 <rawstudio.h>
+#include "exiv2-metadata.h"
+
+static gboolean
+exiv2_load_meta(const gchar *service, RAWFILE *rawfile, guint offset, 
RSMetadata *meta)
+{
+  return exiv2_load_meta_interface(service, rawfile, offset, meta);
+}
+
+G_MODULE_EXPORT void
+rs_plugin_load(RSPlugin *plugin)
+{
+       rs_filetype_register_meta_loader(".jpg", "8 bit JPEG File", 
exiv2_load_meta, 100, RS_LOADER_FLAGS_RAW);
+       rs_filetype_register_meta_loader(".jpeg", "8 bit JPEG File", 
exiv2_load_meta, 100, RS_LOADER_FLAGS_RAW);
+       rs_filetype_register_meta_loader(".png", "PNG File", exiv2_load_meta, 
100, RS_LOADER_FLAGS_RAW);
+       rs_filetype_register_meta_loader(".tiff", "TIFF File", exiv2_load_meta, 
100, RS_LOADER_FLAGS_RAW);
+       rs_filetype_register_meta_loader(".tif", "TIFF File", exiv2_load_meta, 
100, RS_LOADER_FLAGS_RAW);
+}

Added: trunk/plugins/meta-exiv2/exiv2-metadata.cpp
===================================================================
--- trunk/plugins/meta-exiv2/exiv2-metadata.cpp                         (rev 0)
+++ trunk/plugins/meta-exiv2/exiv2-metadata.cpp 2011-02-19 19:14:55 UTC (rev 
3821)
@@ -0,0 +1,184 @@
+/*
+ * * Copyright (C) 2006-2011 Anders Brander <[email protected]>, 
+ * * Anders Kvist <[email protected]> and Klaus Post <[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 <gtk/gtk.h>
+#include <iostream>
+#include <iomanip>
+#include <exiv2/image.hpp>
+#include <exiv2/exif.hpp>
+#include <exiv2/easyaccess.hpp>
+#include <assert.h>
+#include "exiv2-metadata.h"
+#include <math.h>
+
+#ifndef EXIV2_TEST_VERSION
+# define EXIV2_TEST_VERSION(major,minor,patch) \
+       ( EXIV2_VERSION >= EXIV2_MAKE_VERSION((major),(minor),(patch)) )
+#endif
+
+#if EXIV2_TEST_VERSION(0,17,0)
+#include <exiv2/convert.hpp>
+#endif
+
+extern "C" {
+
+/** INTERFACE **/
+
+using namespace Exiv2;
+
+static void 
+set_metadata_maker(std::string maker, RSMetadata *meta)
+{
+       meta->make_ascii = rs_remove_tailing_spaces(g_strdup(maker.c_str()), 
TRUE);
+       
+       if (g_ascii_strncasecmp(meta->make_ascii, "Canon",5))
+               meta->make = MAKE_CANON;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "CASIO", 5))
+               meta->make = MAKE_CASIO;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Hasselblad", 10))
+               meta->make = MAKE_HASSELBLAD;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "KODAK", 5))
+               meta->make = MAKE_KODAK;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "EASTMAN KODAK", 
13))
+               meta->make = MAKE_KODAK;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Leica", 5))
+               meta->make = MAKE_LEICA;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Minolta", 7))
+               meta->make = MAKE_MINOLTA;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "KONICA MINOLTA", 
14))
+               meta->make = MAKE_MINOLTA;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Mamiya", 6))
+               meta->make = MAKE_MAMIYA;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "NIKON", 5))
+               meta->make = MAKE_NIKON;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "OLYMPUS", 7))
+               meta->make = MAKE_OLYMPUS;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Panasonic", 9))
+               meta->make = MAKE_PANASONIC;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "PENTAX", 6))
+               meta->make = MAKE_PENTAX;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Phase One", 9))
+               meta->make = MAKE_PHASEONE;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "Ricoh", 5))
+               meta->make = MAKE_RICOH;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "SAMSUNG", 7))
+               meta->make = MAKE_SAMSUNG;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "SONY", 7))
+               meta->make = MAKE_SONY;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "FUJIFILM", 4))
+               meta->make = MAKE_FUJIFILM;
+       else if (0 == g_ascii_strncasecmp(meta->make_ascii, "SEIKO EPSON", 11))
+               meta->make = MAKE_EPSON;
+}
+
+gboolean
+exiv2_load_meta_interface(const gchar *service, RAWFILE *rawfile, guint 
offset, RSMetadata *meta)
+{
+       try {
+               Image::AutoPtr img = 
ImageFactory::open((byte*)raw_get_map(rawfile), raw_get_filesize(rawfile));
+               img->readMetadata();
+               XmpData &xmpData = img->xmpData();
+               ExifData &exifData = img->exifData();
+
+               /* We perfer XMP data, so copy it to EXIF */
+               if (!xmpData.empty())
+                       copyXmpToExif(xmpData, exifData);
+
+               /* Parse Exif Data */
+               if (!exifData.empty())
+               {
+                       ExifData::const_iterator i;
+                       i = exifData.findKey(ExifKey("Exif.Image.Make"));
+                       if (i != exifData.end())
+                               set_metadata_maker(i->toString(), meta);
+                       
+                       i = exifData.findKey(ExifKey("Exif.Image.Model"));
+                       if (i != exifData.end())
+                               meta->model_ascii = 
g_strdup(i->toString().c_str());
+
+                       i = orientation(exifData);
+                       if (i != exifData.end())
+                       {
+                               switch (i->getValue()->toLong())
+                               {
+                                               case 6: meta->orientation = 90;
+                                                       break;
+                                               case 8: meta->orientation = 270;
+                                                       break;
+                               }
+                       }
+
+                       i = 
exifData.findKey(ExifKey("Exif.Image.DateTimeOriginal"));
+                       if (i == exifData.end())
+                               i = 
exifData.findKey(ExifKey("Exif.Image.DateTime"));
+                       if (i != exifData.end())
+                       {
+                               meta->time_ascii = 
g_strdup(i->toString().c_str());
+                               meta->timestamp = 
rs_exiftime_to_unixtime(meta->time_ascii);
+                       }
+
+                       i = 
exifData.findKey(ExifKey("Exif.Image.ExposureTime"));
+                       if (i == exifData.end())
+                               i = 
exifData.findKey(ExifKey("Exif.Photo.ExposureTime"));
+                       if (i != exifData.end())
+                               meta->shutterspeed = 1.0 / 
i->getValue()->toFloat();
+                       else
+                       {
+                               i = 
exifData.findKey(ExifKey("Exif.Image.ShutterSpeedValue"));
+                               if (i == exifData.end())
+                                       i = 
exifData.findKey(ExifKey("Exif.Photo.ShutterSpeedValue"));
+                               if (i != exifData.end())
+                                       meta->shutterspeed = 1.0 / i->toFloat();
+                       }
+
+                       i = exifData.findKey(ExifKey("Exif.Image.FNumber"));
+                       if (i == exifData.end())
+                               i = 
exifData.findKey(ExifKey("Exif.Photo.FNumber"));
+                       if (i == exifData.end())
+                               i = 
exifData.findKey(ExifKey("Exif.Image.ApertureValue"));
+                       if (i == exifData.end())
+                               i = 
exifData.findKey(ExifKey("Exif.Photo.ApertureValue"));
+                       if (i != exifData.end())
+                               meta->aperture = i->toFloat();
+
+                       i = exifData.findKey(ExifKey("Exif.Image.FocalLength"));
+                       if (i == exifData.end())
+                               i = 
exifData.findKey(ExifKey("Exif.Photo.FocalLength"));
+                       if (i != exifData.end())
+                               meta->focallength = i->toFloat()-0.01;
+
+                       i = isoSpeed(exifData);
+                       if (i != exifData.end())
+                               meta->iso = i->toLong();
+
+                       /* Text based Lens Identifier */
+                       i = lensName(exifData);
+                       if (i != exifData.end())
+                               meta->fixed_lens_identifier = 
g_strdup(i->toString().c_str());
+
+                       /* TODO: Add min/max focal on supported cameras */
+                       return TRUE;
+               }
+       } catch (Exiv2::Error& e) {
+    g_debug("Exiv2 Metadata Loader:'%s'", e.what());
+       }
+       return FALSE;
+}
+/** END INTERFACE **/
+} // extern "C"

Added: trunk/plugins/meta-exiv2/exiv2-metadata.h
===================================================================
--- trunk/plugins/meta-exiv2/exiv2-metadata.h                           (rev 0)
+++ trunk/plugins/meta-exiv2/exiv2-metadata.h   2011-02-19 19:14:55 UTC (rev 
3821)
@@ -0,0 +1,44 @@
+/*
+ * * Copyright (C) 2006-2011 Anders Brander <[email protected]>, 
+ * * Anders Kvist <[email protected]> and Klaus Post <[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 exiv2_metadata_h__
+#define exiv2_metadata_h__
+#include <rawstudio.h>
+
+#ifdef _unix_
+G_BEGIN_DECLS
+#endif
+
+#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
+extern "C" {
+#endif
+
+extern gboolean
+exiv2_load_meta_interface(const gchar *service, RAWFILE *rawfile, guint 
offset, RSMetadata *meta);
+
+
+#ifdef _unix_
+G_END_DECLS
+#endif
+#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
+}
+#endif
+
+
+#endif // exiv2_metadata_h__


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to