[gnome-color-manager] Centralize all the EXIF data reading into GcmExif
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Centralize all the EXIF data reading into GcmExif
- Date: Fri, 21 May 2010 10:47:39 +0000 (UTC)
commit 26d613582e780ca8b3ed99b9f0d641f41ee37205
Author: Richard Hughes <richard hughsie com>
Date: Thu May 20 13:43:57 2010 +0100
Centralize all the EXIF data reading into GcmExif
data/tests/Makefile.am | 3 +
data/tests/test.jpg | Bin 0 -> 13863 bytes
data/tests/test.png | Bin 0 -> 27598 bytes
src/Makefile.am | 2 +
src/gcm-calibrate.c | 38 +++----
src/gcm-exif.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gcm-exif.h | 73 ++++++++++++++
src/gcm-self-test.c | 46 +++++++++
8 files changed, 396 insertions(+), 22 deletions(-)
---
diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am
index 8373822..a745113 100644
--- a/data/tests/Makefile.am
+++ b/data/tests/Makefile.am
@@ -1,4 +1,7 @@
TEST_FILES = \
+ test.tif \
+ test.png \
+ test.jpg \
cie-widget.png \
gamma-widget.png \
ibm-t61.icc \
diff --git a/data/tests/test.jpg b/data/tests/test.jpg
new file mode 100644
index 0000000..2e24ec1
Binary files /dev/null and b/data/tests/test.jpg differ
diff --git a/data/tests/test.png b/data/tests/test.png
new file mode 100644
index 0000000..c17bec6
Binary files /dev/null and b/data/tests/test.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
index d0ad5af..f50e08f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,8 @@ libgcmshared_a_SOURCES = \
gcm-screen.h \
gcm-xyz.c \
gcm-xyz.h \
+ gcm-exif.c \
+ gcm-exif.h \
gcm-print.c \
gcm-print.h \
gcm-utils.c \
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index e81891d..2427f65 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -30,8 +30,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <tiff.h>
-#include <tiffio.h>
#include "gcm-calibrate.h"
#include "gcm-xyz.h"
@@ -41,6 +39,7 @@
#include "gcm-brightness.h"
#include "gcm-colorimeter.h"
#include "gcm-calibrate-dialog.h"
+#include "gcm-exif.h"
#include "egg-debug.h"
@@ -335,28 +334,23 @@ out:
gboolean
gcm_calibrate_set_from_exif (GcmCalibrate *calibrate, const gchar *filename, GError **error)
{
- const gchar *manufacturer = NULL;
- const gchar *model = NULL;
+ const gchar *manufacturer;
+ const gchar *model;
+ const gchar *serial;
gchar *description = NULL;
- const gchar *serial = NULL;
- TIFF *tiff;
- gboolean ret = TRUE;
+ gboolean ret;
+ GcmExif *exif;
- /* open file */
- tiff = TIFFOpen (filename, "r");
- TIFFGetField (tiff,TIFFTAG_MAKE, &manufacturer);
- TIFFGetField (tiff,TIFFTAG_MODEL, &model);
- TIFFGetField (tiff,TIFFTAG_CAMERASERIALNUMBER, &serial);
-
- /* we failed to get data */
- if (manufacturer == NULL || model == NULL) {
- g_set_error (error,
- GCM_CALIBRATE_ERROR,
- GCM_CALIBRATE_ERROR_NO_DATA,
- "failed to get EXIF data from TIFF");
- ret = FALSE;
+ /* parse file */
+ exif = gcm_exif_new ();
+ ret = gcm_exif_parse (exif, filename, error);
+ if (!ret)
goto out;
- }
+
+ /* get data */
+ manufacturer = gcm_exif_get_manufacturer (exif);
+ model = gcm_exif_get_model (exif);
+ serial = gcm_exif_get_serial (exif);
/* do the best we can */
description = g_strdup_printf ("%s - %s", manufacturer, model);
@@ -372,8 +366,8 @@ gcm_calibrate_set_from_exif (GcmCalibrate *calibrate, const gchar *filename, GEr
g_object_set (calibrate, "serial", serial, NULL);
out:
+ g_object_unref (exif);
g_free (description);
- TIFFClose (tiff);
return ret;
}
diff --git a/src/gcm-exif.c b/src/gcm-exif.c
new file mode 100644
index 0000000..840ec25
--- /dev/null
+++ b/src/gcm-exif.c
@@ -0,0 +1,256 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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.
+ */
+
+/**
+ * SECTION:gcm-exif
+ * @short_description: EXIF metadata object
+ *
+ * This object represents a a file wih EXIF data.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+//#include <math.h>
+#include <tiff.h>
+#include <tiffio.h>
+
+#include "gcm-exif.h"
+
+#include "egg-debug.h"
+
+static void gcm_exif_finalize (GObject *object);
+
+#define GCM_EXIF_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_EXIF, GcmExifPrivate))
+
+/**
+ * GcmExifPrivate:
+ *
+ * Private #GcmExif data
+ **/
+struct _GcmExifPrivate
+{
+ gchar *manufacturer;
+ gchar *model;
+ gchar *serial;
+};
+
+enum {
+ PROP_0,
+ PROP_MANUFACTURER,
+ PROP_MODEL,
+ PROP_SERIAL,
+ PROP_LAST
+};
+
+G_DEFINE_TYPE (GcmExif, gcm_exif, G_TYPE_OBJECT)
+
+/**
+ * gcm_exif_parse:
+ **/
+gboolean
+gcm_exif_parse (GcmExif *exif, const gchar *filename, GError **error)
+{
+ gboolean ret = TRUE;
+ const gchar *manufacturer = NULL;
+ const gchar *model = NULL;
+ const gchar *serial = NULL;
+ 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);
+ TIFFGetField (tiff,TIFFTAG_MODEL, &model);
+ TIFFGetField (tiff,TIFFTAG_CAMERASERIALNUMBER, &serial);
+
+ /* we failed to get data */
+ if (manufacturer == 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 (manufacturer);
+ priv->model = g_strdup (model);
+ priv->serial = g_strdup (serial);
+out:
+ TIFFClose (tiff);
+ return ret;
+}
+
+/**
+ * gcm_exif_get_manufacturer:
+ **/
+const gchar *
+gcm_exif_get_manufacturer (GcmExif *exif)
+{
+ g_return_val_if_fail (GCM_IS_EXIF (exif), NULL);
+ return exif->priv->manufacturer;
+}
+
+/**
+ * gcm_exif_get_model:
+ **/
+const gchar *
+gcm_exif_get_model (GcmExif *exif)
+{
+ g_return_val_if_fail (GCM_IS_EXIF (exif), NULL);
+ return exif->priv->model;
+}
+
+/**
+ * gcm_exif_get_serial:
+ **/
+const gchar *
+gcm_exif_get_serial (GcmExif *exif)
+{
+ g_return_val_if_fail (GCM_IS_EXIF (exif), NULL);
+ return exif->priv->serial;
+}
+
+/**
+ * gcm_exif_get_property:
+ **/
+static void
+gcm_exif_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GcmExif *exif = GCM_EXIF (object);
+ GcmExifPrivate *priv = exif->priv;
+
+ switch (prop_id) {
+ case PROP_MANUFACTURER:
+ g_value_set_string (value, priv->manufacturer);
+ break;
+ case PROP_MODEL:
+ g_value_set_string (value, priv->model);
+ break;
+ case PROP_SERIAL:
+ g_value_set_string (value, priv->serial);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+#if 0
+/**
+ * gcm_exif_set_property:
+ **/
+static void
+gcm_exif_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+#endif
+
+/**
+ * gcm_exif_class_init:
+ **/
+static void
+gcm_exif_class_init (GcmExifClass *klass)
+{
+ GParamSpec *pspec;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gcm_exif_finalize;
+ object_class->get_property = gcm_exif_get_property;
+// object_class->set_property = gcm_exif_set_property;
+
+ /**
+ * GcmExif:manufacturer:
+ */
+ pspec = g_param_spec_string ("manufacturer", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_MANUFACTURER, pspec);
+
+ /**
+ * GcmExif:model:
+ */
+ pspec = g_param_spec_string ("model", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_MODEL, pspec);
+
+ /**
+ * GcmExif:serial:
+ */
+ pspec = g_param_spec_string ("serial", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_SERIAL, pspec);
+
+ g_type_class_add_private (klass, sizeof (GcmExifPrivate));
+}
+
+/**
+ * gcm_exif_init:
+ **/
+static void
+gcm_exif_init (GcmExif *exif)
+{
+ exif->priv = GCM_EXIF_GET_PRIVATE (exif);
+ exif->priv->manufacturer = NULL;
+ exif->priv->model = NULL;
+ exif->priv->serial = NULL;
+}
+
+/**
+ * gcm_exif_finalize:
+ **/
+static void
+gcm_exif_finalize (GObject *object)
+{
+ GcmExif *exif = GCM_EXIF (object);
+ GcmExifPrivate *priv = exif->priv;
+
+ g_free (priv->manufacturer);
+ g_free (priv->model);
+ g_free (priv->serial);
+
+ G_OBJECT_CLASS (gcm_exif_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_exif_new:
+ *
+ * Return value: a new GcmExif object.
+ **/
+GcmExif *
+gcm_exif_new (void)
+{
+ GcmExif *exif;
+ exif = g_object_new (GCM_TYPE_EXIF, NULL);
+ return GCM_EXIF (exif);
+}
+
diff --git a/src/gcm-exif.h b/src/gcm-exif.h
new file mode 100644
index 0000000..8af9908
--- /dev/null
+++ b/src/gcm-exif.h
@@ -0,0 +1,73 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 __GCM_EXIF_H
+#define __GCM_EXIF_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_EXIF (gcm_exif_get_type ())
+#define GCM_EXIF(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_EXIF, GcmExif))
+#define GCM_EXIF_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_EXIF, GcmExifClass))
+#define GCM_IS_EXIF(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_EXIF))
+#define GCM_IS_EXIF_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_EXIF))
+#define GCM_EXIF_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_EXIF, GcmExifClass))
+
+typedef struct _GcmExifPrivate GcmExifPrivate;
+typedef struct _GcmExif GcmExif;
+typedef struct _GcmExifClass GcmExifClass;
+
+struct _GcmExif
+{
+ GObject parent;
+ GcmExifPrivate *priv;
+};
+
+struct _GcmExifClass
+{
+ GObjectClass parent_class;
+};
+
+typedef enum
+{
+ GCM_EXIF_ERROR_NO_DATA,
+ GCM_EXIF_ERROR_INTERNAL
+} GcmExifError;
+
+/* dummy */
+#define GCM_EXIF_ERROR 1
+
+GType gcm_exif_get_type (void);
+GcmExif *gcm_exif_new (void);
+
+const gchar *gcm_exif_get_manufacturer (GcmExif *exif);
+const gchar *gcm_exif_get_model (GcmExif *exif);
+const gchar *gcm_exif_get_serial (GcmExif *exif);
+gboolean gcm_exif_parse (GcmExif *exif,
+ const gchar *filename,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __GCM_EXIF_H */
+
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 4dc9516..4b82ffb 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -33,6 +33,7 @@
#include "gcm-device-udev.h"
#include "gcm-dmi.h"
#include "gcm-edid.h"
+#include "gcm-exif.h"
#include "gcm-gamma-widget.h"
#include "gcm-image.h"
#include "gcm-print.h"
@@ -607,6 +608,50 @@ gcm_test_edid_func (void)
}
static void
+gcm_test_exif_func (void)
+{
+ GcmExif *exif;
+ gboolean ret;
+ GError *error = NULL;
+ gchar *filename;
+
+ exif = gcm_exif_new ();
+ g_assert (exif != NULL);
+
+ /* TIFF */
+ filename = gcm_test_get_data_file ("test.tif");
+ ret = gcm_exif_parse (exif, filename, &error);
+ g_free (filename);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_assert_cmpstr (gcm_exif_get_model (exif), ==, "NIKON D60");
+ 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");
+ ret = gcm_exif_parse (exif, filename, &error);
+ g_free (filename);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_assert_cmpstr (gcm_exif_get_model (exif), ==, "NIKON D60");
+ 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");
+ ret = gcm_exif_parse (exif, filename, &error);
+ g_free (filename);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_assert_cmpstr (gcm_exif_get_model (exif), ==, "NIKON D60");
+ g_assert_cmpstr (gcm_exif_get_manufacturer (exif), ==, "NIKON CORPORATION");
+ g_assert_cmpstr (gcm_exif_get_serial (exif), ==, NULL);
+
+ g_object_unref (exif);
+}
+
+static void
gcm_test_gamma_widget_func (void)
{
GtkWidget *widget;
@@ -1112,6 +1157,7 @@ main (int argc, char **argv)
g_test_add_func ("/color/dmi", gcm_test_dmi_func);
g_test_add_func ("/color/calibrate", gcm_test_calibrate_func);
g_test_add_func ("/color/edid", gcm_test_edid_func);
+ g_test_add_func ("/color/exif", gcm_test_exif_func);
g_test_add_func ("/color/tables", gcm_test_tables_func);
g_test_add_func ("/color/utils", gcm_test_utils_func);
g_test_add_func ("/color/device", gcm_test_device_func);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]