Skip to content

Commit

Permalink
*: migrate to breaking exiv2-0.28.x api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
whatdoineed2do/Ray committed Dec 16, 2023
1 parent 8de94ca commit 56155a2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
19 changes: 18 additions & 1 deletion src/ImgExifParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,21 @@ const Img ImgExifParser::_parse(const char* filename_, const struct stat& st_,

try
{
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
Exiv2::Image::UniquePtr image;
#else
Exiv2::Image::AutoPtr image;
#endif
try
{
image = Exiv2::ImageFactory::open(filename_);

}
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
catch (const Exiv2::Error&)
#else
catch (const Exiv2::AnyError&)
#endif
{
std::ostringstream err;
err << "invalid image file " << filename_;
Expand Down Expand Up @@ -181,7 +189,12 @@ const Img ImgExifParser::_parse(const char* filename_, const struct stat& st_,
{
if ( (exif = ed.findKey(Exiv2::ExifKey(mp->tag)) ) != ed.end()) {
if (mp->target) *mp->target = exif->print(&ed);
if (mp->tgtlong) *mp->tgtlong = exif->toLong();
if (mp->tgtlong) *mp->tgtlong =
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
exif->toInt64();
#else
exif->toLong();
#endif
if (mp->tgtfloat) *mp->tgtfloat = exif->toFloat();
}
++mp;
Expand Down Expand Up @@ -256,7 +269,11 @@ const Img ImgExifParser::_parse(const char* filename_, const struct stat& st_,

return Img(ImgKey(mftr.c_str(), data.metaimg.camera.c_str(), data.metaimg.sn.c_str(), dtorg.c_str(), dtorgsub.c_str()), data);
}
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
catch (const Exiv2::Error& e)
#else
catch (const Exiv2::AnyError& e)
#endif
{
std::ostringstream err;
err << "unable to extract exif from " << filename_ << " - " << e;
Expand Down
25 changes: 21 additions & 4 deletions src/ImgThumbGen.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ImgThumbGen.h"

#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <string.h>

Expand Down Expand Up @@ -42,7 +43,12 @@ void ImgThumbGen::generate()
*/
try
{
Exiv2::Image::AutoPtr orig = Exiv2::ImageFactory::open(img.filename);
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
Exiv2::Image::UniquePtr
#else
Exiv2::Image::AutoPtr
#endif
orig = Exiv2::ImageFactory::open(img.filename);
orig->readMetadata();
Exiv2::PreviewManager prevldr(*orig);
Exiv2::PreviewPropertiesList prevs = prevldr.getPreviewProperties();
Expand All @@ -57,7 +63,11 @@ void ImgThumbGen::generate()
_genthumbnail(prevpath, img.filename, preview, orig->exifData(), thumbsize, img.metaimg.rotate, img.metaimg.flop);
}
}
catch (const Exiv2::AnyError& e)
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
catch (const Exiv2::Error& e)
#else
catch (const Exiv2::AnyError& e)
#endif
{
_error << "unable to extract thumbnail from " << img.filename << " - " << e;
}
Expand Down Expand Up @@ -236,8 +246,15 @@ void ImgThumbGen::_genthumbnail(const std::string& path_, const std::string& or
/* found the nikon tag that tells us 0=srgb, 1=argb but need to check if
* this is as-shot with no further mods (ie colorspace conv)
*/
DLOG(origpath_ << " colourspace=" << d->toLong());
if (d->toLong() == 2)
const long l =
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
d->toInt64();
#else
d->toLong();
#endif

DLOG(origpath_ << " colourspace=" << l);
if (l == 2)
{
// it was shot as aRGB - check the orig vs mod times
std::string orig;
Expand Down
24 changes: 21 additions & 3 deletions src/imgprextr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ Exiv2::ExifData::iterator _extractICC(ImgCat::_Buf& buf_, Exiv2::ExifData& exif
/* found the nikon tag that tells us 0=srgb, 1=argb but need to check if
* this is as-shot with no further mods (ie colorspace conv)
*/
if (d->toLong() == 2)
const long l =
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
exif->toInt64();
#else
exif->toLong();
#endif
if (l == 2)
{
// it was shot as aRGB - check the orig vs mod times
std::string orig;
Expand Down Expand Up @@ -650,7 +656,12 @@ int main(int argc, char* const argv[])

try
{
Exiv2::Image::AutoPtr orig = Exiv2::ImageFactory::open(filename_);
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
Exiv2::Image::UniquePtr
#else
Exiv2::Image::AutoPtr
#endif
orig = Exiv2::ImageFactory::open(filename_);
assert(orig.get() != 0);


Expand Down Expand Up @@ -704,8 +715,11 @@ int main(int argc, char* const argv[])

Exiv2::PreviewImage preview = loader.getPreviewImage(*prevp);

#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
Exiv2::Image::UniquePtr upd = Exiv2::ImageFactory::open( preview.data(), preview.size() );
#else
Exiv2::Image::AutoPtr upd = Exiv2::ImageFactory::open( preview.pData(), preview.size() );

#endif
if (!excludeMeta) {
upd->setByteOrder(orig->byteOrder());

Expand Down Expand Up @@ -921,7 +935,11 @@ int main(int argc, char* const argv[])
close(fd);
}
}
#if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0,28,0)
catch (const Exiv2::Error& e)
#else
catch (const Exiv2::AnyError& e)
#endif
{
err << filename_ << ": unable to extract preview/reset exif - " << e;
throw std::overflow_error(err.str());
Expand Down

0 comments on commit 56155a2

Please sign in to comment.