Project

General

Profile

Decoding ShutterCount for Pentax images ยป pentax_shutter_count_tag_decoding.diff

Patch for decoding Pentax ShutterCount tag's value - Alexey Serbin, 09 Sep 2016 06:08

View differences:

src/easyaccess.cpp (working copy)
161 161
            if (md_st == ed.end())
162 162
                break;
163 163
            // otherwise pick up actual value and grab value accordingly
164
            const char *st_key = 0; // nullptr
165 164
            std::ostringstream os;
166 165
            md_st->write(os, &ed);
167 166
            bool ok = false;
src/pentaxmn.cpp (working copy)
22 22
  File:      pentaxmn.cpp
23 23
  Version:   $Rev$
24 24
  Author(s): Michal Cihar <michal@cihar.com>
25
             Alexey Serbin <aserbin at gmail dot com>
25 26
  Based on fujimn.cpp by:
26 27
             Andreas Huggel (ahu) <ahuggel@gmx.net>
27 28
             Gilles Caulier (gc) <caulier dot gilles at gmail dot com>
28 29
  History:   27-Sep-07 created
30
             08-Sep-16 (aserbin) added decoding for the ShutterCount tag
29 31
  Credits:   See header file.
30 32
 */
31 33
// *****************************************************************************
......
44 46
#include "i18n.h"                // NLS support.
45 47

  
46 48
// + standard includes
49
#include <cstdint>
50
#include <iomanip>
47 51
#include <string>
48
#include <sstream>
49
#include <iomanip>
50
#include <cassert>
51
#include <cstring>
52 52

  
53 53
// *****************************************************************************
54 54
// class member definitions
......
1013 1013
        {   4, N_("Custom") },
1014 1014
    };
1015 1015

  
1016
    std::ostream& PentaxMakerNote::printPentaxVersion(std::ostream& os, const Value& value, const ExifData*)
1016
    std::ostream& PentaxMakerNote::printVersion(std::ostream& os, const Value& value, const ExifData*)
1017 1017
    {
1018 1018
        std::string val = value.toString();
1019 1019
        size_t i;
......
1024 1024
        return os;
1025 1025
    }
1026 1026

  
1027
    std::ostream& PentaxMakerNote::printPentaxResolution(std::ostream& os, const Value& value, const ExifData*)
1027
    std::ostream& PentaxMakerNote::printResolution(std::ostream& os, const Value& value, const ExifData*)
1028 1028
    {
1029 1029
        std::string val = value.toString();
1030 1030
        size_t i;
......
1035 1035
        return os;
1036 1036
    }
1037 1037

  
1038
    std::ostream& PentaxMakerNote::printPentaxDate(std::ostream& os, const Value& value, const ExifData*)
1038
    std::ostream& PentaxMakerNote::printDate(std::ostream& os, const Value& value, const ExifData*)
1039 1039
    {
1040 1040
        /* I choose same format as is used inside EXIF itself */
1041 1041
        os << ((value.toLong(0) << 8) + value.toLong(1));
......
1046 1046
        return os;
1047 1047
    }
1048 1048

  
1049
    std::ostream& PentaxMakerNote::printPentaxTime(std::ostream& os, const Value& value, const ExifData*)
1049
    std::ostream& PentaxMakerNote::printTime(std::ostream& os, const Value& value, const ExifData*)
1050 1050
    {
1051 1051
        std::ios::fmtflags f( os.flags() );
1052 1052
        os << std::setw(2) << std::setfill('0') << value.toLong(0);
......
1058 1058
        return os;
1059 1059
    }
1060 1060

  
1061
    std::ostream& PentaxMakerNote::printPentaxExposure(std::ostream& os, const Value& value, const ExifData*)
1061
    std::ostream& PentaxMakerNote::printExposure(std::ostream& os, const Value& value, const ExifData*)
1062 1062
    {
1063 1063
        os << static_cast<float>(value.toLong()) / 100 << " ms";
1064 1064
        return os;
1065 1065
    }
1066 1066

  
1067
    std::ostream& PentaxMakerNote::printPentaxFValue(std::ostream& os, const Value& value, const ExifData*)
1067
    std::ostream& PentaxMakerNote::printFValue(std::ostream& os, const Value& value, const ExifData*)
1068 1068
    {
1069 1069
        std::ios::fmtflags f( os.flags() );
1070 1070
        os << "F" << std::setprecision(2)
......
1073 1073
        return os;
1074 1074
    }
1075 1075

  
1076
    std::ostream& PentaxMakerNote::printPentaxFocalLength(std::ostream& os, const Value& value, const ExifData*)
1076
    std::ostream& PentaxMakerNote::printFocalLength(std::ostream& os, const Value& value, const ExifData*)
