changeset 182:8a417f10ba09

more exiv2 fixes
author nadvornik
date Wed, 13 Feb 2008 23:02:48 +0000
parents c01dd7c9c7dc
children 3962c9d3d6fd
files src/Makefile.am src/bar_exif.c src/exif-common.c src/exif-int.h src/exif.c src/exif.h src/exiv2.cc
diffstat 7 files changed, 328 insertions(+), 271 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Wed Feb 13 19:31:50 2008 +0000
+++ b/src/Makefile.am	Wed Feb 13 23:02:48 2008 +0000
@@ -85,6 +85,7 @@
 	exif.c		\
 	exif.h		\
 	exif-int.h	\
+	exif-common.c   \
 	exiv2.cc	\
 	filelist.c	\
 	filelist.h	\
--- a/src/bar_exif.c	Wed Feb 13 19:31:50 2008 +0000
+++ b/src/bar_exif.c	Wed Feb 13 23:02:48 2008 +0000
@@ -28,7 +28,7 @@
 #define BAR_EXIF_DATA_COLUMN_WIDTH 250
 
 static const gchar *bar_exif_key_list_real[] = {
-	"Exif.Image.Model" /*,
+	"fCamera",
 	"fDateTime",
 	"fShutterSpeed",
 	"fAperture",
@@ -43,7 +43,7 @@
 	"fResolution",
 	"Exif.Image.Orientation",
 	"Exif.Image.ImageDescription",
-	"Exif.Image.Copyright" */
+	"Exif.Image.Copyright" 
 };
 
 const gchar **bar_exif_key_list = bar_exif_key_list_real;
@@ -263,7 +263,7 @@
 			text = bar_exif_validate_text(text);
 			elements = g_strdup_printf("%d", exif_item_get_elements(item));
 			description = exif_item_get_description(item);
-			if (!description) description = "";
+			if (!description) description = g_strdup("");
 			gtk_list_store_append(store, &iter);
 			gtk_list_store_set(store, &iter,
 					EXIF_ADVCOL_ENABLED, bar_exif_row_enabled(tag_name),
@@ -276,6 +276,7 @@
 			g_free(tag);
 			g_free(text);
 			g_free(elements);
+			g_free(description);
 			item = exif_get_next_item(exif);
 			}
 		}
