Fixed wrong plugin options behaviour

While working on MR !230 I noticed that the options read I entered into several plugins could not be read after reading the image.

**The patch fixes problems reading options in plugins and adds option checking in the readtest.cpp.**

In particular, the reading test does the following additional actions:
- reads options before reading the image;
- compare the options read with the options returned by the reader after reading the image;
- compares the format and size of the returned image with the format and size returned by the reader.
This commit is contained in:
Mirco Miranda
2024-06-19 22:18:45 +00:00
committed by Albert Astals Cid
parent 81b7263d73
commit b849e48ef4
18 changed files with 368 additions and 87 deletions

View File

@ -21,7 +21,7 @@
Q_DECLARE_LOGGING_CATEGORY(LOG_PFMPLUGIN)
Q_LOGGING_CATEGORY(LOG_PFMPLUGIN, "kf.imageformats.plugins.pfm", QtWarningMsg)
class PfmHeader
class PFMHeader
{
private:
/*!
@ -61,7 +61,7 @@ private:
QDataStream::ByteOrder m_byteOrder;
public:
PfmHeader() :
PFMHeader() :
m_bw(false),
m_ps(false),
m_width(0),
@ -157,7 +157,18 @@ public:
}
} ;
class PFMHandlerPrivate
{
public:
PFMHandlerPrivate() {}
~PFMHandlerPrivate() {}
PFMHeader m_header;
};
PFMHandler::PFMHandler()
: QImageIOHandler()
, d(new PFMHandlerPrivate)
{
}
@ -177,7 +188,7 @@ bool PFMHandler::canRead(QIODevice *device)
return false;
}
PfmHeader h;
PFMHeader h;
if (!h.peek(device)) {
return false;
}
@ -187,8 +198,7 @@ bool PFMHandler::canRead(QIODevice *device)
bool PFMHandler::read(QImage *image)
{
PfmHeader header;
auto&& header = d->m_header;
if (!header.read(device())) {
qCWarning(LOG_PFMPLUGIN) << "PFMHandler::read() invalid header";
return false;
@ -265,27 +275,33 @@ QVariant PFMHandler::option(ImageOption option) const
QVariant v;
if (option == QImageIOHandler::Size) {
if (auto d = device()) {
PfmHeader h;
if (h.peek(d)) {
auto&& h = d->m_header;
if (h.isValid()) {
v = QVariant::fromValue(h.size());
} else if (auto dev = device()) {
if (h.peek(dev)) {
v = QVariant::fromValue(h.size());
}
}
}
if (option == QImageIOHandler::ImageFormat) {
if (auto d = device()) {
PfmHeader h;
if (h.peek(d)) {
auto&& h = d->m_header;
if (h.isValid()) {
v = QVariant::fromValue(h.format());
} else if (auto dev = device()) {
if (h.peek(dev)) {
v = QVariant::fromValue(h.format());
}
}
}
if (option == QImageIOHandler::Endianness) {
if (auto d = device()) {
PfmHeader h;
if (h.peek(d)) {
auto&& h = d->m_header;
if (h.isValid()) {
v = QVariant::fromValue(h.byteOrder());
} else if (auto dev = device()) {
if (h.peek(dev)) {
v = QVariant::fromValue(h.byteOrder());
}
}