1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
/* exif_nikon.c
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.
*/
#ifdef HAVE_LIBEXIF
#include <stdio.h>
#include <string.h>
#include <libexif/exif-data.h>
#include "feh.h"
#include "debug.h"
#include "exif.h"
#include "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
/* AFInfo2 */
/* http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#AFInfo2 */
#define EXN_CONTRAST_DETECT_AF_MAX 2
char *EXN_NikonContrastDetectAF[EXN_CONTRAST_DETECT_AF_MAX] = {"Off", "On"};
/* AFArea Mode for ContrastDetectAF Off */
#define EXN_AF_AREA_MODE_P_MAX 13
char *EXN_NikonAFAreaModePhase[EXN_AF_AREA_MODE_P_MAX] = {
"Single Area", "Dynamic Area", "Dynamic Area (closest subject)",
"Group Dynamic ", "Dynamic Area (9 points) ", "Dynamic Area (21 points)",
"Dynamic Area (51 points) ", "Dynamic Area (51 points, 3D-tracking)",
"Auto-area", "Dynamic Area (3D-tracking)", "Single Area (wide)",
"Dynamic Area (wide)", "Dynamic Area (wide, 3D-tracking)"};
/* AFArea Mode for ContrastDetectAF On */
#define EXN_AF_AREA_MODE_C_MAX 5
char *EXN_NikonAFAreaModeContr[EXN_AF_AREA_MODE_C_MAX] = {
"Contrast-detect",
"Contrast-detect (normal area)",
"Contrast-detect (wide area)",
"Contrast-detect (face priority)",
"Contrast-detect (subject tracking)"};
#define EXN_PHASE_DETECT_AF_MAX 4
char *EXN_NikonPhaseDetectAF[EXN_PHASE_DETECT_AF_MAX] = {"Off", "On (51-point)",
"On (11-point)", "On (39-point)"};
/* PrimaryAFPoint and AFPointsUsed only valid with PhaseDetectAF == On */
#define EXN_PRIM_AF_PT_51_MAX 52
char * EXN_Prim_AF_Pt_51[EXN_PRIM_AF_PT_51_MAX] = {"(none)", "C6 (Center)", "B6", "A5",
"D6", "E5", "C7", "B7", "A6", "D7", "E6", "C5", "B5", "A4", "D5", "E4", "C8", "B8",
"A7", "D8", "E7", "C9", "B9", "A8", "D9", "E8", "C10", "B10", "A9", "D10", "E9",
"C11", "B11", "D11", "C4", "B4", "A3", "D4", "E3", "C3", "B3", "A2", "D3", "E2",
"C2", "B2", "A1", "D2", "E1", "C1", "B1", "D1"};
#define EXN_PRIM_AF_PT_11_MAX 12
char * EXN_Prim_AF_Pt_11[EXN_PRIM_AF_PT_11_MAX] = {"(none)", "Center", "Top", "Bottom",
"Mid-left", "Upper-left", "Lower-left", "Far Left", "Mid-right", "Upper-right",
"Lower-right", "Far Right"};
#define EXN_PRIM_AF_PT_39_MAX 40
char * EXN_Prim_AF_Pt_39[EXN_PRIM_AF_PT_39_MAX] = {"(none)", "C6 (Center)", "B6", "A2",
"D6", "E2", "C7", "B7", "A3", "D7", "E3", "C5", "B5", "A1", "D5", "E1", "C8", "B8",
"D8", "C9", "B9", "D9", "C10", "B10", "D10", "C11", "B11", "D11", "C4", "B4", "D4",
"C3", "B3", "D3", "C2", "B2", "D2", "C1", "B1", "D1"};
static void exn_get_prim_af_pt(unsigned int phasedetectaf,
unsigned int primafpt,
char * buffer,
unsigned int maxsize);
static void exn_get_mnote_nikon_34(ExifData *ed, char * buffer, unsigned int maxsize);
static void exn_get_mnote_nikon_168(ExifData *ed, char * buffer, unsigned int maxsize);
static void exn_get_mnote_nikon_183(ExifData *ed, char * buffer, unsigned int maxsize);
/* get primary AF point */
static void exn_get_prim_af_pt(unsigned int phasedetectaf,
unsigned int primafpt,
char * buffer,
unsigned int maxsize)
{
switch(phasedetectaf)
{
case 0:
{
/* phasedetect not used. should not happen */
snprintf(buffer, maxsize, "FAIL");
return;
}
break;
case 1:
{
/* 51 pt */
if ( primafpt < EXN_PRIM_AF_PT_51_MAX )
{
snprintf(buffer, maxsize, "%s", EXN_Prim_AF_Pt_51[primafpt]);
}
return;
}
break;
case 2:
{
/* 11 pt */
if ( primafpt < EXN_PRIM_AF_PT_11_MAX )
{
snprintf(buffer, maxsize, "%s", EXN_Prim_AF_Pt_11[primafpt]);
}
return;
}
break;
case 3:
{
/* 39 pt */
if ( primafpt < EXN_PRIM_AF_PT_39_MAX )
{
snprintf(buffer, maxsize, "%s", EXN_Prim_AF_Pt_39[primafpt]);
}
return;
}
break;
default:
{
snprintf(buffer, maxsize, "?");
return;
}
break;
}
}
/* get ActiveD-Lighting (34) info */
static void exn_get_mnote_nikon_34(ExifData *ed, char * buffer, unsigned int maxsize)
{
char buf[EXIF_STD_BUF_LEN];
unsigned int data = 0;
char *answer;
buf[0] = '\0';
exif_get_mnote_tag(ed, 34, buf, sizeof(buf));
sscanf(buf, "(null): %u", &data);
switch(data)
{
case 0:
{
answer = "Off";
}
break;
case 1:
{
answer = "Low";
}
break;
case 3:
{
answer = "Normal";
}
break;
case 5:
{
answer = "High";
}
break;
case 7:
{
answer = "Extra High";
}
break;
case 65535:
{
answer = "Auto";
}
break;
default:
{
answer = "N/A"; /* this is not a nikon value */
}
}
snprintf(buffer + strlen(buffer), maxsize - strlen(buffer), "Active D-Lightning: %s\n",
answer);
}
/* get nikon Flash info: control mode (168) info */
static void exn_get_mnote_nikon_168(ExifData *ed, char * buffer, unsigned int maxsize)
{
char buf[EXIF_STD_BUF_LEN];
unsigned int version = 0;
unsigned int length = 0;
unsigned int exn_fcm = (EXN_FLASH_CONTROL_MODES_MAX-1); /* default to N/A */
/* 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]);
}
}
/* get nikon AFInfo2 (183) info */
static void exn_get_mnote_nikon_183(ExifData *ed, char * buffer, unsigned int maxsize)
{
char buf[EXIF_STD_BUF_LEN];
unsigned int contrastdetectaf = 0;
unsigned int afareamode = 0;
unsigned int phasedetectaf = 0;
unsigned int primaryafpoint = 0;
unsigned int version = 0;
unsigned int length = 0;
/* AFInfo2 */
/* libexif does not support AFInfo2 183 yet. so we have to parse the debug data :-( */
buf[0] = '\0';
exif_get_mnote_tag(ed, 183, buf, sizeof(buf));
sscanf(buf, "(null): %u bytes unknown data: 303130%02X%02X%02X%02X%02X", &length, &version,
&contrastdetectaf,
&afareamode,
&phasedetectaf,
&primaryafpoint
);
if ( ((length == 30) && (version == '0'))
&& (contrastdetectaf < EXN_CONTRAST_DETECT_AF_MAX)
&& (phasedetectaf < EXN_PHASE_DETECT_AF_MAX)
)
{
if ( (contrastdetectaf != 0) && (afareamode < EXN_AF_AREA_MODE_C_MAX) )
{
/* Contrast AF (live view) */
snprintf(buffer + strlen(buffer), maxsize - strlen(buffer),
"ContrastDetectAF: %s; AFAreaMode: %s\n",
EXN_NikonContrastDetectAF[contrastdetectaf],
EXN_NikonAFAreaModeContr[afareamode]);
}
else if ( (phasedetectaf != 0) && (afareamode < EXN_AF_AREA_MODE_P_MAX) )
{
/* Phase AF */
buf[0] = '\0';
exn_get_prim_af_pt(phasedetectaf, primaryafpoint, buf, EXIF_STD_BUF_LEN);
snprintf(buffer + strlen(buffer), maxsize - strlen(buffer),
"PhaseDetectAF: %s; AreaMode: %s; PrimaryAFPoint: %s\n",
EXN_NikonPhaseDetectAF[phasedetectaf],
EXN_NikonAFAreaModePhase[afareamode],
buf
);
}
}
}
/* get interesting nikon maker note tags in readable form */
void exn_get_mnote_nikon_tags(ExifData *ed, unsigned int tag, char * buffer, unsigned int maxsize)
{
char buf[EXIF_STD_BUF_LEN];
buf[0] = '\0';
exif_get_tag(ed, EXIF_IFD_EXIF, EXIF_TAG_FLASH, buf, sizeof(buf));
exif_trim_spaces(buf);
switch(tag)
{
/* show only if flash was used */
case 8: /* Flash Setting */
case 9: /* Flash Mode */
case 24: /* Flash exposure bracket value */
case 135: /* Flash used */
{
if ( !(strcmp("Flash: Flash did not fire\n", buf) == 0) )
{
/* show extended flash info only if flash was fired */
exif_get_mnote_tag(ed, tag, buffer + strlen(buffer), maxsize - strlen(buffer));
}
}
break;
case 34:
{
/* ActiveD-Lighting */
exn_get_mnote_nikon_34(ed, buffer + strlen(buffer), maxsize - strlen(buffer));
}
break;
case 168:
{
/* Flash info: control mode */
if ( !(strcmp("Flash: Flash did not fire\n", buf) == 0) )
{
/* show extended flash info only if flash was fired */
exn_get_mnote_nikon_168(ed, buffer + strlen(buffer), maxsize - strlen(buffer));
}
}
break;
case 183:
{
/* AFInfo 2 */
exn_get_mnote_nikon_183(ed, buffer + strlen(buffer), maxsize - strlen(buffer));
}
break;
default:
{
/* normal makernote tags without special treatment */
exif_get_mnote_tag(ed, tag, buffer + strlen(buffer), maxsize - strlen(buffer));
}
break;
}
return;
}
#endif
|