qimagereader.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qimagereader.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40//#define QIMAGEREADER_DEBUG-
41-
42/*!-
43 \class QImageReader-
44 \brief The QImageReader class provides a format independent interface-
45 for reading images from files or other devices.-
46-
47 \inmodule QtGui-
48 \reentrant-
49 \ingroup painting-
50 \ingroup io-
51-
52 The most common way to read images is through QImage and QPixmap's-
53 constructors, or by calling QImage::load() and-
54 QPixmap::load(). QImageReader is a specialized class which gives-
55 you more control when reading images. For example, you can read an-
56 image into a specific size by calling setScaledSize(), and you can-
57 select a clip rect, effectively loading only parts of an image, by-
58 calling setClipRect(). Depending on the underlying support in the-
59 image format, this can save memory and speed up loading of images.-
60-
61 To read an image, you start by constructing a QImageReader object.-
62 Pass either a file name or a device pointer, and the image format-
63 to QImageReader's constructor. You can then set several options,-
64 such as the clip rect (by calling setClipRect()) and scaled size-
65 (by calling setScaledSize()). canRead() returns the image if the-
66 QImageReader can read the image (i.e., the image format is-
67 supported and the device is open for reading). Call read() to read-
68 the image.-
69-
70 If any error occurs when reading the image, read() will return a-
71 null QImage. You can then call error() to find the type of error-
72 that occurred, or errorString() to get a human readable-
73 description of what went wrong.-
74-
75 \section1 Formats-
76-
77 Call supportedImageFormats() for a list of formats that-
78 QImageReader can read. QImageReader supports all built-in image-
79 formats, in addition to any image format plugins that support-
80 reading. Call supportedMimeTypes() to obtain a list of supported MIME-
81 types, which for example can be passed to QFileDialog::setMimeTypeFilters().-
82-
83 QImageReader autodetects the image format by default, by looking at the-
84 provided (optional) format string, the file name suffix, and the data-
85 stream contents. You can enable or disable this feature, by calling-
86 setAutoDetectImageFormat().-
87-
88 \section1 High Resolution Versions of Images-
89-
90 It is possible to provide high resolution versions of images should a scaling-
91 between \e{device pixels} and \e{device independent pixels} be in effect.-
92-
93 The high resolution version is marked by the suffix \c @2x on the base name.-
94 The image read will have its \e{device pixel ratio} set to a value of 2.-
95-
96 This can be disabled by setting the environment variable-
97 \c QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING.-
98-
99 \sa QImageWriter, QImageIOHandler, QImageIOPlugin, QMimeDatabase-
100 \sa QImage::devicePixelRatio(), QPixmap::devicePixelRatio(), QIcon, QPainter::drawPixmap(), QPainter::drawImage(), Qt::AA_UseHighDpiPixmaps-
101*/-
102-
103/*!-
104 \enum QImageReader::ImageReaderError-
105-
106 This enum describes the different types of errors that can occur-
107 when reading images with QImageReader.-
108-
109 \value FileNotFoundError QImageReader was used with a file name,-
110 but not file was found with that name. This can also happen if the-
111 file name contained no extension, and the file with the correct-
112 extension is not supported by Qt.-
113-
114 \value DeviceError QImageReader encountered a device error when-
115 reading the image. You can consult your particular device for more-
116 details on what went wrong.-
117-
118 \value UnsupportedFormatError Qt does not support the requested-
119 image format.-
120-
121 \value InvalidDataError The image data was invalid, and-
122 QImageReader was unable to read an image from it. The can happen-
123 if the image file is damaged.-
124-
125 \value UnknownError An unknown error occurred. If you get this-
126 value after calling read(), it is most likely caused by a bug in-
127 QImageReader.-
128*/-
129#include "qimagereader.h"-
130-
131#include <qbytearray.h>-
132#ifdef QIMAGEREADER_DEBUG-
133#include <qdebug.h>-
134#endif-
135#include <qfile.h>-
136#include <qfileinfo.h>-
137#include <qimage.h>-
138#include <qimageiohandler.h>-
139#include <qlist.h>-
140#include <qrect.h>-
141#include <qsize.h>-
142#include <qcolor.h>-
143#include <qvariant.h>-
144-
145// factory loader-
146#include <qcoreapplication.h>-
147#include <private/qfactoryloader_p.h>-
148#include <QMutexLocker>-
149-
150// image handlers-
151#include <private/qbmphandler_p.h>-
152#include <private/qppmhandler_p.h>-
153#include <private/qxbmhandler_p.h>-
154#include <private/qxpmhandler_p.h>-
155#ifndef QT_NO_IMAGEFORMAT_PNG-
156#include <private/qpnghandler_p.h>-
157#endif-
158#ifndef QT_NO_IMAGEFORMAT_JPEG-
159#include <private/qjpeghandler_p.h>-
160#endif-
161#ifdef QT_BUILTIN_GIF_READER-
162#include <private/qgifhandler_p.h>-
163#endif-
164-
165#include <algorithm>-
166-
167QT_BEGIN_NAMESPACE-
168-
169#ifndef QT_NO_IMAGEFORMATPLUGIN-
170Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
never executed: end of block
never executed: guard.store(QtGlobalStatic::Destroyed);
never executed: return &holder.value;
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
171 (QImageIOHandlerFactoryInterface_iid, QLatin1String("/imageformats")))-
172#endif-
173-
174enum _qt_BuiltInFormatType {-
175#ifndef QT_NO_IMAGEFORMAT_PNG-
176 _qt_PngFormat,-
177#endif-
178#ifndef QT_NO_IMAGEFORMAT_JPEG-
179 _qt_JpgFormat,-
180 _qt_JpegFormat,-
181#endif-
182#ifdef QT_BUILTIN_GIF_READER-
183 _qt_GifFormat,-
184#endif-
185#ifndef QT_NO_IMAGEFORMAT_BMP-
186 _qt_BmpFormat,-
187#endif-
188#ifndef QT_NO_IMAGEFORMAT_PPM-
189 _qt_PpmFormat,-
190 _qt_PgmFormat,-
191 _qt_PbmFormat,-
192#endif-
193#ifndef QT_NO_IMAGEFORMAT_XBM-
194 _qt_XbmFormat,-
195#endif-
196#ifndef QT_NO_IMAGEFORMAT_XPM-
197 _qt_XpmFormat,-
198#endif-
199 _qt_NumFormats,-
200 _qt_NoFormat = -1-
201};-
202-
203struct _qt_BuiltInFormatStruct-
204{-
205 const char *extension;-
206 const char *mimeType;-
207};-
208-
209static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[] = {-
210#ifndef QT_NO_IMAGEFORMAT_PNG-
211 {"png", "image/png"},-
212#endif-
213#ifndef QT_NO_IMAGEFORMAT_JPEG-
214 {"jpg", "image/jpeg"},-
215 {"jpeg", "image/jpeg"},-
216#endif-
217#ifdef QT_BUILTIN_GIF_READER-
218 {"gif", "image/gif"},-
219#endif-
220#ifndef QT_NO_IMAGEFORMAT_BMP-
221 {"bmp", "image/bmp"},-
222#endif-
223#ifndef QT_NO_IMAGEFORMAT_PPM-
224 {"ppm", "image/x-portable-pixmap"},-
225 {"pgm", "image/x-portable-graymap"},-
226 {"pbm", "image/x-portable-bitmap"},-
227#endif-
228#ifndef QT_NO_IMAGEFORMAT_XBM-
229 {"xbm", "image/x-xbitmap"},-
230#endif-
231#ifndef QT_NO_IMAGEFORMAT_XPM-
232 {"xpm", "image/x-xpixmap"},-
233#endif-
234 {"", ""}-
235};-
236-
237static QImageIOHandler *createReadHandlerHelper(QIODevice *device,-
238 const QByteArray &format,-
239 bool autoDetectImageFormat,-
240 bool ignoresFormatAndExtension)-
241{-
242 if (!autoDetectImageFormat && format.isEmpty())
!autoDetectImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
format.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
243 return 0;
never executed: return 0;
0
244-
245 QByteArray form = format.toLower();-
246 QImageIOHandler *handler = 0;-
247 QByteArray suffix;-
248-
249#ifndef QT_NO_IMAGEFORMATPLUGIN-
250 static QMutex mutex;-
251 QMutexLocker locker(&mutex);-
252-
253 typedef QMultiMap<int, QString> PluginKeyMap;-
254-
255 // check if we have plugins that support the image format-
256 QFactoryLoader *l = loader();-
257 const PluginKeyMap keyMap = l->keyMap();-
258-
259#ifdef QIMAGEREADER_DEBUG-
260 qDebug() << "QImageReader::createReadHandler( device =" << (void *)device << ", format =" << format << "),"-
261 << keyMap.size() << "plugins available: " << keyMap.values();-
262#endif-
263-
264 int suffixPluginIndex = -1;-
265#endif // QT_NO_IMAGEFORMATPLUGIN-
266-
267 if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
format.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
autoDetectImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
!ignoresFormatAndExtensionDescription
TRUEnever evaluated
FALSEnever evaluated
0
268 // if there's no format, see if \a device is a file, and if so, find-
269 // the file suffix and find support for that format among our plugins.-
270 // this allows plugins to override our built-in handlers.-
271 if (QFile *file = qobject_cast<QFile *>(device)) {
QFile *file = ...ile *>(device)Description
TRUEnever evaluated
FALSEnever evaluated
0
272#ifdef QIMAGEREADER_DEBUG-
273 qDebug() << "QImageReader::createReadHandler: device is a file:" << file->fileName();-
274#endif-
275 if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) {
!(suffix = QFi...1()).isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
276#ifndef QT_NO_IMAGEFORMATPLUGIN-
277 const int index = keyMap.key(QString::fromLatin1(suffix), -1);-
278 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
279#ifdef QIMAGEREADER_DEBUG-
280 qDebug() << "QImageReader::createReadHandler: suffix recognized; the"-
281 << suffix << "plugin might be able to read this";-
282#endif-
283 suffixPluginIndex = index;-
284 }
never executed: end of block
0
285#endif // QT_NO_IMAGEFORMATPLUGIN-
286 }
never executed: end of block
0
287 }
never executed: end of block
0
288 }
never executed: end of block
0
289-
290 QByteArray testFormat = !form.isEmpty() ? form : suffix;
!form.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
291-
292 if (ignoresFormatAndExtension)
ignoresFormatAndExtensionDescription
TRUEnever evaluated
FALSEnever evaluated
0
293 testFormat = QByteArray();
never executed: testFormat = QByteArray();
0
294-
295#ifndef QT_NO_IMAGEFORMATPLUGIN-
296 if (suffixPluginIndex != -1) {
suffixPluginIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
297 // check if the plugin that claims support for this format can load-
298 // from this device with this format.-
299 const qint64 pos = device ? device->pos() : 0;
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
300 const int index = keyMap.key(QString::fromLatin1(suffix), -1);-
301 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
302 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index));-
303 if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
pluginDescription
TRUEnever evaluated
FALSEnever evaluated
plugin->capabi...lugin::CanReadDescription
TRUEnever evaluated
FALSEnever evaluated
0
304 handler = plugin->create(device, testFormat);-
305#ifdef QIMAGEREADER_DEBUG-
306 qDebug() << "QImageReader::createReadHandler: using the" << suffix-
307 << "plugin";-
308#endif-
309 }
never executed: end of block
0
310 }
never executed: end of block
0
311 if (device && !device->isSequential())
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
!device->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
0
312 device->seek(pos);
never executed: device->seek(pos);
0
313 }
never executed: end of block
0
314-
315 if (!handler && !testFormat.isEmpty() && !ignoresFormatAndExtension) {
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
!testFormat.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!ignoresFormatAndExtensionDescription
TRUEnever evaluated
FALSEnever evaluated
0
316 // check if any plugin supports the format (they are not allowed to-
317 // read from the device yet).-
318 const qint64 pos = device ? device->pos() : 0;
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
319-
320 if (autoDetectImageFormat) {
autoDetectImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
0
321 const int keyCount = keyMap.size();-
322 for (int i = 0; i < keyCount; ++i) {
i < keyCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
323 if (i != suffixPluginIndex) {
i != suffixPluginIndexDescription
TRUEnever evaluated
FALSEnever evaluated
0
324 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i));-
325 if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
pluginDescription
TRUEnever evaluated
FALSEnever evaluated
plugin->capabi...lugin::CanReadDescription
TRUEnever evaluated
FALSEnever evaluated
0
326#ifdef QIMAGEREADER_DEBUG-
327 qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this format";-
328#endif-
329 handler = plugin->create(device, testFormat);-
330 break;
never executed: break;
0
331 }-
332 }
never executed: end of block
0
333 }
never executed: end of block
0
334 } else {
never executed: end of block
0
335 const int testIndex = keyMap.key(QLatin1String(testFormat), -1);-
336 if (testIndex != -1) {
testIndex != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
337 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(testIndex));-
338 if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
pluginDescription
TRUEnever evaluated
FALSEnever evaluated
plugin->capabi...lugin::CanReadDescription
TRUEnever evaluated
FALSEnever evaluated
0
339#ifdef QIMAGEREADER_DEBUG-
340 qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format";-
341#endif-
342 handler = plugin->create(device, testFormat);-
343 }
never executed: end of block
0
344 }
never executed: end of block
0
345 }
never executed: end of block
0
346 if (device && !device->isSequential())
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
!device->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
0
347 device->seek(pos);
never executed: device->seek(pos);
0
348 }
never executed: end of block
0
349-
350#endif // QT_NO_IMAGEFORMATPLUGIN-
351-
352 // if we don't have a handler yet, check if we have built-in support for-
353 // the format-
354 if (!handler && !testFormat.isEmpty()) {
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
!testFormat.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
355 if (false) {
dead code: { }
-
356#ifndef QT_NO_IMAGEFORMAT_PNG
dead code: { }
-
357 } else if (testFormat == "png") {
testFormat == "png"Description
TRUEnever evaluated
FALSEnever evaluated
dead code: { }
-
358 handler = new QPngHandler;-
359#endif-
360#ifndef QT_NO_IMAGEFORMAT_JPEG-
361 } else if (testFormat == "jpg" || testFormat == "jpeg") {-
362 handler = new QJpegHandler;-
363#endif-
364#ifdef QT_BUILTIN_GIF_READER-
365 } else if (testFormat == "gif") {-
366 handler = new QGifHandler;-
367#endif-
368#ifndef QT_NO_IMAGEFORMAT_BMP-
369 } else if (testFormat == "bmp") {
never executed: end of block
testFormat == "bmp"Description
TRUEnever evaluated
FALSEnever evaluated
0
370 handler = new QBmpHandler;-
371 } else if (testFormat == "dib") {
never executed: end of block
testFormat == "dib"Description
TRUEnever evaluated
FALSEnever evaluated
0
372 handler = new QBmpHandler(QBmpHandler::DibFormat);-
373#endif-
374#ifndef QT_NO_IMAGEFORMAT_XPM-
375 } else if (testFormat == "xpm") {
never executed: end of block
testFormat == "xpm"Description
TRUEnever evaluated
FALSEnever evaluated
0
376 handler = new QXpmHandler;-
377#endif-
378#ifndef QT_NO_IMAGEFORMAT_XBM-
379 } else if (testFormat == "xbm") {
never executed: end of block
testFormat == "xbm"Description
TRUEnever evaluated
FALSEnever evaluated
0
380 handler = new QXbmHandler;-
381 handler->setOption(QImageIOHandler::SubType, testFormat);-
382#endif-
383#ifndef QT_NO_IMAGEFORMAT_PPM-
384 } else if (testFormat == "pbm" || testFormat == "pbmraw" || testFormat == "pgm"
never executed: end of block
testFormat == "pbm"Description
TRUEnever evaluated
FALSEnever evaluated
testFormat == "pbmraw"Description
TRUEnever evaluated
FALSEnever evaluated
testFormat == "pgm"Description
TRUEnever evaluated
FALSEnever evaluated
0
385 || testFormat == "pgmraw" || testFormat == "ppm" || testFormat == "ppmraw") {
testFormat == "pgmraw"Description
TRUEnever evaluated
FALSEnever evaluated
testFormat == "ppm"Description
TRUEnever evaluated
FALSEnever evaluated
testFormat == "ppmraw"Description
TRUEnever evaluated
FALSEnever evaluated
0
386 handler = new QPpmHandler;-
387 handler->setOption(QImageIOHandler::SubType, testFormat);-
388#endif-
389 }
never executed: end of block
0
390-
391#ifdef QIMAGEREADER_DEBUG-
392 if (handler)-
393 qDebug() << "QImageReader::createReadHandler: using the built-in handler for" << testFormat;-
394#endif-
395 }
never executed: end of block
0
396-
397#ifndef QT_NO_IMAGEFORMATPLUGIN-
398 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
autoDetectImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
ignoresFormatAndExtensionDescription
TRUEnever evaluated
FALSEnever evaluated
0
399 // check if any of our plugins recognize the file from its contents.-
400 const qint64 pos = device ? device->pos() : 0;
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
401 const int keyCount = keyMap.size();-
402 for (int i = 0; i < keyCount; ++i) {
i < keyCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
403 if (i != suffixPluginIndex) {
i != suffixPluginIndexDescription
TRUEnever evaluated
FALSEnever evaluated
0
404 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i));-
405 if (plugin && plugin->capabilities(device, QByteArray()) & QImageIOPlugin::CanRead) {
pluginDescription
TRUEnever evaluated
FALSEnever evaluated
plugin->capabi...lugin::CanReadDescription
TRUEnever evaluated
FALSEnever evaluated
0
406 handler = plugin->create(device, testFormat);-
407#ifdef QIMAGEREADER_DEBUG-
408 qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this data";-
409#endif-
410 break;
never executed: break;
0
411 }-
412 }
never executed: end of block
0
413 }
never executed: end of block
0
414 if (device && !device->isSequential())
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
!device->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
0
415 device->seek(pos);
never executed: device->seek(pos);
0
416 }
never executed: end of block
0
417#endif // QT_NO_IMAGEFORMATPLUGIN-
418-
419 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
autoDetectImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
ignoresFormatAndExtensionDescription
TRUEnever evaluated
FALSEnever evaluated
0
420 // check if any of our built-in handlers recognize the file from its-
421 // contents.-
422 int currentFormat = 0;-
423 if (!suffix.isEmpty()) {
!suffix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
424 // If reading from a file with a suffix, start testing our-
425 // built-in handler for that suffix first.-
426 for (int i = 0; i < _qt_NumFormats; ++i) {
i < _qt_NumFormatsDescription
TRUEnever evaluated
FALSEnever evaluated
0
427 if (_qt_BuiltInFormats[i].extension == suffix) {
_qt_BuiltInFor...sion == suffixDescription
TRUEnever evaluated
FALSEnever evaluated
0
428 currentFormat = i;-
429 break;
never executed: break;
0
430 }-
431 }
never executed: end of block
0
432 }
never executed: end of block
0
433-
434 QByteArray subType;-
435 int numFormats = _qt_NumFormats;-
436 while (device && numFormats >= 0) {
deviceDescription
TRUEnever evaluated
FALSEnever evaluated
numFormats >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
437 const qint64 pos = device->pos();-
438 switch (currentFormat) {-
439#ifndef QT_NO_IMAGEFORMAT_PNG-
440 case _qt_PngFormat:
never executed: case _qt_PngFormat:
0
441 if (QPngHandler::canRead(device))
QPngHandler::canRead(device)Description
TRUEnever evaluated
FALSEnever evaluated
0
442 handler = new QPngHandler;
never executed: handler = new QPngHandler;
0
443 break;
never executed: break;
0
444#endif-
445#ifndef QT_NO_IMAGEFORMAT_JPEG-
446 case _qt_JpgFormat:-
447 case _qt_JpegFormat:-
448 if (QJpegHandler::canRead(device))-
449 handler = new QJpegHandler;-
450 break;-
451#endif-
452#ifdef QT_BUILTIN_GIF_READER-
453 case _qt_GifFormat:-
454 if (QGifHandler::canRead(device))-
455 handler = new QGifHandler;-
456 break;-
457#endif-
458#ifndef QT_NO_IMAGEFORMAT_BMP-
459 case _qt_BmpFormat:
never executed: case _qt_BmpFormat:
0
460 if (QBmpHandler::canRead(device))
QBmpHandler::canRead(device)Description
TRUEnever evaluated
FALSEnever evaluated
0
461 handler = new QBmpHandler;
never executed: handler = new QBmpHandler;
0
462 break;
never executed: break;
0
463#endif-
464#ifndef QT_NO_IMAGEFORMAT_XPM-
465 case _qt_XpmFormat:
never executed: case _qt_XpmFormat:
0
466 if (QXpmHandler::canRead(device))
QXpmHandler::canRead(device)Description
TRUEnever evaluated
FALSEnever evaluated
0
467 handler = new QXpmHandler;
never executed: handler = new QXpmHandler;
0
468 break;
never executed: break;
0
469#endif-
470#ifndef QT_NO_IMAGEFORMAT_PPM-
471 case _qt_PbmFormat:
never executed: case _qt_PbmFormat:
0
472 case _qt_PgmFormat:
never executed: case _qt_PgmFormat:
0
473 case _qt_PpmFormat:
never executed: case _qt_PpmFormat:
0
474 if (QPpmHandler::canRead(device, &subType)) {
QPpmHandler::c...ice, &subType)Description
TRUEnever evaluated
FALSEnever evaluated
0
475 handler = new QPpmHandler;-
476 handler->setOption(QImageIOHandler::SubType, subType);-
477 }
never executed: end of block
0
478 break;
never executed: break;
0
479#endif-
480#ifndef QT_NO_IMAGEFORMAT_XBM-
481 case _qt_XbmFormat:
never executed: case _qt_XbmFormat:
0
482 if (QXbmHandler::canRead(device))
QXbmHandler::canRead(device)Description
TRUEnever evaluated
FALSEnever evaluated
0
483 handler = new QXbmHandler;
never executed: handler = new QXbmHandler;
0
484 break;
never executed: break;
0
485#endif-
486 default:
never executed: default:
0
487 break;
never executed: break;
0
488 }-
489 if (!device->isSequential())
!device->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
0
490 device->seek(pos);
never executed: device->seek(pos);
0
491-
492 if (handler) {
handlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
493#ifdef QIMAGEREADER_DEBUG-
494 qDebug() << "QImageReader::createReadHandler: the" << _qt_BuiltInFormats[currentFormat].extension-
495 << "built-in handler can read this data";-
496#endif-
497 break;
never executed: break;
0
498 }-
499-
500 --numFormats;-
501 ++currentFormat;-
502 currentFormat %= _qt_NumFormats;-
503 }
never executed: end of block
0
504 }
never executed: end of block
0
505-
506 if (!handler) {
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
507#ifdef QIMAGEREADER_DEBUG-
508 qDebug("QImageReader::createReadHandler: no handlers found. giving up.");-
509#endif-
510 // no handler: give up.-
511 return 0;
never executed: return 0;
0
512 }-
513-
514 handler->setDevice(device);-
515 if (!form.isEmpty())
!form.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
516 handler->setFormat(form);
never executed: handler->setFormat(form);
0
517 return handler;
never executed: return handler;
0
518}-
519-
520class QImageReaderPrivate-
521{-
522public:-
523 QImageReaderPrivate(QImageReader *qq);-
524 ~QImageReaderPrivate();-
525-
526 // device-
527 QByteArray format;-
528 bool autoDetectImageFormat;-
529 bool ignoresFormatAndExtension;-
530 QIODevice *device;-
531 bool deleteDevice;-
532 QImageIOHandler *handler;-
533 bool initHandler();-
534-
535 // image options-
536 QRect clipRect;-
537 QSize scaledSize;-
538 QRect scaledClipRect;-
539 int quality;-
540 QMap<QString, QString> text;-
541 void getText();-
542 enum {-
543 UsePluginDefault,-
544 ApplyTransform,-
545 DoNotApplyTransform-
546 } autoTransform;-
547-
548 // error-
549 QImageReader::ImageReaderError imageReaderError;-
550 QString errorString;-
551-
552 QImageReader *q;-
553};-
554-
555/*!-
556 \internal-
557*/-
558QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq)-
559 : autoDetectImageFormat(true), ignoresFormatAndExtension(false)-
560{-
561 device = 0;-
562 deleteDevice = false;-
563 handler = 0;-
564 quality = -1;-
565 imageReaderError = QImageReader::UnknownError;-
566 autoTransform = UsePluginDefault;-
567-
568 q = qq;-
569}
never executed: end of block
0
570-
571/*!-
572 \internal-
573*/-
574QImageReaderPrivate::~QImageReaderPrivate()-
575{-
576 if (deleteDevice)
deleteDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
577 delete device;
never executed: delete device;
0
578 delete handler;-
579}
never executed: end of block
0
580-
581/*!-
582 \internal-
583*/-
584bool QImageReaderPrivate::initHandler()-
585{-
586 // check some preconditions-
587 if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) {
!deviceDescription
TRUEnever evaluated
FALSEnever evaluated
!deleteDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
!device->isOpen()Description
TRUEnever evaluated
FALSEnever evaluated
!device->open(...ice::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0
588 imageReaderError = QImageReader::DeviceError;-
589 errorString = QImageReader::tr("Invalid device");-
590 return false;
never executed: return false;
0
591 }-
592-
593 // probe the file extension-
594 if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) {
deleteDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
!device->isOpen()Description
TRUEnever evaluated
FALSEnever evaluated
!device->open(...ice::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
autoDetectImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
0
595 QList<QByteArray> extensions = QImageReader::supportedImageFormats();-
596 if (!format.isEmpty()) {
!format.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
597 // Try the most probable extension first-
598 int currentFormatIndex = extensions.indexOf(format.toLower());-
599 if (currentFormatIndex > 0)
currentFormatIndex > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
600 extensions.swap(0, currentFormatIndex);
never executed: extensions.swap(0, currentFormatIndex);
0
601 }
never executed: end of block
0
602-
603 int currentExtension = 0;-
604-
605 QFile *file = static_cast<QFile *>(device);-
606 QString fileName = file->fileName();-
607-
608 do {-
609 file->setFileName(fileName + QLatin1Char('.')-
610 + QString::fromLatin1(extensions.at(currentExtension++).constData()));-
611 file->open(QIODevice::ReadOnly);-
612 } while (!file->isOpen() && currentExtension < extensions.size());
never executed: end of block
!file->isOpen()Description
TRUEnever evaluated
FALSEnever evaluated
currentExtensi...ensions.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
613-
614 if (!device->isOpen()) {
!device->isOpen()Description
TRUEnever evaluated
FALSEnever evaluated
0
615 imageReaderError = QImageReader::FileNotFoundError;-
616 errorString = QImageReader::tr("File not found");-
617 file->setFileName(fileName); // restore the old file name-
618 return false;
never executed: return false;
0
619 }-
620 }
never executed: end of block
0
621-
622 // assign a handler-
623 if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
(handler = cre...tension)) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
624 imageReaderError = QImageReader::UnsupportedFormatError;-
625 errorString = QImageReader::tr("Unsupported image format");-
626 return false;
never executed: return false;
0
627 }-
628 return true;
never executed: return true;
0
629}-
630-
631/*!-
632 \internal-
633*/-
634void QImageReaderPrivate::getText()-
635{-
636 if (!text.isEmpty() || (!handler && !initHandler()) || !handler->supportsOption(QImageIOHandler::Description))
!text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!handlerDescription
TRUEnever evaluated
FALSEnever evaluated
!initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
!handler->supp...::Description)Description
TRUEnever evaluated
FALSEnever evaluated
0
637 return;
never executed: return;
0
638 foreach (const QString &pair, handler->option(QImageIOHandler::Description).toString().split(-
639 QLatin1String("\n\n"))) {-
640 int index = pair.indexOf(QLatin1Char(':'));-
641 if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) {
index >= 0Description
TRUEnever evaluated
FALSEnever evaluated
pair.indexOf(Q...(' ')) < indexDescription
TRUEnever evaluated
FALSEnever evaluated
0
642 text.insert(QLatin1String("Description"), pair.simplified());-
643 } else {
never executed: end of block
0
644 QString key = pair.left(index);-
645 text.insert(key, pair.mid(index + 2).simplified());-
646 }
never executed: end of block
0
647 }-
648}
never executed: end of block
0
649-
650/*!-
651 Constructs an empty QImageReader object. Before reading an image,-
652 call setDevice() or setFileName().-
653*/-
654QImageReader::QImageReader()-
655 : d(new QImageReaderPrivate(this))-
656{-
657}
never executed: end of block
0
658-
659/*!-
660 Constructs a QImageReader object with the device \a device and the-
661 image format \a format.-
662*/-
663QImageReader::QImageReader(QIODevice *device, const QByteArray &format)-
664 : d(new QImageReaderPrivate(this))-
665{-
666 d->device = device;-
667 d->format = format;-
668}
never executed: end of block
0
669-
670/*!-
671 Constructs a QImageReader object with the file name \a fileName-
672 and the image format \a format.-
673-
674 \sa setFileName()-
675*/-
676QImageReader::QImageReader(const QString &fileName, const QByteArray &format)-
677 : d(new QImageReaderPrivate(this))-
678{-
679 QFile *file = new QFile(fileName);-
680 d->device = file;-
681 d->deleteDevice = true;-
682 d->format = format;-
683}
never executed: end of block
0
684-
685/*!-
686 Destructs the QImageReader object.-
687*/-
688QImageReader::~QImageReader()-
689{-
690 delete d;-
691}
never executed: end of block
0
692-
693/*!-
694 Sets the format QImageReader will use when reading images, to \a-
695 format. \a format is a case insensitive text string. Example:-
696-
697 \snippet code/src_gui_image_qimagereader.cpp 0-
698-
699 You can call supportedImageFormats() for the full list of formats-
700 QImageReader supports.-
701-
702 \sa format()-
703*/-
704void QImageReader::setFormat(const QByteArray &format)-
705{-
706 d->format = format;-
707}
never executed: end of block
0
708-
709/*!-
710 Returns the format QImageReader uses for reading images.-
711-
712 You can call this function after assigning a device to the-
713 reader to determine the format of the device. For example:-
714-
715 \snippet code/src_gui_image_qimagereader.cpp 1-
716-
717 If the reader cannot read any image from the device (e.g., there is no-
718 image there, or the image has already been read), or if the format is-
719 unsupported, this function returns an empty QByteArray().-
720-
721 \sa setFormat(), supportedImageFormats()-
722*/-
723QByteArray QImageReader::format() const-
724{-
725 if (d->format.isEmpty()) {
d->format.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
726 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
727 return QByteArray();
never executed: return QByteArray();
0
728 return d->handler->canRead() ? d->handler->format() : QByteArray();
never executed: return d->handler->canRead() ? d->handler->format() : QByteArray();
0
729 }-
730-
731 return d->format;
never executed: return d->format;
0
732}-
733-
734/*!-
735 If \a enabled is true, image format autodetection is enabled; otherwise,-
736 it is disabled. By default, autodetection is enabled.-
737-
738 QImageReader uses an extensive approach to detecting the image format;-
739 firstly, if you pass a file name to QImageReader, it will attempt to-
740 detect the file extension if the given file name does not point to an-
741 existing file, by appending supported default extensions to the given file-
742 name, one at a time. It then uses the following approach to detect the-
743 image format:-
744-
745 \list-
746-
747 \li Image plugins are queried first, based on either the optional format-
748 string, or the file name suffix (if the source device is a file). No-
749 content detection is done at this stage. QImageReader will choose the-
750 first plugin that supports reading for this format.-
751-
752 \li If no plugin supports the image format, Qt's built-in handlers are-
753 checked based on either the optional format string, or the file name-
754 suffix.-
755-
756 \li If no capable plugins or built-in handlers are found, each plugin is-
757 tested by inspecting the content of the data stream.-
758-
759 \li If no plugins could detect the image format based on data contents,-
760 each built-in image handler is tested by inspecting the contents.-
761-
762 \li Finally, if all above approaches fail, QImageReader will report failure-
763 when trying to read the image.-
764-
765 \endlist-
766-
767 By disabling image format autodetection, QImageReader will only query the-
768 plugins and built-in handlers based on the format string (i.e., no file-
769 name extensions are tested).-
770-
771 \sa QImageIOHandler::canRead(), QImageIOPlugin::capabilities()-
772*/-
773void QImageReader::setAutoDetectImageFormat(bool enabled)-
774{-
775 d->autoDetectImageFormat = enabled;-
776}
never executed: end of block
0
777-
778/*!-
779 Returns \c true if image format autodetection is enabled on this image-
780 reader; otherwise returns \c false. By default, autodetection is enabled.-
781-
782 \sa setAutoDetectImageFormat()-
783*/-
784bool QImageReader::autoDetectImageFormat() const-
785{-
786 return d->autoDetectImageFormat;
never executed: return d->autoDetectImageFormat;
0
787}-
788-
789-
790/*!-
791 If \a ignored is set to true, then the image reader will ignore-
792 specified formats or file extensions and decide which plugin to-
793 use only based on the contents in the datastream.-
794-
795 Setting this flag means that all image plugins gets loaded. Each-
796 plugin will read the first bytes in the image data and decide if-
797 the plugin is compatible or not.-
798-
799 This also disables auto detecting the image format.-
800-
801 \sa decideFormatFromContent()-
802*/-
803-
804void QImageReader::setDecideFormatFromContent(bool ignored)-
805{-
806 d->ignoresFormatAndExtension = ignored;-
807}
never executed: end of block
0
808-
809-
810/*!-
811 Returns whether the image reader should decide which plugin to use-
812 only based on the contents of the datastream rather than on the file-
813 extension.-
814-
815 \sa setDecideFormatFromContent()-
816*/-
817-
818bool QImageReader::decideFormatFromContent() const-
819{-
820 return d->ignoresFormatAndExtension;
never executed: return d->ignoresFormatAndExtension;
0
821}-
822-
823-
824/*!-
825 Sets QImageReader's device to \a device. If a device has already-
826 been set, the old device is removed from QImageReader and is-
827 otherwise left unchanged.-
828-
829 If the device is not already open, QImageReader will attempt to-
830 open the device in \l QIODevice::ReadOnly mode by calling-
831 open(). Note that this does not work for certain devices, such as-
832 QProcess, QTcpSocket and QUdpSocket, where more logic is required-
833 to open the device.-
834-
835 \sa device(), setFileName()-
836*/-
837void QImageReader::setDevice(QIODevice *device)-
838{-
839 if (d->device && d->deleteDevice)
d->deviceDescription
TRUEnever evaluated
FALSEnever evaluated
d->deleteDeviceDescription
TRUEnever evaluated
FALSEnever evaluated
0
840 delete d->device;
never executed: delete d->device;
0
841 d->device = device;-
842 d->deleteDevice = false;-
843 delete d->handler;-
844 d->handler = 0;-
845 d->text.clear();-
846}
never executed: end of block
0
847-
848/*!-
849 Returns the device currently assigned to QImageReader, or 0 if no-
850 device has been assigned.-
851*/-
852QIODevice *QImageReader::device() const-
853{-
854 return d->device;
never executed: return d->device;
0
855}-
856-
857/*!-
858 Sets the file name of QImageReader to \a fileName. Internally,-
859 QImageReader will create a QFile object and open it in \l-
860 QIODevice::ReadOnly mode, and use this when reading images.-
861-
862 If \a fileName does not include a file extension (e.g., .png or .bmp),-
863 QImageReader will cycle through all supported extensions until it finds-
864 a matching file.-
865-
866 \sa fileName(), setDevice(), supportedImageFormats()-
867*/-
868void QImageReader::setFileName(const QString &fileName)-
869{-
870 setDevice(new QFile(fileName));-
871 d->deleteDevice = true;-
872}
never executed: end of block
0
873-
874/*!-
875 If the currently assigned device is a QFile, or if setFileName()-
876 has been called, this function returns the name of the file-
877 QImageReader reads from. Otherwise (i.e., if no device has been-
878 assigned or the device is not a QFile), an empty QString is-
879 returned.-
880-
881 \sa setFileName(), setDevice()-
882*/-
883QString QImageReader::fileName() const-
884{-
885 QFile *file = qobject_cast<QFile *>(d->device);-
886 return file ? file->fileName() : QString();
never executed: return file ? file->fileName() : QString();
0
887}-
888-
889/*!-
890 \since 4.2-
891-
892 Sets the quality setting of the image format to \a quality.-
893-
894 Some image formats, in particular lossy ones, entail a tradeoff between a)-
895 visual quality of the resulting image, and b) decoding execution time.-
896 This function sets the level of that tradeoff for image formats that-
897 support it.-
898-
899 In case of scaled image reading, the quality setting may also influence the-
900 tradeoff level between visual quality and execution speed of the scaling-
901 algorithm.-
902-
903 The value range of \a quality depends on the image format. For example,-
904 the "jpeg" format supports a quality range from 0 (low visual quality) to-
905 100 (high visual quality).-
906-
907 \sa quality() setScaledSize()-
908*/-
909void QImageReader::setQuality(int quality)-
910{-
911 d->quality = quality;-
912}
never executed: end of block
0
913-
914/*!-
915 \since 4.2-
916-
917 Returns the quality setting of the image format.-
918-
919 \sa setQuality()-
920*/-
921int QImageReader::quality() const-
922{-
923 return d->quality;
never executed: return d->quality;
0
924}-
925-
926-
927/*!-
928 Returns the size of the image, without actually reading the image-
929 contents.-
930-
931 If the image format does not support this feature, this function returns-
932 an invalid size. Qt's built-in image handlers all support this feature,-
933 but custom image format plugins are not required to do so.-
934-
935 \sa QImageIOHandler::ImageOption, QImageIOHandler::option(), QImageIOHandler::supportsOption()-
936*/-
937QSize QImageReader::size() const-
938{-
939 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
940 return QSize();
never executed: return QSize();
0
941-
942 if (d->handler->supportsOption(QImageIOHandler::Size))
d->handler->su...Handler::Size)Description
TRUEnever evaluated
FALSEnever evaluated
0
943 return d->handler->option(QImageIOHandler::Size).toSize();
never executed: return d->handler->option(QImageIOHandler::Size).toSize();
0
944-
945 return QSize();
never executed: return QSize();
0
946}-
947-
948/*!-
949 \since 4.5-
950-
951 Returns the format of the image, without actually reading the image-
952 contents. The format describes the image format \l QImageReader::read()-
953 returns, not the format of the actual image.-
954-
955 If the image format does not support this feature, this function returns-
956 an invalid format.-
957-
958 \sa QImageIOHandler::ImageOption, QImageIOHandler::option(), QImageIOHandler::supportsOption()-
959*/-
960QImage::Format QImageReader::imageFormat() const-
961{-
962 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
963 return QImage::Format_Invalid;
never executed: return QImage::Format_Invalid;
0
964-
965 if (d->handler->supportsOption(QImageIOHandler::ImageFormat))
d->handler->su...::ImageFormat)Description
TRUEnever evaluated
FALSEnever evaluated
0
966 return (QImage::Format)d->handler->option(QImageIOHandler::ImageFormat).toInt();
never executed: return (QImage::Format)d->handler->option(QImageIOHandler::ImageFormat).toInt();
0
967-
968 return QImage::Format_Invalid;
never executed: return QImage::Format_Invalid;
0
969}-
970-
971/*!-
972 \since 4.1-
973-
974 Returns the text keys for this image. You can use-
975 these keys with text() to list the image text for-
976 a certain key.-
977-
978 Support for this option is implemented through-
979 QImageIOHandler::Description.-
980-
981 \sa text(), QImageWriter::setText(), QImage::textKeys()-
982*/-
983QStringList QImageReader::textKeys() const-
984{-
985 d->getText();-
986 return d->text.keys();
never executed: return d->text.keys();
0
987}-
988-
989/*!-
990 \since 4.1-
991-
992 Returns the image text associated with \a key.-
993-
994 Support for this option is implemented through-
995 QImageIOHandler::Description.-
996-
997 \sa textKeys(), QImageWriter::setText()-
998*/-
999QString QImageReader::text(const QString &key) const-
1000{-
1001 d->getText();-
1002 return d->text.value(key);
never executed: return d->text.value(key);
0
1003}-
1004-
1005/*!-
1006 Sets the image clip rect (also known as the ROI, or Region Of-
1007 Interest) to \a rect. The coordinates of \a rect are relative to-
1008 the untransformed image size, as returned by size().-
1009-
1010 \sa clipRect(), setScaledSize(), setScaledClipRect()-
1011*/-
1012void QImageReader::setClipRect(const QRect &rect)-
1013{-
1014 d->clipRect = rect;-
1015}
never executed: end of block
0
1016-
1017/*!-
1018 Returns the clip rect (also known as the ROI, or Region Of-
1019 Interest) of the image. If no clip rect has been set, an invalid-
1020 QRect is returned.-
1021-
1022 \sa setClipRect()-
1023*/-
1024QRect QImageReader::clipRect() const-
1025{-
1026 return d->clipRect;
never executed: return d->clipRect;
0
1027}-
1028-
1029/*!-
1030 Sets the scaled size of the image to \a size. The scaling is-
1031 performed after the initial clip rect, but before the scaled clip-
1032 rect is applied. The algorithm used for scaling depends on the-
1033 image format. By default (i.e., if the image format does not-
1034 support scaling), QImageReader will use QImage::scale() with-
1035 Qt::SmoothScaling.-
1036-
1037 \sa scaledSize(), setClipRect(), setScaledClipRect()-
1038*/-
1039void QImageReader::setScaledSize(const QSize &size)-
1040{-
1041 d->scaledSize = size;-
1042}
never executed: end of block
0
1043-
1044/*!-
1045 Returns the scaled size of the image.-
1046-
1047 \sa setScaledSize()-
1048*/-
1049QSize QImageReader::scaledSize() const-
1050{-
1051 return d->scaledSize;
never executed: return d->scaledSize;
0
1052}-
1053-
1054/*!-
1055 Sets the scaled clip rect to \a rect. The scaled clip rect is the-
1056 clip rect (also known as ROI, or Region Of Interest) that is-
1057 applied after the image has been scaled.-
1058-
1059 \sa scaledClipRect(), setScaledSize()-
1060*/-
1061void QImageReader::setScaledClipRect(const QRect &rect)-
1062{-
1063 d->scaledClipRect = rect;-
1064}
never executed: end of block
0
1065-
1066/*!-
1067 Returns the scaled clip rect of the image.-
1068-
1069 \sa setScaledClipRect()-
1070*/-
1071QRect QImageReader::scaledClipRect() const-
1072{-
1073 return d->scaledClipRect;
never executed: return d->scaledClipRect;
0
1074}-
1075-
1076/*!-
1077 \since 4.1-
1078-
1079 Sets the background color to \a color.-
1080 Image formats that support this operation are expected to-
1081 initialize the background to \a color before reading an image.-
1082-
1083 \sa backgroundColor(), read()-
1084*/-
1085void QImageReader::setBackgroundColor(const QColor &color)-
1086{-
1087 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1088 return;
never executed: return;
0
1089 if (d->handler->supportsOption(QImageIOHandler::BackgroundColor))
d->handler->su...ckgroundColor)Description
TRUEnever evaluated
FALSEnever evaluated
0
1090 d->handler->setOption(QImageIOHandler::BackgroundColor, color);
never executed: d->handler->setOption(QImageIOHandler::BackgroundColor, color);
0
1091}
never executed: end of block
0
1092-
1093/*!-
1094 \since 4.1-
1095-
1096 Returns the background color that's used when reading an image.-
1097 If the image format does not support setting the background color-
1098 an invalid color is returned.-
1099-
1100 \sa setBackgroundColor(), read()-
1101*/-
1102QColor QImageReader::backgroundColor() const-
1103{-
1104 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1105 return QColor();
never executed: return QColor();
0
1106 if (d->handler->supportsOption(QImageIOHandler::BackgroundColor))
d->handler->su...ckgroundColor)Description
TRUEnever evaluated
FALSEnever evaluated
0
1107 return qvariant_cast<QColor>(d->handler->option(QImageIOHandler::BackgroundColor));
never executed: return qvariant_cast<QColor>(d->handler->option(QImageIOHandler::BackgroundColor));
0
1108 return QColor();
never executed: return QColor();
0
1109}-
1110-
1111/*!-
1112 \since 4.1-
1113-
1114 Returns \c true if the image format supports animation;-
1115 otherwise, false is returned.-
1116-
1117 \sa QMovie::supportedFormats()-
1118*/-
1119bool QImageReader::supportsAnimation() const-
1120{-
1121 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1122 return false;
never executed: return false;
0
1123 if (d->handler->supportsOption(QImageIOHandler::Animation))
d->handler->su...er::Animation)Description
TRUEnever evaluated
FALSEnever evaluated
0
1124 return d->handler->option(QImageIOHandler::Animation).toBool();
never executed: return d->handler->option(QImageIOHandler::Animation).toBool();
0
1125 return false;
never executed: return false;
0
1126}-
1127-
1128/*!-
1129 \since 5.4-
1130-
1131 Returns the subtype of the image.-
1132*/-
1133QByteArray QImageReader::subType() const-
1134{-
1135 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1136 return QByteArray();
never executed: return QByteArray();
0
1137-
1138 if (d->handler->supportsOption(QImageIOHandler::SubType))
d->handler->su...dler::SubType)Description
TRUEnever evaluated
FALSEnever evaluated
0
1139 return d->handler->option(QImageIOHandler::SubType).toByteArray();
never executed: return d->handler->option(QImageIOHandler::SubType).toByteArray();
0
1140 return QByteArray();
never executed: return QByteArray();
0
1141}-
1142-
1143/*!-
1144 \since 5.4-
1145-
1146 Returns the list of subtypes supported by an image.-
1147*/-
1148QList<QByteArray> QImageReader::supportedSubTypes() const-
1149{-
1150 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1151 return QList<QByteArray>();
never executed: return QList<QByteArray>();
0
1152-
1153 if (!d->handler->supportsOption(QImageIOHandler::SupportedSubTypes))
!d->handler->s...ortedSubTypes)Description
TRUEnever evaluated
FALSEnever evaluated
0
1154 return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >();
never executed: return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >();
0
1155 return QList<QByteArray>();
never executed: return QList<QByteArray>();
0
1156}-
1157-
1158/*!-
1159 \since 5.5-
1160-
1161 Returns the transformation metadata of the image, including image orientation. If the format-
1162 does not support transformation metadata \c QImageIOHandler::Transformation_None is returned.-
1163-
1164 \sa setAutoTransform(), autoTransform()-
1165*/-
1166QImageIOHandler::Transformations QImageReader::transformation() const-
1167{-
1168 int option = QImageIOHandler::TransformationNone;-
1169 if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::ImageTransformation))
d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
d->handler->su...ransformation)Description
TRUEnever evaluated
FALSEnever evaluated
0
1170 option = d->handler->option(QImageIOHandler::ImageTransformation).toInt();
never executed: option = d->handler->option(QImageIOHandler::ImageTransformation).toInt();
0
1171 return QImageIOHandler::Transformations(option);
never executed: return QImageIOHandler::Transformations(option);
0
1172}-
1173-
1174/*!-
1175 \since 5.5-
1176-
1177 Determines that images returned by read() should have transformation metadata automatically-
1178 applied if \a enabled is \c true.-
1179-
1180 \sa autoTransform(), transformation(), read()-
1181*/-
1182void QImageReader::setAutoTransform(bool enabled)-
1183{-
1184 d->autoTransform = enabled ? QImageReaderPrivate::ApplyTransform
enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1185 : QImageReaderPrivate::DoNotApplyTransform;-
1186}
never executed: end of block
0
1187-
1188/*!-
1189 \since 5.5-
1190-
1191 Returns \c true if the image handler will apply transformation metadata on read().-
1192-
1193 \sa setAutoTransform(), transformation(), read()-
1194*/-
1195bool QImageReader::autoTransform() const-
1196{-
1197 switch (d->autoTransform) {-
1198 case QImageReaderPrivate::ApplyTransform:
never executed: case QImageReaderPrivate::ApplyTransform:
0
1199 return true;
never executed: return true;
0
1200 case QImageReaderPrivate::DoNotApplyTransform:
never executed: case QImageReaderPrivate::DoNotApplyTransform:
0
1201 return false;
never executed: return false;
0
1202 case QImageReaderPrivate::UsePluginDefault:
never executed: case QImageReaderPrivate::UsePluginDefault:
0
1203 if (d->initHandler())
d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1204 return d->handler->supportsOption(QImageIOHandler::TransformedByDefault);
never executed: return d->handler->supportsOption(QImageIOHandler::TransformedByDefault);
0
1205 // no break-
1206 default:
code before this statement never executed: default:
never executed: default:
0
1207 break;
never executed: break;
0
1208 }-
1209 return false;
never executed: return false;
0
1210}-
1211-
1212/*!-
1213 \since 5.6-
1214-
1215 This is an image format specific function that forces images with-
1216 gamma information to be gamma corrected to \a gamma. For image formats-
1217 that do not support gamma correction, this value is ignored.-
1218-
1219 To gamma correct to a standard PC color-space, set gamma to \c 1/2.2.-
1220-
1221 \sa gamma()-
1222*/-
1223void QImageReader::setGamma(float gamma)-
1224{-
1225 if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::Gamma))
d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
d->handler->su...andler::Gamma)Description
TRUEnever evaluated
FALSEnever evaluated
0
1226 d->handler->setOption(QImageIOHandler::Gamma, gamma);
never executed: d->handler->setOption(QImageIOHandler::Gamma, gamma);
0
1227}
never executed: end of block
0
1228-
1229/*!-
1230 \since 5.6-
1231-
1232 Returns the gamma level of the decoded image. If setGamma() has been-
1233 called and gamma correction is supported it will return the gamma set.-
1234 If gamma level is not supported by the image format, \c 0.0 is returned.-
1235-
1236 \sa setGamma()-
1237*/-
1238float QImageReader::gamma() const-
1239{-
1240 if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::Gamma))
d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
d->handler->su...andler::Gamma)Description
TRUEnever evaluated
FALSEnever evaluated
0
1241 return d->handler->option(QImageIOHandler::Gamma).toFloat();
never executed: return d->handler->option(QImageIOHandler::Gamma).toFloat();
0
1242 return 0.0;
never executed: return 0.0;
0
1243}-
1244-
1245/*!-
1246 Returns \c true if an image can be read for the device (i.e., the-
1247 image format is supported, and the device seems to contain valid-
1248 data); otherwise returns \c false.-
1249-
1250 canRead() is a lightweight function that only does a quick test to-
1251 see if the image data is valid. read() may still return false-
1252 after canRead() returns \c true, if the image data is corrupt.-
1253-
1254 For images that support animation, canRead() returns \c false when-
1255 all frames have been read.-
1256-
1257 \sa read(), supportedImageFormats()-
1258*/-
1259bool QImageReader::canRead() const-
1260{-
1261 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1262 return false;
never executed: return false;
0
1263-
1264 return d->handler->canRead();
never executed: return d->handler->canRead();
0
1265}-
1266-
1267/*!-
1268 Reads an image from the device. On success, the image that was-
1269 read is returned; otherwise, a null QImage is returned. You can-
1270 then call error() to find the type of error that occurred, or-
1271 errorString() to get a human readable description of the error.-
1272-
1273 For image formats that support animation, calling read()-
1274 repeatedly will return the next frame. When all frames have been-
1275 read, a null image will be returned.-
1276-
1277 \sa canRead(), supportedImageFormats(), supportsAnimation(), QMovie-
1278*/-
1279QImage QImageReader::read()-
1280{-
1281 // Because failed image reading might have side effects, we explicitly-
1282 // return a null image instead of the image we've just created.-
1283 QImage image;-
1284 return read(&image) ? image : QImage();
never executed: return read(&image) ? image : QImage();
0
1285}-
1286-
1287extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient);-
1288-
1289/*!-
1290 \overload-
1291-
1292 Reads an image from the device into \a image, which must point to a-
1293 QImage. Returns \c true on success; otherwise, returns \c false.-
1294-
1295 If \a image has same format and size as the image data that is about to be-
1296 read, this function may not need to allocate a new image before-
1297 reading. Because of this, it can be faster than the other read() overload,-
1298 which always constructs a new image; especially when reading several-
1299 images with the same format and size.-
1300-
1301 \snippet code/src_gui_image_qimagereader.cpp 2-
1302-
1303 For image formats that support animation, calling read() repeatedly will-
1304 return the next frame. When all frames have been read, a null image will-
1305 be returned.-
1306-
1307 \sa canRead(), supportedImageFormats(), supportsAnimation(), QMovie-
1308*/-
1309bool QImageReader::read(QImage *image)-
1310{-
1311 if (!image) {
!imageDescription
TRUEnever evaluated
FALSEnever evaluated
0
1312 qWarning("QImageReader::read: cannot read into null pointer");-
1313 return false;
never executed: return false;
0
1314 }-
1315-
1316 if (!d->handler && !d->initHandler())
!d->handlerDescription
TRUEnever evaluated
FALSEnever evaluated
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1317 return false;
never executed: return false;
0
1318-
1319 // set the handler specific options.-
1320 if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) {
d->handler->su...r::ScaledSize)Description
TRUEnever evaluated
FALSEnever evaluated
d->scaledSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1321 if ((d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull())
d->handler->su...ler::ClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->clipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1322 || d->clipRect.isNull()) {
d->clipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1323 // Only enable the ScaledSize option if there is no clip rect, or-
1324 // if the handler also supports ClipRect.-
1325 d->handler->setOption(QImageIOHandler::ScaledSize, d->scaledSize);-
1326 }
never executed: end of block
0
1327 }
never executed: end of block
0
1328 if (d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull())
d->handler->su...ler::ClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->clipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1329 d->handler->setOption(QImageIOHandler::ClipRect, d->clipRect);
never executed: d->handler->setOption(QImageIOHandler::ClipRect, d->clipRect);
0
1330 if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull())
d->handler->su...caledClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->scaledClipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1331 d->handler->setOption(QImageIOHandler::ScaledClipRect, d->scaledClipRect);
never executed: d->handler->setOption(QImageIOHandler::ScaledClipRect, d->scaledClipRect);
0
1332 if (d->handler->supportsOption(QImageIOHandler::Quality))
d->handler->su...dler::Quality)Description
TRUEnever evaluated
FALSEnever evaluated
0
1333 d->handler->setOption(QImageIOHandler::Quality, d->quality);
never executed: d->handler->setOption(QImageIOHandler::Quality, d->quality);
0
1334-
1335 // read the image-
1336 if (!d->handler->read(image)) {
!d->handler->read(image)Description
TRUEnever evaluated
FALSEnever evaluated
0
1337 d->imageReaderError = InvalidDataError;-
1338 d->errorString = QImageReader::tr("Unable to read image data");-
1339 return false;
never executed: return false;
0
1340 }-
1341-
1342 // provide default implementations for any unsupported image-
1343 // options-
1344 if (d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull()) {
d->handler->su...ler::ClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->clipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1345 if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) {
d->handler->su...r::ScaledSize)Description
TRUEnever evaluated
FALSEnever evaluated
d->scaledSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1346 if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
d->handler->su...caledClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->scaledClipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1347 // all features are supported by the handler; nothing to do.-
1348 } else {
never executed: end of block
0
1349 // the image is already scaled, so apply scaled clipping.-
1350 if (!d->scaledClipRect.isNull())
!d->scaledClipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1351 *image = image->copy(d->scaledClipRect);
never executed: *image = image->copy(d->scaledClipRect);
0
1352 }
never executed: end of block
0
1353 } else {-
1354 if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
d->handler->su...caledClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->scaledClipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1355 // supports scaled clipping but not scaling, most-
1356 // likely a broken handler.-
1357 } else {
never executed: end of block
0
1358 if (d->scaledSize.isValid()) {
d->scaledSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1359 *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);-
1360 }
never executed: end of block
0
1361 if (d->scaledClipRect.isValid()) {
d->scaledClipRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1362 *image = image->copy(d->scaledClipRect);-
1363 }
never executed: end of block
0
1364 }
never executed: end of block
0
1365 }-
1366 } else {-
1367 if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid() && d->clipRect.isNull()) {
d->handler->su...r::ScaledSize)Description
TRUEnever evaluated
FALSEnever evaluated
d->scaledSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
d->clipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1368 if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
d->handler->su...caledClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->scaledClipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1369 // nothing to do (ClipRect is ignored!)-
1370 } else {
never executed: end of block
0
1371 // provide all workarounds.-
1372 if (d->scaledClipRect.isValid()) {
d->scaledClipRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1373 *image = image->copy(d->scaledClipRect);-
1374 }
never executed: end of block
0
1375 }
never executed: end of block
0
1376 } else {-
1377 if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) {
d->handler->su...caledClipRect)Description
TRUEnever evaluated
FALSEnever evaluated
!d->scaledClipRect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1378 // this makes no sense; a handler that supports-
1379 // ScaledClipRect but not ScaledSize is broken, and we-
1380 // can't work around it.-
1381 } else {
never executed: end of block
0
1382 // provide all workarounds.-
1383 if (d->clipRect.isValid())
d->clipRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1384 *image = image->copy(d->clipRect);
never executed: *image = image->copy(d->clipRect);
0
1385 if (d->scaledSize.isValid())
d->scaledSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1386 *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
never executed: *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
0
1387 if (d->scaledClipRect.isValid())
d->scaledClipRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1388 *image = image->copy(d->scaledClipRect);
never executed: *image = image->copy(d->scaledClipRect);
0
1389 }
never executed: end of block
0
1390 }-
1391 }-
1392-
1393 // successful read; check for "@2x" file name suffix and set device pixel ratio.-
1394 static bool disable2xImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");-
1395 if (!disable2xImageLoading && QFileInfo(fileName()).baseName().endsWith(QLatin1String("@2x"))) {
!disable2xImageLoadingDescription
TRUEnever evaluated
FALSEnever evaluated
QFileInfo(file...String("@2x"))Description
TRUEnever evaluated
FALSEnever evaluated
0
1396 image->setDevicePixelRatio(2.0);-
1397 }
never executed: end of block
0
1398 if (autoTransform())
autoTransform()Description
TRUEnever evaluated
FALSEnever evaluated
0
1399 qt_imageTransform(*image, transformation());
never executed: qt_imageTransform(*image, transformation());
0
1400-
1401 return true;
never executed: return true;
0
1402}-
1403-
1404/*!-
1405 For image formats that support animation, this function steps over the-
1406 current image, returning true if successful or false if there is no-
1407 following image in the animation.-
1408-
1409 The default implementation calls read(), then discards the resulting-
1410 image, but the image handler may have a more efficient way of implementing-
1411 this operation.-
1412-
1413 \sa jumpToImage(), QImageIOHandler::jumpToNextImage()-
1414*/-
1415bool QImageReader::jumpToNextImage()-
1416{-
1417 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1418 return false;
never executed: return false;
0
1419 return d->handler->jumpToNextImage();
never executed: return d->handler->jumpToNextImage();
0
1420}-
1421-
1422/*!-
1423 For image formats that support animation, this function skips to the image-
1424 whose sequence number is \a imageNumber, returning true if successful-
1425 or false if the corresponding image cannot be found.-
1426-
1427 The next call to read() will attempt to read this image.-
1428-
1429 \sa jumpToNextImage(), QImageIOHandler::jumpToImage()-
1430*/-
1431bool QImageReader::jumpToImage(int imageNumber)-
1432{-
1433 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1434 return false;
never executed: return false;
0
1435 return d->handler->jumpToImage(imageNumber);
never executed: return d->handler->jumpToImage(imageNumber);
0
1436}-
1437-
1438/*!-
1439 For image formats that support animation, this function returns the number-
1440 of times the animation should loop. If this function returns -1, it can-
1441 either mean the animation should loop forever, or that an error occurred.-
1442 If an error occurred, canRead() will return false.-
1443-
1444 \sa supportsAnimation(), QImageIOHandler::loopCount(), canRead()-
1445*/-
1446int QImageReader::loopCount() const-
1447{-
1448 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1449 return -1;
never executed: return -1;
0
1450 return d->handler->loopCount();
never executed: return d->handler->loopCount();
0
1451}-
1452-
1453/*!-
1454 For image formats that support animation, this function returns the total-
1455 number of images in the animation. If the format does not support-
1456 animation, 0 is returned.-
1457-
1458 This function returns -1 if an error occurred.-
1459-
1460 \sa supportsAnimation(), QImageIOHandler::imageCount(), canRead()-
1461*/-
1462int QImageReader::imageCount() const-
1463{-
1464 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1465 return -1;
never executed: return -1;
0
1466 return d->handler->imageCount();
never executed: return d->handler->imageCount();
0
1467}-
1468-
1469/*!-
1470 For image formats that support animation, this function returns the number-
1471 of milliseconds to wait until displaying the next frame in the animation.-
1472 If the image format doesn't support animation, 0 is returned.-
1473-
1474 This function returns -1 if an error occurred.-
1475-
1476 \sa supportsAnimation(), QImageIOHandler::nextImageDelay(), canRead()-
1477*/-
1478int QImageReader::nextImageDelay() const-
1479{-
1480 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1481 return -1;
never executed: return -1;
0
1482 return d->handler->nextImageDelay();
never executed: return d->handler->nextImageDelay();
0
1483}-
1484-
1485/*!-
1486 For image formats that support animation, this function returns the-
1487 sequence number of the current frame. If the image format doesn't support-
1488 animation, 0 is returned.-
1489-
1490 This function returns -1 if an error occurred.-
1491-
1492 \sa supportsAnimation(), QImageIOHandler::currentImageNumber(), canRead()-
1493*/-
1494int QImageReader::currentImageNumber() const-
1495{-
1496 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1497 return -1;
never executed: return -1;
0
1498 return d->handler->currentImageNumber();
never executed: return d->handler->currentImageNumber();
0
1499}-
1500-
1501/*!-
1502 For image formats that support animation, this function returns-
1503 the rect for the current frame. Otherwise, a null rect is returned.-
1504-
1505 \sa supportsAnimation(), QImageIOHandler::currentImageRect()-
1506*/-
1507QRect QImageReader::currentImageRect() const-
1508{-
1509 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1510 return QRect();
never executed: return QRect();
0
1511 return d->handler->currentImageRect();
never executed: return d->handler->currentImageRect();
0
1512}-
1513-
1514/*!-
1515 Returns the type of error that occurred last.-
1516-
1517 \sa ImageReaderError, errorString()-
1518*/-
1519QImageReader::ImageReaderError QImageReader::error() const-
1520{-
1521 return d->imageReaderError;
never executed: return d->imageReaderError;
0
1522}-
1523-
1524/*!-
1525 Returns a human readable description of the last error that-
1526 occurred.-
1527-
1528 \sa error()-
1529*/-
1530QString QImageReader::errorString() const-
1531{-
1532 if (d->errorString.isEmpty())
d->errorString.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1533 return QImageReader::tr("Unknown error");
never executed: return QImageReader::tr("Unknown error");
0
1534 return d->errorString;
never executed: return d->errorString;
0
1535}-
1536-
1537/*!-
1538 \since 4.2-
1539-
1540 Returns \c true if the reader supports \a option; otherwise returns-
1541 false.-
1542-
1543 Different image formats support different options. Call this function to-
1544 determine whether a certain option is supported by the current format. For-
1545 example, the PNG format allows you to embed text into the image's metadata-
1546 (see text()), and the BMP format allows you to determine the image's size-
1547 without loading the whole image into memory (see size()).-
1548-
1549 \snippet code/src_gui_image_qimagereader.cpp 3-
1550-
1551 \sa QImageWriter::supportsOption()-
1552*/-
1553bool QImageReader::supportsOption(QImageIOHandler::ImageOption option) const-
1554{-
1555 if (!d->initHandler())
!d->initHandler()Description
TRUEnever evaluated
FALSEnever evaluated
0
1556 return false;
never executed: return false;
0
1557 return d->handler->supportsOption(option);
never executed: return d->handler->supportsOption(option);
0
1558}-
1559-
1560/*!-
1561 If supported, this function returns the image format of the file-
1562 \a fileName. Otherwise, an empty string is returned.-
1563*/-
1564QByteArray QImageReader::imageFormat(const QString &fileName)-
1565{-
1566 QFile file(fileName);-
1567 if (!file.open(QFile::ReadOnly))
!file.open(QFile::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
0
1568 return QByteArray();
never executed: return QByteArray();
0
1569-
1570 return imageFormat(&file);
never executed: return imageFormat(&file);
0
1571}-
1572-
1573/*!-
1574 If supported, this function returns the image format of the device-
1575 \a device. Otherwise, an empty string is returned.-
1576-
1577 \sa QImageReader::autoDetectImageFormat()-
1578*/-
1579QByteArray QImageReader::imageFormat(QIODevice *device)-
1580{-
1581 QByteArray format;-
1582 QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true, false);-
1583 if (handler) {
handlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
1584 if (handler->canRead())
handler->canRead()Description
TRUEnever evaluated
FALSEnever evaluated
0
1585 format = handler->format();
never executed: format = handler->format();
0
1586 delete handler;-
1587 }
never executed: end of block
0
1588 return format;
never executed: return format;
0
1589}-
1590-
1591#ifndef QT_NO_IMAGEFORMATPLUGIN-
1592void supportedImageHandlerFormats(QFactoryLoader *loader,-
1593 QImageIOPlugin::Capability cap,-
1594 QList<QByteArray> *result);-
1595-
1596void supportedImageHandlerMimeTypes(QFactoryLoader *loader,-
1597 QImageIOPlugin::Capability cap,-
1598 QList<QByteArray> *result);-
1599#endif-
1600-
1601/*!-
1602 Returns the list of image formats supported by QImageReader.-
1603-
1604 By default, Qt can read the following formats:-
1605-
1606 \table-
1607 \header \li Format \li MIME type \li Description-
1608 \row \li BMP \li image/bmp \li Windows Bitmap-
1609 \row \li GIF \li image/gif \li Graphic Interchange Format (optional)-
1610 \row \li JPG \li image/jpeg \li Joint Photographic Experts Group-
1611 \row \li PNG \li image/png \li Portable Network Graphics-
1612 \row \li PBM \li image/x-portable-bitmap \li Portable Bitmap-
1613 \row \li PGM \li image/x-portable-graymap \li Portable Graymap-
1614 \row \li PPM \li image/x-portable-pixmap \li Portable Pixmap-
1615 \row \li XBM \li image/x-xbitmap \li X11 Bitmap-
1616 \row \li XPM \li image/x-xpixmap \li X11 Pixmap-
1617 \row \li SVG \li image/svg+xml \li Scalable Vector Graphics-
1618 \endtable-
1619-
1620 Reading and writing SVG files is supported through the \l{Qt SVG} module.-
1621 The \l{Qt Image Formats} module provides support for additional image formats.-
1622-
1623 Note that the QApplication instance must be created before this function is-
1624 called.-
1625-
1626 \sa setFormat(), QImageWriter::supportedImageFormats(), QImageIOPlugin-
1627*/-
1628-
1629QList<QByteArray> QImageReader::supportedImageFormats()-
1630{-
1631 QList<QByteArray> formats;-
1632 formats.reserve(_qt_NumFormats);-
1633 for (int i = 0; i < _qt_NumFormats; ++i)
i < _qt_NumFormatsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1634 formats << _qt_BuiltInFormats[i].extension;
never executed: formats << _qt_BuiltInFormats[i].extension;
0
1635-
1636#ifndef QT_NO_IMAGEFORMATPLUGIN-
1637 supportedImageHandlerFormats(loader(), QImageIOPlugin::CanRead, &formats);-
1638#endif // QT_NO_IMAGEFORMATPLUGIN-
1639-
1640 std::sort(formats.begin(), formats.end());-
1641 formats.erase(std::unique(formats.begin(), formats.end()), formats.end());-
1642 return formats;
never executed: return formats;
0
1643}-
1644-
1645/*!-
1646 Returns the list of MIME types supported by QImageReader.-
1647-
1648 Note that the QApplication instance must be created before this function is-
1649 called.-
1650-
1651 \sa supportedImageFormats(), QImageWriter::supportedMimeTypes()-
1652*/-
1653-
1654QList<QByteArray> QImageReader::supportedMimeTypes()-
1655{-
1656 QList<QByteArray> mimeTypes;-
1657 mimeTypes.reserve(_qt_NumFormats);-
1658 for (int i = 0; i < _qt_NumFormats; ++i)
i < _qt_NumFormatsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1659 mimeTypes << _qt_BuiltInFormats[i].mimeType;
never executed: mimeTypes << _qt_BuiltInFormats[i].mimeType;
0
1660-
1661#ifndef QT_NO_IMAGEFORMATPLUGIN-
1662 supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanRead, &mimeTypes);-
1663#endif // QT_NO_IMAGEFORMATPLUGIN-
1664-
1665 std::sort(mimeTypes.begin(), mimeTypes.end());-
1666 mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end());-
1667 return mimeTypes;
never executed: return mimeTypes;
0
1668}-
1669-
1670QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9