Index: src/easyaccess.cpp
===================================================================
--- src/easyaccess.cpp	(revision 4473)
+++ src/easyaccess.cpp	(working copy)
@@ -161,7 +161,6 @@
             if (md_st == ed.end())
                 break;
             // otherwise pick up actual value and grab value accordingly
-            const char *st_key = 0; // nullptr
             std::ostringstream os;
             md_st->write(os, &ed);
             bool ok = false;
Index: src/pentaxmn.cpp
===================================================================
--- src/pentaxmn.cpp	(revision 4473)
+++ src/pentaxmn.cpp	(working copy)
@@ -22,10 +22,12 @@
   File:      pentaxmn.cpp
   Version:   $Rev$
   Author(s): Michal Cihar <michal@cihar.com>
+             Alexey Serbin <aserbin at gmail dot com>
   Based on fujimn.cpp by:
              Andreas Huggel (ahu) <ahuggel@gmx.net>
              Gilles Caulier (gc) <caulier dot gilles at gmail dot com>
   History:   27-Sep-07 created
+             08-Sep-16 (aserbin) added decoding for the ShutterCount tag
   Credits:   See header file.
  */
 // *****************************************************************************
@@ -44,11 +46,9 @@
 #include "i18n.h"                // NLS support.
 
 // + standard includes
+#include <cstdint>
+#include <iomanip>
 #include <string>
-#include <sstream>
-#include <iomanip>
-#include <cassert>
-#include <cstring>
 
 // *****************************************************************************
 // class member definitions
@@ -1013,7 +1013,7 @@
         {   4, N_("Custom") },
     };
 
