~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/image/qpixmap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the QtGui module of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
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.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
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
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
43
43
 
44
44
#include "qpixmap.h"
45
45
#include "qpixmapdata_p.h"
 
46
#include "qimagepixmapcleanuphooks_p.h"
46
47
 
47
48
#include "qbitmap.h"
48
49
#include "qcolormap.h"
76
77
# include <private/qpixmap_x11_p.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
87
 
83
88
// ### 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;
90
 
 
91
 
// ### Qt 5: remove
92
89
Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap)
93
90
{
94
91
    return pixmap.cacheKey();
123
120
        data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
124
121
 
125
122
    data->resize(w, h);
126
 
    data->ref.ref();
127
123
}
128
124
 
129
125
/*!
225
221
QPixmap::QPixmap(QPixmapData *d)
226
222
    : QPaintDevice(), data(d)
227
223
{
228
 
    data->ref.ref();
229
224
}
230
225
 
231
226
/*!
281
276
        return;
282
277
    }
283
278
    if (pixmap.paintingActive()) {                // make a deep copy
284
 
        data = 0;
285
279
        operator=(pixmap.copy());
286
280
    } else {
287
281
        data = pixmap.data;
288
 
        data->ref.ref();
289
282
    }
290
283
}
291
284
 
329
322
 
330
323
QPixmap::~QPixmap()
331
324
{
332
 
    deref();
 
325
    if (data->is_cached && data->ref == 1)
 
326
        QImagePixmapCleanupHooks::executePixmapHooks(this);
333
327
}
334
328
 
335
329
/*!
374
368
    else
375
369
        d = QGraphicsSystem::createDefaultPixmapData(data->pixelType());
376
370
 
377
 
    d->copy(data, r);
 
371
    d->copy(data.data(), r);
378
372
    return QPixmap(d);
379
373
}
380
374
 
381
375
/*!
 
376
    \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed)
 
377
    \since 4.6
 
378
 
 
379
    This convenience function is equivalent to calling QPixmap::scroll(\a dx,
 
380
    \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed).
 
381
 
 
382
    \sa QWidget::scroll(), QGraphicsItem::scroll()
 
383
*/
 
384
 
 
385
/*!
 
386
    \since 4.6
 
387
 
 
388
    Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed
 
389
    region is left unchanged. You can optionally pass a pointer to an empty
 
390
    QRegion to get the region that is \a exposed by the scroll operation.
 
391
 
 
392
    \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2
 
393
 
 
394
    You cannot scroll while there is an active painter on the pixmap.
 
395
 
 
396
    \sa QWidget::scroll(), QGraphicsItem::scroll()
 
397
*/
 
398
void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed)
 
399
{
 
400
    if (isNull() || (dx == 0 && dy == 0))
 
401
        return;
 
402
    QRect dest = rect & this->rect();
 
403
    QRect src = dest.translated(-dx, -dy) & dest;
 
404
    if (src.isEmpty()) {
 
405
        if (exposed)
 
406
            *exposed += dest;
 
407
        return;
 
408
    }
 
409
 
 
410
    detach();
 
411
 
 
412
    if (!data->scroll(dx, dy, src)) {
 
413
        // Fallback
 
414
        QPixmap pix = *this;
 
415
        QPainter painter(&pix);
 
416
        painter.setCompositionMode(QPainter::CompositionMode_Source);
 
417
        painter.drawPixmap(src.translated(dx, dy), *this, src);
 
418
        painter.end();
 
419
        *this = pix;
 
420
    }
 
421
 
 
422
    if (exposed) {
 
423
        *exposed += dest;
 
424
        *exposed -= src.translated(dx, dy);
 
425
    }
 
426
}
 
427
 
 
428
/*!
382
429
    Assigns the given \a pixmap to this pixmap and returns a reference
383
430
    to this pixmap.
384
431
 
394
441
    if (pixmap.paintingActive()) {                // make a deep copy
395
442
        *this = pixmap.copy();
396
443
    } else {
397
 
        pixmap.data->ref.ref();                                // avoid 'x = x'
398
 
        deref();
399
444
        data = pixmap.data;
400
445
    }
401
446
    return *this;
502
547
*/
503
548
bool QPixmap::isNull() const
504
549
{
505
 
    return data->width() == 0;
 
550
    return data->isNull();
506
551
}
507
552
 
