git: f858ee546f4f - main - graphics/krita: make compatible with exiv2 0.28

From: Matthias Andree <mandree_at_FreeBSD.org>
Date: Sun, 09 Jul 2023 22:09:39 UTC
The branch main has been updated by mandree:

URL: https://cgit.FreeBSD.org/ports/commit/?id=f858ee546f4f41478867fce862496935fdfe723b

commit f858ee546f4f41478867fce862496935fdfe723b
Author:     Matthias Andree <mandree@FreeBSD.org>
AuthorDate: 2023-07-02 13:35:32 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2023-07-09 22:08:09 +0000

    graphics/krita: make compatible with exiv2 0.28
    
    Obtained from:  https://invent.kde.org/graphics/krita/-/commits/64382cb061e622211e0f96a1a88f649084c95911
    PR:             272311
---
 graphics/krita/Makefile                            |   2 +-
 graphics/krita/files/patch-git-exiv2-a-e7bf1f0d299 | 582 +++++++++++++++++++++
 2 files changed, 583 insertions(+), 1 deletion(-)

diff --git a/graphics/krita/Makefile b/graphics/krita/Makefile
index 316aaa53cf76..5bc4cf1a2c4e 100644
--- a/graphics/krita/Makefile
+++ b/graphics/krita/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	krita
 DISTVERSION=	5.1.5
-PORTREVISION=	13
+PORTREVISION=	14
 CATEGORIES=	graphics kde
 MASTER_SITES=	KDE/stable/${PORTNAME}/${DISTVERSION}
 DIST_SUBDIR=	KDE/${PORTNAME}
