Skip to content

Commit fe21ccd

Browse files
fxriraveit65
authored andcommitted
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 origin commit: https://gitlab.gnome.org/GNOME/eog/commit/3e4bc1a
1 parent 32f2e6f commit fe21ccd

File tree

1 file changed

+91
-3
lines changed

1 file changed

+91
-3
lines changed

src/eom-exif-details.c

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,94 @@ set_row_data (GtkTreeStore *store, char *path, char *parent, const char *attribu
351351
}
352352

353353
#ifdef HAVE_EXIF
354+
355+
static const char *
356+
eom_exif_entry_get_value (ExifEntry *e,
357+
char *buf,
358+
guint n_buf)
359+
{
360+
ExifByteOrder bo;
361+
362+
/* For now we only want to reformat some GPS values */
363+
if (G_LIKELY (exif_entry_get_ifd (e) != EXIF_IFD_GPS))
364+
return exif_entry_get_value (e, buf, n_buf);
365+
366+
bo = exif_data_get_byte_order (e->parent->parent);
367+
368+
/* Cast to number to avoid warnings about values not in enumeration */
369+
switch ((guint16) e->tag) {
370+
case EXIF_TAG_GPS_LATITUDE:
371+
case EXIF_TAG_GPS_LONGITUDE:
372+
{
373+
gsize rational_size;
374+
ExifRational r;
375+
gfloat h = 0., m = 0.;
376+
377+
378+
rational_size = exif_format_get_size (EXIF_FORMAT_RATIONAL);
379+
if (G_UNLIKELY (e->components != 3 ||
380+
e->format != EXIF_FORMAT_RATIONAL))
381+
return exif_entry_get_value (e, buf, n_buf);
382+
383+
r = exif_get_rational (e->data, bo);
384+
if (r.denominator != 0)
385+
h = (gfloat)r.numerator / r.denominator;
386+
387+
r = exif_get_rational (e->data + rational_size, bo);
388+
if (r.denominator != 0)
389+
m = (gfloat)r.numerator / (gfloat)r.denominator;
390+
391+
r = exif_get_rational (e->data + (2 * rational_size),
392+
bo);
393+
if (r.numerator != 0 && r.denominator != 0) {
394+
gfloat s;
395+
396+
s = (gfloat)r.numerator / (gfloat)r.denominator;
397+
g_snprintf (buf, n_buf,
398+
"%.0f° %.0f' %.2f\"",
399+
h, m, s);
400+
} else {
401+
g_snprintf (buf, n_buf,
402+
"%.0f° %.2f'",
403+
h, m);
404+
}
405+
406+
break;
407+
}
408+
case EXIF_TAG_GPS_LATITUDE_REF:
409+
case EXIF_TAG_GPS_LONGITUDE_REF:
410+
{
411+
if (G_UNLIKELY (e->components != 2 ||
412+
e->format != EXIF_FORMAT_ASCII))
413+
return exif_entry_get_value (e, buf, n_buf);
414+
415+
switch (e->data[0]) {
416+
case 'N':
417+
g_snprintf (buf, n_buf, "%s", _("North"));
418+
break;
419+
case 'E':
420+
g_snprintf (buf, n_buf, "%s", _("East"));
421+
break;
422+
case 'W':
423+
g_snprintf (buf, n_buf, "%s", _("West"));
424+
break;
425+
case 'S':
426+
g_snprintf (buf, n_buf, "%s", _("South"));
427+
break;
428+
default:
429+
return exif_entry_get_value (e, buf, n_buf);
430+
break;
431+
}
432+
break;
433+
}
434+
default:
435+
return exif_entry_get_value (e, buf, n_buf);
436+
break;
437+
}
438+
439+
return buf;
440+
}
441+
354442
static void
355443
exif_entry_cb (ExifEntry *entry, gpointer data)
356444
{
@@ -374,7 +462,7 @@ exif_entry_cb (ExifEntry *entry, gpointer data)
374462
path,
375463
NULL,
376464
exif_tag_get_name_in_ifd (entry->tag, ifd),
377-
exif_entry_get_value (entry, b, sizeof(b)));
465+
eom_exif_entry_get_value (entry, b, sizeof(b)));
378466
} else {
379467

380468
ExifMnoteData *mnote = (entry->tag == EXIF_TAG_MAKER_NOTE ?
@@ -406,8 +494,8 @@ exif_entry_cb (ExifEntry *entry, gpointer data)
406494
NULL,
407495
exif_categories[cat].path,
408496
exif_tag_get_name_in_ifd (entry->tag, ifd),
409-
exif_entry_get_value (entry, b,
410-
sizeof(b)));
497+
eom_exif_entry_get_value (entry, b,
498+
sizeof(b)));
411499

412500
g_hash_table_insert (priv->id_path_hash,
413501
GINT_TO_POINTER (entry->tag),

0 commit comments

Comments
 (0)