Mercurial > geeqie.yaz
diff src/exif-common.c @ 1052:338c21c87ff5
Add support for GPSInfo - patch by Klaus Ethgen
author | nadvornik |
---|---|
date | Wed, 01 Oct 2008 20:57:56 +0000 |
parents | 4fe8f9656107 |
children | 77ca9a5d42be |
line wrap: on
line diff
--- a/src/exif-common.c Mon Sep 29 21:17:19 2008 +0000 +++ b/src/exif-common.c Wed Oct 01 20:57:56 2008 +0000 @@ -429,6 +429,78 @@ return g_strdup_printf("%s (%s)", name, source); } +static gchar *exif_build_formatted_GPSPosition(ExifData *exif) +{ + GString *string; + gchar *text, *ref; + ExifRational *value; + ExifItem *item; + guint i; + gdouble p, p3; + gulong p1, p2; + + string = g_string_new(""); + + item = exif_get_item(exif, "Exif.GPSInfo.GPSLatitude"); + ref = exif_get_data_as_text(exif, "Exif.GPSInfo.GPSLatitudeRef"); + if (item && ref) + { + p = 0; + for (i = 0; i < exif_item_get_elements(item); i++) + { + value = exif_item_get_rational(item, NULL, i); + if (value && value->num && value->den) + p += (gdouble)value->num / (gdouble)value->den / pow(60.0, (gdouble)i); + } + p1 = (gint)p; + p2 = (gint)((p - p1)*60); + p3 = ((p - p1)*60 - p2)*60; + + g_string_append_printf(string, "%0d° %0d' %0.2f\" %.1s", p1, p2, p3, ref); + } // if (item && ref) + + item = exif_get_item(exif, "Exif.GPSInfo.GPSLongitude"); + ref = exif_get_data_as_text(exif, "Exif.GPSInfo.GPSLongitudeRef"); + if (item && ref) + { + p = 0; + for (i = 0; i < exif_item_get_elements(item); i++) + { + value = exif_item_get_rational(item, NULL, i); + if (value && value->num && value->den) + p += (gdouble)value->num / (gdouble)value->den / pow(60.0, (gdouble)i); + } + p1 = (gint)p; + p2 = (gint)((p - p1)*60); + p3 = ((p - p1)*60 - p2)*60; + + g_string_append_printf(string, ", %0d° %0d' %0.2f\" %.1s", p1, p2, p3, ref); + } // if (item && ref) + + text = string->str; + g_string_free(string, FALSE); + + return text; +} // static gchar *exif_build_forma... + +static gchar *exif_build_formatted_GPSAltitude(ExifData *exif) +{ + ExifRational *r; + ExifItem *item; + gdouble alt; + gint ref; + + item = exif_get_item(exif, "Exif.GPSInfo.GPSAltitudeRef"); + r = exif_get_rational(exif, "Exif.GPSInfo.GPSAltitude", NULL); + + if (!r || !item) return NULL; + + alt = exif_rational_to_double(r, 0); + exif_item_get_integer(item, &ref); + + return g_strdup_printf("%0.f m %s", alt, (ref==0)?_("Above Sea Level"):_("Below Sea Level")); +} + /* List of custom formatted pseudo-exif tags */ #define EXIF_FORMATTED_TAG(name, label) { "formatted."#name, label, exif_build_formatted##_##name } @@ -446,6 +518,8 @@ EXIF_FORMATTED_TAG(Flash, N_("Flash")), EXIF_FORMATTED_TAG(Resolution, N_("Resolution")), EXIF_FORMATTED_TAG(ColorProfile, N_("Color profile")), + EXIF_FORMATTED_TAG(GPSPosition, N_("GPS position")), + EXIF_FORMATTED_TAG(GPSAltitude, N_("GPS altitude")), { NULL, NULL, NULL } }; @@ -497,7 +571,7 @@ ExifItem *item; item = exif_get_item(exif, key); - return exif_item_get_rational(item, sign); + return exif_item_get_rational(item, sign, 0); } gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)