Changeset 561 for trunk/src/gui/image/qpixmap.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/image/qpixmap.cpp
r95 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 44 44 #include "qpixmap.h" 45 45 #include "qpixmapdata_p.h" 46 #include "qimagepixmapcleanuphooks_p.h" 46 47 47 48 #include "qbitmap.h" … … 77 78 #endif 78 79 80 #if defined(Q_OS_SYMBIAN) 81 # include <private/qt_s60_p.h> 82 #endif 83 79 84 #include "qpixmap_raster_p.h" 80 85 81 86 QT_BEGIN_NAMESPACE 82 83 // ### Qt 5: remove84 typedef void (*_qt_pixmap_cleanup_hook)(int);85 Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;86 87 // ### Qt 5: rename88 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);89 Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;90 87 91 88 // ### Qt 5: remove … … 117 114 void QPixmap::init(int w, int h, int type) 118 115 { 119 QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); 120 if (gs) 121 data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type)); 116 if ((w > 0 && h > 0) || type == QPixmapData::BitmapType) 117 data = QPixmapData::create(w, h, (QPixmapData::PixelType) type); 122 118 else 123 data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type)); 124 125 data->resize(w, h); 126 data->ref.ref(); 119 data = 0; 127 120 } 128 121 … … 226 219 : QPaintDevice(), data(d) 227 220 { 228 data->ref.ref();229 221 } 230 222 … … 282 274 } 283 275 if (pixmap.paintingActive()) { // make a deep copy 284 data = 0;285 276 operator=(pixmap.copy()); 286 277 } else { 287 278 data = pixmap.data; 288 data->ref.ref();289 279 } 290 280 } … … 315 305 QImage image(xpm); 316 306 if (!image.isNull()) { 317 if (data ->pixelType() == QPixmapData::BitmapType)307 if (data && data->pixelType() == QPixmapData::BitmapType) 318 308 *this = QBitmap::fromImage(image); 319 309 else … … 330 320 QPixmap::~QPixmap() 331 321 { 332 deref(); 322 Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again 323 if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns 324 QImagePixmapCleanupHooks::executePixmapDestructionHooks(this); 333 325 } 334 326 … … 366 358 return QPixmap(); 367 359 368 const QRect r = rect.isEmpty() ? QRect(0, 0, width(), height()) : rect; 369 370 QPixmapData *d; 371 QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); 372 if (gs) 373 d = gs->createPixmapData(data->pixelType()); 374 else 375 d = QGraphicsSystem::createDefaultPixmapData(data->pixelType()); 376 377 d->copy(data, r); 360 QRect r(0, 0, width(), height()); 361 if (!rect.isEmpty()) 362 r = r.intersected(rect); 363 364 QPixmapData *d = data->createCompatiblePixmapData(); 365 d->copy(data.data(), r); 378 366 return QPixmap(d); 367 } 368 369 /*! 370 \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed) 371 \since 4.6 372 373 This convenience function is equivalent to calling QPixmap::scroll(\a dx, 374 \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed). 375 376 \sa QWidget::scroll(), QGraphicsItem::scroll() 377 */ 378 379 /*! 380 \since 4.6 381 382 Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed 383 region is left unchanged. You can optionally pass a pointer to an empty 384 QRegion to get the region that is \a exposed by the scroll operation. 385 386 \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2 387 388 You cannot scroll while there is an active painter on the pixmap. 389 390 \sa QWidget::scroll(), QGraphicsItem::scroll() 391 */ 392 void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed) 393 { 394 if (isNull() || (dx == 0 && dy == 0)) 395 return; 396 QRect dest = rect & this->rect(); 397 QRect src = dest.translated(-dx, -dy) & dest; 398 if (src.isEmpty()) { 399 if (exposed) 400 *exposed += dest; 401 return; 402 } 403 404 detach(); 405 406 if (!data->scroll(dx, dy, src)) { 407 // Fallback 408 QPixmap pix = *this; 409 QPainter painter(&pix); 410 painter.setCompositionMode(QPainter::CompositionMode_Source); 411 painter.drawPixmap(src.translated(dx, dy), *this, src); 412 painter.end(); 413 *this = pix; 414 } 415 416 if (exposed) { 417 *exposed += dest; 418 *exposed -= src.translated(dx, dy); 419 } 379 420 } 380 421 … … 395 436 *this = pixmap.copy(); 396 437 } else { 397 pixmap.data->ref.ref(); // avoid 'x = x'398 deref();399 438 data = pixmap.data; 400 439 } … … 431 470 432 471 If the pixmap has 1-bit depth, the returned image will also be 1 433 bit deep. If the pixmap has 2- to 8-bit depth, the returned image 434 has 8-bit depth. If the pixmap has greater than 8-bit depth, the 435 returned image has 32-bit depth. 472 bit deep. Images with more bits will be returned in a format 473 closely represents the underlying system. Usually this will be 474 QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and 475 QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without 476 alpha. 436 477 437 478 Note that for the moment, alpha masks on monochrome images are … … 503 544 bool QPixmap::isNull() const 504 545 { 505 return data->width() == 0;546 return !data || data->isNull(); 506 547 } 507 548 … … 515 556 int QPixmap::width() const 516 557 { 517 return data ->width();558 return data ? data->width() : 0; 518 559 } 519 560 … … 527 568 int QPixmap::height() const 528 569 { 529 return data ->height();570 return data ? data->height() : 0; 530 571 } 531 572 … … 540 581 QSize QPixmap::size() const 541 582 { 542 return QSize(data->width(), data->height());583 return data ? QSize(data->width(), data->height()) : QSize(); 543 584 } 544 585 … … 552 593 QRect QPixmap::rect() const 553 594 { 554 return QRect(0, 0, data->width(), data->height());595 return data ? QRect(0, 0, data->width(), data->height()) : QRect(); 555 596 } 556 597 … … 568 609 int QPixmap::depth() const 569 610 { 570 return data ->depth();611 return data ? data->depth() : 0; 571 612 } 572 613 … … 598 639 599 640 // Create new pixmap 600 QPixmap pm(QSize(w, h), data ->type);641 QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType); 601 642 bool uninit = false; 602 643 #if defined(Q_WS_X11) 603 QX11PixmapData *x11Data = data ->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data) : 0;644 QX11PixmapData *x11Data = data && data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0; 604 645 if (x11Data) { 605 646 pm.x11SetScreen(x11Data->xinfo.screen()); 606 uninit = x11Data-> uninit;647 uninit = x11Data->flags & QX11PixmapData::Uninitialized; 607 648 } 608 649 #elif defined(Q_WS_MAC) 609 QMacPixmapData *macData = data ->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data) : 0;650 QMacPixmapData *macData = data && data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; 610 651 if (macData) 611 652 uninit = macData->uninit; … … 619 660 } 620 661 621 #if defined(Q_WS_MAC) 622 #ifndef QT_MAC_NO_QUICKDRAW 623 if(macData && macData->qd_alpha) 624 macData->macQDUpdateAlpha(); 625 #endif 626 #elif defined(Q_WS_X11) 662 #if defined(Q_WS_X11) 627 663 if (x11Data && x11Data->x11_mask) { 628 QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data );664 QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data()); 629 665 pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, 630 666 RootWindow(x11Data->xinfo.display(), … … 675 711 being painted on. 676 712 677 This is potentially an expensive operation.713 \warning This is potentially an expensive operation. 678 714 679 715 \sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations}, … … 691 727 return; 692 728 } 729 730 if (isNull()) 731 return; 693 732 694 733 if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask … … 790 829 QFileInfo info(fileName); 791 830 QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') + 792 QString::number(info.size()) + QLatin1Char('_') + QString::number(data->pixelType());831 QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType); 793 832 794 833 if (QPixmapCache::find(key, *this)) 795 834 return true; 796 835 797 QImage image = QImageReader(fileName, format).read(); 798 if (image.isNull()) 799 return false; 800 QPixmap pm; 801 if (data->pixelType() == QPixmapData::BitmapType) 802 pm = QBitmap::fromImage(image, flags); 803 else 804 pm = fromImage(image, flags); 805 if (!pm.isNull()) { 806 *this = pm; 836 QPixmapData *tmp = QPixmapData::create(0, 0, QPixmapData::PixmapType); 837 if (tmp->fromFile(fileName, format, flags)) { 838 data = tmp; 807 839 QPixmapCache::insert(key, *this); 808 840 return true; 809 841 } 842 delete tmp; 810 843 return false; 811 844 } … … 832 865 bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) 833 866 { 834 QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len); 835 QBuffer b(&a); 836 b.open(QIODevice::ReadOnly); 837 838 QImage image = QImageReader(&b, format).read(); 839 QPixmap pm; 840 if (data->pixelType() == QPixmapData::BitmapType) 841 pm = QBitmap::fromImage(image, flags); 842 else 843 pm = fromImage(image, flags); 844 if (!pm.isNull()) { 845 *this = pm; 846 return true; 847 } 848 return false; 867 if (len == 0 || buf == 0) 868 return false; 869 870 if (!data) 871 data = QPixmapData::create(0, 0, QPixmapData::PixmapType); 872 873 return data->fromData(buf, len, format, flags); 849 874 } 850 875 … … 930 955 Fills the pixmap with the given \a color. 931 956 957 The effect of this function is undefined when the pixmap is 958 being painted on. 959 932 960 \sa {QPixmap#Pixmap Transformations}{Pixmap Transformations} 933 961 */ … … 938 966 return; 939 967 940 detach(); 968 // Some people are probably already calling fill while a painter is active, so to not break 969 // their programs, only print a warning and return when the fill operation could cause a crash. 970 if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) { 971 qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on"); 972 return; 973 } 974 975 if (data->ref == 1) { 976 // detach() will also remove this pixmap from caches, so 977 // it has to be called even when ref == 1. 978 detach(); 979 } else { 980 // Don't bother to make a copy of the data object, since 981 // it will be filled with new pixel data anyway. 982 QPixmapData *d = data->createCompatiblePixmapData(); 983 d->resize(data->width(), data->height()); 984 data = d; 985 } 941 986 data->fill(color); 942 987 } … … 971 1016 qint64 QPixmap::cacheKey() const 972 1017 { 1018 if (isNull()) 1019 return 0; 1020 973 1021 int classKey = data->classId(); 974 1022 if (classKey >= 1024) … … 1119 1167 { 1120 1168 #if defined(Q_WS_X11) 1121 if (data ->classId() == QPixmapData::X11Class)1122 return static_cast< QX11PixmapData*>(data)->handle();1169 if (data && data->classId() == QPixmapData::X11Class) 1170 return static_cast<const QX11PixmapData*>(data.constData())->handle(); 1123 1171 #endif 1124 1172 return 0; … … 1170 1218 return; 1171 1219 1172 if (data ->pixelType() == QPixmapData::BitmapType)1220 if (data && data->pixelType() == QPixmapData::BitmapType) 1173 1221 *this = QBitmap::fromImage(image); 1174 1222 else … … 1187 1235 QPixmap &QPixmap::operator=(const QImage &image) 1188 1236 { 1189 if (data ->pixelType() == QPixmapData::BitmapType)1237 if (data && data->pixelType() == QPixmapData::BitmapType) 1190 1238 *this = QBitmap::fromImage(image); 1191 1239 else … … 1217 1265 bool QPixmap::convertFromImage(const QImage &image, ColorMode mode) 1218 1266 { 1219 if (data ->pixelType() == QPixmapData::BitmapType)1267 if (data && data->pixelType() == QPixmapData::BitmapType) 1220 1268 *this = QBitmap::fromImage(image, colorModeToFlags(mode)); 1221 1269 else … … 1233 1281 \relates QPixmap 1234 1282 1235 Writes the given \a pixmap to the thegiven \a stream as a PNG1283 Writes the given \a pixmap to the given \a stream as a PNG 1236 1284 image. Note that writing the stream to a file will not produce a 1237 1285 valid image file. … … 1268 1316 } 1269 1317 1270 #endif // QT_NO_DATASTREAM1318 #endif // QT_NO_DATASTREAM 1271 1319 1272 1320 #ifdef QT3_SUPPORT … … 1304 1352 bool QPixmap::isDetached() const 1305 1353 { 1306 return data->ref == 1; 1307 } 1308 1354 return data && data->ref == 1; 1355 } 1356 1357 /*! \internal 1358 ### Qt5 - remove me. 1359 */ 1309 1360 void QPixmap::deref() 1310 1361 { 1311 if (data && !data->ref.deref()) { // Destroy image if last ref 1312 #if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN) 1313 if (data->classId() == QPixmapData::RasterClass) { 1314 QRasterPixmapData *rData = static_cast<QRasterPixmapData*>(data); 1315 if (rData->texture) 1316 rData->texture->Release(); 1317 rData->texture = 0; 1318 } 1319 #endif 1320 if (data->is_cached && qt_pixmap_cleanup_hook_64) 1321 qt_pixmap_cleanup_hook_64(cacheKey()); 1322 delete data; 1323 data = 0; 1324 } 1362 Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!"); 1325 1363 } 1326 1364 … … 1381 1419 pixmap. 1382 1420 1421 1422 In some cases it can be more beneficial to draw the pixmap to a 1423 painter with a scale set rather than scaling the pixmap. This is 1424 the case when the painter is for instance based on OpenGL or when 1425 the scale factor changes rapidly. 1426 1383 1427 \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap 1384 1428 Transformations} … … 1399 1443 return *this; 1400 1444 1401 QPixmap pix; 1402 QTransform wm; 1403 wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); 1404 pix = transformed(wm, mode); 1445 QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), 1446 (qreal)newSize.height() / height()); 1447 QPixmap pix = transformed(wm, mode); 1405 1448 return pix; 1406 1449 } … … 1429 1472 return QPixmap(); 1430 1473 1431 QTransform wm;1432 1474 qreal factor = (qreal) w / width(); 1433 wm.scale(factor, factor);1475 QTransform wm = QTransform::fromScale(factor, factor); 1434 1476 return transformed(wm, mode); 1435 1477 } … … 1458 1500 return QPixmap(); 1459 1501 1460 QTransform wm;1461 1502 qreal factor = (qreal) h / height(); 1462 wm.scale(factor, factor);1503 QTransform wm = QTransform::fromScale(factor, factor); 1463 1504 return transformed(wm, mode); 1464 1505 } … … 1515 1556 that can be used as a paint device. 1516 1557 1517 \ingroup multimedia1558 \ingroup painting 1518 1559 \ingroup shared 1519 \mainclass 1560 1520 1561 1521 1562 Qt provides four classes for handling image data: QImage, QPixmap, … … 1525 1566 only a convenience class that inherits QPixmap, ensuring a depth 1526 1567 of 1. The isQBitmap() function returns true if a QPixmap object is 1527 really a bitmap, otherwise returns false. Finally, the QPicture class is a1528 paint device that records and replays QPainter commands.1568 really a bitmap, otherwise returns false. Finally, the QPicture class 1569 is a paint device that records and replays QPainter commands. 1529 1570 1530 1571 A QPixmap can easily be displayed on the screen using QLabel or 1531 1572 one of QAbstractButton's subclasses (such as QPushButton and 1532 1573 QToolButton). QLabel has a pixmap property, whereas 1533 QAbstractButton has an icon property. And because QPixmap is a 1534 QPaintDevice subclass, QPainter can be used to draw directly onto 1535 pixmaps. 1574 QAbstractButton has an icon property. 1536 1575 1537 1576 In addition to the ordinary constructors, a QPixmap can be 1538 1577 constructed using the static grabWidget() and grabWindow() 1539 1578 functions which creates a QPixmap and paints the given widget, or 1540 window, in it. 1541 1542 Note that the pixel data in a pixmap is internal and is managed by 1543 the underlying window system. Pixels can only be accessed through 1544 QPainter functions or by converting the QPixmap to a QImage. 1579 window, into it. 1580 1581 QPixmap objects can be passed around by value since the QPixmap 1582 class uses implicit data sharing. For more information, see the \l 1583 {Implicit Data Sharing} documentation. QPixmap objects can also be 1584 streamed. 1585 1545 1586 Depending on the system, QPixmap is stored using a RGB32 or a 1546 1587 premultiplied alpha format. If the image has an alpha channel, and 1547 1588 if the system allows, the preferred format is premultiplied alpha. 1548 1589 Note also that QPixmap, unlike QImage, may be hardware dependent. 1549 On X11 and Mac, a QPixmap is stored on the server side while a1550 QImage is stored on the client side (on Windows, these two classes1590 On X11, Mac and Symbian, a QPixmap is stored on the server side while 1591 a QImage is stored on the client side (on Windows, these two classes 1551 1592 have an equivalent internal representation, i.e. both QImage and 1552 1593 QPixmap are stored on the client side and don't use any GDI 1553 1594 resources). 1595 1596 Note that the pixel data in a pixmap is internal and is managed by 1597 the underlying window system. Because QPixmap is a QPaintDevice 1598 subclass, QPainter can be used to draw directly onto pixmaps. 1599 Pixels can only be accessed through QPainter functions or by 1600 converting the QPixmap to a QImage. However, the fill() function 1601 is available for initializing the entire pixmap with a given color. 1554 1602 1555 1603 There are functions to convert between QImage and … … 1560 1608 file can be loaded directly into a QPixmap. On Windows, the 1561 1609 QPixmap class also supports conversion between \c HBITMAP and 1562 QPixmap. 1610 QPixmap. On Symbian, the QPixmap class also supports conversion 1611 between CFbsBitmap and QPixmap. 1563 1612 1564 1613 QPixmap provides a collection of functions that can be used to … … 1566 1615 there are several functions that enables transformation of the 1567 1616 pixmap. 1568 1569 QPixmap objects can be passed around by value since the QPixmap1570 class uses implicit data sharing. For more information, see the \l1571 {Implicit Data Sharing} documentation. QPixmap objects can also be1572 streamed.1573 1617 1574 1618 \tableofcontents … … 1628 1672 respects the alpha channel, otherwise returns false, while the 1629 1673 hasAlpha() function returns true if the pixmap has an alpha 1630 channel \e or a mask (otherwise false). 1631 1632 The alphaChannel() function returns the alpha channel as a new 1633 QPixmap object, while the mask() function returns the mask as a 1634 QBitmap object. The alpha channel and mask can be set using the 1635 setAlphaChannel() and setMask() functions, respectively. 1636 1637 \row 1638 \o Low-level information 1639 \o 1640 1641 The depth() function returns the depth of the pixmap. The 1642 defaultDepth() function returns the default depth, i.e. the depth 1643 used by the application on the given screen. 1644 1645 The cacheKey() function returns a number that uniquely 1646 identifies the contents of the QPixmap object. 1647 1648 The x11Info() function returns information about the configuration 1649 of the X display used to display the widget. The 1650 x11PictureHandle() function returns the X11 Picture handle of the 1651 pixmap for XRender support. Note that the two latter functions are 1652 only available on x11. 1653 1654 \endtable 1655 1656 \section1 Pixmap Conversion 1657 1658 A QPixmap object can be converted into a QImage using the 1659 toImage() function. Likewise, a QImage can be converted into a 1660 QPixmap using the fromImage(). If this is too expensive an 1661 operation, you can use QBitmap::fromImage() instead. 1662 1663 In addition, on Windows, the QPixmap class supports conversion to 1664 and from HBitmap: the toWinHBITMAP() function creates a HBITMAP 1665 equivalent to the QPixmap, based on the given HBitmapFormat, and 1666 returns the HBITMAP handle. The fromWinHBITMAP() function returns 1667 a QPixmap that is equivalent to the given bitmap which has the 1668 specified format. 1669 1670 \section1 Pixmap Transformations 1671 1672 QPixmap supports a number of functions for creating a new pixmap 1673 that is a transformed version of the original: The 1674 createHeuristicMask() function creates and returns a 1-bpp 1674 channel \e or a mask (otherwise false). The mask() function returns 1675 the mask as a QBitmap object, which can be set using setMask(). 1676 1677 The createHeuristicMask() function creates and returns a 1-bpp 1675 1678 heuristic mask (i.e. a QBitmap) for this pixmap. It works by 1676 1679 selecting a color from one of the corners and then chipping away … … 1679 1682 QBitmap) for the pixmap based on a given color. 1680 1683 1684 \row 1685 \o Low-level information 1686 \o 1687 1688 The depth() function returns the depth of the pixmap. The 1689 defaultDepth() function returns the default depth, i.e. the depth 1690 used by the application on the given screen. 1691 1692 The cacheKey() function returns a number that uniquely 1693 identifies the contents of the QPixmap object. 1694 1695 The x11Info() function returns information about the configuration 1696 of the X display used by the screen to which the pixmap currently 1697 belongs. The x11PictureHandle() function returns the X11 Picture 1698 handle of the pixmap for XRender support. Note that the two latter 1699 functions are only available on x11. 1700 1701 \endtable 1702 1703 \section1 Pixmap Conversion 1704 1705 A QPixmap object can be converted into a QImage using the 1706 toImage() function. Likewise, a QImage can be converted into a 1707 QPixmap using the fromImage(). If this is too expensive an 1708 operation, you can use QBitmap::fromImage() instead. 1709 1710 In addition, on Windows, the QPixmap class supports conversion to 1711 and from HBITMAP: the toWinHBITMAP() function creates a HBITMAP 1712 equivalent to the QPixmap, based on the given HBitmapFormat, and 1713 returns the HBITMAP handle. The fromWinHBITMAP() function returns 1714 a QPixmap that is equivalent to the given bitmap which has the 1715 specified format. The QPixmap class also supports conversion to 1716 and from HICON: the toWinHICON() function creates a HICON equivalent 1717 to the QPixmap, and returns the HICON handle. The fromWinHICON() 1718 function returns a QPixmap that is equivalent to the given icon. 1719 1720 In addition, on Symbian, the QPixmap class supports conversion to 1721 and from CFbsBitmap: the toSymbianCFbsBitmap() function creates 1722 CFbsBitmap equivalent to the QPixmap, based on given mode and returns 1723 a CFbsBitmap object. The fromSymbianCFbsBitmap() function returns a 1724 QPixmap that is equivalent to the given bitmap and given mode. 1725 1726 \section1 Pixmap Transformations 1727 1728 QPixmap supports a number of functions for creating a new pixmap 1729 that is a transformed version of the original: 1681 1730 1682 1731 The scaled(), scaledToWidth() and scaledToHeight() functions … … 1693 1742 pixmap. 1694 1743 1695 There are also functions for changing attributes of a pixmap.1696 in-place: The fill() function fills the entire image with the1697 given color, the setMask() function sets a mask bitmap, and the1698 setAlphaChannel() function sets the pixmap's alpha channel.1699 1700 1744 \sa QBitmap, QImage, QImageReader, QImageWriter 1701 1745 */ … … 1716 1760 mask, otherwise returns false. 1717 1761 1718 \sa hasAlphaChannel(), alphaChannel(),mask()1762 \sa hasAlphaChannel(), mask() 1719 1763 */ 1720 1764 bool QPixmap::hasAlpha() const 1721 1765 { 1722 return (data->hasAlphaChannel() || !data->mask().isNull());1766 return data && (data->hasAlphaChannel() || !data->mask().isNull()); 1723 1767 } 1724 1768 … … 1727 1771 channel, otherwise returns false. 1728 1772 1729 \sa alphaChannel(),hasAlpha()1773 \sa hasAlpha() 1730 1774 */ 1731 1775 bool QPixmap::hasAlphaChannel() const 1732 1776 { 1733 return data ->hasAlphaChannel();1734 } 1735 1736 /*! 1737 \reimp1777 return data && data->hasAlphaChannel(); 1778 } 1779 1780 /*! 1781 \internal 1738 1782 */ 1739 1783 int QPixmap::metric(PaintDeviceMetric metric) const 1740 1784 { 1741 return data ->metric(metric);1785 return data ? data->metric(metric) : 0; 1742 1786 } 1743 1787 1744 1788 /*! 1745 1789 \fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) 1790 \obsolete 1746 1791 1747 1792 Sets the alpha channel of this pixmap to the given \a alphaChannel … … 1751 1796 The effect of this function is undefined when the pixmap is being 1752 1797 painted on. 1798 1799 \warning This is potentially an expensive operation. Most usecases 1800 for this function are covered by QPainter and compositionModes 1801 which will normally execute faster. 1753 1802 1754 1803 \sa alphaChannel(), {QPixmap#Pixmap Transformations}{Pixmap … … 1777 1826 1778 1827 /*! 1828 \obsolete 1829 1779 1830 Returns the alpha channel of the pixmap as a new grayscale QPixmap in which 1780 1831 each pixel's red, green, and blue values are given the alpha value of the … … 1794 1845 \image alphachannelimage.png The pixmap and channelImage QPixmaps 1795 1846 1847 \warning This is an expensive operation. The alpha channel of the 1848 pixmap is extracted dynamically from the pixeldata. Most usecases of this 1849 function are covered by QPainter and compositionModes which will normally 1850 execute faster. 1851 1796 1852 \sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap 1797 1853 Information} … … 1799 1855 QPixmap QPixmap::alphaChannel() const 1800 1856 { 1801 return data ->alphaChannel();1802 } 1803 1804 /*! 1805 \reimp1857 return data ? data->alphaChannel() : QPixmap(); 1858 } 1859 1860 /*! 1861 \internal 1806 1862 */ 1807 1863 QPaintEngine *QPixmap::paintEngine() const 1808 1864 { 1809 return data ->paintEngine();1865 return data ? data->paintEngine() : 0; 1810 1866 } 1811 1867 … … 1813 1869 \fn QBitmap QPixmap::mask() const 1814 1870 1815 Extracts a bitmap mask from the pixmap's alphachannel. 1816 1817 This is potentially an expensive operation. 1871 Extracts a bitmap mask from the pixmap's alpha channel. 1872 1873 \warning This is potentially an expensive operation. The mask of 1874 the pixmap is extracted dynamically from the pixeldata. 1818 1875 1819 1876 \sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information} … … 1821 1878 QBitmap QPixmap::mask() const 1822 1879 { 1823 return data ->mask();1880 return data ? data->mask() : QBitmap(); 1824 1881 } 1825 1882 … … 1840 1897 #elif defined(Q_WS_X11) 1841 1898 return QX11Info::appDepth(); 1842 #elif defined(Q_ OS_WINCE)1899 #elif defined(Q_WS_WINCE) 1843 1900 return QColormap::instance().depth(); 1844 1901 #elif defined(Q_WS_WIN) … … 1848 1905 #elif defined(Q_WS_MAC) 1849 1906 return 32; 1907 #elif defined(Q_OS_SYMBIAN) 1908 return S60->screenDepth; 1850 1909 #endif 1851 1910 } 1852 1853 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);1854 extern _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64;1855 1911 1856 1912 /*! … … 1873 1929 void QPixmap::detach() 1874 1930 { 1931 if (!data) 1932 return; 1933 1875 1934 QPixmapData::ClassId id = data->classId(); 1876 1935 if (id == QPixmapData::RasterClass) { 1877 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data );1936 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); 1878 1937 rasterData->image.detach(); 1879 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D) 1880 if (rasterData->texture) { 1881 rasterData->texture->Release(); 1882 rasterData->texture = 0; 1883 } 1884 #endif 1885 } 1886 1887 if (data->is_cached && qt_pixmap_cleanup_hook_64 && data->ref == 1) 1888 qt_pixmap_cleanup_hook_64(cacheKey()); 1938 } 1939 1940 if (data->is_cached && data->ref == 1) 1941 QImagePixmapCleanupHooks::executePixmapModificationHooks(this); 1889 1942 1890 1943 #if defined(Q_WS_MAC) 1891 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data ) : 0;1944 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; 1892 1945 if (macData) { 1893 1946 if (macData->cg_mask) { … … 1900 1953 if (data->ref != 1) { 1901 1954 *this = copy(); 1902 #if defined(Q_WS_MAC) && !defined(QT_MAC_NO_QUICKDRAW)1903 if (id == QPixmapData::MacClass) {1904 macData->qd_alpha = 0;1905 }1906 #endif1907 1955 } 1908 1956 ++data->detach_no; … … 1910 1958 #if defined(Q_WS_X11) 1911 1959 if (data->classId() == QPixmapData::X11Class) { 1912 QX11PixmapData *d = static_cast<QX11PixmapData*>(data );1913 d-> uninit = false;1960 QX11PixmapData *d = static_cast<QX11PixmapData*>(data.data()); 1961 d->flags &= ~QX11PixmapData::Uninitialized; 1914 1962 1915 1963 // reset the cache data … … 1947 1995 return QPixmap(); 1948 1996 1949 QPixmapData *data;1950 1997 QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); 1951 if (gs) 1952 data = gs->createPixmapData(QPixmapData::PixmapType); 1953 else 1954 data = QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType); 1955 1998 QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType) 1999 : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType)); 1956 2000 data->fromImage(image, flags); 1957 return QPixmap(data );2001 return QPixmap(data.take()); 1958 2002 } 1959 2003 … … 2000 2044 QPixmapData* QPixmap::pixmapData() const 2001 2045 { 2002 return data; 2003 } 2046 return data.data(); 2047 } 2048 2049 /*! 2050 \enum QPixmap::HBitmapFormat 2051 2052 \bold{Win32 only:} This enum defines how the conversion between \c 2053 HBITMAP and QPixmap is performed. 2054 2055 \warning This enum is only available on Windows. 2056 2057 \value NoAlpha The alpha channel is ignored and always treated as 2058 being set to fully opaque. This is preferred if the \c HBITMAP is 2059 used with standard GDI calls, such as \c BitBlt(). 2060 2061 \value PremultipliedAlpha The \c HBITMAP is treated as having an 2062 alpha channel and premultiplied colors. This is preferred if the 2063 \c HBITMAP is accessed through the \c AlphaBlend() GDI function. 2064 2065 \value Alpha The \c HBITMAP is treated as having a plain alpha 2066 channel. This is the preferred format if the \c HBITMAP is going 2067 to be used as an application icon or systray icon. 2068 2069 \sa fromWinHBITMAP(), toWinHBITMAP() 2070 */ 2071 2072 /*! \fn HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const 2073 \bold{Win32 only:} Creates a \c HBITMAP equivalent to the QPixmap, 2074 based on the given \a format. Returns the \c HBITMAP handle. 2075 2076 It is the caller's responsibility to free the \c HBITMAP data 2077 after use. 2078 2079 \warning This function is only available on Windows. 2080 2081 \sa fromWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2082 */ 2083 2084 /*! \fn QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) 2085 \bold{Win32 only:} Returns a QPixmap that is equivalent to the 2086 given \a bitmap. The conversion is based on the specified \a 2087 format. 2088 2089 \warning This function is only available on Windows. 2090 2091 \sa toWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2092 2093 */ 2094 2095 /*! \fn HICON QPixmap::toWinHICON() const 2096 \since 4.6 2097 2098 \bold{Win32 only:} Creates a \c HICON equivalent to the QPixmap. 2099 Returns the \c HICON handle. 2100 2101 It is the caller's responsibility to free the \c HICON data after use. 2102 2103 \warning This function is only available on Windows. 2104 2105 \sa fromWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2106 */ 2107 2108 /*! \fn QPixmap QPixmap::fromWinHICON(HICON icon) 2109 \since 4.6 2110 2111 \bold{Win32 only:} Returns a QPixmap that is equivalent to the given 2112 \a icon. 2113 2114 \warning This function is only available on Windows. 2115 2116 \sa toWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2117 2118 */ 2119 2120 /*! \fn const QX11Info &QPixmap::x11Info() const 2121 \bold{X11 only:} Returns information about the configuration of 2122 the X display used by the screen to which the pixmap currently belongs. 2123 2124 \warning This function is only available on X11. 2125 2126 \sa {QPixmap#Pixmap Information}{Pixmap Information} 2127 */ 2128 2129 /*! \fn Qt::HANDLE QPixmap::x11PictureHandle() const 2130 \bold{X11 only:} Returns the X11 Picture handle of the pixmap for 2131 XRender support. 2132 2133 This function will return 0 if XRender support is not compiled 2134 into Qt, if the XRender extension is not supported on the X11 2135 display, or if the handle could not be created. Use of this 2136 function is not portable. 2137 2138 \warning This function is only available on X11. 2139 2140 \sa {QPixmap#Pixmap Information}{Pixmap Information} 2141 */ 2142 2143 /*! \fn int QPixmap::x11SetDefaultScreen(int screen) 2144 \internal 2145 */ 2146 2147 /*! \fn void QPixmap::x11SetScreen(int screen) 2148 \internal 2149 */ 2150 2151 /*! \fn QRgb* QPixmap::clut() const 2152 \internal 2153 */ 2154 2155 /*! \fn int QPixmap::numCols() const 2156 \obsolete 2157 \internal 2158 \sa colorCount() 2159 */ 2160 2161 /*! \fn int QPixmap::colorCount() const 2162 \since 4.6 2163 \internal 2164 */ 2165 2166 /*! \fn const uchar* QPixmap::qwsBits() const 2167 \internal 2168 \since 4.1 2169 */ 2170 2171 /*! \fn int QPixmap::qwsBytesPerLine() const 2172 \internal 2173 \since 4.1 2174 */ 2004 2175 2005 2176 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.