PSD: added support to EXIF metadata

This commit is contained in:
Mirco Miranda
2025-01-15 08:41:10 +01:00
committed by Albert Astals Cid
parent a89367dde6
commit ac3591c7ea
9 changed files with 124 additions and 10 deletions

View File

@ -106,7 +106,7 @@ kimageformats_add_plugin(kimg_pfm SOURCES pfm.cpp)
##################################
kimageformats_add_plugin(kimg_psd SOURCES psd.cpp scanlineconverter.cpp)
kimageformats_add_plugin(kimg_psd SOURCES psd.cpp microexif.cpp scanlineconverter.cpp)
##################################

View File

@ -3,7 +3,7 @@
SPDX-FileCopyrightText: 2003 Ignacio Castaño <castano@ludicon.com>
SPDX-FileCopyrightText: 2015 Alex Merry <alex.merry@kde.org>
SPDX-FileCopyrightText: 2022-2024 Mirco Miranda <mircomir@outlook.com>
SPDX-FileCopyrightText: 2022-2025 Mirco Miranda <mircomir@outlook.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
@ -27,6 +27,7 @@
*/
#include "fastmath_p.h"
#include "microexif_p.h"
#include "psd_p.h"
#include "scanlineconverter_p.h"
#include "util_p.h"
@ -96,6 +97,8 @@ enum ImageResourceId : quint16 {
IRI_ICCPROFILE = 0x040F,
IRI_TRANSPARENCYINDEX = 0x0417,
IRI_VERSIONINFO = 0x0421,
IRI_EXIFDATA1 = 0x0422,
IRI_EXIFDATA3 = 0x0423, // never seen
IRI_XMPMETADATA = 0x0424
};
@ -522,6 +525,25 @@ static bool setXmpData(QImage& img, const PSDImageResourceSection& irs)
return true;
}
/*!
* \brief setExifData
* Adds EXIF metadata to QImage.
* \param img The image.
* \param irs The image resource section.
* \return True on success, otherwise false.
*/
static bool setExifData(QImage& img, const PSDImageResourceSection& irs)
{
if (!irs.contains(IRI_EXIFDATA1))
return false;
auto irb = irs.value(IRI_EXIFDATA1);
auto exif = MicroExif::fromByteArray(irb.data);
if (exif.isEmpty())
return false;
exif.toImageMetadata(img);
return true;
}
/*!
* \brief hasMergedData
* Checks if merged image data are available.
@ -1356,6 +1378,11 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
// qDebug() << "No XMP data found!";
}
// EXIF data
if (!setExifData(img, irs)) {
// qDebug() << "No EXIF data found!";
}
// Duotone images: color data contains the duotone specification (not documented).
// Other applications that read Photoshop files can treat a duotone image as a gray image,
// and just preserve the contents of the duotone information when reading and writing the file.