508
553
/*!
600
645
    QPixmap pm(QSize(w, h), data->type);
601
646
    bool uninit = false;
602
647
#if defined(Q_WS_X11)
603
 
    QX11PixmapData *x11Data = data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data) : 0;
 
648
    QX11PixmapData *x11Data = data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0;
604
649
    if (x11Data) {
605
650
        pm.x11SetScreen(x11Data->xinfo.screen());
606
 
        uninit = x11Data->uninit;
 
651
        uninit = x11Data->flags & QX11PixmapData::Uninitialized;
607
652
    }
608
653
#elif defined(Q_WS_MAC)
609
 
    QMacPixmapData *macData = data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data) : 0;
 
654
    QMacPixmapData *macData = data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
610
655
    if (macData)
611
656
        uninit = macData->uninit;
612
657
#endif
618
663
        p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h));
619
664
    }
620
665
 
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)
 
666
#if defined(Q_WS_X11)
627
667
    if (x11Data && x11Data->x11_mask) {
628
 
        QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data);
 
668
        QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data());
629
669
        pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display,
630
670
                                                     RootWindow(x11Data->xinfo.display(),
631
671
                                                                x11Data->xinfo.screen()),
794
834
    if (QPixmapCache::find(key, *this))
795
835
        return true;
796
836
 
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;
 
837
    if (data->fromFile(fileName, format, flags)) {
807
838
        QPixmapCache::insert(key, *this);
808
839
        return true;
809
840
    }
 
841
 
810
842
    return false;
811
843
}
812
844
 
831
863
 
832
864
bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
833
865
{
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;
 
866
    return data->fromData(buf, len, format, flags);
849
867
}
850
868
 
851
869
/*!
1119
1137
{
1120
1138
#if defined(Q_WS_X11)
1121
1139
    if (data->classId() == QPixmapData::X11Class)
1122
 
        return static_cast<QX11PixmapData*>(data)->handle();
 
1140
        return static_cast<const QX11PixmapData*>(data.constData())->handle();
1123
1141
#endif
1124
1142
    return 0;
1125
1143
}
1267
1285
    return stream;
1268
1286
}
1269
1287
 
1270
 
#endif //QT_NO_DATASTREAM
 
1288
#endif // QT_NO_DATASTREAM
1271
1289
 
1272
1290
#ifdef QT3_SUPPORT
1273
1291
Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy,
1306
1324
    return data->ref == 1;
1307
1325
}
1308
1326
 
 
1327
/*! \internal
 
1328
  ### Qt5 - remove me.
 
1329
*/
1309
1330
void QPixmap::deref()
1310
1331
{
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
 
    }
 
1332
    Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!");
1325
1333
}
1326
1334
 