@@ -313,6 +314,8 @@
 {
 	ExifBar *eb;
 
+	g_assert(fd);
+	
 	eb = g_object_get_data(G_OBJECT(bar), "bar_exif_data");
 	if (!eb) return;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/exif-common.c	Wed Feb 13 23:02:48 2008 +0000
@@ -0,0 +1,295 @@
+/*
+ *  GQView
+ *  (C) 2006 John Ellis
+ *
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <math.h>
+ 
+#include <glib.h>
+
+#include "intl.h"
+
+#include "gqview.h"
+#include "exif.h"
+
+#include "format_raw.h"
+#include "ui_fileops.h"
+
+
+/* human readable key list */
+
+ExifFormattedText ExifFormattedList[] = {
+	{ "fCamera",		N_("Camera") },
+	{ "fDateTime",		N_("Date") },
+	{ "fShutterSpeed",	N_("Shutter speed") },
+	{ "fAperture",		N_("Aperture") },
+	{ "fExposureBias",	N_("Exposure bias") },
+	{ "fISOSpeedRating",	N_("ISO sensitivity") },
+	{ "fFocalLength",	N_("Focal length") },
+	{ "fSubjectDistance",	N_("Subject distance") },
+	{ "fFlash",		N_("Flash") },
+	{ "fResolution",	N_("Resolution") },
+	{ NULL, NULL }
+};
+
+static ExifTextList ExifFlashList[] = {
+	{ 0,	N_("no") },
+	{ 1,	N_("yes") },
+	{ 5,	N_("yes, not detected by strobe") },
+	{ 7,	N_("yes, detected by strobe") },
+	EXIF_TEXT_LIST_END
+};
+
+
+double exif_rational_to_double(ExifRational *r, gint sign)
+{
+	if (!r || r->den == 0.0) return 0.0;
+
+	if (sign) return (double)((int)r->num) / (double)((int)r->den);
+	return (double)r->num / r->den;
+}
+
+double exif_get_rational_as_double(ExifData *exif, const gchar *key)
+{
+	ExifRational *r;
+	gint sign;
+
+	r = exif_get_rational(exif, key, &sign);
+	return exif_rational_to_double(r, sign);
+}
+
+static GString *append_comma_text(GString *string, const gchar *text)
+{
+	string = g_string_append(string, ", ");
+	string = g_string_append(string, text);
+
+	return string;
+}
+
+
+gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
+{
+	/* must begin with f, else not formatted */
+	if (key[0] != 'f')
+		{
+		if (key_valid) *key_valid = FALSE;
+		return NULL;
+		}
+
+	if (key_valid) *key_valid = TRUE;
+
+	if (strcmp(key, "fCamera") == 0)
+		{
+		gchar *text;
+		gchar *make = exif_get_data_as_text(exif, "Exif.Image.Make");
+		gchar *model = exif_get_data_as_text(exif, "Exif.Image.Model");
+		gchar *software = exif_get_data_as_text(exif, "Exif.Image.Software");
+
+		text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "",
+						       (model) ? model : "",
+						       (software) ? " (" : "",
+						       (software) ? software : "",
+						       (software) ? ")" : "");
+
+		g_free(make);
+		g_free(model);
+		g_free(software);
+		return text;
+		}
+	if (strcmp(key, "fDateTime") == 0)
+		{
+		gchar *text = exif_get_data_as_text(exif, "Exif.Photo.DateTimeOriginal");
+		gchar *subsec = NULL;
+		if (text) subsec = exif_get_data_as_text(exif, "Exif.Photo.SubSecTimeOriginal");
+		if (!text)
+			{
+			text = exif_get_data_as_text(exif, "Exif.Image.DateTime");
+			if (text) subsec = exif_get_data_as_text(exif, "Exif.Photo.SubSecTime");
+			}
+		if (subsec)
+			{
+			gchar *tmp = text;
+			text = g_strconcat(tmp, ".", subsec, NULL);
+			g_free(tmp);
+			g_free(subsec);
+			}
+		return text;
+		}
+	if (strcmp(key, "fShutterSpeed") == 0)
+		{
+		ExifRational *r;
+
+		r = exif_get_rational(exif, "Exif.Photo.ExposureTime", NULL);
+		if (r && r->num && r->den)
+			{
+			double n = (double)r->den / (double)r->num;
+			return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
+							  n > 1.0 ? n : 1.0 / n);
+			}
+		r = exif_get_rational(exif, "Exif.Photo.ShutterSpeedValue", NULL);
+		if (r && r->num  && r->den)
+			{
+			double n = pow(2.0, exif_rational_to_double(r, TRUE));
+
+			/* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
+			if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
+
+			return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
+							  n > 1.0 ? floor(n) : 1.0 / n);	
+			}
+		return NULL;
+		}
+	if (strcmp(key, "fAperture") == 0)
+		{
+		double n;
+
+		n = exif_get_rational_as_double(exif, "Exif.Photo.FNumber");
+		if (n == 0.0) n = exif_get_rational_as_double(exif, "Exif.Photo.ApertureValue");
+		if (n == 0.0) return NULL;
+
+		return g_strdup_printf("f/%.1f", n);
+		}
+	if (strcmp(key, "fExposureBias") == 0)
+		{
+		ExifRational *r;
+		gint sign;
+		double n;
+
+		r = exif_get_rational(exif, "Exif.Photo.ExposureBiasValue", &sign);
+		if (!r) return NULL;
+
+		n = exif_rational_to_double(r, sign);
+		return g_strdup_printf("%+.1f", n);
+		}
+	if (strcmp(key, "fFocalLength") == 0)
+		{
+		double n;
+
+		n = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength");
+		if (n == 0.0) return NULL;
+		return g_strdup_printf("%.2f mm", n);
+		}
+	if (strcmp(key, "fISOSpeedRating") == 0)
+		{
+		gchar *text;
+
+		text = exif_get_data_as_text(exif, "Exif.Photo.ISOSpeedRatings");
+		/* kodak may set this instead */
+		if (!text) text = exif_get_data_as_text(exif, "Exif.Photo.ExposureIndex");
+		return text;
+		}
+	if (strcmp(key, "fSubjectDistance") == 0)
+		{
+		ExifRational *r;
+		gint sign;
+		double n;
+
+		r = exif_get_rational(exif, "Exif.Photo.SubjectDistance", &sign);
+		if (!r) return NULL;
+
+		if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
+		if ((long)r->num == 0) return g_strdup(_("unknown"));
+
+		n = exif_rational_to_double(r, sign);
+		if (n == 0.0) return _("unknown");
+		return g_strdup_printf("%.3f m", n);
+		}
+	if (strcmp(key, "fFlash") == 0)
+		{
+		/* grr, flash is a bitmask... */
+		GString *string;
+		gchar *text;
+		gint n;
+		gint v;
+
+		if (!exif_get_integer(exif, "Exif.Photo.Flash", &n)) return NULL;
+
+		/* Exif 2.1 only defines first 3 bits */
+//		if (n <= 0x07) return exif_text_list_find_value(ExifFlashList, n);
+
+		/* must be Exif 2.2 */
+		string = g_string_new("");
+
+		/* flash fired (bit 0) */
+		string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
+
+		/* flash mode (bits 3, 4) */
+		v = (n >> 3) & 0x03;
+		if (v) string = append_comma_text(string, _("mode:"));
+		switch (v)
+			{
+			case 1:
+				string = g_string_append(string, _("on"));
+				break;
+			case 2:
+				string = g_string_append(string, _("off"));
+				break;
+			case 3:
+				string = g_string_append(string, _("auto"));
+				break;
+			}
+
+		/* return light (bits 1, 2) */
+		v = (n >> 1) & 0x03;
+		if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
+		if (v == 3) string = append_comma_text(string, _("detected by strobe"));
+
+		/* we ignore flash function (bit 5) */
+
+		/* red-eye (bit 6) */
+		if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
+
+		text = string->str;
+		g_string_free(string, FALSE);
+		return text;
+		}
+	if (strcmp(key, "fResolution") == 0)
+		{
+		ExifRational *rx, *ry;
+		gchar *units;
+		gchar *text;
+
+		rx = exif_get_rational(exif, "Exif.Image.XResolution", NULL);
+		ry = exif_get_rational(exif, "Exif.Image.YResolution", NULL);
+		if (!rx || !ry) return NULL;
+
+		units = exif_get_data_as_text(exif, "Exif.Image.ResolutionUnit");
+		text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
+							      ry->den ? (double)ry->num / ry->den : 1.0,
+							      _("dot"), (units) ? units : _("unknown"));
+
+		g_free(units);
+		return text;
+		}
+
+	if (key_valid) *key_valid = FALSE;
+	return NULL;
+}
+
+const gchar *exif_get_description_by_key(const gchar *key)
+{
+	gint i;
+
+	if (!key) return NULL;
+
+	i = 0;
+	while (ExifFormattedList[i].key != NULL)
+		{
+		if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
+		i++;
+		}
+
+	return exif_get_tag_description_by_key(key);
+}
--- a/src/exif-int.h	Wed Feb 13 19:31:50 2008 +0000
+++ b/src/exif-int.h	Wed Feb 13 23:02:48 2008 +0000
@@ -164,6 +164,5 @@
 
 gchar *exif_text_list_find_value(ExifTextList *list, guint value);
 
