| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | static bool qt_pixmap_thread_test() | - |
| 9 | { | - |
| 10 | if (!QCoreApplication::instance()) { | - |
| 11 | QMessageLogger("image/qpixmap.cpp", 76, __PRETTY_FUNCTION__).fatal("QPixmap: Must construct a QApplication before a QPaintDevice"); | - |
| 12 | return false; | - |
| 13 | } | - |
| 14 | | - |
| 15 | if ((static_cast<QGuiApplication *>(QCoreApplication::instance()))->thread() != QThread::currentThread()) { | - |
| 16 | bool fail = false; | - |
| 17 | if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) { | - |
| 18 | printf("Lighthouse plugin does not support threaded pixmaps!\n"); | - |
| 19 | fail = true; | - |
| 20 | } | - |
| 21 | if (fail) { | - |
| 22 | QMessageLogger("image/qpixmap.cpp", 87, __PRETTY_FUNCTION__).warning("QPixmap: It is not safe to use pixmaps outside the GUI thread"); | - |
| 23 | return false; | - |
| 24 | } | - |
| 25 | } | - |
| 26 | return true; | - |
| 27 | } | - |
| 28 | | - |
| 29 | void QPixmap::doInit(int w, int h, int type) | - |
| 30 | { | - |
| 31 | if ((w > 0 && h > 0) || type == QPlatformPixmap::BitmapType) | - |
| 32 | data = QPlatformPixmap::create(w, h, (QPlatformPixmap::PixelType) type); | - |
| 33 | else | - |
| 34 | data = 0; | - |
| 35 | } | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | | - |
| 41 | | - |
| 42 | | - |
| 43 | QPixmap::QPixmap() | - |
| 44 | : QPaintDevice() | - |
| 45 | { | - |
| 46 | (void) qt_pixmap_thread_test(); | - |
| 47 | doInit(0, 0, QPlatformPixmap::PixmapType); | - |
| 48 | } | - |
| 49 | QPixmap::QPixmap(int w, int h) | - |
| 50 | : QPaintDevice() | - |
| 51 | { | - |
| 52 | if (!qt_pixmap_thread_test()) | - |
| 53 | doInit(0, 0, QPlatformPixmap::PixmapType); | - |
| 54 | else | - |
| 55 | doInit(w, h, QPlatformPixmap::PixmapType); | - |
| 56 | } | - |
| 57 | QPixmap::QPixmap(const QSize &size) | - |
| 58 | : QPaintDevice() | - |
| 59 | { | - |
| 60 | if (!qt_pixmap_thread_test()) | - |
| 61 | doInit(0, 0, QPlatformPixmap::PixmapType); | - |
| 62 | else | - |
| 63 | doInit(size.width(), size.height(), QPlatformPixmap::PixmapType); | - |
| 64 | } | - |
| 65 | | - |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | QPixmap::QPixmap(const QSize &s, int type) | - |
| 70 | { | - |
| 71 | if (!qt_pixmap_thread_test()) | - |
| 72 | doInit(0, 0, static_cast<QPlatformPixmap::PixelType>(type)); | - |
| 73 | else | - |
| 74 | doInit(s.width(), s.height(), static_cast<QPlatformPixmap::PixelType>(type)); | - |
| 75 | } | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | QPixmap::QPixmap(QPlatformPixmap *d) | - |
| 81 | : QPaintDevice(), data(d) | - |
| 82 | { | - |
| 83 | } | - |
| 84 | QPixmap::QPixmap(const QString& fileName, const char *format, Qt::ImageConversionFlags flags) | - |
| 85 | : QPaintDevice() | - |
| 86 | { | - |
| 87 | doInit(0, 0, QPlatformPixmap::PixmapType); | - |
| 88 | if (!qt_pixmap_thread_test()) | - |
| 89 | return; | - |
| 90 | | - |
| 91 | load(fileName, format, flags); | - |
| 92 | } | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | QPixmap::QPixmap(const QPixmap &pixmap) | - |
| 101 | : QPaintDevice() | - |
| 102 | { | - |
| 103 | if (!qt_pixmap_thread_test()) { | - |
| 104 | doInit(0, 0, QPlatformPixmap::PixmapType); | - |
| 105 | return; | - |
| 106 | } | - |
| 107 | if (pixmap.paintingActive()) { | - |
| 108 | pixmap.copy().swap(*this); | - |
| 109 | } else { | - |
| 110 | data = pixmap.data; | - |
| 111 | } | - |
| 112 | } | - |
| 113 | QPixmap::QPixmap(const char * const xpm[]) | - |
| 114 | : QPaintDevice() | - |
| 115 | { | - |
| 116 | doInit(0, 0, QPlatformPixmap::PixmapType); | - |
| 117 | if (!xpm) | - |
| 118 | return; | - |
| 119 | | - |
| 120 | QImage image(xpm); | - |
| 121 | if (!image.isNull()) { | - |
| 122 | if (data && data->pixelType() == QPlatformPixmap::BitmapType) | - |
| 123 | *this = QBitmap::fromImage(image); | - |
| 124 | else | - |
| 125 | *this = fromImage(image); | - |
| 126 | } | - |
| 127 | } | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | | - |
| 132 | | - |
| 133 | | - |
| 134 | | - |
| 135 | QPixmap::~QPixmap() | - |
| 136 | { | - |
| 137 | qt_noop(); | - |
| 138 | } | - |
| 139 | | - |
| 140 | | - |
| 141 | | - |
| 142 | | - |
| 143 | int QPixmap::devType() const | - |
| 144 | { | - |
| 145 | return QInternal::Pixmap; | - |
| 146 | } | - |
| 147 | QPixmap QPixmap::copy(const QRect &rect) const | - |
| 148 | { | - |
| 149 | if (isNull()) | - |
| 150 | return QPixmap(); | - |
| 151 | | - |
| 152 | QRect r(0, 0, width(), height()); | - |
| 153 | if (!rect.isEmpty()) | - |
| 154 | r = r.intersected(rect); | - |
| 155 | | - |
| 156 | QPlatformPixmap *d = data->createCompatiblePlatformPixmap(); | - |
| 157 | d->copy(data.data(), r); | - |
| 158 | return QPixmap(d); | - |
| 159 | } | - |
| 160 | void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed) | - |
| 161 | { | - |
| 162 | if (isNull() || (dx == 0 && dy == 0)) | - |
| 163 | return; | - |
| 164 | QRect dest = rect & this->rect(); | - |
| 165 | QRect src = dest.translated(-dx, -dy) & dest; | - |
| 166 | if (src.isEmpty()) { | - |
| 167 | if (exposed) | - |
| 168 | *exposed += dest; | - |
| 169 | return; | - |
| 170 | } | - |
| 171 | | - |
| 172 | detach(); | - |
| 173 | | - |
| 174 | if (!data->scroll(dx, dy, src)) { | - |
| 175 | | - |
| 176 | QPixmap pix = *this; | - |
| 177 | QPainter painter(&pix); | - |
| 178 | painter.setCompositionMode(QPainter::CompositionMode_Source); | - |
| 179 | painter.drawPixmap(src.translated(dx, dy), *this, src); | - |
| 180 | painter.end(); | - |
| 181 | *this = pix; | - |
| 182 | } | - |
| 183 | | - |
| 184 | if (exposed) { | - |
| 185 | *exposed += dest; | - |
| 186 | *exposed -= src.translated(dx, dy); | - |
| 187 | } | - |
| 188 | } | - |
| 189 | QPixmap &QPixmap::operator=(const QPixmap &pixmap) | - |
| 190 | { | - |
| 191 | if (paintingActive()) { | - |
| 192 | QMessageLogger("image/qpixmap.cpp", 383, __PRETTY_FUNCTION__).warning("QPixmap::operator=: Cannot assign to pixmap during painting"); | - |
| 193 | return *this; | - |
| 194 | } | - |
| 195 | if (pixmap.paintingActive()) { | - |
| 196 | pixmap.copy().swap(*this); | - |
| 197 | } else { | - |
| 198 | data = pixmap.data; | - |
| 199 | } | - |
| 200 | return *this; | - |
| 201 | } | - |
| 202 | QPixmap::operator QVariant() const | - |
| 203 | { | - |
| 204 | return QVariant(QVariant::Pixmap, this); | - |
| 205 | } | - |
| 206 | QImage QPixmap::toImage() const | - |
| 207 | { | - |
| 208 | if (isNull()) | - |
| 209 | return QImage(); | - |
| 210 | | - |
| 211 | return data->toImage(); | - |
| 212 | } | - |
| 213 | QTransform QPixmap::trueMatrix(const QTransform &m, int w, int h) | - |
| 214 | { | - |
| 215 | return QImage::trueMatrix(m, w, h); | - |
| 216 | } | - |
| 217 | QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h) | - |
| 218 | { | - |
| 219 | return trueMatrix(QTransform(m), w, h).toAffine(); | - |
| 220 | } | - |
| 221 | bool QPixmap::isQBitmap() const | - |
| 222 | { | - |
| 223 | return data->type == QPlatformPixmap::BitmapType; | - |
| 224 | } | - |
| 225 | bool QPixmap::isNull() const | - |
| 226 | { | - |
| 227 | return !data || data->isNull(); | - |
| 228 | } | - |
| 229 | int QPixmap::width() const | - |
| 230 | { | - |
| 231 | return data ? data->width() : 0; | - |
| 232 | } | - |
| 233 | int QPixmap::height() const | - |
| 234 | { | - |
| 235 | return data ? data->height() : 0; | - |
| 236 | } | - |
| 237 | QSize QPixmap::size() const | - |
| 238 | { | - |
| 239 | return data ? QSize(data->width(), data->height()) : QSize(0, 0); | - |
| 240 | } | - |
| 241 | QRect QPixmap::rect() const | - |
| 242 | { | - |
| 243 | return data ? QRect(0, 0, data->width(), data->height()) : QRect(); | - |
| 244 | } | - |
| 245 | int QPixmap::depth() const | - |
| 246 | { | - |
| 247 | return data ? data->depth() : 0; | - |
| 248 | } | - |
| 249 | void QPixmap::setMask(const QBitmap &mask) | - |
| 250 | { | - |
| 251 | if (paintingActive()) { | - |
| 252 | QMessageLogger("image/qpixmap.cpp", 585, __PRETTY_FUNCTION__).warning("QPixmap::setMask: Cannot set mask while pixmap is being painted on"); | - |
| 253 | return; | - |
| 254 | } | - |
| 255 | | - |
| 256 | if (!mask.isNull() && mask.size() != size()) { | - |
| 257 | QMessageLogger("image/qpixmap.cpp", 590, __PRETTY_FUNCTION__).warning("QPixmap::setMask() mask size differs from pixmap size"); | - |
| 258 | return; | - |
| 259 | } | - |
| 260 | | - |
| 261 | if (isNull()) | - |
| 262 | return; | - |
| 263 | | - |
| 264 | if (static_cast<const QPixmap &>(mask).data == data) | - |
| 265 | return; | - |
| 266 | | - |
| 267 | detach(); | - |
| 268 | | - |
| 269 | QImage image = data->toImage(); | - |
| 270 | if (mask.size().isEmpty()) { | - |
| 271 | if (image.depth() != 1) { | - |
| 272 | image = image.convertToFormat(QImage::Format_RGB32); | - |
| 273 | } | - |
| 274 | } else { | - |
| 275 | const int w = image.width(); | - |
| 276 | const int h = image.height(); | - |
| 277 | | - |
| 278 | switch (image.depth()) { | - |
| 279 | case 1: { | - |
| 280 | const QImage imageMask = mask.toImage().convertToFormat(image.format()); | - |
| 281 | for (int y = 0; y < h; ++y) { | - |
| 282 | const uchar *mscan = imageMask.scanLine(y); | - |
| 283 | uchar *tscan = image.scanLine(y); | - |
| 284 | int bytesPerLine = image.bytesPerLine(); | - |
| 285 | for (int i = 0; i < bytesPerLine; ++i) | - |
| 286 | tscan[i] &= mscan[i]; | - |
| 287 | } | - |
| 288 | break; | - |
| 289 | } | - |
| 290 | default: { | - |
| 291 | const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB); | - |
| 292 | image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); | - |
| 293 | for (int y = 0; y < h; ++y) { | - |
| 294 | const uchar *mscan = imageMask.scanLine(y); | - |
| 295 | QRgb *tscan = (QRgb *)image.scanLine(y); | - |
| 296 | for (int x = 0; x < w; ++x) { | - |
| 297 | if (!(mscan[x>>3] & (1 << (x&7)))) | - |
| 298 | tscan[x] = 0; | - |
| 299 | } | - |
| 300 | } | - |
| 301 | break; | - |
| 302 | } | - |
| 303 | } | - |
| 304 | } | - |
| 305 | data->fromImage(image, Qt::AutoColor); | - |
| 306 | } | - |
| 307 | qreal QPixmap::devicePixelRatio() const | - |
| 308 | { | - |
| 309 | if (!data) | - |
| 310 | return qreal(1.0); | - |
| 311 | return data->devicePixelRatio(); | - |
| 312 | } | - |
| 313 | void QPixmap::setDevicePixelRatio(qreal scaleFactor) | - |
| 314 | { | - |
| 315 | detach(); | - |
| 316 | data->setDevicePixelRatio(scaleFactor); | - |
| 317 | } | - |
| 318 | QBitmap QPixmap::createHeuristicMask(bool clipTight) const | - |
| 319 | { | - |
| 320 | QBitmap m = QBitmap::fromImage(toImage().createHeuristicMask(clipTight)); | - |
| 321 | return m; | - |
| 322 | } | - |
| 323 | QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const | - |
| 324 | { | - |
| 325 | QImage image = toImage().convertToFormat(QImage::Format_ARGB32); | - |
| 326 | return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode)); | - |
| 327 | } | - |
| 328 | bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConversionFlags flags) | - |
| 329 | { | - |
| 330 | if (fileName.isEmpty()) { evaluated: fileName.isEmpty()| yes Evaluation Count:54 | yes Evaluation Count:1711 |
| 54-1711 |
| 331 | data.reset(); | - |
| 332 | return false; executed: return false;Execution Count:54 | 54 |
| 333 | } | - |
| 334 | | - |
| 335 | detach(); | - |
| 336 | | - |
| 337 | QFileInfo info(fileName); | - |
| 338 | QString key = QLatin1String("qt_pixmap") | - |
| 339 | % info.absoluteFilePath() | - |
| 340 | % HexString<uint>(info.lastModified().toTime_t()) | - |
| 341 | % HexString<quint64>(info.size()) | - |
| 342 | % HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType); | - |
| 343 | | - |
| 344 | | - |
| 345 | | - |
| 346 | if (!info.completeSuffix().isEmpty() && !info.exists()) { evaluated: !info.completeSuffix().isEmpty()| yes Evaluation Count:1706 | yes Evaluation Count:5 |
evaluated: !info.exists()| yes Evaluation Count:9 | yes Evaluation Count:1697 |
| 5-1706 |
| 347 | data.reset(); | - |
| 348 | return false; executed: return false;Execution Count:9 | 9 |
| 349 | } | - |
| 350 | | - |
| 351 | if (QPixmapCache::find(key, this)) evaluated: QPixmapCache::find(key, this)| yes Evaluation Count:1575 | yes Evaluation Count:127 |
| 127-1575 |
| 352 | return true; executed: return true;Execution Count:1575 | 1575 |
| 353 | | - |
| 354 | if (!data) evaluated: !data| yes Evaluation Count:125 | yes Evaluation Count:2 |
| 2-125 |
| 355 | data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType); executed: data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType);Execution Count:125 | 125 |
| 356 | | - |
| 357 | if (data->fromFile(fileName, format, flags)) { evaluated: data->fromFile(fileName, format, flags)| yes Evaluation Count:122 | yes Evaluation Count:5 |
| 5-122 |
| 358 | QPixmapCache::insert(key, *this); | - |
| 359 | return true; executed: return true;Execution Count:122 | 122 |
| 360 | } | - |
| 361 | | - |
| 362 | data.reset(); | - |
| 363 | return false; executed: return false;Execution Count:5 | 5 |
| 364 | } | - |
| 365 | bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) | - |
| 366 | { | - |
| 367 | if (len == 0 || buf == 0) { | - |
| 368 | data.reset(); | - |
| 369 | return false; | - |
| 370 | } | - |
| 371 | | - |
| 372 | if (!data) | - |
| 373 | data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType); | - |
| 374 | | - |
| 375 | if (data->fromData(buf, len, format, flags)) | - |
| 376 | return true; | - |
| 377 | | - |
| 378 | data.reset(); | - |
| 379 | return false; | - |
| 380 | } | - |
| 381 | bool QPixmap::save(const QString &fileName, const char *format, int quality) const | - |
| 382 | { | - |
| 383 | if (isNull()) | - |
| 384 | return false; | - |
| 385 | QImageWriter writer(fileName, format); | - |
| 386 | return doImageIO(&writer, quality); | - |
| 387 | } | - |
| 388 | bool QPixmap::save(QIODevice* device, const char* format, int quality) const | - |
| 389 | { | - |
| 390 | if (isNull()) | - |
| 391 | return false; | - |
| 392 | QImageWriter writer(device, format); | - |
| 393 | return doImageIO(&writer, quality); | - |
| 394 | } | - |
| 395 | | - |
| 396 | | - |
| 397 | | - |
| 398 | bool QPixmap::doImageIO(QImageWriter *writer, int quality) const | - |
| 399 | { | - |
| 400 | if (quality > 100 || quality < -1) | - |
| 401 | QMessageLogger("image/qpixmap.cpp", 885887, __PRETTY_FUNCTION__).warning("QPixmap::save: quality out of range [-1,100]"); | - |
| 402 | if (quality >= 0) | - |
| 403 | writer->setQuality(qMin(quality,100)); | - |
| 404 | return writer->write(toImage()); | - |
| 405 | } | - |
| 406 | void QPixmap::fill(const QPaintDevice *device, const QPoint &p) | - |
| 407 | { | - |
| 408 | (void)device; | - |
| 409 | (void)p; | - |
| 410 | QMessageLogger("image/qpixmap.cpp", 902904, __PRETTY_FUNCTION__).warning("%s is deprecated, ignored", __PRETTY_FUNCTION__); | - |
| 411 | } | - |
| 412 | void QPixmap::fill(const QColor &color) | - |
| 413 | { | - |
| 414 | if (isNull()) | - |
| 415 | return; | - |
| 416 | | - |
| 417 | | - |
| 418 | | - |
| 419 | if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) { | - |
| 420 | QMessageLogger("image/qpixmap.cpp", 931933, __PRETTY_FUNCTION__).warning("QPixmap::fill: Cannot fill while pixmap is being painted on"); | - |
| 421 | return; | - |
| 422 | } | - |
| 423 | | - |
| 424 | if (data->ref.load() == 1) { | - |
| 425 | | - |
| 426 | | - |
| 427 | detach(); | - |
| 428 | } else { | - |
| 429 | | - |
| 430 | | - |
| 431 | QPlatformPixmap *d = data->createCompatiblePlatformPixmap(); | - |
| 432 | d->resize(data->width(), data->height()); | - |
| 433 | data = d; | - |
| 434 | } | - |
| 435 | data->fill(color); | - |
| 436 | } | - |
| 437 | qint64 QPixmap::cacheKey() const | - |
| 438 | { | - |
| 439 | if (isNull()) | - |
| 440 | return 0; | - |
| 441 | | - |
| 442 | qt_noop(); | - |
| 443 | return data->cacheKey(); | - |
| 444 | } | - |
| 445 | QPixmap QPixmap::grabWidget(QObject *widget, const QRect &rectangle) | - |
| 446 | { | - |
| 447 | QPixmap pixmap; | - |
| 448 | QMessageLogger("image/qpixmap.cpp", 10031005, __PRETTY_FUNCTION__).warning("QPixmap::grabWidget is deprecated, use QWidget::grab() instead"); | - |
| 449 | if (!widget) | - |
| 450 | return pixmap; | - |
| 451 | QMetaObject::invokeMethod(widget, "grab", Qt::DirectConnection, | - |
| 452 | QReturnArgument<QPixmap >("QPixmap", pixmap), | - |
| 453 | QArgument<QRect >("QRect", rectangle)); | - |
| 454 | return pixmap; | - |
| 455 | } | - |
| 456 | QDataStream &operator<<(QDataStream &stream, const QPixmap &pixmap) | - |
| 457 | { | - |
| 458 | return stream << pixmap.toImage(); | - |
| 459 | } | - |
| 460 | QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) | - |
| 461 | { | - |
| 462 | QImage image; | - |
| 463 | stream >> image; | - |
| 464 | | - |
| 465 | if (image.isNull()) { | - |
| 466 | pixmap = QPixmap(); | - |
| 467 | } else if (image.depth() == 1) { | - |
| 468 | pixmap = QBitmap::fromImage(image); | - |
| 469 | } else { | - |
| 470 | pixmap = QPixmap::fromImage(image); | - |
| 471 | } | - |
| 472 | return stream; | - |
| 473 | } | - |
| 474 | | - |
| 475 | | - |
| 476 | | - |
| 477 | | - |
| 478 | | - |
| 479 | | - |
| 480 | | - |
| 481 | bool QPixmap::isDetached() const | - |
| 482 | { | - |
| 483 | return data && data->ref.load() == 1; | - |
| 484 | } | - |
| 485 | bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) | - |
| 486 | { | - |
| 487 | if (image.isNull() || !data) | - |
| 488 | *this = QPixmap::fromImage(image, flags); | - |
| 489 | else | - |
| 490 | data->fromImage(image, flags); | - |
| 491 | return !isNull(); | - |
| 492 | } | - |
| 493 | QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const | - |
| 494 | { | - |
| 495 | if (isNull()) { | - |
| 496 | QMessageLogger("image/qpixmap.cpp", 11461148, __PRETTY_FUNCTION__).warning("QPixmap::scaled: Pixmap is a null pixmap"); | - |
| 497 | return QPixmap(); | - |
| 498 | } | - |
| 499 | if (s.isEmpty()) | - |
| 500 | return QPixmap(); | - |
| 501 | | - |
| 502 | QSize newSize = size(); | - |
| 503 | newSize.scale(s, aspectMode); | - |
| 504 | newSize.rwidth() = qMax(newSize.width(), 1); | - |
| 505 | newSize.rheight() = qMax(newSize.height(), 1); | - |
| 506 | if (newSize == size()) | - |
| 507 | return *this; | - |
| 508 | | - |
| 509 | QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), | - |
| 510 | (qreal)newSize.height() / height()); | - |
| 511 | QPixmap pix = transformed(wm, mode); | - |
| 512 | return pix; | - |
| 513 | } | - |
| 514 | QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const | - |
| 515 | { | - |
| 516 | if (isNull()) { | - |
| 517 | QMessageLogger("image/qpixmap.cpp", 11821184, __PRETTY_FUNCTION__).warning("QPixmap::scaleWidth: Pixmap is a null pixmap"); | - |
| 518 | return copy(); | - |
| 519 | } | - |
| 520 | if (w <= 0) | - |
| 521 | return QPixmap(); | - |
| 522 | | - |
| 523 | qreal factor = (qreal) w / width(); | - |
| 524 | QTransform wm = QTransform::fromScale(factor, factor); | - |
| 525 | return transformed(wm, mode); | - |
| 526 | } | - |
| 527 | QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const | - |
| 528 | { | - |
| 529 | if (isNull()) { | - |
| 530 | QMessageLogger("image/qpixmap.cpp", 12101212, __PRETTY_FUNCTION__).warning("QPixmap::scaleHeight: Pixmap is a null pixmap"); | - |
| 531 | return copy(); | - |
| 532 | } | - |
| 533 | if (h <= 0) | - |
| 534 | return QPixmap(); | - |
| 535 | | - |
| 536 | qreal factor = (qreal) h / height(); | - |
| 537 | QTransform wm = QTransform::fromScale(factor, factor); | - |
| 538 | return transformed(wm, mode); | - |
| 539 | } | - |
| 540 | QPixmap QPixmap::transformed(const QTransform &transform, | - |
| 541 | Qt::TransformationMode mode) const | - |
| 542 | { | - |
| 543 | if (isNull() || transform.type() <= QTransform::TxTranslate) | - |
| 544 | return *this; | - |
| 545 | | - |
| 546 | return data->transformed(transform, mode); | - |
| 547 | } | - |
| 548 | | - |
| 549 | | - |
| 550 | | - |
| 551 | | - |
| 552 | | - |
| 553 | | - |
| 554 | | - |
| 555 | QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const | - |
| 556 | { | - |
| 557 | return transformed(QTransform(matrix), mode); | - |
| 558 | } | - |
| 559 | bool QPixmap::hasAlpha() const | - |
| 560 | { | - |
| 561 | return data && data->hasAlphaChannel(); | - |
| 562 | } | - |
| 563 | | - |
| 564 | | - |
| 565 | | - |
| 566 | | - |
| 567 | | - |
| 568 | | - |
| 569 | | - |
| 570 | bool QPixmap::hasAlphaChannel() const | - |
| 571 | { | - |
| 572 | return data && data->hasAlphaChannel(); | - |
| 573 | } | - |
| 574 | | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | int QPixmap::metric(PaintDeviceMetric metric) const | - |
| 579 | { | - |
| 580 | return data ? data->metric(metric) : 0; | - |
| 581 | } | - |
| 582 | | - |
| 583 | | - |
| 584 | | - |
| 585 | | - |
| 586 | QPaintEngine *QPixmap::paintEngine() const | - |
| 587 | { | - |
| 588 | return data ? data->paintEngine() : 0; | - |
| 589 | } | - |
| 590 | QBitmap QPixmap::mask() const | - |
| 591 | { | - |
| 592 | if (!data || !hasAlphaChannel()) | - |
| 593 | return QBitmap(); | - |
| 594 | | - |
| 595 | const QImage img = toImage(); | - |
| 596 | const QImage image = (img.depth() < 32 ? img.convertToFormat(QImage::Format_ARGB32_Premultiplied) : img); | - |
| 597 | const int w = image.width(); | - |
| 598 | const int h = image.height(); | - |
| 599 | | - |
| 600 | QImage mask(w, h, QImage::Format_MonoLSB); | - |
| 601 | if (mask.isNull()) | - |
| 602 | return QBitmap(); | - |
| 603 | | - |
| 604 | mask.setColorCount(2); | - |
| 605 | mask.setColor(0, QColor(Qt::color0).rgba()); | - |
| 606 | mask.setColor(1, QColor(Qt::color1).rgba()); | - |
| 607 | | - |
| 608 | const int bpl = mask.bytesPerLine(); | - |
| 609 | | - |
| 610 | for (int y = 0; y < h; ++y) { | - |
| 611 | const QRgb *src = reinterpret_cast<const QRgb*>(image.scanLine(y)); | - |
| 612 | uchar *dest = mask.scanLine(y); | - |
| 613 | memset(dest, 0, bpl); | - |
| 614 | for (int x = 0; x < w; ++x) { | - |
| 615 | if (qAlpha(*src) > 0) | - |
| 616 | dest[x >> 3] |= (1 << (x & 7)); | - |
| 617 | ++src; | - |
| 618 | } | - |
| 619 | } | - |
| 620 | | - |
| 621 | return QBitmap::fromImage(mask); | - |
| 622 | } | - |
| 623 | int QPixmap::defaultDepth() | - |
| 624 | { | - |
| 625 | return QGuiApplication::primaryScreen()->depth(); | - |
| 626 | } | - |
| 627 | void QPixmap::detach() | - |
| 628 | { | - |
| 629 | if (!data) | - |
| 630 | return; | - |
| 631 | | - |
| 632 | | - |
| 633 | | - |
| 634 | QPlatformPixmap *pd = handle(); | - |
| 635 | QPlatformPixmap::ClassId id = pd->classId(); | - |
| 636 | if (id == QPlatformPixmap::RasterClass) { | - |
| 637 | QRasterPlatformPixmap *rasterData = static_cast<QRasterPlatformPixmap*>(pd); | - |
| 638 | rasterData->image.detach(); | - |
| 639 | } | - |
| 640 | | - |
| 641 | if (data->is_cached && data->ref.load() == 1) | - |
| 642 | QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data()); | - |
| 643 | | - |
| 644 | if (data->ref.load() != 1) { | - |
| 645 | *this = copy(); | - |
| 646 | } | - |
| 647 | ++data->detach_no; | - |
| 648 | } | - |
| 649 | QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) | - |
| 650 | { | - |
| 651 | if (image.isNull()) | - |
| 652 | return QPixmap(); | - |
| 653 | | - |
| 654 | QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); | - |
| 655 | data->fromImage(image, flags); | - |
| 656 | return QPixmap(data.take()); | - |
| 657 | } | - |
| 658 | QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) | - |
| 659 | { | - |
| 660 | QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); | - |
| 661 | data->fromImageReader(imageReader, flags); | - |
| 662 | return QPixmap(data.take()); | - |
| 663 | } | - |
| 664 | QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) | - |
| 665 | { | - |
| 666 | QMessageLogger("image/qpixmap.cpp", 16811683, __PRETTY_FUNCTION__).warning("%s is deprecated, use QScreen::grabWindow() instead." | - |
| 667 | " Defaulting to primary screen.", __PRETTY_FUNCTION__); | - |
| 668 | return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h); | - |
| 669 | } | - |
| 670 | | - |
| 671 | | - |
| 672 | | - |
| 673 | | - |
| 674 | QPlatformPixmap* QPixmap::handle() const | - |
| 675 | { | - |
| 676 | return data.data(); | - |
| 677 | } | - |
| 678 | | - |
| 679 | | - |
| 680 | QDebug operator<<(QDebug dbg, const QPixmap &r) | - |
| 681 | { | - |
| 682 | dbg.nospace() << "QPixmap(" << r.size() << ')'; | - |
| 683 | return dbg.space(); | - |
| 684 | } | - |
| 685 | | - |
| 686 | | - |
| | |