[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:41:50 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=55ffbd9

The following commit has been merged in the master branch:
commit 55ffbd9eb93ed186e5b333499043a6aa782f04d5
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Thu Aug 5 01:46:27 2010 +0000

    Added DoubleValue to deal with TIFF Double values (see #711).
---
 src/types.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/types.hpp | 10 ++++++++++
 src/value.cpp |  4 +++-
 src/value.hpp | 34 ++++++++++++++++++++++++++++++---
 4 files changed, 104 insertions(+), 4 deletions(-)

diff --git a/src/types.cpp b/src/types.cpp
index 2a5844b..e037d11 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -245,6 +245,36 @@ namespace Exiv2 {
         return *reinterpret_cast<float*>(&ul);
     }
 
+    double getDouble(const byte* buf, ByteOrder byteOrder)
+    {
+        // This algorithm assumes that the internal representation of the double
+        // type is the 8-byte IEEE 754 binary64 format, which is common but not
+        // required by the C++ standard.
+        assert(sizeof(double) == 8);
+        uint64_t ull = 0;
+        if (byteOrder == littleEndian) {
+            ull =   static_cast<uint64_t>(buf[7]) << 56
+                  | static_cast<uint64_t>(buf[6]) << 48
+                  | static_cast<uint64_t>(buf[5]) << 40
+                  | static_cast<uint64_t>(buf[4]) << 32
+                  | static_cast<uint64_t>(buf[3]) << 24
+                  | static_cast<uint64_t>(buf[2]) << 16
+                  | static_cast<uint64_t>(buf[1]) <<  8
+                  | static_cast<uint64_t>(buf[0]);
+        }
+        else {
+            ull =   static_cast<uint64_t>(buf[0]) << 56
+                  | static_cast<uint64_t>(buf[1]) << 48
+                  | static_cast<uint64_t>(buf[2]) << 40
+                  | static_cast<uint64_t>(buf[3]) << 32
+                  | static_cast<uint64_t>(buf[4]) << 24
+                  | static_cast<uint64_t>(buf[5]) << 16
+                  | static_cast<uint64_t>(buf[6]) <<  8
+                  | static_cast<uint64_t>(buf[7]);
+        }
+        return *reinterpret_cast<double*>(&ull);
+    }
+
     long us2Data(byte* buf, uint16_t s, ByteOrder byteOrder)
     {
         if (byteOrder == littleEndian) {
@@ -329,6 +359,36 @@ namespace Exiv2 {
         return ul2Data(buf, ul, byteOrder);
     }
 
+    long d2Data(byte* buf, double d, ByteOrder byteOrder)
+    {
+        // This algorithm assumes that the internal representation of the double
+        // type is the 8-byte IEEE 754 binary64 format, which is common but not
+        // required by the C++ standard.
+        assert(sizeof(double) == 8);
+        uint64_t ull = *reinterpret_cast<uint64_t*>(&d);
+        if (byteOrder == littleEndian) {
+            buf[0] =  (byte)(ull & 0x00000000000000ff);
+            buf[1] = (byte)((ull & 0x000000000000ff00) >> 8);
+            buf[2] = (byte)((ull & 0x0000000000ff0000) >> 16);
+            buf[3] = (byte)((ull & 0x00000000ff000000) >> 24);
+            buf[4] = (byte)((ull & 0x000000ff00000000) >> 32);
+            buf[5] = (byte)((ull & 0x0000ff0000000000) >> 40);
+            buf[6] = (byte)((ull & 0x00ff000000000000) >> 48);
+            buf[7] = (byte)((ull & 0xff00000000000000) >> 56);
+        }
+        else {
+            buf[0] = (byte)((ull & 0xff00000000000000) >> 56);
+            buf[1] = (byte)((ull & 0x00ff000000000000) >> 48);
+            buf[2] = (byte)((ull & 0x0000ff0000000000) >> 40);
+            buf[3] = (byte)((ull & 0x000000ff00000000) >> 32);
+            buf[4] = (byte)((ull & 0x00000000ff000000) >> 24);
+            buf[5] = (byte)((ull & 0x0000000000ff0000) >> 16);
+            buf[6] = (byte)((ull & 0x000000000000ff00) >> 8);
+            buf[7] =  (byte)(ull & 0x00000000000000ff);
+        }
+        return 8;
+    }
+
     void hexdump(std::ostream& os, const byte* buf, long len, long offset)
     {
         const std::string::size_type pos = 8 + 16 * 3 + 2;
diff --git a/src/types.hpp b/src/types.hpp
index 0dcfa5c..d2efad2 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -62,8 +62,11 @@
 typedef unsigned __int8  uint8_t;
 typedef unsigned __int16 uint16_t;
 typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+typedef __int8           int8_t;
 typedef __int16          int16_t;
 typedef __int32          int32_t;
+typedef __int64          int64_t;
 #endif
 
 /*!
@@ -368,6 +371,8 @@ namespace Exiv2 {
     EXIV2API Rational getRational(const byte* buf, ByteOrder byteOrder);
     //! Read a 4 byte single precision floating point value (IEEE 754 binary32) from the data buffer
     EXIV2API float getFloat(const byte* buf, ByteOrder byteOrder);
+    //! Read an 8 byte double precision floating point value (IEEE 754 binary64) from the data buffer
+    EXIV2API double getDouble(const byte* buf, ByteOrder byteOrder);
 
     //! Output operator for our fake rational
     EXIV2API std::ostream& operator<<(std::ostream& os, const Rational& r);
@@ -413,6 +418,11 @@ namespace Exiv2 {
              to data, write the data to the buffer, return number of bytes written.
      */
     EXIV2API long f2Data(byte* buf, float f, ByteOrder byteOrder);
+    /*!
+      @brief Convert a double precision floating point (IEEE 754 binary64) double
+             to data, write the data to the buffer, return number of bytes written.
+     */
+    EXIV2API long d2Data(byte* buf, double d, ByteOrder byteOrder);
 
     /*!
       @brief Print len bytes from buf in hex and ASCII format to the given
diff --git a/src/value.cpp b/src/value.cpp
index 6e101e6..7b30ad7 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -76,7 +76,6 @@ namespace Exiv2 {
         case invalidTypeId:
         case signedByte:
         case unsignedByte:
-        case tiffDouble:
             value = AutoPtr(new DataValue(typeId));
             break;
         case asciiString:
@@ -107,6 +106,9 @@ namespace Exiv2 {
         case tiffFloat:
             value = AutoPtr(new ValueType<float>);
             break;
+        case tiffDouble:
+            value = AutoPtr(new ValueType<double>);
+            break;
         case string:
             value = AutoPtr(new StringValue);
             break;
diff --git a/src/value.hpp b/src/value.hpp
index 66f19cb..0b7fe3b 100644
--- a/src/value.hpp
+++ b/src/value.hpp
@@ -40,6 +40,7 @@
 #include <vector>
 #include <map>
 #include <iostream>
+#include <iomanip>
 #include <sstream>
 #include <memory>
 #include <cstring>
@@ -217,8 +218,8 @@ namespace Exiv2 {
           <TR><TD class="indexkey">signedShort</TD><TD class="indexvalue">%ValueType < int16_t ></TD></TR>
           <TR><TD class="indexkey">signedLong</TD><TD class="indexvalue">%ValueType < int32_t ></TD></TR>
           <TR><TD class="indexkey">signedRational</TD><TD class="indexvalue">%ValueType < Rational ></TD></TR>
-          <TR><TD class="indexkey">tiffFloat</TD><TD class="indexvalue">%DataValue(tiffFloat)</TD></TR>
-          <TR><TD class="indexkey">tiffDouble</TD><TD class="indexvalue">%DataValue(tiffDouble)</TD></TR>
+          <TR><TD class="indexkey">tiffFloat</TD><TD class="indexvalue">%ValueType < float ></TD></TR>
+          <TR><TD class="indexkey">tiffDouble</TD><TD class="indexvalue">%ValueType < double ></TD></TR>
           <TR><TD class="indexkey">tiffIfd</TD><TD class="indexvalue">%ValueType < uint32_t ></TD></TR>
           <TR><TD class="indexkey">date</TD><TD class="indexvalue">%DateValue</TD></TR>
           <TR><TD class="indexkey">time</TD><TD class="indexvalue">%TimeValue</TD></TR>
@@ -1211,6 +1212,8 @@ namespace Exiv2 {
     template<> inline TypeId getType<Rational>() { return signedRational; }
     //! Specialization for a float
     template<> inline TypeId getType<float>() { return tiffFloat; }
+    //! Specialization for a double
+    template<> inline TypeId getType<double>() { return tiffDouble; }
 
     // No default implementation: let the compiler/linker complain
     // template<typename T> inline TypeId getType() { return invalid; }
@@ -1325,6 +1328,8 @@ namespace Exiv2 {
     typedef ValueType<Rational> RationalValue;
     //! Float value type
     typedef ValueType<float> FloatValue;
+    //! Double value type
+    typedef ValueType<double> DoubleValue;
 
 // *****************************************************************************
 // free functions, template and inline definitions
@@ -1383,6 +1388,12 @@ namespace Exiv2 {
     {
         return getFloat(buf, byteOrder);
     }
+    // Specialization for a 8 byte double value.
+    template<>
+    inline double getValue(const byte* buf, ByteOrder byteOrder)
+    {
+        return getDouble(buf, byteOrder);
+    }
 
     /*!
       @brief Convert a value of type T to data, write the data to the data buffer.
@@ -1460,6 +1471,15 @@ namespace Exiv2 {
     {
         return f2Data(buf, t, byteOrder);
     }
+    /*!
+      @brief Specialization to write a double to the data buffer.
+             Return the number of bytes written.
+     */
+    template<>
+    inline long toData(byte* buf, double t, ByteOrder byteOrder)
+    {
+        return d2Data(buf, t, byteOrder);
+    }
 
     template<typename T>
     ValueType<T>::ValueType()
@@ -1579,7 +1599,7 @@ namespace Exiv2 {
         typename ValueList::const_iterator end = value_.end();
         typename ValueList::const_iterator i = value_.begin();
         while (i != end) {
-            os << *i;
+            os << std::setprecision(15) << *i;
             if (++i != end) os << " ";
         }
         return os;
@@ -1667,6 +1687,14 @@ namespace Exiv2 {
         // Warning: This is a very simple conversion, see floatToRationalCast()
         return floatToRationalCast(value_[n]);
     }
+    // Specialization for double.
+    template<>
+    inline Rational ValueType<double>::toRational(long n) const
+    {
+        ok_ = true;
+        // Warning: This is a very simple conversion, see floatToRationalCast()
+        return floatToRationalCast(static_cast<float>(value_[n]));
+    }
 
     template<typename T>
     long ValueType<T>::sizeDataArea() const

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list