-
 #endif
 
--- a/src/exif.c	Wed Feb 13 19:31:50 2008 +0000
+++ b/src/exif.c	Wed Feb 13 23:02:48 2008 +0000
@@ -329,9 +329,9 @@
 { 0x9214, EXIF_FORMAT_SHORT_UNSIGNED, -1,	"Exif.Photo.SubjectArea",		"Subject area", NULL },
 { 0x927c, EXIF_FORMAT_UNDEFINED, -1,		"Exif.Photo.MakerNote",		"MakerNote", NULL },
 { 0x9286, EXIF_FORMAT_UNDEFINED, -1, 		"Exif.Photo.UserComment",		"UserComment", NULL },
-{ 0x9290, EXIF_FORMAT_STRING, -1,		"SubsecTime",		"Subsecond time", NULL },
-{ 0x9291, EXIF_FORMAT_STRING, -1,		"SubsecTimeOriginal",	"Subsecond time original", NULL },
-{ 0x9292, EXIF_FORMAT_STRING, -1,		"SubsecTimeDigitized",	"Subsecond time digitized", NULL },
+{ 0x9290, EXIF_FORMAT_STRING, -1,		"Exif.Photo.SubSecTime",		"Subsecond time", NULL },
+{ 0x9291, EXIF_FORMAT_STRING, -1,		"Exif.Photo.SubSecTimeOriginal",	"Subsecond time original", NULL },
+{ 0x9292, EXIF_FORMAT_STRING, -1,		"Exif.Photo.SubSecTimeDigitized",	"Subsecond time digitized", NULL },
 { 0xa000, EXIF_FORMAT_UNDEFINED, 4,		"FlashPixVersion",	"FlashPix version", NULL },
 { 0xa001, EXIF_FORMAT_SHORT_UNSIGNED, 1,	"Exif.Photo.ColorSpace",		"Colorspace", ExifColorSpaceList },
 	/* ExifImageWidth, ExifImageHeight can also be unsigned short */
