1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
|
/*
/--------------------------------------------------------------------
|
| $Id: plexif.cpp,v 1.10 2004/09/11 12:41:35 uzadow Exp $
|
| Copyright (c) 1996-2003 Ulrich von Zadow
|
| Implementation of PLExif class by Mike Franklin
| Much of the decoding code was adapted from code by Ken Reneris:
| http://www.reneris.com/tools/exif.asp -
| though it has been heavily modified!
|
|
\--------------------------------------------------------------------
*/
#include "config.h"
#include "plexif.h"
#include "pldebug.h"
#include "plexcept.h"
#include <sstream>
#include <cctype>
#include <iomanip>
#include <memory>
#include <cmath>
#include <iostream>
extern "C"
{
#include "jpeglib.h"
}
using namespace std;
struct _PLExifTranslator
{
int Value;
char * Desc;
};
struct _PLExifTagValues
{
PLUINT Tag; // The tag #
char * ShortName; // Short name for the tag
_PLExifTranslator *Trans; // Translate values / units
void (PLExifTag::*Convert)(std::string &); // convert to common format
char * Desc; // Normal name for the tag
};
struct _PLExifFormatter
{
PLUINT Size; // Size of each item in this format
void (*Swizzle)(PLBYTE *Data); // Swizzle the data
size_t (PLExifTag:: *Render)(PLBYTE * & Buffer);
};
// place all these globals in an anonymous namespace
// so they are only visible (accessible) to this
// compilation unit (source file)
namespace
{
const int VALUE_UNIT = -1;
const int VALUE_LOWER_STR = -2;
enum ExifType {etUint8 = 1, etAsciiStr, etUint16, etUint32, etUrat64,
etInt8, etInt16, etInt32, etRat64};
_PLExifTranslator OffOn[] = {
0, "Off",
1, "On",
0, NULL
};
_PLExifTranslator OnOff[] = {
0, "On",
1, "Off",
0, NULL
};
_PLExifTranslator DisableEnable[] = {
0, "Disable",
1, "Enable",
0, NULL
};
_PLExifTranslator EnableDisable[] = {
0, "Enable",
1, "Disable",
0, NULL
};
_PLExifTranslator ResUnit[] = {
1, "no-unit",
2, "inch",
3, "cm",
0, NULL
};
_PLExifTranslator FPResUnit[] = {
1, "inch",
2, "inch", // should be meter, but broke on some cameras?
3, "centimeter",
4, "milimemeter",
5, "micrometer",
0, NULL
};
_PLExifTranslator ExpProg[] = {
1, "Manual",
2, "Program",
3, "Aperture priority",
4, "Shutter priority",
5, "Slow",
6, "Action",
7, "Portrait",
8, "Landscape",
0, NULL
};
_PLExifTranslator BpsCompress[] = {
1, "Basic",
2, "Normal",
3, "Fine",
4, "Fine",
0, NULL
};
_PLExifTranslator MeterMode[] = {
0, "Unknown",
1, "Average",
2, "Center weighted",
3, "Spot",
4, "Multi-spot",
5, "Multi-segment",
6, "Partial",
255,"Other",
0, NULL
};
_PLExifTranslator LightSource[] = {
0, "Unknown/cloudy",
1, "Daylight",
2, "Fluorescent",
3, "Tungsten",
10, "Flash",
17, "Standard light A",
18, "Standard light B",
19, "Standard light C",
20, "D55",
21, "D65",
22, "D75",
0, NULL
};
_PLExifTranslator FlashUsed[] = {
0, "No",
1, "Yes",
5, "Yes, no return detect",
7, "Yes, return detected",
9, "Yes", // maybe should be more than just yes ?
16, "No forced", // not sure about this one!
0, NULL
};
_PLExifTranslator ColorSpace[] = {
1, "sRGB",
65535, "Uncalibrated",
0, NULL
};
_PLExifTranslator SenseMethod[] = {
2, "1 chip color area",
0, NULL
};
_PLExifTranslator FileSource[] = {
3, "Digital still camera",
0, NULL
};
_PLExifTranslator SceneType[] = {
1, "Directly photographed",
0, NULL
};
_PLExifTranslator N2Quality[] = {
1, "VGA Basic",
2, "VGA Normal",
3, "VGA Fine",
4, "SXGA Basic",
5, "SXGA Normal",
6, "SXGA Fine",
12,"UXGA Fine",
20,"HI (Uncompressed)",
0, NULL
};
_PLExifTranslator N2Color[] = {
1, "Colour",
2, "Monochrome",
0, NULL
};
_PLExifTranslator N2ImgAdjust[] = {
0, "Normal",
1, "Bright+",
2, "Bright-",
3, "Contrast+",
4, "Contrast-",
0, NULL
};
_PLExifTranslator N2Iso[] = {
0, "80",
2, "160",
4, "320",
5, "100",
0, NULL
};
_PLExifTranslator N2WhiteBal[] = {
0, "Auto",
1, "Preset",
2, "Daylight",
3, "Incandescent",
4, "Flourescent",
5, "Cloudy",
6, "SpeedLight",
0, NULL
};
_PLExifTranslator N2Converter[] = {
0, "None",
1, "Fisheye",
0, NULL
};
_PLExifTranslator OlyJpegQ[] = {
1, "SQ",
2, "HQ",
3, "SHQ",
0, NULL
};
_PLExifTranslator OlyMacro[] = {
0, "Normal",
1, "Macro",
0, NULL
};
_PLExifTranslator OlySharp[] = {
0, "Normal",
1, "Hard",
2, "Soft",
0, NULL
};
_PLExifTranslator OlyFlash[] = {
0, "On",
1, "Red-eye",
2, "Fill",
2, "Off",
0, NULL
};
_PLExifTranslator CanMacro[] = {
1, "Macro",
2, "Off",
0, NULL
};
_PLExifTranslator CanFlashMode[] = {
0, "Off",
1, "Auto",
2, "On",
3, "Red-eye",
4, "Slow",
5, "Auto + red-eye",
6, "On + red-eye",
16, "External",
0, NULL
};
_PLExifTranslator CanDrvMode[] = {
0, "Single/self timer",
1, "Continuous",
0, NULL
};
_PLExifTranslator CanFocusMode[] = {
0, "One-shot",
1, "AI servo",
2, "AI Focus",
3, "Manual",
4, "Single",
5, "Continuous",
6, "Manual",
0, NULL
};
_PLExifTranslator CanImgSize[] = {
0, "Large",
1, "Medium",
2, "Small",
0, NULL
};
_PLExifTranslator CanShootMode[] = {
0, "Full auto",
1, "Manual",
2, "Landscape",
3, "Fast shutter",
4, "Slow shutter",
5, "Night",
6, "B & W",
7, "Sepia",
8, "Portrait",
9, "Sports",
10, "Macro",
11, "Pan Focus",
0, NULL
};
_PLExifTranslator CanLNH[] = {
0xFFFF, "Low",
0, "Normal",
1, "High",
0, NULL
};
_PLExifTranslator CanIso[] = {
0, "Not supplied use EXIF tag",
15, "Auto",
16, "50",
17, "100",
18, "200",
19, "400",
0, NULL
};
_PLExifTranslator CanMeter[] = {
3, "Evaluative",
4, "Partial",
5, "Center-weighted",
0, NULL
};
_PLExifTranslator CanWhiteBal[] = {
0, "Auto",
1, "Sunny",
2, "Cloudy",
3, "Tungsten",
4, "Flourescent",
5, "Flash",
6, "Custom",
0, NULL
};
_PLExifTranslator CanFlashBias[] = {
0xFFC0, "-2 EV",
0xFFCC, "-1.67 EV",
0xFFD0, "-1.50 EV",
0xFFD4, "-1.33 EV",
0xFFE0, "-1 EV",
0xFFEC, "-0.67 EV",
0xFFF0, "-0.50 EV",
0xFFF4, "-0.33 EV",
0x0000, "0 EV",
0x000C, "0.33 EV",
0x0010, "0.50 EV",
0x0014, "0.67 EV",
0x0020, "1 EV",
0x002C, "1.33 EV",
0x0030, "1.50 EV",
0x0034, "1.67 EV",
0x0040, "2 EV",
0, NULL
};
_PLExifTranslator CanAFPoint[] = {
0x3000, "MF",
0x3001, "Auto selected",
0x3002, "Right",
0x3003, "Center",
0x3004, "Left",
0, NULL
};
_PLExifTranslator CFnLock[] = {
0, "AF/AE Lock",
1, "AE Lock/AF",
2, "AF/AF Lock",
3, "AE+release/AE+AF",
0, NULL
};
_PLExifTranslator CFnTVAV[] = {
0, "1/2 stop",
1, "1/3 stop",
0, NULL
};
_PLExifTranslator CFnAFAssist[] = {
0, "On (auto)",
1, "Off",
2, "External only",
0, NULL
};
_PLExifTranslator CFnShutAv[] = {
0, "Auto",
1, "1/200(fixed)",
0, NULL
};
_PLExifTranslator CFnAeb[] = {
0, "0,-,+/Enabled",
1, "0,-,+/Disabled",
2, "-,0,+/Enabled",
3, "-,0,+/Disabled",
0, NULL
};
_PLExifTranslator CFnShutSync[] = {
0, "1st-curtain sync",
1, "2nd-curtain sync",
0, NULL
};
_PLExifTranslator CFnAFStop[] = {
0, "AF Stop",
1, "Operate AF",
2, "Lock AE & start timer",
0, NULL
};
_PLExifTranslator CFnMenu[] = {
0, "Top",
1, "Previous(volatile)",
2, "Previous",
0, NULL
};
_PLExifTranslator CFnSet[] = {
0, "Not assigned",
1, "Change quality",
2, "Change ISO",
3, "Select Params",
0, NULL
};
_PLExifTranslator FujiSharp[] = {
1, "Soft",
2, "Soft",
3, "Normal",
4, "Hard",
5, "Hard",
0, NULL
};
_PLExifTranslator FujiWBal[] = {
0x0000, "Auto",
0x0100, "Daylight",
0x0200, "Cloudy",
0x0300, "DaylightColor-fluorescent",
0x0301, "DaywhiteColor-fluorescent",
0x0302, "White-fluorescent",
0x0400, "Incandescent",
0x0F00, "Custom",
0, NULL
};
_PLExifTranslator FujiColor[] = {
0x0000, "Normal",
0x0100, "High",
0x0200, "Low",
0x0300, "Black & White",
0, NULL
};
_PLExifTranslator FujiTone[] = {
0x0000, "Normal",
0x0100, "High",
0x0200, "Low",
0, NULL
};
_PLExifTranslator FujiFlashMode[] = {
0, "Auto",
1, "On",
2, "Off",
3, "Red-eye",
0, NULL
};
_PLExifTranslator FujiFlashStrg[] = {
0, "Auto",
1, "On",
2, "Off",
3, "Red-eye",
0, NULL
};
_PLExifTranslator FujiMacro[] = {
0, "Off",
1, "Macro",
2, "Super Macro",
0, NULL
};
_PLExifTranslator FujiFocus[] = {
0, "Auto",
1, "Manual",
0, NULL
};
_PLExifTranslator FujiPicture[] = {
0x0000, "Auto",
0x0001, "Portrait",
0x0002, "Landscape",
0x0004, "Sports",
0x0005, "Night",
0x0006, "Program AE",
0x0100, "Aperture Prior AE",
0x0200, "Shutter Prior AE",
0x0300, "Manual exposure",
0, NULL
};
_PLExifTranslator FujiBlurFocus[] = {
0, "OK",
1, "Warning",
0, NULL
};
_PLExifTranslator FujiAE[] = {
0, "OK",
1, "Over-exposed",
0, NULL
};
_PLExifTranslator CasioRecord[] = {
1, "Single Shutter",
2, "Panorama",
3, "Night Scene",
4, "Portrait",
5, "Landscape",
7, "Panorama",
10, "Night Scene",
15, "Portrait",
16, "Landscape",
0, NULL
};
_PLExifTranslator CasioQuality[] = {
1, "Economy",
2, "Normal",
3, "Fine",
0, NULL
};
_PLExifTranslator CasioFocus[] = {
2, "Macro",
3, "Auto Focus",
4, "Manual Focus",
5, "Infinity",
0, NULL
};
_PLExifTranslator CasioFlashMode[] = {
1, "Auto",
2, "On",
3, "Off",
4, "Off", // on QV2000 this is Red Eye Reduction must be fixed as a special case :(
5, "Red Eye Reduction",
0, NULL
};
_PLExifTranslator CasioFlashInt[] = {
11, "Weak",
13, "Normal",
14, "High",
15, "Strong",
0, NULL
};
_PLExifTranslator CasioWhite[] = {
1, "Auto",
2, "Tungsten",
3, "Daylight",
4, "Fluorescent",
5, "Shade",
9, "Manual",
0, NULL
};
_PLExifTranslator CasioZoom[] = {
0x10000, "Off",
0x10001, "2X", // QV2000
0x20000, "2X", // QV8000
0x40000, "4X", // QV8000
0, NULL
};
_PLExifTranslator CasioSharp[] = {
0, "Normal",
1, "Soft",
2, "Hard",
0, NULL
};
_PLExifTranslator CasioLowHi[] = {
0, "Normal",
1, "Low",
2, "High",
0, NULL
};
_PLExifTranslator CasioSens[] = {
64, "Normal", // QV3k
80, "Normal", // QV8k/2k
100, "High", // 8k/2k
125, "+1.0", // 3k
250, "+2.0", // 3k
244, "+3.0", // 3k
9, "Manual",
0, NULL
};
_PLExifTranslator CasioEnhance[] = {
1, "Off",
2, "Red",
3, "Green",
4, "Blue",
5, "Flesh Tones",
0, NULL
};
_PLExifTranslator CasioFFrmLoc[] = {
1, "Centre",
2, "Scene S1",
3, "Scene S2",
4, "Scene S3",
5, "Scene S4",
6, "Scene S5",
7, "Scene S8",
8, "Scene S6",
9, "Scene S7",
10, "Top Left",
11, "Top Middle",
12, "Top Right",
13, "Middle Left",
14, "Middle Right",
15, "Bottom Left",
16, "Bottom Middle",
17, "Bottom Right",
0, NULL
};
_PLExifTranslator CasioFilter[] = {
1, "Off",
2, "Black & White",
3, "Sepia",
4, "Red",
5, "Green",
6, "Blue",
7, "Yellow",
8, "Pink",
9, "Purple",
0, NULL
};
_PLExifTranslator CasioMeter[] = {
2, "Centre",
3, "Spot",
5, "Multi",
0, NULL
};
_PLExifTranslator CasioEVShift[] = {
-6, "-2.0 EV",
-5, "-1.67 EV",
-4, "-1.33 EV",
-3, "-1.0 EV",
-2, "-0.67 EV",
-1, "-0.33 EV",
0, "0 EV",
1, "+0.33 EV",
2, "+0.67 EV",
3, "+1.0 EV",
4, "+1.33 EV",
5, "+1.67 EV",
6, "+2.0 EV",
0, NULL
};
_PLExifTranslator CasioAperture[] = {
1, "f2.0",
2, "f2.3",
3, "f2.8",
4, "f4.0",
5, "f5.6",
6, "f8.0",
15, "f8.0",
0, NULL
};
_PLExifTranslator CasioRecord2[] = {
0, "Normal",
1, "Portrait",
2, "Landscape",
3, "Night Scene",
4, "Slow Shutter",
0, NULL
};
_PLExifTranslator CasioComp[] = {
1, "Off",
2, "Scene S1",
3, "Scene S2",
4, "Scene S3",
5, "Scene S4",
6, "Scene S5",
7, "Scene S8",
8, "Scene S6",
9, "Scene S7",
0, NULL
};
_PLExifTranslator CasioExp[] = {
1, "Manual",
2, "Program AE",
3, "Aperture Priority",
4, "Shutter Priority",
0, NULL
};
// Units
_PLExifTranslator UnitsSec[] = { VALUE_UNIT, "s" };
_PLExifTranslator UnitsM[] = { VALUE_UNIT, "m" };
_PLExifTranslator UnitsMM[] = { VALUE_UNIT, "mm" };
_PLExifTranslator UnitsX[] = { VALUE_UNIT, "x" };
_PLExifTranslator LowerStr[] = { VALUE_LOWER_STR, NULL };
PLUINT rgMask[] = { 0, 0x000000FF, 0x0000FFFF, 0x00FFFFFF, 0xFFFFFF };
static string Nullstring;
// Internal EXIF exception
struct PLExifException
{
PLExifException(const string & m) : m_message(m) {}
string m_message;
};
struct PLExifFormatException : public PLExifException
{
PLExifFormatException(const string & m) : PLExifException(m) {}
};
struct PLExifTagNoException : public PLExifException
{
PLExifTagNoException(const string & m) : PLExifException(m) {}
};
struct PLExifNoCompException : public PLExifException
{
PLExifNoCompException(const string & m) : PLExifException(m) {}
};
} // end of anonymous namespace (see comment at top)
// tag arrays contain details of all known tags
// declared as static members in PLExifTag so they have access
// to the private conversion functions declared in PLExifTag
_PLExifTagValues PLExifTag::MainTags[] = { // Prefix Main
0x010E, "Desc", NULL, NULL, "Image Description",
0x010F, "Make", NULL, NULL, "Camera Make",
0x0110, "Model", NULL, NULL, "Camera Model",
0x0112, "Ori", NULL, NULL, "Orientation",
0x011A, "XRes", NULL, NULL, "X Resolution",
0x011B, "YRes", NULL, NULL, "Y Resolution",
0x0128, "ResUnit", ResUnit, NULL, "Resolution Unit",
0x0131, "Software", NULL, NULL, "Camera Software",
0x0132, "ModTime", NULL, NULL, "Last Modification",
0x013E, "WPoint", NULL, NULL, "White Point",
0x013F, "PrimChr", NULL, NULL, "Primary Chromaticities",
0x0211, "YCbCrCoef", NULL, NULL, "YCbCrCoefficients",
0x0213, "YCbCrPos", NULL, NULL, "YCbCrPositioning",
0x0214, "RefBW", NULL, NULL, "Reference Black/White point",
0x8298, "Copy", NULL, NULL, "Copyright",
0x8769, "ExifOffset", NULL, NULL, "Sub IFD Offset",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::SubTags[] = { // Prefix Sub
0x829A, "Shutter", UnitsSec, &PLExifTag::CnvFrac, "Exposure Time",
0x829D, "FStop", NULL, &PLExifTag::CnvRatAp, "F-Stop",
0x8822, "Prog", ExpProg, NULL, "Program",
0x8827, "Iso", NULL, NULL, "Equivalent ISO speed",
0x9000, "ExifVer", NULL, NULL, "Exif Version",
0x9003, "OrigTime", NULL, NULL, "Original Time",
0x9004, "DigTime", NULL, NULL, "Digitized Time",
0x9101, "CompConfig", NULL, &PLExifTag::CnvCompCfg, "Components Configuration",
0x9102, "Bpp", BpsCompress,NULL, "Average compression ratio",
0x9201, "Shuttera", NULL, &PLExifTag::CnvApexShutter, "Shutter Speed",
0x9202, "Aperturea", NULL, &PLExifTag::CnvApexAp, "Aperture",
0x9203, "Brighta", NULL, &PLExifTag::CnvRat, "Brightness APEX",
0x9204, "Expbiasa", NULL, &PLExifTag::CnvRat, "Exposure Bias APEX",
0x9205, "Maxapa", NULL, &PLExifTag::CnvApexAp, "Maximum Aperture APEX",
0x9206, "Dist", UnitsM, &PLExifTag::CnvRat, "Subject Distance",
0x9207, "Meter", MeterMode, NULL, "Metering Mode",
0x9208, "Lights", LightSource,NULL, "Light Source",
0x9209, "Flash", FlashUsed, NULL, "Flash Used",
0x920a, "Focal", UnitsMM, &PLExifTag::CnvRat, "Focal Length",
0x927c, "Maker", NULL, NULL, "Maker Note",
0x9286, "User", NULL, NULL, "User Comment",
0x9290, "STime", NULL, NULL, "Subsecond Time",
0x9291, "SOrigTime", NULL, NULL, "Subsecond Original Time",
0x9292, "SDigTime", NULL, NULL, "Subsecond Digitized Time",
0xA000, "Flashpix", NULL, NULL, "Flash Pix Version",
0xA001, "ColorSpace", ColorSpace, NULL, "Color Space",
0xA002, "Width", NULL, NULL, "Image Width",
0xA003, "Height", NULL, NULL, "Image Height",
0xA004, "SndFile", NULL, NULL, "Sound File",
0xA005, "ExifIntOff", NULL, NULL, "Exif Interoperability Offset",
0xA20E, "FPXRes", NULL, &PLExifTag::CnvRat, "Focal Plane X Resolution",
0xA20F, "FPYRes", NULL, &PLExifTag::CnvRat, "Focal Plane Y Resolution",
0xA210, "FPResUnit", FPResUnit, NULL, "Focal Plane Unit",
0xA215, "ExpIndex", NULL, &PLExifTag::CnvRat, "Exposure Index",
0xA217, "SenseMethod", SenseMethod,NULL, "Sensing Method",
0xA300, "FileSource", FileSource, NULL, "File Source",
0xA301, "SceneType", SceneType, NULL, "Scene Type",
0xA302, "CFAPat", NULL, NULL, "CFA Pattern",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::NikonTags[] = { // Prefix is Nikon
0x0002, "ISO", NULL, NULL, "Nikon ISO Setting",
0x0003, "Color", LowerStr, NULL, "Nikon Color Mode",
0x0004, "Quality", LowerStr, NULL, "Nikon Quality",
0x0005, "WhiteBal", LowerStr, NULL, "Nikon White Balance",
0x0006, "Sharp", LowerStr, NULL, "Nikon Image Sharpening",
0x0007, "Focus", LowerStr, NULL, "Nikon Focus Mode",
0x0008, "Flash", LowerStr, NULL, "Nikon Flash",
0x0009, "FlashMode", LowerStr, NULL, "Nikon Flash Mode",
0x000F, "ISOSel", LowerStr, NULL, "Nikon ISO Selection",
0x0080, "ImgAdjust", LowerStr, NULL, "Nikon Image Adjustment",
0x0082, "Adapter", LowerStr, NULL, "Nikon Adapter Setting",
0x0084, "Lens", LowerStr, NULL, "Nikon Lens",
0x0085, "ManFocus", UnitsM, &PLExifTag::CnvRat, "Nikon Manual Focus Distance",
0x0086, "DigZoom", UnitsX, &PLExifTag::CnvRat, "Nikon Digital Zoom",
0x0088, "AFPos", NULL, NULL, "Nikon Auto Focus Position",
//0x0090, "FlashType?", LowerStr, "Nikon Flash Type",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::Nikon2Tags[] = { // Prefix is Nikon2
0x0002, "Unknown0002", NULL, NULL, "Nikon Unknown (0002)",
0x0003, "Quality", N2Quality, NULL, "Nikon Quality",
0x0004, "Color", N2Color, NULL, "Nikon Color Mode",
0x0005, "ImgAdjust", N2ImgAdjust,NULL, "Nikon Image Adjustment",
0x0006, "CCDSens" , N2Iso, NULL, "Nikon ISO Setting",
0x0007, "WhiteBal", N2WhiteBal, NULL, "Nikon White Balance",
0x0008, "Focus", NULL, &PLExifTag::CnvRat, "Nikon Focus",
0x0009, "Unknown0009", NULL, NULL, "Nikon Unknown (0009)",
0x000A, "DigZoom", UnitsX, &PLExifTag::CnvRat, "Nikon Digital Zoom",
0x000B, "Converter", N2Converter,NULL, "Nikon Converter",
0x0F00, "Unknown0F00", NULL, NULL, "Nikon Unknown (0F00)",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::OlympusTags[] = { // Prefix is Oly
0x0200, "SpcMode", NULL, NULL, "Olympus Special Mode",
0x0201, "Quality", OlyJpegQ, NULL, "Olympus JPG Quality",
0x0202, "Macro", OlyMacro, NULL, "Olympus Macro",
0x0204, "DigZoom", UnitsX, &PLExifTag::CnvRat, "Olympus Digital Zoom",
0x0207, "Software", NULL, NULL, "Olympus Software",
0x0209, "CameraID", NULL, NULL, "Olympus Camera ID",
// E-10 fields (from dougho@niceties.com)
0x1004, "Flash", OlyFlash, NULL, "Olympus Flash Mode",
0x100F, "Sharp", OlySharp, NULL, "Olympus Sharpness Mode",
0x102a, "SharpScale", NULL, NULL, "Olympus Sharpness",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::CanonTags[] = { // Prefix is Canon
0x0001, "CnSet1", NULL, NULL, "Canon Settings 1",
0x0004, "CnSet2", NULL, NULL, "Canon Settings 2",
0x0006, "ImageType", NULL, NULL, "Canon Image Type",
0x0007, "Software", NULL, NULL, "Canon Firmware Version",
0x0008, "ImageNo", NULL, &PLExifTag::CnvCanINo,"Canon Image Number",
0x0009, "Owner", NULL, NULL, "Canon Owner Name",
0x000C, "SerialNo", NULL, &PLExifTag::CnvCanSNo,"Canon Serial Number",
0x000F, "CustomFnc", NULL, NULL, "Canon Custom Functions",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::CanonSet1[] = {
1, "Macro", CanMacro, NULL, "Canon Macro Mode",
4, "Flash", CanFlashMode, NULL, "Canon Flash Mode",
5, "Drive", CanDrvMode, NULL, "Canon Drive Mode",
7, "Focus", CanFocusMode, NULL, "Canon Focus Mode",
10, "ImgSize", CanImgSize, NULL, "Canon Image Size",
11, "Shoot", CanShootMode, NULL, "Canon Easy Shooting Mode",
13, "Contrast", CanLNH, NULL, "Canon Contrast Setting",
14, "Saturation", CanLNH, NULL, "Canon Saturation Setting",
15, "Sharpness", CanLNH, NULL, "Canon Sharpness Setting",
16, "ISO", CanIso, NULL, "Canon ISO",
17, "Metering", CanMeter, NULL, "Canon Metering mode",
19, "AFPoint", CanAFPoint, NULL, "Canon AutoFocus Point",
20, "ExpMode", NULL, NULL, "Canon Exposure Mode",
23, "LongFocal", NULL, NULL, "Canon Long Focal Length",
24, "ShortFocal", NULL, NULL, "Canon Short Focal Length",
25, "FocalUnits", NULL, NULL, "Canon Focal Units per mm",
29, "FlashDet", NULL, &PLExifTag::CnvCanFlash, "Canon Flash Details",
32, "FocusMode", NULL, NULL, "Canon Focus Mode",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::CanonSet2[] = {
7, "WhiteBal", CanWhiteBal, NULL, "Canon White Balance",
9, "SeqNo", NULL, NULL, "Canon Continuous Frame",
14, "AF Point", NULL, &PLExifTag::CnvCanAFPnt, "Canon Focus Point",
15, "FlashBias", CanFlashBias, NULL, "Canon Flash Bias",
19, "SubjectDist", NULL, NULL, "Canon Subject Distance (0.01m or 0.001m)",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::CanonCFn[] = {
0x01, "NoiseRed", OffOn, NULL, "Canon CFn 01 Long exp noise reduction",
0x02, "Lock", CFnLock, NULL, "Canon CFn 02 Shutter/AE lock buttons",
0x03, "MirrorLock", DisableEnable, NULL, "Canon CFn 03 Mirror lockup ",
0x04, "TVAVexp", CFnTVAV, NULL, "Canon CFn 04 Tv/Av & exposure level",
0x05, "AFassist", CFnAFAssist, NULL, "Canon CFn 05 AF-assist light",
0x06, "ShuttAv", CFnShutAv, NULL, "Canon CFn 06 Shutter speed in Av mode",
0x07, "AEBSeq", CFnAeb, NULL, "Canon CFn 07 AEB Sequence/auto cancel",
0x08, "ShuttSync", CFnShutSync, NULL, "Canon CFn 08 Shutter curtain sync",
0x09, "AFStop", CFnAFStop, NULL, "Canon CFn 09 Lens AF stop button switch",
0x0A, "FillReduce", EnableDisable, NULL, "Canon CFn 10 Fill flash auto reduction",
0x0B, "MenuButt", CFnMenu, NULL, "Canon CFn 11 Menu button return pos",
0x0C, "SetButt", CFnSet, NULL, "Canon CFn 12 SET button when shooting",
0x0D, "SensClean", DisableEnable, NULL, "Canon CFn 13 Sensor cleaning ",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::FujifilmTags[] = { // Prefix is Fuji
0x0000, "Version", NULL, NULL, "Fuji Version",
0x1000, "Quality", LowerStr, NULL, "Fuji Quality",
0x1001, "Sharpness", FujiSharp, NULL, "Fuji Sharpness",
0x1002, "WhiteBal", FujiWBal, NULL, "Fuji White Balance",
0x1003, "Color", FujiColor, NULL, "Fuji Color",
0x1004, "Contrast", FujiTone, NULL, "Fuji Tone",
0x1010, "FlashMode", FujiFlashMode, NULL, "Fuji Flash Mode",
0x1011, "FlashStrg", NULL, &PLExifTag::CnvRat, "Fuji Flash Strength APEX",
0x1020, "Macro", OffOn, NULL, "Fuji Macro Mode",
0x1021, "Focus", FujiFocus, NULL, "Fuji Focus Mode",
0x1022, "Unknown1022", NULL, NULL, "Fuji Unknown (1022)",
0x1023, "Unknown1023", NULL, NULL, "Fuji Unknown (1023)",
0x1030, "SlowSnyc", OffOn, NULL, "Fuji Slow Sync",
0x1031, "Picture", FujiPicture, NULL, "Fuji Exposure Mode",
0x1032, "Unknown1032", NULL, NULL, "Fuji Unknown (1032)",
0x1100, "Sequence", OffOn, NULL, "Fuji Sequence Mode",
0x1101, "Unknown1101", NULL, NULL, "Fuji Unknown (1101)",
0x1200, "Unknown1200", NULL, NULL, "Fuji Unknown (1200)",
0x1300, "BlurWarn", FujiBlurFocus, NULL, "Fuji Blur Warning",
0x1301, "FocusWarn", FujiBlurFocus, NULL, "Fuji Focus Warning",
0x1302, "AEWarn", FujiAE, NULL, "Fuji Exposure Warning",
0, NULL, NULL, NULL, NULL
};
_PLExifTagValues PLExifTag::CasioTags[] = { // Prefix is Casio
0x0001, "RecordMode", CasioRecord, NULL, "Casio Recording Mode",
0x0002, "Quality", CasioQuality, NULL, "Casio Quality ",
0x0003, "FocusMode", CasioFocus, NULL, "Casio Focusing Mode",
0x0004, "FlashMode", CasioFlashMode, NULL, "Casio Flash Mode",
0x0005, "FlasIntense", CasioFlashInt, NULL, "Casio Flash Intensity",
0x0006, "ObjDist", UnitsMM, NULL, "Casio Object Distance",
0x0007, "WhiteBal", CasioWhite, NULL, "Casio White Balance",
0x0008, "Unknown0008", NULL, NULL, "Casio Unknown (0008)",
0x0009, "Unknown0009", NULL, NULL, "Casio Unknown (0009)",
0x000A, "DigZoom", CasioZoom, NULL, "Casio Digital Zoom",
0x000B, "Sharpness", CasioSharp, NULL, "Casio Sharpness",
0x000C, "Contrast", CasioLowHi, NULL, "Casio Contrast ",
0x000D, "Saturation", CasioLowHi, NULL, "Casio Saturation",
0x000E, "Unknown000E", NULL, NULL, "Casio Unknown (000E)",
0x000F, "Unknown000F", NULL, NULL, "Casio Unknown (000F)",
0x0010, "Unknown0010", NULL, NULL, "Casio Unknown (0010)",
0x0011, "Unknown0011", NULL, NULL, "Casio Unknown (0011)",
0x0012, "Unknown0012", NULL, NULL, "Casio Unknown (0012)",
0x0013, "Unknown0013", NULL, NULL, "Casio Unknown (0013)",
0x0014, "CCDSense", FujiAE, NULL, "Casio CCD Sensitivity",
0x0015, "Unknown0015", NULL, NULL, "Casio Unknown (0015)",
0x0016, "Enhancement", CasioEnhance, NULL, "Casio Enhancement",
0x0017, "Filter", CasioFilter, NULL, "Casio Filter ",
0x0018, "FocFrmLoc", CasioFFrmLoc, NULL, "Casio Focus Frame Locator",
0x0019, "CCDSense", CasioSens, NULL, "Casio CCD Sensitivity",
0x001A, "Unknown001A", NULL, NULL, "Casio Unknown (001A)",
0x0100, "MeterMode", CasioMeter, NULL, "Casio Metering Mode",
0x0101, "EVShift", CasioEVShift, NULL, "Casio EV Shift",
0x0102, "Unknown0102", NULL, NULL, "Casio Unknown (0102)",
0x0103, "Aperture", CasioAperture, NULL, "Casio Apertue",
0x0104, "RecordMode2", CasioRecord2, NULL, "Casio Recording Mode",
0x0105, "Composition", CasioComp, NULL, "Casio Composition Frame",
0x0106, "ExpMode", CasioExp, NULL, "Casio Exposure Mode",
0x0107, "Unknown0107", NULL, NULL, "Casio Unknown (0107)",
0, NULL, NULL, NULL, NULL
};
//
// Format types
//
static void Swiz16(PLBYTE *);
static void Swiz32(PLBYTE *);
static void SwizR64(PLBYTE *);
_PLExifFormatter PLExifTag::rgExifFormat[] = {
1, NULL, &PLExifTag::RenUndef, // 0. undefined
1, NULL, &PLExifTag::RenUDef, // 1. unsigned byte
1, NULL, &PLExifTag::RenStr, // 2. ascii string
2, Swiz16, &PLExifTag::RenUDef, // 3. unsigned short
4, Swiz32, &PLExifTag::RenUDef, // 4. unsigned long
8, SwizR64,&PLExifTag::RenURat, // 5. unsigned rational
1, NULL, &PLExifTag::RenDef, // 6. signed byte
1, NULL, &PLExifTag::RenUndef, // 7. undefined
2, Swiz16, &PLExifTag::RenDef, // 8. signed short
4, Swiz32, &PLExifTag::RenDef, // 9. signed long
8, SwizR64,&PLExifTag::RenRat, // 10. signed rational
4, NULL, &PLExifTag::RenUndef, // 11. signed float (not used)
8, NULL, &PLExifTag::RenUndef, // 12. signed double (not used)
};
// Swizzle functions to deal with different endian formats
static void Swiz16(PLBYTE *Buffer)
{
PLBYTE l0;
l0 = Buffer[0];
Buffer[0] = Buffer[1];
Buffer[1] = l0;
}
static void Swiz32(PLBYTE *Buffer)
{
PLBYTE l0, l1, l2;
l0 = Buffer[0];
l1 = Buffer[1];
l2 = Buffer[2];
Buffer[0] = Buffer[3];
Buffer[1] = l2;
Buffer[2] = l1;
Buffer[3] = l0;
}
static void SwizR64(PLBYTE *Buffer)
// Rationals are 2 32bit values in a row
{
Swiz32(Buffer);
Swiz32(Buffer + 4);
}
// simple utility functions
static void MakeLower(string & s)
{
for (string::iterator iter = s.begin(); iter != s.end(); ++iter)
*iter = tolower(*iter);
}
static void TrimRight(string & s, char c)
{
for (string::reverse_iterator iter = s.rbegin(); iter != s.rend() && *iter == c; )
s.erase((++iter).base());
}
static void TrimLeft(string & s, char c)
{
for (string::iterator iter = s.begin(); iter != s.end() && *iter == c; )
s.erase(iter++);
}
static double round(double value, unsigned int precision)
{
double factor = 1.0f;
for (unsigned int i = 0; i < precision; ++i)
factor *= 10.0f;
value = value * factor;
value += 0.5f;
value = floor(value) / factor;
return value;
}
/***************************************************************
*
* PLExif implementation
*
***************************************************************/
PLExif::PLExif()
: m_Pos(0)
, m_Endian(false)
, m_IdfOffset(0)
{
}
PLExif::~PLExif()
{
Clear();
}
void PLExif::Clear()
{
m_Data = PLByteCPtr(0);
m_DataSize = 0;
// Free any tags we may have allocated
while (!m_AllTags.empty())
m_AllTags.pop_back();
m_Tags.clear();
// Re-Initialize values
m_IdfOffset = 0;
m_Pos = 0;
m_Endian = false;
}
void PLExif::ReadData(const jpeg_decompress_struct * pcinfo)
{
Clear();
jpeg_saved_marker_ptr marker;
for (marker = pcinfo->marker_list; marker != NULL; marker = marker->next)
{
if (marker->marker == JPEG_APP0 + 1) // EXIF marker
{
m_DataSize = marker->data_length;
m_Data = PLByteCPtr(new PLBYTE[m_DataSize]);
PLBYTE * pSrc = marker->data;
PLBYTE * pEnd = pSrc + marker->data_length;
PLBYTE * pDst = m_Data.get();
while (pSrc != pEnd) // copy the data
*pDst++ = *pSrc++;
}
/* code removed should probably be in PLBmpInfo
else if (marker->marker == JPEG_COM)
{
m_Comment.reserve(marker->data_length);
PLBYTE * pSrc = marker->data;
PLBYTE * pEnd = pSrc + marker->data_length;
while (pSrc != pEnd) // copy the data
m_Comment += (char)*pSrc++;
}
*/
}
if (m_DataSize) // else there's no data to decode
{
// verify this is an Exif file
PLBYTE text[6];
Read(&text, 6);
if (memcmp(text, "Exif\0\0", 6) != 0) {
Clear();
return;
}
// Determine the endian type
PLWORD type;
Read((PLBYTE *)&type, sizeof(type));
if (type == 256*'I'+'I')
#ifdef WORDS_BIGENDIAN
m_Endian = TRUE;
#else
m_Endian = FALSE;
#endif
else if (type == 256*'M'+'M')
#ifdef WORDS_BIGENDIAN
m_Endian = FALSE;
#else
m_Endian = TRUE;
#endif
else
PLASSERT (FALSE); // Illegal data in file - should throw an exception.
// Check for valid len
PLWORD Len = GetU16();
if (Len != 0x2a)
PLASSERT(false); // should maybe replace this with an exception later
// all seems ok so lets decode
decode();
}
}
void PLExif::WriteData(jpeg_compress_struct * pcinfo)
{
// this code copied from transupp.c from the JPEG library utilities
#ifdef NEED_FAR_POINTERS
/* We could use jpeg_write_marker if the data weren't FAR... */
unsigned int i;
jpeg_write_m_header(pcinfo, JPEG_APP0 + 1, m_Data.size());
for (i = 0; i < m_Data.size(); ++i)
jpeg_write_m_byte(pcinfo, m_Data[i]);
/* code removed should probably be in PLBmpInfo
jpeg_write_m_header(pcinfo, JPEG_COM, m_Comment.size());
for (i = 0; i < m_Comment.size(); ++i)
jpeg_write_m_byte(pcinfo, m_Comment[i]);
*/
#else
jpeg_write_marker(pcinfo, JPEG_APP0 + 1, m_Data.get(), m_DataSize);
/* code removed should probably be in PLBmpInfo
jpeg_write_marker(pcinfo, JPEG_COM, (PLBYTE *)&m_Comment[0], m_Comment.size());
*/
#endif
}
/* code removed should probably be in PLBmpInfo
const string & PLExif::GetComment() const
{
return m_Comment;
}
const char * PLExif::GetCommmentCStr() const
{
return m_Comment.c_str();
}
void PLExif::SetComment(const std::string & s)
{
m_Comment = s;
}
void PLExif::SetComment(const char * s)
{
m_Comment = s;
}
*/
PLBYTE * PLExif::GetRawData()
{
return m_Data.get();
}
const PLBYTE * PLExif::GetRawData() const
{
return m_Data.get();
}
size_t PLExif::GetRawDataSize() const
{
return m_DataSize;
}
const PLExifTagList & PLExif::GetAllTags() const
{
return m_AllTags;
}
const PLExifTagList & PLExif::GetMainTags() const
{
return m_MainTags;
}
const PLExifTagList & PLExif::GetSubTags() const
{
return m_SubTags;
}
const PLExifTagList & PLExif::GetManufacturerTags() const
{
return m_ManufacturerTags;
}
const PLExifTagCPtr * PLExif::GetAllTagsC(size_t & size) const
{
size = m_AllTags.size();
return &m_AllTags[0];
}
const PLExifTagCPtr * PLExif::GetMainTagsC(size_t & size) const
{
size = m_AllTags.size();
return &m_MainTags[0];
}
const PLExifTagCPtr * PLExif::GetSubTagsC(size_t & size) const
{
size = m_AllTags.size();
return &m_SubTags[0];
}
const PLExifTagCPtr * PLExif::GetManufacturerTagsC(size_t & size) const
{
size = m_AllTags.size();
return &m_ManufacturerTags[0];
}
PLExifTag * PLExif::GetTag(const char * TagName) const
{
string Str = TagName;
MakeLower(Str);
TagMap::const_iterator iter = m_Tags.find(Str);
return iter != m_Tags.end() ? iter->second.get() : NULL;
}
PLExifTag * PLExif::GetTag(const char * TagName, string & Value) const
{
PLExifTag * Tag = GetTag(TagName);
Value.erase();
if (Tag)
Value = Tag->m_Value;
return Tag;
}
PLExifTag * PLExif::GetTagCommon(const char * TagName, std::string & Value) const
{
PLExifTag * Tag = GetTag(TagName);
Value.erase();
if (Tag)
Value = Tag->m_Common;
return Tag;
}
PLExifTag * PLExif::GetTag(const char * TagName, double & Value) const
{
PLExifTag * Tag = GetTag(TagName);
Value = 0.0;
if (Tag)
Value = Tag->m_Double;
return Tag;
}
const char * PLExif::TagCStr(const char * TagName) const
{
PLExifTag * Tag = GetTag(TagName);
return Tag ? Tag->m_Value.c_str() : Nullstring.c_str();
}
const char * PLExif::TagCStrCommon(const char * TagName) const
{
PLExifTag * Tag = GetTag(TagName);
return Tag ? Tag->m_Common.c_str() : Nullstring.c_str();
}
string & PLExif::TagStr(const char * TagName) const
{
PLExifTag * Tag = GetTag(TagName);
return Tag ? Tag->m_Value : Nullstring;
}
string & PLExif::TagStrCommon(const char * TagName) const
{
PLExifTag * Tag = GetTag(TagName);
return Tag ? Tag->m_Common : Nullstring;
}
//
// private interface
//
// main EXIF decoding routine
//
void PLExif::decode()
{
try
{
PLExifTag * Tag;
// crack the main Exif directory
//
m_IdfOffset = m_IdfOffset + 6; // 0xC;
GetU32(); // junk
ReadIFD(PLExifTag::MainTags, "Main.", m_MainTags);
//
// Crack the sub-Exif directory
//
Tag = GetTag("Main.ExifOffset");
if (Tag)
{
SetPos(Tag->m_UInt);
ReadIFD(PLExifTag::SubTags, "Sub.", m_SubTags);
}
//
// Crack camera specific information
//
string Str;
GetTag("Main.Make", Str);
Tag = GetTag("Sub.Maker");
MakeLower(Str);
try // still sometimes get make notes that make no sense so just ignore the exception
{ // and at least we have the main and sub tags
if (Tag)
{
if (Str.find("nikon") != string::npos) // Nikon
{
SetPos(Tag->m_Pos);
char name[6];
Read((PLBYTE *)name, 5);
name[5] = '\0';
if (strcmp(name, "Nikon")) // if not starting with string Nikon
{ // nikon format 1
SetPos(Tag->m_Pos); // reset to the start
ReadIFD(PLExifTag::NikonTags, "Nikon.", m_ManufacturerTags);
/*
GetTag("Main.Model", Str);
if (Str == "E990" || Str == "E880")
m_FocalConvert = 0.209;
if (Str.find("D1X") != string::npos)
m_FocalConvert = 1 / 1.5;
*/
}
else
{
SetPos(Tag->m_Pos + 8);
ReadIFD(PLExifTag::Nikon2Tags, "Nikon2.", m_ManufacturerTags);
}
}
else if (Str.find("olympus") != string::npos) // Olympus
{
SetPos(Tag->m_Pos + 8);
ReadIFD(PLExifTag::OlympusTags, "Oly.", m_ManufacturerTags);
/*
GetTag("Main.Model", Str);
if (Str == "E-10")
m_FocalConvert = 0.2571;
*/
}
else if (Str.find("canon") != string::npos) // Canon
{
SetPos(Tag->m_Pos);
ReadIFD(PLExifTag::CanonTags, "Canon.", m_ManufacturerTags);
ExpandBinaryTag("Canon.CnSet1", PLExifTag::CanonSet1, etUint16, m_ManufacturerTags);
ExpandBinaryTag("Canon.CnSet2", PLExifTag::CanonSet2, etUint16, m_ManufacturerTags);
if (PLExifTag * tagp = GetTag("Canon.CustomFnc"))
DecodeCanCustomFncs(*tagp, PLExifTag::CanonCFn, m_ManufacturerTags);
}
else if (Str.find("fujifilm") != string::npos)
{
m_Endian = false; // for some bizarre reason Fuji switch to Intel for their maker data
m_IdfOffset = Tag->m_Pos + 6; // All Fuji offsets from start of Fuji notes not EXIF
SetPos(0x0C);
ReadIFD(PLExifTag::FujifilmTags, "Fuji.", m_ManufacturerTags);
}
else if (Str.find("casio") != string::npos) // Nikon
{
SetPos(Tag->m_Pos);
ReadIFD(PLExifTag::CasioTags, "Casio.", m_ManufacturerTags);
// Now sort the Casio Flash Mode mess
PLExifTag * model = GetTag("Main.Model");
PLExifTag * flash = GetTag("Casio.FlashMode");
if (flash && model && model->m_Common == "QV-2000UX")
{
if (flash->m_Int == 4)
{
flash->m_Value = "Red Eye Reduction";
flash->m_Common = "Red Eye Reduction";
}
}
}
}
}
catch(...) // catch all and ignore (see note above on try)
{}
//
// OK, we've cracked everything we know about. Now we will
// build our default tags
//
//BuildDefaultTags();
PLExifTagList::iterator iter;
for (iter = m_AllTags.begin(); iter != m_AllTags.end(); ++iter)
(*iter)->CleanWorkingArea();
}
catch(PLExifException & p)
{
throw PLTextException(PL_ERRBAD_EXIF, p.m_message.c_str());
}
}
void PLExif::CopyTag(const char * Src, const char * Dst)
// N.B. this only copies the string value of the tag
{
PLExifTag *Tag = GetTag(Src);
if (Tag)
SetTag(Dst, Tag->m_Value);
}
void PLExif::SetTag(const char * Dst, const char * Value)
{
PLExifTag *Tag = GetTag(Dst);
if (!Tag)
{
PLExifTagCPtr Tagcp(new PLExifTag(0, 2, 0));
Tag = Tagcp.get();
// Add to our list of tags
Tag->m_ShortName = Dst;
Tag->m_Lookup = Tag->m_ShortName;
MakeLower(Tag->m_Lookup);
m_AllTags.push_back(Tagcp);
m_Tags[Tag->m_Lookup] = Tagcp;
}
Tag->m_Fmt = &PLExifTag::rgExifFormat[2];
Tag->m_Value = Value;
}
void PLExif::AddTag(const char * DstTag, const char * SrcTag, const char * Skip, const char * Sep)
// Add SrcTag to DstTag if SrcTag is present and is not Skip
// Put the string Sep between the tags
{
string Str;
GetTag(SrcTag, Str);
AddStr(DstTag, Str, Skip, Sep);
}
void PLExif::AddStr(const char * DstTag, const string & SrcStr, const char * Skip, const char * Sep)
{
string Str(SrcStr);
string Str2;
Str = SrcStr;
MakeLower(Str);
if (!(SrcStr.empty() || (Skip && Str == Skip)))
{
GetTag(DstTag, Str2);
if (!Sep)
Sep = " / ";
if (Str2.empty())
Sep = "";
Str = Str2 + Sep + SrcStr;
SetTag(DstTag, Str);
}
}
void PLExif::FormatRange(double Low, double High, string & Str)
{
ostringstream oss;
oss << ios::fixed << setprecision(1) << setw(4) << Low;
string LStr(oss.str());
TrimRight(LStr, '0');
TrimRight(LStr, '.');
TrimLeft(LStr, ' ');
oss.str("");
oss << setw(4) << High;
string HStr(oss.str());
TrimRight(HStr, '0');
TrimRight(HStr, '.');
TrimLeft(HStr, ' ');
Str = LStr;
if (LStr != HStr)
Str = LStr + '-' + HStr;
}
void PLExif::ReadIFD(const _PLExifTagValues *Tags, char * Prefix, PLExifTagList & sectionList)
{
size_t NoDir, DirPos, Index;
size_t TagNo, Format, NoComp, Offset;
NoDir = GetU16();
DirPos = GetPos();
while (NoDir)
{
ostringstream oss;
//
// Allocate a new tag
//
SetPos(DirPos);
TagNo = GetU16();
Format = GetU16();
NoComp = GetU32();
if (NoComp != 0) // otherwise no components so no data
{
PLExifTagCPtr Tag(new PLExifTag(TagNo, Format, NoComp));
//
// Create the tag's shortname (and initialize it's m_Tag)
//
oss << Prefix << setfill('0') << setw(4) << hex << Tag->m_TagNo;
Tag->m_ShortName = oss.str();
for(Index=0; Tags[Index].ShortName; Index++)
{
if (Tags[Index].Tag == Tag->m_TagNo)
{
Tag->m_Tag = &Tags[Index];
Tag->m_ShortName = Prefix;
Tag->m_ShortName += Tag->m_Tag->ShortName;
break;
}
}
//
// Read the tag's data into its buffer
//
// If the data size is larger then 4, then we have a pointer to it
if (Tag->m_Size > 4)
{
Offset = GetU32();
SetPos(Offset);
}
Tag->m_Pos = GetPos();
Read(Tag->m_Buffer.get(), Tag->m_Size);
//
// If we are the wrong endian, then swizzle the data buffer
//
if (m_Endian)
Tag->Swizzle();
//
// Print the value into a string
//
Tag->Render();
//
// Add this tag to the database
//
Tag->m_Lookup = Tag->m_ShortName;
MakeLower(Tag->m_Lookup);
m_AllTags.push_back(Tag); // add to all tags list
m_Tags[Tag->m_Lookup] = Tag; // add to the look up map
sectionList.push_back(Tag); // add to the section list
}
//
// Next DirEntry
//
NoDir = NoDir - 1;
DirPos = DirPos + 12;
}
}
/*
void PLExif::BuildDefaultTags()
{
string Str;//, Str1, Str2, Model;
string Model;
PLExifTag * Tag;
double w, d1, d2;
PLBYTE c;
ostringstream oss;
oss << fixed; // set stream to fixed precision
//
// Once all the other tags are read in, we create a common set
// of tags built up from the others. This allows the callers to
// read the common stuff without needing to worry about the camera
// specific fields, but if they want they can read those as well.
//
// Make - Camera Make
// Model - Camera Model
// Software - Camera Software
// Date - Original Photo date/time
// Res - X x Y size of original
// Flash - Flash used & setting
// Focal - Focal length
// s - Exposure time
// f - Aperture f/
// ISO - ISO Equiv
// WhiteBal - WhiteBalance
// Meter - Metering mode
// ExpProg - Exposure program
// ExpBias - Exposure Bias
// Focus - Focus
// qual - Compression quality
// Lens - Info on the lens
// ImageAdj - Image adjustment
// Sharpness - Sharpness setting
//
//
Model = TagStr("Main.Model");
// Many tags are just copies.. so make them
CopyTag("Main.Make", "Make");
CopyTag("Main.Model", "Model");
CopyTag("Sub.Meter", "Meter");
CopyTag("Sub.Prog", "ExpProg");
// For Date use the last found of these time fields
CopyTag("Sub.ModTime", "Date");
CopyTag("Sub.OrigTime", "Date");
CopyTag("Sub.DigTime", "Date");
CopyTag("Main.Software", "Software");
CopyTag("Canon.Software", "Software");
AddTag ("Software", "Oly.Software");
// Get the width & height for Res
Str = TagStr("Sub.Width") + " x " + TagStr("Sub.Height");
SetTag("Res", Str);
// Set the flash mode - append the camera specific setting if the flash fired
GetTag("Sub.Flash", Str);
SetTag("Flash", Str);
if (Str.find("yes") != string::npos)
{
AddTag("Flash", "Nikon.Flash");
AddTag("Flash", "Canon.Flash");
AddTag("Flash", "Oly.Flash");
}
// The D1x doesn't set Sub.Flash
if (Model.find("D1X") != string::npos)
{
AddTag("Flash", "Nikon.Flash");
AddTag("Flash", "Nikon.FlashMode");
}
// CCD width
GetTag("Sub.Width", w);
GetTag("Sub.FPXRes", d1);
Tag = GetTag("Sub.FPResUnit");
d2 = 0;
if (Tag)
{
switch(Tag->m_UInt)
{
case 1: d2 = 25.4; break; // inch
case 2: d2 = 25.4; break; // inch
case 3: d2 = 10; break; // centimeter
case 4: d2 = 1; break; // milimeter
case 5: d2 = 0.001; break; // micrometer
}
}
if (w && d1 && d2)
{
d1 = w * d2 / d1;
oss.str("");
oss << setprecision(2) << setw(4) << d1 << "mm";
// Str.Format("%4.2fmm", d1);
SetTag("CCDWidth", oss.str());
// Set conversion
if (!m_FocalConvert)
m_FocalConvert = d1 / 35;
}
// Focal length
Tag = GetTag("Sub.Focal");
if (Tag)
{
oss.str("");
oss << setprecision(1) << setw(4) << Tag->m_Double << "mm";
// Str.Format("%4.1fmm", );
if (m_FocalConvert > 0)
{
oss.str("");
oss << setprecision(1) << setw(4) << Tag->m_Double << "mm (35mm equivalent: "
<< (PLUINT) (Tag->m_Double / m_FocalConvert + 0.5) << "mm";
// Str.Format("%4.1fmm (35mm equivalent: %dmm)", );
}
SetTag("Focal", oss.str());
}
// shutter speed
Tag = GetTag("Sub.s");
if (Tag)
{
oss.str("");
oss << setprecision(3) << setw(6) << Tag->m_Double << "fs";
// Str.Format("%6.3fs", );
if (Tag->m_Double <= 0.5)
{
oss.str("");
oss << setprecision(3) << setw(6) << Tag->m_Double
<< "fs (1/" << (PLUINT) (1 / Tag->m_Double + 0.5) << ')';
// Str.Format("%6.3fs (1/%d)", );
}
SetTag("s", oss.str());
}
// aperture
Tag = GetTag("Sub.f");
if (Tag)
{
oss.str("");
oss << "f/" << setprecision(1) << setw(3) << Tag->m_Double;
// Str.Format("f/%3.1f", );
SetTag("f", oss.str());
}
// ISO
CopyTag("Sub.ISO", "ISO");
if (!GetTag("ISO"))
{ // ISO set?
Tag = GetTag("Nikon.ISO"); // No, get the Nikon.ISO setting
if (Tag)
{
oss.str("");
oss << (int)Tag->m_Int;
SetTag("ISO", oss.str()); // to the ISO info
}
}
// Exposure Bias
GetTag("Sub.eba", d1);
if (d1 != 0)
{
c = '+';
if (d1 < 0)
{
d1 = -d1;
c = '-';
}
oss.str("");
oss << c << setprecision(2) << setw(3) << d1;
// Str.Format("%c%3.2f", c, d1);
SetTag("ExpBias", oss.str());
}
// White balance
CopyTag("Sub.ls", "WhiteBal");
CopyTag("Nikon.WhiteBal", "WhiteBal");
//
// Focus
//
AddTag("Focus", "Nikon.Focus");
AddTag("Focus", "Oly.Macro", "normal");
Tag = GetTag("Sub.Dist", d1);
// Kodak is expressing -1 as an unsigned in the numerator. So check for it.
if (Tag && Tag->m_Num == 0xFFFFFFFF)
d1 = -1;
Tag = GetTag("Nikon.ManFocus");
if (Tag && Tag->m_Num != 0)
{
d1 = Tag->m_Double;
// Nikon expresses INF as 1/0
if (Tag->m_Num == 1 && Tag->m_Den == 0)
d1 = -1;
}
oss.str("");
if (d1 > 0)
oss << setprecision(2) << setw(5) << d1 << "fm";
// Str1.Format("%5.2fm", d1);
else if (d1 < 0)
oss << "Infinite";
AddStr("Focus", oss.str());
//
// Compression Quality
//
CopyTag("Sub.bpp", "Qual");
CopyTag("Nikon.Quality", "Qual");
CopyTag("Oly.Quality", "Qual");
// Lens, ImageAdj, Sharpness
Tag = GetTag("Nikon.Lens");
if (Tag)
{
double Low, High;
string Focal, Aperture;
Low = Tag->GetDouble(0);
High = Tag->GetDouble(1);
FormatRange(Low, High, Focal);
Low = Tag->GetDouble(2);
High = Tag->GetDouble(3);
FormatRange(Low, High, Aperture);
oss.str("");
oss << Focal << "mm f/" << Aperture;
// Str.Format("%smm f/%s", Focal, Aperture);
SetTag("Lens", oss.str());
}
AddTag("Lens", "Nikon.Adapter", "off");
// ImageAdj, Sharpness
AddTag("ImageAdj", "Nikon.ImgAdjust", "auto");
AddTag("Sharpness","Nikon.Sharp", "auto");
AddTag("Sharpness","Oly.Sharp", "normal");
}
*/
void PLExif::ExpandBinaryTag(const string & Src,
const _PLExifTagValues *Tags,
PLUINT Type,
PLExifTagList & sectionList)
{
PLUINT ElmSize, ElmFormat;
PLExifTag * SrcTag;
string Prefix;
size_t Index;
size_t Pos;
ostringstream oss;
SrcTag = GetTag(Src);
if (!SrcTag || SrcTag->m_Fmt != &PLExifTag::rgExifFormat[Type]) {
return ;
}
// Prefix is the original prefix
Prefix = Src;
Pos = Prefix.find(".");
if (Pos != string::npos)
{
Prefix = Prefix.substr(Pos+1);
Prefix += '.';
}
// Tag should be items of all one size. For now we are assuming they
// are type 3 (unsigned short)
ElmSize = PLExifTag::rgExifFormat[Type].Size;
ElmFormat = Type;
for (Index=0; Tags[Index].ShortName && Tags[Index].Tag < SrcTag->m_NoComp; Index++)
{
//
// Allocate a tag for this item
//
PLExifTagCPtr Tag(new PLExifTag(Tags[Index].Tag, ElmFormat, 1));
Tag->m_Tag = &Tags[Index];
Tag->m_ShortName = Prefix + Tag->m_Tag->ShortName;
memcpy (Tag->m_Buffer.get(), SrcTag->m_Buffer.get() + Tag->m_TagNo * ElmSize, ElmSize);
//
// If we are the wrong endian, then swizzle the data buffer
//
if (m_Endian) {
Tag->Swizzle();
}
//
// Print the value into a string
//
Tag->Render();
//
// Add this tag to the database
//
Tag->m_Lookup = Tag->m_ShortName;
MakeLower(Tag->m_Lookup);
m_AllTags.push_back(Tag); // add to all tags list
m_Tags[Tag->m_Lookup] = Tag; // add to the look up map
sectionList.push_back(Tag); // add to the section list
}
}
void PLExif::DecodeCanCustomFncs(const PLExifTag & rootTag, const _PLExifTagValues *Tags, PLExifTagList & sectionList)
{
string Prefix("CanonCFn.");
const unsigned short * datap = (const unsigned short *)rootTag.m_Buffer.get();
unsigned short count = *datap++ / 2; // step over the count
for (unsigned short i = 0; i < count; ++i, ++datap)
{
if (*datap & 0xFF00) // ignore a zero tag
{
ostringstream oss;
PLExifTagCPtr Tag(new PLExifTag((*datap & 0xFF00) >> 8, 1, 0)); // use auto_ptr for exception safety
//
// Create the tag's shortname (and initialize it's m_Tag)
//
oss << Prefix << setfill('0') << setw(2) << Tag->m_TagNo;
Tag->m_ShortName = oss.str();
for(size_t i = 0; Tags[i].ShortName; ++i)
{
if (Tags[i].Tag == Tag->m_TagNo)
{
Tag->m_Tag = &Tags[i];
Tag->m_ShortName = Prefix;
Tag->m_ShortName += Tag->m_Tag->ShortName;
break;
}
}
Tag->m_Int = *datap & 0x00FF;
Tag->m_UInt = Tag->m_Int;
Tag->DoTranslation();
//
// Add this tag to the database
//
Tag->m_Lookup = Tag->m_ShortName;
MakeLower(Tag->m_Lookup);
m_AllTags.push_back(Tag); // add to all tags list
m_Tags[Tag->m_Lookup] = Tag; // add to the look up map
sectionList.push_back(Tag); // add to the section list
}
}
}
// these functions were originally designed to read from a file
// they have been kept but are now "reading" from the vector m_Data
// I may remove at least the first couple later
void PLExif::SetPos(size_t pos)
{
m_Pos = pos + m_IdfOffset;
}
size_t PLExif::GetPos()
{
return m_Pos - m_IdfOffset;
}
void PLExif::Read(void * buffer, size_t size)
{
memcpy(buffer, m_Data.get() + m_Pos, size);
m_Pos += size;
}
PLWORD PLExif::GetU16()
{
PLWORD u16;
Read(&u16, sizeof(u16));
if (m_Endian) {
Swiz16((PLBYTE *) &u16);
}
return u16;
}
PLLONG PLExif::GetU32()
{
PLLONG u32;
Read(&u32, sizeof(u32));
if (m_Endian) {
Swiz32((PLBYTE *) &u32);
}
return u32;
}
/***************************************************************
*
* PLExifTag implementation
*
***************************************************************/
// true public interface
// C Interface - returning const char *
const char * PLExifTag::GetShortNameCStr() const
{
return m_ShortName.c_str();
}
const char * PLExifTag::GetDescriptionCStr() const
{
return m_Tag ? m_Tag->Desc : Nullstring.c_str();
}
// Format is basic as stored in the raw EXIF data
// eg f4.0 is likely to be 40/10
const char * PLExifTag::GetValueCStr() const
{
return m_Value.c_str();
}
// format is common form eg f4.0 is 4.0 rather than 40/10
const char * PLExifTag::GetValueCommonCStr() const
{
return m_Common.c_str();
}
// STL Interface - returning const string &
const string & PLExifTag::GetShortName() const
{
return m_ShortName;
}
const string PLExifTag::GetDescription() const
{
return m_Tag ? m_Tag->Desc : Nullstring;
}
// Format is basic as stored in the raw EXIF data
// eg f4.0 is likely to be 40/10
const string & PLExifTag::GetValue() const
{
return m_Value;
}
// format is common form eg f4.0 is 4.0 rather than 40/10
const string & PLExifTag::GetValueCommon() const
{
return m_Common;
}
// interface only used by PLExif
PLExifTag::PLExifTag(PLUINT TagNo, PLUINT Format, PLUINT NoComp)
: m_Tag(NULL)
, m_Fmt(NULL)
, m_Buffer(NULL)
, m_Size(0)
, m_Num(0)
, m_Den(1)
, m_Int(0)
, m_UInt(0)
, m_Double(0)
, m_TagNo(TagNo)
, m_Format(Format)
, m_NoComp(NoComp)
{
if (Format < 1 || Format > 12)
throw PLExifException("EXIF Tag format field not understood");
// Allocate a buffer for this tags data
m_Fmt = &rgExifFormat[Format];
m_Size = m_Fmt->Size * m_NoComp;
if (m_Size > 64*1024 || m_NoComp > 64*1024)
throw PLExifException("EXIF NoComp field not understood");
if (m_Size)
{
m_Buffer = PLByteCPtr(new PLBYTE [m_Size]);
}
}
PLExifTag::~PLExifTag()
{
m_Buffer = PLByteCPtr(0);
}
void PLExifTag::CleanWorkingArea()
{
m_Buffer = PLByteCPtr(0);
}
void PLExifTag::Swizzle()
// Data needs swizzled
{
if (m_Fmt->Swizzle)
{
PLBYTE * Buffer = m_Buffer.get();
for (size_t Index=0; Index < m_NoComp; ++Index)
{
m_Fmt->Swizzle(Buffer);
Buffer = Buffer + m_Fmt->Size;
}
}
}
void PLExifTag::Render()
{
size_t Index, Count;
PLBYTE * Buffer = m_Buffer.get();
m_Value.erase();
Index = 0;
Count = 0;
for (; ;)
{
Index += (this->*m_Fmt->Render)(Buffer);
if (Index >= m_NoComp)
break;
Count += 1;
if (Count >= 16)
{
m_Value += " ...";
break;
}
// Add a space between the array of values
m_Value += " ";
}
// Normalize the value into different formats
if (m_Den != 0)
{
m_Double = (float) m_Num / (float) m_Den;
m_Int = (PLULONG) (m_Double + 0.5);
m_UInt = (PLUINT) m_Int;
}
// set up the common string
if (m_Tag)
{
if (m_Tag->Convert)
(this->*m_Tag->Convert)(m_Common);
else
m_Common = m_Value;
}
DoTranslation();
// Trim trailing spaces from output
TrimRight(m_Value, ' ');
}
void PLExifTag::DoTranslation()
{
// See if there is any translation
if (m_Tag && m_Tag->Trans)
{
_PLExifTranslator *Trans;
Trans = m_Tag->Trans;
if (Trans[0].Value == VALUE_UNIT)
{
// Translator supplies units of value
m_Value += " ";
m_Common += " ";
m_Value += Trans[0].Desc;
m_Common += Trans[0].Desc;
}
else if (Trans[0].Value == VALUE_LOWER_STR)
{
MakeLower(m_Value);
m_Value[0] = toupper(m_Value[0]);
MakeLower(m_Common);
m_Common[0] = toupper(m_Common[0]);
}
else
{
// Lookup value's verbose name and use that
for (size_t Index=0; Trans[Index].Desc; Index++)
{
if (Trans[Index].Value == m_UInt)
{
m_Value = Trans[Index].Desc;
m_Common = Trans[Index].Desc;
break;
}
}
}
}
}
double PLExifTag::GetDouble(size_t Index)
{
Value(Index);
return m_Double;
}
void PLExifTag::Value(size_t Index)
{
string HoldValue = m_Value;
m_Num = 0;
m_Den = 0;
m_Int = 0;
m_UInt = 0;
m_Double = 0;
// If Index is in range, let's get it
if (Index <= m_NoComp)
{
PLBYTE * Buffer = m_Buffer.get();
// Render each element and stop at the one we want
size_t Count = 0;
while (Count <= Index)
{
m_Value = "";
Count += (this->*m_Fmt->Render)(Buffer);
}
}
// Normalize the value into different formats
if (m_Den != 0)
{
m_Double = (double) m_Num / (double) m_Den;
m_Int = (PLULONG) (m_Double + 0.5);
m_UInt = (PLUINT) m_Int;
}
// restore original string
m_Value = HoldValue;
}
//
// Render functions
//
size_t PLExifTag::RenUDef(PLBYTE * & Buffer)
// Default unsigned number of m_Fmt->Size
{
PLULONG Accum, Size;
ostringstream oss;
// Pull the value from the stream
Size = m_Fmt->Size;
memcpy (&Accum, Buffer, Size);
Accum = Accum & rgMask[Size];
// Append this value to the output
oss << Accum;
m_Value += oss.str();
// Remember last value
m_Num = Accum;
// Done - we handled 1 value of this type
Buffer += Size;
return 1;
}
size_t PLExifTag::RenDef(PLBYTE * &Buffer)
// Default signed number of m_Fmt->Size
{
PLULONG Size, Mask;
PLLONG Accum;
ostringstream oss;
// Pull the value from the stream
Size = m_Fmt->Size;
Mask = rgMask[Size];
memcpy (&Accum, Buffer, Size);
Accum = Accum & Mask;
// If the sign bit is set, sign extend the value
if (Accum & (1 << (Size * 8 - 1)))
Accum = Accum | (-1L ^ Mask);
// Append this value to the output
oss << Accum;
m_Value += oss.str();
m_Num = Accum;
// Done - we handled 1 value of this type
Buffer += Size;
return 1;
}
size_t PLExifTag::RenRat(PLBYTE * &Buffer)
// Signed Rational
{
PLLONG Num, Den;
ostringstream oss;
memcpy (&Num, Buffer, 4);
memcpy (&Den, Buffer+4, 4);
// Append this value to the output
oss << Num << '/' << Den;
m_Value += oss.str();
m_Num = Num;
m_Den = Den;
// Done - we handle 1 value of this type
Buffer += 8;
return 1;
}
size_t PLExifTag::RenURat(PLBYTE * &Buffer)
// Unsigned Rational
{
PLULONG Num, Den;
ostringstream oss;
memcpy (&Num, Buffer, 4);
memcpy (&Den, Buffer+4, 4);
// Append this value to the output
oss << Num << '/' << Den;
m_Value += oss.str();
m_Num = Num;
m_Den = Den;
// Done - we handle 1 value of this type
Buffer += 8;
return 1;
}
size_t PLExifTag::RenStr(PLBYTE * &Buffer)
{
size_t Index;
PLBYTE c;
char Str[20];
ostringstream oss;
Index = 0;
while (*Buffer && Index < m_Size)
{
c = *Buffer;
if (c >= ' ' && c <= 127)
{
m_Value += c;
}
else
{
switch (c)
{
case '\n':
strcpy(Str, "\\n");
break;
case '\r':
strcpy(Str, "\\r");
break;
case '\t':
strcpy(Str, "\\t");
break;
case '\b':
strcpy(Str, "\\b");
break;
default:
sprintf(Str, "\\0x%02x", c);
}
m_Value += Str;
}
// Next char
Buffer += 1;
Index += 1;
}
// Done - we handled the whole value
return m_NoComp;
}
size_t PLExifTag::RenUndef(PLBYTE * &Buffer)
{
bool AscStr;
size_t Index, Size;
PLBYTE c;
char Str[20];
AscStr = true;
for(Index=0; Index < m_Size; Index++)
{
c = Buffer[Index];
if ((c < ' '|| c > 127) && c != 0 && c != '\n' && c != '\r' && c != '\t' && c != '\b')
{
AscStr = false;
break;
}
}
if (AscStr)
{
return RenStr(Buffer);
}
else
{
// Dump the leading bytes
Size = m_Size;
if (Size > 16)
Size = 16;
m_Value += "{ ";
for(Index=0; Index < Size; Index++)
{
sprintf(Str, "%02x ", Buffer[Index]);
m_Value += Str;
}
if (Size != m_Size)
m_Value += "... ";
m_Value += "}";
// Take the last byte as our default value
m_Num = Buffer[m_Size-1];
// Done - we handled the whole value
return m_NoComp;
}
}
// evaluate nominator/denominator
void PLExifTag::CnvRat(std::string & result)
{
if (m_Den)
{
ostringstream oss;
oss << double(m_Num) / double(m_Den);
result = oss.str();
}
else
result = m_Value;
}
// evaluate nominator/denominator for fstop
void PLExifTag::CnvRatAp(std::string & result)
{
if (m_Den)
{
ostringstream oss;
oss << 'f' << round(double(m_Num) / double(m_Den), 1);
result = oss.str();
}
else
result = m_Value;
}
// evaluate nominator/denominator if greater than 1
// and reduce to 1/x
void PLExifTag::CnvFrac(std::string & result)
{
ostringstream oss;
if (m_Den && m_Den <= m_Num)
{
oss << double(m_Num) / double(m_Den);
result = oss.str();
}
else if (m_Num != 1 && m_Num != 0)
{
oss << "1/" << m_Den / m_Num;
result = oss.str();
}
else
result = m_Value;
}
void PLExifTag::CnvApexShutter(std::string & result)
{
if (m_Den)
{
ostringstream oss;
double d = 0.0;
d = double(m_Num) / double(m_Den);
d = pow(2.0, d);
oss << 1 << '/' << round(d, 0) << " s";
result = oss.str();
}
else
result = m_Value;
}
void PLExifTag::CnvApexAp(std::string & result)
{
if (m_Den)
{
ostringstream oss;
double d = 0.0;
d = double(m_Num) / double(m_Den);
d = pow(1.4142, d);
oss << 'f' << round(d, 1);
result = oss.str();
}
else
result = m_Value;
}
void PLExifTag::CnvCompCfg(std::string & result)
{
result.erase();
istringstream iss(m_Value.c_str());
string val;
iss >> val; // reject leading {
for (int i = 0; i < 4; ++i) // read four values
{
iss >> val;
if (val == "00")
; // ignore
else if (val == "01")
result += 'Y';
else if (val == "02")
result += "Cb";
else if (val == "03")
result += "Cr";
else if (val == "04")
result += 'R';
else if (val == "05")
result += 'G';
else if (val == "06")
result += 'B';
else
{
result += ' ';
result += val;
}
}
}
// decode canon image number
void PLExifTag::CnvCanINo(std::string & result)
{
ostringstream oss;
oss << setfill('0') << setw(3) << m_Int / 10000 << '-' << setw(4) << m_Int % 10000;
result = oss.str();
}
// decode canon serial number
void PLExifTag::CnvCanSNo(std::string & result)
{
ostringstream oss;
unsigned short * low = (unsigned short *)&m_Int;
unsigned short * high = low + 1;
oss << setfill('0') << setw(4) << hex << *high;
oss << setw(5) << dec << *low;
result = oss.str();
}
// decode canon flash details
void PLExifTag::CnvCanFlash(std::string & result)
{
result.erase();
if (0x4000 & m_Int)
result += "External E-TTL ";
if (0x2000 & m_Int)
result += "Internal Flash ";
if (0x0800 & m_Int)
result += "FP sync used ";
if (0x0010 & m_Int)
result += "FP sync enabled ";
}
// decode canon flash details
void PLExifTag::CnvCanAFPnt(string & result)
{
result.erase();
if (0xF000 & m_Int)
{
switch(0x0FFF & m_Int)
{
case 0:
result = "Right";
break;
case 1:
result = "Centre";
break;
case 2:
result = "Left";
break;
}
}
}
|