Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/uni-exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,31 @@

#include <exiv2/exiv2.hpp>
#include <iostream>
#include <memory>

#include "uni-exiv2.hpp"

#define ARRAY_SIZE(array) (sizeof array/sizeof(array[0]))

static Exiv2::Image::AutoPtr cached_image;
#define EXIV_ERROR Exiv2::AnyError
#ifdef EXIV2_VERSION
#ifdef EXIV2_TEST_VERSION
#if EXIV2_TEST_VERSION(0,28,0)
#define EXIV_ERROR Exiv2::Error
#endif
#endif
#endif

static std::unique_ptr<Exiv2::Image> cached_image;

extern "C"
void
uni_read_exiv2_map(const char *uri, void (*callback)(const char*, const char*, void*), void *user_data)
{
Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);
try {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(uri);
if ( image.get() == 0 ) {
std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open(uri);
if (image == nullptr) {
return;
}

Expand Down Expand Up @@ -80,7 +90,7 @@ uni_read_exiv2_map(const char *uri, void (*callback)(const char*, const char*, v
}
}
}
} catch (Exiv2::AnyError& e) {
} catch (EXIV_ERROR& e) {
std::cerr << "Exiv2: '" << e << "'\n";
}
}
Expand All @@ -91,19 +101,19 @@ uni_read_exiv2_to_cache(const char *uri)
{
Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);

if ( cached_image.get() != NULL ) {
if (cached_image != nullptr) {
cached_image->clearMetadata();
cached_image.reset(NULL);
cached_image.reset(nullptr);
}

try {
cached_image = Exiv2::ImageFactory::open(uri);
if ( cached_image.get() == 0 ) {
if (cached_image == nullptr) {
return 1;
}

cached_image->readMetadata();
} catch (Exiv2::AnyError& e) {
} catch (EXIV_ERROR& e) {
std::cerr << "Exiv2: '" << e << "'\n";
}

Expand All @@ -116,24 +126,24 @@ uni_write_exiv2_from_cache(const char *uri)
{
Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);

if ( cached_image.get() == NULL ) {
if (cached_image == nullptr) {
return 1;
}

try {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(uri);
if ( image.get() == 0 ) {
std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open(uri);
if (image == nullptr) {
return 2;
}

image->setMetadata( *cached_image );
image->writeMetadata();

cached_image->clearMetadata();
cached_image.reset(NULL);
cached_image.reset(nullptr);

return 0;
} catch (Exiv2::AnyError& e) {
} catch (EXIV_ERROR& e) {
std::cerr << "Exiv2: '" << e << "'\n";
}

Expand Down