From e4483e5e25a1471728a31a18d22ba86def489509 Mon Sep 17 00:00:00 2001 From: Dennis Real Date: Sun, 5 Feb 2012 16:56:29 +0100 Subject: - improved handling of images which have exif tags but not ours - fixed uninitialized pointer in thumbnail mode - added nikon lens info if available --- src/exif.c | 8 +++++--- src/filelist.c | 5 ++++- src/imlib.c | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/exif.c b/src/exif.c index 02154e4..9d26072 100644 --- a/src/exif.c +++ b/src/exif.c @@ -45,10 +45,10 @@ static void exif_trim_spaces(char *str) { if (*str != ' ') { - end = str; + end = str+1; } } - *++end = '\0'; + *end = '\0'; } @@ -146,7 +146,7 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) { return; } - else if (ed == NULL ) + else if (ed == NULL) { snprintf(buffer, (size_t)maxsize, "%s\n", "No Exif data in file."); return; @@ -187,6 +187,8 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) { /* Digital Vari-Program */ exif_get_mnote_tag(ed, 171, buffer + strlen(buffer), maxsize - strlen(buffer)); + /* Lens */ + exif_get_mnote_tag(ed, 132, buffer + strlen(buffer), maxsize - strlen(buffer)); } } diff --git a/src/filelist.c b/src/filelist.c index 32bc2a5..9756c27 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -54,6 +54,9 @@ feh_file *feh_file_new(char *filename) else newfile->name = estrdup(filename); newfile->info = NULL; +#ifdef HAVE_LIBEXIF + newfile->ed = NULL; +#endif return(newfile); } @@ -70,7 +73,7 @@ void feh_file_free(feh_file * file) if (file->info) feh_file_info_free(file->info); #ifdef HAVE_LIBEXIF - if (file->info) + if (file->ed) exif_data_unref(file->ed); #endif free(file); diff --git a/src/imlib.c b/src/imlib.c index 0b60180..197b8f5 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -522,6 +522,8 @@ void feh_draw_exif(winwidget w) return; } + + buffer[0] = '\0'; exif_get_info(FEH_FILE(w->file->data)->ed, buffer, MAX_EXIF_DATA); fn = feh_load_font(w); -- cgit v1.2.3 From 458c5cfd464c84048c7e9027f6ef803d261742e3 Mon Sep 17 00:00:00 2001 From: Dennis Real Date: Sun, 26 Feb 2012 18:56:53 +0100 Subject: evaluate some nikon specific flash info --- src/exif.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- src/exif_nikon.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 src/exif_nikon.h (limited to 'src') diff --git a/src/exif.c b/src/exif.c index 9d26072..19b75f4 100644 --- a/src/exif.c +++ b/src/exif.c @@ -33,7 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "options.h" #include "debug.h" #include "exif.h" - +#include "exif_nikon.h" /* remove all spaces on the right end of a string */ @@ -140,7 +140,10 @@ ExifData * exif_get_data(char *path) void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) { ExifEntry *entry = NULL; - char buf[64]; + char buf[128]; + unsigned int exn_fcm = (EXN_FLASH_CONTROL_MODES_MAX-1); /* default to N/A */ + unsigned int version = 0; + unsigned int length = 0; if ( (buffer == NULL) || (maxsize == 0) ) { @@ -151,7 +154,7 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) snprintf(buffer, (size_t)maxsize, "%s\n", "No Exif data in file."); return; } - else if ( ed != NULL ) + else { /* normal exif tags */ exif_get_tag(ed, EXIF_IFD_0, EXIF_TAG_MAKE, buffer, maxsize); @@ -185,10 +188,49 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize) /* Nikon */ if ( strcmp(buf, "Nikon") != 0 ) { - /* Digital Vari-Program */ - exif_get_mnote_tag(ed, 171, buffer + strlen(buffer), maxsize - strlen(buffer)); + /* this is a nikon camera */ + + buf[0] = '\0'; + exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FLASH, buf, sizeof(buf)); + exif_trim_spaces(buf); + + if ( !(strcmp("Flash: Flash did not fire\n", buf) == 0) ) + { + /* extended flash info if it was fired */ + + /* Flash Setting */ + exif_get_mnote_tag(ed, 8, buffer + strlen(buffer), maxsize - strlen(buffer)); + /* Flash Mode */ + exif_get_mnote_tag(ed, 9, buffer + strlen(buffer), maxsize - strlen(buffer)); + /* flash exposure bracket value */ + exif_get_mnote_tag(ed, 24, buffer + strlen(buffer), maxsize - strlen(buffer)); + /* Flash used */ + exif_get_mnote_tag(ed, 135, buffer + strlen(buffer), maxsize - strlen(buffer)); + + /* Flash info: control mode. */ + /* libexif does not support flash info 168 yet. so we have to parse the debug data :-( */ + buf[0] = '\0'; + exif_get_mnote_tag(ed, 168, buf, sizeof(buf)); + sscanf(buf, "(null): %u bytes unknown data: 303130%02X%*10s%02X", &length, &version, &exn_fcm); + exn_fcm = exn_fcm & EXN_FLASH_CONTROL_MODE_MASK; + + if ( (exn_fcm < EXN_FLASH_CONTROL_MODES_MAX) + && ( ((length == 22) && (version == '3')) /* Nikon FlashInfo0103 */ + || ((length == 22) && (version == '4')) /* Nikon FlashInfo0104 */ + || ((length == 21) && (version == '2')) /* Nikon FlashInfo0102 */ + || ((length == 19) && (version == '0')) /* Nikon FlashInfo0100 */ + ) + ) + { + snprintf(buffer + strlen(buffer), maxsize - strlen(buffer), "NikonFlashControlMode: %s\n", + EXN_NikonFlashControlModeValues[exn_fcm]); + } + } /* Lens */ exif_get_mnote_tag(ed, 132, buffer + strlen(buffer), maxsize - strlen(buffer)); + /* Digital Vari-Program */ + exif_get_mnote_tag(ed, 171, buffer + strlen(buffer), maxsize - strlen(buffer)); + } } diff --git a/src/exif_nikon.h b/src/exif_nikon.h new file mode 100644 index 0000000..e2baf0d --- /dev/null +++ b/src/exif_nikon.h @@ -0,0 +1,41 @@ +/* exif_nikon.h + +Copyright (C) 2012 Dennis Real. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies of the Software and its documentation and acknowledgment shall be +given in the documentation and software packages that this Software was +used. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +#ifndef EXIF_NIKON_H +#define EXIF_NIKON_H + +/* Flash control mode */ +/* http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#FlashControlMode */ +#define EXN_FLASH_CONTROL_MODES_MAX 9 +char *EXN_NikonFlashControlModeValues[EXN_FLASH_CONTROL_MODES_MAX] = {"Off", + "iTTL-BL", "iTTL", "Auto Aperture", + "Automatic", "GN (distance priority)", + "Manual", "Repeating Flash", + "N/A" /* "N/A" is not a nikon setting */ + }; + +#define EXN_FLASH_CONTROL_MODE_MASK 0x7F + +#endif -- cgit v1.2.3