mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-03-22 07:39:48 -04: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
@ -266,31 +266,16 @@ PCXHEADER::PCXHEADER()
|
||||
|
||||
bool peekHeader(QIODevice *d, PCXHEADER& h)
|
||||
{
|
||||
qint64 oldPos = d->pos();
|
||||
QByteArray head = d->read(sizeof(PCXHEADER));
|
||||
int readBytes = head.size();
|
||||
|
||||
if (d->isSequential()) {
|
||||
for (int pos = readBytes -1; pos >= 0; --pos) {
|
||||
d->ungetChar(head[pos]);
|
||||
}
|
||||
} else {
|
||||
d->seek(oldPos);
|
||||
}
|
||||
|
||||
if (readBytes < sizeof(PCXHEADER)) {
|
||||
auto head = d->peek(sizeof(PCXHEADER));
|
||||
if (size_t(head.size()) < sizeof(PCXHEADER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ok = false;
|
||||
{ // datastream is destroyed before working on device
|
||||
QDataStream ds(head);
|
||||
ds.setByteOrder(QDataStream::LittleEndian);
|
||||
ds >> h;
|
||||
ok = ds.status() == QDataStream::Ok && h.isValid();
|
||||
}
|
||||
QDataStream ds(head);
|
||||
ds.setByteOrder(QDataStream::LittleEndian);
|
||||
ds >> h;
|
||||
|
||||
return ok;
|
||||
return ds.status() == QDataStream::Ok && h.isValid();
|
||||
}
|
||||
|
||||
static bool readLine(QDataStream &s, QByteArray &buf, const PCXHEADER &header)
|
||||
|
||||
Reference in New Issue
Block a user