diff --git a/graphics/krita/files/patch-git-exiv2-a-e7bf1f0d299 b/graphics/krita/files/patch-git-exiv2-a-e7bf1f0d299
new file mode 100644
index 000000000000..9727deba37d4
--- /dev/null
+++ b/graphics/krita/files/patch-git-exiv2-a-e7bf1f0d299
@@ -0,0 +1,582 @@
+From e7bf1f0d299c4f7c6529438059d14e7a99907066 Mon Sep 17 00:00:00 2001
+From: Antonio Rojas <arojas@archlinux.org>
+Date: Sun, 4 Jun 2023 18:04:59 +0200
+Subject: [PATCH] Fix build with exiv2 0.28
+
+---
+ plugins/impex/jpeg/kis_jpeg_converter.cc     |  8 ++
+ plugins/impex/tiff/kis_tiff_export.cc        |  9 +++
+ plugins/impex/tiff/kis_tiff_import.cc        |  9 +++
+ plugins/metadata/common/KisExiv2IODevice.cpp | 36 +++++++++
+ plugins/metadata/common/KisExiv2IODevice.h   | 23 ++++++
+ plugins/metadata/common/kis_exiv2_common.h   | 20 +++++
+ plugins/metadata/exif/kis_exif_io.cpp        | 79 +++++++++++++++++++-
+ plugins/metadata/iptc/kis_iptc_io.cpp        | 12 +++
+ plugins/metadata/xmp/kis_xmp_io.cpp          |  9 ++-
+ 9 files changed, 200 insertions(+), 5 deletions(-)
+
+diff --git ./plugins/impex/jpeg/kis_jpeg_converter.cc ./plugins/impex/jpeg/kis_jpeg_converter.cc
+index 3364ae6eda7..476151e1234 100644
+--- ./plugins/impex/jpeg/kis_jpeg_converter.cc
++++ ./plugins/impex/jpeg/kis_jpeg_converter.cc
+@@ -20,6 +20,10 @@ extern "C" {
+ }
+ 
+ #include <exiv2/jpgimage.hpp>
++#include <exiv2/version.hpp>
++#if EXIV2_TEST_VERSION(0,28,0)
++#include <exiv2/photoshop.hpp>
++#endif
+ 
+ #include <QFile>
+ #include <QBuffer>
+@@ -376,7 +380,11 @@ KisImportExportErrorCode KisJPEGConverter::decode(QIODevice *io)
+             uint32_t sizeHdr = 0;
+             // Find actual Iptc data within the APP13 segment
+             if (!Exiv2::Photoshop::locateIptcIrb((Exiv2::byte*)(marker->data + 14),
++#if EXIV2_TEST_VERSION(0,28,0)
++                                                 marker->data_length - 14, &record, sizeHdr, sizeIptc)) {
++#else
+                                                  marker->data_length - 14, &record, &sizeHdr, &sizeIptc)) {
++#endif
+                 if (sizeIptc) {
+                     // Decode the IPTC data
+                     QByteArray byteArray((const char*)(record + sizeHdr), sizeIptc);
+diff --git ./plugins/impex/tiff/kis_tiff_export.cc ./plugins/impex/tiff/kis_tiff_export.cc
+index 8c8f71d7c08..69cbda63033 100644
+--- ./plugins/impex/tiff/kis_tiff_export.cc
++++ ./plugins/impex/tiff/kis_tiff_export.cc
+@@ -206,7 +206,11 @@ KisImportExportErrorCode KisTIFFExport::convert(KisDocument *document, QIODevice
+         try {
+             KisExiv2IODevice::ptr_type basicIoDevice(new KisExiv2IODevice(filename()));
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++            const std::unique_ptr<Exiv2::Image> img = Exiv2::ImageFactory::open(std::move(basicIoDevice));
++#else
+             const std::unique_ptr<Exiv2::Image> img(Exiv2::ImageFactory::open(basicIoDevice).release());
++#endif
+ 
+             img->readMetadata();
+ 
+@@ -241,9 +245,14 @@ KisImportExportErrorCode KisTIFFExport::convert(KisDocument *document, QIODevice
+             }
+             // Write metadata
+             img->writeMetadata();
++#if EXIV2_TEST_VERSION(0,28,0)
++        } catch (Exiv2::Error &e) {
++            errFile << "Failed injecting TIFF metadata:" << Exiv2::Error(e.code()).what();
++#else
+         } catch (Exiv2::AnyError &e) {
+             errFile << "Failed injecting TIFF metadata:" << e.code()
+                     << e.what();
++#endif
+         }
+     }
+     return ImportExportCodes::OK;
+diff --git ./plugins/impex/tiff/kis_tiff_import.cc ./plugins/impex/tiff/kis_tiff_import.cc
+index e6d408e923b..5be62bbbf51 100644
+--- ./plugins/impex/tiff/kis_tiff_import.cc
++++ ./plugins/impex/tiff/kis_tiff_import.cc
+@@ -1842,7 +1842,11 @@ KisTIFFImport::convert(KisDocument *document,
+         try {
+             KisExiv2IODevice::ptr_type basicIoDevice(new KisExiv2IODevice(filename()));
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++            const std::unique_ptr<Exiv2::Image> readImg = Exiv2::ImageFactory::open(std::move(basicIoDevice));
++#else
+             const std::unique_ptr<Exiv2::Image> readImg(Exiv2::ImageFactory::open(basicIoDevice).release());
++#endif
+ 
+             readImg->readMetadata();
+ 
+@@ -1910,8 +1914,13 @@ KisTIFFImport::convert(KisDocument *document,
+ 
+             // Inject the data as any other IOBackend
+             io->loadFrom(layer->metaData(), &ioDevice);
++#if EXIV2_TEST_VERSION(0,28,0)
++        } catch (Exiv2::Error &e) {
++            errFile << "Failed metadata import:" << Exiv2::Error(e.code()).what();
++#else
+         } catch (Exiv2::AnyError &e) {
+             errFile << "Failed metadata import:" << e.code() << e.what();
++#endif
+         }
+     }
+ 
+diff --git ./plugins/metadata/common/KisExiv2IODevice.cpp ./plugins/metadata/common/KisExiv2IODevice.cpp
+index c62e2d15ae9..bf5cdc2bd63 100644
+--- ./plugins/metadata/common/KisExiv2IODevice.cpp
++++ ./plugins/metadata/common/KisExiv2IODevice.cpp
+@@ -39,7 +39,11 @@ int KisExiv2IODevice::close()
+     return 0;
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++size_t KisExiv2IODevice::write(const Exiv2::byte *data, size_t wcount)
++#else
+ long KisExiv2IODevice::write(const Exiv2::byte *data, long wcount)
++#endif
+ {
+     if (!m_file.isWritable()) {
+         qWarning() << "KisExiv2IODevice: File not open for writing.";
+@@ -53,7 +57,11 @@ long KisExiv2IODevice::write(const Exiv2::byte *data, long wcount)
+     return 0;
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++size_t KisExiv2IODevice::write(Exiv2::BasicIo &src)
++#else
+ long KisExiv2IODevice::write(Exiv2::BasicIo &src)
++#endif
+ {
+     if (static_cast<BasicIo *>(this) == &src) {
+         return 0;
+@@ -88,15 +96,28 @@ int KisExiv2IODevice::putb(Exiv2::byte data)
+     }
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++Exiv2::DataBuf KisExiv2IODevice::read(size_t rcount)
++#else
+ Exiv2::DataBuf KisExiv2IODevice::read(long rcount)
++#endif
+ {
+     Exiv2::DataBuf buf(rcount);
++#if EXIV2_TEST_VERSION(0,28,0)
++    const size_t readCount = read(buf.data(), buf.size());
++    buf.resize(readCount);
++#else
+     const long readCount = read(buf.pData_, buf.size_);
+     buf.size_ = readCount;
++#endif
+     return buf;
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++size_t KisExiv2IODevice::read(Exiv2::byte *buf, size_t rcount)
++#else
+ long KisExiv2IODevice::read(Exiv2::byte *buf, long rcount)
++#endif
+ {
+     const qint64 bytesRead = m_file.read(reinterpret_cast<char *>(buf), rcount);
+     if (bytesRead > 0) {
+@@ -202,7 +223,18 @@ int KisExiv2IODevice::munmap()
+     return 0;
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++void KisExiv2IODevice::populateFakeData()
++{
++    return;
++}
++#endif
++
++#if EXIV2_TEST_VERSION(0,28,0)
++size_t KisExiv2IODevice::tell() const
++#else
+ long KisExiv2IODevice::tell() const
++#endif
+ {
+     return m_file.pos();
+ }
+@@ -231,7 +263,11 @@ bool KisExiv2IODevice::eof() const
+     return m_file.atEnd();
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++const std::string& KisExiv2IODevice::path() const noexcept
++#else
+ std::string KisExiv2IODevice::path() const
++#endif
+ {
+     return filePathQString().toStdString();
+ }
+diff --git ./plugins/metadata/common/KisExiv2IODevice.h ./plugins/metadata/common/KisExiv2IODevice.h
+index d90831e8325..27f5f8d5fc4 100644
+--- ./plugins/metadata/common/KisExiv2IODevice.h
++++ ./plugins/metadata/common/KisExiv2IODevice.h
+@@ -18,18 +18,30 @@
+ class KRITAEXIFCOMMON_EXPORT KisExiv2IODevice : public Exiv2::BasicIo
+ {
+ public:
++#if EXIV2_TEST_VERSION(0,28,0)
++    using ptr_type = Exiv2::BasicIo::UniquePtr;
++#else
+     using ptr_type = Exiv2::BasicIo::AutoPtr;
++#endif
+ 
+     KisExiv2IODevice(QString path);
+     ~KisExiv2IODevice() override;
+ 
+     int open() override;
+     int close() override;
++#if EXIV2_TEST_VERSION(0,28,0)
++    size_t write(const Exiv2::byte *data, size_t wcount) override;
++    size_t write(Exiv2::BasicIo &src) override;
++    int putb(Exiv2::byte data) override;
++    Exiv2::DataBuf read(size_t rcount) override;
++    size_t read(Exiv2::byte *buf, size_t rcount) override;
++#else
+     long write(const Exiv2::byte *data, long wcount) override;
+     long write(Exiv2::BasicIo &src) override;
+     int putb(Exiv2::byte data) override;
+     Exiv2::DataBuf read(long rcount) override;
+     long read(Exiv2::byte *buf, long rcount) override;
++#endif
+     int getb() override;
+     void transfer(BasicIo &src) override;
+ #if defined(_MSC_VER)
+@@ -39,13 +51,24 @@ public:
+ #endif
+ 
+     Exiv2::byte *mmap(bool isWriteable = false) override;
++#if EXIV2_TEST_VERSION(0,28,0)
++    void populateFakeData() override;
++#endif
+     int munmap() override;
++#if EXIV2_TEST_VERSION(0,28,0)
++    size_t tell() const override;
++#else
+     long tell() const override;
++#endif
+     size_t size() const override;
+     bool isopen() const override;
+     int error() const override;
+     bool eof() const override;
++#if EXIV2_TEST_VERSION(0,28,0)
++    const std::string& path() const noexcept override;
++#else
+     std::string path() const override;
++#endif
+ 
+ private:
+     bool open(QFile::OpenMode mode);
+--- ./plugins/metadata/common/kis_exiv2_common.h
++++ ./plugins/metadata/common/kis_exiv2_common.h
+@@ -19,9 +19,13 @@
+ 
+ // Convert an exiv value to a KisMetaData value
+ inline KisMetaData::Value
++#if EXIV2_TEST_VERSION(0,28,0)
++exivValueToKMDValue(const Exiv2::Value::UniquePtr &value, bool forceSeq, KisMetaData::Value::ValueType arrayType = KisMetaData::Value::UnorderedArray)
++#else
+ exivValueToKMDValue(const Exiv2::Value::AutoPtr value,
+                     bool forceSeq,
+                     KisMetaData::Value::ValueType arrayType = KisMetaData::Value::UnorderedArray)
++#endif
+ {
+     switch (value->typeId()) {
+     case Exiv2::signedByte:
+@@ -42,11 +46,19 @@
+     case Exiv2::signedShort:
+     case Exiv2::signedLong: {
+         if (value->count() == 1 && !forceSeq) {
++#if EXIV2_TEST_VERSION(0,28,0)
++            return {static_cast<int>(value->toUint32())};
++#else
+             return KisMetaData::Value((int)value->toLong());
++#endif
+         } else {
+             QList<KisMetaData::Value> array;
+             for (int i = 0; i < value->count(); i++)
++#if EXIV2_TEST_VERSION(0,28,0)
++                array.push_back({static_cast<int>(value->toUint32(i))});
++#else
+                 array.push_back(KisMetaData::Value((int)value->toLong(i)));
++#endif
+             return KisMetaData::Value(array, arrayType);
+         }
+     }
+@@ -63,7 +75,11 @@
+             return {KisMetaData::Rational(value->toRational().first, value->toRational().second)};
+         } else {
+             QList<KisMetaData::Value> array;
++#if EXIV2_TEST_VERSION(0,28,0)
++            for (size_t i = 0; i < value->count(); i++) {
++#else
+             for (long i = 0; i < value->count(); i++) {
++#endif
+                 array.push_back(KisMetaData::Rational(value->toRational(i).first, value->toRational(i).second));
+             }
+             return KisMetaData::Value(array, arrayType);
+@@ -77,7 +93,11 @@
+             return KisMetaData::Value(KisMetaData::Rational(value->toRational().first, value->toRational().second));
+         } else {
+             QList<KisMetaData::Value> array;
++#if EXIV2_TEST_VERSION(0,28,0)
++            for (size_t i = 0; i < value->count(); i++) {
++#else
+             for (long i = 0; i < value->count(); i++) {
++#endif
+                 array.push_back(KisMetaData::Rational(value->toRational(i).first, value->toRational(i).second));
+             }
+             return KisMetaData::Value(array, arrayType);
+diff --git ./plugins/metadata/exif/kis_exif_io.cpp ./plugins/metadata/exif/kis_exif_io.cpp
+index a3ee6927fca..a3b903afcb5 100644
+--- ./plugins/metadata/exif/kis_exif_io.cpp
++++ ./plugins/metadata/exif/kis_exif_io.cpp
+@@ -31,7 +31,11 @@
+ // ---- Exception conversion functions ---- //
+ 
+ // convert ExifVersion and FlashpixVersion to a KisMetaData value
++#if EXIV2_TEST_VERSION(0,28,0)
++KisMetaData::Value exifVersionToKMDValue(const Exiv2::Value::UniquePtr value)
++#else
+ KisMetaData::Value exifVersionToKMDValue(const Exiv2::Value::AutoPtr value)
++#endif
+ {
+     const Exiv2::DataValue *dvalue = dynamic_cast<const Exiv2::DataValue *>(&*value);
+     if (dvalue) {
+@@ -55,13 +59,22 @@ Exiv2::Value *kmdValueToExifVersion(const KisMetaData::Value &value)
+ }
+ 
+ // Convert an exif array of integer string to a KisMetaData array of integer
++#if EXIV2_TEST_VERSION(0,28,0)
++KisMetaData::Value exifArrayToKMDIntOrderedArray(const Exiv2::Value::UniquePtr value)
++#else
+ KisMetaData::Value exifArrayToKMDIntOrderedArray(const Exiv2::Value::AutoPtr value)
++#endif
+ {
+     QList<KisMetaData::Value> v;
+     const Exiv2::DataValue *dvalue = dynamic_cast<const Exiv2::DataValue *>(&*value);
+     if (dvalue) {
++#if EXIV2_TEST_VERSION(0,28,0)
++        for (size_t i = 0; i < dvalue->count(); i++) {
++            v.push_back({(int)dvalue->toUint32(i)});
++#else
+         for (long i = 0; i < dvalue->count(); i++) {
+             v.push_back({(int)dvalue->toLong(i)});
++#endif
+         }
+     } else {
+         Q_ASSERT(value->typeId() == Exiv2::asciiString);
+@@ -81,7 +94,11 @@ Exiv2::Value *kmdIntOrderedArrayToExifArray(const KisMetaData::Value &value)
+     return new Exiv2::DataValue(v.data(), static_cast<long>(v.size()));
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++QDateTime exivValueToDateTime(const Exiv2::Value::UniquePtr value)
++#else
+ QDateTime exivValueToDateTime(const Exiv2::Value::AutoPtr value)
++#endif
+ {
+     return QDateTime::fromString(value->toString().c_str(), Qt::ISODate);
+ }
+@@ -115,7 +132,11 @@ Exiv2::ByteOrder invertByteOrder(Exiv2::ByteOrder order)
+     return Exiv2::invalidByteOrder;
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++KisMetaData::Value exifOECFToKMDOECFStructure(const Exiv2::Value::UniquePtr value, Exiv2::ByteOrder order)
++#else
+ KisMetaData::Value exifOECFToKMDOECFStructure(const Exiv2::Value::AutoPtr value, Exiv2::ByteOrder order)
++#endif
+ {
+     QMap<QString, KisMetaData::Value> oecfStructure;
+     const Exiv2::DataValue *dvalue = dynamic_cast<const Exiv2::DataValue *>(&*value);
+@@ -123,22 +144,39 @@ KisMetaData::Value exifOECFToKMDOECFStructure(const Exiv2::Value::AutoPtr value,
+     QByteArray array(dvalue->count(), 0);
+ 
+     dvalue->copy((Exiv2::byte *)array.data());
++#if EXIV2_TEST_VERSION(0,28,0)
++    size_t columns = fixEndianess<qsizetype>((reinterpret_cast<qsizetype *>(array.data()))[0], order);
++    size_t rows = fixEndianess<qsizetype>((reinterpret_cast<qsizetype *>(array.data()))[1], order);
++#else
+     int columns = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[0], order);
+     int rows = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[1], order);
++#endif
+ 
+     if ((columns * rows + 4)
+         > dvalue->count()) { // Sometime byteOrder get messed up (especially if metadata got saved with kexiv2 library,
+                              // or any library that doesn't save back with the same byte order as the camera)
+         order = invertByteOrder(order);
++#if EXIV2_TEST_VERSION(0,28,0)
++        columns = fixEndianess<qsizetype>((reinterpret_cast<qsizetype *>(array.data()))[0], order);
++        rows = fixEndianess<qsizetype>((reinterpret_cast<qsizetype *>(array.data()))[1], order);
++#else
+         columns = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[0], order);
+         rows = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[1], order);
++#endif
+         Q_ASSERT((columns * rows + 4) > dvalue->count());
+     }
+-    oecfStructure["Columns"] = KisMetaData::Value(columns);
+-    oecfStructure["Rows"] = KisMetaData::Value(rows);
++    QVariant qcolumns, qrows;
++    qcolumns.setValue(columns);
++    qrows.setValue(rows);
++    oecfStructure["Columns"] = KisMetaData::Value(qcolumns);
++    oecfStructure["Rows"] = KisMetaData::Value(qrows);
+     int index = 4;
+     QList<KisMetaData::Value> names;
++#if EXIV2_TEST_VERSION(0,28,0)
++    for (size_t i = 0; i < columns; i++) {
++#else
+     for (int i = 0; i < columns; i++) {
++#endif
+         int lastIndex = array.indexOf((char)0, index);
+         QString name = array.mid(index, lastIndex - index);
+         if (index != lastIndex) {
+@@ -153,8 +191,13 @@ KisMetaData::Value exifOECFToKMDOECFStructure(const Exiv2::Value::AutoPtr value,
+     oecfStructure["Names"] = KisMetaData::Value(names, KisMetaData::Value::OrderedArray);
+     QList<KisMetaData::Value> values;
+     qint32 *dataIt = reinterpret_cast<qint32 *>(array.data() + index);
++#if EXIV2_TEST_VERSION(0,28,0)
++    for (size_t i = 0; i < columns; i++) {
++        for (size_t j = 0; j < rows; j++) {
++#else
+     for (int i = 0; i < columns; i++) {
+         for (int j = 0; j < rows; j++) {
++#endif
+             values.append(KisMetaData::Value(
+                 KisMetaData::Rational(fixEndianess<qint32>(dataIt[0], order), fixEndianess<qint32>(dataIt[1], order))));
+             dataIt += 2;
+@@ -202,7 +245,11 @@ Exiv2::Value *kmdOECFStructureToExifOECF(const KisMetaData::Value &value)
+     return new Exiv2::DataValue((const Exiv2::byte *)array.data(), array.size());
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++KisMetaData::Value deviceSettingDescriptionExifToKMD(const Exiv2::Value::UniquePtr value)
++#else
+ KisMetaData::Value deviceSettingDescriptionExifToKMD(const Exiv2::Value::AutoPtr value)
++#endif
+ {
+     QMap<QString, KisMetaData::Value> deviceSettingStructure;
+     QByteArray array;
+@@ -258,15 +305,24 @@ Exiv2::Value *deviceSettingDescriptionKMDToExif(const KisMetaData::Value &value)
+     return new Exiv2::DataValue((const Exiv2::byte *)array.data(), array.size());
+ }
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++KisMetaData::Value cfaPatternExifToKMD(const Exiv2::Value::UniquePtr value, Exiv2::ByteOrder order)
++#else
+ KisMetaData::Value cfaPatternExifToKMD(const Exiv2::Value::AutoPtr value, Exiv2::ByteOrder order)
++#endif
+ {
+     QMap<QString, KisMetaData::Value> cfaPatternStructure;
+     const Exiv2::DataValue *dvalue = dynamic_cast<const Exiv2::DataValue *>(&*value);
+     Q_ASSERT(dvalue);
+     QByteArray array(dvalue->count(), 0);
+     dvalue->copy((Exiv2::byte *)array.data());
++#if EXIV2_TEST_VERSION(0,28,0)
++    size_t columns = fixEndianess<qsizetype>((reinterpret_cast<qsizetype *>(array.data()))[0], order);
++    size_t rows = fixEndianess<qsizetype>((reinterpret_cast<qsizetype *>(array.data()))[1], order);
++#else
+     int columns = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[0], order);
+     int rows = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[1], order);
++#endif
+     if ((columns * rows + 4)
+         != dvalue->count()) { // Sometime byteOrder get messed up (especially if metadata got saved with kexiv2 library,
+                               // or any library that doesn't save back with the same byte order as the camera)
+@@ -275,8 +331,11 @@ KisMetaData::Value cfaPatternExifToKMD(const Exiv2::Value::AutoPtr value, Exiv2:
+         rows = fixEndianess<quint16>((reinterpret_cast<quint16 *>(array.data()))[1], order);
+         Q_ASSERT((columns * rows + 4) == dvalue->count());
+     }
+-    cfaPatternStructure["Columns"] = KisMetaData::Value(columns);
+-    cfaPatternStructure["Rows"] = KisMetaData::Value(rows);
++    QVariant qcolumns, qrows;
++    qcolumns.setValue(columns);
++    qrows.setValue(rows);
++    cfaPatternStructure["Columns"] = KisMetaData::Value(qcolumns);
++    cfaPatternStructure["Rows"] = KisMetaData::Value(qrows);
+     QList<KisMetaData::Value> values;
+     int index = 4;
+     for (int i = 0; i < columns * rows; i++) {
+@@ -310,9 +369,17 @@ Exiv2::Value *cfaPatternKMDToExif(const KisMetaData::Value &value)
+ 
+ // Read and write Flash //
+ 
++#if EXIV2_TEST_VERSION(0,28,0)
++KisMetaData::Value flashExifToKMD(const Exiv2::Value::UniquePtr value)
++#else
+ KisMetaData::Value flashExifToKMD(const Exiv2::Value::AutoPtr value)
++#endif
+ {
++#if EXIV2_TEST_VERSION(0,28,0)
++    const uint16_t v = static_cast<uint16_t>(value->toUint32());
++#else
+     const uint16_t v = static_cast<uint16_t>(value->toLong());
++#endif
+     QMap<QString, KisMetaData::Value> flashStructure;
+     bool fired = (v & 0x01); // bit 1 is whether flash was fired or not
+     flashStructure["Fired"] = QVariant(fired);
+@@ -465,7 +532,11 @@ bool KisExifIO::saveTo(const KisMetaData::Store *store, QIODevice *ioDevice, Hea
+                                 << exivKey; // << " of KMD value" << entry.value();
+                 }
+             }
++#if EXIV2_TEST_VERSION(0,28,0)
++        } catch (Exiv2::Error &e) {
++#else
+         } catch (Exiv2::AnyError &e) {
++#endif
+             dbgMetaData << "exiv error " << e.what();
+         }
+     }
+diff --git ./plugins/metadata/iptc/kis_iptc_io.cpp ./plugins/metadata/iptc/kis_iptc_io.cpp
+index 9e85624644d..88d80b38b8d 100644
+--- ./plugins/metadata/iptc/kis_iptc_io.cpp
++++ ./plugins/metadata/iptc/kis_iptc_io.cpp
+@@ -109,7 +109,11 @@ bool KisIptcIO::saveTo(const KisMetaData::Store *store, QIODevice *ioDevice, Hea
+                 if (v && v->typeId() != Exiv2::invalidTypeId) {
+                     iptcData.add(iptcKey, v);
+                 }
++#if EXIV2_TEST_VERSION(0,28,0)
++            } catch (Exiv2::Error &e) {
++#else
+             } catch (Exiv2::AnyError &e) {
++#endif
+                 dbgMetaData << "exiv error " << e.what();
+             }
+         }
+@@ -127,7 +131,11 @@ bool KisIptcIO::saveTo(const KisMetaData::Store *store, QIODevice *ioDevice, Hea
+         header.append(photoshopBimId_);
+         header.append(photoshopIptc_);
+         header.append(QByteArray(2, 0));
++#if EXIV2_TEST_VERSION(0, 28, 0)
++        qint32 size = rawData.size();
++#else
+         qint32 size = rawData.size_;
++#endif
+         QByteArray sizeArray(4, 0);
+         sizeArray[0] = (char)((size & 0xff000000) >> 24);
+         sizeArray[1] = (char)((size & 0x00ff0000) >> 16);
+@@ -137,7 +145,11 @@ bool KisIptcIO::saveTo(const KisMetaData::Store *store, QIODevice *ioDevice, Hea
+         ioDevice->write(header);
+     }
+ 
++#if EXIV2_TEST_VERSION(0, 28, 0)
++    ioDevice->write((const char *)rawData.data(), rawData.size());
++#else
+     ioDevice->write((const char *)rawData.pData_, rawData.size_);
++#endif
+     ioDevice->close();
+     return true;
+ }
+diff --git ./plugins/metadata/xmp/kis_xmp_io.cpp ./plugins/metadata/xmp/kis_xmp_io.cpp
+index a1003175455..927abe8dddf 100644
+--- ./plugins/metadata/xmp/kis_xmp_io.cpp
++++ ./plugins/metadata/xmp/kis_xmp_io.cpp
+@@ -249,8 +249,11 @@ bool KisXMPIO::loadFrom(KisMetaData::Store *store, QIODevice *ioDevice) const
+                     Q_ASSERT(schema);
+                 }
+             }
++#if EXIV2_TEST_VERSION(0,28,0)
++            const Exiv2::Value::UniquePtr value = it->getValue();
++#else
+             const Exiv2::Value::AutoPtr value = it->getValue();
+-
++#endif
+             QString structName;
+             int arrayIndex = -1;
+             QString tagName;
+@@ -279,7 +282,11 @@ bool KisXMPIO::loadFrom(KisMetaData::Store *store, QIODevice *ioDevice) const
+                 const Exiv2::XmpArrayValue *xav = dynamic_cast<const Exiv2::XmpArrayValue *>(value.get());
+                 Q_ASSERT(xav);
+                 QList<KisMetaData::Value> array;
++#if EXIV2_TEST_VERSION(0,28,0)
++                for (size_t i = 0; i < xav->count(); ++i) {
++#else
+                 for (int i = 0; i < xav->count(); ++i) {
++#endif
+                     QString value = QString::fromStdString(xav->toString(i));
+                     if (parser) {
+                         array.push_back(parser->parse(value));