From f8a251e2688962842f41c66fda872e649492265a Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Thu, 28 Apr 2022 08:52:18 +0200 Subject: [PATCH] Support to QImageIOHandler::Size option --- src/imageformats/psd.cpp | 32 ++++++++++++++++++++++++++++++++ src/imageformats/psd_p.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/imageformats/psd.cpp b/src/imageformats/psd.cpp index 0477c3f..49f2abd 100644 --- a/src/imageformats/psd.cpp +++ b/src/imageformats/psd.cpp @@ -820,6 +820,38 @@ bool PSDHandler::read(QImage *image) return true; } +bool PSDHandler::supportsOption(ImageOption option) const +{ + if (option == QImageIOHandler::Size) + return true; + return false; +} + +QVariant PSDHandler::option(ImageOption option) const +{ + QVariant v; + + if (option == QImageIOHandler::Size) { + if (auto d = device()) { + // transactions works on both random and sequential devices + d->startTransaction(); + auto ba = d->read(sizeof(PSDHeader)); + d->rollbackTransaction(); + + QDataStream s(ba); + s.setByteOrder(QDataStream::BigEndian); + + PSDHeader header; + s >> header; + + if (s.status() == QDataStream::Ok && IsValid(header)) + v = QVariant::fromValue(QSize(header.width, header.height)); + } + } + + return v; +} + bool PSDHandler::canRead(QIODevice *device) { if (!device) { diff --git a/src/imageformats/psd_p.h b/src/imageformats/psd_p.h index 0ad483c..f0014a0 100644 --- a/src/imageformats/psd_p.h +++ b/src/imageformats/psd_p.h @@ -18,6 +18,9 @@ public: bool canRead() const override; bool read(QImage *image) override; + bool supportsOption(QImageIOHandler::ImageOption option) const override; + QVariant option(QImageIOHandler::ImageOption option) const override; + static bool canRead(QIODevice *device); };