#define HAVE_EXIV2_ERROR_CODE
#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
#if EXIV2_TEST_VERSION(0,27,0)
#define EXV_PACKAGE "exiv2"
#include <glib.h>
-#include "main.h"
#include "exif.h"
+#include "debug.h"
+#include "filedata.h"
#include "filefilter.h"
-#include "ui-fileops.h"
-
#include "misc.h"
+#include "options.h"
+#include "ui-fileops.h"
#if EXIV2_TEST_VERSION(0,28,0)
#define AnyError Error
};
/* this is a list of keys that should be converted, even with the older Exiv2 which does not support it directly */
-static const AltKey alt_keys[] = {
+static constexpr AltKey alt_keys[] = {
{"Xmp.tiff.Orientation", "Exif.Image.Orientation", nullptr},
{"Xmp.dc.title", nullptr, "Iptc.Application2.ObjectName" },
{"Xmp.photoshop.Urgency", nullptr, "Iptc.Application2.Urgency" },
{"Xmp.dc.rights", nullptr, "Iptc.Application2.Copyright" },
{"Xmp.dc.description", nullptr, "Iptc.Application2.Caption" },
{"Xmp.photoshop.CaptionWriter", nullptr, "Iptc.Application2.Writer" },
- {nullptr, nullptr, nullptr}
};
static void _debug_exception(const char* file,
virtual ~ExifData() = default;
- virtual void writeMetadata(gchar *UNUSED(path) = nullptr)
+ virtual void writeMetadata(gchar * = nullptr)
{
g_critical("Unsupported method of writing metadata");
}
try
{
image_ = Exiv2::ImageFactory::open(pathl_);
-// g_assert (image.get() != 0);
image_->readMetadata();
#if EXIV2_TEST_VERSION(0,16,0)
return utf8_validate_or_convert((reinterpret_cast<Exiv2::Metadatum *>(item))->tagLabel().c_str());
}
catch (std::exception& e) {
-// debug_exception(e);
return nullptr;
}
}
}
}
-const char *exif_item_get_format_name(ExifItem *item, gboolean UNUSED(brief))
+const char *exif_item_get_format_name(ExifItem *item, gboolean)
{
try {
if (!item) return nullptr;
static const AltKey *find_alt_key(const gchar *xmp_key)
{
- gint i = 0;
-
- while (alt_keys[i].xmp_key)
- {
- if (strcmp(xmp_key, alt_keys[i].xmp_key) == 0) return &alt_keys[i];
- i++;
- }
+ for (const auto& k : alt_keys)
+ if (strcmp(xmp_key, k.xmp_key) == 0) return &k;
return nullptr;
}
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
+ // Let's not touch data_len until we finish copy.
+ // Just in case we run into OOM.
+ size_t img_sz = image.size();
+ auto* b = new Exiv2::byte[img_sz];
+ std::copy_n(image.pData(), img_sz, b);
+ *data_len = img_sz;
+ return b;
}
return nullptr;
}
}
}
-void exif_free_preview(guchar *buf)
+void exif_free_preview(const guchar *buf)
{
- delete[] static_cast<Exiv2::byte*>(buf);
+delete[] static_cast<const Exiv2::byte*>(buf);
}
#endif
}
-void exif_free_preview(guchar *buf)
+void exif_free_preview(const guchar *buf)
{
GList *work = exif_unmap_list;