mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-05-28 00:30:23 -04:00
MicroExif: search for the TIFF signature
This commit is contained in:
parent
7742537f8c
commit
25cc8bc262
@ -953,7 +953,7 @@ bool HEIFHandler::ensureDecoder()
|
|||||||
if (isXmp) {
|
if (isXmp) {
|
||||||
m_current_image.setText(QStringLiteral(META_KEY_XMP_ADOBE), QString::fromUtf8(ba));
|
m_current_image.setText(QStringLiteral(META_KEY_XMP_ADOBE), QString::fromUtf8(ba));
|
||||||
} else if (isExif) {
|
} else if (isExif) {
|
||||||
auto exif = MicroExif::fromByteArray(ba.mid(4));
|
auto exif = MicroExif::fromByteArray(ba, true);
|
||||||
if (!exif.isEmpty()) {
|
if (!exif.isEmpty()) {
|
||||||
exif.updateImageResolution(m_current_image);
|
exif.updateImageResolution(m_current_image);
|
||||||
exif.updateImageMetadata(m_current_image);
|
exif.updateImageMetadata(m_current_image);
|
||||||
|
@ -1166,18 +1166,30 @@ void MicroExif::updateImageResolution(QImage &targetImage)
|
|||||||
targetImage.setDotsPerMeterY(qRound(verticalResolution() / 25.4 * 1000));
|
targetImage.setDotsPerMeterY(qRound(verticalResolution() / 25.4 * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
MicroExif MicroExif::fromByteArray(const QByteArray &ba)
|
MicroExif MicroExif::fromByteArray(const QByteArray &ba, bool searchHeader)
|
||||||
{
|
{
|
||||||
|
auto ba0(ba);
|
||||||
|
if (searchHeader) {
|
||||||
|
auto idxLE = ba0.indexOf(QByteArray("II"));
|
||||||
|
auto idxBE = ba0.indexOf(QByteArray("MM"));
|
||||||
|
auto idx = -1;
|
||||||
|
if (idxLE > -1 && idxBE > -1)
|
||||||
|
idx = std::min(idxLE, idxBE);
|
||||||
|
else
|
||||||
|
idx = idxLE > -1 ? idxLE : idxBE;
|
||||||
|
if(idx > 0)
|
||||||
|
ba0 = ba0.mid(idx);
|
||||||
|
}
|
||||||
QBuffer buf;
|
QBuffer buf;
|
||||||
buf.setData(ba);
|
buf.setData(ba0);
|
||||||
return fromDevice(&buf);
|
return fromDevice(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
MicroExif MicroExif::fromRawData(const char *data, size_t size)
|
MicroExif MicroExif::fromRawData(const char *data, size_t size, bool searchHeader)
|
||||||
{
|
{
|
||||||
if (data == nullptr || size == 0)
|
if (data == nullptr || size == 0)
|
||||||
return {};
|
return {};
|
||||||
return fromByteArray(QByteArray::fromRawData(data, size));
|
return fromByteArray(QByteArray::fromRawData(data, size), searchHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
MicroExif MicroExif::fromDevice(QIODevice *device)
|
MicroExif MicroExif::fromDevice(QIODevice *device)
|
||||||
|
@ -332,18 +332,23 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
* \brief fromByteArray
|
* \brief fromByteArray
|
||||||
* Creates the class from RAW EXIF data.
|
* Creates the class from RAW EXIF data.
|
||||||
|
* \param ba Raw data containing EXIF data.
|
||||||
|
* \param searchHeader If true, the EXIF header is searched within the data. If false, the data must begin with the EXIF header.
|
||||||
* \return The created class (empty on error).
|
* \return The created class (empty on error).
|
||||||
* \sa isEmpty
|
* \sa isEmpty
|
||||||
*/
|
*/
|
||||||
static MicroExif fromByteArray(const QByteArray &ba);
|
static MicroExif fromByteArray(const QByteArray &ba, bool searchHeader = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief fromRawData
|
* \brief fromRawData
|
||||||
* Creates the class from RAW EXIF data.
|
* Creates the class from RAW EXIF data.
|
||||||
|
* \param data Raw data containing EXIF data.
|
||||||
|
* \param size The size of \a data.
|
||||||
|
* \param searchHeader If true, the EXIF header is searched within the data. If false, the data must begin with the EXIF header.
|
||||||
* \return The created class (empty on error).
|
* \return The created class (empty on error).
|
||||||
* \sa isEmpty
|
* \sa isEmpty, fromByteArray
|
||||||
*/
|
*/
|
||||||
static MicroExif fromRawData(const char *data, size_t size);
|
static MicroExif fromRawData(const char *data, size_t size, bool searchHeader = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief fromDevice
|
* \brief fromDevice
|
||||||
|
Loading…
Reference in New Issue
Block a user