1327
1335
/*!
1404
1412
    if (newSize == size())
1405
1413
        return *this;
1406
1414
 
1407
 
    QPixmap pix;
1408
 
    QTransform wm;
1409
 
    wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
1410
 
    pix = transformed(wm, mode);
 
1415
    QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(),
 
1416
                                          (qreal)newSize.height() / height());
 
1417
    QPixmap pix = transformed(wm, mode);
1411
1418
    return pix;
1412
1419
}
1413
1420
 
1434
1441
    if (w <= 0)
1435
1442
        return QPixmap();
1436
1443
 
1437
 
    QTransform wm;
1438
1444
    qreal factor = (qreal) w / width();
1439
 
    wm.scale(factor, factor);
 
1445
    QTransform wm = QTransform::fromScale(factor, factor);
1440
1446
    return transformed(wm, mode);
1441
1447
}
1442
1448
 
1463
1469
    if (h <= 0)
1464
1470
        return QPixmap();
1465
1471
 
1466
 
    QTransform wm;
1467
1472
    qreal factor = (qreal) h / height();
1468
 
    wm.scale(factor, factor);
 
1473
    QTransform wm = QTransform::fromScale(factor, factor);
1469
1474
    return transformed(wm, mode);
1470
1475
}
1471
1476
 
1520
1525
    \brief The QPixmap class is an off-screen image representation
1521
1526
    that can be used as a paint device.
1522
1527
 
1523
 
    \ingroup multimedia
 
1528
    \ingroup painting
1524
1529
    \ingroup shared
1525
 
    \mainclass
 
1530
 
1526
1531
 
1527
1532
    Qt provides four classes for handling image data: QImage, QPixmap,
1528
1533
    QBitmap and QPicture. QImage is designed and optimized for I/O,
1530
1535
    designed and optimized for showing images on screen. QBitmap is
1531
1536
    only a convenience class that inherits QPixmap, ensuring a depth
1532
1537
    of 1. The isQBitmap() function returns true if a QPixmap object is
1533
 
    really a bitmap, otherwise returns false. Finally, the QPicture class is a
1534
 
    paint device that records and replays QPainter commands.
 
1538
    really a bitmap, otherwise returns false. Finally, the QPicture class
 
1539
    is a paint device that records and replays QPainter commands.
1535
1540
 
1536
1541
    A QPixmap can easily be displayed on the screen using QLabel or
1537
1542
    one of QAbstractButton's subclasses (such as QPushButton and
1538
1543
    QToolButton). QLabel has a pixmap property, whereas
1539
 
    QAbstractButton has an icon property. And because QPixmap is a
1540
 
    QPaintDevice subclass, QPainter can be used to draw directly onto
1541
 
    pixmaps.
 
1544
    QAbstractButton has an icon property.
1542
1545
 
1543
1546
    In addition to the ordinary constructors, a QPixmap can be
1544
1547
    constructed using the static grabWidget() and grabWindow()
1545
1548
    functions which creates a QPixmap and paints the given widget, or
1546
 
    window, in it.
1547
 
 
1548
 
    Note that the pixel data in a pixmap is internal and is managed by
1549
 
    the underlying window system. Pixels can only be accessed through
1550
 
    QPainter functions or by converting the QPixmap to a QImage.
 
1549
    window, into it.
 
1550
 
 
1551
    QPixmap objects can be passed around by value since the QPixmap
 
1552
    class uses implicit data sharing. For more information, see the \l
 
1553
    {Implicit Data Sharing} documentation. QPixmap objects can also be
 
1554
    streamed.
 
1555
 
1551
1556
    Depending on the system, QPixmap is stored using a RGB32 or a
1552
1557
    premultiplied alpha format. If the image has an alpha channel, and
1553
1558
    if the system allows, the preferred format is premultiplied alpha.
1554
1559
    Note also that QPixmap, unlike QImage, may be hardware dependent.
1555
 
    On X11 and Mac, a QPixmap is stored on the server side while a
1556
 
    QImage is stored on the client side (on Windows, these two classes
 
1560
    On X11, Mac and Symbian, a QPixmap is stored on the server side while
 
1561
    a QImage is stored on the client side (on Windows, these two classes
1557
1562
    have an equivalent internal representation, i.e. both QImage and
1558
1563
    QPixmap are stored on the client side and don't use any GDI
1559
1564
    resources).
1560
1565
 
 
1566
    Note that the pixel data in a pixmap is internal and is managed by
 
1567
    the underlying window system. Because QPixmap is a QPaintDevice
 
1568
    subclass, QPainter can be used to draw directly onto pixmaps.
 
1569
    Pixels can only be accessed through QPainter functions or by
 
1570
    converting the QPixmap to a QImage. However, the fill() function
 
1571
    is available for initializing the entire pixmap with a given color.
 
1572
 
1561
1573
    There are functions to convert between QImage and
1562
1574
    QPixmap. Typically, the QImage class is used to load an image
1563
1575
    file, optionally manipulating the image data, before the QImage
1565
1577
    screen. Alternatively, if no manipulation is desired, the image
1566
1578
    file can be loaded directly into a QPixmap. On Windows, the
1567
1579
    QPixmap class also supports conversion between \c HBITMAP and
1568
 
    QPixmap.
 
1580
    QPixmap. On Symbian, the QPixmap class also supports conversion
 
1581
    between CFbsBitmap and QPixmap.
1569
1582
 
1570
1583
    QPixmap provides a collection of functions that can be used to
1571
1584
    obtain a variety of information about the pixmap. In addition,
1572
1585
    there are several functions that enables transformation of the
1573
1586
    pixmap.
1574
1587
 
1575
 
    QPixmap objects can be passed around by value since the QPixmap
1576
 
    class uses implicit data sharing. For more information, see the \l
1577
 
    {Implicit Data Sharing} documentation. QPixmap objects can also be
1578
 
    streamed.
1579
 
 
1580
1588
    \tableofcontents
1581
1589
 
1582
1590
    \section1 Reading and Writing Image Files
1633
1641
    The hasAlphaChannel() returns true if the pixmap has a format that
1634
1642
    respects the alpha channel, otherwise returns false, while the
1635
1643
    hasAlpha() function returns true if the pixmap has an alpha
1636
 
    channel \e or a mask (otherwise false).
 
1644
    channel \e or a mask (otherwise false). The mask() function returns
 
1645
    the mask as a QBitmap object, which can be set using setMask().
1637
1646
 
1638
 
    The alphaChannel() function returns the alpha channel as a new
1639
 
    QPixmap object, while the mask() function returns the mask as a
1640
 
    QBitmap object. The alpha channel and mask can be set using the
1641
 
    setAlphaChannel() and setMask() functions, respectively.
 
1647
    The createHeuristicMask() function creates and returns a 1-bpp
 
1648
    heuristic mask (i.e. a QBitmap) for this pixmap. It works by
 
1649
    selecting a color from one of the corners and then chipping away
 
1650
    pixels of that color, starting at all the edges. The
 
1651
    createMaskFromColor() function creates and returns a mask (i.e. a
 
1652
    QBitmap) for the pixmap based on a given color.
1642
1653
 
1643
1654
    \row
1644
1655
    \o Low-level information
1667
1678
    operation, you can use QBitmap::fromImage() instead.
1668
1679
 
1669
1680
    In addition, on Windows, the QPixmap class supports conversion to
1670
 
    and from HBitmap: the toWinHBITMAP() function creates a HBITMAP
 
1681
    and from HBITMAP: the toWinHBITMAP() function creates a HBITMAP
1671
1682
    equivalent to the QPixmap, based on the given HBitmapFormat, and
1672
1683
    returns the HBITMAP handle. The fromWinHBITMAP() function returns
1673
1684
    a QPixmap that is equivalent to the given bitmap which has the
1674
 
    specified format.
 
1685
    specified format. The QPixmap class also supports conversion to
 
1686
    and from HICON: the toWinHICON() function creates a HICON equivalent
 
1687
    to the QPixmap, and returns the HICON handle. The fromWinHICON()
 
1688
    function returns a QPixmap that is equivalent to the given icon.
 
1689
 
 
1690
    In addition, on Symbian, the QPixmap class supports conversion to
 
1691
    and from CFbsBitmap: the toSymbianCFbsBitmap() function creates
 
1692
    CFbsBitmap equivalent to the QPixmap, based on given mode and returns 
 
1693
    a CFbsBitmap object. The fromSymbianCFbsBitmap() function returns a 
 
1694
    QPixmap that is equivalent to the given bitmap and given mode.
1675
1695
 
1676
1696
    \section1 Pixmap Transformations
1677
1697
 
1678
1698
    QPixmap supports a number of functions for creating a new pixmap
1679
 
    that is a transformed version of the original: The
1680
 
    createHeuristicMask() function creates and returns a 1-bpp
1681
 
    heuristic mask (i.e. a QBitmap) for this pixmap. It works by
1682
 
    selecting a color from one of the corners and then chipping away
1683
 
    pixels of that color, starting at all the edges. The
1684
 
    createMaskFromColor() function creates and returns a mask (i.e. a
1685
 
    QBitmap) for the pixmap based on a given color.
1686
 
 
 
1699
    that is a transformed version of the original:
1687
1700
 
1688
1701
    The scaled(), scaledToWidth() and scaledToHeight() functions
1689
1702
    return scaled copies of the pixmap, while the copy() function
1698
1711
    function returns the actual matrix used for transforming the
1699
1712
    pixmap.
1700
1713
 
1701
 
    There are also functions for changing attributes of a pixmap.
1702
 
    in-place: The fill() function fills the entire image with the
1703
 
    given color, the setMask() function sets a mask bitmap, and the
1704
 
    setAlphaChannel() function sets the pixmap's alpha channel.
1705
 
 
1706
1714
    \sa QBitmap, QImage, QImageReader, QImageWriter
1707
1715
*/
1708
1716
 
