Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qpixmap.cpp

    r95 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    4444#include "qpixmap.h"
    4545#include "qpixmapdata_p.h"
     46#include "qimagepixmapcleanuphooks_p.h"
    4647
    4748#include "qbitmap.h"
     
    7778#endif
    7879
     80#if defined(Q_OS_SYMBIAN)
     81# include <private/qt_s60_p.h>
     82#endif
     83
    7984#include "qpixmap_raster_p.h"
    8085
    8186QT_BEGIN_NAMESPACE
    82 
    83 // ### Qt 5: remove
    84 typedef void (*_qt_pixmap_cleanup_hook)(int);
    85 Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;
    86 
    87 // ### Qt 5: rename
    88 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
    89 Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;
    9087
    9188// ### Qt 5: remove
     
    117114void QPixmap::init(int w, int h, int type)
    118115{
    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);
    122118    else
    123         data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
    124 
    125     data->resize(w, h);
    126     data->ref.ref();
     119        data = 0;
    127120}
    128121
     
    226219    : QPaintDevice(), data(d)
    227220{
    228     data->ref.ref();
    229221}
    230222
     
    282274    }
    283275    if (pixmap.paintingActive()) {                // make a deep copy
    284         data = 0;
    285276        operator=(pixmap.copy());
    286277    } else {
    287278        data = pixmap.data;
    288         data->ref.ref();
    289279    }
    290280}
     
    315305    QImage image(xpm);
    316306    if (!image.isNull()) {
    317         if (data->pixelType() == QPixmapData::BitmapType)
     307        if (data && data->pixelType() == QPixmapData::BitmapType)
    318308            *this = QBitmap::fromImage(image);
    319309        else
     
    330320QPixmap::~QPixmap()
    331321{
    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);
    333325}
    334326
     
    366358        return QPixmap();
    367359
    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);
    378366    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*/
     392void 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    }
    379420}
    380421
     
    395436        *this = pixmap.copy();
    396437    } else {
    397         pixmap.data->ref.ref();                                // avoid 'x = x'
    398         deref();
    399438        data = pixmap.data;
    400439    }
     
    431470
    432471    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.
    436477
    437478    Note that for the moment, alpha masks on monochrome images are
     
    503544bool QPixmap::isNull() const
    504545{
    505     return data->width() == 0;
     546    return !data || data->isNull();
    506547}
    507548
     
    515556int QPixmap::width() const
    516557{
    517     return data->width();
     558    return data ? data->width() : 0;
    518559}
    519560
     
    527568int QPixmap::height() const
    528569{
    529     return data->height();
     570    return data ? data->height() : 0;
    530571}
    531572
     
    540581QSize QPixmap::size() const
    541582{
    542     return QSize(data->width(), data->height());
     583    return data ? QSize(data->width(), data->height()) : QSize();
    543584}
    544585
     
    552593QRect QPixmap::rect() const
    553594{
    554     return QRect(0, 0, data->width(), data->height());
     595    return data ? QRect(0, 0, data->width(), data->height()) : QRect();
    555596}
    556597
     
    568609int QPixmap::depth() const
    569610{
    570     return data->depth();
     611    return data ? data->depth() : 0;
    571612}
    572613
     
    598639
    599640    // Create new pixmap
    600     QPixmap pm(QSize(w, h), data->type);
     641    QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType);
    601642    bool uninit = false;
    602643#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;
    604645    if (x11Data) {
    605646        pm.x11SetScreen(x11Data->xinfo.screen());
    606         uninit = x11Data->uninit;
     647        uninit = x11Data->flags & QX11PixmapData::Uninitialized;
    607648    }
    608649#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;
    610651    if (macData)
    611652        uninit = macData->uninit;
     
    619660    }
    620661
    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)
    627663    if (x11Data && x11Data->x11_mask) {
    628         QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data);
     664        QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data());
    629665        pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display,
    630666                                                     RootWindow(x11Data->xinfo.display(),
     
    675711    being painted on.
    676712
    677     This is potentially an expensive operation.
     713    \warning This is potentially an expensive operation.
    678714
    679715    \sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations},
     
    691727        return;
    692728    }
     729
     730    if (isNull())
     731        return;
    693732
    694733    if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask
     
    790829    QFileInfo info(fileName);
    791830    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);
    793832
    794833    if (QPixmapCache::find(key, *this))
    795834        return true;
    796835
    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;
    807839        QPixmapCache::insert(key, *this);
    808840        return true;
    809841    }
     842    delete tmp;
    810843    return false;
    811844}
     
    832865bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
    833866{
    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);
    849874}
    850875
     
    930955    Fills the pixmap with the given \a color.
    931956
     957    The effect of this function is undefined when the pixmap is
     958    being painted on.
     959
    932960    \sa {QPixmap#Pixmap Transformations}{Pixmap Transformations}
    933961*/
     
    938966        return;
    939967
    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    }
    941986    data->fill(color);
    942987}
     
    9711016qint64 QPixmap::cacheKey() const
    9721017{
     1018    if (isNull())
     1019        return 0;
     1020
    9731021    int classKey = data->classId();
    9741022    if (classKey >= 1024)
     
    11191167{
    11201168#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();
    11231171#endif
    11241172    return 0;
     
    11701218        return;
    11711219
    1172     if (data->pixelType() == QPixmapData::BitmapType)
     1220    if (data && data->pixelType() == QPixmapData::BitmapType)
    11731221        *this = QBitmap::fromImage(image);
    11741222    else
     
    11871235QPixmap &QPixmap::operator=(const QImage &image)
    11881236{
    1189     if (data->pixelType() == QPixmapData::BitmapType)
     1237    if (data && data->pixelType() == QPixmapData::BitmapType)
    11901238        *this = QBitmap::fromImage(image);
    11911239    else
     
    12171265bool QPixmap::convertFromImage(const QImage &image, ColorMode mode)
    12181266{
    1219     if (data->pixelType() == QPixmapData::BitmapType)
     1267    if (data && data->pixelType() == QPixmapData::BitmapType)
    12201268        *this = QBitmap::fromImage(image, colorModeToFlags(mode));
    12211269    else
     
    12331281    \relates QPixmap
    12341282
    1235     Writes the given \a pixmap to the the given \a stream as a PNG
     1283    Writes the given \a pixmap to the given \a stream as a PNG
    12361284    image. Note that writing the stream to a file will not produce a
    12371285    valid image file.
     
    12681316}
    12691317
    1270 #endif //QT_NO_DATASTREAM
     1318#endif // QT_NO_DATASTREAM
    12711319
    12721320#ifdef QT3_SUPPORT
     
    13041352bool QPixmap::isDetached() const
    13051353{
    1306     return data->ref == 1;
    1307 }
    1308 
     1354    return data && data->ref == 1;
     1355}
     1356
     1357/*! \internal
     1358  ### Qt5 - remove me.
     1359*/
    13091360void QPixmap::deref()
    13101361{
    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!");
    13251363}
    13261364
     
    13811419    pixmap.
    13821420
     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
    13831427    \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap
    13841428    Transformations}
     
    13991443        return *this;
    14001444
    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);
    14051448    return pix;
    14061449}
     
    14291472        return QPixmap();
    14301473
    1431     QTransform wm;
    14321474    qreal factor = (qreal) w / width();
    1433     wm.scale(factor, factor);
     1475    QTransform wm = QTransform::fromScale(factor, factor);
    14341476    return transformed(wm, mode);
    14351477}
     
    14581500        return QPixmap();
    14591501
    1460     QTransform wm;
    14611502    qreal factor = (qreal) h / height();
    1462     wm.scale(factor, factor);
     1503    QTransform wm = QTransform::fromScale(factor, factor);
    14631504    return transformed(wm, mode);
    14641505}
     
    15151556    that can be used as a paint device.
    15161557
    1517     \ingroup multimedia
     1558    \ingroup painting
    15181559    \ingroup shared
    1519     \mainclass
     1560
    15201561
    15211562    Qt provides four classes for handling image data: QImage, QPixmap,
     
    15251566    only a convenience class that inherits QPixmap, ensuring a depth
    15261567    of 1. The isQBitmap() function returns true if a QPixmap object is
    1527     really a bitmap, otherwise returns false. Finally, the QPicture class is a
    1528     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.
    15291570
    15301571    A QPixmap can easily be displayed on the screen using QLabel or
    15311572    one of QAbstractButton's subclasses (such as QPushButton and
    15321573    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.
    15361575
    15371576    In addition to the ordinary constructors, a QPixmap can be
    15381577    constructed using the static grabWidget() and grabWindow()
    15391578    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
    15451586    Depending on the system, QPixmap is stored using a RGB32 or a
    15461587    premultiplied alpha format. If the image has an alpha channel, and
    15471588    if the system allows, the preferred format is premultiplied alpha.
    15481589    Note also that QPixmap, unlike QImage, may be hardware dependent.
    1549     On X11 and Mac, a QPixmap is stored on the server side while a
    1550     QImage is stored on the client side (on Windows, these two classes
     1590    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
    15511592    have an equivalent internal representation, i.e. both QImage and
    15521593    QPixmap are stored on the client side and don't use any GDI
    15531594    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.
    15541602
    15551603    There are functions to convert between QImage and
     
    15601608    file can be loaded directly into a QPixmap. On Windows, the
    15611609    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.
    15631612
    15641613    QPixmap provides a collection of functions that can be used to
     
    15661615    there are several functions that enables transformation of the
    15671616    pixmap.
    1568 
    1569     QPixmap objects can be passed around by value since the QPixmap
    1570     class uses implicit data sharing. For more information, see the \l
    1571     {Implicit Data Sharing} documentation. QPixmap objects can also be
    1572     streamed.
    15731617
    15741618    \tableofcontents
     
    16281672    respects the alpha channel, otherwise returns false, while the
    16291673    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
    16751678    heuristic mask (i.e. a QBitmap) for this pixmap. It works by
    16761679    selecting a color from one of the corners and then chipping away
     
    16791682    QBitmap) for the pixmap based on a given color.
    16801683
     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:
    16811730
    16821731    The scaled(), scaledToWidth() and scaledToHeight() functions
     
    16931742    pixmap.
    16941743
    1695     There are also functions for changing attributes of a pixmap.
    1696     in-place: The fill() function fills the entire image with the
    1697     given color, the setMask() function sets a mask bitmap, and the
    1698     setAlphaChannel() function sets the pixmap's alpha channel.
    1699 
    17001744    \sa QBitmap, QImage, QImageReader, QImageWriter
    17011745*/
     
    17161760    mask, otherwise returns false.
    17171761
    1718     \sa hasAlphaChannel(), alphaChannel(), mask()
     1762    \sa hasAlphaChannel(), mask()
    17191763*/
    17201764bool QPixmap::hasAlpha() const
    17211765{
    1722     return (data->hasAlphaChannel() || !data->mask().isNull());
     1766    return data && (data->hasAlphaChannel() || !data->mask().isNull());
    17231767}
    17241768
     
    17271771    channel, otherwise returns false.
    17281772
    1729     \sa alphaChannel(), hasAlpha()
     1773    \sa hasAlpha()
    17301774*/
    17311775bool QPixmap::hasAlphaChannel() const
    17321776{
    1733     return data->hasAlphaChannel();
    1734 }
    1735 
    1736 /*!
    1737   \reimp
     1777    return data && data->hasAlphaChannel();
     1778}
     1779
     1780/*!
     1781    \internal
    17381782*/
    17391783int QPixmap::metric(PaintDeviceMetric metric) const
    17401784{
    1741     return data->metric(metric);
     1785    return data ? data->metric(metric) : 0;
    17421786}
    17431787
    17441788/*!
    17451789    \fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel)
     1790    \obsolete
    17461791
    17471792    Sets the alpha channel of this pixmap to the given \a alphaChannel
     
    17511796    The effect of this function is undefined when the pixmap is being
    17521797    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.
    17531802
    17541803    \sa alphaChannel(), {QPixmap#Pixmap Transformations}{Pixmap
     
    17771826
    17781827/*!
     1828    \obsolete
     1829
    17791830    Returns the alpha channel of the pixmap as a new grayscale QPixmap in which
    17801831    each pixel's red, green, and blue values are given the alpha value of the
     
    17941845    \image alphachannelimage.png The pixmap and channelImage QPixmaps
    17951846
     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
    17961852    \sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap
    17971853    Information}
     
    17991855QPixmap QPixmap::alphaChannel() const
    18001856{
    1801     return data->alphaChannel();
    1802 }
    1803 
    1804 /*!
    1805   \reimp
     1857    return data ? data->alphaChannel() : QPixmap();
     1858}
     1859
     1860/*!
     1861    \internal
    18061862*/
    18071863QPaintEngine *QPixmap::paintEngine() const
    18081864{
    1809     return data->paintEngine();
     1865    return data ? data->paintEngine() : 0;
    18101866}
    18111867
     
    18131869    \fn QBitmap QPixmap::mask() const
    18141870
    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.
    18181875
    18191876    \sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information}
     
    18211878QBitmap QPixmap::mask() const
    18221879{
    1823     return data->mask();
     1880    return data ? data->mask() : QBitmap();
    18241881}
    18251882
     
    18401897#elif defined(Q_WS_X11)
    18411898    return QX11Info::appDepth();
    1842 #elif defined(Q_OS_WINCE)
     1899#elif defined(Q_WS_WINCE)
    18431900    return QColormap::instance().depth();
    18441901#elif defined(Q_WS_WIN)
     
    18481905#elif defined(Q_WS_MAC)
    18491906    return 32;
     1907#elif defined(Q_OS_SYMBIAN)
     1908    return S60->screenDepth;
    18501909#endif
    18511910}
    1852 
    1853 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
    1854 extern _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64;
    18551911
    18561912/*!
     
    18731929void QPixmap::detach()
    18741930{
     1931    if (!data)
     1932        return;
     1933
    18751934    QPixmapData::ClassId id = data->classId();
    18761935    if (id == QPixmapData::RasterClass) {
    1877         QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data);
     1936        QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
    18781937        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);
    18891942
    18901943#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;
    18921945    if (macData) {
    18931946        if (macData->cg_mask) {
     
    19001953    if (data->ref != 1) {
    19011954        *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 #endif
    19071955    }
    19081956    ++data->detach_no;
     
    19101958#if defined(Q_WS_X11)
    19111959    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;
    19141962
    19151963        // reset the cache data
     
    19471995        return QPixmap();
    19481996
    1949     QPixmapData *data;
    19501997    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));
    19562000    data->fromImage(image, flags);
    1957     return QPixmap(data);
     2001    return QPixmap(data.take());
    19582002}
    19592003
     
    20002044QPixmapData* QPixmap::pixmapData() const
    20012045{
    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*/
    20042175
    20052176QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.