-    std::ostream& PentaxMakerNote::printPentaxVersion(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printVersion(std::ostream& os, const Value& value, const ExifData*)
     {
         std::string val = value.toString();
         size_t i;
@@ -1024,7 +1024,7 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxResolution(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printResolution(std::ostream& os, const Value& value, const ExifData*)
     {
         std::string val = value.toString();
         size_t i;
@@ -1035,7 +1035,7 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxDate(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printDate(std::ostream& os, const Value& value, const ExifData*)
     {
         /* I choose same format as is used inside EXIF itself */
         os << ((value.toLong(0) << 8) + value.toLong(1));
@@ -1046,7 +1046,7 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxTime(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printTime(std::ostream& os, const Value& value, const ExifData*)
     {
         std::ios::fmtflags f( os.flags() );
         os << std::setw(2) << std::setfill('0') << value.toLong(0);
@@ -1058,13 +1058,13 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxExposure(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printExposure(std::ostream& os, const Value& value, const ExifData*)
     {
         os << static_cast<float>(value.toLong()) / 100 << " ms";
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxFValue(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printFValue(std::ostream& os, const Value& value, const ExifData*)
     {
         std::ios::fmtflags f( os.flags() );
         os << "F" << std::setprecision(2)
@@ -1073,7 +1073,7 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxFocalLength(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printFocalLength(std::ostream& os, const Value& value, const ExifData*)
     {
         std::ios::fmtflags f( os.flags() );
         os << std::fixed << std::setprecision(1)
@@ -1083,7 +1083,7 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxCompensation(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printCompensation(std::ostream& os, const Value& value, const ExifData*)
     {
         std::ios::fmtflags f( os.flags() );
         os << std::setprecision(2)
@@ -1093,13 +1093,13 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxTemperature(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printTemperature(std::ostream& os, const Value& value, const ExifData*)
     {
         os << value.toLong() << " C";
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxFlashCompensation(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Value& value, const ExifData*)
     {
         std::ios::fmtflags f( os.flags() );
         os << std::setprecision(2)
@@ -1109,7 +1109,7 @@
         return os;
     }
 
-    std::ostream& PentaxMakerNote::printPentaxBracketing(std::ostream& os, const Value& value, const ExifData*)
+    std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*)
     {
         long l0 = value.toLong(0);
 
@@ -1160,6 +1160,42 @@
         return os;
     }
 
+    std::ostream& PentaxMakerNote::printShutterCount(std::ostream& os, const Value& value, const ExifData* metadata)
+    {
+        ExifData::const_iterator dateIt = metadata->findKey(
+                ExifKey("Exif.PentaxDng.Date"));
+        if (dateIt == metadata->end()) {
+            dateIt = metadata->findKey(ExifKey("Exif.Pentax.Date"));
+        }
+        ExifData::const_iterator timeIt = metadata->findKey(
+                ExifKey("Exif.PentaxDng.Time"));
+        if (timeIt == metadata->end()) {
+            timeIt = metadata->findKey(ExifKey("Exif.Pentax.Time"));
+        }
+        if (    dateIt == metadata->end() || dateIt->size() != 4 ||
+                timeIt == metadata->end() || timeIt->size() != 3 ||
+                value.size() != 4) {
+            os << "undefined";
+            return os;
+        }
+        const uint32_t date =
+            (dateIt->toLong(0) << 24) + (dateIt->toLong(1) << 16) +
+            (dateIt->toLong(2) <<  8) + (dateIt->toLong(3) <<  0);
+        const uint32_t time =
+            (timeIt->toLong(0) << 24) + (timeIt->toLong(1) << 16) +
+            (timeIt->toLong(2) <<  8);
+        const uint32_t countEnc =
+            (value.toLong(0) << 24) + (value.toLong(1) << 16) +
+            (value.toLong(2) <<  8) + (value.toLong(3) <<  0);
+        // The shutter count is encoded using date and time values stored
+        // in Pentax-specific tags.  The prototype for the encoding/decoding
+        // function is taken from Phil Harvey's ExifTool: Pentax.pm file,
+        // CryptShutterCount() routine.
+        const uint32_t count = countEnc ^ date ^ (~time);
+        os << count;
+        return os;
+    }
+
     // #1144 begin
     static std::string getKeyString(const std::string& key,const ExifData* metadata)
     {
@@ -1389,13 +1425,13 @@
     const TagInfo PentaxMakerNote::tagInfo_[] = {
         TagInfo(0x0000, "Version", N_("Version"),
                 N_("Pentax Makernote version"),
-                pentaxId, makerTags, undefined, -1, printPentaxVersion),
+                pentaxId, makerTags, undefined, -1, printVersion),
         TagInfo(0x0001, "Mode", N_("Shooting mode"),
                 N_("Camera shooting mode"),
                 pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxShootingMode)),
         TagInfo(0x0002, "PreviewResolution", N_("Resolution of a preview image"),
                 N_("Resolution of a preview image"),
-                pentaxId, makerTags, undefined, -1, printPentaxResolution),
+                pentaxId, makerTags, undefined, -1, printResolution),
         TagInfo(0x0003, "PreviewLength", N_("Length of a preview image"),
                 N_("Size of an IFD containing a preview image"),
                 pentaxId, makerTags, undefined, -1, printValue),
@@ -1407,10 +1443,10 @@
                 pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxModel)),
         TagInfo(0x0006, "Date", N_("Date"),
                 N_("Date"),
-                pentaxId, makerTags, undefined, -1, printPentaxDate),
+                pentaxId, makerTags, undefined, -1, printDate),
         TagInfo(0x0007, "Time", N_("Time"),
                 N_("Time"),
-                pentaxId, makerTags, undefined, -1, printPentaxTime),
+                pentaxId, makerTags, undefined, -1, printTime),
         TagInfo(0x0008, "Quality", N_("Image quality"),
                 N_("Image quality settings"),
                 pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxQuality)),
@@ -1433,24 +1469,24 @@
         /* Some missing ! */
         TagInfo(0x0012, "ExposureTime", N_("Exposure time"),
                 N_("Exposure time"),
-                pentaxId, makerTags, unsignedLong, -1, printPentaxExposure),
+                pentaxId, makerTags, unsignedLong, -1, printExposure),
         TagInfo(0x0013, "FNumber", N_("F-Number"),
                 N_("F-Number"),
-                pentaxId, makerTags, unsignedLong, -1, printPentaxFValue),
+                pentaxId, makerTags, unsignedLong, -1, printFValue),
         TagInfo(0x0014, "ISO", N_("ISO sensitivity"),
                 N_("ISO sensitivity settings"),
                 pentaxId, makerTags, unsignedLong, -1, EXV_PRINT_TAG(pentaxISO)),
         /* Some missing ! */
         TagInfo(0x0016, "ExposureCompensation", N_("Exposure compensation"),
                 N_("Exposure compensation"),
-                pentaxId, makerTags, unsignedLong, -1, printPentaxCompensation),
+                pentaxId, makerTags, unsignedLong, -1, printCompensation),
         /* Some missing ! */
         TagInfo(0x0017, "MeteringMode", N_("MeteringMode"),
                 N_("MeteringMode"),
                 pentaxId, makerTags, undefined, -1, EXV_PRINT_TAG(pentaxMeteringMode)),
         TagInfo(0x0018, "AutoBracketing", N_("AutoBracketing"),
                 N_("AutoBracketing"),
-                pentaxId, makerTags, undefined, -1, printPentaxBracketing),
+                pentaxId, makerTags, undefined, -1, printBracketing),
         TagInfo(0x0019, "WhiteBalance", N_("White balance"),
                 N_("White balance"),
                 pentaxId, makerTags, undefined, -1, EXV_PRINT_TAG(pentaxWhiteBalance)),
@@ -1465,7 +1501,7 @@
                 pentaxId, makerTags, unsignedLong, -1, printValue),
         TagInfo(0x001d, "FocalLength", N_("FocalLength"),
                 N_("FocalLength"),
-                pentaxId, makerTags, undefined, -1, printPentaxFocalLength),
+                pentaxId, makerTags, undefined, -1, printFocalLength),
         TagInfo(0x001e, "DigitalZoom", N_("Digital zoom"),
                 N_("Digital zoom"),
                 pentaxId, makerTags, unsignedLong, -1, printValue),
@@ -1542,7 +1578,7 @@
         /* Some missing ! */
         TagInfo(0x0047, "Temperature", N_("Temperature"),
                 N_("Camera temperature"),
-                pentaxId, makerTags, signedByte, -1, printPentaxTemperature),
+                pentaxId, makerTags, signedByte, -1, printTemperature),
         TagInfo(0x0048, "AELock", N_("AE lock"),
                 N_("AE lock"),
                 pentaxId, makerTags, unsignedShort, -1, EXV_PRINT_TAG(pentaxOffOn)),
@@ -1552,7 +1588,7 @@
         /* Some missing ! */
         TagInfo(0x004d, "FlashExposureCompensation", N_("Flash exposure compensation"),
                 N_("Flash exposure compensation"),
-                pentaxId, makerTags, signedLong, -1, printPentaxFlashCompensation),
+                pentaxId, makerTags, signedLong, -1, printFlashCompensation),
         /* Some missing ! */
         TagInfo(0x004f, "ImageTone", N_("Image tone"),
                 N_("Image tone"),
@@ -1566,7 +1602,7 @@
                 pentaxId, makerTags, undefined, -1, printValue),
         TagInfo(0x005d, "ShutterCount", N_("Shutter count"),
                 N_("Shutter count"),
-                pentaxId, makerTags, undefined, -1, printValue), /* TODO: This has some encryption by date (see exiftool) */
+                pentaxId, makerTags, undefined, -1, printShutterCount),
         TagInfo(0x0069, "DynamicRangeExpansion", N_("Dynamic range expansion"),
                 N_("Dynamic range expansion"),
                 pentaxId, makerTags, undefined, -1, EXV_PRINT_COMBITAG(pentaxDynamicRangeExpansion, 4, 0)),
@@ -1656,4 +1692,5 @@
         return tagInfo_;
     }
 
-}}                                       // namespace Internal, Exiv2
+    } // namespace Internal
+} // namespace Exiv2
Index: src/pentaxmn_int.hpp
===================================================================
--- src/pentaxmn_int.hpp	(revision 4473)
+++ src/pentaxmn_int.hpp	(working copy)
@@ -39,10 +39,8 @@
 #include "types.hpp"
 
 // + standard includes
