summaryrefslogtreecommitdiff
path: root/src/libexif/canon/mnote-canon-entry.c
blob: 5fa499143640258e74f14fc359f74001ccbbe17b (plain)
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/* mnote-canon-entry.c
 *
 * Copyright © 2002 Lutz Müller <lutz@users.sourceforge.net>
 * Copyright © 2003 Matthieu Castet <mat-c@users.sourceforge.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include "mnote-canon-entry.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <libexif/exif-format.h>
#include <libexif/exif-utils.h>
#include <libexif/i18n.h>

/* #define DEBUG */

#undef  MIN
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))

#define CF(format,target,v,maxlen)                              \
{                                                               \
        if (format != target) {                                 \
                snprintf (v, maxlen,                            \
                        _("Invalid format '%s', "               \
                        "expected '%s'."),                      \
                        exif_format_get_name (format),          \
                        exif_format_get_name (target));         \
                break;                                          \
        }                                                       \
}

#define CC(number,target,v,maxlen)                                      \
{                                                                       \
        if (number != target) {                                         \
                snprintf (v, maxlen,                                    \
                        _("Invalid number of components (%i, "          \
                        "expected %i)."), (int) number, (int) target);  \
                break;                                                  \
        }                                                               \
}
#define CC2(number,t1,t2,v,maxlen)                                      \
{                                                                       \
	if ((number != t1) && (number != t2)) {                         \
		snprintf (v, maxlen,                                    \
			_("Invalid number of components (%i, "          \
			"expected %i or %i)."), (int) number,		\
			(int) t1, (int) t2);  				\
		break;                                                  \
	}                                                               \
}

