diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2012-12-27 20:31:26 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2012-12-27 20:31:26 +0100 |
| commit | 9024ebb192d2ecdd2305a3ff3fbb54481035bd08 (patch) | |
| tree | 54f50b6a9094892fb1e8942b5c47590e822e251a | |
| parent | d0599f8ab5c38e14845407dea4eef4d4957f9e28 (diff) | |
| download | cataract-9024ebb192d2ecdd2305a3ff3fbb54481035bd08.tar.xz | |
Add support for EXIF Canon Camera temperature
For the moment we're using Exif.CanonSi.0x000c key from Exiv2 namespace
since it's an unknown tag to it. This may need little tweaking in the
future when proper naming becomes upstream.
| -rw-r--r-- | src/jpeg-utils.cpp | 40 | ||||
| -rw-r--r-- | src/jpeg-utils.h | 1 | ||||
| -rw-r--r-- | templates/template_picture.html | 3 |
3 files changed, 44 insertions, 0 deletions
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp index 389b8e4..196752a 100644 --- a/src/jpeg-utils.cpp +++ b/src/jpeg-utils.cpp @@ -69,6 +69,25 @@ exif_data_free (ExifData *data) } } +static const gchar * +get_real_key_name (const gchar *key) +{ + struct StrKeyPair { + const gchar *from; + const gchar *to; + }; + static const struct StrKeyPair conv[] = { + { EXIF_CANON_CAMERA_TEMP, "Exif.CanonSi.0x000c" }, + }; + + guint i; + + for (i = 0; i < G_N_ELEMENTS (conv); i++) + if (g_str_equal (conv[i].from, key)) + return conv[i].to; + + return key; +} /* * Retrieves value of the specified key or NULL if the key does not exist. @@ -77,6 +96,11 @@ exif_data_free (ExifData *data) gchar * get_exif_data (ExifData *exif, const gchar *key) { + g_return_val_if_fail (exif != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + key = get_real_key_name (key); + try { if (g_strcmp0 (key, JPEG_COMMENT) == 0) { return g_strdup (exif->image->comment().c_str()); @@ -106,6 +130,9 @@ get_exif_data (ExifData *exif, const gchar *key) gchar * get_exif_data_fixed (ExifData *exif, const gchar *key) { + g_return_val_if_fail (exif != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + try { if (g_str_has_prefix (key, EXIF_APERTURE)) { @@ -189,6 +216,17 @@ get_exif_data_fixed (ExifData *exif, const gchar *key) return g_strdup_printf ("%ld", val); } } + + if (g_str_has_prefix (key, EXIF_CANON_CAMERA_TEMP)) { + Exiv2::ExifData &exifData = exif->image->exifData(); + if (! exifData.empty()) { + if (exifData["Exif.CanonSi.0x000c"].count() > 0) { + int long val = exifData["Exif.CanonSi.0x000c"].toLong(); + if (val > 0) + return g_strdup_printf ("%ld °C", val - 128); + } + } + } } catch (...) { return NULL; @@ -206,6 +244,8 @@ exif_has_key (ExifData *exif, const gchar *key) g_return_val_if_fail (exif != NULL, FALSE); g_return_val_if_fail (key != NULL, FALSE); + key = get_real_key_name (key); + try { if (g_strcmp0 (key, JPEG_COMMENT) == 0) { return (! exif->image->comment().empty()); diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h index 7cec3a7..86602a2 100644 --- a/src/jpeg-utils.h +++ b/src/jpeg-utils.h @@ -38,6 +38,7 @@ G_BEGIN_DECLS #define EXIF_ARTIST "Exif.Image.Artist" #define EXIF_COPYRIGHT "Exif.Image.Copyright" #define EXIF_COMMENT "Exif.Photo.UserComment" +#define EXIF_CANON_CAMERA_TEMP "Exif.CanonSi.CameraTemperature" #define IPTC_COPYRIGHT "Iptc.Application2.Copyright" #define IPTC_CAPTION "Iptc.Application2.Caption" #define IPTC_AUTHOR "Iptc.Application2.Byline" diff --git a/templates/template_picture.html b/templates/template_picture.html index d164b6d..9d0e92c 100644 --- a/templates/template_picture.html +++ b/templates/template_picture.html @@ -57,6 +57,9 @@ <tr><td>Aperture value: </td> <td><!-- $(get_exif_value_fixed("Exif.Photo.FNumber")) --></td></tr> <tr><td>Exposure time: </td> <td><!-- $(get_exif_value_fixed("Exif.Photo.ExposureTime")) --></td></tr> <tr><td>Flash: </td> <td><!-- $(get_exif_value_fixed("Exif.Photo.Flash")) --></td></tr> +<!-- $(if (has_exif_key ("Exif.CanonSi.CameraTemperature"))) --> + <tr><td>Camera temperature: </td> <td><!-- $(get_exif_value_fixed("Exif.CanonSi.CameraTemperature")) --></td></tr> +<!-- $(endif (has_exif_key ())) --> </tbody></table> <!-- $(else(HAS_EXIF)) --> <div class="no_exif"> |
