Skip to content

Commit

Permalink
Fix #1090: exiv2 0.28.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosen Penev  authored and caclark committed Jun 2, 2023
1 parent 89e3b9e commit 86d5f78
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions src/exiv2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -174,7 +179,7 @@ struct _ExifDataOriginal : public _ExifData
{
cp_data_ = NULL;
cp_length_ = 0;
image_ = image;
image_ = std::move(image);
valid_ = TRUE;
}

Expand Down Expand Up @@ -364,7 +369,11 @@ struct _ExifDataProcessed : public _ExifData
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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 86d5f78

Please sign in to comment.