char *
mnote_canon_entry_get_value (const MnoteCanonEntry *entry, char *val, unsigned int maxlen)
{
    char buf[128];
    ExifLong vl;
    ExifShort vs, n;
    int i;
    unsigned char *data = entry->data;

    if (!entry) return NULL;

    memset (val, 0, maxlen);
    maxlen--;

	switch (entry->tag) {
	case MNOTE_CANON_TAG_SETTINGS_1:
		CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
		n = exif_get_short (data, entry->order) / 2;
		data += 2;
		CC (entry->components, n, val, maxlen);
		for (i = 1; i < n; i++) {
		    vs = exif_get_short (data, entry->order);
		    data += 2;
		    switch (i) {
		    case 1:
			strncpy (val, _("Macro mode : "), maxlen);
			switch (vs) {
			case 1:
			    strncat (val, _("Macro"), maxlen - strlen(val));
			    break;
			case 2:
			    strncat (val, _("Normal"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 2:
			if (vs) {
				snprintf (buf, sizeof (buf),
					_(" / Self Timer : %i (ms)"), vs*100);
				strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 4:
			strncat (val, _(" / Flash mode : "), maxlen - strlen(val));
			switch (vs) {
			case 0:
			    strncat (val, _("Flash not fired"), maxlen - strlen(val));
			    break;
			case 1:
			    strncat (val, _("auto"), maxlen - strlen(val));
			    break;
			case 2:
			    strncat (val, _("on"), maxlen - strlen(val));
			    break;
			case 3:
			    strncat (val, _("red eyes reduction"), maxlen - strlen(val));
			    break;
			case 4:
			    strncat (val, _("slow synchro"), maxlen - strlen(val));
			    break;
			case 5:
			    strncat (val, _("auto + red eyes reduction"), maxlen - strlen(val));
			    break;
			case 6:
			    strncat (val, _("on + red eyes reduction"), maxlen - strlen(val));
			    break;
			case 16:
			    strncat (val, _("external"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 5:
			strncat (val, _(" / Continuous drive mode : "), maxlen - strlen(val));
			switch (vs) {
			case 0:
			    strncat (val, _("single or timer"), maxlen - strlen(val));
			    break;
			case 1:
			    strncat (val, _("continuous"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 7:
			strncat (val, _(" / Focus mode : "), maxlen - strlen(val));
			switch (vs) {
			case 0:
			    strncat (val, _("One-Shot"), maxlen - strlen(val));
			    break;
			case 1:
			    strncat (val, _("AI Servo"), maxlen - strlen(val));
			    break;
			case 2:
			    strncat (val, _("AI Focus"), maxlen - strlen(val));
			    break;
			case 3:
			    strncat (val, _("MF"), maxlen - strlen(val));
			    break;
			case 4:
			    strncat (val, _("Single"), maxlen - strlen(val));
			    break;
			case 5:
			    strncat (val, _("Continuous"), maxlen - strlen(val));
			    break;
			case 6:
			    strncat (val, _("MF"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 10:
			strncat (val, _(" / Image size : "), maxlen - strlen(val));
			switch (vs) {
			case 0:
			    strncat (val, _("Large"), maxlen - strlen(val));
			    break;
			case 1:
			    strncat (val, _("Medium"), maxlen - strlen(val));
			    break;
			case 2:
			    strncat (val, _("Small"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 11:
			strncat (val, _(" / Easy shooting mode : "), maxlen - strlen(val));
			switch (vs) {
			case 0:
			    strncat (val, _("Full Auto"), maxlen - strlen(val));
			    break;
			case 1:
			    strncat (val, _("Manual"), maxlen - strlen(val));
			    break;
			case 2:
			    strncat (val, _("Landscape"), maxlen - strlen(val));
			    break;
			case 3:
			    strncat (val, _("Fast Shutter"), maxlen - strlen(val));
			    break;
			case 4:
			    strncat (val, _("Slow Shutter"), maxlen - strlen(val));
			    break;
			case 5:
			    strncat (val, _("Night"), maxlen - strlen(val));
			    break;
			case 6:
			    strncat (val, _("Black & White"), maxlen - strlen(val));
			    break;
			case 7:
			    strncat (val, _("Sepia"), maxlen - strlen(val));
			    break;
			case 8:
			    strncat (val, _("Portrait"), maxlen - strlen(val));
			    break;
			case 9:
			    strncat (val, _("Sports"), maxlen - strlen(val));
			    break;
			case 10:
			    strncat (val, _("Macro / Close-Up"), maxlen - strlen(val));
			    break;
			case 11:
			    strncat (val, _("Pan Focus"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 13:
			strncat (val, _(" / Contrast : "), maxlen - strlen(val));
			switch (vs) {
			case 0xffff:
			    strncat (val, _("Low"), maxlen - strlen(val));
			    break;
			case 0x0000:
			    strncat (val, _("Normal"), maxlen - strlen(val));
			    break;
			case 0x0001:
			    strncat (val, _("High"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 14:
			strncat (val, _(" / Saturation : "), maxlen - strlen(val));
			switch (vs) {
			case 0xffff:
			    strncat (val, _("Low"), maxlen - strlen(val));
			    break;
			case 0x0000:
			    strncat (val, _("Normal"), maxlen - strlen(val));
			    break;
			case 0x0001:
			    strncat (val, _("High"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 15:
			strncat (val, _(" / Sharpness : "), maxlen - strlen(val));
			switch (vs) {
			case 0xffff:
			    strncat (val, _("Low"), maxlen - strlen(val));
			    break;
			case 0x0000:
			    strncat (val, _("Normal"), maxlen - strlen(val));
			    break;
			case 0x0001:
			    strncat (val, _("High"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 16:
			if (vs) {
			    strncat (val, _(" / ISO : "), maxlen - strlen(val));
			    switch (vs) {
			    case 15:
				strncat (val, _("auto"), maxlen - strlen(val));
				break;
			    case 16:
				strncat (val, _("50"), maxlen - strlen(val));
				break;
			    case 17:
				strncat (val, _("100"), maxlen - strlen(val));
				break;
			    case 18:
				strncat (val, _("200"), maxlen - strlen(val));
				break;
			    case 19:
				strncat (val, _("400"), maxlen - strlen(val));
				break;
			    default:
				snprintf (buf, sizeof (buf), _("%i???"), vs);
				strncat (val, buf, maxlen - strlen(val));
			    }
			    break;
			}
		    case 17:
			strncat (val, _(" / Metering mode : "), maxlen - strlen(val));
			switch (vs) {
			case 3:
			    strncat (val, _("Evaluative"), maxlen - strlen(val));
			    break;
			case 4:
			    strncat (val, _("Partial"), maxlen - strlen(val));
			    break;
			case 5:
			    strncat (val, _("Center-weighted"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("%i???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 19:
			strncat (val, _(" / AF point selected : "), maxlen - strlen(val));
			switch (vs) {
			case 0x3000:
			    strncat (val, _("none (MF)"), maxlen - strlen(val));
			    break;
			case 0x3001:
			    strncat (val, _("auto-selected"), maxlen - strlen(val));
			    break;
			case 0x3002:
			    strncat (val, _("right"), maxlen - strlen(val));
			    break;
			case 0x3003:
			    strncat (val, _("center"), maxlen - strlen(val));
			    break;
			case 0x3004:
			    strncat (val, _("left"), maxlen - strlen(val));
			    break;
			default:
			    snprintf (buf, sizeof (buf), _("0x%x???"), vs);
			    strncat (val, buf, maxlen - strlen(val));
			}
			break;
		    case 20:
				strncat (val, _(" / Exposure mode : "), maxlen - strlen(val));
				switch (vs) {
           		case 0:
					strncat (val, _("Easy shooting"), maxlen - strlen(val));
                    break;
                case 1:
					strncat (val, _("Program"), maxlen - strlen(val));
					break;
				case 2:
					strncat (val, _("Tv-priority"), maxlen - strlen(val));
					break;
				case 3:
					strncat (val, _("Av-priority"), maxlen - strlen(val));
					break;
				case 4:
					strncat (val, _("Manual"), maxlen - strlen(val));
					break;
				case 5:
					strncat (val, _("A-DEP"), maxlen - strlen(val));
					break;
				default:
					snprintf (buf, sizeof (buf), _("%i???"), vs);
					strncat (val, buf, maxlen - strlen(val));
                }
				break;
			case 23:
				snprintf (buf, sizeof (buf), _(" / long focal length of lens (in focal units) : %u"), vs);
				strncat (val, buf, maxlen - strlen(val));
				break;
			case 24:
				snprintf (buf, sizeof (buf), _(" / short focal length of lens (in focal units) : %u"), vs);
				strncat (val, buf, maxlen - strlen(val));
				break;
			case 25:
				snprintf (buf, sizeof (buf), _(" / focal units per mm : %u"), vs);
				strncat (val, buf, maxlen - strlen(val));
				break;
			case 29:
				strncat (val, _(" / Flash details : "), maxlen - strlen(val));
				if ((vs>>14)&1)
					strncat (val, _("External E-TTL"), maxlen - strlen(val));
				if ((vs>>13)&1)
					strncat (val, _("Internal flash"), maxlen - strlen(val));
				if ((vs>>11)&1)
					strncat (val, _("FP sync used"), maxlen - strlen(val));
				if ((vs>>4)&1)
					strncat (val, _("FP sync enabled"), maxlen - strlen(val));
#ifdef DEBUG
				printf ("Value29=0x%08x\n", vs);
#endif
				break;
			case 32:
				strncat (val, _(" / Focus mode2 : "), maxlen - strlen(val));
				switch (vs) {
				case 0:
					strncat (val, _("Single"), maxlen - strlen(val));
					break;
				case 1:
					strncat (val, _("Continuous"), maxlen - strlen(val));
					break;
				default:
					snprintf (buf, sizeof (buf), _("%i???"), vs);
					strncat (val, buf, maxlen - strlen(val));
				}
				break;
#ifdef DEBUG
			default:
                        	printf ("Value%d=%d\n", i, vs);
#endif
			}
		}

                break;

	case MNOTE_CANON_TAG_SETTINGS_2:
		CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
		n = exif_get_short (data, entry->order)/2;
		data += 2;
		CC (entry->components, n, val, maxlen);
#ifdef DEBUG
		printf ("Setting2 size %d %d\n",n,entry->size);
#endif
		for (i=1;i<n;i++)
		{
			vs = exif_get_short (data, entry->order);
			data+=2;
			switch(i) {
			case 7:
				strncpy (val, _("White balance : "), maxlen - strlen(val));
				switch (vs) {
				case 0:
					strncat (val, _("Auto"), maxlen - strlen(val));
					break;
				case 1:
					strncat (val, _("Sunny"), maxlen - strlen(val));
					break;
				case 2:
					strncat (val, _("Cloudy"), maxlen - strlen(val));
					break;
				case 3:
					strncat (val, _("Tungsten"), maxlen - strlen(val));
					break;
				case 4:
					strncat (val, _("Flourescent"), maxlen - strlen(val));
					break;
				case 5:
					strncat (val, _("Flash"), maxlen - strlen(val));
					break;
				case 6:
					strncat (val, _("Custom"), maxlen - strlen(val));
					break;
				default:
					snprintf (buf, sizeof (buf), _("%i???"), vs);
					strncat (val, buf, maxlen - strlen(val));
				}
				break;
			case 9:
				snprintf (buf, sizeof (buf), _(" / Sequence number : %u"), vs);
				strncat (val, buf, maxlen - strlen(val));
				break;
			case 14:
				if (vs>>12)
				{
					strncat (val, _(" / AF point used : "), maxlen - strlen(val));
					if (vs&1)
						strncat (val, _("Right"), maxlen - strlen(val));
					if ((vs>>1)&1)
						strncat (val, _("Center"), maxlen - strlen(val));
					if ((vs>>2)&1)
						strncat (val, _("Left"), maxlen - strlen(val));
					snprintf (buf, sizeof (buf), _(" (%u available focus point)"), vs>>12);
					strncat (val, buf, maxlen - strlen(val));
				}
#ifdef DEBUG
					printf ("0x%08x\n", vs);
#endif
				break;
			case 15:
				snprintf (buf, sizeof (buf), _(" / Flash bias : %.2f EV"), vs/32.0);
				strncat (val, buf, maxlen - strlen(val));

				break;
			case 19:
				snprintf (buf, sizeof (buf), _(" / Subject Distance (mm) : %u"), vs);
				strncat (val, buf, maxlen - strlen(val));
				break;
#ifdef DEBUG
			default:
				printf ("Value%d=%d\n", i, vs);
#endif
			}
		}

		break;

	case MNOTE_CANON_TAG_IMAGE_TYPE:
	case MNOTE_CANON_TAG_OWNER:
		CF (entry->format, EXIF_FORMAT_ASCII, val, maxlen);
		CC (entry->components, 32, val, maxlen);
		strncpy (val, data, MIN (entry->size, maxlen));
		break;

	case MNOTE_CANON_TAG_FIRMWARE:
		CF (entry->format, EXIF_FORMAT_ASCII, val, maxlen);
		CC2 (entry->components, 24, 32, val, maxlen);
		strncpy (val, data, MIN (entry->size, maxlen));
		break;

	case MNOTE_CANON_TAG_IMAGE_NUMBER:
		CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
		CC (entry->components, 1, val, maxlen);
		vl = exif_get_long (data, entry->order);
		snprintf (val, maxlen, "%03lu-%04lu",
				(unsigned long) vl/10000,
				(unsigned long) vl%10000);
		break;

	case MNOTE_CANON_TAG_SERIAL_NUMBER:
		CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
		CC (entry->components, 1, val, maxlen);
		vl = exif_get_long (data, entry->order);
		snprintf (val, maxlen, "%04X-%05d", (int)vl>>16,(int)vl&0xffff);
		break;

	case MNOTE_CANON_TAG_CUSTOM_FUNCS:
		CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
		n = exif_get_short (data, entry->order)/2;
		data+=2;
		CC (entry->components, n, val, maxlen);
#ifdef DEBUG
		printf ("Custom Function size %d %d\n",n,entry->size);
#endif
		for (i=1;i<n;i++)
		{
			vs = exif_get_short (data, entry->order);
			data += 2;
			snprintf (buf, sizeof(buf), _("C.F%d : %u"), i, vs);
			strncat (val, buf, maxlen - strlen(val));
		}
		break;

	default:
#ifdef DEBUG
		if (entry->format == EXIF_FORMAT_SHORT)
		for(i=0;i<entry->components;i++) {
			vs = exif_get_short (data, entry->order);
			data+=2;
			printf ("Value%d=%d\n", i, vs);
		}
		else if (entry->format == EXIF_FORMAT_LONG)
		for(i=0;i<entry->components;i++) {
			vl = exif_get_long (data, entry->order);
			data+=4;
			printf ("Value%d=%d\n", i, vs);
		}
		else if (entry->format == EXIF_FORMAT_ASCII)
		    strncpy (val, data, MIN (entry->size, maxlen));
#endif
		break;
        }

        return val;
}