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