summaryrefslogtreecommitdiff
path: root/src/exif.c
diff options
context:
space:
mode:
authorDennis Real <github@tildepipe.org>2012-03-21 19:47:15 +0100
committerDennis Real <github@tildepipe.org>2012-03-21 19:47:15 +0100
commite401bd9c78a82b8290ec524e56b7c832631725e6 (patch)
treeec3203018c9dd2edb0d6cf2971c16b6b43c2fbfe /src/exif.c
parent39cbd1ed2b6693beea5e974a6ae83207c6e9a826 (diff)
1. Own module for nikon maker notes
2. Support for AFInfo2
Diffstat (limited to 'src/exif.c')
-rw-r--r--src/exif.c99
1 files changed, 23 insertions, 76 deletions
diff --git a/src/exif.c b/src/exif.c
index 6f6440f..91e1735 100644
--- a/src/exif.c
+++ b/src/exif.c
@@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdio.h>
#include <string.h>
#include <libexif/exif-data.h>
+#include <limits.h>
#include "feh.h"
#include "options.h"
@@ -36,15 +37,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "exif_nikon.h"
#include "exif_cfg.h"
-static void exif_trim_spaces(char *str);
-static void exif_get_tag(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize);
-static void exif_get_tag_content(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize);
-static void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsigned int maxsize);
-static void exif_get_mnote_nikon_tags(ExifData *ed, char * buffer, unsigned int maxsize);
-static void exif_get_gps_coords(ExifData * ed, char *buffer, unsigned int maxsize);
/* remove all spaces on the right end of a string */
-static void exif_trim_spaces(char *str)
+void exif_trim_spaces(char *str)
{
char *end;
@@ -52,20 +47,21 @@ static void exif_trim_spaces(char *str)
{
if (*str != ' ')
{
- end = str+1;
+ end = str + 1;
}
}
*end = '\0';
}
+
/* show given exif tag content with tag name */
-static void exif_get_tag(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize)
+void exif_get_tag(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize)
{
char s[EXIF_MAX_DATA];
ExifEntry *entry = NULL;
- if ( (d != NULL) && (buffer != NULL) && (maxsize>0) )
+ if ( (d != NULL) && (buffer != NULL) && (maxsize > 0) )
{
entry = exif_content_get_entry(d->ifd[ifd], tag);
if (entry != NULL)
@@ -87,12 +83,12 @@ static void exif_get_tag(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, un
/* show given exif tag content without tag name */
-static void exif_get_tag_content(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize)
+void exif_get_tag_content(ExifData *d, ExifIfd ifd, ExifTag tag, char* buffer, unsigned int maxsize)
{
char s[EXIF_MAX_DATA];
ExifEntry *entry = NULL;
- if ( (d != NULL) && (buffer != NULL) && (maxsize>0) )
+ if ( (d != NULL) && (buffer != NULL) && (maxsize > 0) )
{
entry = exif_content_get_entry(d->ifd[ifd], tag);
if (entry != NULL)
@@ -104,7 +100,7 @@ static void exif_get_tag_content(ExifData *d, ExifIfd ifd, ExifTag tag, char* bu
exif_trim_spaces(s);
if (*s != '\0')
{
- D(("%s", exif_tag_get_name_in_ifd(tag,ifd), s));
+ D(("%s - %s\n", exif_tag_get_name_in_ifd(tag,ifd), s));
snprintf(buffer, (size_t)maxsize, "%s", s);
}
}
@@ -115,7 +111,7 @@ static void exif_get_tag_content(ExifData *d, ExifIfd ifd, ExifTag tag, char* bu
/* Show the given MakerNote tag if it exists */
-static void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsigned int maxsize)
+void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsigned int maxsize)
{
ExifMnoteData *mn = NULL;
int i, num;
@@ -137,6 +133,11 @@ static void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsi
/* Loop through all MakerNote tags, searching for the desired one */
for (i=0; i < num; ++i)
{
+ D(("%d/%d %d 0x%2x %s; %s\n", i, num, exif_mnote_data_get_id(mn, i),
+ exif_mnote_data_get_id(mn, i),
+ exif_mnote_data_get_name(mn,i),
+ exif_mnote_data_get_title(mn, i) ));
+
if (exif_mnote_data_get_id(mn, i) == tag)
{
if (exif_mnote_data_get_value(mn, i, buf, sizeof(buf)))
@@ -145,6 +146,7 @@ static void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsi
exif_trim_spaces(buf);
if (*buf != '\0')
{
+ D(("%s\n", buf));
snprintf(buffer, (size_t)maxsize, "%s: %s\n", exif_mnote_data_get_title(mn, i), buf);
}
}
@@ -155,63 +157,8 @@ static void exif_get_mnote_tag(ExifData *d, unsigned int tag, char* buffer, unsi
-/* get interesting nikon maker note tags in readable form */
-static void exif_get_mnote_nikon_tags(ExifData *ed, char * buffer, unsigned int maxsize)
-{
- char buf[EXIF_STD_BUF_LEN];
- unsigned int exn_fcm = (EXN_FLASH_CONTROL_MODES_MAX-1); /* default to N/A */
- unsigned int version = 0;
- unsigned int length = 0;
-
- 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) )
- {
- /* show extended flash info if flash 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));
-
- return;
-}
-
-
-
/* get gps coordinates if available */
-static void exif_get_gps_coords(ExifData * ed, char *buffer, unsigned int maxsize)
+void exif_get_gps_coords(ExifData * ed, char *buffer, unsigned int maxsize)
{
char buf[EXIF_STD_BUF_LEN];
@@ -297,7 +244,7 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize)
{
ExifEntry *entry = NULL;
char buf[EXIF_STD_BUF_LEN];
- int i = 0;
+ unsigned short int i = 0;
if ( (buffer == NULL) || (maxsize == 0) )
{
@@ -310,14 +257,14 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize)
}
else
{
- /* normal exif tags */
- while ( Exif_tag_list[i].ifd != EXIF_IFD_COUNT )
+ /* show normal exif tags. list must be defined in exif_cfg.h */
+ while ( (Exif_tag_list[i].ifd != EXIF_IFD_COUNT) && (i < USHRT_MAX) )
{
exif_get_tag(ed, Exif_tag_list[i].ifd, Exif_tag_list[i].tag, buffer + strlen(buffer), maxsize - strlen(buffer));
i++;
}
- /* vendor specific makernote tags */
+ /* show vendor specific makernote tags */
entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_MAKE);
if (entry != NULL)
{
@@ -332,14 +279,14 @@ void exif_get_info(ExifData * ed, char *buffer, unsigned int maxsize)
)
{
/* this is a nikon camera */
- exif_get_mnote_nikon_tags(ed, buffer + strlen(buffer), maxsize - strlen(buffer));
+ exn_get_mnote_nikon_tags(ed, buffer + strlen(buffer), maxsize - strlen(buffer));
}
}
}
- /* gps info */
+ /* show gps coordinates */
exif_get_gps_coords(ed, buffer + strlen(buffer), maxsize - strlen(buffer));
}