mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-11-22 10:02:43 -05:00
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:
committed by
Albert Astals Cid
parent
fee0165bef
commit
97120b2537
@ -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
|
||||
|
||||
Reference in New Issue
Block a user