PSD: impreved support to sequential access device

This commit is contained in:
Mirco Miranda 2022-09-26 12:49:17 +02:00 committed by Albert Astals Cid
parent ea14882ff7
commit c5f7ea7eac

View File

@ -172,7 +172,8 @@ struct PSDLayerAndMaskSection {
if (globalLayerMaskInfo.size > -1) { if (globalLayerMaskInfo.size > -1) {
currentSize += globalLayerMaskInfo.size + 4; currentSize += globalLayerMaskInfo.size + 4;
} }
for (auto && v : additionalLayerInfo.values()) { auto aliv = additionalLayerInfo.values();
for (auto &&v : aliv) {
currentSize += (12 + v.size); currentSize += (12 + v.size);
if (v.signature == S_8B64) if (v.signature == S_8B64)
currentSize += 4; currentSize += 4;
@ -286,12 +287,6 @@ static PSDImageResourceSection readImageResourceSection(QDataStream &s, bool *ok
qint32 sectioSize; qint32 sectioSize;
s >> sectioSize; s >> sectioSize;
#ifdef QT_DEBUG
auto pos = qint64();
if (auto dev = s.device())
pos = dev->pos();
#endif
// Reading Image resource block // Reading Image resource block
for (auto size = sectioSize; size > 0;) { for (auto size = sectioSize; size > 0;) {
// Length Description // Length Description
@ -356,14 +351,6 @@ static PSDImageResourceSection readImageResourceSection(QDataStream &s, bool *ok
irs.insert(id, irb); irs.insert(id, irb);
} }
#ifdef QT_DEBUG
if (auto dev = s.device()) {
if ((dev->pos() - pos) != sectioSize) {
*ok = false;
}
}
#endif
return irs; return irs;
} }
@ -1249,39 +1236,28 @@ bool PSDHandler::canRead(QIODevice *device)
qWarning("PSDHandler::canRead() called with no device"); qWarning("PSDHandler::canRead() called with no device");
return false; return false;
} }
if (device->isSequential()) {
return false;
}
qint64 oldPos = device->pos(); device->startTransaction();
char head[4]; QDataStream s(device);
qint64 readBytes = device->read(head, sizeof(head)); s.setByteOrder(QDataStream::BigEndian);
if (readBytes < 0) {
qWarning() << "Read failed" << device->errorString();
return false;
}
if (readBytes != sizeof(head)) { PSDHeader header;
if (device->isSequential()) { s >> header;
while (readBytes > 0) {
device->ungetChar(head[readBytes-- - 1]); device->rollbackTransaction();
}
} else { if (s.status() != QDataStream::Ok) {
device->seek(oldPos);
}
return false; return false;
} }
if (device->isSequential()) { if (device->isSequential()) {
while (readBytes > 0) { if (header.color_mode == CM_CMYK || header.color_mode == CM_LABCOLOR || header.color_mode == CM_MULTICHANNEL) {
device->ungetChar(head[readBytes-- - 1]); return false;
} }
} else {
device->seek(oldPos);
} }
return qstrncmp(head, "8BPS", 4) == 0; return IsValid(header);
} }
QImageIOPlugin::Capabilities PSDPlugin::capabilities(QIODevice *device, const QByteArray &format) const QImageIOPlugin::Capabilities PSDPlugin::capabilities(QIODevice *device, const QByteArray &format) const