mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-07-18 03:54:18 -04:00
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:
committed by
Albert Astals Cid
parent
81b7263d73
commit
b849e48ef4
@ -112,6 +112,10 @@ enum LayerId : quint32 {
|
||||
};
|
||||
|
||||
struct PSDHeader {
|
||||
PSDHeader() {
|
||||
memset(this, 0, sizeof(PSDHeader));
|
||||
}
|
||||
|
||||
uint signature;
|
||||
ushort version;
|
||||
uchar reserved[6];
|
||||
@ -1375,7 +1379,17 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
|
||||
} // Private
|
||||
|
||||
class PSDHandlerPrivate
|
||||
{
|
||||
public:
|
||||
PSDHandlerPrivate() {}
|
||||
~PSDHandlerPrivate() {}
|
||||
PSDHeader m_header;
|
||||
};
|
||||
|
||||
PSDHandler::PSDHandler()
|
||||
: QImageIOHandler()
|
||||
, d(new PSDHandlerPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1393,7 +1407,7 @@ bool PSDHandler::read(QImage *image)
|
||||
QDataStream s(device());
|
||||
s.setByteOrder(QDataStream::BigEndian);
|
||||
|
||||
PSDHeader header;
|
||||
auto&& header = d->m_header;
|
||||
s >> header;
|
||||
|
||||
// Check image file format.
|
||||
@ -1430,18 +1444,20 @@ QVariant PSDHandler::option(ImageOption option) const
|
||||
QVariant v;
|
||||
|
||||
if (option == QImageIOHandler::Size) {
|
||||
if (auto d = device()) {
|
||||
auto&& header = d->m_header;
|
||||
if (IsValid(header)) {
|
||||
v = QVariant::fromValue(QSize(header.width, header.height));
|
||||
}
|
||||
else if (auto dev = device()) {
|
||||
// transactions works on both random and sequential devices
|
||||
d->startTransaction();
|
||||
auto ba = d->read(sizeof(PSDHeader));
|
||||
d->rollbackTransaction();
|
||||
dev->startTransaction();
|
||||
auto ba = dev->read(sizeof(PSDHeader));
|
||||
dev->rollbackTransaction();
|
||||
|
||||
QDataStream s(ba);
|
||||
s.setByteOrder(QDataStream::BigEndian);
|
||||
|
||||
PSDHeader header;
|
||||
s >> header;
|
||||
|
||||
if (s.status() == QDataStream::Ok && IsValid(header))
|
||||
v = QVariant::fromValue(QSize(header.width, header.height));
|
||||
}
|
||||
|
Reference in New Issue
Block a user