Use of metadata macro definitions

Replaced the metadata string with the common macro definition
This commit is contained in:
Mirco Miranda 2024-06-07 15:08:37 +00:00 committed by Albert Astals Cid
parent cb5ca7fc48
commit 7499e3b8d4
6 changed files with 39 additions and 32 deletions

View File

@ -290,23 +290,23 @@ static void readMetadata(const Imf::Header &header, QImage &image)
{
// set some useful metadata
if (auto comments = header.findTypedAttribute<Imf::StringAttribute>("comments")) {
image.setText(QStringLiteral("Comment"), QString::fromStdString(comments->value()));
image.setText(QStringLiteral(META_KEY_COMMENT), QString::fromStdString(comments->value()));
}
if (auto owner = header.findTypedAttribute<Imf::StringAttribute>("owner")) {
image.setText(QStringLiteral("Owner"), QString::fromStdString(owner->value()));
image.setText(QStringLiteral(META_KEY_OWNER), QString::fromStdString(owner->value()));
}
if (auto lat = header.findTypedAttribute<Imf::FloatAttribute>("latitude")) {
image.setText(QStringLiteral("Latitude"), QLocale::c().toString(lat->value()));
image.setText(QStringLiteral(META_KEY_LATITUDE), QLocale::c().toString(lat->value()));
}
if (auto lon = header.findTypedAttribute<Imf::FloatAttribute>("longitude")) {
image.setText(QStringLiteral("Longitude"), QLocale::c().toString(lon->value()));
image.setText(QStringLiteral(META_KEY_LONGITUDE), QLocale::c().toString(lon->value()));
}
if (auto alt = header.findTypedAttribute<Imf::FloatAttribute>("altitude")) {
image.setText(QStringLiteral("Altitude"), QLocale::c().toString(alt->value()));
image.setText(QStringLiteral(META_KEY_ALTITUDE), QLocale::c().toString(alt->value()));
}
if (auto capDate = header.findTypedAttribute<Imf::StringAttribute>("capDate")) {
@ -317,7 +317,7 @@ static void readMetadata(const Imf::Header &header, QImage &image)
auto dateTime = QDateTime::fromString(QString::fromStdString(capDate->value()), QStringLiteral("yyyy:MM:dd HH:mm:ss"));
if (dateTime.isValid()) {
dateTime.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(off));
image.setText(QStringLiteral("CreationDate"), dateTime.toString(Qt::ISODate));
image.setText(QStringLiteral(META_KEY_CREATIONDATE), dateTime.toString(Qt::ISODate));
}
}
@ -332,7 +332,7 @@ static void readMetadata(const Imf::Header &header, QImage &image)
// Non-standard attribute
if (auto xmp = header.findTypedAttribute<Imf::StringAttribute>("xmp")) {
image.setText(QStringLiteral("XML:com.adobe.xmp"), QString::fromStdString(xmp->value()));
image.setText(QStringLiteral(META_KEY_XMP_ADOBE), QString::fromStdString(xmp->value()));
}
/* TODO: OpenEXR 3.2 metadata
@ -530,18 +530,18 @@ static void setMetadata(const QImage &image, Imf::Header &header)
auto dateTime = QDateTime::currentDateTime();
for (auto &&key : image.textKeys()) {
auto text = image.text(key);
if (!key.compare(QStringLiteral("Comment"), Qt::CaseInsensitive)) {
if (!key.compare(QStringLiteral(META_KEY_COMMENT), Qt::CaseInsensitive)) {
header.insert("comments", Imf::StringAttribute(text.toStdString()));
}
if (!key.compare(QStringLiteral("Owner"), Qt::CaseInsensitive)) {
if (!key.compare(QStringLiteral(META_KEY_OWNER), Qt::CaseInsensitive)) {
header.insert("owner", Imf::StringAttribute(text.toStdString()));
}
// clang-format off
if (!key.compare(QStringLiteral("Latitude"), Qt::CaseInsensitive) ||
!key.compare(QStringLiteral("Longitude"), Qt::CaseInsensitive) ||
!key.compare(QStringLiteral("Altitude"), Qt::CaseInsensitive)) {
if (!key.compare(QStringLiteral(META_KEY_LATITUDE), Qt::CaseInsensitive) ||
!key.compare(QStringLiteral(META_KEY_LONGITUDE), Qt::CaseInsensitive) ||
!key.compare(QStringLiteral(META_KEY_ALTITUDE), Qt::CaseInsensitive)) {
// clang-format on
auto ok = false;
auto value = QLocale::c().toFloat(text, &ok);
@ -550,7 +550,7 @@ static void setMetadata(const QImage &image, Imf::Header &header)
}
}
if (!key.compare(QStringLiteral("CreationDate"), Qt::CaseInsensitive)) {
if (!key.compare(QStringLiteral(META_KEY_CREATIONDATE), Qt::CaseInsensitive)) {
auto dt = QDateTime::fromString(text, Qt::ISODate);
if (dt.isValid()) {
dateTime = dt;
@ -558,7 +558,7 @@ static void setMetadata(const QImage &image, Imf::Header &header)
}
#ifndef EXR_DISABLE_XMP_ATTRIBUTE // warning: Non-standard attribute!
if (!key.compare(QStringLiteral("XML:com.adobe.xmp"), Qt::CaseInsensitive)) {
if (!key.compare(QStringLiteral(META_KEY_XMP_ADOBE), Qt::CaseInsensitive)) {
header.insert("xmp", Imf::StringAttribute(text.toStdString()));
}
#endif

View File

@ -319,7 +319,7 @@ public:
{
auto xmp = xmpData();
if (!xmp.isEmpty()) {
image.setText(QStringLiteral(META_KEY_XMP), xmp);
image.setText(QStringLiteral(META_KEY_XMP_ADOBE), xmp);
}
auto descr = description();
if (!descr.isEmpty()) {
@ -563,7 +563,7 @@ public:
meta.pvarSoftware.VT.pszVal = software.data();
}
auto xmp = image.text(QStringLiteral(META_KEY_XMP)).toUtf8();
auto xmp = image.text(QStringLiteral(META_KEY_XMP_ADOBE)).toUtf8();
if (!xmp.isNull()) {
if (auto err = PKImageEncode_SetXMPMetadata_WMP(pEncoder, reinterpret_cast<quint8 *>(xmp.data()), xmp.size())) {
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::write() error while setting XMP data:" << err;

View File

@ -521,7 +521,7 @@ static bool setXmpData(QImage& img, const PSDImageResourceSection& irs)
// NOTE: "XML:com.adobe.xmp" is the meta set by Qt reader when an
// XMP packet is found (e.g. when reading a PNG saved by Photoshop).
// I'm reusing the same key because a programs could search for it.
img.setText(QStringLiteral("XML:com.adobe.xmp"), xmp);
img.setText(QStringLiteral(META_KEY_XMP_ADOBE), xmp);
return true;
}

View File

@ -690,29 +690,29 @@ bool LoadRAW(QImageIOHandler *handler, QImage &img)
xmpPacket = QString::fromUtf8(xmpdata, xmplen);
}
// Add info from LibRAW structs (e.g. GPS position, info about lens, info about shot and flash, etc...)
img.setText(QStringLiteral("XML:com.adobe.xmp"), updateXmpPacket(xmpPacket, rawProcessor.get()));
img.setText(QStringLiteral(META_KEY_XMP_ADOBE), updateXmpPacket(xmpPacket, rawProcessor.get()));
auto model = QString::fromUtf8(iparams.normalized_model);
if (!model.isEmpty()) {
img.setText(QStringLiteral("Model"), model);
img.setText(QStringLiteral(META_KEY_MODEL), model);
}
auto manufacturer = QString::fromUtf8(iparams.normalized_make);
if (!manufacturer.isEmpty()) {
img.setText(QStringLiteral("Manufacturer"), manufacturer);
img.setText(QStringLiteral(META_KEY_MANUFACTURER), manufacturer);
}
auto software = QString::fromUtf8(iparams.software);
if (!software.isEmpty()) {
img.setText(QStringLiteral("Software"), software);
img.setText(QStringLiteral(META_KEY_SOFTWARE), software);
}
auto &&iother = rawProcessor->imgdata.other;
auto description = QString::fromUtf8(iother.desc);
if (!description.isEmpty()) {
img.setText(QStringLiteral("Description"), description);
img.setText(QStringLiteral(META_KEY_DESCRIPTION), description);
}
auto artist = QString::fromUtf8(iother.artist);
if (!artist.isEmpty()) {
img.setText(QStringLiteral("Author"), artist);
img.setText(QStringLiteral(META_KEY_AUTHOR), artist);
}
return true;

View File

@ -14,17 +14,24 @@
#include <QImageIOHandler>
// Image metadata keys to use in plugins (so they are consistent)
#define META_KEY_DESCRIPTION "Description"
#define META_KEY_MANUFACTURER "Manufacturer"
#define META_KEY_SOFTWARE "Software"
#define META_KEY_MODEL "Model"
#define META_KEY_ALTITUDE "Altitude"
#define META_KEY_AUTHOR "Author"
#define META_KEY_COMMENT "Comment"
#define META_KEY_COPYRIGHT "Copyright"
#define META_KEY_CREATIONDATE "CreationDate"
#define META_KEY_TITLE "Title"
#define META_KEY_DESCRIPTION "Description"
#define META_KEY_DOCUMENTNAME "DocumentName"
#define META_KEY_HOSTCOMPUTER "HostComputer"
#define META_KEY_XMP "XML:com.adobe.xmp"
#define META_KEY_LATITUDE "Latitude"
#define META_KEY_LONGITUDE "Longitude"
#define META_KEY_HOSTCOMPUTER "HostComputer"
#define META_KEY_MANUFACTURER "Manufacturer"
#define META_KEY_MODEL "Model"
#define META_KEY_OWNER "Owner"
#define META_KEY_SOFTWARE "Software"
#define META_KEY_TITLE "Title"
#define META_KEY_XML_GIMP "XML:org.gimp.xml"
#define META_KEY_XMP_ADOBE "XML:com.adobe.xmp"
// QList uses some extra space for stuff, hence the 32 here suggested by Thiago Macieira
static constexpr int kMaxQVectorSize = std::numeric_limits<int>::max() - 32;

View File

@ -1596,7 +1596,7 @@ void XCFImageFormat::setImageParasites(const XCFImage &xcf_image, QImage &image)
// comments may also be present in the "gimp-metadata" parasite.
if (key == QStringLiteral("gimp-comment")) {
value.replace('\0', QByteArray());
image.setText(QStringLiteral("Comment"), QString::fromUtf8(value));
image.setText(QStringLiteral(META_KEY_COMMENT), QString::fromUtf8(value));
continue;
}
@ -1607,7 +1607,7 @@ void XCFImageFormat::setImageParasites(const XCFImage &xcf_image, QImage &image)
// NOTE: I arbitrary defined the metadata "XML:org.gimp.xml" because it seems
// a GIMP proprietary XML format (no xmlns defined)
value.replace('\0', QByteArray());
image.setText(QStringLiteral("XML:org.gimp.xml"), QString::fromUtf8(value));
image.setText(QStringLiteral(META_KEY_XML_GIMP), QString::fromUtf8(value));
continue;
}
@ -1623,7 +1623,7 @@ void XCFImageFormat::setImageParasites(const XCFImage &xcf_image, QImage &image)
// XMP packet is found (e.g. when reading a PNG saved by Photoshop).
// I reused the same key because some programs could search for it.
value.replace('\0', QByteArray());
image.setText(QStringLiteral("XML:com.adobe.xmp"), QString::fromUtf8(value));
image.setText(QStringLiteral(META_KEY_XMP_ADOBE), QString::fromUtf8(value));
continue;
}
#endif