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

@ -578,30 +578,8 @@ bool SGIImagePrivate::isSupported() const
bool SGIImagePrivate::peekHeader(QIODevice *device)
{
qint64 pos = 0;
if (!device->isSequential()) {
pos = device->pos();
}
auto ok = false;
QByteArray header;
{ // datastream is destroyed before working on device
header = device->read(512);
QDataStream ds(header);
ok = SGIImagePrivate::readHeader(ds, this) && isValid();
}
if (!device->isSequential()) {
return device->seek(pos) && ok;
}
// sequential device undo
auto head = header.data();
auto readBytes = header.size();
while (readBytes > 0) {
device->ungetChar(head[readBytes-- - 1]);
}
return ok;
QDataStream ds(device->peek(512));
return SGIImagePrivate::readHeader(ds, this) && isValid();
}
QSize SGIImagePrivate::size() const