@@ -413,23 +413,6 @@
 { 0x0000, EXIF_FORMAT_DOUBLE, -1,		"unknown",	NULL, NULL },
 };
 
-/* human readable key list */
-
-ExifFormattedText ExifFormattedList[] = {
-	{ "fCamera",		N_("Camera") },
-	{ "fDateTime",		N_("Date") },
-	{ "fShutterSpeed",	N_("Shutter speed") },
-	{ "fAperture",		N_("Aperture") },
-	{ "fExposureBias",	N_("Exposure bias") },
-	{ "fISOSpeedRating",	N_("ISO sensitivity") },
-	{ "fFocalLength",	N_("Focal length") },
-	{ "fSubjectDistance",	N_("Subject distance") },
-	{ "fFlash",		N_("Exif.Photo.Flash") },
-	{ "fResolution",	N_("Resolution") },
-	{ NULL, NULL }
-};
-
-
 static const ExifMarker *exif_marker_from_tag(guint16 tag, const ExifMarker *list);
 
 /*
@@ -537,10 +520,10 @@
 }
 
 
-const char *exif_item_get_description(ExifItem *item)
+char *exif_item_get_description(ExifItem *item)
 {
 	if (!item || !item->marker) return NULL;
-	return _(item->marker->description);
+	return g_strdup(_(item->marker->description));
 }
 
 const char *exif_item_get_format_name(ExifItem *item, gint brief)
@@ -584,6 +567,7 @@
 	return string;
 }
 
+
 gchar *exif_text_list_find_value(ExifTextList *list, guint value)
 {
 	gchar *result = NULL;
@@ -1241,7 +1225,7 @@
 	int size, res;
 	gchar *pathl;
 
-	if (!fd) return NULL;
+	if (!path) return NULL;
 
 	pathl = path_from_utf8(path);
 	if (map_file(pathl, &f, &size) == -1)
@@ -1531,229 +1515,6 @@
 	return exif_item_get_rational(item, sign);
 }
 
-double exif_rational_to_double(ExifRational *r, gint sign)
-{
-	if (!r || r->den == 0.0) return 0.0;
-
-	if (sign) return (double)((int)r->num) / (double)((int)r->den);
-	return (double)r->num / r->den;
-}
-
-static double exif_get_rational_as_double(ExifData *exif, const gchar *key)
-{
-	ExifRational *r;
-	gint sign;
-
-	r = exif_get_rational(exif, key, &sign);
-	return exif_rational_to_double(r, sign);
-}
-
-static GString *append_comma_text(GString *string, const gchar *text)
-{
-	string = g_string_append(string, ", ");
-	string = g_string_append(string, text);
-
-	return string;
-}
-
-static gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid)
-{
-	/* must begin with f, else not formatted */
-	if (key[0] != 'f')
-		{
-		if (key_valid) *key_valid = FALSE;
-		return NULL;
-		}
-
-	if (key_valid) *key_valid = TRUE;
-
-	if (strcmp(key, "fCamera") == 0)
-		{
-		gchar *text;
-		gchar *make = exif_get_data_as_text(exif, "Exif.Image.Make");
-		gchar *model = exif_get_data_as_text(exif, "Exif.Image.Model");
-		gchar *software = exif_get_data_as_text(exif, "Exif.Image.Software");
-
-		text = g_strdup_printf("%s%s%s%s%s%s", (make) ? make : "", ((make) && (model)) ? " " : "",
-						       (model) ? model : "",
-						       (software) ? " (" : "",
-						       (software) ? software : "",
-						       (software) ? ")" : "");
-
-		g_free(make);
-		g_free(model);
-		g_free(software);
-		return text;
-		}
-	if (strcmp(key, "fDateTime") == 0)
-		{
-		gchar *text = exif_get_data_as_text(exif, "Exif.Photo.DateTimeOriginal");
-		gchar *subsec = NULL;
-		if (text) subsec = exif_get_data_as_text(exif, "SubsecTimeOriginal");
-		if (!text)
-			{
-			text = exif_get_data_as_text(exif, "Exif.Image.DateTime");
-			if (text) subsec = exif_get_data_as_text(exif, "SubsecTime");
-			}
-		if (subsec)
-			{
-			gchar *tmp = text;
-			text = g_strconcat(tmp, ".", subsec, NULL);
-			g_free(tmp);
-			g_free(subsec);
-			}
-		return text;
-		}
-	if (strcmp(key, "fShutterSpeed") == 0)
-		{
-		ExifRational *r;
-
-		r = exif_get_rational(exif, "Exif.Photo.ExposureTime", NULL);
-		if (r && r->num && r->den)
-			{
-			double n = (double)r->den / (double)r->num;
-			return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
-							  n > 1.0 ? n : 1.0 / n);
-			}
-		r = exif_get_rational(exif, "Exif.Photo.ShutterSpeedValue", NULL);
-		if (r && r->num  && r->den)
-			{
-			double n = pow(2.0, exif_rational_to_double(r, TRUE));
-
-			/* Correct exposure time to avoid values like 1/91s (seen on Minolta DImage 7) */
-			if (n > 1.0 && (int)n - ((int)(n/10))*10 == 1) n--;
-
-			return g_strdup_printf("%s%.0fs", n > 1.0 ? "1/" : "",
-							  n > 1.0 ? floor(n) : 1.0 / n);	
-			}
-		return NULL;
-		}
-	if (strcmp(key, "fAperture") == 0)
-		{
-		double n;
-
-		n = exif_get_rational_as_double(exif, "Exif.Photo.FNumber");
-		if (n == 0.0) n = exif_get_rational_as_double(exif, "Exif.Photo.ApertureValue");
-		if (n == 0.0) return NULL;
-
-		return g_strdup_printf("f/%.1f", n);
-		}
-	if (strcmp(key, "fExposureBias") == 0)
-		{
-		ExifRational *r;
-		gint sign;
-		double n;
-
-		r = exif_get_rational(exif, "Exif.Photo.ExposureBiasValue", &sign);
-		if (!r) return NULL;
-
-		n = exif_rational_to_double(r, sign);
-		return g_strdup_printf("%+.1f", n);
-		}
-	if (strcmp(key, "fFocalLength") == 0)
-		{
-		double n;
-
-		n = exif_get_rational_as_double(exif, "Exif.Photo.FocalLength");
-		if (n == 0.0) return NULL;
-		return g_strdup_printf("%.2f mm", n);
-		}
-	if (strcmp(key, "fISOSpeedRating") == 0)
-		{
-		gchar *text;
-
-		text = exif_get_data_as_text(exif, "Exif.Photo.ISOSpeedRatings");
-		/* kodak may set this instead */
-		if (!text) text = exif_get_data_as_text(exif, "Exif.Photo.ExposureIndex");
-		return text;
-		}
-	if (strcmp(key, "fSubjectDistance") == 0)
-		{
-		ExifRational *r;
-		gint sign;
-		double n;
-
-		r = exif_get_rational(exif, "Exif.Photo.SubjectDistance", &sign);
-		if (!r) return NULL;
-
-		if ((long)r->num == 0xffffffff) return g_strdup(_("infinity"));
-		if ((long)r->num == 0) return g_strdup(_("unknown"));
-
-		n = exif_rational_to_double(r, sign);
-		if (n == 0.0) return _("unknown");
-		return g_strdup_printf("%.3f m", n);
-		}
-	if (strcmp(key, "fFlash") == 0)
-		{
-		/* grr, flash is a bitmask... */
-		GString *string;
-		gchar *text;
-		gint n;
-		gint v;
-
-		if (!exif_get_integer(exif, "Exif.Photo.Flash", &n)) return NULL;
-
-		/* Exif 2.1 only defines first 3 bits */
-		if (n <= 0x07) return exif_text_list_find_value(ExifFlashList, n);
-
-		/* must be Exif 2.2 */
-		string = g_string_new("");
-
-		/* flash fired (bit 0) */
-		string = g_string_append(string, (n & 0x01) ? _("yes") : _("no"));
-
-		/* flash mode (bits 3, 4) */
-		v = (n >> 3) & 0x03;
-		if (v) string = append_comma_text(string, _("mode:"));
-		switch (v)
-			{
-			case 1:
-				string = g_string_append(string, _("on"));
-				break;
-			case 2:
-				string = g_string_append(string, _("off"));
-				break;
-			case 3:
-				string = g_string_append(string, _("auto"));
-				break;
-			}
-
-		/* return light (bits 1, 2) */
-		v = (n >> 1) & 0x03;
-		if (v == 2) string = append_comma_text(string, _("not detected by strobe"));
-		if (v == 3) string = append_comma_text(string, _("detected by strobe"));
-
-		/* we ignore flash function (bit 5) */
-
-		/* red-eye (bit 6) */
-		if ((n >> 5) & 0x01) string = append_comma_text(string, _("red-eye reduction"));
-
-		text = string->str;
-		g_string_free(string, FALSE);
-		return text;
-		}
-	if (strcmp(key, "fResolution") == 0)
-		{
-		ExifRational *rx, *ry;
-		gchar *units;
-		gchar *text;
-
-		rx = exif_get_rational(exif, "Exif.Image.XResolution", NULL);
-		ry = exif_get_rational(exif, "Exif.Image.YResolution", NULL);
-		if (!rx || !ry) return NULL;
-
-		units = exif_get_data_as_text(exif, "Exif.Image.ResolutionUnit");
-		text = g_strdup_printf("%0.f x %0.f (%s/%s)", rx->den ? (double)rx->num / rx->den : 1.0,
-							      ry->den ? (double)ry->num / ry->den : 1.0,
-							      _("dot"), (units) ? units : _("unknown"));
-
-		g_free(units);
-		return text;
-		}
-
-	if (key_valid) *key_valid = FALSE;
-	return NULL;
-}
 
 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
 {
@@ -1772,20 +1533,13 @@
 	return NULL;
 }
 
