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