| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | | - |
| 41 | | - |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | | - |
| 48 | | - |
| 49 | | - |
| 50 | | - |
| 51 | | - |
| 52 | | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | | - |
| 64 | | - |
| 65 | | - |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | | - |
| 91 | | - |
| 92 | | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | | - |
| 101 | | - |
| 102 | | - |
| 103 | | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | | - |
| 123 | | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | #include "qimagereader.h" | - |
| 130 | | - |
| 131 | #include <qbytearray.h> | - |
| 132 | #ifdef QIMAGEREADER_DEBUG | - |
| 133 | #include <qdebug.h> | - |
| 134 | #endif | - |
| 135 | #include <qfile.h> | - |
| 136 | #include <qfileinfo.h> | - |
| 137 | #include <qimage.h> | - |
| 138 | #include <qimageiohandler.h> | - |
| 139 | #include <qlist.h> | - |
| 140 | #include <qrect.h> | - |
| 141 | #include <qsize.h> | - |
| 142 | #include <qcolor.h> | - |
| 143 | #include <qvariant.h> | - |
| 144 | | - |
| 145 | | - |
| 146 | #include <qcoreapplication.h> | - |
| 147 | #include <private/qfactoryloader_p.h> | - |
| 148 | #include <QMutexLocker> | - |
| 149 | | - |
| 150 | | - |
| 151 | #include <private/qbmphandler_p.h> | - |
| 152 | #include <private/qppmhandler_p.h> | - |
| 153 | #include <private/qxbmhandler_p.h> | - |
| 154 | #include <private/qxpmhandler_p.h> | - |
| 155 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 156 | #include <private/qpnghandler_p.h> | - |
| 157 | #endif | - |
| 158 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 159 | #include <private/qjpeghandler_p.h> | - |
| 160 | #endif | - |
| 161 | #ifdef QT_BUILTIN_GIF_READER | - |
| 162 | #include <private/qgifhandler_p.h> | - |
| 163 | #endif | - |
| 164 | | - |
| 165 | #include <algorithm> | - |
| 166 | | - |
| 167 | QT_BEGIN_NAMESPACE | - |
| 168 | | - |
| 169 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 170 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, | - |
| 171 | (QImageIOHandlerFactoryInterface_iid, QLatin1String("/imageformats"))) | - |
| 172 | #endif | - |
| 173 | | - |
| 174 | enum _qt_BuiltInFormatType { | - |
| 175 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 176 | _qt_PngFormat, | - |
| 177 | #endif | - |
| 178 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 179 | _qt_JpgFormat, | - |
| 180 | _qt_JpegFormat, | - |
| 181 | #endif | - |
| 182 | #ifdef QT_BUILTIN_GIF_READER | - |
| 183 | _qt_GifFormat, | - |
| 184 | #endif | - |
| 185 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 186 | _qt_BmpFormat, | - |
| 187 | #endif | - |
| 188 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 189 | _qt_PpmFormat, | - |
| 190 | _qt_PgmFormat, | - |
| 191 | _qt_PbmFormat, | - |
| 192 | #endif | - |
| 193 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 194 | _qt_XbmFormat, | - |
| 195 | #endif | - |
| 196 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 197 | _qt_XpmFormat, | - |
| 198 | #endif | - |
| 199 | _qt_NumFormats, | - |
| 200 | _qt_NoFormat = -1 | - |
| 201 | }; | - |
| 202 | | - |
| 203 | struct _qt_BuiltInFormatStruct | - |
| 204 | { | - |
| 205 | const char *extension; | - |
| 206 | const char *mimeType; | - |
| 207 | }; | - |
| 208 | | - |
| 209 | static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[] = { | - |
| 210 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 211 | {"png", "image/png"}, | - |
| 212 | #endif | - |
| 213 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 214 | {"jpg", "image/jpeg"}, | - |
| 215 | {"jpeg", "image/jpeg"}, | - |
| 216 | #endif | - |
| 217 | #ifdef QT_BUILTIN_GIF_READER | - |
| 218 | {"gif", "image/gif"}, | - |
| 219 | #endif | - |
| 220 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 221 | {"bmp", "image/bmp"}, | - |
| 222 | #endif | - |
| 223 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 224 | {"ppm", "image/x-portable-pixmap"}, | - |
| 225 | {"pgm", "image/x-portable-graymap"}, | - |
| 226 | {"pbm", "image/x-portable-bitmap"}, | - |
| 227 | #endif | - |
| 228 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 229 | {"xbm", "image/x-xbitmap"}, | - |
| 230 | #endif | - |
| 231 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 232 | {"xpm", "image/x-xpixmap"}, | - |
| 233 | #endif | - |
| 234 | {"", ""} | - |
| 235 | }; | - |
| 236 | | - |
| 237 | static QImageIOHandler *createReadHandlerHelper(QIODevice *device, | - |
| 238 | const QByteArray &format, | - |
| 239 | bool autoDetectImageFormat, | - |
| 240 | bool ignoresFormatAndExtension) | - |
| 241 | { | - |
| 242 | if (!autoDetectImageFormat && format.isEmpty())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 243 | return 0; never executed: return 0; | 0 |
| 244 | | - |
| 245 | QByteArray form = format.toLower(); | - |
| 246 | QImageIOHandler *handler = 0; | - |
| 247 | QByteArray suffix; | - |
| 248 | | - |
| 249 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 250 | static QMutex mutex; | - |
| 251 | QMutexLocker locker(&mutex); | - |
| 252 | | - |
| 253 | typedef QMultiMap<int, QString> PluginKeyMap; | - |
| 254 | | - |
| 255 | | - |
| 256 | QFactoryLoader *l = loader(); | - |
| 257 | const PluginKeyMap keyMap = l->keyMap(); | - |
| 258 | | - |
| 259 | #ifdef QIMAGEREADER_DEBUG | - |
| 260 | qDebug() << "QImageReader::createReadHandler( device =" << (void *)device << ", format =" << format << ")," | - |
| 261 | << keyMap.size() << "plugins available: " << keyMap.values(); | - |
| 262 | #endif | - |
| 263 | | - |
| 264 | int suffixPluginIndex = -1; | - |
| 265 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 266 | | - |
| 267 | if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 268 | | - |
| 269 | | - |
| 270 | | - |
| 271 | if (QFile *file = qobject_cast<QFile *>(device)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 272 | #ifdef QIMAGEREADER_DEBUG | - |
| 273 | qDebug() << "QImageReader::createReadHandler: device is a file:" << file->fileName(); | - |
| 274 | #endif | - |
| 275 | if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 276 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 277 | const int index = keyMap.key(QString::fromLatin1(suffix), -1); | - |
| 278 | if (index != -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 279 | #ifdef QIMAGEREADER_DEBUG | - |
| 280 | qDebug() << "QImageReader::createReadHandler: suffix recognized; the" | - |
| 281 | << suffix << "plugin might be able to read this"; | - |
| 282 | #endif | - |
| 283 | suffixPluginIndex = index; | - |
| 284 | } never executed: end of block | 0 |
| 285 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 286 | } never executed: end of block | 0 |
| 287 | } never executed: end of block | 0 |
| 288 | } never executed: end of block | 0 |
| 289 | | - |
| 290 | QByteArray testFormat = !form.isEmpty() ? form : suffix;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 291 | | - |
| 292 | if (ignoresFormatAndExtension)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 293 | testFormat = QByteArray(); never executed: testFormat = QByteArray(); | 0 |
| 294 | | - |
| 295 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 296 | if (suffixPluginIndex != -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 297 | | - |
| 298 | | - |
| 299 | const qint64 pos = device ? device->pos() : 0;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 300 | const int index = keyMap.key(QString::fromLatin1(suffix), -1); | - |
| 301 | if (index != -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 302 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index)); | - |
| 303 | if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 304 | handler = plugin->create(device, testFormat); | - |
| 305 | #ifdef QIMAGEREADER_DEBUG | - |
| 306 | qDebug() << "QImageReader::createReadHandler: using the" << suffix | - |
| 307 | << "plugin"; | - |
| 308 | #endif | - |
| 309 | } never executed: end of block | 0 |
| 310 | } never executed: end of block | 0 |
| 311 | if (device && !device->isSequential())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 312 | device->seek(pos); never executed: device->seek(pos); | 0 |
| 313 | } never executed: end of block | 0 |
| 314 | | - |
| 315 | if (!handler && !testFormat.isEmpty() && !ignoresFormatAndExtension) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 316 | | - |
| 317 | | - |
| 318 | const qint64 pos = device ? device->pos() : 0;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 319 | | - |
| 320 | if (autoDetectImageFormat) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 321 | const int keyCount = keyMap.size(); | - |
| 322 | for (int i = 0; i < keyCount; ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 323 | if (i != suffixPluginIndex) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 324 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i)); | - |
| 325 | if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 326 | #ifdef QIMAGEREADER_DEBUG | - |
| 327 | qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this format"; | - |
| 328 | #endif | - |
| 329 | handler = plugin->create(device, testFormat); | - |
| 330 | break; never executed: break; | 0 |
| 331 | } | - |
| 332 | } never executed: end of block | 0 |
| 333 | } never executed: end of block | 0 |
| 334 | } else { never executed: end of block | 0 |
| 335 | const int testIndex = keyMap.key(QLatin1String(testFormat), -1); | - |
| 336 | if (testIndex != -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 337 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(testIndex)); | - |
| 338 | if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 339 | #ifdef QIMAGEREADER_DEBUG | - |
| 340 | qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format"; | - |
| 341 | #endif | - |
| 342 | handler = plugin->create(device, testFormat); | - |
| 343 | } never executed: end of block | 0 |
| 344 | } never executed: end of block | 0 |
| 345 | } never executed: end of block | 0 |
| 346 | if (device && !device->isSequential())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 347 | device->seek(pos); never executed: device->seek(pos); | 0 |
| 348 | } never executed: end of block | 0 |
| 349 | | - |
| 350 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 351 | | - |
| 352 | | - |
| 353 | | - |
| 354 | if (!handler && !testFormat.isEmpty()) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 355 | if (false) { dead code: { } | - |
| 356 | #ifndef QT_NO_IMAGEFORMAT_PNG dead code: { } | - |
| 357 | } else if (testFormat == "png") {| TRUE | never evaluated | | FALSE | never evaluated |
dead code: { } | - |
| 358 | handler = new QPngHandler; | - |
| 359 | #endif | - |
| 360 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 361 | } else if (testFormat == "jpg" || testFormat == "jpeg") { | - |
| 362 | handler = new QJpegHandler; | - |
| 363 | #endif | - |
| 364 | #ifdef QT_BUILTIN_GIF_READER | - |
| 365 | } else if (testFormat == "gif") { | - |
| 366 | handler = new QGifHandler; | - |
| 367 | #endif | - |
| 368 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 369 | } else if (testFormat == "bmp") { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 370 | handler = new QBmpHandler; | - |
| 371 | } else if (testFormat == "dib") { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 372 | handler = new QBmpHandler(QBmpHandler::DibFormat); | - |
| 373 | #endif | - |
| 374 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 375 | } else if (testFormat == "xpm") { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 376 | handler = new QXpmHandler; | - |
| 377 | #endif | - |
| 378 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 379 | } else if (testFormat == "xbm") { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 380 | handler = new QXbmHandler; | - |
| 381 | handler->setOption(QImageIOHandler::SubType, testFormat); | - |
| 382 | #endif | - |
| 383 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 384 | } else if (testFormat == "pbm" || testFormat == "pbmraw" || testFormat == "pgm" never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 385 | || testFormat == "pgmraw" || testFormat == "ppm" || testFormat == "ppmraw") {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 386 | handler = new QPpmHandler; | - |
| 387 | handler->setOption(QImageIOHandler::SubType, testFormat); | - |
| 388 | #endif | - |
| 389 | } never executed: end of block | 0 |
| 390 | | - |
| 391 | #ifdef QIMAGEREADER_DEBUG | - |
| 392 | if (handler) | - |
| 393 | qDebug() << "QImageReader::createReadHandler: using the built-in handler for" << testFormat; | - |
| 394 | #endif | - |
| 395 | } never executed: end of block | 0 |
| 396 | | - |
| 397 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 398 | if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 399 | | - |
| 400 | const qint64 pos = device ? device->pos() : 0;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 401 | const int keyCount = keyMap.size(); | - |
| 402 | for (int i = 0; i < keyCount; ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 403 | if (i != suffixPluginIndex) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 404 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i)); | - |
| 405 | if (plugin && plugin->capabilities(device, QByteArray()) & QImageIOPlugin::CanRead) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 406 | handler = plugin->create(device, testFormat); | - |
| 407 | #ifdef QIMAGEREADER_DEBUG | - |
| 408 | qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this data"; | - |
| 409 | #endif | - |
| 410 | break; never executed: break; | 0 |
| 411 | } | - |
| 412 | } never executed: end of block | 0 |
| 413 | } never executed: end of block | 0 |
| 414 | if (device && !device->isSequential())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 415 | device->seek(pos); never executed: device->seek(pos); | 0 |
| 416 | } never executed: end of block | 0 |
| 417 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 418 | | - |
| 419 | if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 420 | | - |
| 421 | | - |
| 422 | int currentFormat = 0; | - |
| 423 | if (!suffix.isEmpty()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 424 | | - |
| 425 | | - |
| 426 | for (int i = 0; i < _qt_NumFormats; ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 427 | if (_qt_BuiltInFormats[i].extension == suffix) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 428 | currentFormat = i; | - |
| 429 | break; never executed: break; | 0 |
| 430 | } | - |
| 431 | } never executed: end of block | 0 |
| 432 | } never executed: end of block | 0 |
| 433 | | - |
| 434 | QByteArray subType; | - |
| 435 | int numFormats = _qt_NumFormats; | - |
| 436 | while (device && numFormats >= 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 437 | const qint64 pos = device->pos(); | - |
| 438 | switch (currentFormat) { | - |
| 439 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 440 | case _qt_PngFormat: never executed: case _qt_PngFormat: | 0 |
| 441 | if (QPngHandler::canRead(device))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 442 | handler = new QPngHandler; never executed: handler = new QPngHandler; | 0 |
| 443 | break; never executed: break; | 0 |
| 444 | #endif | - |
| 445 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 446 | case _qt_JpgFormat: | - |
| 447 | case _qt_JpegFormat: | - |
| 448 | if (QJpegHandler::canRead(device)) | - |
| 449 | handler = new QJpegHandler; | - |
| 450 | break; | - |
| 451 | #endif | - |
| 452 | #ifdef QT_BUILTIN_GIF_READER | - |
| 453 | case _qt_GifFormat: | - |
| 454 | if (QGifHandler::canRead(device)) | - |
| 455 | handler = new QGifHandler; | - |
| 456 | break; | - |
| 457 | #endif | - |
| 458 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 459 | case _qt_BmpFormat: never executed: case _qt_BmpFormat: | 0 |
| 460 | if (QBmpHandler::canRead(device))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 461 | handler = new QBmpHandler; never executed: handler = new QBmpHandler; | 0 |
| 462 | break; never executed: break; | 0 |
| 463 | #endif | - |
| 464 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 465 | case _qt_XpmFormat: never executed: case _qt_XpmFormat: | 0 |
| 466 | if (QXpmHandler::canRead(device))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 467 | handler = new QXpmHandler; never executed: handler = new QXpmHandler; | 0 |
| 468 | break; never executed: break; | 0 |
| 469 | #endif | - |
| 470 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 471 | case _qt_PbmFormat: never executed: case _qt_PbmFormat: | 0 |
| 472 | case _qt_PgmFormat: never executed: case _qt_PgmFormat: | 0 |
| 473 | case _qt_PpmFormat: never executed: case _qt_PpmFormat: | 0 |
| 474 | if (QPpmHandler::canRead(device, &subType)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 475 | handler = new QPpmHandler; | - |
| 476 | handler->setOption(QImageIOHandler::SubType, subType); | - |
| 477 | } never executed: end of block | 0 |
| 478 | break; never executed: break; | 0 |
| 479 | #endif | - |
| 480 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 481 | case _qt_XbmFormat: never executed: case _qt_XbmFormat: | 0 |
| 482 | if (QXbmHandler::canRead(device))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 483 | handler = new QXbmHandler; never executed: handler = new QXbmHandler; | 0 |
| 484 | break; never executed: break; | 0 |
| 485 | #endif | - |
| 486 | default: never executed: default: | 0 |
| 487 | break; never executed: break; | 0 |
| 488 | } | - |
| 489 | if (!device->isSequential())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 490 | device->seek(pos); never executed: device->seek(pos); | 0 |
| 491 | | - |
| 492 | if (handler) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 493 | #ifdef QIMAGEREADER_DEBUG | - |
| 494 | qDebug() << "QImageReader::createReadHandler: the" << _qt_BuiltInFormats[currentFormat].extension | - |
| 495 | << "built-in handler can read this data"; | - |
| 496 | #endif | - |
| 497 | break; never executed: break; | 0 |
| 498 | } | - |
| 499 | | - |
| 500 | --numFormats; | - |
| 501 | ++currentFormat; | - |
| 502 | currentFormat %= _qt_NumFormats; | - |
| 503 | } never executed: end of block | 0 |
| 504 | } never executed: end of block | 0 |
| 505 | | - |
| 506 | if (!handler) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 507 | #ifdef QIMAGEREADER_DEBUG | - |
| 508 | qDebug() << ("QImageReader::createReadHandler: no handlers found. giving up.";); | - |
| 509 | #endif | - |
| 510 | | - |
| 511 | return 0; never executed: return 0; | 0 |
| 512 | } | - |
| 513 | | - |
| 514 | handler->setDevice(device); | - |
| 515 | if (!form.isEmpty())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 516 | handler->setFormat(form); never executed: handler->setFormat(form); | 0 |
| 517 | return handler; never executed: return handler; | 0 |
| 518 | } | - |
| 519 | | - |
| 520 | class QImageReaderPrivate | - |
| 521 | { | - |
| 522 | public: | - |
| 523 | QImageReaderPrivate(QImageReader *qq); | - |
| 524 | ~QImageReaderPrivate(); | - |
| 525 | | - |
| 526 | | - |
| 527 | QByteArray format; | - |
| 528 | bool autoDetectImageFormat; | - |
| 529 | bool ignoresFormatAndExtension; | - |
| 530 | QIODevice *device; | - |
| 531 | bool deleteDevice; | - |
| 532 | QImageIOHandler *handler; | - |
| 533 | bool initHandler(); | - |
| 534 | | - |
| 535 | | - |
| 536 | QRect clipRect; | - |
| 537 | QSize scaledSize; | - |
| 538 | QRect scaledClipRect; | - |
| 539 | int quality; | - |
| 540 | QMap<QString, QString> text; | - |
| 541 | void getText(); | - |
| 542 | enum { | - |
| 543 | UsePluginDefault, | - |
| 544 | ApplyTransform, | - |
| 545 | DoNotApplyTransform | - |
| 546 | } autoTransform; | - |
| 547 | | - |
| 548 | | - |
| 549 | QImageReader::ImageReaderError imageReaderError; | - |
| 550 | QString errorString; | - |
| 551 | | - |
| 552 | QImageReader *q; | - |
| 553 | }; | - |
| 554 | | - |
| 555 | | - |
| 556 | | - |
| 557 | | - |
| 558 | QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq) | - |
| 559 | : autoDetectImageFormat(true), ignoresFormatAndExtension(false) | - |
| 560 | { | - |
| 561 | device = 0; | - |
| 562 | deleteDevice = false; | - |
| 563 | handler = 0; | - |
| 564 | quality = -1; | - |
| 565 | imageReaderError = QImageReader::UnknownError; | - |
| 566 | autoTransform = UsePluginDefault; | - |
| 567 | | - |
| 568 | q = qq; | - |
| 569 | } | - |
| 570 | | - |
| 571 | | - |
| 572 | | - |
| 573 | | - |
| 574 | QImageReaderPrivate::~QImageReaderPrivate() | - |
| 575 | { | - |
| 576 | if (deleteDevice) | - |
| 577 | delete device; | - |
| 578 | delete handler; | - |
| 579 | } | - |
| 580 | | - |
| 581 | | - |
| 582 | | - |
| 583 | | - |
| 584 | bool QImageReaderPrivate::initHandler() | - |
| 585 | { | - |
| 586 | | - |
| 587 | if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) { | - |
| 588 | imageReaderError = QImageReader::DeviceError; | - |
| 589 | errorString = QImageReader::tr("Invalid device"); | - |
| 590 | return false; | - |
| 591 | } | - |
| 592 | | - |
| 593 | | - |
| 594 | if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) { | - |
| 595 | QList<QByteArray> extensions = QImageReader::supportedImageFormats(); | - |
| 596 | if (!format.isEmpty()) { | - |
| 597 | | - |
| 598 | int currentFormatIndex = extensions.indexOf(format.toLower()); | - |
| 599 | if (currentFormatIndex > 0) | - |
| 600 | extensions.swap(0, currentFormatIndex); | - |
| 601 | } | - |
| 602 | | - |
| 603 | int currentExtension = 0; | - |
| 604 | | - |
| 605 | QFile *file = static_cast<QFile *>(device); | - |
| 606 | QString fileName = file->fileName(); | - |
| 607 | | - |
| 608 | do { | - |
| 609 | file->setFileName(fileName + QLatin1Char('.') | - |
| 610 | + QString::fromLatin1(extensions.at(currentExtension++).constData())); | - |
| 611 | file->open(QIODevice::ReadOnly); | - |
| 612 | } while (!file->isOpen() && currentExtension < extensions.size()); | - |
| 613 | | - |
| 614 | if (!device->isOpen()) { | - |
| 615 | imageReaderError = QImageReader::FileNotFoundError; | - |
| 616 | errorString = QImageReader::tr("File not found"); | - |
| 617 | file->setFileName(fileName); | - |
| 618 | return false; | - |
| 619 | } | - |
| 620 | } | - |
| 621 | | - |
| 622 | | - |
| 623 | if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) { | - |
| 624 | imageReaderError = QImageReader::UnsupportedFormatError; | - |
| 625 | errorString = QImageReader::tr("Unsupported image format"); | - |
| 626 | return false; | - |
| 627 | } | - |
| 628 | return true; | - |
| 629 | } | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | | - |
| 634 | void QImageReaderPrivate::getText() | - |
| 635 | { | - |
| 636 | if (!text.isEmpty() || (!handler && !initHandler()) || !handler->supportsOption(QImageIOHandler::Description)) | - |
| 637 | return; | - |
| 638 | foreach (const QString &pair, handler->option(QImageIOHandler::Description).toString().split( | - |
| 639 | QLatin1String("\n\n"))) { | - |
| 640 | int index = pair.indexOf(QLatin1Char(':')); | - |
| 641 | if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) { | - |
| 642 | text.insert(QLatin1String("Description"), pair.simplified()); | - |
| 643 | } else { | - |
| 644 | QString key = pair.left(index); | - |
| 645 | text.insert(key, pair.mid(index + 2).simplified()); | - |
| 646 | } | - |
| 647 | } | - |
| 648 | } | - |
| 649 | | - |
| 650 | | - |
| 651 | | - |
| 652 | | - |
| 653 | | - |
| 654 | QImageReader::QImageReader() | - |
| 655 | : d(new QImageReaderPrivate(this)) | - |
| 656 | { | - |
| 657 | } | - |
| 658 | | - |
| 659 | | - |
| 660 | | - |
| 661 | | - |
| 662 | | - |
| 663 | QImageReader::QImageReader(QIODevice *device, const QByteArray &format) | - |
| 664 | : d(new QImageReaderPrivate(this)) | - |
| 665 | { | - |
| 666 | d->device = device; | - |
| 667 | d->format = format; | - |
| 668 | } | - |
| 669 | | - |
| 670 | | - |
| 671 | | - |
| 672 | | - |
| 673 | | - |
| 674 | | - |
| 675 | | - |
| 676 | QImageReader::QImageReader(const QString &fileName, const QByteArray &format) | - |
| 677 | : d(new QImageReaderPrivate(this)) | - |
| 678 | { | - |
| 679 | QFile *file = new QFile(fileName); | - |
| 680 | d->device = file; | - |
| 681 | d->deleteDevice = true; | - |
| 682 | d->format = format; | - |
| 683 | } | - |
| 684 | | - |
| 685 | | - |
| 686 | | - |
| 687 | | - |
| 688 | QImageReader::~QImageReader() | - |
| 689 | { | - |
| 690 | delete d; | - |
| 691 | } | - |
| 692 | | - |
| 693 | | - |
| 694 | | - |
| 695 | | - |
| 696 | | - |
| 697 | | - |
| 698 | | - |
| 699 | | - |
| 700 | | - |
| 701 | | - |
| 702 | | - |
| 703 | | - |
| 704 | void QImageReader::setFormat(const QByteArray &format) | - |
| 705 | { | - |
| 706 | d->format = format; | - |
| 707 | } | - |
| 708 | | - |
| 709 | | - |
| 710 | | - |
| 711 | | - |
| 712 | | - |
| 713 | | - |
| 714 | | - |
| 715 | | - |
| 716 | | - |
| 717 | | - |
| 718 | | - |
| 719 | | - |
| 720 | | - |
| 721 | | - |
| 722 | | - |
| 723 | QByteArray QImageReader::format() const | - |
| 724 | { | - |
| 725 | if (d->format.isEmpty()) { | - |
| 726 | if (!d->initHandler()) | - |
| 727 | return QByteArray(); | - |
| 728 | return d->handler->canRead() ? d->handler->format() : QByteArray(); | - |
| 729 | } | - |
| 730 | | - |
| 731 | return d->format; | - |
| 732 | } | - |
| 733 | | - |
| 734 | | - |
| 735 | | - |
| 736 | | - |
| 737 | | - |
| 738 | | - |
| 739 | | - |
| 740 | | - |
| 741 | | - |
| 742 | | - |
| 743 | | - |
| 744 | | - |
| 745 | | - |
| 746 | | - |
| 747 | | - |
| 748 | | - |
| 749 | | - |
| 750 | | - |
| 751 | | - |
| 752 | | - |
| 753 | | - |
| 754 | | - |
| 755 | | - |
| 756 | | - |
| 757 | | - |
| 758 | | - |
| 759 | | - |
| 760 | | - |
| 761 | | - |
| 762 | | - |
| 763 | | - |
| 764 | | - |
| 765 | | - |
| 766 | | - |
| 767 | | - |
| 768 | | - |
| 769 | | - |
| 770 | | - |
| 771 | | - |
| 772 | | - |
| 773 | void QImageReader::setAutoDetectImageFormat(bool enabled) | - |
| 774 | { | - |
| 775 | d->autoDetectImageFormat = enabled; | - |
| 776 | } | - |
| 777 | | - |
| 778 | | - |
| 779 | | - |
| 780 | | - |
| 781 | | - |
| 782 | | - |
| 783 | | - |
| 784 | bool QImageReader::autoDetectImageFormat() const | - |
| 785 | { | - |
| 786 | return d->autoDetectImageFormat; | - |
| 787 | } | - |
| 788 | | - |
| 789 | | - |
| 790 | | - |
| 791 | | - |
| 792 | | - |
| 793 | | - |
| 794 | | - |
| 795 | | - |
| 796 | | - |
| 797 | | - |
| 798 | | - |
| 799 | | - |
| 800 | | - |
| 801 | | - |
| 802 | | - |
| 803 | | - |
| 804 | void QImageReader::setDecideFormatFromContent(bool ignored) | - |
| 805 | { | - |
| 806 | d->ignoresFormatAndExtension = ignored; | - |
| 807 | } | - |
| 808 | | - |
| 809 | | - |
| 810 | | - |
| 811 | | - |
| 812 | | - |
| 813 | | - |
| 814 | | - |
| 815 | | - |
| 816 | | - |
| 817 | | - |
| 818 | bool QImageReader::decideFormatFromContent() const | - |
| 819 | { | - |
| 820 | return d->ignoresFormatAndExtension; | - |
| 821 | } | - |
| 822 | | - |
| 823 | | - |
| 824 | | - |
| 825 | | - |
| 826 | | - |
| 827 | | - |
| 828 | | - |
| 829 | | - |
| 830 | | - |
| 831 | | - |
| 832 | | - |
| 833 | | - |
| 834 | | - |
| 835 | | - |
| 836 | | - |
| 837 | void QImageReader::setDevice(QIODevice *device) | - |
| 838 | { | - |
| 839 | if (d->device && d->deleteDevice) | - |
| 840 | delete d->device; | - |
| 841 | d->device = device; | - |
| 842 | d->deleteDevice = false; | - |
| 843 | delete d->handler; | - |
| 844 | d->handler = 0; | - |
| 845 | d->text.clear(); | - |
| 846 | } | - |
| 847 | | - |
| 848 | | - |
| 849 | | - |
| 850 | | - |
| 851 | | - |
| 852 | QIODevice *QImageReader::device() const | - |
| 853 | { | - |
| 854 | return d->device; | - |
| 855 | } | - |
| 856 | | - |
| 857 | | - |
| 858 | | - |
| 859 | | - |
| 860 | | - |
| 861 | | - |
| 862 | | - |
| 863 | | - |
| 864 | | - |
| 865 | | - |
| 866 | | - |
| 867 | | - |
| 868 | void QImageReader::setFileName(const QString &fileName) | - |
| 869 | { | - |
| 870 | setDevice(new QFile(fileName)); | - |
| 871 | d->deleteDevice = true; | - |
| 872 | } | - |
| 873 | | - |
| 874 | | - |
| 875 | | - |
| 876 | | - |
| 877 | | - |
| 878 | | - |
| 879 | | - |
| 880 | | - |
| 881 | | - |
| 882 | | - |
| 883 | QString QImageReader::fileName() const | - |
| 884 | { | - |
| 885 | QFile *file = qobject_cast<QFile *>(d->device); | - |
| 886 | return file ? file->fileName() : QString(); | - |
| 887 | } | - |
| 888 | | - |
| 889 | | - |
| 890 | | - |
| 891 | | - |
| 892 | | - |
| 893 | | - |
| 894 | | - |
| 895 | | - |
| 896 | | - |
| 897 | | - |
| 898 | | - |
| 899 | | - |
| 900 | | - |
| 901 | | - |
| 902 | | - |
| 903 | | - |
| 904 | | - |
| 905 | | - |
| 906 | | - |
| 907 | | - |
| 908 | | - |
| 909 | void QImageReader::setQuality(int quality) | - |
| 910 | { | - |
| 911 | d->quality = quality; | - |
| 912 | } | - |
| 913 | | - |
| 914 | | - |
| 915 | | - |
| 916 | | - |
| 917 | | - |
| 918 | | - |
| 919 | | - |
| 920 | | - |
| 921 | int QImageReader::quality() const | - |
| 922 | { | - |
| 923 | return d->quality; | - |
| 924 | } | - |
| 925 | | - |
| 926 | | - |
| 927 | | - |
| 928 | | - |
| 929 | | - |
| 930 | | - |
| 931 | | - |
| 932 | | - |
| 933 | | - |
| 934 | | - |
| 935 | | - |
| 936 | | - |
| 937 | QSize QImageReader::size() const | - |
| 938 | { | - |
| 939 | if (!d->initHandler()) | - |
| 940 | return QSize(); | - |
| 941 | | - |
| 942 | if (d->handler->supportsOption(QImageIOHandler::Size)) | - |
| 943 | return d->handler->option(QImageIOHandler::Size).toSize(); | - |
| 944 | | - |
| 945 | return QSize(); | - |
| 946 | } | - |
| 947 | | - |
| 948 | | - |
| 949 | | - |
| 950 | | - |
| 951 | | - |
| 952 | | - |
| 953 | | - |
| 954 | | - |
| 955 | | - |
| 956 | | - |
| 957 | | - |
| 958 | | - |
| 959 | | - |
| 960 | QImage::Format QImageReader::imageFormat() const | - |
| 961 | { | - |
| 962 | if (!d->initHandler()) | - |
| 963 | return QImage::Format_Invalid; | - |
| 964 | | - |
| 965 | if (d->handler->supportsOption(QImageIOHandler::ImageFormat)) | - |
| 966 | return (QImage::Format)d->handler->option(QImageIOHandler::ImageFormat).toInt(); | - |
| 967 | | - |
| 968 | return QImage::Format_Invalid; | - |
| 969 | } | - |
| 970 | | - |
| 971 | | - |
| 972 | | - |
| 973 | | - |
| 974 | | - |
| 975 | | - |
| 976 | | - |
| 977 | | - |
| 978 | | - |
| 979 | | - |
| 980 | | - |
| 981 | | - |
| 982 | | - |
| 983 | QStringList QImageReader::textKeys() const | - |
| 984 | { | - |
| 985 | d->getText(); | - |
| 986 | return d->text.keys(); | - |
| 987 | } | - |
| 988 | | - |
| 989 | | - |
| 990 | | - |
| 991 | | - |
| 992 | | - |
| 993 | | - |
| 994 | | - |
| 995 | | - |
| 996 | | - |
| 997 | | - |
| 998 | | - |
| 999 | QString QImageReader::text(const QString &key) const | - |
| 1000 | { | - |
| 1001 | d->getText(); | - |
| 1002 | return d->text.value(key); | - |
| 1003 | } | - |
| 1004 | | - |
| 1005 | | - |
| 1006 | | - |
| 1007 | | - |
| 1008 | | - |
| 1009 | | - |
| 1010 | | - |
| 1011 | | - |
| 1012 | void QImageReader::setClipRect(const QRect &rect) | - |
| 1013 | { | - |
| 1014 | d->clipRect = rect; | - |
| 1015 | } | - |
| 1016 | | - |
| 1017 | | - |
| 1018 | | - |
| 1019 | | - |
| 1020 | | - |
| 1021 | | - |
| 1022 | | - |
| 1023 | | - |
| 1024 | QRect QImageReader::clipRect() const | - |
| 1025 | { | - |
| 1026 | return d->clipRect; | - |
| 1027 | } | - |
| 1028 | | - |
| 1029 | | - |
| 1030 | | - |
| 1031 | | - |
| 1032 | | - |
| 1033 | | - |
| 1034 | | - |
| 1035 | | - |
| 1036 | | - |
| 1037 | | - |
| 1038 | | - |
| 1039 | void QImageReader::setScaledSize(const QSize &size) | - |
| 1040 | { | - |
| 1041 | d->scaledSize = size; | - |
| 1042 | } | - |
| 1043 | | - |
| 1044 | | - |
| 1045 | | - |
| 1046 | | - |
| 1047 | | - |
| 1048 | | - |
| 1049 | QSize QImageReader::scaledSize() const | - |
| 1050 | { | - |
| 1051 | return d->scaledSize; | - |
| 1052 | } | - |
| 1053 | | - |
| 1054 | | - |
| 1055 | | - |
| 1056 | | - |
| 1057 | | - |
| 1058 | | - |
| 1059 | | - |
| 1060 | | - |
| 1061 | void QImageReader::setScaledClipRect(const QRect &rect) | - |
| 1062 | { | - |
| 1063 | d->scaledClipRect = rect; | - |
| 1064 | } | - |
| 1065 | | - |
| 1066 | | - |
| 1067 | | - |
| 1068 | | - |
| 1069 | | - |
| 1070 | | - |
| 1071 | QRect QImageReader::scaledClipRect() const | - |
| 1072 | { | - |
| 1073 | return d->scaledClipRect; | - |
| 1074 | } | - |
| 1075 | | - |
| 1076 | | - |
| 1077 | | - |
| 1078 | | - |
| 1079 | | - |
| 1080 | | - |
| 1081 | | - |
| 1082 | | - |
| 1083 | | - |
| 1084 | | - |
| 1085 | void QImageReader::setBackgroundColor(const QColor &color) | - |
| 1086 | { | - |
| 1087 | if (!d->initHandler()) | - |
| 1088 | return; | - |
| 1089 | if (d->handler->supportsOption(QImageIOHandler::BackgroundColor)) | - |
| 1090 | d->handler->setOption(QImageIOHandler::BackgroundColor, color); | - |
| 1091 | } | - |
| 1092 | | - |
| 1093 | | - |
| 1094 | | - |
| 1095 | | - |
| 1096 | | - |
| 1097 | | - |
| 1098 | | - |
| 1099 | | - |
| 1100 | | - |
| 1101 | | - |
| 1102 | QColor QImageReader::backgroundColor() const | - |
| 1103 | { | - |
| 1104 | if (!d->initHandler()) | - |
| 1105 | return QColor(); | - |
| 1106 | if (d->handler->supportsOption(QImageIOHandler::BackgroundColor)) | - |
| 1107 | return qvariant_cast<QColor>(d->handler->option(QImageIOHandler::BackgroundColor)); | - |
| 1108 | return QColor(); | - |
| 1109 | } | - |
| 1110 | | - |
| 1111 | | - |
| 1112 | | - |
| 1113 | | - |
| 1114 | | - |
| 1115 | | - |
| 1116 | | - |
| 1117 | | - |
| 1118 | | - |
| 1119 | bool QImageReader::supportsAnimation() const | - |
| 1120 | { | - |
| 1121 | if (!d->initHandler()) | - |
| 1122 | return false; | - |
| 1123 | if (d->handler->supportsOption(QImageIOHandler::Animation)) | - |
| 1124 | return d->handler->option(QImageIOHandler::Animation).toBool(); | - |
| 1125 | return false; | - |
| 1126 | } | - |
| 1127 | | - |
| 1128 | | - |
| 1129 | | - |
| 1130 | | - |
| 1131 | | - |
| 1132 | | - |
| 1133 | QByteArray QImageReader::subType() const | - |
| 1134 | { | - |
| 1135 | if (!d->initHandler()) | - |
| 1136 | return QByteArray(); | - |
| 1137 | | - |
| 1138 | if (d->handler->supportsOption(QImageIOHandler::SubType)) | - |
| 1139 | return d->handler->option(QImageIOHandler::SubType).toByteArray(); | - |
| 1140 | return QByteArray(); | - |
| 1141 | } | - |
| 1142 | | - |
| 1143 | | - |
| 1144 | | - |
| 1145 | | - |
| 1146 | | - |
| 1147 | | - |
| 1148 | QList<QByteArray> QImageReader::supportedSubTypes() const | - |
| 1149 | { | - |
| 1150 | if (!d->initHandler()) | - |
| 1151 | return QList<QByteArray>(); | - |
| 1152 | | - |
| 1153 | if (!d->handler->supportsOption(QImageIOHandler::SupportedSubTypes)) | - |
| 1154 | return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >(); | - |
| 1155 | return QList<QByteArray>(); | - |
| 1156 | } | - |
| 1157 | | - |
| 1158 | | - |
| 1159 | | - |
| 1160 | | - |
| 1161 | | - |
| 1162 | | - |
| 1163 | | - |
| 1164 | | - |
| 1165 | | - |
| 1166 | QImageIOHandler::Transformations QImageReader::transformation() const | - |
| 1167 | { | - |
| 1168 | int option = QImageIOHandler::TransformationNone; | - |
| 1169 | if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::ImageTransformation)) | - |
| 1170 | option = d->handler->option(QImageIOHandler::ImageTransformation).toInt(); | - |
| 1171 | return QImageIOHandler::Transformations(option); | - |
| 1172 | } | - |
| 1173 | | - |
| 1174 | | - |
| 1175 | | - |
| 1176 | | - |
| 1177 | | - |
| 1178 | | - |
| 1179 | | - |
| 1180 | | - |
| 1181 | | - |
| 1182 | void QImageReader::setAutoTransform(bool enabled) | - |
| 1183 | { | - |
| 1184 | d->autoTransform = enabled ? QImageReaderPrivate::ApplyTransform | - |
| 1185 | : QImageReaderPrivate::DoNotApplyTransform; | - |
| 1186 | } | - |
| 1187 | | - |
| 1188 | | - |
| 1189 | | - |
| 1190 | | - |
| 1191 | | - |
| 1192 | | - |
| 1193 | | - |
| 1194 | | - |
| 1195 | bool QImageReader::autoTransform() const | - |
| 1196 | { | - |
| 1197 | switch (d->autoTransform) { | - |
| 1198 | case QImageReaderPrivate::ApplyTransform: | - |
| 1199 | return true; | - |
| 1200 | case QImageReaderPrivate::DoNotApplyTransform: | - |
| 1201 | return false; | - |
| 1202 | case QImageReaderPrivate::UsePluginDefault: | - |
| 1203 | if (d->initHandler()) | - |
| 1204 | return d->handler->supportsOption(QImageIOHandler::TransformedByDefault); | - |
| 1205 | | - |
| 1206 | default: | - |
| 1207 | break; | - |
| 1208 | } | - |
| 1209 | return false; | - |
| 1210 | } | - |
| 1211 | | - |
| 1212 | | - |
| 1213 | | - |
| 1214 | | - |
| 1215 | | - |
| 1216 | | - |
| 1217 | | - |
| 1218 | | - |
| 1219 | | - |
| 1220 | | - |
| 1221 | | - |
| 1222 | | - |
| 1223 | void QImageReader::setGamma(float gamma) | - |
| 1224 | { | - |
| 1225 | if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::Gamma)) | - |
| 1226 | d->handler->setOption(QImageIOHandler::Gamma, gamma); | - |
| 1227 | } | - |
| 1228 | | - |
| 1229 | | - |
| 1230 | | - |
| 1231 | | - |
| 1232 | | - |
| 1233 | | - |
| 1234 | | - |
| 1235 | | - |
| 1236 | | - |
| 1237 | | - |
| 1238 | float QImageReader::gamma() const | - |
| 1239 | { | - |
| 1240 | if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::Gamma)) | - |
| 1241 | return d->handler->option(QImageIOHandler::Gamma).toFloat(); | - |
| 1242 | return 0.0; | - |
| 1243 | } | - |
| 1244 | | - |
| 1245 | | - |
| 1246 | | - |
| 1247 | | - |
| 1248 | | - |
| 1249 | | - |
| 1250 | | - |
| 1251 | | - |
| 1252 | | - |
| 1253 | | - |
| 1254 | | - |
| 1255 | | - |
| 1256 | | - |
| 1257 | | - |
| 1258 | | - |
| 1259 | bool QImageReader::canRead() const | - |
| 1260 | { | - |
| 1261 | if (!d->initHandler()) | - |
| 1262 | return false; | - |
| 1263 | | - |
| 1264 | return d->handler->canRead(); | - |
| 1265 | } | - |
| 1266 | | - |
| 1267 | | - |
| 1268 | | - |
| 1269 | | - |
| 1270 | | - |
| 1271 | | - |
| 1272 | | - |
| 1273 | | - |
| 1274 | | - |
| 1275 | | - |
| 1276 | | - |
| 1277 | | - |
| 1278 | | - |
| 1279 | QImage QImageReader::read() | - |
| 1280 | { | - |
| 1281 | | - |
| 1282 | | - |
| 1283 | QImage image; | - |
| 1284 | return read(&image) ? image : QImage(); | - |
| 1285 | } | - |
| 1286 | | - |
| 1287 | extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient); | - |
| 1288 | | - |
| 1289 | | - |
| 1290 | | - |
| 1291 | | - |
| 1292 | | - |
| 1293 | | - |
| 1294 | | - |
| 1295 | | - |
| 1296 | | - |
| 1297 | | - |
| 1298 | | - |
| 1299 | | - |
| 1300 | | - |
| 1301 | | - |
| 1302 | | - |
| 1303 | | - |
| 1304 | | - |
| 1305 | | - |
| 1306 | | - |
| 1307 | | - |
| 1308 | | - |
| 1309 | bool QImageReader::read(QImage *image) | - |
| 1310 | { | - |
| 1311 | if (!image) { | - |
| 1312 | qWarning("QImageReader::read: cannot read into null pointer"); | - |
| 1313 | return false; | - |
| 1314 | } | - |
| 1315 | | - |
| 1316 | if (!d->handler && !d->initHandler()) | - |
| 1317 | return false; | - |
| 1318 | | - |
| 1319 | | - |
| 1320 | if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) { | - |
| 1321 | if ((d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull()) | - |
| 1322 | || d->clipRect.isNull()) { | - |
| 1323 | | - |
| 1324 | | - |
| 1325 | d->handler->setOption(QImageIOHandler::ScaledSize, d->scaledSize); | - |
| 1326 | } | - |
| 1327 | } | - |
| 1328 | if (d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull()) | - |
| 1329 | d->handler->setOption(QImageIOHandler::ClipRect, d->clipRect); | - |
| 1330 | if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) | - |
| 1331 | d->handler->setOption(QImageIOHandler::ScaledClipRect, d->scaledClipRect); | - |
| 1332 | if (d->handler->supportsOption(QImageIOHandler::Quality)) | - |
| 1333 | d->handler->setOption(QImageIOHandler::Quality, d->quality); | - |
| 1334 | | - |
| 1335 | | - |
| 1336 | if (!d->handler->read(image)) { | - |
| 1337 | d->imageReaderError = InvalidDataError; | - |
| 1338 | d->errorString = QImageReader::tr("Unable to read image data"); | - |
| 1339 | return false; | - |
| 1340 | } | - |
| 1341 | | - |
| 1342 | | - |
| 1343 | | - |
| 1344 | if (d->handler->supportsOption(QImageIOHandler::ClipRect) && !d->clipRect.isNull()) { | - |
| 1345 | if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid()) { | - |
| 1346 | if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) { | - |
| 1347 | | - |
| 1348 | } else { | - |
| 1349 | | - |
| 1350 | if (!d->scaledClipRect.isNull()) | - |
| 1351 | *image = image->copy(d->scaledClipRect); | - |
| 1352 | } | - |
| 1353 | } else { | - |
| 1354 | if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) { | - |
| 1355 | | - |
| 1356 | | - |
| 1357 | } else { | - |
| 1358 | if (d->scaledSize.isValid()) { | - |
| 1359 | *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | - |
| 1360 | } | - |
| 1361 | if (d->scaledClipRect.isValid()) { | - |
| 1362 | *image = image->copy(d->scaledClipRect); | - |
| 1363 | } | - |
| 1364 | } | - |
| 1365 | } | - |
| 1366 | } else { | - |
| 1367 | if (d->handler->supportsOption(QImageIOHandler::ScaledSize) && d->scaledSize.isValid() && d->clipRect.isNull()) { | - |
| 1368 | if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) { | - |
| 1369 | | - |
| 1370 | } else { | - |
| 1371 | | - |
| 1372 | if (d->scaledClipRect.isValid()) { | - |
| 1373 | *image = image->copy(d->scaledClipRect); | - |
| 1374 | } | - |
| 1375 | } | - |
| 1376 | } else { | - |
| 1377 | if (d->handler->supportsOption(QImageIOHandler::ScaledClipRect) && !d->scaledClipRect.isNull()) { | - |
| 1378 | | - |
| 1379 | | - |
| 1380 | | - |
| 1381 | } else { | - |
| 1382 | | - |
| 1383 | if (d->clipRect.isValid()) | - |
| 1384 | *image = image->copy(d->clipRect); | - |
| 1385 | if (d->scaledSize.isValid()) | - |
| 1386 | *image = image->scaled(d->scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | - |
| 1387 | if (d->scaledClipRect.isValid()) | - |
| 1388 | *image = image->copy(d->scaledClipRect); | - |
| 1389 | } | - |
| 1390 | } | - |
| 1391 | } | - |
| 1392 | | - |
| 1393 | | - |
| 1394 | static bool disable2xImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING"); | - |
| 1395 | if (!disable2xImageLoading && QFileInfo(fileName()).baseName().endsWith(QLatin1String("@2x"))) { | - |
| 1396 | image->setDevicePixelRatio(2.0); | - |
| 1397 | } | - |
| 1398 | if (autoTransform()) | - |
| 1399 | qt_imageTransform(*image, transformation()); | - |
| 1400 | | - |
| 1401 | return true; | - |
| 1402 | } | - |
| 1403 | | - |
| 1404 | | - |
| 1405 | | - |
| 1406 | | - |
| 1407 | | - |
| 1408 | | - |
| 1409 | | - |
| 1410 | | - |
| 1411 | | - |
| 1412 | | - |
| 1413 | | - |
| 1414 | | - |
| 1415 | bool QImageReader::jumpToNextImage() | - |
| 1416 | { | - |
| 1417 | if (!d->initHandler()) | - |
| 1418 | return false; | - |
| 1419 | return d->handler->jumpToNextImage(); | - |
| 1420 | } | - |
| 1421 | | - |
| 1422 | | - |
| 1423 | | - |
| 1424 | | - |
| 1425 | | - |
| 1426 | | - |
| 1427 | | - |
| 1428 | | - |
| 1429 | | - |
| 1430 | | - |
| 1431 | bool QImageReader::jumpToImage(int imageNumber) | - |
| 1432 | { | - |
| 1433 | if (!d->initHandler()) | - |
| 1434 | return false; | - |
| 1435 | return d->handler->jumpToImage(imageNumber); | - |
| 1436 | } | - |
| 1437 | | - |
| 1438 | | - |
| 1439 | | - |
| 1440 | | - |
| 1441 | | - |
| 1442 | | - |
| 1443 | | - |
| 1444 | | - |
| 1445 | | - |
| 1446 | int QImageReader::loopCount() const | - |
| 1447 | { | - |
| 1448 | if (!d->initHandler()) | - |
| 1449 | return -1; | - |
| 1450 | return d->handler->loopCount(); | - |
| 1451 | } | - |
| 1452 | | - |
| 1453 | | - |
| 1454 | | - |
| 1455 | | - |
| 1456 | | - |
| 1457 | | - |
| 1458 | | - |
| 1459 | | - |
| 1460 | | - |
| 1461 | | - |
| 1462 | int QImageReader::imageCount() const | - |
| 1463 | { | - |
| 1464 | if (!d->initHandler()) | - |
| 1465 | return -1; | - |
| 1466 | return d->handler->imageCount(); | - |
| 1467 | } | - |
| 1468 | | - |
| 1469 | | - |
| 1470 | | - |
| 1471 | | - |
| 1472 | | - |
| 1473 | | - |
| 1474 | | - |
| 1475 | | - |
| 1476 | | - |
| 1477 | | - |
| 1478 | int QImageReader::nextImageDelay() const | - |
| 1479 | { | - |
| 1480 | if (!d->initHandler()) | - |
| 1481 | return -1; | - |
| 1482 | return d->handler->nextImageDelay(); | - |
| 1483 | } | - |
| 1484 | | - |
| 1485 | | - |
| 1486 | | - |
| 1487 | | - |
| 1488 | | - |
| 1489 | | - |
| 1490 | | - |
| 1491 | | - |
| 1492 | | - |
| 1493 | | - |
| 1494 | int QImageReader::currentImageNumber() const | - |
| 1495 | { | - |
| 1496 | if (!d->initHandler()) | - |
| 1497 | return -1; | - |
| 1498 | return d->handler->currentImageNumber(); | - |
| 1499 | } | - |
| 1500 | | - |
| 1501 | | - |
| 1502 | | - |
| 1503 | | - |
| 1504 | | - |
| 1505 | | - |
| 1506 | | - |
| 1507 | QRect QImageReader::currentImageRect() const | - |
| 1508 | { | - |
| 1509 | if (!d->initHandler()) | - |
| 1510 | return QRect(); | - |
| 1511 | return d->handler->currentImageRect(); | - |
| 1512 | } | - |
| 1513 | | - |
| 1514 | | - |
| 1515 | | - |
| 1516 | | - |
| 1517 | | - |
| 1518 | | - |
| 1519 | QImageReader::ImageReaderError QImageReader::error() const | - |
| 1520 | { | - |
| 1521 | return d->imageReaderError; | - |
| 1522 | } | - |
| 1523 | | - |
| 1524 | | - |
| 1525 | | - |
| 1526 | | - |
| 1527 | | - |
| 1528 | | - |
| 1529 | | - |
| 1530 | QString QImageReader::errorString() const | - |
| 1531 | { | - |
| 1532 | if (d->errorString.isEmpty()) | - |
| 1533 | return QImageReader::tr("Unknown error"); | - |
| 1534 | return d->errorString; | - |
| 1535 | } | - |
| 1536 | | - |
| 1537 | | - |
| 1538 | | - |
| 1539 | | - |
| 1540 | | - |
| 1541 | | - |
| 1542 | | - |
| 1543 | | - |
| 1544 | | - |
| 1545 | | - |
| 1546 | | - |
| 1547 | | - |
| 1548 | | - |
| 1549 | | - |
| 1550 | | - |
| 1551 | | - |
| 1552 | | - |
| 1553 | bool QImageReader::supportsOption(QImageIOHandler::ImageOption option) const | - |
| 1554 | { | - |
| 1555 | if (!d->initHandler()) | - |
| 1556 | return false; | - |
| 1557 | return d->handler->supportsOption(option); | - |
| 1558 | } | - |
| 1559 | | - |
| 1560 | | - |
| 1561 | | - |
| 1562 | | - |
| 1563 | | - |
| 1564 | QByteArray QImageReader::imageFormat(const QString &fileName) | - |
| 1565 | { | - |
| 1566 | QFile file(fileName); | - |
| 1567 | if (!file.open(QFile::ReadOnly)) | - |
| 1568 | return QByteArray(); | - |
| 1569 | | - |
| 1570 | return imageFormat(&file); | - |
| 1571 | } | - |
| 1572 | | - |
| 1573 | | - |
| 1574 | | - |
| 1575 | | - |
| 1576 | | - |
| 1577 | | - |
| 1578 | | - |
| 1579 | QByteArray QImageReader::imageFormat(QIODevice *device) | - |
| 1580 | { | - |
| 1581 | QByteArray format; | - |
| 1582 | QImageIOHandler *handler = createReadHandlerHelper(device, format, true, false); | - |
| 1583 | if (handler) { | - |
| 1584 | if (handler->canRead()) | - |
| 1585 | format = handler->format(); | - |
| 1586 | delete handler; | - |
| 1587 | } | - |
| 1588 | return format; | - |
| 1589 | } | - |
| 1590 | | - |
| 1591 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 1592 | void supportedImageHandlerFormats(QFactoryLoader *loader, | - |
| 1593 | QImageIOPlugin::Capability cap, | - |
| 1594 | QList<QByteArray> *result); | - |
| 1595 | | - |
| 1596 | void supportedImageHandlerMimeTypes(QFactoryLoader *loader, | - |
| 1597 | QImageIOPlugin::Capability cap, | - |
| 1598 | QList<QByteArray> *result); | - |
| 1599 | #endif | - |
| 1600 | | - |
| 1601 | | - |
| 1602 | | - |
| 1603 | | - |
| 1604 | | - |
| 1605 | | - |
| 1606 | | - |
| 1607 | | - |
| 1608 | | - |
| 1609 | | - |
| 1610 | | - |
| 1611 | | - |
| 1612 | | - |
| 1613 | | - |
| 1614 | | - |
| 1615 | | - |
| 1616 | | - |
| 1617 | | - |
| 1618 | | - |
| 1619 | | - |
| 1620 | | - |
| 1621 | | - |
| 1622 | | - |
| 1623 | | - |
| 1624 | | - |
| 1625 | | - |
| 1626 | | - |
| 1627 | | - |
| 1628 | | - |
| 1629 | QList<QByteArray> QImageReader::supportedImageFormats() | - |
| 1630 | { | - |
| 1631 | QList<QByteArray> formats; | - |
| 1632 | formats.reserve(_qt_NumFormats); | - |
| 1633 | for (int i = 0; i < _qt_NumFormats; ++i) | - |
| 1634 | formats << _qt_BuiltInFormats[i].extension; | - |
| 1635 | | - |
| 1636 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 1637 | supportedImageHandlerFormats(loader(), QImageIOPlugin::CanRead, &formats); | - |
| 1638 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 1639 | | - |
| 1640 | std::sort(formats.begin(), formats.end()); | - |
| 1641 | formats.erase(std::unique(formats.begin(), formats.end()), formats.end()); | - |
| 1642 | return formats; | - |
| 1643 | } | - |
| 1644 | | - |
| 1645 | | - |
| 1646 | | - |
| 1647 | | - |
| 1648 | | - |
| 1649 | | - |
| 1650 | | - |
| 1651 | | - |
| 1652 | | - |
| 1653 | | - |
| 1654 | QList<QByteArray> QImageReader::supportedMimeTypes() | - |
| 1655 | { | - |
| 1656 | QList<QByteArray> mimeTypes; | - |
| 1657 | mimeTypes.reserve(_qt_NumFormats); | - |
| 1658 | for (int i = 0; i < _qt_NumFormats; ++i) | - |
| 1659 | mimeTypes << _qt_BuiltInFormats[i].mimeType; | - |
| 1660 | | - |
| 1661 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 1662 | supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanRead, &mimeTypes); | - |
| 1663 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 1664 | | - |
| 1665 | std::sort(mimeTypes.begin(), mimeTypes.end()); | - |
| 1666 | mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end()); | - |
| 1667 | return mimeTypes; | - |
| 1668 | } | - |
| 1669 | | - |
| 1670 | QT_END_NAMESPACE | - |
| | |