1721
1729
    Returns true if this pixmap has an alpha channel, \e or has a
1722
1730
    mask, otherwise returns false.
1723
1731
 
1724
 
    \sa hasAlphaChannel(), alphaChannel(), mask()
 
1732
    \sa hasAlphaChannel(), mask()
1725
1733
*/
1726
1734
bool QPixmap::hasAlpha() const
1727
1735
{
1732
1740
    Returns true if the pixmap has a format that respects the alpha
1733
1741
    channel, otherwise returns false.
1734
1742
 
1735
 
    \sa alphaChannel(), hasAlpha()
 
1743
    \sa hasAlpha()
1736
1744
*/
1737
1745
bool QPixmap::hasAlphaChannel() const
1738
1746
{
1740
1748
}
1741
1749
 
1742
1750
/*!
1743
 
  \reimp
 
1751
    \internal
1744
1752
*/
1745
1753
int QPixmap::metric(PaintDeviceMetric metric) const
1746
1754
{
1749
1757
 
1750
1758
/*!
1751
1759
    \fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel)
 
1760
    \obsolete
1752
1761
 
1753
1762
    Sets the alpha channel of this pixmap to the given \a alphaChannel
1754
1763
    by converting the \a alphaChannel into 32 bit and using the
1786
1795
}
1787
1796
 
1788
1797
/*!
 
1798
    \obsolete
 
1799
 
1789
1800
    Returns the alpha channel of the pixmap as a new grayscale QPixmap in which
1790
1801
    each pixel's red, green, and blue values are given the alpha value of the
1791
1802
    original pixmap. The color depth of the returned pixmap is the system depth
1804
1815
    \image alphachannelimage.png The pixmap and channelImage QPixmaps
1805
1816
 
1806
1817
    \warning This is an expensive operation. The alpha channel of the
1807
 
    pixmap is extracted dynamically from the pixeldata.
 
1818
    pixmap is extracted dynamically from the pixeldata. Most usecases of this
 
1819
    function are covered by QPainter and compositionModes which will normally
 
1820
    execute faster.
1808
1821
 
1809
1822
    \sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap
1810
1823
    Information}
1815
1828
}
1816
1829
 
1817
1830
/*!
1818
 
  \reimp
 
1831
    \internal
1819
1832
*/
1820
1833
QPaintEngine *QPixmap::paintEngine() const
1821
1834
{
1825
1838
/*!
1826
1839
    \fn QBitmap QPixmap::mask() const
1827
1840
 
1828
 
    Extracts a bitmap mask from the pixmap's alphachannel.
 
1841
    Extracts a bitmap mask from the pixmap's alpha channel.
1829
1842
 
1830
1843
    \warning This is potentially an expensive operation. The mask of
1831
1844
    the pixmap is extracted dynamically from the pixeldata.
1853
1866
    return QScreen::instance()->depth();
1854
1867
#elif defined(Q_WS_X11)
1855
1868
    return QX11Info::appDepth();
1856
 
#elif defined(Q_OS_WINCE)
 
1869
#elif defined(Q_WS_WINCE)
1857
1870
    return QColormap::instance().depth();
1858
1871
#elif defined(Q_WS_WIN)
1859
1872
    return 32; // XXX
1860
1873
#elif defined(Q_WS_MAC)
1861
1874
    return 32;
 
1875
#elif defined(Q_OS_SYMBIAN)
 
1876
    return S60->screenDepth;
1862
1877
#endif
1863
1878
}
1864
1879
 
1865
 
typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
1866
 
extern _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64;
1867
 
 
1868
1880
/*!
1869
1881
    Detaches the pixmap from shared pixmap data.
1870
1882
 
1886
1898
{
1887
1899
    QPixmapData::ClassId id = data->classId();
1888
1900
    if (id == QPixmapData::RasterClass) {
1889
 
        QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data);
 
1901
        QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
1890
1902
        rasterData->image.detach();
1891
 
#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
1892
 
        if (rasterData->texture) {
1893
 
            rasterData->texture->Release();
1894
 
            rasterData->texture = 0;
1895
 
        }
1896
 
#endif
1897
1903
    }
1898
1904
 
1899
 
    if (data->is_cached && qt_pixmap_cleanup_hook_64 && data->ref == 1)
1900
 
        qt_pixmap_cleanup_hook_64(cacheKey());
 
1905
    if (data->is_cached && data->ref == 1)
 
1906
        QImagePixmapCleanupHooks::executePixmapHooks(this);
1901
1907
 
1902
1908
#if defined(Q_WS_MAC)
1903
 
    QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data) : 0;
 
1909
    QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
1904
1910
    if (macData) {
1905
1911
        if (macData->cg_mask) {
1906
1912
            CGImageRelease(macData->cg_mask);
1911
1917
 
1912
1918
    if (data->ref != 1) {
1913
1919
        *this = copy();
1914
 
#if defined(Q_WS_MAC) && !defined(QT_MAC_NO_QUICKDRAW)
1915
 
        if (id == QPixmapData::MacClass) {
1916
 
            macData->qd_alpha = 0;
1917
 
        }
1918
 
#endif
1919
1920
    }
1920
1921
    ++data->detach_no;
1921
1922
 
1922
1923
#if defined(Q_WS_X11)
1923
1924
    if (data->classId() == QPixmapData::X11Class) {
1924
 
        QX11PixmapData *d = static_cast<QX11PixmapData*>(data);
1925
 
        d->uninit = false;
 
1925
        QX11PixmapData *d = static_cast<QX11PixmapData*>(data.data());
 
1926
        d->flags &= ~QX11PixmapData::Uninitialized;
1926
1927
 
1927
1928
        // reset the cache data
1928
1929
        if (d->hd2) {
1958
1959
    if (image.isNull())
1959
1960
        return QPixmap();
1960
1961
 
1961
 
    QPixmapData *data;
1962
1962
    QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
1963
 
    if (gs)
1964
 
        data = gs->createPixmapData(QPixmapData::PixmapType);
1965
 
    else
1966
 
        data = QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType);
1967
 
 
 
1963
    QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType)
 
1964
            : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType));
1968
1965
    data->fromImage(image, flags);
1969
 
    return QPixmap(data);
 
1966
    return QPixmap(data.take());
1970
1967
}
1971
1968
 
1972
1969
/*!
2011
2008
*/
2012
2009
QPixmapData* QPixmap::pixmapData() const
2013
2010
{
2014
 
    return data;
 
2011
    return data.data();
2015
2012
}
2016
2013
 
2017
2014
/*!
2046
2043
 
2047
2044
    \warning This function is only available on Windows.
2048
2045
 
2049
 
    \sa fromWinHBITMAP()
 
2046
    \sa fromWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}
2050
2047
*/
2051
2048
 
2052
2049
/*! \fn QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
2060
2057
 
2061
2058
*/
2062
2059
 
 
2060
/*! \fn HICON QPixmap::toWinHICON() const
 
2061
    \since 4.6
 
2062
 
 
2063
    \bold{Win32 only:} Creates a \c HICON equivalent to the QPixmap.
 
2064
    Returns the \c HICON handle.
 
2065
 
 
2066
    It is the caller's responsibility to free the \c HICON data after use.
 
2067
 
 
2068
    \warning This function is only available on Windows.
 
2069
 
 
2070
    \sa fromWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}
 
2071
*/
 
2072
 
 
2073
/*! \fn QPixmap QPixmap::fromWinHICON(HICON icon)
 
2074
    \since 4.6
 
2075
 
 
2076
    \bold{Win32 only:} Returns a QPixmap that is equivalent to the given
 
2077
    \a icon.
 
2078
 
 
2079
    \warning This function is only available on Windows.
 
2080
 
 
2081
    \sa toWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}
 
2082
 
 
2083
*/
 
2084
 
2063
2085
/*! \fn const QX11Info &QPixmap::x11Info() const
2064
2086
    \bold{X11 only:} Returns information about the configuration of
2065
2087
    the X display used to display the widget.