1077 1077
    {
1078 1078
        std::ios::fmtflags f( os.flags() );
1079 1079
        os << std::fixed << std::setprecision(1)
......
1083 1083
        return os;
1084 1084
    }
1085 1085

  
1086
    std::ostream& PentaxMakerNote::printPentaxCompensation(std::ostream& os, const Value& value, const ExifData*)
1086
    std::ostream& PentaxMakerNote::printCompensation(std::ostream& os, const Value& value, const ExifData*)
1087 1087
    {
1088 1088
        std::ios::fmtflags f( os.flags() );
1089 1089
        os << std::setprecision(2)
......
1093 1093
        return os;
1094 1094
    }
1095 1095

  
1096
    std::ostream& PentaxMakerNote::printPentaxTemperature(std::ostream& os, const Value& value, const ExifData*)
1096
    std::ostream& PentaxMakerNote::printTemperature(std::ostream& os, const Value& value, const ExifData*)
1097 1097
    {
1098 1098
        os << value.toLong() << " C";
1099 1099
        return os;
1100 1100
    }
1101 1101

  
1102
    std::ostream& PentaxMakerNote::printPentaxFlashCompensation(std::ostream& os, const Value& value, const ExifData*)
1102
    std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Value& value, const ExifData*)
1103 1103
    {
1104 1104
        std::ios::fmtflags f( os.flags() );
1105 1105
        os << std::setprecision(2)
......
1109 1109
        return os;
1110 1110
    }
1111 1111

  
1112
    std::ostream& PentaxMakerNote::printPentaxBracketing(std::ostream& os, const Value& value, const ExifData*)
1112
    std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*)
1113 1113
    {
1114 1114
        long l0 = value.toLong(0);
1115 1115

  
......
1160 1160
        return os;
1161 1161
    }
1162 1162

  
1163
    std::ostream& PentaxMakerNote::printShutterCount(std::ostream& os, const Value& value, const ExifData* metadata)
1164
    {
1165
        ExifData::const_iterator dateIt = metadata->findKey(
1166
                ExifKey("Exif.PentaxDng.Date"));
1167
        if (dateIt == metadata->end()) {
1168
            dateIt = metadata->findKey(ExifKey("Exif.Pentax.Date"));
1169
        }
1170
        ExifData::const_iterator timeIt = metadata->findKey(
1171
                ExifKey("Exif.PentaxDng.Time"));
1172
        if (timeIt == metadata->end()) {
1173
            timeIt = metadata->findKey(ExifKey("Exif.Pentax.Time"));
1174
        }
1175
        if (    dateIt == metadata->end() || dateIt->size() != 4 ||
1176
                timeIt == metadata->end() || timeIt->size() != 3 ||
1177
                value.size() != 4) {
1178
            os << "undefined";
1179
            return os;
1180
        }
1181
        const uint32_t date =
1182
            (dateIt->toLong(0) << 24) + (dateIt->toLong(1) << 16) +
1183
            (dateIt->toLong(2) <<  8) + (dateIt->toLong(3) <<  0);
1184
        const uint32_t time =
1185
            (timeIt->toLong(0) << 24) + (timeIt->toLong(1) << 16) +
1186
            (timeIt->toLong(2) <<  8);
1187
        const uint32_t countEnc =
1188
            (value.toLong(0) << 24) + (value.toLong(1) << 16) +
1189
            (value.toLong(2) <<  8) + (value.toLong(3) <<  0);
1190
        // The shutter count is encoded using date and time values stored
1191
        // in Pentax-specific tags.  The prototype for the encoding/decoding
1192
        // function is taken from Phil Harvey's ExifTool: Pentax.pm file,
1193
        // CryptShutterCount() routine.
1194
        const uint32_t count = countEnc ^ date ^ (~time);
1195
        os << count;
1196
        return os;
1197
    }
1198

  
1163 1199
    // #1144 begin
1164 1200
    static std::string getKeyString(const std::string& key,const ExifData* metadata)
1165 1201
    {
......
1389 1425
    const TagInfo PentaxMakerNote::tagInfo_[] = {
1390 1426
        TagInfo(0x0000, "Version", N_("Version"),
1391 1427
                N_("Pentax Makernote version"),
1392
                pentaxId, makerTags, undefined, -1, printPentaxVersion),
1428
                pentaxId, makerTags, undefined, -1, printVersion),
1393 1429
        TagInfo(0x0001, "Mode", N_("Shooting mode"),
1394 1430
                N_("Camera shooting mode"),
1395 1431
                pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxShootingMode)),
1396 1432
        TagInfo(0x0002, "PreviewResolution", N_("Resolution of a preview image"),
1397 1433
                N_("Resolution of a preview image"),
1398
                pentaxId, makerTags, undefined, -1, printPentaxResolution),
1434
                pentaxId, makerTags, undefined, -1, printResolution),
