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

TIFF: parse IPTC metadata

CCBUG: 413970
parent 53643c78
......@@ -46,6 +46,7 @@
#include "kis_transparency_mask.h"
#include <KisImportExportAdditionalChecks.h>
#include <kis_meta_data_backend_registry.h>
#if TIFFLIB_VERSION < 20111221
typedef size_t tmsize_t;
......@@ -663,6 +664,13 @@ KisImportExportErrorCode KisTIFFConverter::readImageFromTiff(TIFF *image, KisTif
dbgFile << "Orientation:" << orientation;
// Try to get IPTC metadata
uint32_t iptc_profile_size = 0;
uint32_t *iptc_profile_data = nullptr;
if (TIFFGetField(image, TIFFTAG_RICHTIFFIPTC, &iptc_profile_size, &iptc_profile_data) == 0) {
dbgFile << "IPTC metadata not found!";
}
// Get the planar configuration
uint16_t planarconfig;
if (TIFFGetField(image, TIFFTAG_PLANARCONFIG, &planarconfig) == 0) {
......@@ -1008,6 +1016,22 @@ KisImportExportErrorCode KisTIFFConverter::readImageFromTiff(TIFF *image, KisTif
break;
}
// Process IPTC metadata
if (iptc_profile_size > 0 && iptc_profile_data != nullptr) {
// warning: profile is an array of uint32_t's
if (TIFFIsByteSwapped(image) != 0) {
TIFFSwabArrayOfLong(iptc_profile_data, iptc_profile_size);
}
KisMetaData::IOBackend *iptcIO = KisMetadataBackendRegistry::instance()->value("iptc");
// Copy the xmp data into the byte array
QByteArray ba(reinterpret_cast<char *>(iptc_profile_data),
static_cast<int>(sizeof(uint32_t) * iptc_profile_size));
QBuffer buf(&ba);
iptcIO->loadFrom(layer->metaData(), &buf);
}
return ImportExportCodes::OK;
}
......
......@@ -6,10 +6,15 @@
#include "kis_tiff_writer_visitor.h"
#include <QBuffer>
#include <tiff.h>
#include <KoColorProfile.h>
#include <KoColorSpace.h>
#include <KoID.h>
#include <KoColorSpaceRegistry.h>
#include <KoID.h>
#include <kis_meta_data_backend_registry.h>
#include <KoConfig.h>
#ifdef HAVE_OPENEXR
......@@ -246,6 +251,17 @@ bool KisTIFFWriterVisitor::saveLayerProjection(KisLayer *layer)
TIFFWriteScanline(image(), buff, y, (tsample_t) - 1);
}
_TIFFfree(buff);
{
// IPTC
KisMetaData::IOBackend *io = KisMetadataBackendRegistry::instance()->value("iptc");
QBuffer buf;
io->saveTo(layer->metaData(), &buf, KisMetaData::IOBackend::NoHeader);
if (!TIFFSetField(image(), TIFFTAG_RICHTIFFIPTC, static_cast<uint32_t>(buf.size()), buf.data().data())) {
dbgFile << "Failed to write the IPTC 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