Commit d8822ab9 authored by Amyspark's avatar Amyspark Committed by Dmitry Kazakov
Browse files

TIFF: parse XMP metadata

CCBUG: 413970
parent 25c2d09e
......@@ -671,6 +671,13 @@ KisImportExportErrorCode KisTIFFConverter::readImageFromTiff(TIFF *image, KisTif
dbgFile << "IPTC metadata not found!";
}
// Try to get XMP metadata
uint32_t xmp_size = 0;
uint8_t *xmp_data = nullptr;
if (TIFFGetField(image, TIFFTAG_XMLPACKET, &xmp_size, &xmp_data) == 0) {
dbgFile << "XML metadata not found!";
}
// Get the planar configuration
uint16_t planarconfig;
if (TIFFGetField(image, TIFFTAG_PLANARCONFIG, &planarconfig) == 0) {
......@@ -1018,6 +1025,8 @@ KisImportExportErrorCode KisTIFFConverter::readImageFromTiff(TIFF *image, KisTif
// Process IPTC metadata
if (iptc_profile_size > 0 && iptc_profile_data != nullptr) {
dbgFile << "Loading IPTC profile. Size: " << sizeof(uint32_t) * iptc_profile_size;
// warning: profile is an array of uint32_t's
if (TIFFIsByteSwapped(image) != 0) {
TIFFSwabArrayOfLong(iptc_profile_data, iptc_profile_size);
......@@ -1032,6 +1041,18 @@ KisImportExportErrorCode KisTIFFConverter::readImageFromTiff(TIFF *image, KisTif
iptcIO->loadFrom(layer->metaData(), &buf);
}
// Process XMP metadata
if (xmp_size > 0 && xmp_data != nullptr) {
dbgFile << "Loading XMP data. Size: " << xmp_size;
KisMetaData::IOBackend *xmpIO = KisMetadataBackendRegistry::instance()->value("xmp");
// Copy the xmp data into the byte array
QByteArray ba(reinterpret_cast<char *>(xmp_data), static_cast<int>(xmp_size));
QBuffer buf(&ba);
xmpIO->loadFrom(layer->metaData(), &buf);
}
return ImportExportCodes::OK;
}
......
......@@ -262,6 +262,17 @@ bool KisTIFFWriterVisitor::saveLayerProjection(KisLayer *layer)
dbgFile << "Failed to write the IPTC metadata to the TIFF field";
}
}
{
// XMP
KisMetaData::IOBackend *io = KisMetadataBackendRegistry::instance()->value("xmp");
QBuffer buf;
io->saveTo(layer->metaData(), &buf, KisMetaData::IOBackend::NoHeader);
if (!TIFFSetField(image(), TIFFTAG_XMLPACKET, static_cast<uint32_t>(buf.size()), buf.data().data())) {
dbgFile << "Failed to write the XMP metadata to the TIFF field";
}
}
TIFFWriteDirectory(image());
return true;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment