Simplified read/verify header process

Where possible, QIODevice::peek has been used instead of transactions or instead of using ungetchar() for sequential access devices and seek() for random access devices.

Furthermore:
- RAS format gained the ability of read on sequential devices.
- Removed unused code in XCF (still related to ungetchar and sequential devices).
- These changes should prevent errors like the ones fixed by MR !258
This commit is contained in:
Mirco Miranda
2024-10-06 17:26:25 +00:00
committed by Albert Astals Cid
parent fee0165bef
commit 97120b2537
7 changed files with 51 additions and 180 deletions

View File

@ -341,12 +341,8 @@ bool QOIHandler::canRead(QIODevice *device)
return false;
}
device->startTransaction();
QByteArray head = device->read(QOI_HEADER_SIZE);
qsizetype readBytes = head.size();
device->rollbackTransaction();
if (readBytes < QOI_HEADER_SIZE) {
auto head = device->peek(QOI_HEADER_SIZE);
if (head.size() < QOI_HEADER_SIZE) {
return false;
}
@ -430,12 +426,7 @@ QVariant QOIHandler::option(ImageOption option) const
if (IsSupported(header)) {
v = QVariant::fromValue(QSize(header.Width, header.Height));
} else if (auto d = device()) {
// transactions works on both random and sequential devices
d->startTransaction();
auto ba = d->read(sizeof(QoiHeader));
d->rollbackTransaction();
QDataStream s(ba);
QDataStream s(d->peek(sizeof(QoiHeader)));
s.setByteOrder(QDataStream::BigEndian);
s >> header;
if (s.status() == QDataStream::Ok && IsSupported(header)) {
@ -449,12 +440,7 @@ QVariant QOIHandler::option(ImageOption option) const
if (IsSupported(header)) {
v = QVariant::fromValue(imageFormat(header));
} else if (auto d = device()) {
// transactions works on both random and sequential devices
d->startTransaction();
auto ba = d->read(sizeof(QoiHeader));
d->rollbackTransaction();
QDataStream s(ba);
QDataStream s(d->peek(sizeof(QoiHeader)));
s.setByteOrder(QDataStream::BigEndian);
s >> header;
if (s.status() == QDataStream::Ok && IsSupported(header)) {