From 7c945a5c9116325dad795dbe9682c2c4a4dea2d9 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <asturm@gentoo.org>
Date: Sun, 20 Aug 2023 18:57:43 +0200
Subject: [PATCH] Fix build with >=exiv2-0.28

Fixes https://github.com/dfandrich/gpscorrelate/issues/22

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 exif-gps.cpp | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/exif-gps.cpp b/exif-gps.cpp
index d464d62..71b46ef 100644
--- a/exif-gps.cpp
+++ b/exif-gps.cpp
@@ -44,6 +44,7 @@
 #include "exiv2/image.hpp"
 #include "exiv2/exif.hpp"
 #include "exiv2/error.hpp"
+#include "exiv2/version.hpp"
 
 #include "gpsstructure.h"
 #include "exif-gps.h"
@@ -97,7 +98,11 @@ int main(int argc, char* argv[])
 char* ReadExifDate(const char* File, int* IncludesGPS)
 {
 	// Open and read the file.
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Image::UniquePtr Image;
+#else
 	Exiv2::Image::AutoPtr Image;
+#endif
 
 	try {
 		Image = Exiv2::ImageFactory::open(File);
@@ -154,7 +159,11 @@ char* ReadExifData(const char* File, double* Lat, double* Long, double* Elev, in
 	// much more data than the last, specifically
 	// for display purposes. For the GUI version.
 	// Open and read the file.
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Image::UniquePtr Image;
+#else
 	Exiv2::Image::AutoPtr Image;
+#endif
 
 	try {
 		Image = Exiv2::ImageFactory::open(File);
@@ -273,7 +282,11 @@ char* ReadExifData(const char* File, double* Lat, double* Long, double* Elev, in
 
 		// Is the altitude below sea level? If so, negate the value.
 		GPSData = ExifRead["Exif.GPSInfo.GPSAltitudeRef"];
+#if EXIV2_TEST_VERSION(0, 28, 0)
+		if (GPSData.count() >= 1 && GPSData.toUint32() == 1)
+#else
 		if (GPSData.count() >= 1 && GPSData.toLong() == 1)
+#endif
 		{
 				// Negate the elevation.
 				*Elev = -*Elev;
@@ -292,7 +305,11 @@ char* ReadGPSTimestamp(const char* File, char* DateStamp, char* TimeStamp, int*
 	// much more data than the last, specifically
 	// for display purposes. For the GUI version.
 	// Open and read the file.
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Image::UniquePtr Image;
+#else
 	Exiv2::Image::AutoPtr Image;
+#endif
 
 	try {
 		Image = Exiv2::ImageFactory::open(File);
@@ -463,7 +480,11 @@ int WriteGPSData(const char* File, const struct GPSPoint* Point,
 	struct utimbuf utb;
 	if (NoChangeMtime)
 		stat(File, &statbuf);
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Image::UniquePtr Image;
+#else
 	Exiv2::Image::AutoPtr Image;
+#endif
 
 	try {
 		Image = Exiv2::ImageFactory::open(File);
@@ -493,7 +514,11 @@ int WriteGPSData(const char* File, const struct GPSPoint* Point,
 	// Do all the easy constant ones first.
 	// GPSVersionID tag: standard says it should be four bytes: 02 02 00 00
 	//  (and, must be present).
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Value::UniquePtr Value = Exiv2::Value::create(Exiv2::unsignedByte);
+#else
 	Exiv2::Value::AutoPtr Value = Exiv2::Value::create(Exiv2::unsignedByte);
+#endif
 	Value->read("2 2 0 0");
 	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID"), Value.get());
 	// Datum: the datum of the measured data. The default is WGS-84.
@@ -643,7 +668,11 @@ int WriteFixedDatestamp(const char* File, time_t Time)
 	struct utimbuf utb;
 	stat(File, &statbuf);
 
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Image::UniquePtr Image;
+#else
 	Exiv2::Image::AutoPtr Image;
+#endif
 
 	try {
 		Image = Exiv2::ImageFactory::open(File);
@@ -672,7 +701,11 @@ int WriteFixedDatestamp(const char* File, time_t Time)
 	ExifToWrite.erase(ExifToWrite.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSDateStamp")));
 	ExifToWrite["Exif.GPSInfo.GPSDateStamp"] = ScratchBuf;
 
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Value::UniquePtr Value = Exiv2::Value::create(Exiv2::unsignedRational);
+#else
 	Exiv2::Value::AutoPtr Value = Exiv2::Value::create(Exiv2::unsignedRational);
+#endif
 	snprintf(ScratchBuf, sizeof(ScratchBuf), "%d/1 %d/1 %d/1",
 			TimeStamp.tm_hour, TimeStamp.tm_min,
 			TimeStamp.tm_sec);
@@ -705,7 +738,11 @@ int RemoveGPSExif(const char* File, int NoChangeMtime, int NoWriteExif)
 		stat(File, &statbuf);
 
 	// Open the file and start reading.
+#if EXIV2_TEST_VERSION(0, 28, 0)
+	Exiv2::Image::UniquePtr Image;
+#else
 	Exiv2::Image::AutoPtr Image;
+#endif
 	
 	try {
 		Image = Exiv2::ImageFactory::open(File);
-- 
2.41.0