-#include <string>
 #include <iostream>
 #include <iomanip>
-#include <memory>
 
 // *****************************************************************************
 // namespace extensions
@@ -59,27 +57,29 @@
         static const TagInfo* tagList();
 
         //! Print Pentax version
-        static std::ostream& printPentaxVersion(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printVersion(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax resolution
-        static std::ostream& printPentaxResolution(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printResolution(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax date
-        static std::ostream& printPentaxDate(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printDate(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax time
-        static std::ostream& printPentaxTime(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printTime(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax exposure
-        static std::ostream& printPentaxExposure(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printExposure(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax F value
-        static std::ostream& printPentaxFValue(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printFValue(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax focal length
-        static std::ostream& printPentaxFocalLength(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printFocalLength(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax compensation
-        static std::ostream& printPentaxCompensation(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printCompensation(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax temperature
-        static std::ostream& printPentaxTemperature(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printTemperature(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax flash compensation
-        static std::ostream& printPentaxFlashCompensation(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printFlashCompensation(std::ostream& os, const Value& value, const ExifData*);
         //! Print Pentax bracketing
-        static std::ostream& printPentaxBracketing(std::ostream& os, const Value& value, const ExifData*);
+        static std::ostream& printBracketing(std::ostream& os, const Value& value, const ExifData*);
+        //! Print Pentax shutter count
+        static std::ostream& printShutterCount(std::ostream& os, const Value& value, const ExifData*);
 
     private:
         //! Tag information
@@ -123,6 +123,8 @@
 //! Shortcut for the printCombiTag template which requires typing the array name only once.
 #define EXV_PRINT_COMBITAG_MULTI(array, count, ignoredcount, ignoredcountmax) printCombiTag<EXV_COUNTOF(array), array, count, ignoredcount, ignoredcountmax>
 
-}}                                      // namespace Internal, Exiv2
+    } // namespace Internal
+} // namespace Exiv2
+    
 
 #endif                                  // #ifndef PENTAXMN_INT_HPP_