-const gchar *exif_get_description_by_key(const gchar *key)
+const gchar *exif_get_tag_description_by_key(const gchar *key)
 {
 	gint i;
 
 	if (!key) return NULL;
 
 	i = 0;
-	while (ExifFormattedList[i].key != NULL)
-		{
-		if (strcmp(key, ExifFormattedList[i].key) == 0) return _(ExifFormattedList[i].description);
-		i++;
-		}
-
-	i = 0;
 	while (ExifKnownMarkersList[i].tag > 0)
 		{
 		if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
--- a/src/exif.h	Wed Feb 13 19:31:50 2008 +0000
+++ b/src/exif.h	Wed Feb 13 23:02:48 2008 +0000
@@ -112,6 +112,7 @@
 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value);
 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign);
 double exif_rational_to_double(ExifRational *r, gint sign);
+double exif_get_rational_as_double(ExifData *exif, const gchar *key);
 
 ExifItem *exif_get_item(ExifData *exif, const gchar *key);
 ExifItem *exif_get_first_item(ExifData *exif);
@@ -121,7 +122,7 @@
 guint exif_item_get_tag_id(ExifItem *item);
 guint exif_item_get_elements(ExifItem *item);
 char *exif_item_get_data(ExifItem *item, guint *data_len);
-const char *exif_item_get_description(ExifItem *item);
+char *exif_item_get_description(ExifItem *item);
 guint exif_item_get_format_id(ExifItem *item);
 const char *exif_item_get_format_name(ExifItem *item, gint brief);
 gchar *exif_item_get_data_as_text(ExifItem *item);
