From 296e67254ed94b1dcf47e5669fff925cb0dc1e71 Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Thu, 1 May 2025 10:45:04 +0200 Subject: [PATCH] Fix wrong device position after read options --- src/imageformats/jxr.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/imageformats/jxr.cpp b/src/imageformats/jxr.cpp index 7124f53..b671685 100644 --- a/src/imageformats/jxr.cpp +++ b/src/imageformats/jxr.cpp @@ -243,6 +243,22 @@ public: return true; } + /*! + * \brief initForReadingAndRollBack + * Initialize the device for reading and rollback the device to start position. + * \param device The source device. + * \return True on success, otherwise false. + */ + bool initForReadingAndRollBack(QIODevice *device) + { + if (device) + device->startTransaction(); + auto ok = initForReading(device); + if (device) + device->rollbackTransaction(); + return ok; + } + /*! * \brief jxrFormat * \return The JXR format. @@ -1153,7 +1169,7 @@ QVariant JXRHandler::option(ImageOption option) const QVariant v; if (option == QImageIOHandler::Size) { - if (d->initForReading(device())) { + if (d->initForReadingAndRollBack(device())) { auto size = d->imageSize(); if (size.isValid()) { v = QVariant::fromValue(size); @@ -1162,7 +1178,7 @@ QVariant JXRHandler::option(ImageOption option) const } if (option == QImageIOHandler::ImageFormat) { - if (d->initForReading(device())) { + if (d->initForReadingAndRollBack(device())) { v = QVariant::fromValue(d->imageFormat()); } } @@ -1173,7 +1189,7 @@ QVariant JXRHandler::option(ImageOption option) const if (option == QImageIOHandler::ImageTransformation) { // ignore result: I might want to read the value set in writing - d->initForReading(device()); + d->initForReadingAndRollBack(device()); v = int(d->transformation()); }