00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "mnote-canon-entry.h"
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <math.h>
00029
00030 #include <libexif/exif-format.h>
00031 #include <libexif/exif-utils.h>
00032 #include <libexif/i18n.h>
00033
00034
00035
00036 #define CF(format,target,v,maxlen) \
00037 { \
00038 if (format != target) { \
00039 snprintf (v, maxlen, \
00040 _("Invalid format '%s', " \
00041 "expected '%s'."), \
00042 exif_format_get_name (format), \
00043 exif_format_get_name (target)); \
00044 break; \
00045 } \
00046 }
00047
00048 #define CC(number,target,v,maxlen) \
00049 { \
00050 if (number != target) { \
00051 snprintf (v, maxlen, \
00052 _("Invalid number of components (%i, " \
00053 "expected %i)."), (int) number, (int) target); \
00054 break; \
00055 } \
00056 }
00057 #define CC2(number,t1,t2,v,maxlen) \
00058 { \
00059 if ((number != t1) && (number != t2)) { \
00060 snprintf (v, maxlen, \
00061 _("Invalid number of components (%i, " \
00062 "expected %i or %i)."), (int) number, \
00063 (int) t1, (int) t2); \
00064 break; \
00065 } \
00066 }
00067
00068 #define UNDEFINED 0xFF
00069
00070 static const struct canon_entry_table_t {
00071 unsigned int subtag;
00072 ExifShort value;
00073 const char *name;
00074 } entries_settings_1 [] = {
00075 #ifndef NO_VERBOSE_TAG_DATA
00076 { 0, 1, N_("Macro")},
00077 { 0, 2, N_("Normal")},
00078 { 2, 1, N_("Economy")},
00079 { 2, 2, N_("Normal")},
00080 { 2, 3, N_("Fine")},
00081 { 2, 4, N_("RAW")},
00082 { 2, 5, N_("Superfine")},
00083 { 3, 0, N_("Off")},
00084 { 3, 1, N_("Auto")},
00085 { 3, 2, N_("On")},
00086 { 3, 3, N_("Red-eye reduction")},
00087 { 3, 4, N_("Slow synchro")},
00088 { 3, 5, N_("Auto, red-eye reduction")},
00089 { 3, 6, N_("On, red-eye reduction")},
00090 { 3, 16, N_("External flash")},
00091 { 4, 0, N_("Single")},
00092 { 4, 1, N_("Continuous")},
00093 { 4, 2, N_("Movie")},
00094 { 4, 3, N_("Continuous, speed priority")},
00095 { 4, 4, N_("Continuous, low")},
00096 { 4, 5, N_("Continuous, high")},
00097 { 6, 0, N_("One-shot AF")},
00098 { 6, 1, N_("AI servo AF")},
00099 { 6, 2, N_("AI focus AF")},
00100 { 6, 3, N_("Manual focus")},
00101 { 6, 4, N_("Single")},
00102 { 6, 5, N_("Continuous")},
00103 { 6, 6, N_("Manual focus")},
00104 { 6, 16, N_("Pan focus")},
00105 { 8, 1, N_("JPEG")},
00106 { 8, 2, N_("CRW+THM")},
00107 { 8, 3, N_("AVI+THM")},
00108 { 8, 4, N_("TIF")},
00109 { 8, 5, N_("TIF+JPEG")},
00110 { 8, 6, N_("CR2")},
00111 { 8, 7, N_("CR2+JPEG")},
00112 { 9, 0, N_("Large")},
00113 { 9, 1, N_("Medium")},
00114 { 9, 2, N_("Small")},
00115 { 9, 5, N_("Medium 1")},
00116 { 9, 6, N_("Medium 2")},
00117 { 9, 7, N_("Medium 3")},
00118 { 9, 8, N_("Postcard")},
00119 { 9, 9, N_("Widescreen")},
00120 {10, 0, N_("Full auto")},
00121 {10, 1, N_("Manual")},
00122 {10, 2, N_("Landscape")},
00123 {10, 3, N_("Fast shutter")},
00124 {10, 4, N_("Slow shutter")},
00125 {10, 5, N_("Night")},
00126 {10, 6, N_("Grayscale")},
00127 {10, 7, N_("Sepia")},
00128 {10, 8, N_("Portrait")},
00129 {10, 9, N_("Sports")},
00130 {10, 10, N_("Macro")},
00131 {10, 11, N_("Black & white")},
00132 {10, 12, N_("Pan focus")},
00133 {10, 13, N_("Vivid")},
00134 {10, 14, N_("Neutral")},
00135 {10, 15, N_("Flash off")},
00136 {10, 16, N_("Long shutter")},
00137 {10, 17, N_("Super macro")},
00138 {10, 18, N_("Foliage")},
00139 {10, 19, N_("Indoor")},
00140 {10, 20, N_("Fireworks")},
00141 {10, 21, N_("Beach")},
00142 {10, 22, N_("Underwater")},
00143 {10, 23, N_("Snow")},
00144 {10, 24, N_("Kids & pets")},
00145 {10, 25, N_("Night snapshot")},
00146 {10, 26, N_("Digital macro")},
00147 {10, 27, N_("My colors")},
00148 {10, 28, N_("Still image")},
00149 {10, 30, N_("Color accent")},
00150 {10, 31, N_("Color swap")},
00151 {10, 32, N_("Aquarium")},
00152 {10, 33, N_("ISO 3200")},
00153 {11, 0, N_("None")},
00154 {11, 1, N_("2x")},
00155 {11, 2, N_("4x")},
00156 {11, 3, N_("Other")},
00157 {12, 0x0000, N_("Normal")},
00158 {12, 0x0001, N_("High")},
00159 {12, 0xffff, N_("Low")},
00160 {13, 0x0000, N_("Normal")},
00161 {13, 0x0001, N_("High")},
00162 {13, 0xffff, N_("Low")},
00163 {14, 0x0000, N_("Normal")},
00164 {14, 0x0001, N_("High")},
00165 {14, 0xffff, N_("Low")},
00166 {15, 14, N_("Auto high")},
00167 {15, 15, N_("Auto")},
00168 {15, 16, N_("50")},
00169 {15, 17, N_("100")},
00170 {15, 18, N_("200")},
00171 {15, 19, N_("400")},
00172 {15, 20, N_("800")},
00173 {16, 0, N_("Default")},
00174 {16, 1, N_("Spot")},
00175 {16, 2, N_("Average")},
00176 {16, 3, N_("Evaluative")},
00177 {16, 4, N_("Partial")},
00178 {16, 5, N_("Center-weighted average")},
00179 {17, 0, N_("Manual")},
00180 {17, 1, N_("Auto")},
00181 {17, 2, N_("Not known")},
00182 {17, 3, N_("Macro")},
00183 {17, 4, N_("Very close")},
00184 {17, 5, N_("Close")},
00185 {17, 6, N_("Middle range")},
00186 {17, 7, N_("Far range")},
00187 {17, 8, N_("Pan focus")},
00188 {17, 9, N_("Super macro")},
00189 {17, 10, N_("Infinity")},
00190 {18, 0x2005, N_("Manual AF point selection")},
00191 {18, 0x3000, N_("None (MF)")},
00192 {18, 0x3001, N_("Auto-selected")},
00193 {18, 0x3002, N_("Right")},
00194 {18, 0x3003, N_("Center")},
00195 {18, 0x3004, N_("Left")},
00196 {18, 0x4001, N_("Auto AF point selection")},
00197 {19, 0, N_("Easy shooting")},
00198 {19, 1, N_("Program")},
00199 {19, 2, N_("Tv-priority")},
00200 {19, 3, N_("Av-priority")},
00201 {19, 4, N_("Manual")},
00202 {19, 5, N_("A-DEP")},
00203 {19, 6, N_("M-DEP")},
00204 {21, 1, N_("Canon EF 50mm f/1.8")},
00205 {21, 2, N_("Canon EF 28mm f/2.8")},
00206 {21, 4, N_("Sigma UC Zoom 35-135mm f/4-5.6")},
00207 {21, 6, N_("Tokina AF193-2 19-35mm f/3.5-4.5")},
00208 {21, 7, N_("Canon EF 100-300mm F5.6L")},
00209 {21, 10, N_("Sigma 50mm f/2.8 EX or 28mm f/1.8")},
00210 {21, 11, N_("Canon EF 35mm f/2")},
00211 {21, 13, N_("Canon EF 15mm f/2.8")},
00212 {21, 21, N_("Canon EF 80-200mm f/2.8L")},
00213 {21, 22, N_("Tokina AT-X280AF PRO 28-80mm F2.8 Aspherical")},
00214 {21, 26, N_("Cosina 100mm f/3.5 Macro AF")},
00215 {21, 28, N_("Tamron AF Aspherical 28-200mm f/3.8-5.6")},
00216 {21, 29, N_("Canon EF 50mm f/1.8 MkII")},
00217 {21, 31, N_("Tamron SP AF 300mm f/2.8 LD IF")},
00218 {21, 32, N_("Canon EF 24mm f/2.8 or Sigma 15mm f/2.8 EX Fisheye")},
00219 {21, 37, N_("Canon EF 35-80mm f/4-5.6")},
00220 {21, 39, N_("Canon EF 75-300mm f/4-5.6")},
00221 {21, 40, N_("Canon EF 28-80mm f/3.5-5.6")},
00222 {21, 43, N_("Canon EF 28-105mm f/4-5.6")},
00223 {21, 45, N_("Canon EF-S 18-55mm f/3.5-5.6")},
00224 {21, 52, N_("Canon EF-S 18-55mm f/3.5-5.6 IS II")},
00225 {21, 124, N_("Canon MP-E 65mm f/2.8 1-5x Macro Photo")},
00226 {21, 125, N_("Canon TS-E 24mm f/3.5L")},
00227 {21, 126, N_("Canon TS-E 45mm f/2.8")},
00228 {21, 127, N_("Canon TS-E 90mm f/2.8")},
00229 {21, 130, N_("Canon EF 50mm f/1.0L")},
00230 {21, 131, N_("Sigma 17-35mm f2.8-4 EX Aspherical HSM")},
00231 {21, 134, N_("Canon EF 600mm f/4L IS")},
00232 {21, 135, N_("Canon EF 200mm f/1.8L")},
00233 {21, 136, N_("Canon EF 300mm f/2.8L")},
00234 {21, 137, N_("Canon EF 85mm f/1.2L")},
00235 {21, 139, N_("Canon EF 400mm f/2.8L")},
00236 {21, 141, N_("Canon EF 500mm f/4.5L")},
00237 {21, 142, N_("Canon EF 300mm f/2.8L IS")},
00238 {21, 143, N_("Canon EF 500mm f/4L IS")},
00239 {21, 149, N_("Canon EF 100mm f/2")},
00240 {21, 150, N_("Sigma 20mm EX f/1.8")},
00241 {21, 151, N_("Canon EF 200mm f/2.8L")},
00242 {21, 152, N_("Sigma 10-20mm F4-5.6 or 12-24mm f/4.5-5.6 or 14mm f/2.8")},
00243 {21, 153, N_("Canon EF 35-350mm f/3.5-5.6L")},
00244 {21, 155, N_("Canon EF 85mm f/1.8 USM")},
00245 {21, 156, N_("Canon EF 28-105mm f/3.5-4.5 USM")},
00246 {21, 160, N_("Canon EF 20-35mm f/3.5-4.5 USM")},
00247 {21, 161, N_("Canon EF 28-70mm f/2.8L or Sigma 24-70mm EX f/2.8")},
00248 {21, 165, N_("Canon EF 70-200mm f/2.8 L")},
00249 {21, 166, N_("Canon EF 70-200mm f/2.8 L + x1.4")},
00250 {21, 167, N_("Canon EF 70-200mm f/2.8 L + x2")},
00251 {21, 168, N_("Canon EF 28mm f/1.8 USM")},
00252 {21, 169, N_("Sigma 15-30mm f/3.5-4.5 EX DG Aspherical")},
00253 {21, 170, N_("Canon EF 200mm f/2.8L II")},
00254 {21, 173, N_("Canon EF 180mm Macro f/3.5L or Sigma 180mm EX HSM Macro f/3.5")},
00255 {21, 174, N_("Canon EF 135mm f/2L")},
00256 {21, 176, N_("Canon EF 24-85mm f/3.5-4.5 USM")},
00257 {21, 177, N_("Canon EF 300mm f/4L IS")},
00258 {21, 178, N_("Canon EF 28-135mm f/3.5-5.6 IS")},
00259 {21, 180, N_("Canon EF 35mm f/1.4L")},
00260 {21, 181, N_("Canon EF 100-400mm f/4.5-5.6L IS + x1.4")},
00261 {21, 182, N_("Canon EF 100-400mm f/4.5-5.6L IS + x2")},
00262 {21, 183, N_("Canon EF 100-400mm f/4.5-5.6L IS")},
00263 {21, 184, N_("Canon EF 400mm f/2.8L + x2")},
00264 {21, 186, N_("Canon EF 70-200mm f/4L")},
00265 {21, 190, N_("Canon EF 100mm f/2.8 Macro")},
00266 {21, 191, N_("Canon EF 400mm f/4 DO IS")},
00267 {21, 197, N_("Canon EF 75-300mm f/4-5.6 IS")},
00268 {21, 198, N_("Canon EF 50mm f/1.4")},
00269 {21, 202, N_("Canon EF 28-80 f/3.5-5.6 USM IV")},
00270 {21, 211, N_("Canon EF 28-200mm f/3.5-5.6")},
00271 {21, 213, N_("Canon EF 90-300mm f/4.5-5.6")},
00272 {21, 214, N_("Canon EF-S 18-55mm f/3.5-4.5 USM")},
00273 {21, 224, N_("Canon EF 70-200mm f/2.8L IS USM")},
00274 {21, 225, N_("Canon EF 70-200mm f/2.8L IS USM + x1.4")},
00275 {21, 226, N_("Canon EF 70-200mm f/2.8L IS USM + x2")},
00276 {21, 229, N_("Canon EF 16-35mm f/2.8L")},
00277 {21, 230, N_("Canon EF 24-70mm f/2.8L")},
00278 {21, 231, N_("Canon EF 17-40mm f/4L")},
00279 {21, 232, N_("Canon EF 70-300mm f/4.5-5.6 DO IS USM")},
00280 {21, 234, N_("Canon EF-S 17-85mm f4-5.6 IS USM")},
00281 {21, 235, N_("Canon EF-S10-22mm F3.5-4.5 USM")},
00282 {21, 236, N_("Canon EF-S60mm F2.8 Macro USM")},
00283 {21, 237, N_("Canon EF 24-105mm f/4L IS")},
00284 {21, 238, N_("Canon EF 70-300mm F4-5.6 IS USM")},
00285 {21, 241, N_("Canon EF 50mm F1.2L USM")},
00286 {21, 242, N_("Canon EF 70-200mm f/4L IS USM")},
00287 {21, 251, N_("Canon EF 70-200mm f/2.8L IS II USM")},
00288 {28, 0, N_("Manual")},
00289 {28, 1, N_("TTL")},
00290 {28, 2, N_("A-TTL")},
00291 {28, 3, N_("E-TTL")},
00292 {28, 4, N_("FP sync enabled")},
00293 {28, 7, N_("2nd-curtain sync used")},
00294 {28, 11, N_("FP sync used")},
00295 {28, 13, N_("Internal")},
00296 {28, 14, N_("External")},
00297 {31, 0, N_("Single")},
00298 {31, 1, N_("Continuous")},
00299 {32, 0, N_("Normal AE")},
00300 {32, 1, N_("Exposure compensation")},
00301 {32, 2, N_("AE lock")},
00302 {32, 3, N_("AE lock + exposure compensation")},
00303 {32, 4, N_("No AE")},
00304 {33, 0, N_("Off")},
00305 {33, 1, N_("On")},
00306 {33, 2, N_("On, shot only")},
00307 {39, 0, N_("Off")},
00308 {39, 1, N_("Vivid")},
00309 {39, 2, N_("Neutral")},
00310 {39, 3, N_("Smooth")},
00311 {39, 4, N_("Sepia")},
00312 {39, 5, N_("Black & white")},
00313 {39, 6, N_("Custom")},
00314 {39, 100, N_("My color data")},
00315 {40, 0, N_("Off")},
00316 {40, 0x0500, N_("Full")},
00317 {40, 0x0502, N_("2/3")},
00318 {40, 0x0504, N_("1/3")},
00319 #endif
00320 { 0, 0, NULL}
00321 },
00322 entries_focal_length [] = {
00323 #ifndef NO_VERBOSE_TAG_DATA
00324 {0, 1, N_("Fixed")},
00325 {0, 2, N_("Zoom")},
00326 #endif
00327 {0, 0, NULL}
00328 },
00329 entries_settings_2 [] = {
00330 #ifndef NO_VERBOSE_TAG_DATA
00331 { 6, 0, N_("Auto")},
00332 { 6, 1, N_("Sunny")},
00333 { 6, 2, N_("Cloudy")},
00334 { 6, 3, N_("Tungsten")},
00335 { 6, 4, N_("Fluorescent")},
00336 { 6, 5, N_("Flash")},
00337 { 6, 6, N_("Custom")},
00338 { 6, 7, N_("Black & white")},
00339 { 6, 8, N_("Shade")},
00340 { 6, 9, N_("Manual temperature (Kelvin)")},
00341 { 6, 10, N_("PC set 1")},
00342 { 6, 11, N_("PC set 2")},
00343 { 6, 12, N_("PC set 3")},
00344 { 6, 14, N_("Daylight fluorescent")},
00345 { 6, 15, N_("Custom 1")},
00346 { 6, 16, N_("Custom 2")},
00347 { 6, 17, N_("Underwater")},
00348 { 7, 0, N_("Off")},
00349 { 7, 1, N_("Night scene")},
00350 { 7, 2, N_("On")},
00351 { 7, 3, N_("None")},
00352 { 13, 0x3000, N_("None (MF)")},
00353 { 13, 0x3001, N_("Right")},
00354 { 13, 0x3002, N_("Center")},
00355 { 13, 0x3003, N_("Center-right")},
00356 { 13, 0x3004, N_("Left")},
00357 { 13, 0x3005, N_("Left-right")},
00358 { 13, 0x3006, N_("Left-center")},
00359 { 13, 0x3007, N_("All")},
00360 { 15, 0, N_("Off")},
00361 { 15, 1, N_("On (shot 1)")},
00362 { 15, 2, N_("On (shot 2)")},
00363 { 15, 3, N_("On (shot 3)")},
00364 { 15, 0xffff, N_("On")},
00365 { 25, 248, N_("EOS high-end")},
00366 { 25, 250, N_("Compact")},
00367 { 25, 252, N_("EOS mid-range")},
00368 { 26, 0, N_("None")},
00369 { 26, 1, N_("Rotate 90 CW")},
00370 { 26, 2, N_("Rotate 180")},
00371 { 26, 3, N_("Rotate 270 CW")},
00372 { 26, 0xffff, N_("Rotated by software")},
00373 { 27, 0, N_("Off")},
00374 { 27, 1, N_("On")},
00375 { 32, 0, N_("Off")},
00376 { 32, 0x0014, N_("1/3")},
00377 { 32, 0x008c, N_("2/3")},
00378 { 32, 0x07d0, N_("Full")},
00379 #endif
00380 {0, 0, NULL}
00381 },
00382 entries_panorama [] = {
00383 #ifndef NO_VERBOSE_TAG_DATA
00384 {0, 0, N_("Left to right")},
00385 {0, 1, N_("Right to left")},
00386 {0, 2, N_("Bottom to top")},
00387 {0, 3, N_("Top to bottom")},
00388 {0, 4, N_("2x2 matrix (clockwise)")},
00389 #endif
00390 {0, 0, NULL}
00391 },
00392 color_information [] = {
00393 #ifndef NO_VERBOSE_TAG_DATA
00394 {0, 0, N_("Standard")},
00395 {0, 1, N_("Manual")},
00396 {0, 2, N_("Custom")},
00397 {2, 0, N_("N/A")},
00398 {2, 1, N_("Lowest")},
00399 {2, 2, N_("Low")},
00400 {2, 3, N_("Standard")},
00401 {2, 4, N_("High")},
00402 {2, 5, N_("Highest")},
00403 {7, 0, N_("Auto")},
00404 {7, 1, N_("Daylight")},
00405 {7, 2, N_("Cloudy")},
00406 {7, 3, N_("Tungsten")},
00407 {7, 4, N_("Fluorescent")},
00408 {7, 5, N_("Flash")},
00409 {7, 6, N_("Custom")},
00410 {7, 7, N_("Black & white")},
00411 {7, 8, N_("Shade")},
00412 {7, 9, N_("Manual temperature (Kelvin)")},
00413 {7, 10, N_("PC set 1")},
00414 {7, 11, N_("PC set 2")},
00415 {7, 12, N_("PC set 3")},
00416 {7, 14, N_("Daylight fluorescent")},
00417 {7, 15, N_("Custom 1")},
00418 {7, 16, N_("Custom 2")},
00419 {7, 17, N_("Underwater")},
00420 {9, 0x00, N_("None")},
00421 {9, 0x01, N_("Standard")},
00422 {9, 0x02, N_("Set 1")},
00423 {9, 0x03, N_("Set 2")},
00424 {9, 0x04, N_("Set 3")},
00425 {9, 0x21, N_("User def. 1")},
00426 {9, 0x22, N_("User def. 2")},
00427 {9, 0x23, N_("User def. 3")},
00428 {9, 0x41, N_("External 1")},
00429 {9, 0x42, N_("External 2")},
00430 {9, 0x43, N_("External 3")},
00431 {9, 0x81, N_("Standard")},
00432 {9, 0x82, N_("Portrait")},
00433 {9, 0x83, N_("Landscape")},
00434 {9, 0x84, N_("Neutral")},
00435 {9, 0x85, N_("Faithful")},
00436 {9, 0x86, N_("Monochrome")},
00437 #endif
00438 {0, 0, NULL}
00439 };
00440
00441 static void
00442 canon_search_table_value (const struct canon_entry_table_t table[],
00443 unsigned int t, ExifShort vs, char *val, unsigned int maxlen)
00444 {
00445 unsigned int j;
00446
00447
00448 for (j = 0; table[j].name && ((table[j].subtag < t) ||
00449 ((table[j].subtag == t) && table[j].value <= vs)); j++) {
00450 if ((table[j].subtag == t) && (table[j].value == vs)) {
00451 break;
00452 }
00453 }
00454 if ((table[j].subtag == t) && (table[j].value == vs) && table[j].name) {
00455
00456 strncpy (val, _(table[j].name), maxlen);
00457 } else {
00458
00459 snprintf (val, maxlen, "0x%04x", vs);
00460 }
00461 }
00462
00463 static void
00464 canon_search_table_bitfield (const struct canon_entry_table_t table[],
00465 unsigned int t, ExifShort vs, char *val, unsigned int maxlen)
00466 {
00467 unsigned int j;
00468
00469
00470 for (j = 0; table[j].name && (table[j].subtag <= t); j++) {
00471 if (table[j].subtag == t) {
00472 break;
00473 }
00474 }
00475 if ((table[j].subtag == t) && table[j].name) {
00476 unsigned int i, bit, lastbit = 0;
00477
00478
00479
00480
00481
00482 for (i = j; table[i].name && (table[i].subtag == t); i++) {
00483 bit = table[i].value;
00484 if ((vs >> bit) & 1) {
00485 lastbit = bit;
00486 }
00487 }
00488
00489 for (i = j; table[i].name && (table[i].subtag == t); i++) {
00490 bit = table[i].value;
00491 if ((vs >> bit) & 1) {
00492 strncat(val, _(table[i].name), maxlen - strlen (val));
00493 if (bit != lastbit)
00494 strncat (val, _(", "), maxlen - strlen (val));
00495 }
00496 }
00497 } else {
00498
00499 snprintf (val, maxlen, "0x%04x", vs);
00500 }
00501 }
00502
00503 unsigned int
00504 mnote_canon_entry_count_values (const MnoteCanonEntry *entry)
00505 {
00506 unsigned int val;
00507
00508 if (!entry) return 0;
00509
00510 switch (entry->tag) {
00511 case MNOTE_CANON_TAG_FOCAL_LENGTH:
00512 case MNOTE_CANON_TAG_PANORAMA:
00513 return entry->components;
00514 case MNOTE_CANON_TAG_SETTINGS_1:
00515 case MNOTE_CANON_TAG_SETTINGS_2:
00516 case MNOTE_CANON_TAG_CUSTOM_FUNCS:
00517 case MNOTE_CANON_TAG_COLOR_INFORMATION:
00518 if (entry->format != EXIF_FORMAT_SHORT) return 0;
00519
00520 val = exif_get_short (entry->data, entry->order);
00521
00522 return MIN (entry->size - 2, val) / 2;
00523 default:
00524 return 1;
00525 }
00526 }
00527
00528
00529
00530
00531
00532 static double
00533 apex_value_to_aperture (double x)
00534 {
00535 return pow (2, x / 2.);
00536 }
00537
00538 static double
00539 apex_value_to_shutter_speed(double x)
00540 {
00541 return 1.0 / pow (2, x);
00542 }
00543
00544 static double
00545 apex_value_to_iso_speed (double x)
00546 {
00547 return 3.125 * pow (2, x);
00548 }
00549
00550 char *
00551 mnote_canon_entry_get_value (const MnoteCanonEntry *entry, unsigned int t, char *val, unsigned int maxlen)
00552 {
00553 char buf[128];
00554 ExifLong vl;
00555 ExifShort vs, n;
00556 unsigned char *data;
00557 double d;
00558
00559 if (!entry)
00560 return NULL;
00561
00562 data = entry->data;
00563
00564 memset (val, 0, maxlen);
00565 maxlen--;
00566
00567 switch (entry->tag) {
00568 case MNOTE_CANON_TAG_SETTINGS_1:
00569 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00570 n = exif_get_short (data, entry->order) / 2;
00571 if (t >= n) return NULL;
00572 CC (entry->components, n, val, maxlen);
00573 vs = exif_get_short (data + 2 + t * 2, entry->order);
00574 switch (t) {
00575 case 1:
00576 if (!vs) {
00577 strncpy(val, _("Off"), maxlen);
00578 break;
00579 }
00580 snprintf (val, maxlen, _("%i (ms)"), vs * 100);
00581 break;
00582 case 15:
00583 if (((vs & 0xC000) == 0x4000) && (vs != 0x7FFF)) {
00584
00585 snprintf (val, maxlen, "%i", vs & ~0x4000);
00586 } else {
00587
00588 canon_search_table_value (entries_settings_1, t, vs, val, maxlen);
00589 }
00590 break;
00591 case 22:
00592 case 23:
00593 case 24:
00594 snprintf (val, maxlen, "%u", vs);
00595 break;
00596 case 25:
00597 case 26:
00598 snprintf (val, maxlen, "%.2f", apex_value_to_aperture (vs / 32.0));
00599 break;
00600 case 28:
00601 canon_search_table_bitfield(entries_settings_1, t, vs, val, maxlen);
00602 break;
00603 case 34:
00604 snprintf (val, maxlen, "%.2f", vs / 10.0);
00605 break;
00606 case 35:
00607 case 36:
00608 snprintf (val, maxlen, "%u", vs);
00609 break;
00610 default:
00611 canon_search_table_value (entries_settings_1, t, vs, val, maxlen);
00612 }
00613 break;
00614
00615 case MNOTE_CANON_TAG_FOCAL_LENGTH:
00616 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00617 vs = exif_get_short (data + t * 2, entry->order);
00618 switch (t) {
00619 case 1:
00620 snprintf (val, maxlen, "%u", vs);
00621 break;
00622 case 2:
00623 case 3:
00624 snprintf (val, maxlen, _("%.2f mm"), vs * 25.4 / 1000);
00625 break;
00626 default:
00627 canon_search_table_value (entries_focal_length, t, vs, val, maxlen);
00628 }
00629 break;
00630
00631 case MNOTE_CANON_TAG_SETTINGS_2:
00632 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00633 n = exif_get_short (data, entry->order) / 2;
00634 if (t >= n) return NULL;
00635 CC (entry->components, n, val, maxlen);
00636 vs = exif_get_short (data + 2 + t * 2, entry->order);
00637 switch (t) {
00638 case 0:
00639 snprintf (val, maxlen, "%.3f", pow (2, (ExifSShort)vs / 32.0));
00640 break;
00641 case 1:
00642 snprintf (val, maxlen, "%.0f", apex_value_to_iso_speed ((ExifSShort)vs / 32.0));
00643 break;
00644 case 2:
00645 case 5:
00646 case 14:
00647 case 16:
00648 snprintf (val, maxlen, _("%.2f EV"), (ExifSShort)vs / 32.0);
00649 break;
00650 case 3:
00651 case 20:
00652 snprintf (val, maxlen, "%.2f", apex_value_to_aperture (vs / 32.0));
00653 break;
00654 case 4:
00655 case 21:
00656 d = apex_value_to_shutter_speed ((ExifSShort)vs / 32.0);
00657 if (d < 1)
00658 snprintf (val, maxlen, _("1/%i"),(int)(1.0 / d));
00659 else
00660 snprintf (val, maxlen, "%i", (int) d);
00661 break;
00662 case 8:
00663 snprintf (val, maxlen, "%u", vs);
00664 break;
00665 case 12:
00666 snprintf (val, maxlen, "%.2f", vs / 32.0);
00667 break;
00668 case 18:
00669 case 19:
00670 snprintf (val, maxlen, _("%u mm"), vs);
00671 break;
00672 case 28:
00673 if ((ExifSShort)vs <= 0) {
00674 strncpy(val, _("Off"), maxlen);
00675 break;
00676 }
00677 snprintf (val, maxlen, _("%i (ms)"), vs * 100);
00678 break;
00679 default:
00680 canon_search_table_value (entries_settings_2, t, vs, val, maxlen);
00681 }
00682 break;
00683
00684 case MNOTE_CANON_TAG_PANORAMA:
00685 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00686 vs = exif_get_short (data + t * 2, entry->order);
00687 canon_search_table_value (entries_panorama, t, vs, val, maxlen);
00688 break;
00689
00690 case MNOTE_CANON_TAG_OWNER:
00691 CC (entry->components, 32, val, maxlen);
00692
00693 case MNOTE_CANON_TAG_IMAGE_TYPE:
00694 CF (entry->format, EXIF_FORMAT_ASCII, val, maxlen);
00695 strncpy (val, (char *)data, MIN (entry->size, maxlen));
00696 break;
00697
00698 case MNOTE_CANON_TAG_FIRMWARE:
00699 CF (entry->format, EXIF_FORMAT_ASCII, val, maxlen);
00700
00701 strncpy (val, (char *)data, MIN (entry->size, maxlen));
00702 break;
00703
00704 case MNOTE_CANON_TAG_IMAGE_NUMBER:
00705 CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
00706 CC (entry->components, 1, val, maxlen);
00707 vl = exif_get_long (data, entry->order);
00708 snprintf (val, maxlen, "%03lu-%04lu",
00709 (unsigned long) vl/10000,
00710 (unsigned long) vl%10000);
00711 break;
00712
00713 case MNOTE_CANON_TAG_SERIAL_NUMBER:
00714 CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
00715 CC (entry->components, 1, val, maxlen);
00716 vl = exif_get_long (data, entry->order);
00717 snprintf (val, maxlen, "%04X-%05d", (int)vl>>16,(int)vl&0xffff);
00718 break;
00719
00720 case MNOTE_CANON_TAG_CUSTOM_FUNCS:
00721 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00722 n = exif_get_short (data, entry->order) / 2;
00723 if (t >= n) return NULL;
00724 CC (entry->components, n, val, maxlen);
00725 vs = exif_get_short (data + 2 + t * 2, entry->order);
00726 snprintf (buf, sizeof (buf), "%u", vs);
00727 strncat (val, buf, maxlen - strlen (val));
00728 break;
00729
00730 case MNOTE_CANON_TAG_COLOR_INFORMATION:
00731 CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
00732 n = exif_get_short (data, entry->order) / 2;
00733 if (t >= n) return NULL;
00734 CC (entry->components, n, val, maxlen);
00735 vs = exif_get_short (data + 2 + t * 2, entry->order);
00736 canon_search_table_value (color_information, t, vs, val, maxlen);
00737 break;
00738
00739 default:
00740 #ifdef DEBUG
00741 {
00742 int i;
00743 if (entry->format == EXIF_FORMAT_SHORT)
00744 for(i=0;i<entry->components;i++) {
00745 vs = exif_get_short (data, entry->order);
00746 data+=2;
00747 printf ("Value%d=%d\n", i, vs);
00748 }
00749 else if (entry->format == EXIF_FORMAT_LONG)
00750 for(i=0;i<entry->components;i++) {
00751 vl = exif_get_long (data, entry->order);
00752 data+=4;
00753 printf ("Value%d=%d\n", i, vs);
00754 }
00755 else if (entry->format == EXIF_FORMAT_ASCII)
00756 strncpy (val, data, MIN (entry->size, maxlen));
00757 }
00758 #endif
00759 break;
00760 }
00761 return val;
00762 }