1399 1435
        TagInfo(0x0003, "PreviewLength", N_("Length of a preview image"),
1400 1436
                N_("Size of an IFD containing a preview image"),
1401 1437
                pentaxId, makerTags, undefined, -1, printValue),
......
1407 1443
                pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxModel)),
1408 1444
        TagInfo(0x0006, "Date", N_("Date"),
1409 1445
                N_("Date"),
1410
                pentaxId, makerTags, undefined, -1, printPentaxDate),
1446
                pentaxId, makerTags, undefined, -1, printDate),
1411 1447
        TagInfo(0x0007, "Time", N_("Time"),
1412 1448
                N_("Time"),
1413
                pentaxId, makerTags, undefined, -1, printPentaxTime),
1449
                pentaxId, makerTags, undefined, -1, printTime),
1414 1450
        TagInfo(0x0008, "Quality", N_("Image quality"),
1415 1451
                N_("Image quality settings"),
1416 1452
                pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxQuality)),
......
1433 1469
        /* Some missing ! */
1434 1470
        TagInfo(0x0012, "ExposureTime", N_("Exposure time"),
1435 1471
                N_("Exposure time"),
1436
                pentaxId, makerTags, unsignedLong, -1, printPentaxExposure),
1472
                pentaxId, makerTags, unsignedLong, -1, printExposure),
1437 1473
        TagInfo(0x0013, "FNumber", N_("F-Number"),
1438 1474
                N_("F-Number"),
1439
                pentaxId, makerTags, unsignedLong, -1, printPentaxFValue),
1475
                pentaxId, makerTags, unsignedLong, -1, printFValue),
1440 1476
        TagInfo(0x0014, "ISO", N_("ISO sensitivity"),
1441 1477
                N_("ISO sensitivity settings"),
1442 1478
                pentaxId, makerTags, unsignedLong, -1, EXV_PRINT_TAG(pentaxISO)),
1443 1479
        /* Some missing ! */
1444 1480
        TagInfo(0x0016, "ExposureCompensation", N_("Exposure compensation"),
1445 1481
                N_("Exposure compensation"),
1446
                pentaxId, makerTags, unsignedLong, -1, printPentaxCompensation),
1482
                pentaxId, makerTags, unsignedLong, -1, printCompensation),
1447 1483
        /* Some missing ! */
1448 1484
        TagInfo(0x0017, "MeteringMode", N_("MeteringMode"),
1449 1485
                N_("MeteringMode"),
1450 1486
                pentaxId, makerTags, undefined, -1, EXV_PRINT_TAG(pentaxMeteringMode)),
1451 1487
        TagInfo(0x0018, "AutoBracketing", N_("AutoBracketing"),
1452 1488
                N_("AutoBracketing"),
1453
                pentaxId, makerTags, undefined, -1, printPentaxBracketing),
1489
                pentaxId, makerTags, undefined, -1, printBracketing),
1454 1490
        TagInfo(0x0019, "WhiteBalance", N_("White balance"),
1455 1491
                N_("White balance"),
1456 1492
                pentaxId, makerTags, undefined, -1, EXV_PRINT_TAG(pentaxWhiteBalance)),
......
1465 1501
                pentaxId, makerTags, unsignedLong, -1, printValue),
1466 1502
        TagInfo(0x001d, "FocalLength", N_("FocalLength"),
1467 1503
                N_("FocalLength"),
1468
                pentaxId, makerTags, undefined, -1, printPentaxFocalLength),
1504
                pentaxId, makerTags, undefined, -1, printFocalLength),
1469 1505
        TagInfo(0x001e, "DigitalZoom", N_("Digital zoom"),
1470 1506
                N_("Digital zoom"),
1471 1507
                pentaxId, makerTags, unsignedLong, -1, printValue),
......
1542 1578
        /* Some missing ! */
1543 1579
        TagInfo(0x0047, "Temperature", N_("Temperature"),
1544 1580
                N_("Camera temperature"),
1545
                pentaxId, makerTags, signedByte, -1, printPentaxTemperature),
1581
                pentaxId, makerTags, signedByte, -1, printTemperature),
1546 1582
        TagInfo(0x0048, "AELock", N_("AE lock"),
1547 1583
                N_("AE lock"),
1548 1584
                pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxOffOn)),
......
1552 1588
        /* Some missing ! */
1553 1589
        TagInfo(0x004d, "FlashExposureCompensation", N_("Flash exposure compensation"),
1554 1590
                N_("Flash exposure compensation"),
1555
                pentaxId, makerTags, signedLong, -1, printPentaxFlashCompensation),
1591
                pentaxId, makerTags, signedLong, -1, printFlashCompensation),
1556 1592
        /* Some missing ! */
