image/qimagereader.cpp

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

Generated by Squish Coco Non-Commercial