[gnome-color-manager] Use libexif to read JPG metadata
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Use libexif to read JPG metadata
- Date: Fri, 21 May 2010 10:47:44 +0000 (UTC)
commit fd09118d3400549140a71cf6f923ac794e09529c
Author: Richard Hughes <richard hughsie com>
Date: Thu May 20 23:05:49 2010 +0100
Use libexif to read JPG metadata
configure.ac | 1 +
contrib/gnome-color-manager.spec.in | 1 +
src/Makefile.am | 4 ++
src/gcm-exif.c | 99 ++++++++++++++++++++++++++++++++---
src/gcm-exif.h | 1 +
src/gcm-self-test.c | 8 ++--
6 files changed, 103 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bfa23f4..4cbdaa7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,7 @@ fi
PKG_CHECK_MODULES(CANBERRA, libcanberra-gtk >= $CANBERRA_REQUIRED)
+PKG_CHECK_MODULES(EXIF, libexif)
AC_CHECK_LIB(tiff, TIFFReadRGBAImageOriented,
TIFF_CFLAGS=""
TIFF_LIBS="-ltiff"
diff --git a/contrib/gnome-color-manager.spec.in b/contrib/gnome-color-manager.spec.in
index 62ff589..a79decd 100644
--- a/contrib/gnome-color-manager.spec.in
+++ b/contrib/gnome-color-manager.spec.in
@@ -39,6 +39,7 @@ BuildRequires: lcms-devel
BuildRequires: cups-devel
BuildRequires: sane-backends-devel
BuildRequires: libtiff-devel
+BuildRequires: libexif-devel
BuildRequires: libcanberra-devel
BuildRequires: libnotify-devel
BuildRequires: glib2-devel >= 2.25.1
diff --git a/src/Makefile.am b/src/Makefile.am
index f50e08f..2ecd2c9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ INCLUDES = \
$(CUPS_CFLAGS) \
$(SANE_CFLAGS) \
$(TIFF_CFLAGS) \
+ $(EXIF_CFLAGS) \
$(NOTIFY_CFLAGS) \
$(CANBERRA_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
@@ -253,6 +254,7 @@ gcm_prefs_LDADD = \
$(SANE_LIBS) \
$(CUPS_LIBS) \
$(TIFF_LIBS) \
+ $(EXIF_LIBS) \
$(CANBERRA_LIBS) \
-lm
@@ -277,6 +279,7 @@ gcm_picker_LDADD = \
$(SANE_LIBS) \
$(CUPS_LIBS) \
$(TIFF_LIBS) \
+ $(EXIF_LIBS) \
$(CANBERRA_LIBS) \
-lm
@@ -330,6 +333,7 @@ gcm_self_test_LDADD = \
$(SANE_LIBS) \
$(CUPS_LIBS) \
$(TIFF_LIBS) \
+ $(EXIF_LIBS) \
-lm
gcm_self_test_CFLAGS = $(AM_CFLAGS) $(WARNINGFLAGS_C)
diff --git a/src/gcm-exif.c b/src/gcm-exif.c
index 840ec25..5745942 100644
--- a/src/gcm-exif.c
+++ b/src/gcm-exif.c
@@ -29,9 +29,9 @@
#include "config.h"
#include <glib-object.h>
-//#include <math.h>
#include <tiff.h>
#include <tiffio.h>
+#include <libexif/exif-data.h>
#include "gcm-exif.h"
@@ -64,10 +64,10 @@ enum {
G_DEFINE_TYPE (GcmExif, gcm_exif, G_TYPE_OBJECT)
/**
- * gcm_exif_parse:
+ * gcm_exif_parse_tiff:
**/
-gboolean
-gcm_exif_parse (GcmExif *exif, const gchar *filename, GError **error)
+static gboolean
+gcm_exif_parse_tiff (GcmExif *exif, const gchar *filename, GError **error)
{
gboolean ret = TRUE;
const gchar *manufacturer = NULL;
@@ -76,9 +76,6 @@ gcm_exif_parse (GcmExif *exif, const gchar *filename, GError **error)
TIFF *tiff;
GcmExifPrivate *priv = exif->priv;
- g_return_val_if_fail (GCM_IS_EXIF (exif), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
/* open file */
tiff = TIFFOpen (filename, "r");
TIFFGetField (tiff,TIFFTAG_MAKE, &manufacturer);
@@ -105,6 +102,94 @@ out:
}
/**
+ * gcm_exif_parse_jpeg:
+ **/
+static gboolean
+gcm_exif_parse_jpeg (GcmExif *exif, const gchar *filename, GError **error)
+{
+ gboolean ret = TRUE;
+ GcmExifPrivate *priv = exif->priv;
+ ExifData *ed = NULL;
+ ExifEntry *entry;
+ gchar make[1024] = { '\0' };
+ gchar model[1024] = { '\0' };
+
+ /* load EXIF file */
+ ed = exif_data_new_from_file (filename);
+ if (ed == NULL) {
+ g_set_error (error,
+ GCM_EXIF_ERROR,
+ GCM_EXIF_ERROR_NO_DATA,
+ "File not readable or no EXIF data in file");
+ ret = FALSE;
+ goto out;
+ }
+
+ /* get make */
+ entry = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_MAKE);
+ if (entry != NULL) {
+ exif_entry_get_value (entry, make, sizeof (make));
+ g_strchomp (make);
+ }
+
+ /* get model */
+ entry = exif_content_get_entry (ed->ifd[EXIF_IFD_0], EXIF_TAG_MODEL);
+ if (entry != NULL) {
+ exif_entry_get_value (entry, model, sizeof (model));
+ g_strchomp (model);
+ }
+
+ /* we failed to get data */
+ if (make == NULL || model == NULL) {
+ g_set_error (error,
+ GCM_EXIF_ERROR,
+ GCM_EXIF_ERROR_NO_DATA,
+ "failed to get EXIF data from TIFF");
+ ret = FALSE;
+ goto out;
+ }
+
+ /* create copies for ourselves */
+ priv->manufacturer = g_strdup (make);
+ priv->model = g_strdup (model);
+ priv->serial = NULL;
+out:
+ if (ed != NULL)
+ exif_data_unref (ed);
+ return ret;
+}
+
+/**
+ * gcm_exif_parse:
+ **/
+gboolean
+gcm_exif_parse (GcmExif *exif, const gchar *filename, GError **error)
+{
+ gboolean ret = FALSE;
+
+ g_return_val_if_fail (GCM_IS_EXIF (exif), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ //FIXME: get type, not extension
+ if (g_str_has_suffix (filename, "tif")) {
+ ret = gcm_exif_parse_tiff (exif, filename, error);
+ goto out;
+ }
+ if (g_str_has_suffix (filename, "jpg")) {
+ ret = gcm_exif_parse_jpeg (exif, filename, error);
+ goto out;
+ }
+
+ /* no support */
+ g_set_error (error,
+ GCM_EXIF_ERROR,
+ GCM_EXIF_ERROR_NO_SUPPORT,
+ "no support for %s filetype", filename);
+out:
+ return ret;
+}
+
+/**
* gcm_exif_get_manufacturer:
**/
const gchar *
diff --git a/src/gcm-exif.h b/src/gcm-exif.h
index 8af9908..b888ba9 100644
--- a/src/gcm-exif.h
+++ b/src/gcm-exif.h
@@ -51,6 +51,7 @@ struct _GcmExifClass
typedef enum
{
GCM_EXIF_ERROR_NO_DATA,
+ GCM_EXIF_ERROR_NO_SUPPORT,
GCM_EXIF_ERROR_INTERNAL
} GcmExifError;
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 4b82ffb..4fdaad1 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -628,8 +628,8 @@ gcm_test_exif_func (void)
g_assert_cmpstr (gcm_exif_get_manufacturer (exif), ==, "NIKON CORPORATION");
g_assert_cmpstr (gcm_exif_get_serial (exif), ==, NULL);
- /* PNG */
- filename = gcm_test_get_data_file ("test.png");
+ /* JPG */
+ filename = gcm_test_get_data_file ("test.jpg");
ret = gcm_exif_parse (exif, filename, &error);
g_free (filename);
g_assert_no_error (error);
@@ -638,8 +638,8 @@ gcm_test_exif_func (void)
g_assert_cmpstr (gcm_exif_get_manufacturer (exif), ==, "NIKON CORPORATION");
g_assert_cmpstr (gcm_exif_get_serial (exif), ==, NULL);
- /* JPG */
- filename = gcm_test_get_data_file ("test.jpg");
+ /* PNG */
+ filename = gcm_test_get_data_file ("test.png");
ret = gcm_exif_parse (exif, filename, &error);
g_free (filename);
g_assert_no_error (error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]