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