[eog] Reformat Exif tags for GPS position to be better understandable
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] Reformat Exif tags for GPS position to be better understandable
- Date: Sun, 17 Jul 2011 13:51:10 +0000 (UTC)
commit 3e4bc1aad5bf9236705bdb049ed017f374e27552
Author: Felix Riemann <friemann gnome org>
Date: Sun Jul 17 15:47:28 2011 +0200
Reformat Exif tags for GPS position to be better understandable
libexif's formatting of these tags is not nice to read.
Reformatted are latitude and longitude values and their reference points.
https://bugzilla.gnome.org/show_bug.cgi?id=627185
src/eog-exif-details.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 91 insertions(+), 3 deletions(-)
---
diff --git a/src/eog-exif-details.c b/src/eog-exif-details.c
index 67b26ac..8cc3920 100644
--- a/src/eog-exif-details.c
+++ b/src/eog-exif-details.c
@@ -354,6 +354,94 @@ set_row_data (GtkTreeStore *store, char *path, char *parent, const char *attribu
}
#ifdef HAVE_EXIF
+
+static const char *
+eog_exif_entry_get_value (ExifEntry *e,
+ char *buf,
+ guint n_buf)
+{
+ ExifByteOrder bo;
+
+ /* For now we only want to reformat some GPS values */
+ if (G_LIKELY (exif_entry_get_ifd (e) != EXIF_IFD_GPS))
+ return exif_entry_get_value (e, buf, n_buf);
+
+ bo = exif_data_get_byte_order (e->parent->parent);
+
+ /* Cast to number to avoid warnings about values not in enumeration */
+ switch ((guint16) e->tag) {
+ case EXIF_TAG_GPS_LATITUDE:
+ case EXIF_TAG_GPS_LONGITUDE:
+ {
+ gsize rational_size;
+ ExifRational r;
+ gfloat h = 0., m = 0.;
+
+
+ rational_size = exif_format_get_size (EXIF_FORMAT_RATIONAL);
+ if (G_UNLIKELY (e->components != 3 ||
+ e->format != EXIF_FORMAT_RATIONAL))
+ return exif_entry_get_value (e, buf, n_buf);
+
+ r = exif_get_rational (e->data, bo);
+ if (r.denominator != 0)
+ h = (gfloat)r.numerator / r.denominator;
+
+ r = exif_get_rational (e->data + rational_size, bo);
+ if (r.denominator != 0)
+ m = (gfloat)r.numerator / (gfloat)r.denominator;
+
+ r = exif_get_rational (e->data + (2 * rational_size),
+ bo);
+ if (r.numerator != 0 && r.denominator != 0) {
+ gfloat s;
+
+ s = (gfloat)r.numerator / (gfloat)r.denominator;
+ g_snprintf (buf, n_buf,
+ "%.0f %.0f' %.2f\"",
+ h, m, s);
+ } else {
+ g_snprintf (buf, n_buf,
+ "%.0f %.2f'",
+ h, m);
+ }
+
+ break;
+ }
+ case EXIF_TAG_GPS_LATITUDE_REF:
+ case EXIF_TAG_GPS_LONGITUDE_REF:
+ {
+ if (G_UNLIKELY (e->components != 2 ||
+ e->format != EXIF_FORMAT_ASCII))
+ return exif_entry_get_value (e, buf, n_buf);
+
+ switch (e->data[0]) {
+ case 'N':
+ g_snprintf (buf, n_buf, "%s", _("North"));
+ break;
+ case 'E':
+ g_snprintf (buf, n_buf, "%s", _("East"));
+ break;
+ case 'W':
+ g_snprintf (buf, n_buf, "%s", _("West"));
+ break;
+ case 'S':
+ g_snprintf (buf, n_buf, "%s", _("South"));
+ break;
+ default:
+ return exif_entry_get_value (e, buf, n_buf);
+ break;
+ }
+ break;
+ }
+ default:
+ return exif_entry_get_value (e, buf, n_buf);
+ break;
+ }
+
+ return buf;
+}
+
static void
exif_entry_cb (ExifEntry *entry, gpointer data)
{
@@ -377,7 +465,7 @@ exif_entry_cb (ExifEntry *entry, gpointer data)
path,
NULL,
exif_tag_get_name_in_ifd (entry->tag, ifd),
- exif_entry_get_value (entry, b, sizeof(b)));
+ eog_exif_entry_get_value (entry, b, sizeof(b)));
} else {
ExifMnoteData *mnote = (entry->tag == EXIF_TAG_MAKER_NOTE ?
@@ -409,8 +497,8 @@ exif_entry_cb (ExifEntry *entry, gpointer data)
NULL,
exif_categories[cat].path,
exif_tag_get_name_in_ifd (entry->tag, ifd),
- exif_entry_get_value (entry, b,
- sizeof(b)));
+ eog_exif_entry_get_value (entry, b,
+ sizeof(b)));
g_hash_table_insert (priv->id_path_hash,
GINT_TO_POINTER (entry->tag),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]