mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 17:08:08 -04:00
Fixes the following warning: ``` /home/daniel/kimageformats/src/imageformats/dds.cpp: In function ‘qfloat16 readFloat16(QDataStream&)’: /home/daniel/kimageformats/src/imageformats/dds.cpp:1037:11: warning: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘class qfloat16’ from an array of ‘quint16’ {aka ‘short unsigned int’} [-Wclass-memaccess] 1037 | memcpy(&f16, &rawData, sizeof(rawData)); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/qt6/QtCore/qmetatype.h:14, from /usr/include/qt6/QtCore/qobject.h:18, from /usr/include/qt6/QtCore/qiodevice.h:10, from /usr/include/qt6/QtGui/qimageiohandler.h:9, from /usr/include/qt6/QtGui/QImageIOPlugin:1, from /home/daniel/kimageformats/src/imageformats/dds_p.h:13, from /home/daniel/kimageformats/src/imageformats/dds.cpp:12: /usr/include/qt6/QtCore/qfloat16.h:46:7: note: ‘class qfloat16’ declared here 46 | class qfloat16 | ^~~~~~~~ ``` Should also fixes the following failed tests under PowerPC (32-bits): ``` INFO : rgba16dx10.dds: converting rgba16dx10.dds from RGBA16FPx4 to ARGB32 FAIL : rgba16dx10.dds: differs from rgba16dx10.png expected data written to rgba16dx10.dds-expected.data actual data written to rgba16dx10.dds-actual.data ``` ``` INFO : rgba_f16.dds: converting rgba_f16.dds from RGBA16FPx4 to ARGB32 FAIL : rgba_f16.dds: differs from rgba_f16.png expected data written to rgba_f16.dds-expected.data actual data written to rgba_f16.dds-actual.data ```
180 lines
4.6 KiB
C++
180 lines
4.6 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
*/
|
|
|
|
#include "templateimage.h"
|
|
|
|
#include <QFile>
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QVersionNumber>
|
|
|
|
static QJsonObject searchObject(const QFileInfo& file)
|
|
{
|
|
auto fi = QFileInfo(QStringLiteral("%1.json").arg(file.filePath()));
|
|
if (!fi.exists()) {
|
|
return {};
|
|
}
|
|
|
|
QFile f(fi.filePath());
|
|
if (!f.open(QFile::ReadOnly)) {
|
|
return {};
|
|
}
|
|
|
|
QJsonParseError err;
|
|
auto doc = QJsonDocument::fromJson(f.readAll(), &err);
|
|
if (err.error != QJsonParseError::NoError || !doc.isArray()) {
|
|
return {};
|
|
}
|
|
|
|
auto currentQt = QVersionNumber::fromString(qVersion());
|
|
auto arr = doc.array();
|
|
for (auto val : arr) {
|
|
if (!val.isObject())
|
|
continue;
|
|
auto obj = val.toObject();
|
|
auto minQt = QVersionNumber::fromString(obj.value("minQtVersion").toString());
|
|
auto maxQt = QVersionNumber::fromString(obj.value("maxQtVersion").toString());
|
|
auto name = obj.value("fileName").toString();
|
|
auto unsupportedFormat = obj.value("unsupportedFormat").toBool();
|
|
|
|
// filter
|
|
if (name.isEmpty() && !unsupportedFormat)
|
|
continue;
|
|
if (!minQt.isNull() && currentQt < minQt)
|
|
continue;
|
|
if (!maxQt.isNull() && currentQt > maxQt)
|
|
continue;
|
|
return obj;
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
|
|
TemplateImage::TemplateImage(const QFileInfo &fi) :
|
|
m_fi(fi)
|
|
{
|
|
|
|
}
|
|
|
|
bool TemplateImage::isTemplate() const
|
|
{
|
|
auto list = suffixes();
|
|
for (auto&& suffix : list) {
|
|
if (!m_fi.suffix().compare(suffix, Qt::CaseInsensitive))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TemplateImage::isLicense() const
|
|
{
|
|
return !m_fi.suffix().compare(QStringLiteral("license"), Qt::CaseInsensitive);
|
|
}
|
|
|
|
QFileInfo TemplateImage::compareImage(TestFlags &flags, QString& comment) const
|
|
{
|
|
auto fi = jsonImage(flags, comment);
|
|
if ((flags & TestFlag::SkipTest) == TestFlag::SkipTest) {
|
|
return {};
|
|
}
|
|
if (fi.exists()) {
|
|
return fi;
|
|
}
|
|
return legacyImage();
|
|
}
|
|
|
|
bool TemplateImage::checkOptionaInfo(const QImage& image, QString& error) const
|
|
{
|
|
auto obj = searchObject(m_fi);
|
|
if (obj.isEmpty()) {
|
|
return true;
|
|
}
|
|
|
|
// Test resolution
|
|
auto res = obj.value("resolution").toObject();
|
|
if (!res.isEmpty()) {
|
|
auto resx = res.value("dotsPerMeterX").toInt();
|
|
auto resy = res.value("dotsPerMeterY").toInt();
|
|
if (resx != image.dotsPerMeterX()) {
|
|
error = QStringLiteral("X resolution mismatch (current: %1, expected: %2)!").arg(image.dotsPerMeterX()).arg(resx);
|
|
return false;
|
|
}
|
|
if (resy != image.dotsPerMeterY()) {
|
|
error = QStringLiteral("Y resolution mismatch (current: %1, expected: %2)!").arg(image.dotsPerMeterY()).arg(resy);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Test metadata
|
|
auto meta = obj.value("metadata").toArray();
|
|
for (auto jv : meta) {
|
|
auto obj = jv.toObject();
|
|
auto key = obj.value("Key").toString();
|
|
auto val = obj.value("Value").toString();
|
|
auto cur = image.text(key);
|
|
if (cur != val) {
|
|
error = QStringLiteral("Metadata '%1' mismatch (current: '%2', expected:'%3')!").arg(key, cur, val);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
quint8 TemplateImage::fuzziness() const
|
|
{
|
|
auto obj = searchObject(m_fi);
|
|
if (obj.isEmpty()) {
|
|
return quint8(0);
|
|
}
|
|
return quint8(obj.value("fuzziness").toInt());
|
|
}
|
|
|
|
QStringList TemplateImage::suffixes()
|
|
{
|
|
return QStringList({"png", "tif", "tiff", "json"});
|
|
}
|
|
|
|
QFileInfo TemplateImage::legacyImage() const
|
|
{
|
|
auto list = suffixes();
|
|
for (auto&& suffix : list) {
|
|
auto fi = QFileInfo(QStringLiteral("%1/%2.%3").arg(m_fi.path(), m_fi.completeBaseName(), suffix));
|
|
if (fi.exists()) {
|
|
return fi;
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
|
|
QFileInfo TemplateImage::jsonImage(TestFlags &flags, QString& comment) const
|
|
{
|
|
flags = TestFlag::None;
|
|
|
|
auto obj = searchObject(m_fi);
|
|
if (obj.isEmpty()) {
|
|
return {};
|
|
}
|
|
|
|
auto name = obj.value("fileName").toString();
|
|
auto unsupportedFormat = obj.value("unsupportedFormat").toBool();
|
|
comment = obj.value("comment").toString();
|
|
|
|
if(obj.value("disableAutoTransform").toBool()) {
|
|
flags |= TestFlag::DisableAutotransform;
|
|
}
|
|
|
|
if (unsupportedFormat) {
|
|
flags |= TestFlag::SkipTest;
|
|
return {};
|
|
}
|
|
|
|
return QFileInfo(QStringLiteral("%1/%2").arg(m_fi.path(), name));
|
|
}
|
|
|