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