1557 1593
        TagInfo(0x004f, "ImageTone", N_("Image tone"),
1558 1594
                N_("Image tone"),
......
1566 1602
                pentaxId, makerTags, undefined, -1, printValue),
1567 1603
        TagInfo(0x005d, "ShutterCount", N_("Shutter count"),
1568 1604
                N_("Shutter count"),
1569
                pentaxId, makerTags, undefined, -1, printValue), /* TODO: This has some encryption by date (see exiftool) */
1605
                pentaxId, makerTags, undefined, -1, printShutterCount),
1570 1606
        TagInfo(0x0069, "DynamicRangeExpansion", N_("Dynamic range expansion"),
1571 1607
                N_("Dynamic range expansion"),
1572 1608
                pentaxId, makerTags, undefined, -1, EXV_PRINT_COMBITAG(pentaxDynamicRangeExpansion, 4, 0)),
......
1656 1692
        return tagInfo_;
1657 1693
    }
1658 1694

  
1659
}}                                       // namespace Internal, Exiv2
1695
    } // namespace Internal
1696
} // namespace Exiv2
src/pentaxmn_int.hpp (working copy)
39 39
#include "types.hpp"
40 40

  
41 41
// + standard includes
42
#include <string>
43 42
#include <iostream>
44 43
#include <iomanip>
45
#include <memory>
46 44

  
47 45
// *****************************************************************************
48 46
// namespace extensions
......
59 57
        static const TagInfo* tagList();
60 58

  
61 59
        //! Print Pentax version
62
        static std::ostream& printPentaxVersion(std::ostream& os, const Value& value, const ExifData*);
60
        static std::ostream& printVersion(std::ostream& os, const Value& value, const ExifData*);
63 61
        //! Print Pentax resolution
64
        static std::ostream& printPentaxResolution(std::ostream& os, const Value& value, const ExifData*);
62
        static std::ostream& printResolution(std::ostream& os, const Value& value, const ExifData*);
65 63
        //! Print Pentax date
66
        static std::ostream& printPentaxDate(std::ostream& os, const Value& value, const ExifData*);
64
        static std::ostream& printDate(std::ostream& os, const Value& value, const ExifData*);
67 65
        //! Print Pentax time
68
        static std::ostream& printPentaxTime(std::ostream& os, const Value& value, const ExifData*);
66
        static std::ostream& printTime(std::ostream& os, const Value& value, const ExifData*);
69 67
        //! Print Pentax exposure
70
        static std::ostream& printPentaxExposure(std::ostream& os, const Value& value, const ExifData*);
68
        static std::ostream& printExposure(std::ostream& os, const Value& value, const ExifData*);
71 69
        //! Print Pentax F value
72
        static std::ostream& printPentaxFValue(std::ostream& os, const Value& value, const ExifData*);
70
        static std::ostream& printFValue(std::ostream& os, const Value& value, const ExifData*);
73 71
        //! Print Pentax focal length
74
        static std::ostream& printPentaxFocalLength(std::ostream& os, const Value& value, const ExifData*);
72
        static std::ostream& printFocalLength(std::ostream& os, const Value& value, const ExifData*);
75 73
        //! Print Pentax compensation
76
        static std::ostream& printPentaxCompensation(std::ostream& os, const Value& value, const ExifData*);
74
        static std::ostream& printCompensation(std::ostream& os, const Value& value, const ExifData*);
77 75
        //! Print Pentax temperature
78
        static std::ostream& printPentaxTemperature(std::ostream& os, const Value& value, const ExifData*);
76
        static std::ostream& printTemperature(std::ostream& os, const Value& value, const ExifData*);
79 77
        //! Print Pentax flash compensation
80
        static std::ostream& printPentaxFlashCompensation(std::ostream& os, const Value& value, const ExifData*);
78
        static std::ostream& printFlashCompensation(std::ostream& os, const Value& value, const ExifData*);
81 79
        //! Print Pentax bracketing
82
        static std::ostream& printPentaxBracketing(std::ostream& os, const Value& value, const ExifData*);
80
        static std::ostream& printBracketing(std::ostream& os, const Value& value, const ExifData*);
81
        //! Print Pentax shutter count
82
        static std::ostream& printShutterCount(std::ostream& os, const Value& value, const ExifData*);
83 83

  
84 84
    private:
85 85
        //! Tag information
......
123 123
//! Shortcut for the printCombiTag template which requires typing the array name only once.
124 124
#define EXV_PRINT_COMBITAG_MULTI(array, count, ignoredcount, ignoredcountmax) printCombiTag<EXV_COUNTOF(array), array, count, ignoredcount, ignoredcountmax>
125 125

  
126
}}                                      // namespace Internal, Exiv2
126
    } // namespace Internal
127
} // namespace Exiv2
128
    
127 129

  
128 130
#endif                                  // #ifndef PENTAXMN_INT_HPP_
    (1-1/1)