Merge pull request #2613 from cytrinox/fuji_xmp_fix

Extract XMP data from embedded JPEG preview inside RAF files
This commit is contained in:
Miloš Komarčević 2023-05-19 09:25:04 +02:00 committed by GitHub
commit 05ccb5ae58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -10,6 +10,7 @@
#include "futils.hpp"
#include "image.hpp"
#include "image_int.hpp"
#include "jpgimage.hpp"
#include "safe_op.hpp"
#include "tiffimage.hpp"
@ -248,23 +249,32 @@ void RafImage::readMetadata() {
Internal::enforce(jpg_img_len >= 12, ErrorCode::kerCorruptedMetadata);
DataBuf buf(jpg_img_len - 12);
if (io_->seek(jpg_img_off + 12, BasicIo::beg) != 0)
DataBuf jpg_buf(jpg_img_len);
if (io_->seek(jpg_img_off, BasicIo::beg) != 0)
throw Error(ErrorCode::kerFailedToReadImageData);
if (!buf.empty()) {
io_->read(buf.data(), buf.size());
if (!jpg_buf.empty()) {
io_->read(jpg_buf.data(), jpg_buf.size());
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
}
ByteOrder bo = TiffParser::decode(exifData_, iptcData_, xmpData_, buf.c_data(), buf.size());
// Retreive metadata from embedded JPEG preview image.
try {
auto jpg_io = std::make_unique<Exiv2::MemIo>(jpg_buf.data(), jpg_buf.size());
auto jpg_img = JpegImage(std::move(jpg_io), false);
jpg_img.readMetadata();
setByteOrder(jpg_img.byteOrder());
xmpData_ = jpg_img.xmpData();
exifData_ = jpg_img.exifData();
iptcData_ = jpg_img.iptcData();
comment_ = jpg_img.comment();
} catch (const Exiv2::Error&) {
}
exifData_["Exif.Image2.JPEGInterchangeFormat"] = getULong(jpg_img_offset, bigEndian);
exifData_["Exif.Image2.JPEGInterchangeFormatLength"] = getULong(jpg_img_length, bigEndian);
setByteOrder(bo);
// parse the tiff
byte readBuff[4];
if (io_->seek(100, BasicIo::beg) != 0)

View File

@ -22,7 +22,7 @@ class OutOfMemoryInRafImageReadMetadata(metaclass=CaseMeta):
$kerCorruptedMetadata
""",
"""Exiv2 exception in print action for file $filename2:
This does not look like a TIFF image
$kerCorruptedMetadata
"""
]
retval = [1,1]