Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qimagereader.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4//#define QIMAGEREADER_DEBUG
5
97#include "qimagereader.h"
98
99#include <qbytearray.h>
100#ifdef QIMAGEREADER_DEBUG
101#include <qdebug.h>
102#endif
103#include <qfile.h>
104#include <qfileinfo.h>
105#include <qimage.h>
106#include <qimageiohandler.h>
107#include <qlist.h>
108#include <qrect.h>
109#include <qsize.h>
110#include <qcolor.h>
111#include <qvariant.h>
112
113// factory loader
114#include <qcoreapplication.h>
115#include <private/qfactoryloader_p.h>
116#include <QtCore/private/qlocking_p.h>
117
118// for qt_getImageText
119#include <private/qimage_p.h>
120
121// image handlers
122#include <private/qbmphandler_p.h>
123#include <private/qppmhandler_p.h>
124#include <private/qxbmhandler_p.h>
125#include <private/qxpmhandler_p.h>
126#ifndef QT_NO_IMAGEFORMAT_PNG
127#include <private/qpnghandler_p.h>
128#endif
129
130#include <private/qimagereaderwriterhelpers_p.h>
131#include <qtgui_tracepoints_p.h>
132
133#include <algorithm>
134
136
137using namespace QImageReaderWriterHelpers;
138using namespace Qt::StringLiterals;
139
140Q_TRACE_POINT(qtgui, QImageReader_read_before_reading, QImageReader *reader, const QString &filename);
141Q_TRACE_POINT(qtgui, QImageReader_read_after_reading, QImageReader *reader, bool result);
142
144 const QByteArray &format,
145 bool autoDetectImageFormat,
146 bool ignoresFormatAndExtension)
147{
148 if (!autoDetectImageFormat && format.isEmpty())
149 return nullptr;
150
151 QByteArray form = format.toLower();
152 QImageIOHandler *handler = nullptr;
153 QByteArray suffix;
154
155#ifndef QT_NO_IMAGEFORMATPLUGIN
156 Q_CONSTINIT static QBasicMutex mutex;
157 const auto locker = qt_scoped_lock(mutex);
158
159 typedef QMultiMap<int, QString> PluginKeyMap;
160
161 // check if we have plugins that support the image format
163 const PluginKeyMap keyMap = l->keyMap();
164
165#ifdef QIMAGEREADER_DEBUG
166 qDebug() << "QImageReader::createReadHandler( device =" << (void *)device << ", format =" << format << "),"
167 << keyMap.uniqueKeys().size() << "plugins available: " << keyMap;
168#endif
169
170 int suffixPluginIndex = -1;
171#endif // QT_NO_IMAGEFORMATPLUGIN
172
173 if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
174 // if there's no format, see if \a device is a file, and if so, find
175 // the file suffix and find support for that format among our plugins.
176 // this allows plugins to override our built-in handlers.
177 if (QFile *file = qobject_cast<QFile *>(device)) {
178#ifdef QIMAGEREADER_DEBUG
179 qDebug() << "QImageReader::createReadHandler: device is a file:" << file->fileName();
180#endif
181 if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) {
182#ifndef QT_NO_IMAGEFORMATPLUGIN
183 const int index = keyMap.key(QString::fromLatin1(suffix), -1);
184 if (index != -1) {
185#ifdef QIMAGEREADER_DEBUG
186 qDebug() << "QImageReader::createReadHandler: suffix recognized; the"
187 << suffix << "plugin might be able to read this";
188#endif
189 suffixPluginIndex = index;
190 }
191#endif // QT_NO_IMAGEFORMATPLUGIN
192 }
193 }
194 }
195
196 QByteArray testFormat = !form.isEmpty() ? form : suffix;
197
198 if (ignoresFormatAndExtension)
199 testFormat = QByteArray();
200
201#ifndef QT_NO_IMAGEFORMATPLUGIN
202 if (suffixPluginIndex != -1) {
203 // check if the plugin that claims support for this format can load
204 // from this device with this format.
205 const qint64 pos = device ? device->pos() : 0;
206 const int index = keyMap.key(QString::fromLatin1(suffix), -1);
207 if (index != -1) {
208 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index));
210 handler = plugin->create(device, testFormat);
211#ifdef QIMAGEREADER_DEBUG
212 qDebug() << "QImageReader::createReadHandler: using the" << suffix
213 << "plugin";
214#endif
215 }
216 }
217 if (device && !device->isSequential())
218 device->seek(pos);
219 }
220
221 if (!handler && !testFormat.isEmpty() && !ignoresFormatAndExtension) {
222 // check if any plugin supports the format (they are not allowed to
223 // read from the device yet).
224 const qint64 pos = device ? device->pos() : 0;
225
226 if (autoDetectImageFormat) {
227 const int keyCount = keyMap.size();
228 for (int i = 0; i < keyCount; ++i) {
229 if (i != suffixPluginIndex) {
230 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i));
232#ifdef QIMAGEREADER_DEBUG
233 qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this format";
234#endif
235 handler = plugin->create(device, testFormat);
236 break;
237 }
238 }
239 }
240 } else {
241 const int testIndex = keyMap.key(QLatin1StringView(testFormat), -1);
242 if (testIndex != -1) {
243 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(testIndex));
245#ifdef QIMAGEREADER_DEBUG
246 qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format";
247#endif
248 handler = plugin->create(device, testFormat);
249 }
250 }
251 }
252 if (device && !device->isSequential())
253 device->seek(pos);
254 }
255
256#endif // QT_NO_IMAGEFORMATPLUGIN
257
258 // if we don't have a handler yet, check if we have built-in support for
259 // the format
260 if (!handler && !testFormat.isEmpty()) {
261 if (false) {
262#ifndef QT_NO_IMAGEFORMAT_PNG
263 } else if (testFormat == "png") {
264 handler = new QPngHandler;
265#endif
266#ifndef QT_NO_IMAGEFORMAT_BMP
267 } else if (testFormat == "bmp") {
268 handler = new QBmpHandler;
269 } else if (testFormat == "dib") {
270 handler = new QBmpHandler(QBmpHandler::DibFormat);
271#endif
272#ifndef QT_NO_IMAGEFORMAT_XPM
273 } else if (testFormat == "xpm") {
274 handler = new QXpmHandler;
275#endif
276#ifndef QT_NO_IMAGEFORMAT_XBM
277 } else if (testFormat == "xbm") {
278 handler = new QXbmHandler;
279 handler->setOption(QImageIOHandler::SubType, testFormat);
280#endif
281#ifndef QT_NO_IMAGEFORMAT_PPM
282 } else if (testFormat == "pbm" || testFormat == "pbmraw" || testFormat == "pgm"
283 || testFormat == "pgmraw" || testFormat == "ppm" || testFormat == "ppmraw") {
284 handler = new QPpmHandler;
285 handler->setOption(QImageIOHandler::SubType, testFormat);
286#endif
287 }
288
289#ifdef QIMAGEREADER_DEBUG
290 if (handler)
291 qDebug() << "QImageReader::createReadHandler: using the built-in handler for" << testFormat;
292#endif
293 }
294
295 if (handler && device && !suffix.isEmpty()) {
296 Q_ASSERT(qobject_cast<QFile *>(device));
297 // We have a file claiming to be of a recognized format. Now confirm that
298 // the handler also recognizes the file contents.
299 const qint64 pos = device->pos();
300 handler->setDevice(device);
301 if (!form.isEmpty())
302 handler->setFormat(form);
303 bool canRead = handler->canRead();
304 device->seek(pos);
305 if (canRead) {
306 // ok, we're done.
307 return handler;
308 }
309#ifdef QIMAGEREADER_DEBUG
310 qDebug() << "QImageReader::createReadHandler: the" << suffix << "handler can not read this file";
311#endif
312 // File may still be valid, just with wrong suffix, so fall back to
313 // finding a handler based on contents, below.
314 delete handler;
315 handler = nullptr;
316 }
317
318#ifndef QT_NO_IMAGEFORMATPLUGIN
319 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
320 // check if any of our plugins recognize the file from its contents.
321 const qint64 pos = device ? device->pos() : 0;
322 const int keyCount = keyMap.size();
323 for (int i = 0; i < keyCount; ++i) {
324 if (i != suffixPluginIndex) {
325 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i));
327 handler = plugin->create(device, testFormat);
328#ifdef QIMAGEREADER_DEBUG
329 qDebug() << "QImageReader::createReadHandler: the" << keyMap.value(i) << "plugin can read this data";
330#endif
331 break;
332 }
333 }
334 }
335 if (device && !device->isSequential())
336 device->seek(pos);
337 }
338#endif // QT_NO_IMAGEFORMATPLUGIN
339
340 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
341 // check if any of our built-in handlers recognize the file from its
342 // contents.
343 int currentFormat = 0;
344 if (!suffix.isEmpty()) {
345 // If reading from a file with a suffix, start testing our
346 // built-in handler for that suffix first.
347 for (int i = 0; i < _qt_NumFormats; ++i) {
348 if (_qt_BuiltInFormats[i].extension == suffix) {
349 currentFormat = i;
350 break;
351 }
352 }
353 }
354
355 QByteArray subType;
356 int numFormats = _qt_NumFormats;
357 while (device && numFormats >= 0) {
358 const qint64 pos = device->pos();
359 switch (currentFormat) {
360#ifndef QT_NO_IMAGEFORMAT_PNG
361 case _qt_PngFormat:
363 handler = new QPngHandler;
364 break;
365#endif
366#ifndef QT_NO_IMAGEFORMAT_BMP
367 case _qt_BmpFormat:
369 handler = new QBmpHandler;
370 break;
371#endif
372#ifndef QT_NO_IMAGEFORMAT_XPM
373 case _qt_XpmFormat:
375 handler = new QXpmHandler;
376 break;
377#endif
378#ifndef QT_NO_IMAGEFORMAT_PPM
379 case _qt_PbmFormat:
380 case _qt_PgmFormat:
381 case _qt_PpmFormat:
382 if (QPpmHandler::canRead(device, &subType)) {
383 handler = new QPpmHandler;
384 handler->setOption(QImageIOHandler::SubType, subType);
385 }
386 break;
387#endif
388#ifndef QT_NO_IMAGEFORMAT_XBM
389 case _qt_XbmFormat:
391 handler = new QXbmHandler;
392 break;
393#endif
394 default:
395 break;
396 }
397 if (!device->isSequential())
398 device->seek(pos);
399
400 if (handler) {
401#ifdef QIMAGEREADER_DEBUG
402 qDebug("QImageReader::createReadHandler: the %s built-in handler can read this data",
403 _qt_BuiltInFormats[currentFormat].extension);
404#endif
405 break;
406 }
407
408 --numFormats;
409 ++currentFormat;
410 if (currentFormat >= _qt_NumFormats)
411 currentFormat = 0;
412 }
413 }
414
415 if (!handler) {
416#ifdef QIMAGEREADER_DEBUG
417 qDebug("QImageReader::createReadHandler: no handlers found. giving up.");
418#endif
419 // no handler: give up.
420 return nullptr;
421 }
422
423 handler->setDevice(device);
424 if (!form.isEmpty())
425 handler->setFormat(form);
426 return handler;
427}
428
430{
431public:
434
435 // device
442 bool initHandler();
443
444 // image options
450 void getText();
451 enum {
456
457 // error
460
462
463 static int maxAlloc;
464};
465
466int QImageReaderPrivate::maxAlloc = 256; // 256 MB is enough for an 8K 64bpp image
467
472 : autoDetectImageFormat(true), ignoresFormatAndExtension(false)
473{
474 device = nullptr;
475 deleteDevice = false;
476 handler = nullptr;
477 quality = -1;
480
481 q = qq;
482}
483
488{
489 delete handler;
490 if (deleteDevice)
491 delete device;
492}
493
498{
499 if (handler)
500 return true;
501
502 // check some preconditions
505 errorString = QImageReader::tr("Invalid device");
506 return false;
507 }
508
509 // probe the file extension
511 Q_ASSERT(qobject_cast<QFile*>(device) != nullptr); // future-proofing; for now this should always be the case, so...
512 QFile *file = static_cast<QFile *>(device);
513
515 // this is bad. we should abort the open attempt and note the failure.
518 return false;
519 }
520
522 if (!format.isEmpty()) {
523 // Try the most probable extension first
524 int currentFormatIndex = extensions.indexOf(format.toLower());
525 if (currentFormatIndex > 0)
526 extensions.swapItemsAt(0, currentFormatIndex);
527 }
528
529 int currentExtension = 0;
530
532
533 do {
535 + QLatin1StringView(extensions.at(currentExtension++).constData()));
537 } while (!file->isOpen() && currentExtension < extensions.size());
538
539 if (!device->isOpen()) {
541 errorString = QImageReader::tr("File not found");
542 file->setFileName(fileName); // restore the old file name
543 return false;
544 }
545 }
546
547 // assign a handler
550 errorString = QImageReader::tr("Unsupported image format");
551 return false;
552 }
553 return true;
554}
555
560{
563}
564
571{
572}
573
580{
581 d->device = device;
582 d->format = format;
583}
584
593{
594 d->deleteDevice = true;
595}
596
601{
602 delete d;
603}
604
617{
618 d->format = format;
619}
620
636{
637 if (d->format.isEmpty()) {
638 if (!d->initHandler())
639 return QByteArray();
640 return d->handler->canRead() ? d->handler->format() : QByteArray();
641 }
642
643 return d->format;
644}
645
686{
688}
689
697{
698 return d->autoDetectImageFormat;
699}
700
701
717{
718 d->ignoresFormatAndExtension = ignored;
719}
720
721
731{
733}
734
735
750{
751 delete d->handler;
752 d->handler = nullptr;
753 if (d->device && d->deleteDevice)
754 delete d->device;
755 d->device = device;
756 d->deleteDevice = false;
757 d->text.clear();
758}
759
765{
766 return d->device;
767}
768
781{
783 d->deleteDevice = true;
784}
785
796{
797 QFile *file = qobject_cast<QFile *>(d->device);
798 return file ? file->fileName() : QString();
799}
800
822{
823 d->quality = quality;
824}
825
834{
835 return d->quality;
836}
837
838
850{
851 if (!d->initHandler())
852 return QSize();
853
856
857 return QSize();
858}
859
873{
874 if (!d->initHandler())
876
879
881}
882
896{
897 d->getText();
898 return d->text.keys();
899}
900
912{
913 d->getText();
914 return d->text.value(key);
915}
916
925{
926 d->clipRect = rect;
927}
928
937{
938 return d->clipRect;
939}
940
952{
953 d->scaledSize = size;
954}
955
962{
963 return d->scaledSize;
964}
965
974{
975 d->scaledClipRect = rect;
976}
977
984{
985 return d->scaledClipRect;
986}
987
998{
999 if (!d->initHandler())
1000 return;
1003}
1004
1015{
1016 if (!d->initHandler())
1017 return QColor();
1019 return qvariant_cast<QColor>(d->handler->option(QImageIOHandler::BackgroundColor));
1020 return QColor();
1021}
1022
1032{
1033 if (!d->initHandler())
1034 return false;
1037 return false;
1038}
1039
1046{
1047 if (!d->initHandler())
1048 return QByteArray();
1049
1052 return QByteArray();
1053}
1054
1061{
1062 if (!d->initHandler())
1063 return QList<QByteArray>();
1064
1066 return qvariant_cast<QList<QByteArray> >(d->handler->option(QImageIOHandler::SupportedSubTypes));
1067 return QList<QByteArray>();
1068}
1069
1078QImageIOHandler::Transformations QImageReader::transformation() const
1079{
1083 return QImageIOHandler::Transformations(option);
1084}
1085
1095{
1098}
1099
1108{
1109 switch (d->autoTransform) {
1111 return true;
1113 return false;
1115 Q_FALLTHROUGH();
1116 default:
1117 break;
1118 }
1119 return false;
1120}
1121
1140{
1141 if (!d->initHandler())
1142 return false;
1143
1144 return d->handler->canRead();
1145}
1146
1160{
1161 // Because failed image reading might have side effects, we explicitly
1162 // return a null image instead of the image we've just created.
1163 QImage image;
1164 return read(&image) ? image : QImage();
1165}
1166
1167extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient);
1168
1190{
1191 if (!image) {
1192 qWarning("QImageReader::read: cannot read into null pointer");
1193 return false;
1194 }
1195
1196 if (!d->initHandler())
1197 return false;
1198
1199 // set the handler specific options.
1202 || d->clipRect.isNull()) {
1203 // Only enable the ScaledSize option if there is no clip rect, or
1204 // if the handler also supports ClipRect.
1206 }
1207 }
1214
1215 // read the image
1216 QString filename = fileName();
1217 if (Q_TRACE_ENABLED(QImageReader_read_before_reading)) {
1218 Q_TRACE(QImageReader_read_before_reading, this, filename.isEmpty() ? u"unknown"_s : filename);
1219 }
1220
1221 const bool result = d->handler->read(image);
1222
1223 Q_TRACE(QImageReader_read_after_reading, this, result);
1224
1225 if (!result) {
1227 d->errorString = QImageReader::tr("Unable to read image data");
1228 return false;
1229 }
1230
1231 // provide default implementations for any unsupported image
1232 // options
1236 // all features are supported by the handler; nothing to do.
1237 } else {
1238 // the image is already scaled, so apply scaled clipping.
1239 if (!d->scaledClipRect.isNull())
1240 *image = image->copy(d->scaledClipRect);
1241 }
1242 } else {
1244 // supports scaled clipping but not scaling, most
1245 // likely a broken handler.
1246 } else {
1247 if (d->scaledSize.isValid()) {
1249 }
1250 if (d->scaledClipRect.isValid()) {
1251 *image = image->copy(d->scaledClipRect);
1252 }
1253 }
1254 }
1255 } else {
1258 // nothing to do (ClipRect is ignored!)
1259 } else {
1260 // provide all workarounds.
1261 if (d->scaledClipRect.isValid()) {
1262 *image = image->copy(d->scaledClipRect);
1263 }
1264 }
1265 } else {
1267 // this makes no sense; a handler that supports
1268 // ScaledClipRect but not ScaledSize is broken, and we
1269 // can't work around it.
1270 } else {
1271 // provide all workarounds.
1272 if (d->clipRect.isValid())
1273 *image = image->copy(d->clipRect);
1274 if (d->scaledSize.isValid())
1276 if (d->scaledClipRect.isValid())
1277 *image = image->copy(d->scaledClipRect);
1278 }
1279 }
1280 }
1281
1282 // successful read; check for "@Nx" file name suffix and set device pixel ratio.
1283 static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
1284 if (!disableNxImageLoading) {
1285 const QByteArray suffix = QFileInfo(filename).baseName().right(3).toLatin1();
1286 if (suffix.size() == 3 && suffix[0] == '@' && suffix[1] >= '2' && suffix[1] <= '9' && suffix[2] == 'x')
1287 image->setDevicePixelRatio(suffix[1] - '0');
1288 }
1289 if (autoTransform())
1291
1292 return true;
1293}
1294
1307{
1308 if (!d->initHandler())
1309 return false;
1310 return d->handler->jumpToNextImage();
1311}
1312
1322bool QImageReader::jumpToImage(int imageNumber)
1323{
1324 if (!d->initHandler())
1325 return false;
1326 return d->handler->jumpToImage(imageNumber);
1327}
1328
1338{
1339 if (!d->initHandler())
1340 return -1;
1341 return d->handler->loopCount();
1342}
1343
1354{
1355 if (!d->initHandler())
1356 return -1;
1357 return d->handler->imageCount();
1358}
1359
1370{
1371 if (!d->initHandler())
1372 return -1;
1373 return d->handler->nextImageDelay();
1374}
1375
1386{
1387 if (!d->initHandler())
1388 return -1;
1389 return d->handler->currentImageNumber();
1390}
1391
1399{
1400 if (!d->initHandler())
1401 return QRect();
1402 return d->handler->currentImageRect();
1403}
1404
1411{
1412 return d->imageReaderError;
1413}
1414
1422{
1423 if (d->errorString.isEmpty())
1424 return QImageReader::tr("Unknown error");
1425 return d->errorString;
1426}
1427
1445{
1446 if (!d->initHandler())
1447 return false;
1448 return d->handler->supportsOption(option);
1449}
1450
1456{
1459 return QByteArray();
1460
1461 return imageFormat(&file);
1462}
1463
1471{
1473 QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true, false);
1474 if (handler) {
1475 if (handler->canRead())
1476 format = handler->format();
1477 delete handler;
1478 }
1479 return format;
1480}
1481
1511{
1513}
1514
1525{
1527}
1528
1541{
1544}
1545
1554{
1555 static int envLimit = []() {
1556 bool ok = false;
1557 int res = qEnvironmentVariableIntValue("QT_IMAGEIO_MAXALLOC", &ok);
1558 return ok ? res : -1;
1559 }();
1560
1561 return envLimit >= 0 ? envLimit : QImageReaderPrivate::maxAlloc;
1562}
1563
1584{
1585 if (mbLimit >= 0)
1587}
1588
IOBluetoothDevice * device
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:474
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:106
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
FileError error() const
Returns the file error status.
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QString baseName() const
Returns the base name of the file without the path.
QString suffix() const
Returns the suffix (extension) of the file.
\inmodule QtCore
Definition qfile.h:93
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition qfile.cpp:881
void setFileName(const QString &name)
Sets the name of the file.
Definition qfile.cpp:302
QString fileName() const override
Returns the name set by setFileName() or to the QFile constructors.
Definition qfile.cpp:277
virtual bool isEmpty() const
\inmodule QtCore \reentrant
Definition qiodevice.h:34
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.
virtual QRect currentImageRect() const
Returns the rect of the current image.
virtual int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
virtual int imageCount() const
For image formats that support animation, this function returns the number of images in the animation...
ImageOption
This enum describes the different options supported by QImageIOHandler.
virtual bool jumpToNextImage()
For image formats that support animation, this function jumps to the next image.
virtual int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current im...
virtual bool canRead() const =0
Returns true if an image can be read from the device (i.e., the image format is supported,...
virtual void setOption(ImageOption option, const QVariant &value)
Sets the option option with the value value.
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
virtual bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
virtual QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
void setDevice(QIODevice *device)
Sets the device of the QImageIOHandler to device.
virtual bool jumpToImage(int imageNumber)
For image formats that support animation, this function jumps to the image whose sequence number is i...
virtual int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
virtual bool read(QImage *image)=0
Read an image from the device, and stores it in image.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
\inmodule QtGui
virtual QImageIOHandler * create(QIODevice *device, const QByteArray &format=QByteArray()) const =0
Creates and returns a QImageIOHandler subclass, with device and format set.
virtual Capabilities capabilities(QIODevice *device, const QByteArray &format) const =0
Returns the capabilities of the plugin, based on the data in device and the format format.
QImageReaderPrivate(QImageReader *qq)
enum QImageReaderPrivate::@197 autoTransform
QImageReader::ImageReaderError imageReaderError
QMap< QString, QString > text
QImageIOHandler * handler
The QImageReader class provides a format independent interface for reading images from files or other...
void setScaledClipRect(const QRect &rect)
Sets the scaled clip rect to rect.
QString errorString() const
Returns a human readable description of the last error that occurred.
~QImageReader()
Destructs the QImageReader object.
bool decideFormatFromContent() const
Returns whether the image reader should decide which plugin to use only based on the contents of the ...
int imageCount() const
For image formats that support animation, this function returns the total number of images in the ani...
void setDevice(QIODevice *device)
Sets QImageReader's device to device.
bool autoTransform() const
bool autoDetectImageFormat() const
Returns true if image format autodetection is enabled on this image reader; otherwise returns false.
static QList< QByteArray > supportedMimeTypes()
Returns the list of MIME types supported by QImageReader.
int quality() const
QSize scaledSize() const
Returns the scaled size of the image.
QString fileName() const
If the currently assigned device is a QFile, or if setFileName() has been called, this function retur...
void setFileName(const QString &fileName)
Sets the file name of QImageReader to fileName.
void setScaledSize(const QSize &size)
Sets the scaled size of the image to size.
ImageReaderError
This enum describes the different types of errors that can occur when reading images with QImageReade...
QImageIOHandler::Transformations transformation() const
QIODevice * device() const
Returns the device currently assigned to QImageReader, or \nullptr if no device has been assigned.
QByteArray subType() const
QColor backgroundColor() const
static void setAllocationLimit(int mbLimit)
QRect currentImageRect() const
For image formats that support animation, this function returns the rect for the current frame.
bool supportsAnimation() const
void setDecideFormatFromContent(bool ignored)
If ignored is set to true, then the image reader will ignore specified formats or file extensions and...
void setAutoTransform(bool enabled)
QString text(const QString &key) const
bool jumpToImage(int imageNumber)
For image formats that support animation, this function skips to the image whose sequence number is i...
QRect clipRect() const
Returns the clip rect (also known as the ROI, or Region Of Interest) of the image.
QImageReader()
Constructs an empty QImageReader object.
bool supportsOption(QImageIOHandler::ImageOption option) const
static int allocationLimit()
QList< QByteArray > supportedSubTypes() const
static QList< QByteArray > imageFormatsForMimeType(const QByteArray &mimeType)
QByteArray format() const
Returns the format QImageReader uses for reading images.
bool canRead() const
Returns true if an image can be read for the device (i.e., the image format is supported,...
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageReader.
void setQuality(int quality)
void setBackgroundColor(const QColor &color)
bool jumpToNextImage()
For image formats that support animation, this function steps over the current image,...
void setFormat(const QByteArray &format)
Sets the format QImageReader will use when reading images, to format.
QSize size() const
Returns the size of the image, without actually reading the image contents.
void setClipRect(const QRect &rect)
Sets the image clip rect (also known as the ROI, or Region Of Interest) to rect.
void setAutoDetectImageFormat(bool enabled)
If enabled is true, image format autodetection is enabled; otherwise, it is disabled.
int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current fr...
ImageReaderError error() const
Returns the type of error that occurred last.
QRect scaledClipRect() const
Returns the scaled clip rect of the image.
int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
QStringList textKeys() const
int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
QImage::Format imageFormat() const
QImage read()
Reads an image from the device.
\inmodule QtGui
Definition qimage.h:37
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_Invalid
Definition qimage.h:42
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
void swapItemsAt(qsizetype i, qsizetype j)
Definition qlist.h:664
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
Definition qmap.h:186
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:356
void clear()
Definition qmap.h:288
QList< Key > keys() const
Definition qmap.h:382
bool isEmpty() const
Definition qmap.h:268
\inmodule QtCore
Definition qmutex.h:285
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:169
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:163
\inmodule QtCore
Definition qsize.h:25
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:126
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString right(qsizetype n) const
Returns a substring that contains the n rightmost characters of the string.
Definition qstring.cpp:5180
QByteArray toLatin1() const &
Definition qstring.h:559
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QString toLower() const &
Definition qstring.h:368
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
QSize toSize() const
Returns the variant as a QSize if the variant has userType() \l QMetaType::QSize; otherwise returns a...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMet...
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
void extension()
[6]
Definition dialogs.cpp:230
#define this
Definition dialogs.cpp:9
rect
[4]
QList< QByteArray > imageFormatsForMimeType(const QByteArray &mimeType, Capability cap)
QSharedPointer< QFactoryLoader > pluginLoader()
QList< QByteArray > supportedImageFormats(Capability cap)
static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[]
QList< QByteArray > supportedMimeTypes(Capability cap)
Combined button and popup list for selecting options.
@ SmoothTransformation
@ IgnoreAspectRatio
Definition image.cpp:4
#define Q_FALLTHROUGH()
const char * mimeType
Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)
Definition qimage.cpp:5739
QMap< QString, QString > qt_getImageTextFromDescription(const QString &description)
Definition qimage.cpp:5764
void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)
Definition qimage.cpp:5739
static QImageIOHandler * createReadHandlerHelper(QIODevice *device, const QByteArray &format, bool autoDetectImageFormat, bool ignoresFormatAndExtension)
#define qDebug
[1]
Definition qlogging.h:160
#define qWarning
Definition qlogging.h:162
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum src
GLint GLsizei GLsizei GLenum format
GLuint res
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLuint GLenum option
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_TRACE_ENABLED(x)
Definition qtrace_p.h:148
#define Q_TRACE(x,...)
Definition qtrace_p.h:144
#define Q_TRACE_POINT(provider, tracepoint,...)
Definition qtrace_p.h:232
long long qint64
Definition qtypes.h:55
#define enabled
QFile file
[0]
QMutex mutex
[2]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:955