| 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 | #include "qimagewriter.h" | - |
| 96 | | - |
| 97 | #include <qbytearray.h> | - |
| 98 | #include <qfile.h> | - |
| 99 | #include <qfileinfo.h> | - |
| 100 | #include <qimage.h> | - |
| 101 | #include <qimageiohandler.h> | - |
| 102 | #include <qjsonarray.h> | - |
| 103 | #include <qset.h> | - |
| 104 | #include <qvariant.h> | - |
| 105 | | - |
| 106 | | - |
| 107 | #include <qcoreapplication.h> | - |
| 108 | #include <private/qfactoryloader_p.h> | - |
| 109 | | - |
| 110 | | - |
| 111 | #include <private/qbmphandler_p.h> | - |
| 112 | #include <private/qppmhandler_p.h> | - |
| 113 | #include <private/qxbmhandler_p.h> | - |
| 114 | #include <private/qxpmhandler_p.h> | - |
| 115 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 116 | #include <private/qpnghandler_p.h> | - |
| 117 | #endif | - |
| 118 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 119 | #include <private/qjpeghandler_p.h> | - |
| 120 | #endif | - |
| 121 | #ifdef QT_BUILTIN_GIF_READER | - |
| 122 | #include <private/qgifhandler_p.h> | - |
| 123 | #endif | - |
| 124 | | - |
| 125 | #include <algorithm> | - |
| 126 | | - |
| 127 | QT_BEGIN_NAMESPACE | - |
| 128 | | - |
| 129 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 130 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, | - |
| 131 | (QImageIOHandlerFactoryInterface_iid, QLatin1String("/imageformats"))) | - |
| 132 | #endif | - |
| 133 | | - |
| 134 | static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, | - |
| 135 | const QByteArray &format) | - |
| 136 | { | - |
| 137 | QByteArray form = format.toLower(); | - |
| 138 | QByteArray suffix; | - |
| 139 | QImageIOHandler *handler = 0; | - |
| 140 | | - |
| 141 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 142 | typedef QMultiMap<int, QString> PluginKeyMap; | - |
| 143 | | - |
| 144 | | - |
| 145 | QFactoryLoader *l = loader(); | - |
| 146 | const PluginKeyMap keyMap = l->keyMap(); | - |
| 147 | int suffixPluginIndex = -1; | - |
| 148 | #endif | - |
| 149 | | - |
| 150 | if (device && format.isEmpty()) { | - |
| 151 | | - |
| 152 | | - |
| 153 | | - |
| 154 | if (QFile *file = qobject_cast<QFile *>(device)) { | - |
| 155 | if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) { | - |
| 156 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 157 | const int index = keyMap.key(QString::fromLatin1(suffix), -1); | - |
| 158 | if (index != -1) | - |
| 159 | suffixPluginIndex = index; | - |
| 160 | #endif | - |
| 161 | } | - |
| 162 | } | - |
| 163 | } | - |
| 164 | | - |
| 165 | QByteArray testFormat = !form.isEmpty() ? form : suffix; | - |
| 166 | | - |
| 167 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 168 | if (suffixPluginIndex != -1) { | - |
| 169 | | - |
| 170 | | - |
| 171 | const int index = keyMap.key(QString::fromLatin1(suffix), -1); | - |
| 172 | if (index != -1) { | - |
| 173 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index)); | - |
| 174 | if (plugin && (plugin->capabilities(device, suffix) & QImageIOPlugin::CanWrite)) | - |
| 175 | handler = plugin->create(device, suffix); | - |
| 176 | } | - |
| 177 | } | - |
| 178 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 179 | | - |
| 180 | | - |
| 181 | if (!handler && !testFormat.isEmpty()) { | - |
| 182 | if (false) { dead code: { } | - |
| 183 | #ifndef QT_NO_IMAGEFORMAT_PNG dead code: { } | - |
| 184 | } else if (testFormat == "png") { dead code: { } | - |
| 185 | handler = new QPngHandler; | - |
| 186 | #endif | - |
| 187 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 188 | } else if (testFormat == "jpg" || testFormat == "jpeg") { | - |
| 189 | handler = new QJpegHandler; | - |
| 190 | #endif | - |
| 191 | #ifdef QT_BUILTIN_GIF_READER | - |
| 192 | } else if (testFormat == "gif") { | - |
| 193 | handler = new QGifHandler; | - |
| 194 | #endif | - |
| 195 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 196 | } else if (testFormat == "bmp") { | - |
| 197 | handler = new QBmpHandler; | - |
| 198 | } else if (testFormat == "dib") { | - |
| 199 | handler = new QBmpHandler(QBmpHandler::DibFormat); | - |
| 200 | #endif | - |
| 201 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 202 | } else if (testFormat == "xpm") { | - |
| 203 | handler = new QXpmHandler; | - |
| 204 | #endif | - |
| 205 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 206 | } else if (testFormat == "xbm") { | - |
| 207 | handler = new QXbmHandler; | - |
| 208 | handler->setOption(QImageIOHandler::SubType, testFormat); | - |
| 209 | #endif | - |
| 210 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 211 | } else if (testFormat == "pbm" || testFormat == "pbmraw" || testFormat == "pgm" | - |
| 212 | || testFormat == "pgmraw" || testFormat == "ppm" || testFormat == "ppmraw") { | - |
| 213 | handler = new QPpmHandler; | - |
| 214 | handler->setOption(QImageIOHandler::SubType, testFormat); | - |
| 215 | #endif | - |
| 216 | } | - |
| 217 | } | - |
| 218 | | - |
| 219 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 220 | if (!testFormat.isEmpty()) { | - |
| 221 | const int keyCount = keyMap.size(); | - |
| 222 | for (int i = 0; i < keyCount; ++i) { | - |
| 223 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i)); | - |
| 224 | if (plugin && (plugin->capabilities(device, testFormat) & QImageIOPlugin::CanWrite)) { | - |
| 225 | delete handler; | - |
| 226 | handler = plugin->create(device, testFormat); | - |
| 227 | break; | - |
| 228 | } | - |
| 229 | } | - |
| 230 | } | - |
| 231 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 232 | | - |
| 233 | if (!handler) | - |
| 234 | return 0; | - |
| 235 | | - |
| 236 | handler->setDevice(device); | - |
| 237 | if (!testFormat.isEmpty()) | - |
| 238 | handler->setFormat(testFormat); | - |
| 239 | return handler; | - |
| 240 | } | - |
| 241 | | - |
| 242 | class QImageWriterPrivate | - |
| 243 | { | - |
| 244 | public: | - |
| 245 | QImageWriterPrivate(QImageWriter *qq); | - |
| 246 | | - |
| 247 | bool canWriteHelper(); | - |
| 248 | | - |
| 249 | | - |
| 250 | QByteArray format; | - |
| 251 | QIODevice *device; | - |
| 252 | bool deleteDevice; | - |
| 253 | QImageIOHandler *handler; | - |
| 254 | | - |
| 255 | | - |
| 256 | int quality; | - |
| 257 | int compression; | - |
| 258 | float gamma; | - |
| 259 | QString description; | - |
| 260 | QString text; | - |
| 261 | QByteArray subType; | - |
| 262 | bool optimizedWrite; | - |
| 263 | bool progressiveScanWrite; | - |
| 264 | QImageIOHandler::Transformations transformation; | - |
| 265 | | - |
| 266 | | - |
| 267 | QImageWriter::ImageWriterError imageWriterError; | - |
| 268 | QString errorString; | - |
| 269 | | - |
| 270 | QImageWriter *q; | - |
| 271 | }; | - |
| 272 | | - |
| 273 | | - |
| 274 | | - |
| 275 | | - |
| 276 | QImageWriterPrivate::QImageWriterPrivate(QImageWriter *qq) | - |
| 277 | { | - |
| 278 | device = 0; | - |
| 279 | deleteDevice = false; | - |
| 280 | handler = 0; | - |
| 281 | quality = -1; | - |
| 282 | compression = 0; | - |
| 283 | gamma = 0.0; | - |
| 284 | optimizedWrite = false; | - |
| 285 | progressiveScanWrite = false; | - |
| 286 | imageWriterError = QImageWriter::UnknownError; | - |
| 287 | errorString = QImageWriter::tr("Unknown error"); | - |
| 288 | transformation = QImageIOHandler::TransformationNone; | - |
| 289 | | - |
| 290 | q = qq; | - |
| 291 | } | - |
| 292 | | - |
| 293 | bool QImageWriterPrivate::canWriteHelper() | - |
| 294 | { | - |
| 295 | if (!device) { | - |
| 296 | imageWriterError = QImageWriter::DeviceError; | - |
| 297 | errorString = QImageWriter::tr("Device is not set"); | - |
| 298 | return false; | - |
| 299 | } | - |
| 300 | if (!device->isOpen()) | - |
| 301 | device->open(QIODevice::WriteOnly); | - |
| 302 | if (!device->isWritable()) { | - |
| 303 | imageWriterError = QImageWriter::DeviceError; | - |
| 304 | errorString = QImageWriter::tr("Device not writable"); | - |
| 305 | return false; | - |
| 306 | } | - |
| 307 | if (!handler && (handler = createWriteHandlerHelper(device, format)) == 0) { | - |
| 308 | imageWriterError = QImageWriter::UnsupportedFormatError; | - |
| 309 | errorString = QImageWriter::tr("Unsupported image format"); | - |
| 310 | return false; | - |
| 311 | } | - |
| 312 | return true; | - |
| 313 | } | - |
| 314 | | - |
| 315 | | - |
| 316 | | - |
| 317 | | - |
| 318 | | - |
| 319 | | - |
| 320 | QImageWriter::QImageWriter() | - |
| 321 | : d(new QImageWriterPrivate(this)) | - |
| 322 | { | - |
| 323 | } | - |
| 324 | | - |
| 325 | | - |
| 326 | | - |
| 327 | | - |
| 328 | | - |
| 329 | QImageWriter::QImageWriter(QIODevice *device, const QByteArray &format) | - |
| 330 | : d(new QImageWriterPrivate(this)) | - |
| 331 | { | - |
| 332 | d->device = device; | - |
| 333 | d->format = format; | - |
| 334 | } | - |
| 335 | | - |
| 336 | | - |
| 337 | | - |
| 338 | | - |
| 339 | | - |
| 340 | | - |
| 341 | | - |
| 342 | QImageWriter::QImageWriter(const QString &fileName, const QByteArray &format) | - |
| 343 | : d(new QImageWriterPrivate(this)) | - |
| 344 | { | - |
| 345 | QFile *file = new QFile(fileName); | - |
| 346 | d->device = file; | - |
| 347 | d->deleteDevice = true; | - |
| 348 | d->format = format; | - |
| 349 | } | - |
| 350 | | - |
| 351 | | - |
| 352 | | - |
| 353 | | - |
| 354 | QImageWriter::~QImageWriter() | - |
| 355 | { | - |
| 356 | if (d->deleteDevice) | - |
| 357 | delete d->device; | - |
| 358 | delete d->handler; | - |
| 359 | delete d; | - |
| 360 | } | - |
| 361 | | - |
| 362 | | - |
| 363 | | - |
| 364 | | - |
| 365 | | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | | - |
| 370 | | - |
| 371 | | - |
| 372 | | - |
| 373 | void QImageWriter::setFormat(const QByteArray &format) | - |
| 374 | { | - |
| 375 | d->format = format; | - |
| 376 | } | - |
| 377 | | - |
| 378 | | - |
| 379 | | - |
| 380 | | - |
| 381 | | - |
| 382 | | - |
| 383 | QByteArray QImageWriter::format() const | - |
| 384 | { | - |
| 385 | return d->format; | - |
| 386 | } | - |
| 387 | | - |
| 388 | | - |
| 389 | | - |
| 390 | | - |
| 391 | | - |
| 392 | | - |
| 393 | | - |
| 394 | | - |
| 395 | | - |
| 396 | | - |
| 397 | | - |
| 398 | | - |
| 399 | | - |
| 400 | | - |
| 401 | void QImageWriter::setDevice(QIODevice *device) | - |
| 402 | { | - |
| 403 | if (d->device && d->deleteDevice) | - |
| 404 | delete d->device; | - |
| 405 | | - |
| 406 | d->device = device; | - |
| 407 | d->deleteDevice = false; | - |
| 408 | delete d->handler; | - |
| 409 | d->handler = 0; | - |
| 410 | } | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| 415 | | - |
| 416 | QIODevice *QImageWriter::device() const | - |
| 417 | { | - |
| 418 | return d->device; | - |
| 419 | } | - |
| 420 | | - |
| 421 | | - |
| 422 | | - |
| 423 | | - |
| 424 | | - |
| 425 | | - |
| 426 | | - |
| 427 | | - |
| 428 | void QImageWriter::setFileName(const QString &fileName) | - |
| 429 | { | - |
| 430 | setDevice(new QFile(fileName)); | - |
| 431 | d->deleteDevice = true; | - |
| 432 | } | - |
| 433 | | - |
| 434 | | - |
| 435 | | - |
| 436 | | - |
| 437 | | - |
| 438 | | - |
| 439 | | - |
| 440 | | - |
| 441 | | - |
| 442 | | - |
| 443 | QString QImageWriter::fileName() const | - |
| 444 | { | - |
| 445 | QFile *file = qobject_cast<QFile *>(d->device); | - |
| 446 | return file ? file->fileName() : QString(); | - |
| 447 | } | - |
| 448 | | - |
| 449 | | - |
| 450 | | - |
| 451 | | - |
| 452 | | - |
| 453 | | - |
| 454 | | - |
| 455 | | - |
| 456 | | - |
| 457 | | - |
| 458 | | - |
| 459 | | - |
| 460 | | - |
| 461 | | - |
| 462 | | - |
| 463 | void QImageWriter::setQuality(int quality) | - |
| 464 | { | - |
| 465 | d->quality = quality; | - |
| 466 | } | - |
| 467 | | - |
| 468 | | - |
| 469 | | - |
| 470 | | - |
| 471 | | - |
| 472 | | - |
| 473 | int QImageWriter::quality() const | - |
| 474 | { | - |
| 475 | return d->quality; | - |
| 476 | } | - |
| 477 | | - |
| 478 | | - |
| 479 | | - |
| 480 | | - |
| 481 | | - |
| 482 | | - |
| 483 | | - |
| 484 | | - |
| 485 | | - |
| 486 | | - |
| 487 | | - |
| 488 | | - |
| 489 | void QImageWriter::setCompression(int compression) | - |
| 490 | { | - |
| 491 | d->compression = compression; | - |
| 492 | } | - |
| 493 | | - |
| 494 | | - |
| 495 | | - |
| 496 | | - |
| 497 | | - |
| 498 | | - |
| 499 | int QImageWriter::compression() const | - |
| 500 | { | - |
| 501 | return d->compression; | - |
| 502 | } | - |
| 503 | | - |
| 504 | | - |
| 505 | | - |
| 506 | | - |
| 507 | | - |
| 508 | | - |
| 509 | | - |
| 510 | | - |
| 511 | | - |
| 512 | | - |
| 513 | | - |
| 514 | void QImageWriter::setGamma(float gamma) | - |
| 515 | { | - |
| 516 | d->gamma = gamma; | - |
| 517 | } | - |
| 518 | | - |
| 519 | | - |
| 520 | | - |
| 521 | | - |
| 522 | | - |
| 523 | | - |
| 524 | float QImageWriter::gamma() const | - |
| 525 | { | - |
| 526 | return d->gamma; | - |
| 527 | } | - |
| 528 | | - |
| 529 | | - |
| 530 | | - |
| 531 | | - |
| 532 | | - |
| 533 | | - |
| 534 | | - |
| 535 | | - |
| 536 | | - |
| 537 | | - |
| 538 | | - |
| 539 | | - |
| 540 | | - |
| 541 | void QImageWriter::setSubType(const QByteArray &type) | - |
| 542 | { | - |
| 543 | d->subType = type; | - |
| 544 | } | - |
| 545 | | - |
| 546 | | - |
| 547 | | - |
| 548 | | - |
| 549 | | - |
| 550 | | - |
| 551 | | - |
| 552 | | - |
| 553 | QByteArray QImageWriter::subType() const | - |
| 554 | { | - |
| 555 | return d->subType; | - |
| 556 | } | - |
| 557 | | - |
| 558 | | - |
| 559 | | - |
| 560 | | - |
| 561 | | - |
| 562 | | - |
| 563 | QList<QByteArray> QImageWriter::supportedSubTypes() const | - |
| 564 | { | - |
| 565 | if (!supportsOption(QImageIOHandler::SupportedSubTypes)) | - |
| 566 | return QList<QByteArray>(); | - |
| 567 | return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >(); | - |
| 568 | } | - |
| 569 | | - |
| 570 | | - |
| 571 | | - |
| 572 | | - |
| 573 | | - |
| 574 | | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | | - |
| 579 | | - |
| 580 | | - |
| 581 | void QImageWriter::setOptimizedWrite(bool optimize) | - |
| 582 | { | - |
| 583 | d->optimizedWrite = optimize; | - |
| 584 | } | - |
| 585 | | - |
| 586 | | - |
| 587 | | - |
| 588 | | - |
| 589 | | - |
| 590 | | - |
| 591 | | - |
| 592 | | - |
| 593 | bool QImageWriter::optimizedWrite() const | - |
| 594 | { | - |
| 595 | return d->optimizedWrite; | - |
| 596 | } | - |
| 597 | | - |
| 598 | | - |
| 599 | | - |
| 600 | | - |
| 601 | | - |
| 602 | | - |
| 603 | | - |
| 604 | | - |
| 605 | | - |
| 606 | | - |
| 607 | | - |
| 608 | | - |
| 609 | | - |
| 610 | void QImageWriter::setProgressiveScanWrite(bool progressive) | - |
| 611 | { | - |
| 612 | d->progressiveScanWrite = progressive; | - |
| 613 | } | - |
| 614 | | - |
| 615 | | - |
| 616 | | - |
| 617 | | - |
| 618 | | - |
| 619 | | - |
| 620 | | - |
| 621 | | - |
| 622 | bool QImageWriter::progressiveScanWrite() const | - |
| 623 | { | - |
| 624 | return d->progressiveScanWrite; | - |
| 625 | } | - |
| 626 | | - |
| 627 | | - |
| 628 | | - |
| 629 | | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | | - |
| 634 | | - |
| 635 | | - |
| 636 | | - |
| 637 | void QImageWriter::setTransformation(QImageIOHandler::Transformations transform) | - |
| 638 | { | - |
| 639 | d->transformation = transform; | - |
| 640 | } | - |
| 641 | | - |
| 642 | | - |
| 643 | | - |
| 644 | | - |
| 645 | | - |
| 646 | | - |
| 647 | | - |
| 648 | | - |
| 649 | QImageIOHandler::Transformations QImageWriter::transformation() const | - |
| 650 | { | - |
| 651 | return d->transformation; | - |
| 652 | } | - |
| 653 | | - |
| 654 | | - |
| 655 | | - |
| 656 | | - |
| 657 | | - |
| 658 | | - |
| 659 | | - |
| 660 | | - |
| 661 | | - |
| 662 | | - |
| 663 | | - |
| 664 | | - |
| 665 | | - |
| 666 | | - |
| 667 | void QImageWriter::setDescription(const QString &description) | - |
| 668 | { | - |
| 669 | d->description = description; | - |
| 670 | } | - |
| 671 | | - |
| 672 | | - |
| 673 | | - |
| 674 | | - |
| 675 | | - |
| 676 | | - |
| 677 | | - |
| 678 | | - |
| 679 | | - |
| 680 | | - |
| 681 | QString QImageWriter::description() const | - |
| 682 | { | - |
| 683 | return d->description; | - |
| 684 | } | - |
| 685 | | - |
| 686 | | - |
| 687 | | - |
| 688 | | - |
| 689 | | - |
| 690 | | - |
| 691 | | - |
| 692 | | - |
| 693 | | - |
| 694 | | - |
| 695 | | - |
| 696 | | - |
| 697 | | - |
| 698 | | - |
| 699 | | - |
| 700 | | - |
| 701 | | - |
| 702 | | - |
| 703 | | - |
| 704 | | - |
| 705 | | - |
| 706 | | - |
| 707 | void QImageWriter::setText(const QString &key, const QString &text) | - |
| 708 | { | - |
| 709 | if (!d->description.isEmpty()) | - |
| 710 | d->description += QLatin1String("\n\n"); | - |
| 711 | d->description += key.simplified() + QLatin1String(": ") + text.simplified(); | - |
| 712 | } | - |
| 713 | | - |
| 714 | | - |
| 715 | | - |
| 716 | | - |
| 717 | | - |
| 718 | | - |
| 719 | | - |
| 720 | bool QImageWriter::canWrite() const | - |
| 721 | { | - |
| 722 | if (QFile *file = qobject_cast<QFile *>(d->device)) { | - |
| 723 | const bool remove = !file->isOpen() && !file->exists(); | - |
| 724 | const bool result = d->canWriteHelper(); | - |
| 725 | if (!result && remove) | - |
| 726 | file->remove(); | - |
| 727 | return result; | - |
| 728 | } | - |
| 729 | | - |
| 730 | return d->canWriteHelper(); | - |
| 731 | } | - |
| 732 | | - |
| 733 | extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient); | - |
| 734 | | - |
| 735 | | - |
| 736 | | - |
| 737 | | - |
| 738 | | - |
| 739 | | - |
| 740 | | - |
| 741 | | - |
| 742 | | - |
| 743 | | - |
| 744 | bool QImageWriter::write(const QImage &image) | - |
| 745 | { | - |
| 746 | if (!canWrite()) | - |
| 747 | return false; | - |
| 748 | | - |
| 749 | QImage img = image; | - |
| 750 | if (d->handler->supportsOption(QImageIOHandler::Quality)) | - |
| 751 | d->handler->setOption(QImageIOHandler::Quality, d->quality); | - |
| 752 | if (d->handler->supportsOption(QImageIOHandler::CompressionRatio)) | - |
| 753 | d->handler->setOption(QImageIOHandler::CompressionRatio, d->compression); | - |
| 754 | if (d->handler->supportsOption(QImageIOHandler::Gamma)) | - |
| 755 | d->handler->setOption(QImageIOHandler::Gamma, d->gamma); | - |
| 756 | if (!d->description.isEmpty() && d->handler->supportsOption(QImageIOHandler::Description)) | - |
| 757 | d->handler->setOption(QImageIOHandler::Description, d->description); | - |
| 758 | if (!d->subType.isEmpty() && d->handler->supportsOption(QImageIOHandler::SubType)) | - |
| 759 | d->handler->setOption(QImageIOHandler::SubType, d->subType); | - |
| 760 | if (d->handler->supportsOption(QImageIOHandler::OptimizedWrite)) | - |
| 761 | d->handler->setOption(QImageIOHandler::OptimizedWrite, d->optimizedWrite); | - |
| 762 | if (d->handler->supportsOption(QImageIOHandler::ProgressiveScanWrite)) | - |
| 763 | d->handler->setOption(QImageIOHandler::ProgressiveScanWrite, d->progressiveScanWrite); | - |
| 764 | if (d->handler->supportsOption(QImageIOHandler::ImageTransformation)) | - |
| 765 | d->handler->setOption(QImageIOHandler::ImageTransformation, int(d->transformation)); | - |
| 766 | else | - |
| 767 | qt_imageTransform(img, d->transformation); | - |
| 768 | | - |
| 769 | if (!d->handler->write(img)) | - |
| 770 | return false; | - |
| 771 | if (QFile *file = qobject_cast<QFile *>(d->device)) | - |
| 772 | file->flush(); | - |
| 773 | return true; | - |
| 774 | } | - |
| 775 | | - |
| 776 | | - |
| 777 | | - |
| 778 | | - |
| 779 | | - |
| 780 | | - |
| 781 | QImageWriter::ImageWriterError QImageWriter::error() const | - |
| 782 | { | - |
| 783 | return d->imageWriterError; | - |
| 784 | } | - |
| 785 | | - |
| 786 | | - |
| 787 | | - |
| 788 | | - |
| 789 | | - |
| 790 | | - |
| 791 | QString QImageWriter::errorString() const | - |
| 792 | { | - |
| 793 | return d->errorString; | - |
| 794 | } | - |
| 795 | | - |
| 796 | | - |
| 797 | | - |
| 798 | | - |
| 799 | | - |
| 800 | | - |
| 801 | | - |
| 802 | | - |
| 803 | | - |
| 804 | | - |
| 805 | | - |
| 806 | | - |
| 807 | | - |
| 808 | | - |
| 809 | | - |
| 810 | | - |
| 811 | | - |
| 812 | | - |
| 813 | bool QImageWriter::supportsOption(QImageIOHandler::ImageOption option) const | - |
| 814 | { | - |
| 815 | if (!d->handler && (d->handler = createWriteHandlerHelper(d->device, d->format)) == 0) { | - |
| 816 | d->imageWriterError = QImageWriter::UnsupportedFormatError; | - |
| 817 | d->errorString = QImageWriter::tr("Unsupported image format"); | - |
| 818 | return false; | - |
| 819 | } | - |
| 820 | | - |
| 821 | return d->handler->supportsOption(option); | - |
| 822 | } | - |
| 823 | | - |
| 824 | | - |
| 825 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 826 | void supportedImageHandlerFormats(QFactoryLoader *loader, | - |
| 827 | QImageIOPlugin::Capability cap, | - |
| 828 | QList<QByteArray> *result) | - |
| 829 | { | - |
| 830 | typedef QMultiMap<int, QString> PluginKeyMap; | - |
| 831 | typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; | - |
| 832 | | - |
| 833 | const PluginKeyMap keyMap = loader->keyMap(); | - |
| 834 | const PluginKeyMapConstIterator cend = keyMap.constEnd(); | - |
| 835 | int i = -1; | - |
| 836 | QImageIOPlugin *plugin = 0; | - |
| 837 | result->reserve(result->size() + keyMap.size()); | - |
| 838 | for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) { | - |
| 839 | if (it.key() != i) { | - |
| 840 | i = it.key(); | - |
| 841 | plugin = qobject_cast<QImageIOPlugin *>(loader->instance(i)); | - |
| 842 | } | - |
| 843 | const QByteArray key = it.value().toLatin1(); | - |
| 844 | if (plugin && (plugin->capabilities(0, key) & cap) != 0) | - |
| 845 | result->append(key); | - |
| 846 | } | - |
| 847 | } | - |
| 848 | | - |
| 849 | void supportedImageHandlerMimeTypes(QFactoryLoader *loader, | - |
| 850 | QImageIOPlugin::Capability cap, | - |
| 851 | QList<QByteArray> *result) | - |
| 852 | { | - |
| 853 | QList<QJsonObject> metaDataList = loader->metaData(); | - |
| 854 | | - |
| 855 | const int pluginCount = metaDataList.size(); | - |
| 856 | for (int i = 0; i < pluginCount; ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 857 | const QJsonObject metaData = metaDataList.at(i).value(QStringLiteralQLatin1String("MetaData")).toObject(); | - |
| 858 | const QJsonArray keys = metaData.value(QStringLiteralQLatin1String("Keys")).toArray(); | - |
| 859 | const QJsonArray mimeTypes = metaData.value(QStringLiteralQLatin1String("MimeTypes")).toArray(); | - |
| 860 | QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(loader->instance(i)); | - |
| 861 | const int keyCount = keys.size(); | - |
| 862 | for (int k = 0; k < keyCount; ++k) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 863 | if (plugin && (plugin->capabilities(0, keys.at(k).toString().toLatin1()) & cap) != 0)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 864 | result->append(mimeTypes.at(k).toString().toLatin1()); never executed: result->append(mimeTypes.at(k).toString().toLatin1()); | 0 |
| 865 | } never executed: end of block | 0 |
| 866 | } never executed: end of block | 0 |
| 867 | } never executed: end of block | 0 |
| 868 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 869 | | - |
| 870 | | - |
| 871 | | - |
| 872 | | - |
| 873 | | - |
| 874 | | - |
| 875 | | - |
| 876 | | - |
| 877 | | - |
| 878 | | - |
| 879 | | - |
| 880 | | - |
| 881 | | - |
| 882 | | - |
| 883 | | - |
| 884 | | - |
| 885 | | - |
| 886 | | - |
| 887 | | - |
| 888 | | - |
| 889 | | - |
| 890 | | - |
| 891 | | - |
| 892 | | - |
| 893 | | - |
| 894 | | - |
| 895 | QList<QByteArray> QImageWriter::supportedImageFormats() | - |
| 896 | { | - |
| 897 | QList<QByteArray> formats; | - |
| 898 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 899 | formats << "bmp"; | - |
| 900 | #endif | - |
| 901 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 902 | formats << "pbm" << "pgm" << "ppm"; | - |
| 903 | #endif | - |
| 904 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 905 | formats << "xbm"; | - |
| 906 | #endif | - |
| 907 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 908 | formats << "xpm"; | - |
| 909 | #endif | - |
| 910 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 911 | formats << "png"; | - |
| 912 | #endif | - |
| 913 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 914 | formats << "jpg" << "jpeg"; | - |
| 915 | #endif | - |
| 916 | | - |
| 917 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 918 | supportedImageHandlerFormats(loader(), QImageIOPlugin::CanWrite, &formats); | - |
| 919 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 920 | | - |
| 921 | std::sort(formats.begin(), formats.end()); | - |
| 922 | formats.erase(std::unique(formats.begin(), formats.end()), formats.end()); | - |
| 923 | return formats; | - |
| 924 | } | - |
| 925 | | - |
| 926 | | - |
| 927 | | - |
| 928 | | - |
| 929 | | - |
| 930 | | - |
| 931 | | - |
| 932 | | - |
| 933 | | - |
| 934 | QList<QByteArray> QImageWriter::supportedMimeTypes() | - |
| 935 | { | - |
| 936 | QList<QByteArray> mimeTypes; | - |
| 937 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 938 | mimeTypes << "image/bmp"; | - |
| 939 | #endif | - |
| 940 | #ifndef QT_NO_IMAGEFORMAT_PPM | - |
| 941 | mimeTypes << "image/x-portable-bitmap"; | - |
| 942 | mimeTypes << "image/x-portable-graymap"; | - |
| 943 | mimeTypes << "image/x-portable-pixmap"; | - |
| 944 | #endif | - |
| 945 | #ifndef QT_NO_IMAGEFORMAT_XBM | - |
| 946 | mimeTypes << "image/x-xbitmap"; | - |
| 947 | #endif | - |
| 948 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
| 949 | mimeTypes << "image/x-xpixmap"; | - |
| 950 | #endif | - |
| 951 | #ifndef QT_NO_IMAGEFORMAT_PNG | - |
| 952 | mimeTypes << "image/png"; | - |
| 953 | #endif | - |
| 954 | #ifndef QT_NO_IMAGEFORMAT_JPEG | - |
| 955 | mimeTypes << "image/jpeg"; | - |
| 956 | #endif | - |
| 957 | | - |
| 958 | #ifndef QT_NO_IMAGEFORMATPLUGIN | - |
| 959 | supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanWrite, &mimeTypes); | - |
| 960 | #endif // QT_NO_IMAGEFORMATPLUGIN | - |
| 961 | | - |
| 962 | std::sort(mimeTypes.begin(), mimeTypes.end()); | - |
| 963 | mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end()); | - |
| 964 | return mimeTypes; | - |
| 965 | } | - |
| 966 | | - |
| 967 | QT_END_NAMESPACE | - |
| | |