From 86d5f780bae35d0fc2122646ff415633b5f15a60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rosen=20Penev=C2=A0?= <>
Date: Fri, 2 Jun 2023 16:41:12 +0100
Subject: [PATCH] Fix #1090: exiv2 0.28.0 support

https://github.com/BestImageViewer/geeqie/issues/1090
---
 src/exiv2.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git a/src/exiv2.cc b/src/exiv2.cc
index a2c16c4c..6c745a86 100644
--- a/src/exiv2.cc
+++ b/src/exiv2.cc
@@ -62,6 +62,11 @@
 
 #include "misc.h"
 
+#if EXIV2_TEST_VERSION(0,28,0)
+#define AnyError Error
+#define AutoPtr UniquePtr
+#endif
+
 typedef struct _AltKey AltKey;
 
 struct _AltKey
@@ -174,7 +179,7 @@ public:
 	{
 		cp_data_ = NULL;
 		cp_length_ = 0;
-		image_ = image;
+        image_ = std::move(image);
 		valid_ = TRUE;
 	}
 
@@ -364,7 +369,11 @@ public:
 			Exiv2::Image *image = imageData_->image();
 
 #ifdef HAVE_EXIV2_ERROR_CODE
+#if EXIV2_TEST_VERSION(0,28,0)
+            if (!image) throw Exiv2::Error(Exiv2::ErrorCode::kerInputDataReadFailed);
+#else
 			if (!image) throw Exiv2::Error(Exiv2::kerInputDataReadFailed);
+#endif
 #else
 			if (!image) throw Exiv2::Error(21);
 #endif
@@ -839,7 +848,12 @@ gint exif_item_get_integer(ExifItem *item, gint *value)
 {
 	try {
 		if (!item || exif_item_get_elements(item) == 0) return 0;
+
+#if EXIV2_TEST_VERSION(0,28,0)
+        *value = ((Exiv2::Metadatum *)item)->toInt64();
+#else
 		*value = ((Exiv2::Metadatum *)item)->toLong();
+#endif
 		return 1;
 	}
 	catch (Exiv2::AnyError& e) {
@@ -1224,10 +1238,18 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 			Exiv2::PreviewImage image = pm.getPreviewImage(*pos);
 
 			Exiv2::DataBuf buf = image.copy();
+
+#if EXIV2_TEST_VERSION(0,28,0)
+                       *data_len = buf.size();
+                       auto b = buf.data();
+                       buf.reset();
+                       return b;
+#else
 			std::pair<Exiv2::byte*, long> p = buf.release();
 
 			*data_len = p.second;
 			return p.first;
+#endif
 			}
 		return NULL;
 	}
@@ -1487,22 +1509,41 @@ unsigned long RawFile::preview_offset(void)
 	if (type == Exiv2::ImageType::cr2)
 		{
 		val = find(0x111, Group::ifd0);
-		if (val) return val->toLong();
-
+#if EXIV2_TEST_VERSION(0,28,0)
+		if (val) return val->toInt64();
+#else
+		if (val) return val->tolong();
+#endif
 		return 0;
 		}
 
 	val = find(0x201, Group::sub0_0);
-	if (val) return val->toLong();
+#if EXIV2_TEST_VERSION(0,28,0)
+	if (val) return val->toInt64();
+#else
+	if (val) return val->tolong();
+#endif
 
 	val = find(0x201, Group::ifd0);
-	if (val) return val->toLong();
+#if EXIV2_TEST_VERSION(0,28,0)
+	if (val) return val->toInt64();
+#else
+	if (val) return val->tolong();
+#endif
 
 	val = find(0x201, Group::ignr); // for PEF files, originally it was probably ifd2
-	if (val) return val->toLong();
+#if EXIV2_TEST_VERSION(0,28,0)
+	if (val) return val->toInt64();
+#else
+	if (val) return val->tolong();
+#endif
 
 	val = find(0x111, Group::sub0_1); // dng
-	if (val) return val->toLong();
+#if EXIV2_TEST_VERSION(0,28,0)
+	if (val) return val->toInt64();
+#else
+	if (val) return val->tolong();
+#endif
 
 	return 0;
 }
-- 
2.40.1

