EXIF library (libexif) Internals  0.6.24
mnote-canon-entry.c
Go to the documentation of this file.
1 /* mnote-canon-entry.c
2  *
3  * Copyright (c) 2002 Lutz Mueller <lutz@users.sourceforge.net>
4  * Copyright (c) 2003 Matthieu Castet <mat-c@users.sourceforge.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301 USA.
20  */
21 
22 #include "config.h"
23 #include "mnote-canon-entry.h"
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <math.h>
29 
30 #include <libexif/exif-format.h>
31 #include <libexif/exif-utils.h>
32 #include <libexif/i18n.h>
33 
34 #define CF(format,target,v,maxlen) \
35 { \
36  if (format != target) { \
37  snprintf (v, maxlen, \
38  _("Invalid format '%s', " \
39  "expected '%s'."), \
40  exif_format_get_name (format), \
41  exif_format_get_name (target)); \
42  break; \
43  } \
44 }
45 
46 #define CC(number,target,v,maxlen) \
47 { \
48  if (number != target) { \
49  snprintf (v, maxlen, \
50  _("Invalid number of components (%i, " \
51  "expected %i)."), (int) number, (int) target); \
52  break; \
53  } \
54 }
55 #define CC2(number,t1,t2,v,maxlen) \
56 { \
57  if ((number != t1) && (number != t2)) { \
58  snprintf (v, maxlen, \
59  _("Invalid number of components (%i, " \
60  "expected %i or %i)."), (int) number, \
61  (int) t1, (int) t2); \
62  break; \
63  } \
64 }
65 
66 #define UNDEFINED 0xFF
67 
68 static const struct canon_entry_table_t {
69  unsigned int subtag;
71  const char *name;
72 } entries_settings_1 [] = {
73 #ifndef NO_VERBOSE_TAG_DATA
74  { 0, 1, N_("Macro")},
75  { 0, 2, N_("Normal")},
76  { 2, 1, N_("Economy")},
77  { 2, 2, N_("Normal")},
78  { 2, 3, N_("Fine")},
79  { 2, 4, N_("RAW")},
80  { 2, 5, N_("Superfine")},
81  { 3, 0, N_("Off")},
82  { 3, 1, N_("Auto")},
83  { 3, 2, N_("On")},
84  { 3, 3, N_("Red-eye reduction")},
85  { 3, 4, N_("Slow synchro")},
86  { 3, 5, N_("Auto, red-eye reduction")},
87  { 3, 6, N_("On, red-eye reduction")},
88  { 3, 16, N_("External flash")},
89  { 4, 0, N_("Single")},
90  { 4, 1, N_("Continuous")},
91  { 4, 2, N_("Movie")},
92  { 4, 3, N_("Continuous, speed priority")},
93  { 4, 4, N_("Continuous, low")},
94  { 4, 5, N_("Continuous, high")},
95  { 6, 0, N_("One-shot AF")},
96  { 6, 1, N_("AI servo AF")},
97  { 6, 2, N_("AI focus AF")},
98  { 6, 3, N_("Manual focus")},
99  { 6, 4, N_("Single")},
100  { 6, 5, N_("Continuous")},
101  { 6, 6, N_("Manual focus")},
102  { 6, 16, N_("Pan focus")},
103  { 8, 1, N_("JPEG")},
104  { 8, 2, N_("CRW+THM")},
105  { 8, 3, N_("AVI+THM")},
106  { 8, 4, N_("TIF")},
107  { 8, 5, N_("TIF+JPEG")},
108  { 8, 6, N_("CR2")},
109  { 8, 7, N_("CR2+JPEG")},
110  { 9, 0, N_("Large")},
111  { 9, 1, N_("Medium")},
112  { 9, 2, N_("Small")},
113  { 9, 5, N_("Medium 1")},
114  { 9, 6, N_("Medium 2")},
115  { 9, 7, N_("Medium 3")},
116  { 9, 8, N_("Postcard")},
117  { 9, 9, N_("Widescreen")},
118  {10, 0, N_("Full auto")},
119  {10, 1, N_("Manual")},
120  {10, 2, N_("Landscape")},
121  {10, 3, N_("Fast shutter")},
122  {10, 4, N_("Slow shutter")},
123  {10, 5, N_("Night")},
124  {10, 6, N_("Grayscale")},
125  {10, 7, N_("Sepia")},
126  {10, 8, N_("Portrait")},
127  {10, 9, N_("Sports")},
128  {10, 10, N_("Macro")},
129  {10, 11, N_("Black & white")},
130  {10, 12, N_("Pan focus")},
131  {10, 13, N_("Vivid")},
132  {10, 14, N_("Neutral")},
133  {10, 15, N_("Flash off")},
134  {10, 16, N_("Long shutter")},
135  {10, 17, N_("Super macro")},
136  {10, 18, N_("Foliage")},
137  {10, 19, N_("Indoor")},
138  {10, 20, N_("Fireworks")},
139  {10, 21, N_("Beach")},
140  {10, 22, N_("Underwater")},
141  {10, 23, N_("Snow")},
142  {10, 24, N_("Kids & pets")},
143  {10, 25, N_("Night snapshot")},
144  {10, 26, N_("Digital macro")},
145  {10, 27, N_("My colors")},
146  {10, 28, N_("Still image")},
147  {10, 30, N_("Color accent")},
148  {10, 31, N_("Color swap")},
149  {10, 32, N_("Aquarium")},
150  {10, 33, N_("ISO 3200")},
151  {11, 0, N_("None")},
152  {11, 1, N_("2x")},
153  {11, 2, N_("4x")},
154  {11, 3, N_("Other")},
155  {12, 0x0000, N_("Normal")},
156  {12, 0x0001, N_("High")},
157  {12, 0xffff, N_("Low")},
158  {13, 0x0000, N_("Normal")},
159  {13, 0x0001, N_("High")},
160  {13, 0xffff, N_("Low")},
161  {14, 0x0000, N_("Normal")},
162  {14, 0x0001, N_("High")},
163  {14, 0xffff, N_("Low")},
164  {15, 14, N_("Auto high")},
165  {15, 15, N_("Auto")},
166  {15, 16, N_("50")},
167  {15, 17, N_("100")},
168  {15, 18, N_("200")},
169  {15, 19, N_("400")},
170  {15, 20, N_("800")},
171  {16, 0, N_("Default")},
172  {16, 1, N_("Spot")},
173  {16, 2, N_("Average")},
174  {16, 3, N_("Evaluative")},
175  {16, 4, N_("Partial")},
176  {16, 5, N_("Center-weighted average")},
177  {17, 0, N_("Manual")},
178  {17, 1, N_("Auto")},
179  {17, 2, N_("Not known")},
180  {17, 3, N_("Macro")},
181  {17, 4, N_("Very close")},
182  {17, 5, N_("Close")},
183  {17, 6, N_("Middle range")},
184  {17, 7, N_("Far range")},
185  {17, 8, N_("Pan focus")},
186  {17, 9, N_("Super macro")},
187  {17, 10, N_("Infinity")},
188  {18, 0x2005, N_("Manual AF point selection")},
189  {18, 0x3000, N_("None (MF)")},
190  {18, 0x3001, N_("Auto-selected")},
191  {18, 0x3002, N_("Right")},
192  {18, 0x3003, N_("Center")},
193  {18, 0x3004, N_("Left")},
194  {18, 0x4001, N_("Auto AF point selection")},
195  {19, 0, N_("Easy shooting")},
196  {19, 1, N_("Program")},
197  {19, 2, N_("Tv-priority")},
198  {19, 3, N_("Av-priority")},
199  {19, 4, N_("Manual")},
200  {19, 5, N_("A-DEP")},
201  {19, 6, N_("M-DEP")},
202  {21, 1, N_("Canon EF 50mm f/1.8")},
203  {21, 2, N_("Canon EF 28mm f/2.8")},
204  {21, 4, N_("Sigma UC Zoom 35-135mm f/4-5.6")},
205  {21, 6, N_("Tokina AF193-2 19-35mm f/3.5-4.5")},
206  {21, 7, N_("Canon EF 100-300mm F5.6L")},
207  {21, 10, N_("Sigma 50mm f/2.8 EX or 28mm f/1.8")},
208  {21, 11, N_("Canon EF 35mm f/2")},
209  {21, 13, N_("Canon EF 15mm f/2.8")},
210  {21, 21, N_("Canon EF 80-200mm f/2.8L")},
211  {21, 22, N_("Tokina AT-X280AF PRO 28-80mm F2.8 Aspherical")},
212  {21, 26, N_("Cosina 100mm f/3.5 Macro AF")},
213  {21, 28, N_("Tamron AF Aspherical 28-200mm f/3.8-5.6")},
214  {21, 29, N_("Canon EF 50mm f/1.8 MkII")},
215  {21, 31, N_("Tamron SP AF 300mm f/2.8 LD IF")},
216  {21, 32, N_("Canon EF 24mm f/2.8 or Sigma 15mm f/2.8 EX Fisheye")},
217  {21, 37, N_("Canon EF 35-80mm f/4-5.6")},
218  {21, 39, N_("Canon EF 75-300mm f/4-5.6")},
219  {21, 40, N_("Canon EF 28-80mm f/3.5-5.6")},
220  {21, 43, N_("Canon EF 28-105mm f/4-5.6")},
221  {21, 45, N_("Canon EF-S 18-55mm f/3.5-5.6")},
222  {21, 52, N_("Canon EF-S 18-55mm f/3.5-5.6 IS II")},
223  {21, 124, N_("Canon MP-E 65mm f/2.8 1-5x Macro Photo")},
224  {21, 125, N_("Canon TS-E 24mm f/3.5L")},
225  {21, 126, N_("Canon TS-E 45mm f/2.8")},
226  {21, 127, N_("Canon TS-E 90mm f/2.8")},
227  {21, 130, N_("Canon EF 50mm f/1.0L")},
228  {21, 131, N_("Sigma 17-35mm f2.8-4 EX Aspherical HSM")},
229  {21, 134, N_("Canon EF 600mm f/4L IS")},
230  {21, 135, N_("Canon EF 200mm f/1.8L")},
231  {21, 136, N_("Canon EF 300mm f/2.8L")},
232  {21, 137, N_("Canon EF 85mm f/1.2L")},
233  {21, 139, N_("Canon EF 400mm f/2.8L")},
234  {21, 141, N_("Canon EF 500mm f/4.5L")},
235  {21, 142, N_("Canon EF 300mm f/2.8L IS")},
236  {21, 143, N_("Canon EF 500mm f/4L IS")},
237  {21, 149, N_("Canon EF 100mm f/2")},
238  {21, 150, N_("Sigma 20mm EX f/1.8")},
239  {21, 151, N_("Canon EF 200mm f/2.8L")},
240  {21, 152, N_("Sigma 10-20mm F4-5.6 or 12-24mm f/4.5-5.6 or 14mm f/2.8")},
241  {21, 153, N_("Canon EF 35-350mm f/3.5-5.6L")},
242  {21, 155, N_("Canon EF 85mm f/1.8 USM")},
243  {21, 156, N_("Canon EF 28-105mm f/3.5-4.5 USM")},
244  {21, 160, N_("Canon EF 20-35mm f/3.5-4.5 USM")},
245  {21, 161, N_("Canon EF 28-70mm f/2.8L or Sigma 24-70mm EX f/2.8")},
246  {21, 165, N_("Canon EF 70-200mm f/2.8 L")},
247  {21, 166, N_("Canon EF 70-200mm f/2.8 L + x1.4")},
248  {21, 167, N_("Canon EF 70-200mm f/2.8 L + x2")},
249  {21, 168, N_("Canon EF 28mm f/1.8 USM")},
250  {21, 169, N_("Sigma 15-30mm f/3.5-4.5 EX DG Aspherical")},
251  {21, 170, N_("Canon EF 200mm f/2.8L II")},
252  {21, 173, N_("Canon EF 180mm Macro f/3.5L or Sigma 180mm EX HSM Macro f/3.5")},
253  {21, 174, N_("Canon EF 135mm f/2L")},
254  {21, 176, N_("Canon EF 24-85mm f/3.5-4.5 USM")},
255  {21, 177, N_("Canon EF 300mm f/4L IS")},
256  {21, 178, N_("Canon EF 28-135mm f/3.5-5.6 IS")},
257  {21, 180, N_("Canon EF 35mm f/1.4L")},
258  {21, 181, N_("Canon EF 100-400mm f/4.5-5.6L IS + x1.4")},
259  {21, 182, N_("Canon EF 100-400mm f/4.5-5.6L IS + x2")},
260  {21, 183, N_("Canon EF 100-400mm f/4.5-5.6L IS")},
261  {21, 184, N_("Canon EF 400mm f/2.8L + x2")},
262  {21, 186, N_("Canon EF 70-200mm f/4L")},
263  {21, 190, N_("Canon EF 100mm f/2.8 Macro")},
264  {21, 191, N_("Canon EF 400mm f/4 DO IS")},
265  {21, 197, N_("Canon EF 75-300mm f/4-5.6 IS")},
266  {21, 198, N_("Canon EF 50mm f/1.4")},
267  {21, 202, N_("Canon EF 28-80 f/3.5-5.6 USM IV")},
268  {21, 211, N_("Canon EF 28-200mm f/3.5-5.6")},
269  {21, 213, N_("Canon EF 90-300mm f/4.5-5.6")},
270  {21, 214, N_("Canon EF-S 18-55mm f/3.5-4.5 USM")},
271  {21, 224, N_("Canon EF 70-200mm f/2.8L IS USM")},
272  {21, 225, N_("Canon EF 70-200mm f/2.8L IS USM + x1.4")},
273  {21, 226, N_("Canon EF 70-200mm f/2.8L IS USM + x2")},
274  {21, 229, N_("Canon EF 16-35mm f/2.8L")},
275  {21, 230, N_("Canon EF 24-70mm f/2.8L")},
276  {21, 231, N_("Canon EF 17-40mm f/4L")},
277  {21, 232, N_("Canon EF 70-300mm f/4.5-5.6 DO IS USM")},
278  {21, 234, N_("Canon EF-S 17-85mm f4-5.6 IS USM")},
279  {21, 235, N_("Canon EF-S10-22mm F3.5-4.5 USM")},
280  {21, 236, N_("Canon EF-S60mm F2.8 Macro USM")},
281  {21, 237, N_("Canon EF 24-105mm f/4L IS")},
282  {21, 238, N_("Canon EF 70-300mm F4-5.6 IS USM")},
283  {21, 241, N_("Canon EF 50mm F1.2L USM")},
284  {21, 242, N_("Canon EF 70-200mm f/4L IS USM")},
285  {21, 251, N_("Canon EF 70-200mm f/2.8L IS II USM")},
286  {28, 0, N_("Manual")},
287  {28, 1, N_("TTL")},
288  {28, 2, N_("A-TTL")},
289  {28, 3, N_("E-TTL")},
290  {28, 4, N_("FP sync enabled")},
291  {28, 7, N_("2nd-curtain sync used")},
292  {28, 11, N_("FP sync used")},
293  {28, 13, N_("Internal")},
294  {28, 14, N_("External")},
295  {31, 0, N_("Single")},
296  {31, 1, N_("Continuous")},
297  {32, 0, N_("Normal AE")},
298  {32, 1, N_("Exposure compensation")},
299  {32, 2, N_("AE lock")},
300  {32, 3, N_("AE lock + exposure compensation")},
301  {32, 4, N_("No AE")},
302  {33, 0, N_("Off")},
303  {33, 1, N_("On")},
304  {33, 2, N_("On, shot only")},
305  {39, 0, N_("Off")},
306  {39, 1, N_("Vivid")},
307  {39, 2, N_("Neutral")},
308  {39, 3, N_("Smooth")},
309  {39, 4, N_("Sepia")},
310  {39, 5, N_("Black & white")},
311  {39, 6, N_("Custom")},
312  {39, 100, N_("My color data")},
313  {40, 0, N_("Off")},
314  {40, 0x0500, N_("Full")},
315  {40, 0x0502, N_("2/3")},
316  {40, 0x0504, N_("1/3")},
317 #endif
318  { 0, 0, NULL}
319 },
321 #ifndef NO_VERBOSE_TAG_DATA
322  {0, 1, N_("Fixed")},
323  {0, 2, N_("Zoom")},
324 #endif
325  {0, 0, NULL}
326 },
327 entries_settings_2 [] = {
328 #ifndef NO_VERBOSE_TAG_DATA
329  { 6, 0, N_("Auto")},
330  { 6, 1, N_("Sunny")},
331  { 6, 2, N_("Cloudy")},
332  { 6, 3, N_("Tungsten")},
333  { 6, 4, N_("Fluorescent")},
334  { 6, 5, N_("Flash")},
335  { 6, 6, N_("Custom")},
336  { 6, 7, N_("Black & white")},
337  { 6, 8, N_("Shade")},
338  { 6, 9, N_("Manual temperature (Kelvin)")},
339  { 6, 10, N_("PC set 1")},
340  { 6, 11, N_("PC set 2")},
341  { 6, 12, N_("PC set 3")},
342  { 6, 14, N_("Daylight fluorescent")},
343  { 6, 15, N_("Custom 1")},
344  { 6, 16, N_("Custom 2")},
345  { 6, 17, N_("Underwater")},
346  { 7, 0, N_("Off")},
347  { 7, 1, N_("Night scene")},
348  { 7, 2, N_("On")},
349  { 7, 3, N_("None")},
350  { 13, 0x3000, N_("None (MF)")},
351  { 13, 0x3001, N_("Right")},
352  { 13, 0x3002, N_("Center")},
353  { 13, 0x3003, N_("Center-right")},
354  { 13, 0x3004, N_("Left")},
355  { 13, 0x3005, N_("Left-right")},
356  { 13, 0x3006, N_("Left-center")},
357  { 13, 0x3007, N_("All")},
358  { 15, 0, N_("Off")},
359  { 15, 1, N_("On (shot 1)")},
360  { 15, 2, N_("On (shot 2)")},
361  { 15, 3, N_("On (shot 3)")},
362  { 15, 0xffff, N_("On")},
363  { 25, 248, N_("EOS high-end")},
364  { 25, 250, N_("Compact")},
365  { 25, 252, N_("EOS mid-range")},
366  { 26, 0, N_("None")},
367  { 26, 1, N_("Rotate 90 CW")},
368  { 26, 2, N_("Rotate 180")},
369  { 26, 3, N_("Rotate 270 CW")},
370  { 26, 0xffff, N_("Rotated by software")},
371  { 27, 0, N_("Off")},
372  { 27, 1, N_("On")},
373  { 32, 0, N_("Off")},
374  { 32, 0x0014, N_("1/3")},
375  { 32, 0x008c, N_("2/3")},
376  { 32, 0x07d0, N_("Full")},
377 #endif
378  {0, 0, NULL}
379 },
380 entries_panorama [] = {
381 #ifndef NO_VERBOSE_TAG_DATA
382  {0, 0, N_("Left to right")},
383  {0, 1, N_("Right to left")},
384  {0, 2, N_("Bottom to top")},
385  {0, 3, N_("Top to bottom")},
386  {0, 4, N_("2x2 matrix (clockwise)")},
387 #endif
388  {0, 0, NULL}
389 },
390 color_information [] = {
391 #ifndef NO_VERBOSE_TAG_DATA
392  {0, 0, N_("Standard")},
393  {0, 1, N_("Manual")},
394  {0, 2, N_("Custom")},
395  {2, 0, N_("N/A")},
396  {2, 1, N_("Lowest")},
397  {2, 2, N_("Low")},
398  {2, 3, N_("Standard")},
399  {2, 4, N_("High")},
400  {2, 5, N_("Highest")},
401  {7, 0, N_("Auto")},
402  {7, 1, N_("Daylight")},
403  {7, 2, N_("Cloudy")},
404  {7, 3, N_("Tungsten")},
405  {7, 4, N_("Fluorescent")},
406  {7, 5, N_("Flash")},
407  {7, 6, N_("Custom")},
408  {7, 7, N_("Black & white")},
409  {7, 8, N_("Shade")},
410  {7, 9, N_("Manual temperature (Kelvin)")},
411  {7, 10, N_("PC set 1")},
412  {7, 11, N_("PC set 2")},
413  {7, 12, N_("PC set 3")},
414  {7, 14, N_("Daylight fluorescent")},
415  {7, 15, N_("Custom 1")},
416  {7, 16, N_("Custom 2")},
417  {7, 17, N_("Underwater")},
418  {9, 0x00, N_("None")},
419  {9, 0x01, N_("Standard")},
420  {9, 0x02, N_("Set 1")},
421  {9, 0x03, N_("Set 2")},
422  {9, 0x04, N_("Set 3")},
423  {9, 0x21, N_("User def. 1")},
424  {9, 0x22, N_("User def. 2")},
425  {9, 0x23, N_("User def. 3")},
426  {9, 0x41, N_("External 1")},
427  {9, 0x42, N_("External 2")},
428  {9, 0x43, N_("External 3")},
429  {9, 0x81, N_("Standard")},
430  {9, 0x82, N_("Portrait")},
431  {9, 0x83, N_("Landscape")},
432  {9, 0x84, N_("Neutral")},
433  {9, 0x85, N_("Faithful")},
434  {9, 0x86, N_("Monochrome")},
435 #endif
436  {0, 0, NULL}
437 };
438 
439 static void
441  unsigned int t, ExifShort vs, char *val, unsigned int maxlen)
442 {
443  unsigned int j;
444 
445  /* Search the table for the first matching subtag and value. */
446  for (j = 0; table[j].name && ((table[j].subtag < t) ||
447  ((table[j].subtag == t) && table[j].value <= vs)); j++) {
448  if ((table[j].subtag == t) && (table[j].value == vs)) {
449  break;
450  }
451  }
452  if ((table[j].subtag == t) && (table[j].value == vs) && table[j].name) {
453  /* Matching subtag and value found. */
454  strncpy (val, _(table[j].name), maxlen);
455  } else {
456  /* No matching subtag and/or value found. */
457  snprintf (val, maxlen, "0x%04x", vs);
458  }
459 }
460 
461 static void
463  unsigned int t, ExifShort vs, char *val, unsigned int maxlen)
464 {
465  unsigned int j;
466 
467  /* Search the table for the first matching subtag. */
468  for (j = 0; table[j].name && (table[j].subtag <= t); j++) {
469  if (table[j].subtag == t) {
470  break;
471  }
472  }
473  if ((table[j].subtag == t) && table[j].name) {
474  unsigned int i, bit, lastbit = 0;
475 
476  /*
477  * Search the table for the last matching bit, because
478  * that one needs no additional comma appended.
479  */
480  for (i = j; table[i].name && (table[i].subtag == t); i++) {
481  bit = table[i].value;
482  if ((vs >> bit) & 1) {
483  lastbit = bit;
484  }
485  }
486  /* Search the table for all matching bits. */
487  for (i = j; table[i].name && (table[i].subtag == t); i++) {
488  bit = table[i].value;
489  if ((vs >> bit) & 1) {
490  strncat(val, _(table[i].name), maxlen - strlen (val));
491  if (bit != lastbit)
492  strncat (val, _(", "), maxlen - strlen (val));
493  }
494  }
495  } else {
496  /* No matching subtag found. */
497  snprintf (val, maxlen, "0x%04x", vs);
498  }
499 }
500 
501 unsigned int
503 {
504  unsigned int val;
505 
506  if (!entry) return 0;
507 
508  switch (entry->tag) {
511  return entry->components;
516  if (entry->format != EXIF_FORMAT_SHORT) return 0;
517 
518  val = exif_get_short (entry->data, entry->order);
519  /* val is buffer size, i.e. # of values plus 1 */
520  return MIN (entry->size - 2, val) / 2;
521  default:
522  return 1;
523  }
524 }
525 
526 /*
527  * For reference, see Exif 2.1 specification (Appendix C),
528  * or http://en.wikipedia.org/wiki/APEX_system
529  */
530 static double
532 {
533  return pow (2, x / 2.);
534 }
535 
536 static double
538 {
539  return 1.0 / pow (2, x);
540 }
541 
542 static double
544 {
545  return 3.125 * pow (2, x);
546 }
547 
548 char *
549 mnote_canon_entry_get_value (const MnoteCanonEntry *entry, unsigned int t, char *val, unsigned int maxlen)
550 {
551  char buf[128];
552  ExifLong vl;
553  ExifSLong vsl;
554  ExifShort vs, n;
555  ExifSShort vss;
556  unsigned char *data;
557  size_t size;
558  double d;
559 
560  if (!entry)
561  return NULL;
562 
563  data = entry->data;
564  size = entry->size;
565 
566  memset (val, 0, maxlen);
567  maxlen--;
568 
569  switch (entry->tag) {
571  CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
572 
573  if (size < 2) return NULL;
574  n = exif_get_short (data, entry->order) / 2;
575  if (t >= n) return NULL;
576 
577  CC (entry->components, n, val, maxlen);
578 
579  if (size < 2 + t*2 + 2) return NULL;
580  vs = exif_get_short (data + 2 + t * 2, entry->order);
581  switch (t) {
582  case 1:
583  if (!vs) {
584  strncpy(val, _("Off"), maxlen);
585  break;
586  }
587  snprintf (val, maxlen, _("%i (ms)"), vs * 100);
588  break;
589  case 15:
590  if (((vs & 0xC000) == 0x4000) && (vs != 0x7FFF)) {
591  /* Canon S3 IS - directly specified value */
592  snprintf (val, maxlen, "%i", vs & ~0x4000);
593  } else {
594  /* Standard Canon - index into lookup table */
595  canon_search_table_value (entries_settings_1, t, vs, val, maxlen);
596  }
597  break;
598  case 22:
599  case 23:
600  case 24:
601  snprintf (val, maxlen, "%u", vs);
602  break;
603  case 25:
604  case 26:
605  snprintf (val, maxlen, "%.2f", apex_value_to_aperture (vs / 32.0));
606  break;
607  case 28:
608  canon_search_table_bitfield(entries_settings_1, t, vs, val, maxlen);
609  break;
610  case 34:
611  snprintf (val, maxlen, "%.2f", vs / 10.0);
612  break;
613  case 35:
614  case 36:
615  snprintf (val, maxlen, "%u", vs);
616  break;
617  default:
618  canon_search_table_value (entries_settings_1, t, vs, val, maxlen);
619  }
620  break;
621 
623  CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
624  if (size < t*2 + 2) return NULL;
625  vs = exif_get_short (data + t * 2, entry->order);
626  switch (t) {
627  case 1:
628  snprintf (val, maxlen, "%u", vs);
629  break;
630  case 2:
631  case 3:
632  snprintf (val, maxlen, _("%.2f mm"), vs * 25.4 / 1000);
633  break;
634  default:
635  canon_search_table_value (entries_focal_length, t, vs, val, maxlen);
636  }
637  break;
638 
640  CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
641  if (size < 2) return NULL;
642  n = exif_get_short (data, entry->order) / 2;
643  if (t >= n) return NULL;
644  CC (entry->components, n, val, maxlen);
645  if (size < 2 + t*2 + 2) return NULL;
646  vss = exif_get_sshort (data + 2 + t * 2, entry->order);
647  switch (t) {
648  case 0:
649  snprintf (val, maxlen, "%.3f", pow (2, vss / 32.0));
650  break;
651  case 1:
652  snprintf (val, maxlen, "%.0f", apex_value_to_iso_speed (vss / 32.0));
653  break;
654  case 2:
655  case 5:
656  case 14:
657  case 16:
658  snprintf (val, maxlen, _("%.2f EV"), vss / 32.0);
659  break;
660  case 3:
661  case 20:
662  snprintf (val, maxlen, "%.2f", apex_value_to_aperture (vss / 32.0));
663  break;
664  case 4:
665  case 21:
666  d = apex_value_to_shutter_speed (vss / 32.0);
667  if (d < 1)
668  snprintf (val, maxlen, _("1/%.0f"), 1.0 / d);
669  else
670  snprintf (val, maxlen, "%.0f", d);
671  break;
672  case 8:
673  snprintf (val, maxlen, "%u", vss);
674  break;
675  case 12:
676  snprintf (val, maxlen, "%.2f", vss / 32.0);
677  break;
678  case 18:
679  case 19:
680  snprintf (val, maxlen, _("%u mm"), vss);
681  break;
682  case 28:
683  if (vss <= 0) {
684  strncpy(val, _("Off"), maxlen);
685  break;
686  }
687  snprintf (val, maxlen, _("%i (ms)"), vss * 100);
688  break;
689  default:
690  canon_search_table_value (entries_settings_2, t, vss, val, maxlen);
691  }
692  break;
693 
695  CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
696  if (size < t*2 + 2) return NULL;
697  vs = exif_get_short (data + t * 2, entry->order);
698  canon_search_table_value (entries_panorama, t, vs, val, maxlen);
699  break;
700 
702  CC (entry->components, 32, val, maxlen);
703  /* Fall through; ImageType can have many sizes */
704  /* fall through */
706  CF (entry->format, EXIF_FORMAT_ASCII, val, maxlen);
707  strncpy (val, (char *)data, MIN (entry->size, maxlen));
708  break;
709 
711  CF (entry->format, EXIF_FORMAT_ASCII, val, maxlen);
712 /* CC2 (entry->components, 24, 32, val, maxlen); Can also be 22 */
713  strncpy (val, (char *)data, MIN (entry->size, maxlen));
714  break;
715 
717  CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
718  CC (entry->components, 1, val, maxlen);
719  if (size < 4) return NULL;
720  vl = exif_get_long (data, entry->order);
721  snprintf (val, maxlen, "%03lu-%04lu",
722  (unsigned long) vl/10000,
723  (unsigned long) vl%10000);
724  break;
725 
727  CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
728  CC (entry->components, 1, val, maxlen);
729  if (size < 4) return NULL;
730  vl = exif_get_long (data, entry->order);
731  snprintf (val, maxlen, "%04X-%05d", (int)vl>>16,(int)vl&0xffff);
732  break;
733 
735  CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
736  if (size < 2) return NULL;
737  n = exif_get_short (data, entry->order) / 2;
738  if (t >= n) return NULL;
739  CC (entry->components, n, val, maxlen);
740  if (size < 2 + t*2 + 2) return NULL;
741  vs = exif_get_short (data + 2 + t * 2, entry->order);
742  snprintf (buf, sizeof (buf), "%u", vs);
743  strncat (val, buf, maxlen - strlen (val));
744  break;
745 
747  CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
748  if (size < 2) return NULL;
749  n = exif_get_short (data, entry->order) / 2;
750  if (t >= n) return NULL;
751  CC (entry->components, n, val, maxlen);
752  if (size < 2 + t*2 + 2) return NULL;
753  vs = exif_get_short (data + 2 + t * 2, entry->order);
754  canon_search_table_value (color_information, t, vs, val, maxlen);
755  break;
756 
757  default:
758  switch (entry->format) {
759  case EXIF_FORMAT_SHORT:
760  {
761  size_t i, len = strlen(val);
762  for(i=0; i<entry->components; i++) {
763  if (size < 2)
764  break;
765  vs = exif_get_short (data, entry->order);
766  snprintf (val+len, maxlen-len, "%hu ", vs);
767  len = strlen(val);
768  data += 2;
769  size -= 2;
770  }
771  }
772  break;
773  case EXIF_FORMAT_SSHORT:
774  {
775  size_t i, len = strlen(val);
776  for(i=0; i<entry->components; i++) {
777  if (size < 2)
778  break;
779  vss = exif_get_sshort (data, entry->order);
780  snprintf (val+len, maxlen-len, "%hi ", vss);
781  data += 2;
782  size -= 2;
783  }
784  }
785  break;
786  case EXIF_FORMAT_LONG:
787  {
788  size_t i, len = strlen(val);
789  for(i=0; i<entry->components; i++) {
790  if (size < 4)
791  break;
792  vl = exif_get_long (data, entry->order);
793  snprintf (val+len, maxlen-len, "%lu ", (long unsigned) vl);
794  data += 4;
795  size -= 4;
796  }
797  }
798  break;
799  case EXIF_FORMAT_SLONG:
800  {
801  size_t i, len = strlen(val);
802  for(i=0; i<entry->components; i++) {
803  if (size < 4)
804  break;
805  vsl = exif_get_slong (data, entry->order);
806  snprintf (val+len, maxlen-len, "%li ", (long int) vsl);
807  data += 4;
808  size -= 4;
809  }
810  }
811  break;
812  case EXIF_FORMAT_ASCII:
813  strncpy (val, (char *)data, MIN (entry->size, maxlen));
814  break;
815  default:
816  snprintf (val, maxlen, _("%i bytes unknown data"),
817  entry->size);
818  break;
819  }
820  break;
821  }
822  return val;
823 }
unsigned char size
Definition: exif-format.c:35
Handling native EXIF data types.
@ EXIF_FORMAT_SLONG
Definition: exif-format.h:41
@ EXIF_FORMAT_LONG
Definition: exif-format.h:36
@ EXIF_FORMAT_SHORT
Definition: exif-format.h:35
@ EXIF_FORMAT_SSHORT
Definition: exif-format.h:40
@ EXIF_FORMAT_ASCII
Definition: exif-format.h:34
ExifLong exif_get_long(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifLong value from memory.
Definition: exif-utils.c:165
ExifShort exif_get_short(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifShort value from memory.
Definition: exif-utils.c:102
ExifSLong exif_get_slong(const unsigned char *b, ExifByteOrder order)
Retrieve an ExifSLong value from memory.
Definition: exif-utils.c:130
ExifSShort exif_get_sshort(const unsigned char *buf, ExifByteOrder order)
Retrieve an ExifSShort value from memory.
Definition: exif-utils.c:87
EXIF data manipulation functions and types.
uint32_t ExifLong
EXIF Unsigned Long data type.
Definition: exif-utils.h:54
int32_t ExifSLong
EXIF Signed Long data type.
Definition: exif-utils.h:57
uint16_t ExifShort
EXIF Unsigned Short data type.
Definition: exif-utils.h:48
#define MIN(a, b)
Definition: exif-utils.h:180
int16_t ExifSShort
EXIF Signed Short data type.
Definition: exif-utils.h:51
#define _(String)
Definition: i18n.h:48
#define N_(String)
Definition: i18n.h:49
const char * name
static const struct @0 table[]
static double apex_value_to_iso_speed(double x)
static double apex_value_to_aperture(double x)
#define CC(number, target, v, maxlen)
static double apex_value_to_shutter_speed(double x)
static const struct canon_entry_table_t entries_settings_2[]
static const struct canon_entry_table_t entries_settings_1[]
static const struct canon_entry_table_t color_information[]
char * mnote_canon_entry_get_value(const MnoteCanonEntry *entry, unsigned int t, char *val, unsigned int maxlen)
static void canon_search_table_value(const struct canon_entry_table_t table[], unsigned int t, ExifShort vs, char *val, unsigned int maxlen)
static const struct canon_entry_table_t entries_focal_length[]
unsigned int mnote_canon_entry_count_values(const MnoteCanonEntry *entry)
#define CF(format, target, v, maxlen)
static void canon_search_table_bitfield(const struct canon_entry_table_t table[], unsigned int t, ExifShort vs, char *val, unsigned int maxlen)
static const struct canon_entry_table_t entries_panorama[]
unsigned int subtag
@ MNOTE_CANON_TAG_PANORAMA
@ MNOTE_CANON_TAG_SETTINGS_1
@ MNOTE_CANON_TAG_SETTINGS_2
@ MNOTE_CANON_TAG_IMAGE_NUMBER
@ MNOTE_CANON_TAG_COLOR_INFORMATION
@ MNOTE_CANON_TAG_IMAGE_TYPE
@ MNOTE_CANON_TAG_CUSTOM_FUNCS
@ MNOTE_CANON_TAG_FIRMWARE
@ MNOTE_CANON_TAG_SERIAL_NUMBER
@ MNOTE_CANON_TAG_OWNER
@ MNOTE_CANON_TAG_FOCAL_LENGTH
ExifByteOrder order
MnoteCanonTag tag
unsigned long components
unsigned char * data
unsigned int subtag
const char * name
ExifShort value

libexif Generated by doxygen