@@ -129,6 +130,9 @@
 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign);
 
 const gchar *exif_get_description_by_key(const gchar *key);
+const gchar *exif_get_tag_description_by_key(const gchar *key);
+
+gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid);
 
 gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
 				    unsigned char *header_data, const guint header_len,
--- a/src/exiv2.cc	Wed Feb 13 19:31:50 2008 +0000
+++ b/src/exiv2.cc	Wed Feb 13 23:02:48 2008 +0000
@@ -24,8 +24,9 @@
 
 ExifData *exif_read(gchar *path, gint parse_color_profile)
 {
+	printf("exif %s\n", path);
 	try {
-		ExifData *exif = g_new0(ExifData, 1);
+		ExifData *exif = new ExifData;
 	
 		Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
 		g_assert (image.get() != 0);
@@ -42,11 +43,17 @@
 
 void exif_free(ExifData *exif)
 {
+	
+	delete exif;
 }
 
 
 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
 {
+	gint key_valid;
+	gchar *text = exif_get_formatted_by_key(exif, key, &key_valid);
+	if (key_valid) return text;
+
 	return g_strdup(exif->exifData[key].toString().c_str());
 }
 
@@ -68,14 +75,6 @@
 */
 }
 
-double exif_rational_to_double(ExifRational *r, gint sign)
-{
-	if (!r || r->den == 0.0) return 0.0;
-
-	if (sign) return (double)((int)r->num) / (double)((int)r->den);
-	return (double)r->num / r->den;
-}
-
 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
 {
 	Exiv2::Exifdatum *item = &exif->exifData[key];
@@ -117,9 +116,9 @@
 {
 }
 
-const char *exif_item_get_description(ExifItem *item)
+char *exif_item_get_description(ExifItem *item)
 {
-	return ((Exiv2::Exifdatum *)item)->tagLabel().c_str();
+	return g_strdup(((Exiv2::Exifdatum *)item)->tagLabel().c_str());
 }
 
 /*
@@ -170,8 +169,10 @@
 {
 }
 
-const gchar *exif_get_description_by_key(const gchar *key)
+const gchar *exif_get_tag_description_by_key(const gchar *key)
 {
+	Exiv2::ExifKey ekey(key);
+	return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ());
 }
 
 gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,