mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-07-19 12:14:20 -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
@ -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)) {
|
||||
|
Reference in New Issue
Block a user