X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=blobdiff_plain;f=src%2Fexif.c;h=872b9ccd65e54979ccc108845eb952b1af2975e1;hp=e7f41e2895e8b1704614e98ea9d7006138d70a8f;hb=50f5ef3cedbeaa251a1e838bf5045a9dc7dda1ee;hpb=11a4cc2074aa9544a906434f40eda2b27d6ef5c1 diff --git a/src/exif.c b/src/exif.c index e7f41e28..872b9ccd 100644 --- a/src/exif.c +++ b/src/exif.c @@ -1,13 +1,22 @@ /* - * Geeqie - * (C) 2006 John Ellis - * Copyright (C) 2008 - 2009 The Geeqie Team + * Copyright (C) 2003, 2006 John Ellis + * Copyright (C) 2008 - 2016 The Geeqie Team * - * Authors: - * Support for Exif file format, originally written by Eric Swalens. - * Modified by Quy Tonthat + * Authors: Eric Swalens, Quy Tonthat * - * Reimplemented with generic data storage by John Ellis (Nov 2003) + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * The tags were added with information from the FREE document: * http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html @@ -34,22 +43,7 @@ * ComponentsConfiguration * UserComment (convert this to UTF-8?) * Add support for marker tag 0x0000 - * - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -67,11 +61,13 @@ #include #include +#include #include "intl.h" #include "main.h" #include "exif-int.h" +#include "jpeg_parser.h" #include "format_raw.h" #include "ui_fileops.h" @@ -510,8 +506,6 @@ ExifItem *exif_item_new(ExifFormatType format, guint tag, item->tag = tag; item->marker = marker; item->elements = elements; - item->data = NULL; - item->data_len = 0; switch (format) { @@ -608,7 +602,7 @@ gchar *exif_item_get_description(ExifItem *item) return g_strdup(_(item->marker->description)); } -const gchar *exif_item_get_format_name(ExifItem *item, gint brief) +const gchar *exif_item_get_format_name(ExifItem *item, gboolean brief) { if (!item || !item->marker) return NULL; return (brief) ? ExifFormatList[item->format].short_name : ExifFormatList[item->format].description; @@ -928,7 +922,7 @@ static gint exif_parse_IFD_entry(ExifData *exif, guchar *tiff, guint offset, if (data_length > 4) { data_offset = data_val; - if (size < data_offset + data_length) + if (size < data_offset || size < data_offset + data_length) { log_printf("warning: exif tag %s data will overrun end of file, ignored.\n", marker->key); return -1; @@ -1087,7 +1081,7 @@ static gint exif_jpeg_parse(ExifData *exif, return -2; } - if (exif_jpeg_segment_find(data, size, JPEG_MARKER_APP1, + if (jpeg_segment_find(data, size, JPEG_MARKER_APP1, "Exif\x00\x00", 6, &seg_offset, &seg_length)) { @@ -1111,6 +1105,18 @@ guchar *exif_get_color_profile(ExifData *exif, guint *data_len) } +gchar* exif_get_image_comment(FileData* fd) +{ + log_printf("%s", _("Can't get image comment: not compiled with Exiv2.\n")); + return g_strdup(""); +} + +void exif_set_image_comment(FileData* fd, const gchar* comment) +{ + log_printf("%s", _("Can't set image comment: not compiled with Exiv2.\n")); +} + + /* *------------------------------------------------------------------- * misc @@ -1227,8 +1233,6 @@ ExifData *exif_read(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp) g_free(pathl); exif = g_new0(ExifData, 1); - exif->items = NULL; - exif->current = NULL; exif->path = g_strdup(path); res = exif_jpeg_parse(exif, (guchar *)f, size, ExifKnownMarkersList); @@ -1283,11 +1287,6 @@ ExifData *exif_read(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp) if (exif) exif->items = g_list_reverse(exif->items); -#if 0 - exif_write_data_list(exif, stdout, TRUE); - exif_write_data_list(exif, stdout, FALSE); -#endif - return exif; } @@ -1311,13 +1310,8 @@ ExifItem *exif_get_item(ExifData *exif, const gchar *key) #define EXIF_DATA_AS_TEXT_MAX_COUNT 16 -gchar *exif_item_get_string(ExifItem *item, gint idx) -{ - return exif_item_get_data_as_text(item); -} - -gchar *exif_item_get_data_as_text(ExifItem *item) +static gchar *exif_item_get_data_as_text_full(ExifItem *item, MetadataFormat format) { const ExifMarker *marker; gpointer data; @@ -1342,7 +1336,7 @@ gchar *exif_item_get_data_as_text(ExifItem *item) case EXIF_FORMAT_BYTE_UNSIGNED: case EXIF_FORMAT_BYTE: case EXIF_FORMAT_UNDEFINED: - if (ne == 1 && marker->list) + if (ne == 1 && marker->list && format == METADATA_FORMATTED) { gchar *result; guchar val; @@ -1370,7 +1364,7 @@ gchar *exif_item_get_data_as_text(ExifItem *item) if (item->data) string = g_string_append(string, (gchar *)(item->data)); break; case EXIF_FORMAT_SHORT_UNSIGNED: - if (ne == 1 && marker->list) + if (ne == 1 && marker->list && format == METADATA_FORMATTED) { gchar *result; @@ -1453,9 +1447,20 @@ gchar *exif_item_get_data_as_text(ExifItem *item) return text; } +gchar *exif_item_get_string(ExifItem *item, gint idx) +{ + return exif_item_get_data_as_text_full(item, METADATA_PLAIN); +} + +gchar *exif_item_get_data_as_text(ExifItem *item) +{ + return exif_item_get_data_as_text_full(item, METADATA_FORMATTED); +} + gint exif_item_get_integer(ExifItem *item, gint *value) { if (!item) return FALSE; + if (!item->elements) return FALSE; switch (item->format) { @@ -1514,7 +1519,7 @@ gchar *exif_get_tag_description_by_key(const gchar *key) i = 0; while (ExifKnownGPSInfoMarkersList[i].tag > 0) { - if (strcmp(key, ExifKnownGPSInfoMarkersList[i].key) == 0) return _(ExifKnownGPSInfoMarkersList[i].description); + if (strcmp(key, ExifKnownGPSInfoMarkersList[i].key) == 0) return g_strdup(_(ExifKnownGPSInfoMarkersList[i].description)); i++; } @@ -1529,7 +1534,7 @@ static void exif_write_item(FILE *f, ExifItem *item) if (text) { gchar *tag = exif_item_get_tag_name(item); - fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name, + g_fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name, tag, text); g_free(tag); } @@ -1540,8 +1545,8 @@ void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list) { if (!f || !exif) return; - fprintf(f, " tag format key value\n"); - fprintf(f, "----------------------------------------------------\n"); + g_fprintf(f, " tag format key value\n"); + g_fprintf(f, "----------------------------------------------------\n"); if (human_readable_list) { @@ -1555,7 +1560,7 @@ void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list) text = exif_get_formatted_by_key(exif, ExifFormattedList[i].key, NULL); if (text) { - fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text); + g_fprintf(f, " %9s %30s %s\n", "string", ExifFormattedList[i].key, text); } i++; } @@ -1575,18 +1580,18 @@ void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list) exif_write_item(f, item); } } - fprintf(f, "----------------------------------------------------\n"); + g_fprintf(f, "----------------------------------------------------\n"); } gboolean exif_write(ExifData *exif) { - log_printf("Not compiled with EXIF write support"); + log_printf("Not compiled with EXIF write support\n"); return FALSE; } gboolean exif_write_sidecar(ExifData *exif, gchar *path) { - log_printf("Not compiled with EXIF write support"); + log_printf("Not compiled with EXIF write support\n"); return FALSE; } @@ -1596,16 +1601,31 @@ gint exif_update_metadata(ExifData *exif, const gchar *key, const GList *values) return 0; } -GList *exif_get_metadata(ExifData *exif, const gchar *key) +GList *exif_get_metadata(ExifData *exif, const gchar *key, MetadataFormat format) { gchar *str; - ExifItem *item = exif_get_item(exif, key); + ExifItem *item; + + if (!key) return NULL; + + /* convert xmp key to exif key */ + if (strcmp(key, "Xmp.tiff.Orientation") == 0) key = "Exif.Image.Orientation"; + + if (format == METADATA_FORMATTED) + { + gchar *text; + gint key_valid; + text = exif_get_formatted_by_key(exif, key, &key_valid); + if (key_valid) return g_list_append(NULL, text); + } + + item = exif_get_item(exif, key); if (!item) return NULL; - - str = exif_item_get_string(item, 0); - + + str = exif_item_get_data_as_text_full(item, format); + if (!str) return NULL; - + return g_list_append(NULL, str); } @@ -1627,13 +1647,13 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, guchar *map_data; size_t map_len; int fd; - + if (!exif) return NULL; path = exif->path; fd = open(path, O_RDONLY); - - + + if (fd == -1) { return 0; @@ -1664,7 +1684,7 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, ud->ptr = map_data + offset; ud->map_data = map_data; ud->map_len = map_len; - + exif_unmap_list = g_list_prepend(exif_unmap_list, ud); return ud->ptr; } @@ -1677,7 +1697,7 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, void exif_free_preview(guchar *buf) { GList *work = exif_unmap_list; - + while (work) { UnmapData *ud = (UnmapData *)work->data; @@ -1692,6 +1712,9 @@ void exif_free_preview(guchar *buf) g_assert_not_reached(); } +void exif_init(void) +{ +} #endif /* not HAVE_EXIV2 */