Fix #1090: exiv2 0.28.0 support
authorRosen PenevĀ  <>
Fri, 2 Jun 2023 15:41:12 +0000 (16:41 +0100)
committerColin Clark <colin.clark@cclark.uk>
Fri, 2 Jun 2023 15:41:12 +0000 (16:41 +0100)
https://github.com/BestImageViewer/geeqie/issues/1090

src/exiv2.cc

index a2c16c4..6c745a8 100644 (file)
 
 #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;
 }