Changeset 561 for trunk/src/gui/image


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:
57 edited
9 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/image.pri

    r95 r561  
    77        image/qbitmap.h \
    88        image/qicon.h \
     9        image/qicon_p.h \
     10        image/qiconloader_p.h \
    911        image/qiconengine.h \
    1012        image/qiconengineplugin.h \
     
    2325        image/qpixmap_raster_p.h \
    2426        image/qpixmapcache.h \
     27        image/qpixmapcache_p.h \
    2528        image/qpixmapdata_p.h \
    2629        image/qpixmapdatafactory_p.h \
    27         image/qpixmapfilter_p.h
     30        image/qpixmapfilter_p.h \
     31        image/qimagepixmapcleanuphooks_p.h \
     32
    2833
    2934SOURCES += \
    3035        image/qbitmap.cpp \
    3136        image/qicon.cpp \
     37        image/qiconloader.cpp \
    3238        image/qimage.cpp \
    3339        image/qimageiohandler.cpp \
     
    4753        image/qpixmap_raster.cpp \
    4854        image/qnativeimage.cpp \
     55        image/qimagepixmapcleanuphooks.cpp \
     56
    4957
    5058win32 {
     
    6472    HEADERS += image/qpixmap_mac_p.h
    6573    SOURCES += image/qpixmap_mac.cpp
     74}
     75symbian {
     76    HEADERS += image/qpixmap_s60_p.h
     77    SOURCES += image/qpixmap_s60.cpp
    6678}
    6779
     
    8597
    8698    contains(QT_CONFIG, system-png) {
    87         unix:LIBS  += -lpng
     99        unix:LIBS_PRIVATE  += -lpng
    88100        win32:LIBS += libpng.lib
    89101    } else {
  • trunk/src/gui/image/qbitmap.cpp

    r2 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**
     
    5454    \brief The QBitmap class provides monochrome (1-bit depth) pixmaps.
    5555
    56     \ingroup multimedia
     56    \ingroup painting
    5757    \ingroup shared
    5858
     
    7979
    8080    The QBitmap class provides the transformed() function returning a
    81     transformed copy of the bitmap; use the QMatrix argument to
     81    transformed copy of the bitmap; use the QTransform argument to
    8282    translate, scale, shear, and rotate the bitmap. In addition,
    8383    QBitmap provides the static fromData() function which returns a
     
    8787
    8888    Just like the QPixmap class, QBitmap is optimized by the use of
    89     implicit data sharing. For more information, see the {Implicit
     89    implicit data sharing. For more information, see the \l {Implicit
    9090    Data Sharing} documentation.
    9191
     
    9393*/
    9494
     95/*! \typedef QBitmap::DataPtr
     96  \internal
     97 */
    9598
    9699/*!
     
    99102    \sa QPixmap::isNull()
    100103*/
    101 
    102104QBitmap::QBitmap()
    103105    : QPixmap(QSize(0, 0), QPixmapData::BitmapType)
     
    266268    }
    267269
    268     QPixmapData *d;
    269270    QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
    270     if (gs)
    271         d = gs->createPixmapData(QPixmapData::BitmapType);
    272     else
    273         d = QGraphicsSystem::createDefaultPixmapData(QPixmapData::BitmapType);
    274 
    275     d->fromImage(img, flags | Qt::MonoOnly);
    276     return QPixmap(d);
     271    QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::BitmapType)
     272                : QGraphicsSystem::createDefaultPixmapData(QPixmapData::BitmapType));
     273
     274    data->fromImage(img, flags | Qt::MonoOnly);
     275    return QPixmap(data.take());
    277276}
    278277
     
    319318/*!
    320319  \overload
     320  \obsolete
    321321
    322322  This convenience function converts the \a matrix to a QTransform
  • trunk/src/gui/image/qbitmap.h

    r2 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**
     
    8383    QT3_SUPPORT QBitmap &operator=(const QImage &image) { *this = fromImage(image); return *this; }
    8484#endif
     85
     86    typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
    8587};
    8688Q_DECLARE_SHARED(QBitmap)
  • trunk/src/gui/image/qbmphandler.cpp

    r2 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**
     
    5353{
    5454    int i;
    55     if (image->depth() == 1 && image->numColors() == 2) {
     55    if (image->depth() == 1 && image->colorCount() == 2) {
    5656        register uint *p = (uint *)image->bits();
    57         int nbytes = image->numBytes();
     57        int nbytes = image->byteCount();
    5858        for (i=0; i<nbytes/4; i++) {
    5959            *p = ~*p;
     
    8282const int BMP_FILEHDR_SIZE = 14;                // size of BMP_FILEHDR data
    8383
    84 QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf)
     84static QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf)
    8585{                                                // read file header
    8686    s.readRawData(bf.bfType, 2);
     
    8989}
    9090
    91 QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf)
     91static QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf)
    9292{                                                // write file header
    9393    s.writeRawData(bf.bfType, 2);
     
    107107
    108108
    109 QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)
     109static QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)
    110110{
    111111    s >> bi.biSize;
     
    129129}
    130130
    131 QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)
     131static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)
    132132{
    133133    s << bi.biSize;
     
    247247    if (depth != 32) {
    248248        ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits;
    249         image.setNumColors(ncols);
     249        image.setColorCount(ncols);
    250250    }
    251251
     
    527527        return false;
    528528
    529     if (image.depth() == 8 && image.numColors() <= 16) {
     529    if (image.depth() == 8 && image.colorCount() <= 16) {
    530530        bpl_bmp = (((bpl+1)/2+3)/4)*4;
    531531        nbits = 4;
     
    555555                                                : 2834; // 72 dpi default
    556556    bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834;
    557     bi.biClrUsed       = image.numColors();
    558     bi.biClrImportant  = image.numColors();
     557    bi.biClrUsed       = image.colorCount();
     558    bi.biClrImportant  = image.colorCount();
    559559    s << bi;                                        // write info header
    560560    if (s.status() != QDataStream::Ok)
     
    562562
    563563    if (image.depth() != 32) {                // write color table
    564         uchar *color_table = new uchar[4*image.numColors()];
     564        uchar *color_table = new uchar[4*image.colorCount()];
    565565        uchar *rgb = color_table;
    566566        QVector<QRgb> c = image.colorTable();
    567         for (int i=0; i<image.numColors(); i++) {
     567        for (int i=0; i<image.colorCount(); i++) {
    568568            *rgb++ = qBlue (c[i]);
    569569            *rgb++ = qGreen(c[i]);
     
    571571            *rgb++ = 0;
    572572        }
    573         if (d->write((char *)color_table, 4*image.numColors()) == -1) {
     573        if (d->write((char *)color_table, 4*image.colorCount()) == -1) {
    574574            delete [] color_table;
    575575            return false;
     
    755755
    756756    // Code partially repeated in qt_write_dib
    757     if (image.depth() == 8 && image.numColors() <= 16) {
     757    if (image.depth() == 8 && image.colorCount() <= 16) {
    758758        bpl_bmp = (((bpl+1)/2+3)/4)*4;
    759759    } else if (image.depth() == 32) {
     
    772772    bf.bfReserved1 = 0;
    773773    bf.bfReserved2 = 0;
    774     bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.numColors() * 4;
     774    bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.colorCount() * 4;
    775775    bf.bfSize = bf.bfOffBits + bpl_bmp*image.height();
    776776    s << bf;
  • trunk/src/gui/image/qbmphandler_p.h

    r2 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**
  • trunk/src/gui/image/qicon.cpp

    r261 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**
     
    4141
    4242#include "qicon.h"
     43#include "qicon_p.h"
    4344#include "qiconengine.h"
    4445#include "qiconengineplugin.h"
    4546#include "private/qfactoryloader_p.h"
     47#include "private/qiconloader_p.h"
    4648#include "qapplication.h"
    4749#include "qstyleoption.h"
     
    5153#include "qpixmapcache.h"
    5254#include "qvariant.h"
     55#include "qcache.h"
    5356#include "qdebug.h"
     57#include "private/qguiplatformplugin_p.h"
    5458
    5559#ifdef Q_WS_MAC
    5660#include <private/qt_mac_p.h>
    57 #include <Carbon/Carbon.h>
     61#include <private/qt_cocoa_helpers_mac_p.h>
    5862#endif
    5963
     64#ifdef Q_WS_X11
     65#include "private/qt_x11_p.h"
     66#include "private/qkde_p.h"
     67#endif
     68
     69#ifndef QT_NO_ICON
    6070QT_BEGIN_NAMESPACE
    6171
     
    95105static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
    96106
    97 class QIconPrivate
    98 {
    99 public:
    100     QIconPrivate(): engine(0), ref(1), serialNum(serialNumCounter.fetchAndAddRelaxed(1)), detach_no(0), engine_version(2), v1RefCount(0) {}
    101 
    102     ~QIconPrivate() {
    103         if (engine_version == 1) {
    104             if (!v1RefCount->deref()) {
    105                 delete engine;
    106                 delete v1RefCount;
    107             }
    108         } else if (engine_version == 2) {
    109             delete engine;
    110         }
    111     }
    112 
    113     QIconEngine *engine;
    114 
    115     QAtomicInt ref;
    116     int serialNum;
    117     int detach_no;
    118     int engine_version;
    119 
    120     QAtomicInt *v1RefCount;
    121 };
    122 
    123 
    124 struct QPixmapIconEngineEntry
    125 {
    126     QPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
    127     QPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
    128         :pixmap(pm), size(pm.size()), mode(m), state(s){}
    129     QPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
    130         :fileName(file), size(sz), mode(m), state(s){}
    131     QPixmap pixmap;
    132     QString fileName;
    133     QSize size;
    134     QIcon::Mode mode;
    135     QIcon::State state;
    136     bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
    137 };
    138 
    139 class QPixmapIconEngine : public QIconEngineV2 {
    140 public:
    141     QPixmapIconEngine();
    142     QPixmapIconEngine(const QPixmapIconEngine &);
    143     ~QPixmapIconEngine();
    144     void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
    145     QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
    146     QPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
    147     QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
    148     void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
    149     void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
    150 
    151     // v2 functions
    152     QString key() const;
    153     QIconEngineV2 *clone() const;
    154     bool read(QDataStream &in);
    155     bool write(QDataStream &out) const;
    156     void virtual_hook(int id, void *data);
    157 
    158 private:
    159     QPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
    160     QVector<QPixmapIconEngineEntry> pixmaps;
    161 
    162     friend QDataStream &operator<<(QDataStream &s, const QIcon &icon);
    163 };
     107QIconPrivate::QIconPrivate()
     108    : engine(0), ref(1),
     109    serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
     110    detach_no(0),
     111    engine_version(2),
     112    v1RefCount(0)
     113{
     114}
    164115
    165116QPixmapIconEngine::QPixmapIconEngine()
     
    179130{
    180131    QSize pixmapSize = rect.size();
    181 #if defined(Q_WS_MAC) && !defined(Q_WS_MAC64)
    182     pixmapSize *= (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) ? HIGetScaleFactor() : 1;
     132#if defined(Q_WS_MAC)
     133    pixmapSize *= qt_mac_get_scalefactor();
    183134#endif
    184135    painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
     
    316267                  + QString::number(pm.cacheKey())
    317268                  + QString::number(pe->mode)
     269                  + QString::number(QApplication::palette().cacheKey())
     270                  + QLatin1Char('_')
    318271                  + QString::number(actualSize.width())
    319272                  + QLatin1Char('_')
     
    440393        in >> mode;
    441394        in >> state;
    442         if (pm.isNull())
     395        if (pm.isNull()) {
    443396            addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
    444         else
    445             addPixmap(pm, QIcon::Mode(mode), QIcon::State(state));
     397        } else {
     398            QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
     399            pe.pixmap = pm;
     400            pixmaps += pe;
     401        }
    446402    }
    447403    return true;
     
    503459  and states.
    504460
    505   \ingroup multimedia
     461  \ingroup painting
    506462  \ingroup shared
    507   \mainclass
     463
    508464
    509465  A QIcon can generate smaller, larger, active, and disabled pixmaps
     
    865821    QImageWriter::supportedImageFormats() functions to retrieve a
    866822    complete list of the supported file formats.
     823
     824    Note: When you add a non-empty filename to a QIcon, the icon becomes
     825    non-null, even if the file doesn't exist or points to a corrupt file.
    867826
    868827    \sa addPixmap()
     
    922881}
    923882
     883/*!
     884    \since 4.6
     885
     886    Sets the search paths for icon themes to \a paths.
     887    \sa themeSearchPaths(), fromTheme(), setThemeName()
     888*/
     889void QIcon::setThemeSearchPaths(const QStringList &paths)
     890{
     891    QIconLoader::instance()->setThemeSearchPath(paths);
     892}
     893
     894/*!
     895  \since 4.6
     896
     897  Returns the search paths for icon themes.
     898
     899  The default value will depend on the platform:
     900
     901  On X11, the search path will use the XDG_DATA_DIRS environment
     902  variable if available.
     903
     904  By default all platforms will have the resource directory
     905  \c{:\icons} as a fallback. You can use "rcc -project" to generate a
     906  resource file from your icon theme.
     907
     908  \sa setThemeSearchPaths(), fromTheme(), setThemeName()
     909*/
     910QStringList QIcon::themeSearchPaths()
     911{
     912    return QIconLoader::instance()->themeSearchPaths();
     913}
     914
     915/*!
     916    \since 4.6
     917
     918    Sets the current icon theme to \a name.
     919
     920    The \a name should correspond to a directory name in the
     921    themeSearchPath() containing an index.theme
     922    file describing it's contents.
     923
     924    \sa themeSearchPaths(), themeName()
     925*/
     926void QIcon::setThemeName(const QString &name)
     927{
     928    QIconLoader::instance()->setThemeName(name);
     929}
     930
     931/*!
     932    \since 4.6
     933
     934    Returns the name of the current icon theme.
     935
     936    On X11, the current icon theme depends on your desktop
     937    settings. On other platforms it is not set by default.
     938
     939    \sa setThemeName(), themeSearchPaths(), fromTheme(),
     940    hasThemeIcon()
     941*/
     942QString QIcon::themeName()
     943{
     944    return QIconLoader::instance()->themeName();
     945}
     946
     947/*!
     948    \since 4.6
     949
     950    Returns the QIcon corresponding to \a name in the current
     951    icon theme. If no such icon is found in the current theme
     952    \a fallback is return instead.
     953
     954    The lastest version of the freedesktop icon specification and naming
     955    spesification can be obtained here:
     956    http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
     957    http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
     958
     959    To fetch an icon from the current icon theme:
     960
     961    \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 3
     962
     963    Or if you want to provide a guaranteed fallback for platforms that
     964    do not support theme icons, you can use the second argument:
     965
     966    \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 4
     967
     968    \note By default, only X11 will support themed icons. In order to
     969    use themed icons on Mac and Windows, you will have to bundle a
     970    compliant theme in one of your themeSearchPaths() and set the
     971    appropriate themeName().
     972
     973    \sa themeName(), setThemeName(), themeSearchPaths()
     974*/
     975QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
     976{
     977    static QCache <QString, QIcon> iconCache;
     978
     979    QIcon icon;
     980
     981    if (iconCache.contains(name)) {
     982        icon = *iconCache.object(name);
     983    } else {
     984        QIcon *cachedIcon  = new QIcon(new QIconLoaderEngine(name));
     985        iconCache.insert(name, cachedIcon);
     986        icon = *cachedIcon;
     987    }
     988
     989    if (icon.availableSizes().isEmpty())
     990        return fallback;
     991
     992    return icon;
     993}
     994
     995/*!
     996    \since 4.6
     997
     998    Returns true if there is an icon available for \a name in the
     999    current icon theme, otherwise returns false.
     1000
     1001    \sa themeSearchPaths(), fromTheme(), setThemeName()
     1002*/
     1003bool QIcon::hasThemeIcon(const QString &name)
     1004{
     1005    QIcon icon = fromTheme(name);
     1006
     1007    return !icon.isNull();
     1008}
     1009
     1010
    9241011/*****************************************************************************
    9251012  QIcon stream functions
     
    9311018    \since 4.2
    9321019
    933     Writes the given \a icon to the the given \a stream as a PNG
     1020    Writes the given \a icon to the given \a stream as a PNG
    9341021    image. If the icon contains more than one image, all images will
    9351022    be written to the stream. Note that writing the stream to a file
     
    9931080            icon.d->engine = engine;
    9941081            engine->read(s);
     1082        } else if (key == QLatin1String("QIconLoaderEngine")) {
     1083            icon.d = new QIconPrivate;
     1084            QIconEngineV2 *engine = new QIconLoaderEngine();
     1085            icon.d->engine = engine;
     1086            engine->read(s);
    9951087#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    9961088        } else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) {
     
    11381230
    11391231QT_END_NAMESPACE
     1232#endif //QT_NO_ICON
  • trunk/src/gui/image/qicon.h

    r2 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**
     
    9898    QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
    9999
     100    static QIcon fromTheme(const QString &name, const QIcon &fallback = QIcon());
     101    static bool hasThemeIcon(const QString &name);
     102
     103    static QStringList themeSearchPaths();
     104    static void setThemeSearchPaths(const QStringList &searchpath);
     105
     106    static QString themeName();
     107    static void setThemeName(const QString &path);
     108
     109
    100110#ifdef QT3_SUPPORT
    101111    enum Size { Small, Large, Automatic = Small };
  • trunk/src/gui/image/qiconengine.cpp

    r2 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**
     
    5050  \brief The QIconEngine class provides an abstract base class for QIcon renderers.
    5151
    52   \ingroup multimedia
     52  \ingroup painting
    5353
    5454  \bold {Use QIconEngineV2 instead.}
     
    145145    \brief The QIconEngineV2 class provides an abstract base class for QIcon renderers.
    146146
    147     \ingroup multimedia
     147    \ingroup painting
    148148    \since 4.3
    149149
  • trunk/src/gui/image/qiconengine.h

    r2 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**
  • trunk/src/gui/image/qiconengineplugin.cpp

    r2 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**
  • trunk/src/gui/image/qiconengineplugin.h

    r2 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**
  • trunk/src/gui/image/qimage.cpp

    r2 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**
     
    5050#include "qstringlist.h"
    5151#include "qvariant.h"
     52#include "qimagepixmapcleanuphooks_p.h"
    5253#include <ctype.h>
    5354#include <stdlib.h>
     
    6162#include <qhash.h>
    6263
    63 #ifdef QT_RASTER_IMAGEENGINE
    6464#include <private/qpaintengine_raster_p.h>
    65 #else
    66 #include <qpaintengine.h>
    67 #endif
    6865
    6966#include <private/qimage_p.h>
     
    106103    }
    107104
    108 
    109 // ### Qt 5: remove
    110 typedef void (*_qt_image_cleanup_hook)(int);
    111 Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook = 0;
    112 
    113 // ### Qt 5: rename
    114 typedef void (*_qt_image_cleanup_hook_64)(qint64);
    115 Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64 = 0;
    116105
    117106static QImage rotated90(const QImage &src);
     
    186175}
    187176
     177/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors)
     178
     179    \internal
     180
     181    Creates a new image data.
     182    Returns 0 if invalid parameters are give or anything else failed.
     183*/
    188184QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors)
    189185{
     
    224220        return 0;
    225221
    226     QImageData *d = new QImageData;
     222    QScopedPointer<QImageData> d(new QImageData);
    227223    d->colortable.resize(numColors);
    228224    if (depth == 1) {
     
    247243
    248244    if (!d->data) {
    249         delete d;
    250245        return 0;
    251246    }
    252247
    253248    d->ref.ref();
    254     return d;
     249    return d.take();
    255250
    256251}
     
    258253QImageData::~QImageData()
    259254{
    260     if (is_cached && qt_image_cleanup_hook_64)
    261         qt_image_cleanup_hook_64((((qint64) ser_no) << 32) | ((qint64) detach_no));
     255    if (is_cached)
     256        QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
    262257    delete paintEngine;
    263258    if (data && own_data)
     
    345340    \class QImage
    346341
    347     \ingroup multimedia
     342    \ingroup painting
    348343    \ingroup shared
    349     \mainclass
     344
    350345    \reentrant
    351346
     
    382377    \note If you would like to load QImage objects in a static build of Qt,
    383378    refer to the \l{How To Create Qt Plugins#Static Plugins}{Plugin HowTo}.
     379
     380    \warning Painting on a QImage with the format
     381    QImage::Format_Indexed8 is not supported.
    384382
    385383    \tableofcontents
     
    452450    as a QRgb value indepedent of the image's format.
    453451
    454     In case of monochrome and 8-bit images, the numColors() and
     452    In case of monochrome and 8-bit images, the colorCount() and
    455453    colorTable() functions provide information about the color
    456454    components used to store the image data: The colorTable() function
     
    487485    \l {QImage#Image Formats}{Image Formats} section).
    488486
    489     The format(), bytesPerLine(), and numBytes() functions provide
     487    The format(), bytesPerLine(), and byteCount() functions provide
    490488    low-level information about the data stored in the image.
    491489
     
    549547    size of the integer varies depending on the format. QImage
    550548    supports several image formats described by the \l Format
    551     enum. The monochrome (1-bit), 8-bit and 32-bit images are
    552     available in all versions of Qt. In addition Qt for Embedded Linux
    553     also supports 2-bit, 4-bit, and 16-bit images. For more information
    554     about the Qt Extended specific formats, see the documentation of the \l
    555     Format enum.
     549    enum.
    556550
    557551    Monochrome images are stored using 1-bit indexes into a color table
     
    591585    The mirrored() function returns a mirror of the image in the
    592586    desired direction, the scaled() returns a copy of the image scaled
    593     to a rectangle of the desired measures, the rgbSwapped() function
    594     constructs a BGR image from a RGB image, and the alphaChannel()
    595     function constructs an image from this image's alpha channel.
     587    to a rectangle of the desired measures, and the rgbSwapped() function
     588    constructs a BGR image from a RGB image.
    596589
    597590    The scaledToWidth() and scaledToHeight() functions return scaled
     
    612605    \table
    613606    \header \o Function \o Description
    614     \row
    615     \o setAlphaChannel()
    616     \o Sets the alpha channel of the image.
    617607    \row
    618608    \o setDotsPerMeterX()
     
    634624    monochrome and 8-bit formats.
    635625    \row
    636     \o setNumColors()
     626    \o setColorCount()
    637627    \o Resizes the color table. Only monochrome and 8-bit formats.
    638628
     
    707697    \enum QImage::Format
    708698
    709     The following image formats are available in all versions of Qt:
     699    The following image formats are available in Qt. Values greater
     700    than QImage::Format_RGB16 were added in Qt 4.4. See the notes
     701    after the table.
    710702
    711703    \value Format_Invalid   The image is invalid.
     
    714706    \value Format_MonoLSB   The image is stored using 1-bit per pixel. Bytes are
    715707                            packed with the less significant bit (LSB) first.
    716     \value Format_Indexed8  The image is stored using 8-bit indexes into a colormap.
     708
     709    \value Format_Indexed8  The image is stored using 8-bit indexes
     710                            into a colormap.
     711
    717712    \value Format_RGB32     The image is stored using a 32-bit RGB format (0xffRRGGBB).
    718     \value Format_ARGB32    The image is stored using a 32-bit ARGB format (0xAARRGGBB).
     713
     714    \value Format_ARGB32    The image is stored using a 32-bit ARGB
     715                            format (0xAARRGGBB).
     716
    719717    \value Format_ARGB32_Premultiplied  The image is stored using a premultiplied 32-bit
    720718                            ARGB format (0xAARRGGBB), i.e. the red,
     
    725723                            using alpha blending) are faster using premultiplied ARGB32
    726724                            than with plain ARGB32.
     725
    727726    \value Format_RGB16     The image is stored using a 16-bit RGB format (5-6-5).
     727
    728728    \value Format_ARGB8565_Premultiplied  The image is stored using a
    729729                            premultiplied 24-bit ARGB format (8-5-6-5).
     
    741741    \value Format_ARGB4444_Premultiplied  The image is stored using a
    742742                            premultiplied 16-bit ARGB format (4-4-4-4).
     743
     744    \note Drawing into a QImage with QImage::Format_Indexed8 is not
     745    supported.
     746
     747    \note Do not render into ARGB32 images using QPainter.  Using
     748    QImage::Format_ARGB32_Premultiplied is significantly faster.
    743749
    744750    \sa format(), convertToFormat()
     
    904910    If \a format is an indexed color format, the image color table is
    905911    initially empty and must be sufficiently expanded with
    906     setNumColors() or setColorTable() before the image is used.
     912    setColorCount() or setColorTable() before the image is used.
    907913*/
    908914QImage::QImage(uchar* data, int width, int height, Format format)
     
    926932    If \a format is an indexed color format, the image color table is
    927933    initially empty and must be sufficiently expanded with
    928     setNumColors() or setColorTable() before the image is used.
     934    setColorCount() or setColorTable() before the image is used.
    929935
    930936    Unlike the similar QImage constructor that takes a non-const data buffer,
     
    952958    If \a format is an indexed color format, the image color table is
    953959    initially empty and must be sufficiently expanded with
    954     setNumColors() or setColorTable() before the image is used.
     960    setColorCount() or setColorTable() before the image is used.
    955961*/
    956962QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format)
     
    972978    If \a format is an indexed color format, the image color table is
    973979    initially empty and must be sufficiently expanded with
    974     setNumColors() or setColorTable() before the image is used.
     980    setColorCount() or setColorTable() before the image is used.
    975981
    976982    Unlike the similar QImage constructor that takes a non-const data buffer,
     
    11241130    Use the constructor that accepts a width, a height and a format
    11251131    (i.e. specifying the depth and bit order), in combination with the
    1126     setNumColors() function, instead.
     1132    setColorCount() function, instead.
    11271133
    11281134    \oldcode
     
    11331139        // For 8 bit images the default number of colors is 256. If
    11341140        // another number of colors is required it can be specified
    1135         // using the setNumColors() function.
    1136         image.setNumColors(numColors);
     1141        // using the setColorCount() function.
     1142        image.setColorCount(numColors);
    11371143    \endcode
    11381144*/
    11391145
    1140 QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder)
     1146QImage::QImage(int w, int h, int depth, int colorCount, Endian bitOrder)
    11411147    : QPaintDevice()
    11421148{
    1143     d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), numColors);
     1149    d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), colorCount);
    11441150}
    11451151
     
    11501156    Use the constructor that accepts a size and a format
    11511157    (i.e. specifying the depth and bit order), in combination with the
    1152     setNumColors() function, instead.
     1158    setColorCount() function, instead.
    11531159
    11541160    \oldcode
     
    11611167        // For 8 bit images the default number of colors is 256. If
    11621168        // another number of colors is required it can be specified
    1163         // using the setNumColors() function.
    1164         image.setNumColors(numColors);
     1169        // using the setColorCount() function.
     1170        image.setColorCount(numColors);
    11651171    \endcode
    11661172*/
     
    12301236            d->colortable[i] = colortable[i];
    12311237    } else if (numColors) {
    1232         setNumColors(numColors);
     1238        setColorCount(numColors);
    12331239    }
    12341240}
     
    12811287            d->colortable[i] = colortable[i];
    12821288    } else if (numColors) {
    1283         setNumColors(numColors);
     1289        setColorCount(numColors);
    12841290    }
    12851291}
     
    13471353{
    13481354    if (d) {
    1349         if (d->is_cached && qt_image_cleanup_hook_64 && d->ref == 1)
    1350             qt_image_cleanup_hook_64(cacheKey());
     1355        if (d->is_cached && d->ref == 1)
     1356            QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
    13511357
    13521358        if (d->ref != 1 || d->ro_data)
     
    15901596
    15911597/*!
     1598    \obsolete
    15921599    \fn int QImage::numColors() const
    15931600
    15941601    Returns the size of the color table for the image.
    15951602
    1596     Notice that numColors() returns 0 for 32-bpp images because these
     1603    \sa setColorCount()
     1604*/
     1605int QImage::numColors() const
     1606{
     1607    return d ? d->colortable.size() : 0;
     1608}
     1609
     1610/*!
     1611    \since 4.6
     1612    \fn int QImage::colorCount() const
     1613
     1614    Returns the size of the color table for the image.
     1615
     1616    Notice that colorCount() returns 0 for 32-bpp images because these
    15971617    images do not use color tables, but instead encode pixel values as
    15981618    ARGB quadruplets.
    15991619
    1600     \sa setNumColors(), {QImage#Image Information}{Image Information}
    1601 */
    1602 int QImage::numColors() const
     1620    \sa setColorCount(), {QImage#Image Information}{Image Information}
     1621*/
     1622int QImage::colorCount() const
    16031623{
    16041624    return d ? d->colortable.size() : 0;
     
    16221642    Returns a pointer to the scanline pointer table. This is the
    16231643    beginning of the data block for the image.
     1644    Returns 0 in case of an error.
    16241645
    16251646    Use the bits() or scanLine() function instead.
     
    16371658    if (!d->jumptable) {
    16381659        d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));
     1660        if (!d->jumptable)
     1661            return 0;
    16391662        uchar *data = d->data;
    16401663        int height = d->height;
     
    16571680    if (!d->jumptable) {
    16581681        d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));
     1682        if (!d->jumptable)
     1683            return 0;
    16591684        uchar *data = d->data;
    16601685        int height = d->height;
     
    16921717    d->colortable = colors;
    16931718    d->has_alpha_clut = false;
    1694     for (int i = 0; i < d->colortable.size(); ++i)
    1695         d->has_alpha_clut |= (qAlpha(d->colortable.at(i)) != 255);
     1719    for (int i = 0; i < d->colortable.size(); ++i) {
     1720        if (qAlpha(d->colortable.at(i)) != 255) {
     1721            d->has_alpha_clut = true;
     1722            break;
     1723        }
     1724    }
    16961725}
    16971726
     
    17001729    or an empty list if the image does not have a color table
    17011730
    1702     \sa setColorTable(), numColors(), color()
     1731    \sa setColorTable(), colorCount(), color()
    17031732*/
    17041733QVector<QRgb> QImage::colorTable() const
     
    17091738
    17101739/*!
     1740    \obsolete
     1741    Returns the number of bytes occupied by the image data.
     1742
     1743    \sa byteCount()
     1744*/
     1745int QImage::numBytes() const
     1746{
     1747    return d ? d->nbytes : 0;
     1748}
     1749
     1750/*!
     1751    \since 4.6
    17111752    Returns the number of bytes occupied by the image data.
    17121753
     
    17141755    Information}
    17151756*/
    1716 int QImage::numBytes() const
     1757int QImage::byteCount() const
    17171758{
    17181759    return d ? d->nbytes : 0;
     
    17221763    Returns the number of bytes per image scanline.
    17231764
    1724     This is equivalent to numBytes()/ height().
     1765    This is equivalent to byteCount() / height().
    17251766
    17261767    \sa scanLine()
     
    17451786QRgb QImage::color(int i) const
    17461787{
    1747     Q_ASSERT(i < numColors());
     1788    Q_ASSERT(i < colorCount());
    17481789    return d ? d->colortable.at(i) : QRgb(uint(-1));
    17491790}
     
    17561797
    17571798    If \a index is outside the current size of the color table, it is
    1758     expanded with setNumColors().
    1759 
    1760     \sa color(), numColors(), setColorTable(), {QImage#Pixel Manipulation}{Pixel
     1799    expanded with setColorCount().
     1800
     1801    \sa color(), colorCount(), setColorTable(), {QImage#Pixel Manipulation}{Pixel
    17611802    Manipulation}
    17621803*/
     
    17761817
    17771818    if (i >= d->colortable.size())
    1778         setNumColors(i+1);
     1819        setColorCount(i+1);
    17791820    d->colortable[i] = c;
    17801821    d->has_alpha_clut |= (qAlpha(c) != 255);
     
    18331874    current return value.
    18341875
    1835     \sa scanLine(), numBytes()
     1876    \sa scanLine(), byteCount()
    18361877*/
    18371878uchar *QImage::bits()
     
    20142055
    20152056/*!
     2057    \obsolete
    20162058    Resizes the color table to contain \a numColors entries.
     2059
     2060    \sa setColorCount()
     2061*/
     2062
     2063void QImage::setNumColors(int numColors)
     2064{
     2065    setColorCount(numColors);
     2066}
     2067
     2068/*!
     2069    \since 4.6
     2070    Resizes the color table to contain \a colorCount entries.
    20172071
    20182072    If the color table is expanded, all the extra colors will be set to
     
    20232077    otherwise the results are undefined.
    20242078
    2025     \sa numColors(), colorTable(), setColor(), {QImage#Image
     2079    \sa colorCount(), colorTable(), setColor(), {QImage#Image
    20262080    Transformations}{Image Transformations}
    20272081*/
    20282082
    2029 void QImage::setNumColors(int numColors)
     2083void QImage::setColorCount(int colorCount)
    20302084{
    20312085    if (!d) {
    2032         qWarning("QImage::setNumColors: null image");
     2086        qWarning("QImage::setColorCount: null image");
    20332087        return;
    20342088    }
     
    20402094        return;
    20412095
    2042     if (numColors == d->colortable.size())
     2096    if (colorCount == d->colortable.size())
    20432097        return;
    2044     if (numColors <= 0) {                        // use no color table
     2098    if (colorCount <= 0) {                        // use no color table
    20452099        d->colortable = QVector<QRgb>();
    20462100        return;
    20472101    }
    20482102    int nc = d->colortable.size();
    2049     d->colortable.resize(numColors);
    2050     for (int i = nc; i < numColors; ++i)
     2103    d->colortable.resize(colorCount);
     2104    for (int i = nc; i < colorCount; ++i)
    20512105        d->colortable[i] = 0;
    2052 
    20532106}
    20542107
     
    23712424    switch (dithermode) {
    23722425    case Diffuse: {
    2373         int *line1 = new int[w];
    2374         int *line2 = new int[w];
     2426        QScopedArrayPointer<int> lineBuffer(new int[w * 2]);
     2427        int *line1 = lineBuffer.data();
     2428        int *line2 = lineBuffer.data() + w;
    23752429        int bmwidth = (w+7)/8;
    23762430
     
    24522506            }
    24532507        }
    2454         delete [] line1;
    2455         delete [] line2;
    24562508    } break;
    24572509    case Ordered: {
     
    25942646static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
    25952647{
    2596     QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32);
    2597     convert_ARGB_PM_to_ARGB(tmp, src, flags);
    2598     dither_to_Mono(dst, tmp, flags, false);
    2599     delete tmp;
     2648    QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
     2649    convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
     2650    dither_to_Mono(dst, tmp.data(), flags, false);
    26002651}
    26012652
     
    27462797            int* line2[3];
    27472798            int* pv[3];
    2748             line1[0] = new int[src->width];
    2749             line2[0] = new int[src->width];
    2750             line1[1] = new int[src->width];
    2751             line2[1] = new int[src->width];
    2752             line1[2] = new int[src->width];
    2753             line2[2] = new int[src->width];
    2754             pv[0] = new int[src->width];
    2755             pv[1] = new int[src->width];
    2756             pv[2] = new int[src->width];
     2799            QScopedArrayPointer<int> lineBuffer(new int[src->width * 9]);
     2800            line1[0] = lineBuffer.data();
     2801            line2[0] = lineBuffer.data() + src->width;
     2802            line1[1] = lineBuffer.data() + src->width * 2;
     2803            line2[1] = lineBuffer.data() + src->width * 3;
     2804            line1[2] = lineBuffer.data() + src->width * 4;
     2805            line2[2] = lineBuffer.data() + src->width * 5;
     2806            pv[0] = lineBuffer.data() + src->width * 6;
     2807            pv[1] = lineBuffer.data() + src->width * 7;
     2808            pv[2] = lineBuffer.data() + src->width * 8;
    27572809
    27582810            int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian);
     
    28172869                dest_data += dst->bytes_per_line;
    28182870            }
    2819             delete [] line1[0];
    2820             delete [] line2[0];
    2821             delete [] line1[1];
    2822             delete [] line2[1];
    2823             delete [] line1[2];
    2824             delete [] line2[2];
    2825             delete [] pv[0];
    2826             delete [] pv[1];
    2827             delete [] pv[2];
    28282871        } else { // OrderedDither
    28292872            for (int y = 0; y < src->height; y++) {
     
    28582901            Q_ASSERT(dst->colortable.size() > trans);
    28592902            dst->colortable[trans] = 0;
    2860             QImageData *mask = QImageData::create(QSize(src->width, src->height), QImage::Format_Mono);
    2861             dither_to_Mono(mask, src, flags, true);
     2903            QScopedPointer<QImageData> mask(QImageData::create(QSize(src->width, src->height), QImage::Format_Mono));
     2904            dither_to_Mono(mask.data(), src, flags, true);
    28622905            uchar *dst_data = dst->data;
    28632906            const uchar *mask_data = mask->data;
     
    28712914            }
    28722915            dst->has_alpha_clut = true;
    2873             delete mask;
    28742916        }
    28752917
     
    28842926static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
    28852927{
    2886     QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32);
    2887     convert_ARGB_PM_to_ARGB(tmp, src, flags);
    2888     convert_RGB_to_Indexed8(dst, tmp, flags);
    2889     delete tmp;
     2928    QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
     2929    convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
     2930    convert_RGB_to_Indexed8(dst, tmp.data(), flags);
    28902931}
    28912932
     
    29052946
    29062947    QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format);
     2948    if (colorTable.size() == 0) {
     2949        colorTable.resize(256);
     2950        for (int i=0; i<256; ++i)
     2951            colorTable[i] = qRgb(i, i, i);
     2952
     2953    }
    29072954
    29082955    int w = src->width;
     
    36073654
    36083655    If the \a position is not valid, the results are undefined.
     3656
     3657    \warning This function is expensive when used for massive pixel
     3658    manipulations.
    36093659
    36103660    \sa setPixel(), valid(), {QImage#Pixel Manipulation}{Pixel
     
    36663716
    36673717    If \a position is not a valid coordinate pair in the image, or if
    3668     \a index_or_rgb >= numColors() in the case of monochrome and
     3718    \a index_or_rgb >= colorCount() in the case of monochrome and
    36693719    8-bit images, the result is undefined.
    36703720
     
    38273877        if (d->colortable.isEmpty())
    38283878            return true;
    3829         for (int i = 0; i < numColors(); i++)
     3879        for (int i = 0; i < colorCount(); i++)
    38303880            if (!qIsGray(d->colortable.at(i)))
    38313881                return false;
     
    38543904        return allGray();
    38553905    case 8: {
    3856         for (int i = 0; i < numColors(); i++)
     3906        for (int i = 0; i < colorCount(); i++)
    38573907            if (d->colortable.at(i) != qRgb(i,i,i))
    38583908                return false;
     
    39453995        return copy();
    39463996
    3947     QImage img;
    3948     QTransform wm;
    3949     wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
    3950     img = transformed(wm, mode);
     3997    QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
     3998    QImage img = transformed(wm, mode);
    39513999    return img;
    39524000}
     
    39754023        return QImage();
    39764024
    3977     QTransform wm;
    39784025    qreal factor = (qreal) w / width();
    3979     wm.scale(factor, factor);
     4026    QTransform wm = QTransform::fromScale(factor, factor);
    39804027    return transformed(wm, mode);
    39814028}
     
    40044051        return QImage();
    40054052
    4006     QTransform wm;
    40074053    qreal factor = (qreal) h / height();
    4008     wm.scale(factor, factor);
     4054    QTransform wm = QTransform::fromScale(factor, factor);
    40094055    return transformed(wm, mode);
    40104056}
     
    40794125
    40804126    QImage mask(d->width, d->height, Format_MonoLSB);
    4081     dither_to_Mono(mask.d, d, flags, true);
     4127    if (!mask.isNull())
     4128        dither_to_Mono(mask.d, d, flags, true);
    40824129    return mask;
    40834130}
     
    41234170    int h = height();
    41244171    QImage m(w, h, Format_MonoLSB);
    4125     m.setNumColors(2);
     4172    m.setColorCount(2);
    41264173    m.setColor(0, QColor(Qt::color0).rgba());
    41274174    m.setColor(1, QColor(Qt::color1).rgba());
     
    42754322    // Create result image, copy colormap
    42764323    QImage result(d->width, d->height, d->format);
     4324
     4325    // check if we ran out of of memory..
     4326    if (!result.d)
     4327        return QImage();
     4328
    42774329    result.d->colortable = d->colortable;
    42784330    result.d->has_alpha_clut = d->has_alpha_clut;
     
    46254677    specified \a format. If \a format is not specified (which is the default),
    46264678    the loader probes the file for a header to guess the file format.
    4627 
    4628     If the loading of the image failed, this object is a null image.
    4629 
    4630     \sa load(), save(), {QImage#Reading and Writing Image
    4631     Files}{Reading and Writing Image Files}
    4632 */
     4679    binary \a data. The loader attempts to read the image, either using the
     4680    optional image \a format specified or by determining the image format from
     4681    the data.
     4682
     4683    If \a format is not specified (which is the default), the loader probes the
     4684    file for a header to determine the file format. If \a format is specified,
     4685    it must be one of the values returned by QImageReader::supportedImageFormats().
     4686
     4687    If the loading of the image fails, the image returned will be a null image.
     4688
     4689    \sa load(), save(), {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}
     4690 */
     4691
    46334692QImage QImage::fromData(const uchar *data, int size, const char *format)
    46344693{
     
    47574816    return s;
    47584817}
    4759 #endif
     4818#endif // QT_NO_DATASTREAM
    47604819
    47614820
     
    48474906
    48484907    if (d->format != Format_RGB32) {
    4849         if (d->colortable != i.d->colortable)
    4850             return false;
    48514908        if (d->format >= Format_ARGB32) { // all bits defined
    48524909            const int n = d->width * d->depth / 8;
     
    48614918            }
    48624919        } else {
    4863             int w = width();
    4864             int h = height();
     4920            const int w = width();
     4921            const int h = height();
     4922            const QVector<QRgb> &colortable = d->colortable;
     4923            const QVector<QRgb> &icolortable = i.d->colortable;
    48654924            for (int y=0; y<h; ++y) {
    48664925                for (int x=0; x<w; ++x) {
    4867                     if (pixelIndex(x, y) != i.pixelIndex(x, y))
     4926                    if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
    48684927                        return false;
    48694928                }
     
    49945053    \fn void QImage::setOffset(const QPoint& offset)
    49955054
    4996     Sets the the number of pixels by which the image is intended to be
     5055    Sets the number of pixels by which the image is intended to be
    49975056    offset by when positioning relative to other images, to \a offset.
    49985057
     
    52525311        return 0;
    52535312
    5254 #ifdef QT_RASTER_IMAGEENGINE
    52555313    if (!d->paintEngine) {
    52565314        d->paintEngine = new QRasterPaintEngine(const_cast<QImage *>(this));
    52575315    }
    5258 #endif
     5316
    52595317    return d->paintEngine;
    52605318}
     
    52625320
    52635321/*!
    5264     \reimp
     5322    \internal
    52655323
    52665324    Returns the size for the specified \a metric on the device.
     
    55805638    format if the function succeeds.
    55815639
    5582     Use one of the composition mods in QPainter::CompositionMode instead.
     5640    Use one of the composition modes in QPainter::CompositionMode instead.
     5641
     5642    \warning This function is expensive.
    55835643
    55845644    \sa alphaChannel(), {QImage#Image Transformations}{Image
     
    56565716
    56575717/*!
     5718    \obsolete
     5719
    56585720    Returns the alpha channel of the image as a new grayscale QImage in which
    56595721    each pixel's red, green, and blue values are given the alpha value of the
     
    56645726    this function on QPixmaps.
    56655727
     5728    Most usecases for this function can be replaced with QPainter and
     5729    using composition modes.
     5730
     5731    \warning This is an expensive function.
     5732
    56665733    \sa setAlphaChannel(), hasAlphaChannel(),
    56675734    {QPixmap#Pixmap Information}{Pixmap},
     
    56785745
    56795746    QImage image(w, h, Format_Indexed8);
    5680     image.setNumColors(256);
     5747    image.setColorCount(256);
    56815748
    56825749    // set up gray scale table.
     
    57305797    channel, otherwise returns false.
    57315798
    5732     \sa alphaChannel(), {QImage#Image Information}{Image Information}
     5799    \sa {QImage#Image Information}{Image Information}
    57335800*/
    57345801bool QImage::hasAlphaChannel() const
     
    58085875static QImage rotated90(const QImage &image) {
    58095876    QImage out(image.height(), image.width(), image.format());
    5810     if (image.numColors() > 0)
     5877    if (image.colorCount() > 0)
    58115878        out.setColorTable(image.colorTable());
    58125879    int w = image.width();
     
    58475914    default:
    58485915        for (int y=0; y<h; ++y) {
    5849             if (image.numColors())
     5916            if (image.colorCount())
    58505917                for (int x=0; x<w; ++x)
    58515918                    out.setPixel(h-y-1, x, image.pixelIndex(x, y));
     
    58675934static QImage rotated270(const QImage &image) {
    58685935    QImage out(image.height(), image.width(), image.format());
    5869     if (image.numColors() > 0)
     5936    if (image.colorCount() > 0)
    58705937        out.setColorTable(image.colorTable());
    58715938    int w = image.width();
     
    59065973    default:
    59075974        for (int y=0; y<h; ++y) {
    5908             if (image.numColors())
     5975            if (image.colorCount())
    59095976                for (int x=0; x<w; ++x)
    59105977                    out.setPixel(y, w-x-1, image.pixelIndex(x, y));
     
    60466113                // colors are left in the color table, so pick that one as transparent
    60476114                dImage.d->colortable.append(0x0);
    6048                 memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.numBytes());
     6115                memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount());
    60496116            } else {
    6050                 memset(dImage.bits(), 0, dImage.numBytes());
     6117                memset(dImage.bits(), 0, dImage.byteCount());
    60516118            }
    60526119            break;
     
    60556122        case 24:
    60566123        case 32:
    6057             memset(dImage.bits(), 0x00, dImage.numBytes());
     6124            memset(dImage.bits(), 0x00, dImage.byteCount());
    60586125            break;
    60596126    }
  • trunk/src/gui/image/qimage.h

    r2 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**
     
    166166
    167167    int depth() const;
    168     int numColors() const;
     168#ifdef QT_DEPRECATED
     169    QT_DEPRECATED int numColors() const;
     170#endif
     171    int colorCount() const;
    169172
    170173    QRgb color(int i) const;
    171174    void setColor(int i, QRgb c);
    172     void setNumColors(int);
     175#ifdef QT_DEPRECATED
     176    QT_DEPRECATED void setNumColors(int);
     177#endif
     178    void setColorCount(int);
    173179
    174180    bool allGray() const;
     
    177183    uchar *bits();
    178184    const uchar *bits() const;
    179     int numBytes() const;
     185#ifdef QT_DEPRECATED
     186    QT_DEPRECATED int numBytes() const;
     187#endif
     188    int byteCount() const;
    180189
    181190    uchar *scanLine(int);
     
    315324
    316325    friend class QRasterPixmapData;
    317     friend class QDetachedPixmap;
     326    friend class QPixmapCacheEntry;
    318327    friend Q_GUI_EXPORT qint64 qt_image_id(const QImage &image);
    319328    friend const QVector<QRgb> *qt_image_colortable(const QImage &image);
  • trunk/src/gui/image/qimage_p.h

    r2 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**
     
    6464QT_BEGIN_NAMESPACE
    6565
    66 struct QImageData {        // internal image data
     66struct Q_GUI_EXPORT QImageData {        // internal image data
    6767    QImageData();
    6868    ~QImageData();
  • trunk/src/gui/image/qimageiohandler.cpp

    r2 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**
     
    273273QImageIOHandler::~QImageIOHandler()
    274274{
    275     delete d_ptr;
    276275}
    277276
  • trunk/src/gui/image/qimageiohandler.h

    r2 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**
     
    4545#include <QtCore/qplugin.h>
    4646#include <QtCore/qfactoryinterface.h>
     47#include <QtCore/qscopedpointer.h>
    4748
    4849QT_BEGIN_HEADER
     
    110111protected:
    111112    QImageIOHandler(QImageIOHandlerPrivate &dd);
    112     QImageIOHandlerPrivate *d_ptr;
     113    QScopedPointer<QImageIOHandlerPrivate> d_ptr;
    113114private:
    114115    Q_DISABLE_COPY(QImageIOHandler)
  • trunk/src/gui/image/qimagereader.cpp

    r2 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**
     
    4848
    4949    \reentrant
    50     \ingroup multimedia
     50    \ingroup painting
    5151    \ingroup io
    5252
     
    196196
    197197static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
    198                                                 const QByteArray &format, bool autoDetectImageFormat)
     198                                                const QByteArray &format,
     199                                                bool autoDetectImageFormat,
     200                                                bool ignoresFormatAndExtension)
    199201{
    200202    if (!autoDetectImageFormat && format.isEmpty())
     
    218220#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    219221    int suffixPluginIndex = -1;
    220     if (device && format.isEmpty() && autoDetectImageFormat) {
     222    if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
    221223        // if there's no format, see if \a device is a file, and if so, find
    222224        // the file suffix and find support for that format among our plugins.
     
    241243
    242244    QByteArray testFormat = !form.isEmpty() ? form : suffix;
     245
     246    if (ignoresFormatAndExtension)
     247        testFormat = QByteArray();
    243248
    244249#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     
    259264    }
    260265
    261     if (!handler && !testFormat.isEmpty() && autoDetectImageFormat) {
     266    if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
    262267        // check if any plugin supports the format (they are not allowed to
    263268        // read from the device yet).
     
    316321
    317322#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    318     if (!handler && autoDetectImageFormat) {
     323    if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
    319324        // check if any of our plugins recognize the file from its contents.
    320325        const qint64 pos = device ? device->pos() : 0;
     
    336341#endif
    337342
    338     if (!handler && autoDetectImageFormat) {
     343    if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
    339344        // check if any of our built-in handlers recognize the file from its
    340345        // contents.
     
    435440    QByteArray format;
    436441    bool autoDetectImageFormat;
     442    bool ignoresFormatAndExtension;
    437443    QIODevice *device;
    438444    bool deleteDevice;
     
    459465*/
    460466QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq)
    461     : autoDetectImageFormat(true)
     467    : autoDetectImageFormat(true), ignoresFormatAndExtension(false)
    462468{
    463469    device = 0;
     
    466472    quality = -1;
    467473    imageReaderError = QImageReader::UnknownError;
    468     errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));
    469474
    470475    q = qq;
     
    523528
    524529    // assign a handler
    525     if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat)) == 0) {
     530    if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
    526531        imageReaderError = QImageReader::UnsupportedFormatError;
    527532        errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
     
    665670    when trying to read the image.
    666671
    667     \endlist   
     672    \endlist
    668673
    669674    By disabling image format autodetection, QImageReader will only query the
     
    682687    reader; otherwise returns false. By default, autodetection is enabled.
    683688
    684     \sa setAutoDetectImageFormat()   
     689    \sa setAutoDetectImageFormat()
    685690*/
    686691bool QImageReader::autoDetectImageFormat() const
     
    688693    return d->autoDetectImageFormat;
    689694}
     695
     696
     697/*!
     698    If \a ignored is set to true, then the image reader will ignore
     699    specified formats or file extensions and decide which plugin to
     700    use only based on the contents in the datastream.
     701
     702    Setting this flag means that all image plugins gets loaded. Each
     703    plugin will read the first bytes in the image data and decide if
     704    the plugin is compatible or not.
     705
     706    This also disables auto detecting the image format.
     707
     708    \sa decideFormatFromContent()
     709*/
     710
     711void QImageReader::setDecideFormatFromContent(bool ignored)
     712{
     713    d->ignoresFormatAndExtension = ignored;
     714}
     715
     716
     717/*!
     718    Returns whether the image reader should decide which plugin to use
     719    only based on the contents of the datastream rather than on the file
     720    extension.
     721
     722    \sa setDecideFormatFromContent()
     723*/
     724
     725bool QImageReader::decideFormatFromContent() const
     726{
     727    return d->ignoresFormatAndExtension;
     728}
     729
    690730
    691731/*!
     
    11741214
    11751215/*!
    1176     For image formats that support animation, this function returns
    1177     the number of times the animation should loop. Otherwise, it
    1178     returns -1.
    1179 
    1180     \sa supportsAnimation(), QImageIOHandler::loopCount()
     1216    For image formats that support animation, this function returns the number
     1217    of times the animation should loop. If this function returns -1, it can
     1218    either mean the animation should loop forever, or that an error occurred.
     1219    If an error occurred, canRead() will return false.
     1220
     1221    \sa supportsAnimation(), QImageIOHandler::loopCount(), canRead()
    11811222*/
    11821223int QImageReader::loopCount() const
     
    11881229
    11891230/*!
    1190     For image formats that support animation, this function returns
    1191     the total number of images in the animation.
    1192 
    1193     Certain animation formats do not support this feature, in which
    1194     case 0 is returned.
    1195 
    1196     \sa supportsAnimation(), QImageIOHandler::imageCount()
     1231    For image formats that support animation, this function returns the total
     1232    number of images in the animation. If the format does not support
     1233    animation, 0 is returned.
     1234
     1235    This function returns -1 if an error occurred.
     1236
     1237    \sa supportsAnimation(), QImageIOHandler::imageCount(), canRead()
    11971238*/
    11981239int QImageReader::imageCount() const
     
    12041245
    12051246/*!
    1206     For image formats that support animation, this function returns
    1207     the number of milliseconds to wait until displaying the next frame
    1208     in the animation. Otherwise, 0 is returned.
    1209 
    1210     \sa supportsAnimation(), QImageIOHandler::nextImageDelay()
     1247    For image formats that support animation, this function returns the number
     1248    of milliseconds to wait until displaying the next frame in the animation.
     1249    If the image format doesn't support animation, 0 is returned.
     1250
     1251    This function returns -1 if an error occurred.
     1252
     1253    \sa supportsAnimation(), QImageIOHandler::nextImageDelay(), canRead()
    12111254*/
    12121255int QImageReader::nextImageDelay() const
     
    12181261
    12191262/*!
    1220     For image formats that support animation, this function returns
    1221     the sequence number of the current frame. Otherwise, -1 is
    1222     returned.
    1223 
    1224     \sa supportsAnimation(), QImageIOHandler::currentImageNumber()
     1263    For image formats that support animation, this function returns the
     1264    sequence number of the current frame. If the image format doesn't support
     1265    animation, 0 is returned.
     1266
     1267    This function returns -1 if an error occurred.
     1268
     1269    \sa supportsAnimation(), QImageIOHandler::currentImageNumber(), canRead()
    12251270*/
    12261271int QImageReader::currentImageNumber() const
     
    12621307QString QImageReader::errorString() const
    12631308{
     1309    if (d->errorString.isEmpty())
     1310        return QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));
    12641311    return d->errorString;
    12651312}
     
    13101357{
    13111358    QByteArray format;
    1312     QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true);
     1359    QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true, false);
    13131360    if (handler) {
    13141361        if (handler->canRead())
     
    13381385    \row    \o XBM    \o X11 Bitmap
    13391386    \row    \o XPM    \o X11 Pixmap
     1387    \row    \o SVG    \o Scalable Vector Graphics
    13401388    \endtable
    13411389
  • trunk/src/gui/image/qimagereader.h

    r2 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**
     
    8181    void setAutoDetectImageFormat(bool enabled);
    8282    bool autoDetectImageFormat() const;
     83
     84    void setDecideFormatFromContent(bool ignored);
     85    bool decideFormatFromContent() const;
    8386
    8487    void setDevice(QIODevice *device);
  • trunk/src/gui/image/qimagewriter.cpp

    r2 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**
     
    4646
    4747    \reentrant
    48     \ingroup multimedia
     48    \ingroup painting
    4949    \ingroup io
    5050
  • trunk/src/gui/image/qimagewriter.h

    r2 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**
  • trunk/src/gui/image/qmovie.cpp

    r2 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**
     
    4646    with QImageReader.
    4747
    48     \ingroup multimedia
     48    \ingroup painting
     49
     50    This class is used to show simple animations without sound. If you want
     51    to display video and media content, use the \l{Phonon Module}{Phonon}
     52    multimedia framework instead.
    4953
    5054    First, create a QMovie object by passing either the name of a file or a
     
    357361                    else
    358362                        reader = new QImageReader(absoluteFilePath, format);
    359                     reader->canRead(); // Provoke a device->open() call
     363                    (void)reader->canRead(); // Provoke a device->open() call
    360364                    reader->device()->seek(initialDevicePos);
    361365                    reader->setBackgroundColor(bgColor);
  • trunk/src/gui/image/qmovie.h

    r2 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**
  • trunk/src/gui/image/qnativeimage.cpp

    r115 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**
     
    5151#include <sys/shm.h>
    5252#include <qwidget.h>
     53#endif
     54
     55#ifdef Q_WS_MAC
     56#include <private/qpaintengine_mac_p.h>
    5357#endif
    5458
     
    6670QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool isTextBuffer, QWidget *)
    6771{
    68 #ifndef Q_OS_WINCE
     72#ifndef Q_WS_WINCE
    6973    Q_UNUSED(isTextBuffer);
    7074#endif
     
    7983    if (format == QImage::Format_RGB16) {
    8084        bmi.bmiHeader.biBitCount = 16;
    81 #ifdef Q_OS_WINCE
     85#ifdef Q_WS_WINCE
    8286        if (isTextBuffer) {
    8387            bmi.bmiHeader.biCompression = BI_RGB;
     
    117121    static_cast<QRasterPaintEngine *>(image.paintEngine())->setDC(hdc);
    118122
    119 #ifndef Q_OS_WINCE
     123#ifndef Q_WS_WINCE
    120124    GdiFlush();
    121125#endif
     
    164168
    165169QNativeImage::QNativeImage(int width, int height, QImage::Format format,bool /* isTextBuffer */, QWidget *widget)
     170    : xshmimg(0), xshmpm(0)
    166171{
    167172    if (!X11->use_mitshm) {
    168         xshmimg = 0;
    169         xshmpm = 0;
    170173        image = QImage(width, height, format);
     174        // follow good coding practice and set xshminfo attributes, though values not used in this case
     175        xshminfo.readOnly = true;
     176        xshminfo.shmaddr = 0;
     177        xshminfo.shmid = 0;
     178        xshminfo.shmseg = 0;
    171179        return;
    172180    }
     
    190198        xshmimg->data = (char*)shmat(xshminfo.shmid, 0, 0);
    191199        xshminfo.shmaddr = xshmimg->data;
     200        if (shmctl(xshminfo.shmid, IPC_RMID, 0) == -1)
     201            qWarning() << "Error while marking the shared memory segment to be destroyed";
    192202        ok = (xshminfo.shmaddr != (char*)-1);
    193203        if (ok)
     
    211221        return;
    212222    }
    213     xshmpm = XShmCreatePixmap(X11->display, DefaultRootWindow(X11->display), xshmimg->data,
    214                               &xshminfo, width, height, dd);
    215     if (!xshmpm) {
    216         qWarning() << "QNativeImage: Unable to create shared Pixmap.";
     223    if (X11->use_mitshm_pixmaps) {
     224        xshmpm = XShmCreatePixmap(X11->display, DefaultRootWindow(X11->display), xshmimg->data,
     225                                  &xshminfo, width, height, dd);
     226        if (!xshmpm) {
     227            qWarning() << "QNativeImage: Unable to create shared Pixmap.";
     228        }
    217229    }
    218230}
     
    245257#elif defined(Q_WS_MAC)
    246258
    247 QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget *)
     259QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget *widget)
    248260    : image(width, height, format)
    249261{
    250     cgColorSpace = CGColorSpaceCreateDeviceRGB();
     262
     263
    251264    uint cgflags = kCGImageAlphaNoneSkipFirst;
    252265
    253266#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
    254     if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    255         cgflags |= kCGBitmapByteOrder32Host;
    256 #endif
    257 
    258     cg = CGBitmapContextCreate(image.bits(), width, height, 8, image.bytesPerLine(), cgColorSpace, cgflags);
     267    cgflags |= kCGBitmapByteOrder32Host;
     268#endif
     269
     270    cg = CGBitmapContextCreate(image.bits(), width, height, 8, image.bytesPerLine(),
     271                               QCoreGraphicsPaintEngine::macDisplayColorSpace(widget), cgflags);
    259272    CGContextTranslateCTM(cg, 0, height);
    260273    CGContextScaleCTM(cg, 1, -1);
     
    268281{
    269282    CGContextRelease(cg);
    270     CGColorSpaceRelease(cgColorSpace);
    271283}
    272284
  • trunk/src/gui/image/qnativeimage_p.h

    r115 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**
     
    7171class QWidget;
    7272
    73 class Q_GUI_EXPORT QNativeImage
     73class QNativeImage
    7474{
    7575public:
     
    9696#elif defined(Q_WS_MAC)
    9797    CGContextRef cg;
    98     CGColorSpaceRef cgColorSpace;
    9998#endif
    10099
  • trunk/src/gui/image/qpaintengine_pic.cpp

    r2 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**
  • trunk/src/gui/image/qpaintengine_pic_p.h

    r2 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**
  • trunk/src/gui/image/qpicture.cpp

    r2 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**
     
    7070    replays QPainter commands.
    7171
    72     \ingroup multimedia
     72    \ingroup painting
    7373    \ingroup shared
    74     \mainclass
     74
    7575
    7676    A picture serializes painter commands to an IO device in a
     
    132132{
    133133    Q_D(QPicture);
    134     d_ptr->q_ptr = this;
    135     d->paintEngine = 0;
    136134
    137135    if (formatVersion == 0)
     
    143141        d->formatMinor = 0;
    144142        d->formatOk = false;
    145     }
    146     else {
     143    } else {
    147144        d->resetFormat();
    148145    }
     
    158155    : QPaintDevice(), d_ptr(pic.d_ptr)
    159156{
    160     d_func()->ref.ref();
    161157}
    162158
     
    166162      d_ptr(&dptr)
    167163{
    168     d_ptr->q_ptr = this;
    169164}
    170165
     
    174169QPicture::~QPicture()
    175170{
    176     if (!d_func()->ref.deref()) {
    177         delete d_func()->paintEngine;
    178         delete d_func();
    179     }
    180171}
    181172
     
    231222void QPicture::detach()
    232223{
    233     if (d_func()->ref != 1)
    234         detach_helper();
     224    d_ptr.detach();
    235225}
    236226
     
    955945
    956946/*!
     947    \internal
     948
    957949    Internal implementation of the virtual QPaintDevice::metric()
    958950    function.
     
    10161008\internal
    10171009*/
     1010
     1011/*! \internal
     1012### Qt 5 - remove me
     1013 */
    10181014void QPicture::detach_helper()
    10191015{
    1020     Q_D(QPicture);
    1021     QPicturePrivate *x = new QPicturePrivate;
    1022     int pictsize = size();
    1023     x->pictb.setData(data(), pictsize);
    1024     if (d->pictb.isOpen()) {
    1025         x->pictb.open(d->pictb.openMode());
    1026         x->pictb.seek(d->pictb.pos());
    1027     }
    1028     x->trecs = d->trecs;
    1029     x->formatOk = d->formatOk;
    1030     x->formatMinor = d->formatMinor;
    1031     x->brect = d->brect;
    1032     x->override_rect = d->override_rect;
    1033     if (!d->ref.deref())
    1034         delete d;
    1035     d_ptr = x;
     1016    // QExplicitelySharedDataPointer takes care of cloning using
     1017    // QPicturePrivate's copy constructor. Do not call detach_helper() anymore
     1018    // and remove in Qt 5, please.
     1019    Q_ASSERT_X(false, "QPicture::detach_helper()", "Do not call this function");
    10361020}
    10371021
     
    10421026QPicture& QPicture::operator=(const QPicture &p)
    10431027{
    1044     qAtomicAssign<QPicturePrivate>(d_ptr, p.d_ptr);
     1028    d_ptr = p.d_ptr;
    10451029    return *this;
     1030}
     1031
     1032/*!
     1033  \internal
     1034
     1035  Constructs a QPicturePrivate
     1036*/
     1037QPicturePrivate::QPicturePrivate()
     1038    : in_memory_only(false)
     1039{
     1040}
     1041
     1042/*!
     1043  \internal
     1044
     1045  Copy-Constructs a QPicturePrivate. Needed when detaching.
     1046*/
     1047QPicturePrivate::QPicturePrivate(const QPicturePrivate &other)
     1048    : trecs(other.trecs),
     1049      formatOk(other.formatOk),
     1050      formatMinor(other.formatMinor),
     1051      brect(other.brect),
     1052      override_rect(other.override_rect),
     1053      in_memory_only(false)
     1054{
     1055    pictb.setData(other.pictb.data(), other.pictb.size());
     1056    if (other.pictb.isOpen()) {
     1057        pictb.open(other.pictb.openMode());
     1058        pictb.seek(other.pictb.pos());
     1059    }
    10461060}
    10471061
     
    11361150{
    11371151    if (!d_func()->paintEngine)
    1138         const_cast<QPicture*>(this)->d_func()->paintEngine = new QPicturePaintEngine;
    1139     return d_func()->paintEngine;
     1152        const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine);
     1153    return d_func()->paintEngine.data();
    11401154}
    11411155
     
    11441158 *****************************************************************************/
    11451159
     1160#ifndef QT_NO_DATASTREAM
    11461161/*!
    11471162    \relates QPicture
     
    11891204    return s;
    11901205}
     1206#endif // QT_NO_DATASTREAM
    11911207
    11921208
     
    12951311    saving pictures.
    12961312
    1297     \ingroup multimedia
     1313    \ingroup painting
    12981314    \ingroup io
    12991315
  • trunk/src/gui/image/qpicture.h

    r2 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**
     
    4343#define QPICTURE_H
    4444
     45#include <QtCore/qstringlist.h>
     46#include <QtCore/qsharedpointer.h>
    4547#include <QtGui/qpaintdevice.h>
    46 #include <QtCore/qstringlist.h>
    4748
    4849QT_BEGIN_HEADER
     
    107108    void detach_helper();
    108109
    109     QPicturePrivate *d_ptr;
     110    QExplicitlySharedDataPointer<QPicturePrivate> d_ptr;
    110111    friend class QPicturePaintEngine;
    111112    friend class Q3Picture;
     
    114115
    115116public:
    116     typedef QPicturePrivate* DataPtr;
     117    typedef QExplicitlySharedDataPointer<QPicturePrivate> DataPtr;
    117118    inline DataPtr &data_ptr() { return d_ptr; }
    118119};
     
    185186 *****************************************************************************/
    186187
     188#ifndef QT_NO_DATASTREAM
    187189Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPicture &);
    188190Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPicture &);
     191#endif
    189192
    190193#endif // QT_NO_PICTURE
  • trunk/src/gui/image/qpicture_p.h

    r2 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**
     
    7070extern const char  *qt_mfhdr_tag;
    7171
    72 class Q_GUI_EXPORT QPicturePrivate
     72class QPicturePrivate
    7373{
    74     Q_DECLARE_PUBLIC(QPicture)
    7574    friend class QPicturePaintEngine;
    7675    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPicture &r);
     
    144143    };
    145144
    146     inline QPicturePrivate() : in_memory_only(false), q_ptr(0) { ref = 1; }
     145    QPicturePrivate();
     146    QPicturePrivate(const QPicturePrivate &other);
    147147    QAtomicInt ref;
    148148
     
    157157    QRect brect;
    158158    QRect override_rect;
    159     QPaintEngine *paintEngine;
     159    QScopedPointer<QPaintEngine> paintEngine;
    160160    bool in_memory_only;
    161161    QList<QImage> image_list;
     
    163163    QList<QBrush> brush_list;
    164164    QList<QPen> pen_list;
    165 
    166     QPicture *q_ptr;
    167165};
    168166
  • trunk/src/gui/image/qpictureformatplugin.cpp

    r2 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**
  • trunk/src/gui/image/qpictureformatplugin.h

    r2 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**
  • 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
  • trunk/src/gui/image/qpixmap.h

    r342 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**
     
    4747#include <QtCore/qnamespace.h>
    4848#include <QtCore/qstring.h> // char*->QString conversion
     49#include <QtCore/qsharedpointer.h>
    4950#include <QtGui/qimage.h>
    5051#include <QtGui/qtransform.h>
    5152
    5253QT_BEGIN_HEADER
     54
     55#if defined(Q_OS_SYMBIAN)
     56class CFbsBitmap;
     57class RSgImage;
     58#endif
    5359
    5460QT_BEGIN_NAMESPACE
     
    6066class QVariant;
    6167class QX11Info;
     68
     69#if defined(Q_WS_PM)
    6270class QIcon;
     71#endif
    6372
    6473class QPixmapData;
     
    8190    operator QVariant() const;
    8291
    83     bool isNull() const;
     92    bool isNull() const; // ### Qt 5: make inline
    8493    int devType() const;
    8594
    86     int width() const;
    87     int height() const;
     95    int width() const; // ### Qt 5: make inline
     96    int height() const; // ### Qt 5: make inline
    8897    QSize size() const;
    8998    QRect rect() const;
     
    146155
    147156    HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const;
     157    HICON toWinHICON() const;
     158
    148159    static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha);
     160    static QPixmap fromWinHICON(HICON hicon);
    149161#endif
    150162
     
    162174#endif
    163175
     176#if defined(Q_OS_SYMBIAN)
     177    CFbsBitmap *toSymbianCFbsBitmap() const;
     178    static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap);
     179    RSgImage* toSymbianRSgImage() const;
     180    static QPixmap fromSymbianRSgImage(RSgImage *sgImage);
     181#endif
     182
    164183    inline QPixmap copy(int x, int y, int width, int height) const;
    165184    QPixmap copy(const QRect &rect = QRect()) const;
     185
     186    inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
     187    void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
    166188
    167189    int serialNumber() const;
     
    177199    int qwsBytesPerLine() const;
    178200    QRgb *clut() const;
    179     int numCols() const;
     201#ifdef QT_DEPRECATED
     202    QT_DEPRECATED int numCols() const;
     203#endif
     204    int colorCount() const;
    180205#elif defined(Q_WS_MAC)
    181206    Qt::HANDLE macQDHandle() const;
     
    226251
    227252private:
    228     QPixmapData *data;
     253    QExplicitlySharedDataPointer<QPixmapData> data;
    229254
    230255    bool doImageIO(QImageWriter *io, int quality) const;
     
    252277    friend class QX11PixmapData;
    253278    friend class QMacPixmapData;
     279    friend class QS60PixmapData;
    254280    friend class QBitmap;
    255281    friend class QPaintDevice;
     
    261287    friend class QRasterPaintEngine;
    262288    friend class QRasterBuffer;
    263     friend class QDirect3DPaintEngine;
    264     friend class QDirect3DPaintEnginePrivate;
    265     friend class QDetachedPixmap;
     289    friend class QPixmapCacheEntry;
    266290#if !defined(QT_NO_DATASTREAM)
    267291    friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
     
    273297
    274298public:
    275     typedef QPixmapData * DataPtr;
     299    typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
    276300    inline DataPtr &data_ptr() { return data; }
    277301};
     
    282306{
    283307    return copy(QRect(ax, ay, awidth, aheight));
     308}
     309
     310inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
     311{
     312    scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
    284313}
    285314
  • trunk/src/gui/image/qpixmap_mac.cpp

    r2 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**
    4040****************************************************************************/
    41 //#define QT_RASTER_PAINTENGINE
    4241
    4342#include "qpixmap.h"
     
    5352#include <private/qpixmap_mac_p.h>
    5453#include <private/qpixmap_raster_p.h>
    55 #ifdef QT_RASTER_PAINTENGINE
    56 #  include <private/qpaintengine_raster_p.h>
    57 #endif
    5854#include <private/qpaintengine_mac_p.h>
    5955#include <private/qt_mac_p.h>
     
    7874Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix)
    7975{
    80     return static_cast<QMacPixmapData*>(pix->data)->pixels;
     76    return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
    8177}
    8278
    8379Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix)
    8480{
    85     return static_cast<QMacPixmapData*>(pix->data)->bytesPerRow;
     81    return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
    8682}
    8783
     
    120116                                     0);
    121117
    122 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    123118    uint cgflags = kCGImageAlphaPremultipliedFirst;
    124119#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
    125     if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    126         cgflags |= kCGBitmapByteOrder32Host;
    127 #endif
    128 #else
    129     CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst;
     120    cgflags |= kCGBitmapByteOrder32Host;
    130121#endif
    131122
     
    169160
    170161QMacPixmapData::QMacPixmapData(PixelType type)
    171     : QPixmapData(type, MacClass), w(0), h(0), d(0), has_alpha(0), has_mask(0),
    172       uninit(true), pixels(0), pixelsToFree(0), bytesPerRow(0),
    173       cg_data(0), cg_dataBeingReleased(0), cg_mask(0),
    174 #ifndef QT_MAC_NO_QUICKDRAW
    175       qd_data(0), qd_alpha(0),
    176 #endif
     162    : QPixmapData(type, MacClass), has_alpha(0), has_mask(0),
     163      uninit(true), pixels(0), pixelsSize(0), pixelsToFree(0),
     164      bytesPerRow(0), cg_data(0), cg_dataBeingReleased(0), cg_mask(0),
    177165      pengine(0)
    178166{
     167}
     168
     169QPixmapData *QMacPixmapData::createCompatiblePixmapData() const
     170{
     171    return new QMacPixmapData(pixelType());
    179172}
    180173
     
    189182    w = width;
    190183    h = height;
     184    is_null = (w <= 0 || h <= 0);
    191185    d = (pixelType() == BitmapType ? 1 : 32);
    192186    bool make_null = w <= 0 || h <= 0;                // create null pixmap
     
    194188        w = 0;
    195189        h = 0;
     190        is_null = true;
    196191        d = 0;
    197192        if (!make_null)
     
    232227    w = img.width();
    233228    h = img.height();
     229    is_null = (w <= 0 || h <= 0);
    234230    d = (pixelType() == BitmapType ? 1 : img.depth());
    235231
     
    253249            conv8 = d == 1;                     // native depth wanted
    254250        } else if (d == 1) {
    255             if (image.numColors() == 2) {
     251            if (image.colorCount() == 2) {
    256252                QRgb c0 = image.color(0);       // Auto: convert to best
    257253                QRgb c1 = image.color(1);
     
    310306            break;
    311307        }
    312         case QImage::Format_Indexed8:
    313             for (int x = 0; x < w; ++x) {
    314                 *(drow+x) = PREMUL(image.color(*(srow + x)));
     308        case QImage::Format_Indexed8: {
     309            int numColors = image.numColors();
     310            if (numColors > 0) {
     311                for (int x = 0; x < w; ++x) {
     312                    int index = *(srow + x);
     313                    *(drow+x) = PREMUL(image.color(qMin(index, numColors)));
     314                }
    315315            }
    316             break;
     316        } break;
    317317        case QImage::Format_RGB32:
    318318            for (int x = 0; x < w; ++x)
     
    340340        if (sfmt == QImage::Format_Indexed8) {
    341341            const QVector<QRgb> rgb = image.colorTable();
    342             for (int i = 0, count = image.numColors(); i < count; ++i) {
     342            for (int i = 0, count = image.colorCount(); i < count; ++i) {
    343343                const int alpha = qAlpha(rgb[i]);
    344344                if (alpha != 0xff) {
     
    356356{
    357357    int loopc;
    358     for(loopc=0;loopc<qi->numColors();loopc++) {
     358    for(loopc=0;loopc<qi->colorCount();loopc++) {
    359359        if(qi->color(loopc)==mycol)
    360360            return loopc;
    361361    }
    362     qi->setNumColors(qi->numColors()+1);
    363     qi->setColor(qi->numColors(),mycol);
    364     return qi->numColors();
     362    qi->setColorCount(qi->colorCount()+1);
     363    qi->setColor(qi->colorCount(),mycol);
     364    return qi->colorCount();
    365365}
    366366
     
    377377    if (format == QImage::Format_MonoLSB) {
    378378        image.fill(0);
    379         image.setNumColors(2);
     379        image.setColorCount(2);
    380380        image.setColor(0, QColor(Qt::color0).rgba());
    381381        image.setColor(1, QColor(Qt::color1).rgba());
     
    431431{
    432432    has_mask = true;
    433     QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data);
     433    QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data());
    434434    macSetAlphaChannel(alphaData, false);
    435435}
     
    459459    has_alpha = false;
    460460    has_mask = true;
    461     QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data);
     461    QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data());
    462462    macSetAlphaChannel(maskData, true);
    463463}
     
    497497{
    498498    validDataPointers.remove(this);
    499 #ifndef QT_MAC_NO_QUICKDRAW
    500     macQDDisposeAlpha();
    501     if (qd_data) {
    502         DisposeGWorld(qd_data);
    503         qd_data = 0;
    504     }
    505 #endif
    506499    if (cg_mask) {
    507500        CGImageRelease(cg_mask);
     
    592585{
    593586    has_alpha = b;
    594 #ifndef QT_MAC_NO_QUICKDRAW
    595     macQDDisposeAlpha(); //let it get created lazily
    596 #endif
    597587    macReleaseCGImageRef();
    598588}
    599 
    600 #ifndef QT_MAC_NO_QUICKDRAW
    601 void QMacPixmapData::macQDDisposeAlpha()
    602 {
    603     if (qd_alpha) {
    604         DisposeGWorld(qd_alpha);
    605         qd_alpha = 0;
    606     }
    607 }
    608 
    609 void QMacPixmapData::macQDUpdateAlpha()
    610 {
    611     macQDDisposeAlpha(); // get rid of alpha pixmap
    612     if (!has_alpha && !has_mask)
    613         return;
    614 
    615     //setup
    616     Rect rect;
    617     SetRect(&rect, 0, 0, w, h);
    618     const int params = alignPix | stretchPix | newDepth;
    619     NewGWorld(&qd_alpha, 32, &rect, 0, 0, params);
    620     int *dptr = (int *)GetPixBaseAddr(GetGWorldPixMap(qd_alpha)), *drow;
    621     unsigned short dbpr = GetPixRowBytes(GetGWorldPixMap(qd_alpha));
    622     const int *sptr = (int*)pixels, *srow;
    623     const uint sbpr = bytesPerRow;
    624     uchar clr;
    625     for (int y = 0; y < h; ++y) {
    626         drow = (int*)((char *)dptr + (y * dbpr));
    627         srow = (int*)((char *)sptr + (y * sbpr));
    628         for (int x=0; x < w; x++) {
    629             clr = qAlpha(*(srow + x));
    630             *(drow + x) = qRgba(~clr, ~clr, ~clr, 0);
    631         }
    632     }
    633 }
    634 #endif
    635589
    636590void QMacPixmapData::macCreateCGImageRef()
     
    643597                                                              qt_mac_cgimage_data_free);
    644598    validDataPointers.insert(this);
    645 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    646599    uint cgflags = kCGImageAlphaPremultipliedFirst;
    647600#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
    648     if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    649         cgflags |= kCGBitmapByteOrder32Host;
    650 #endif
    651 #else
    652     CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst;
     601    cgflags |= kCGBitmapByteOrder32Host;
    653602#endif
    654603    cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace,
     
    689638
    690639    if (pixels)
    691         memcpy(base_pixels, pixels, numBytes);
     640        memcpy(base_pixels, pixels, pixelsSize);
    692641    pixels = base_pixels;
     642    pixelsSize = numBytes;
    693643}
    694644
     
    891841}
    892842
    893 static CGImageRef qt_mac_createImageFromBitmapContext(CGContextRef c)
    894 {
    895     void *rasterData = CGBitmapContextGetData(c);
    896     const int width = CGBitmapContextGetBytesPerRow(c),
    897              height = CGBitmapContextGetHeight(c);
    898     size_t imageDataSize = width*height;
    899 
    900     if(!rasterData)
    901         return 0;
    902 
    903     // Create the data provider from the image data, using
    904     // the image releaser function releaseBitmapContextImageData.
    905     CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, rasterData,
    906                                                                   imageDataSize,
    907                                                                   qt_mac_cgimage_data_free);
    908 
    909     if(!dataProvider)
    910         return 0;
    911 
    912     uint bitmapInfo = 0;
    913 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    914     if(CGBitmapContextGetBitmapInfo)
    915         bitmapInfo = CGBitmapContextGetBitmapInfo(c);
    916     else
    917 #endif
    918         bitmapInfo = CGBitmapContextGetAlphaInfo(c);
    919     return CGImageCreate(width, height, CGBitmapContextGetBitsPerComponent(c),
    920                          CGBitmapContextGetBitsPerPixel(c), CGBitmapContextGetBytesPerRow(c),
    921                          CGBitmapContextGetColorSpace(c), bitmapInfo, dataProvider,
    922                          0, true, kCGRenderingIntentDefault);
    923 }
    924 
    925843// Returns a pixmap containing the screen contents at rect.
    926844static QPixmap qt_mac_grabScreenRect(const QRect &rect)
     
    956874                                        QCoreGraphicsPaintEngine::macGenericColorSpace(),
    957875                                        kCGImageAlphaNoneSkipFirst);
    958 
    959 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    960     if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    961         QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
    962         return QPixmap::fromMacCGImageRef(image);
    963     } else
    964 #endif
    965     {
    966         QCFType<CGImageRef> image = qt_mac_createImageFromBitmapContext(bitmap);
    967         if (!image)
    968             return QPixmap();
    969         return QPixmap::fromMacCGImageRef(image);
    970     }
     876    QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
     877    return QPixmap::fromMacCGImageRef(image);
    971878}
    972879
     
    1030937
    1031938    \warning This function is only available on Mac OS X.
     939    \warning As of Qt 4.6, this function \e{always} returns zero.
    1032940*/
    1033941
    1034942Qt::HANDLE QPixmap::macQDHandle() const
    1035943{
    1036 #ifndef QT_MAC_NO_QUICKDRAW
    1037     QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
    1038     if (!d->qd_data) { //create the qd data
    1039         Rect rect;
    1040         SetRect(&rect, 0, 0, d->w, d->h);
    1041         unsigned long qdformat = k32ARGBPixelFormat;
    1042         GWorldFlags qdflags = 0;
    1043 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    1044         if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    1045             //we play such games so we can use the same buffer in CG as QD this
    1046             //makes our merge much simpler, at some point the hacks will go away
    1047             //because QD will be removed, but until that day this keeps them coexisting
    1048             if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
    1049                 qdformat = k32BGRAPixelFormat;
    1050 #if 0
    1051             qdflags |= kNativeEndianPixMap;
    1052 #endif
    1053         }
    1054 #endif
    1055         if(NewGWorldFromPtr(&d->qd_data, qdformat, &rect, 0, 0, qdflags,
    1056                             (char*)d->pixels, d->bytesPerRow) != noErr)
    1057             qWarning("Qt: internal: QPixmap::init error (%d %d %d %d)", rect.left, rect.top, rect.right, rect.bottom);
    1058     }
    1059     return d->qd_data;
    1060 #else
    1061944    return 0;
    1062 #endif
    1063945}
    1064946
     
    1070952
    1071953    \warning This function is only available on Mac OS X.
     954    \warning As of Qt 4.6, this function \e{always} returns zero.
    1072955*/
    1073956
    1074957Qt::HANDLE QPixmap::macQDAlphaHandle() const
    1075958{
    1076 #ifndef QT_MAC_NO_QUICKDRAW
    1077     QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
    1078     if (d->has_alpha || d->has_mask) {
    1079         if (!d->qd_alpha) //lazily created
    1080             d->macQDUpdateAlpha();
    1081         return d->qd_alpha;
    1082     }
    1083 #endif
    1084959    return 0;
    1085960}
     
    1096971Qt::HANDLE QPixmap::macCGHandle() const
    1097972{
     973    if (isNull())
     974        return 0;
     975
    1098976    if (data->classId() == QPixmapData::MacClass) {
    1099         QMacPixmapData *d = static_cast<QMacPixmapData *>(data);
     977        QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data());
    1100978        if (!d->cg_data)
    1101979            d->macCreateCGImageRef();
     
    1104982        return ret;
    1105983    } else if (data->classId() == QPixmapData::RasterClass) {
    1106         return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data)->image);
     984        return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data.data())->image);
    1107985    }
    1108986    return 0;
     
    1116994CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr)
    1117995{
    1118     QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data);
     996    QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
    1119997    if (px->cg_mask) {
    1120998        if (px->cg_mask_rect == sr) {
     
    11511029        return 0;
    11521030
    1153     QMacSavedPortInfo pi; //save the current state
    11541031    //create icon
    11551032    IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
     
    12261103#endif
    12271104
    1228 QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
    1229 {
    1230     QPixmap ret(width, height);
    1231     ret.fill(QColor(0, 0, 0, 0));
    1232 
    1233     CGRect rect = CGRectMake(0, 0, width, height);
    1234 
    1235     CGContextRef ctx = qt_mac_cg_context(&ret);
    1236     CGAffineTransform old_xform = CGContextGetCTM(ctx);
    1237     CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));
    1238     CGContextConcatCTM(ctx, CGAffineTransformIdentity);
    1239 
    1240     ::RGBColor b;
    1241     b.blue = b.green = b.red = 255*255;
    1242     PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);
    1243     CGContextRelease(ctx);
    1244     return ret;
    1245 }
    1246 
    12471105/*! \internal */
    12481106QPaintEngine* QMacPixmapData::paintEngine() const
     
    12501108    if (!pengine) {
    12511109        QMacPixmapData *that = const_cast<QMacPixmapData*>(this);
    1252 #ifdef QT_RASTER_PAINTENGINE
    1253         if (qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())
    1254             that->pengine = new QRasterPaintEngine();
    1255         else
    1256             that->pengine = new QCoreGraphicsPaintEngine();
    1257 #else
    12581110        that->pengine = new QCoreGraphicsPaintEngine();
    1259 #endif
    12601111    }
    12611112    return pengine;
     
    12911142}
    12921143
     1144bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect)
     1145{
     1146    Q_UNUSED(dx);
     1147    Q_UNUSED(dy);
     1148    Q_UNUSED(rect);
     1149    return false;
     1150}
     1151
    12931152/*!
    12941153    \since 4.2
     
    13221181                 h = CGImageGetHeight(image);
    13231182    QPixmap ret(w, h);
     1183    ret.fill(Qt::transparent);
    13241184    CGRect rect = CGRectMake(0, 0, w, h);
    13251185    CGContextRef ctx = qt_mac_cg_context(&ret);
  • trunk/src/gui/image/qpixmap_mac_p.h

    r2 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**
     
    6666    ~QMacPixmapData();
    6767
     68    QPixmapData *createCompatiblePixmapData() const;
     69
    6870    void resize(int width, int height);
    6971    void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
    7072    void copy(const QPixmapData *data, const QRect &rect);
     73    bool scroll(int dx, int dy, const QRect &rect);
    7174
    7275    int metric(QPaintDevice::PaintDeviceMetric metric) const;
     
    8386
    8487private:
    85     int w, h, d;
    8688
    8789    uint has_alpha : 1, has_mask : 1, uninit : 1;
     
    106108    */
    107109    quint32 *pixels;
     110    uint pixelsSize;
    108111    quint32 *pixelsToFree;
    109112    uint bytesPerRow;
    110113    QRectF cg_mask_rect;
    111114    CGImageRef cg_data, cg_dataBeingReleased, cg_mask;
    112 #ifndef QT_MAC_NO_QUICKDRAW
    113     GWorldPtr qd_data, qd_alpha;
    114     void macQDDisposeAlpha();
    115     void macQDUpdateAlpha();
    116 #endif
    117115    static QSet<QMacPixmapData*> validDataPointers;
    118116
  • trunk/src/gui/image/qpixmap_raster.cpp

    r2 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**
     
    5151#include <private/qdrawhelper_p.h>
    5252
    53 #if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
    54 #include <private/qpaintengine_d3d_p.h>
    55 #include <d3d9.h>
    56 extern QDirect3DPaintEngine *qt_d3dEngine();
    57 #endif
    58 
    5953QT_BEGIN_NAMESPACE
    6054
     
    6256                                     0x10, 0x20, 0x40, 0x80 };
    6357
     58QPixmap qt_toRasterPixmap(const QImage &image)
     59{
     60    QPixmapData *data =
     61        new QRasterPixmapData(image.depth() == 1
     62                           ? QPixmapData::BitmapType
     63                           : QPixmapData::PixmapType);
     64
     65    data->fromImage(image, Qt::AutoColor);
     66
     67    return QPixmap(data);
     68}
     69
     70QPixmap qt_toRasterPixmap(const QPixmap &pixmap)
     71{
     72    if (pixmap.isNull())
     73        return QPixmap();
     74
     75    if (QPixmap(pixmap).data_ptr()->classId() == QPixmapData::RasterClass)
     76        return pixmap;
     77
     78    return qt_toRasterPixmap(pixmap.toImage());
     79}
     80
    6481QRasterPixmapData::QRasterPixmapData(PixelType type)
    6582    : QPixmapData(type, RasterClass)
    66 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
    67     , texture(0)
    68 #endif
    6983{
    7084}
     
    7286QRasterPixmapData::~QRasterPixmapData()
    7387{
     88}
     89
     90QPixmapData *QRasterPixmapData::createCompatiblePixmapData() const
     91{
     92    return new QRasterPixmapData(pixelType());
    7493}
    7594
     
    95114
    96115    image = QImage(width, height, format);
     116    w = width;
     117    h = height;
     118    d = image.depth();
     119    is_null = (w <= 0 || h <= 0);
    97120
    98121    if (pixelType() == BitmapType && !image.isNull()) {
    99         image.setNumColors(2);
     122        image.setColorCount(2);
    100123        image.setColor(0, QColor(Qt::color0).rgba());
    101124        image.setColor(1, QColor(Qt::color1).rgba());
     
    178201    }
    179202#endif
     203    if (image.d) {
     204        w = image.d->width;
     205        h = image.d->height;
     206        d = image.d->depth;
     207    } else {
     208        w = h = d = 0;
     209    }
     210    is_null = (w <= 0 || h <= 0);
    180211
    181212    setSerialNumber(image.serialNumber());
     213}
     214
     215// from qwindowsurface.cpp
     216extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
     217
     218bool QRasterPixmapData::scroll(int dx, int dy, const QRect &rect)
     219{
     220    if (!image.isNull())
     221        qt_scrollRectInImage(image, rect, QPoint(dx, dy));
     222    return true;
    182223}
    183224
     
    322363int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
    323364{
     365    QImageData *d = image.d;
     366    if (!d)
     367        return 0;
     368
    324369    // override the image dpi with the screen dpi when rendering to a pixmap
    325     const int dpmX = qRound(qt_defaultDpiX() * 100 / qreal(2.54));
    326     const int dpmY = qRound(qt_defaultDpiY() * 100 / qreal(2.54));
    327370    switch (metric) {
     371    case QPaintDevice::PdmWidth:
     372        return w;
     373    case QPaintDevice::PdmHeight:
     374        return h;
    328375    case QPaintDevice::PdmWidthMM:
    329         return qRound(image.width() * 1000 / dpmX);
     376        return qRound(d->width * 25.4 / qt_defaultDpiX());
    330377    case QPaintDevice::PdmHeightMM:
    331         return qRound(image.height() * 1000 / dpmY);
    332     case QPaintDevice::PdmDpiX:
    333         return qRound(dpmX * qreal(0.0254));
    334     case QPaintDevice::PdmDpiY:
    335         return qRound(dpmY * qreal(0.0254));
     378        return qRound(d->height * 25.4 / qt_defaultDpiY());
     379    case QPaintDevice::PdmNumColors:
     380        return d->colortable.size();
     381    case QPaintDevice::PdmDepth:
     382        return this->d;
     383    case QPaintDevice::PdmDpiX: // fall-through
    336384    case QPaintDevice::PdmPhysicalDpiX:
    337         return qRound(dpmX * qreal(0.0254));
     385        return qt_defaultDpiX();
     386    case QPaintDevice::PdmDpiY: // fall-through
    338387    case QPaintDevice::PdmPhysicalDpiY:
    339         return qRound(dpmY * qreal(0.0254));
     388        return qt_defaultDpiY();
    340389    default:
    341         return image.metric(metric);
    342     }
     390        qWarning("QRasterPixmapData::metric(): Unhandled metric type %d", metric);
     391        break;
     392    }
     393
     394    return 0;
    343395}
    344396
  • trunk/src/gui/image/qpixmap_raster_p.h

    r2 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**
     
    5959#ifdef Q_WS_WIN
    6060# include "qt_windows.h"
    61 # ifndef QT_NO_DIRECT3D
    62 #  include <d3d9.h>
    63 # endif
    6461#endif
    6562
     
    7269    ~QRasterPixmapData();
    7370
     71    QPixmapData *createCompatiblePixmapData() const;
     72
    7473    void resize(int width, int height);
    7574    void fromFile(const QString &filename, Qt::ImageConversionFlags flags);
    7675    void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
    7776
     77    bool scroll(int dx, int dy, const QRect &rect);
    7878    void fill(const QColor &color);
    7979    void setMask(const QBitmap &mask);
     
    8686protected:
    8787    int metric(QPaintDevice::PaintDeviceMetric metric) const;
     88    QImage image;
    8889
    8990private:
    90 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
    91     friend class QDirect3DPaintEnginePrivate;
    92     IDirect3DTexture9 *texture;
    93 #endif
    9491    friend class QPixmap;
    9592    friend class QBitmap;
    96     friend class QDetachedPixmap;
     93    friend class QPixmapCacheEntry;
    9794    friend class QRasterPaintEngine;
    98     QImage image;
    9995};
    10096
  • trunk/src/gui/image/qpixmap_win.cpp

    r2 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**
     
    6060#include "qt_windows.h"
    6161
    62 #if defined(Q_OS_WINCE)
     62#if defined(Q_WS_WINCE)
    6363#include <winbase.h>
    6464#include "qguifunctions_wince.h"
     
    8181    if (h < 0) h = r.bottom - r.top;
    8282
    83 #ifdef Q_OS_WINCE_WM
     83#ifdef Q_WS_WINCE_WM
    8484    if (qt_wince_is_pocket_pc()) {
    8585        QWidget *widget = QWidget::find(winId);
     
    102102    HDC window_dc = GetDC(winId);
    103103    BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY
    104 #ifndef Q_OS_WINCE
     104#ifndef Q_WS_WINCE
    105105                                    | CAPTUREBLT
    106106#endif
     
    120120}
    121121
    122 
    123 
    124 /*!
    125     \enum QPixmap::HBitmapFormat
    126 
    127     This enum defines how the conversion between \c HBITMAP
    128     and QPixmap is performed.
    129 
    130     \warning This enum is only available on Windows.
    131 
    132     \value NoAlpha The alpha channel is ignored and always treated as
    133     being set to fully opaque. This is preferred if the \c HBITMAP is
    134     used with standard GDI calls, such as \c BitBlt().
    135 
    136     \value PremultipliedAlpha The \c HBITMAP is treated as having an
    137     alpha channel and premultiplied colors. This is preferred if the
    138     \c HBITMAP is accessed through the \c AlphaBlend() GDI function.
    139 
    140     \value Alpha The \c HBITMAP is treated as having a plain alpha
    141     channel. This is the preferred format if the \c HBITMAP is going
    142     to be used as an application icon or systray icon.
    143 
    144     \sa fromWinHBITMAP(), toWinHBITMAP()
    145 */
    146 
    147 /*!
    148     Creates a \c HBITMAP equivalent to the QPixmap, based on the given
    149     \a format. Returns the \c HBITMAP handle.
    150 
    151     It is the caller's responsibility to free the \c HBITMAP data
    152     after use.
    153 
    154     \warning This function is only available on Windows.
    155 
    156     \sa fromWinHBITMAP()
    157 */
    158122HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const
    159123{
     124    if (isNull())
     125        return 0;
     126
    160127    HBITMAP bitmap = 0;
    161128    if (data->classId() == QPixmapData::RasterClass) {
    162         QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data);
     129        QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
    163130        int w = d->image.width();
    164131        int h = d->image.height();
     
    210177}
    211178
    212 /*!
    213     Returns a QPixmap that is equivalent to the given \a bitmap. The
    214     conversion is based on the specified \a format.
    215 
    216     \warning This function is only available on Windows.
    217 
    218     \sa toWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}
    219 
    220 */
    221179QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
    222180{
     
    225183    memset(&bitmap_info, 0, sizeof(BITMAP));
    226184
    227     int res;
    228     QT_WA({
    229             res = GetObjectW(bitmap, sizeof(BITMAP), &bitmap_info);
    230         } , {
    231               res = GetObjectA(bitmap, sizeof(BITMAP), &bitmap_info);
    232           });
    233 
     185    int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info);
    234186    if (!res) {
    235187        qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
     
    288240}
    289241
     242HBITMAP qt_createIconMask(const QBitmap &bitmap)
     243{
     244    QImage bm = bitmap.toImage().convertToFormat(QImage::Format_Mono);
     245    int w = bm.width();
     246    int h = bm.height();
     247    int bpl = ((w+15)/16)*2;                        // bpl, 16 bit alignment
     248    uchar *bits = new uchar[bpl*h];
     249    bm.invertPixels();
     250    for (int y=0; y<h; y++)
     251        memcpy(bits+y*bpl, bm.scanLine(y), bpl);
     252    HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits);
     253    delete [] bits;
     254    return hbm;
     255}
     256
     257HICON QPixmap::toWinHICON() const
     258{
     259    QBitmap maskBitmap = mask();
     260    if (maskBitmap.isNull()) {
     261        maskBitmap= QBitmap(size());
     262        maskBitmap.fill(Qt::color1);
     263    }
     264
     265    ICONINFO ii;
     266    ii.fIcon    = true;
     267    ii.hbmMask  = qt_createIconMask(maskBitmap);
     268    ii.hbmColor = toWinHBITMAP(QPixmap::Alpha);
     269    ii.xHotspot = 0;
     270    ii.yHotspot = 0;
     271
     272    HICON hIcon = CreateIconIndirect(&ii);
     273
     274    DeleteObject(ii.hbmColor);
     275    DeleteObject(ii.hbmMask);
     276
     277    return hIcon;
     278}
     279
    290280#ifdef Q_WS_WIN
    291 #ifndef Q_OS_WINCE
     281#ifndef Q_WS_WINCE
    292282
    293283static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
     
    320310        qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits");
    321311    }
     312    qFree(data);
    322313
    323314    return image;
    324315}
    325316
    326 QPixmap convertHIconToPixmap( const HICON icon)
     317QPixmap QPixmap::fromWinHICON(HICON icon)
    327318{
    328319    bool foundAlpha = false;
     
    334325    bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center
    335326    if (!result)
    336         qWarning("convertHIconToPixmap(), failed to GetIconInfo()");
     327        qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()");
    337328
    338329    int w = iconinfo.xHotspot * 2;
     
    392383    return QPixmap::fromImage(image);
    393384}
    394 #else //ifndef Q_OS_WINCE
    395 QPixmap convertHIconToPixmap( const HICON icon, bool large)
     385#else //ifndef Q_WS_WINCE
     386QPixmap QPixmap::fromWinHICON(HICON icon)
    396387{
    397388    HDC screenDevice = GetDC(0);
     
    399390    ReleaseDC(0, screenDevice);
    400391
    401     int size = large ? 64 : 32;
     392    ICONINFO iconinfo;
     393    bool result = GetIconInfo(icon, &iconinfo);
     394    if (!result)
     395        qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()");
     396
     397    int w = 0;
     398    int h = 0;
     399    if (!iconinfo.xHotspot || !iconinfo.yHotspot) {
     400        // We could not retrieve the icon size via GetIconInfo,
     401        // so we try again using the icon bitmap.
     402        BITMAP bm;
     403        int result = GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bm);
     404        if (!result) result = GetObject(iconinfo.hbmMask, sizeof(BITMAP), &bm);
     405        if (!result) {
     406            qWarning("QPixmap::fromWinHICON(), failed to retrieve icon size");
     407            return QPixmap();
     408        }
     409        w = bm.bmWidth;
     410        h = bm.bmHeight;
     411    } else {
     412        // x and y Hotspot describes the icon center
     413        w = iconinfo.xHotspot * 2;
     414        h = iconinfo.yHotspot * 2;
     415    }
     416    const DWORD dwImageSize = w * h * 4;
    402417
    403418    BITMAPINFO bmi;
    404419    memset(&bmi, 0, sizeof(bmi));
    405420    bmi.bmiHeader.biSize        = sizeof(BITMAPINFO);
    406     bmi.bmiHeader.biWidth       = size;
    407     bmi.bmiHeader.biHeight      = -size;
     421    bmi.bmiHeader.biWidth       = w;
     422    bmi.bmiHeader.biHeight      = -h;
    408423    bmi.bmiHeader.biPlanes      = 1;
    409424    bmi.bmiHeader.biBitCount    = 32;
    410425    bmi.bmiHeader.biCompression = BI_RGB;
    411     bmi.bmiHeader.biSizeImage   = size*size*4;
     426    bmi.bmiHeader.biSizeImage   = dwImageSize;
    412427
    413428    uchar* bits;
     
    415430    HBITMAP winBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &bits, 0, 0);
    416431    if (winBitmap )
    417         memset(bits, 0xff, size*size*4);
     432        memset(bits, 0xff, dwImageSize);
    418433    if (!winBitmap) {
    419         qWarning("convertHIconToPixmap(), failed to CreateDIBSection()");
     434        qWarning("QPixmap::fromWinHICON(), failed to CreateDIBSection()");
    420435        return QPixmap();
    421436    }
    422437
    423438    HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
    424     if (!DrawIconEx( hdc, 0, 0, icon, size, size, 0, 0, DI_NORMAL))
    425         qWarning("convertHIconToPixmap(), failed to DrawIcon()");
     439    if (!DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_NORMAL))
     440        qWarning("QPixmap::fromWinHICON(), failed to DrawIcon()");
    426441
    427442    uint mask = 0xff000000;
    428443    // Create image and copy data into image.
    429     QImage image(size, size, QImage::Format_ARGB32);
     444    QImage image(w, h, QImage::Format_ARGB32);
    430445
    431446    if (!image.isNull()) { // failed to alloc?
    432         int bytes_per_line = size * sizeof(QRgb);
    433         for (int y=0; y<size; ++y) {
     447        int bytes_per_line = w * sizeof(QRgb);
     448        for (int y=0; y < h; ++y) {
    434449            QRgb *dest = (QRgb *) image.scanLine(y);
    435450            const QRgb *src = (const QRgb *) (bits + y * bytes_per_line);
    436             for (int x=0; x<size; ++x) {
     451            for (int x=0; x < w; ++x) {
    437452                dest[x] = src[x];
    438453            }
    439454        }
    440455    }
    441     if (!DrawIconEx( hdc, 0, 0, icon, size, size, 0, 0, DI_MASK))
    442         qWarning("convertHIconToPixmap(), failed to DrawIcon()");
     456    if (!DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_MASK))
     457        qWarning("QPixmap::fromWinHICON(), failed to DrawIcon()");
    443458    if (!image.isNull()) { // failed to alloc?
    444         int bytes_per_line = size * sizeof(QRgb);
    445         for (int y=0; y<size; ++y) {
     459        int bytes_per_line = w * sizeof(QRgb);
     460        for (int y=0; y < h; ++y) {
    446461            QRgb *dest = (QRgb *) image.scanLine(y);
    447462            const QRgb *src = (const QRgb *) (bits + y * bytes_per_line);
    448             for (int x=0; x<size; ++x) {
     463            for (int x=0; x < w; ++x) {
    449464                if (!src[x])
    450465                    dest[x] = dest[x] | mask;
     
    457472    return QPixmap::fromImage(image);
    458473}
    459 #endif //ifndef Q_OS_WINCE
    460 
    461 QPixmap loadIconFromShell32( int resourceId, int size )
    462 {
    463 #ifdef Q_OS_WINCE
    464     HMODULE hmod = LoadLibrary((const wchar_t *) QString::fromLatin1("ceshell.dll").utf16());
    465 #else
    466     HMODULE hmod = LoadLibraryA("shell32.dll");
    467 #endif
    468     if( hmod ) {
    469         HICON iconHandle = (HICON)LoadImage(hmod, MAKEINTRESOURCE(resourceId), IMAGE_ICON, size, size, 0);
    470         if( iconHandle ) {
    471             QPixmap iconpixmap = convertHIconToPixmap( iconHandle );
    472             DestroyIcon(iconHandle);
    473             return iconpixmap;
    474         }
    475     }
    476     return QPixmap();
    477 }
    478 
    479 #endif
     474#endif //ifndef Q_WS_WINCE
     475#endif //ifdef Q_WS_WIN
    480476
    481477QT_END_NAMESPACE
  • trunk/src/gui/image/qpixmap_x11.cpp

    r2 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**
     
    6868#include "qx11info_x11.h"
    6969#include <private/qdrawhelper_p.h>
     70#include <private/qimage_p.h>
    7071
    7172#include <stdlib.h>
     
    313314
    314315QX11PixmapData::QX11PixmapData(PixelType type)
    315     : QPixmapData(type, X11Class), hd(0), w(0), h(0), d(0),
    316       uninit(true), read_only(false), x11_mask(0), picture(0), mask_picture(0), hd2(0),
     316    : QPixmapData(type, X11Class), hd(0),
     317      flags(Uninitialized), x11_mask(0), picture(0), mask_picture(0), hd2(0), gl_surface(0),
    317318      share_mode(QPixmap::ImplicitlyShared), pengine(0)
    318319{
     320}
     321
     322QPixmapData *QX11PixmapData::createCompatiblePixmapData() const
     323{
     324    return new QX11PixmapData(pixelType());
    319325}
    320326
     
    325331    w = width;
    326332    h = height;
     333    is_null = (w <= 0 || h <= 0);
    327334
    328335    if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
     
    348355        w = 0;
    349356        h = 0;
     357        is_null = true;
    350358        hd = 0;
    351359        picture = 0;
     
    368376}
    369377
     378struct QX11AlphaDetector
     379{
     380    bool hasAlpha() const {
     381        if (checked)
     382            return has;
     383        // Will implicitly also check format and return quickly for opaque types...
     384        checked = true;
     385        has = const_cast<QImage *>(image)->data_ptr()->checkForAlphaPixels();
     386        return has;
     387    }
     388
     389    bool hasXRenderAndAlpha() const {
     390        if (!X11->use_xrender)
     391            return false;
     392        return hasAlpha();
     393    }
     394
     395    QX11AlphaDetector(const QImage *i, Qt::ImageConversionFlags flags)
     396        : image(i), checked(false), has(false)
     397    {
     398        if (flags & Qt::NoOpaqueDetection) {
     399            checked = true;
     400            has = image->hasAlphaChannel();
     401        }
     402    }
     403
     404    const QImage *image;
     405    mutable bool checked;
     406    mutable bool has;
     407};
     408
    370409void QX11PixmapData::fromImage(const QImage &img,
    371410                               Qt::ImageConversionFlags flags)
     
    376415    h = img.height();
    377416    d = img.depth();
     417    is_null = (w <= 0 || h <= 0);
     418
     419    if (is_null) {
     420        w = h = 0;
     421        return;
     422    }
    378423
    379424    if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
     
    396441    if (uint(w) >= 32768 || uint(h) >= 32768) {
    397442        w = h = 0;
     443        is_null = true;
    398444        return;
    399445    }
    400446
    401     int dd = X11->use_xrender && img.hasAlphaChannel() ? 32 : xinfo.depth();
     447    QX11AlphaDetector alphaCheck(&img, flags);
     448    int dd = alphaCheck.hasXRenderAndAlpha() ? 32 : xinfo.depth();
     449
    402450    if (qt_x11_preferred_pixmap_depth)
    403451        dd = qt_x11_preferred_pixmap_depth;
     
    422470            conv8 = (d == 1);                        // native depth wanted
    423471        } else if (d == 1) {
    424             if (image.numColors() == 2) {
     472            if (image.colorCount() == 2) {
    425473                QRgb c0 = image.color(0);        // Auto: convert to best
    426474                QRgb c1 = image.color(1);
     
    447495    XImage *xi = 0;
    448496    bool    trucol = (visual->c_class >= TrueColor);
    449     int     nbytes = image.numBytes();
     497    int     nbytes = image.byteCount();
    450498    uchar  *newbits= 0;
    451499
    452500#ifndef QT_NO_XRENDER
    453     if (X11->use_xrender && image.hasAlphaChannel()) {
     501    if (alphaCheck.hasXRenderAndAlpha()) {
    454502        const QImage &cimage = image;
    455503
     
    589637        if (d8) {                                // setup pixel translation
    590638            QVector<QRgb> ctable = cimage.colorTable();
    591             for (int i=0; i < cimage.numColors(); i++) {
     639            for (int i=0; i < cimage.colorCount(); i++) {
    592640                int r = qRed  (ctable[i]);
    593641                int g = qGreen(ctable[i]);
     
    915963        int  pop[256];                                // pixel popularity
    916964
    917         if (image.numColors() == 0)
    918             image.setNumColors(1);
     965        if (image.colorCount() == 0)
     966            image.setColorCount(1);
    919967
    920968        const QImage &cimage = image;
     
    946994        };
    947995        int ncols = 0;
    948         for (int i=0; i< cimage.numColors(); i++) { // compute number of colors
     996        for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors
    949997            if (pop[i] > 0)
    950998                ncols++;
    951999        }
    952         for (int i = cimage.numColors(); i < 256; i++) // ignore out-of-range pixels
     1000        for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels
    9531001            pop[i] = 0;
    9541002
     
    10881136#endif
    10891137
    1090     if (image.hasAlphaChannel()) {
     1138    if (alphaCheck.hasAlpha()) {
    10911139        QBitmap m = QBitmap::fromImage(image.createAlphaMask(flags));
    10921140        setMask(m);
     
    11101158    h = img.height();
    11111159    d = 1;
     1160    is_null = (w <= 0 || h <= 0);
    11121161    int bpl = (w + 7) / 8;
    11131162    int ibpl = img.bytesPerLine();
     
    12131262            hd2 = 0;
    12141263        }
    1215         if (!read_only)
     1264        if (!(flags & Readonly))
    12161265            XFreePixmap(xinfo.display(), hd);
    12171266        hd = 0;
     
    12211270QPixmap QX11PixmapData::alphaChannel() const
    12221271{
    1223     if (!hasAlphaChannel())
    1224         return QPixmap();
     1272    if (!hasAlphaChannel()) {
     1273        QPixmap pm(w, h);
     1274        pm.fill(Qt::white);
     1275        return pm;
     1276    }
    12251277    QImage im(toImage());
    12261278    return QPixmap::fromImage(im.alphaChannel(), Qt::OrderedDither);
     
    14381490        // we may have to swap the byte order
    14391491        if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst)
    1440             || (QSysInfo::ByteOrder == QSysInfo::BigEndian))
     1492            || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst))
    14411493        {
    14421494            for (int i=0; i < image.height(); i++) {
     
    16051657
    16061658    if (d == 1) {                                // bitmap
    1607         image.setNumColors(2);
     1659        image.setColorCount(2);
    16081660        image.setColor(0, qRgb(255,255,255));
    16091661        image.setColor(1, qRgb(0,0,0));
     
    16611713            if (ncols < 256) {
    16621714                trans = ncols++;
    1663                 image.setNumColors(ncols);        // create color table
     1715                image.setColorCount(ncols);        // create color table
    16641716                image.setColor(trans, 0x00000000);
    16651717            } else {
    1666                 image.setNumColors(ncols);        // create color table
     1718                image.setColorCount(ncols);        // create color table
    16671719                // oh dear... no spare "transparent" pixel.
    16681720                // use first pixel in image (as good as any).
     
    16871739            }
    16881740        } else {
    1689             image.setNumColors(ncols);        // create color table
     1741            image.setColorCount(ncols);        // create color table
    16901742        }
    16911743        QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap();
     
    18701922        return bm;
    18711923    } else {                                        // color pixmap
    1872         QPixmap pm;
    1873         QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pm.data);
    1874         x11Data->uninit = false;
     1924        QX11PixmapData *x11Data = new QX11PixmapData(QPixmapData::PixmapType);
     1925        QPixmap pm(x11Data);
     1926        x11Data->flags &= ~QX11PixmapData::Uninitialized;
    18751927        x11Data->xinfo = xinfo;
    18761928        x11Data->d = d;
    18771929        x11Data->w = w;
    18781930        x11Data->h = h;
     1931        x11Data->is_null = (w <= 0 || h <= 0);
    18791932        x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display,
    18801933                                                RootWindow(X11->display, xinfo.screen()),
    18811934                                                w, h, d);
     1935        x11Data->setSerialNumber(++qt_pixmap_serial);
     1936
    18821937#ifndef QT_NO_XRENDER
    18831938        if (X11->use_xrender) {
     
    19151970}
    19161971
    1917 /*!
    1918   \internal
    1919 */
    19201972int QPixmap::x11SetDefaultScreen(int screen)
    19211973{
     
    19251977}
    19261978
    1927 /*!
    1928   \internal
    1929 */
    19301979void QPixmap::x11SetScreen(int screen)
    19311980{
     
    19351984    }
    19361985
     1986    if (isNull())
     1987        return;
     1988
    19371989    if (data->classId() != QPixmapData::X11Class)
    19381990        return;
     
    19411993        screen = QX11Info::appScreen();
    19421994
    1943     QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data);
     1995    QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data.data());
    19441996    if (screen == x11Data->xinfo.screen())
    19451997        return; // nothing to do
     
    20192071    QPixmap pm(data);
    20202072
    2021     data->uninit = false;
     2073    data->flags &= ~QX11PixmapData::Uninitialized;
    20222074    pm.x11SetScreen(scr);
    20232075
     
    20352087}
    20362088
    2037 /*!
    2038     Returns information about the configuration of the X display used to display
    2039     the widget.
    2040 
    2041     \warning This function is only available on X11.
    2042 
    2043     \sa {QPixmap#Pixmap Information}{Pixmap Information}
    2044 */
    20452089const QX11Info &QPixmap::x11Info() const
    20462090{
    2047     if (data->classId() == QPixmapData::X11Class)
    2048         return static_cast<QX11PixmapData*>(data)->xinfo;
     2091    if (data && data->classId() == QPixmapData::X11Class)
     2092        return static_cast<QX11PixmapData*>(data.data())->xinfo;
    20492093    else {
    20502094        static QX11Info nullX11Info;
     
    20692113    QX11PixmapData *that = const_cast<QX11PixmapData*>(this);
    20702114
    2071     if (read_only && share_mode == QPixmap::ImplicitlyShared) {
     2115    if ((flags & Readonly) && share_mode == QPixmap::ImplicitlyShared) {
    20722116        // if someone wants to draw onto us, copy the shared contents
    20732117        // and turn it into a fully fledged QPixmap
     
    20912135        }
    20922136        that->hd = hd_copy;
    2093         that->read_only = false;
     2137        that->flags &= ~QX11PixmapData::Readonly;
    20942138    }
    20952139
     
    20992143}
    21002144
    2101 /*!
    2102     Returns the X11 Picture handle of the pixmap for XRender
    2103     support.
    2104 
    2105     This function will return 0 if XRender support is not compiled
    2106     into Qt, if the XRender extension is not supported on the X11
    2107     display, or if the handle could not be created. Use of this
    2108     function is not portable.
    2109 
    2110     \warning This function is only available on X11.
    2111 
    2112     \sa {QPixmap#Pixmap Information}{Pixmap Information}
    2113 */
    2114 
    21152145Qt::HANDLE QPixmap::x11PictureHandle() const
    21162146{
    21172147#ifndef QT_NO_XRENDER
    2118     if (data->classId() == QPixmapData::X11Class)
    2119         return static_cast<QX11PixmapData*>(data)->picture;
     2148    if (data && data->classId() == QPixmapData::X11Class)
     2149        return static_cast<const QX11PixmapData*>(data.data())->picture;
    21202150    else
    21212151        return 0;
     
    21562186    setSerialNumber(++qt_pixmap_serial);
    21572187
    2158     uninit = false;
     2188    flags &= ~Uninitialized;
    21592189    xinfo = x11Data->xinfo;
    21602190    d = x11Data->d;
    21612191    w = rect.width();
    21622192    h = rect.height();
     2193    is_null = (w <= 0 || h <= 0);
    21632194    hd = (Qt::HANDLE)XCreatePixmap(X11->display,
    21642195                                   RootWindow(X11->display, x11Data->xinfo.screen()),
     
    22062237}
    22072238
     2239bool QX11PixmapData::scroll(int dx, int dy, const QRect &rect)
     2240{
     2241    GC gc = XCreateGC(X11->display, hd, 0, 0);
     2242    XCopyArea(X11->display, hd, hd, gc,
     2243              rect.left(), rect.top(), rect.width(), rect.height(),
     2244              rect.left() + dx, rect.top() + dy);
     2245    XFreeGC(X11->display, gc);
     2246    return true;
     2247}
     2248
    22082249#if !defined(QT_NO_XRENDER)
    22092250void QX11PixmapData::convertToARGB32(bool preserveContents)
     
    22132254
    22142255    // Q_ASSERT(count == 1);
    2215     if (read_only && share_mode == QPixmap::ExplicitlyShared)
     2256    if ((flags & Readonly) && share_mode == QPixmap::ExplicitlyShared)
    22162257        return;
    22172258
     
    22232264        if (preserveContents)
    22242265            XRenderComposite(X11->display, PictOpSrc, picture, 0, p, 0, 0, 0, 0, 0, 0, w, h);
    2225         if (!read_only)
     2266        if (!(flags & Readonly))
    22262267            XRenderFreePicture(X11->display, picture);
    22272268    }
    2228     if (hd && !read_only)
     2269    if (hd && !(flags & Readonly))
    22292270        XFreePixmap(X11->display, hd);
    22302271    if (x11_mask) {
     
    22642305    QX11PixmapData *data = new QX11PixmapData(depth == 1 ? QPixmapData::BitmapType : QPixmapData::PixmapType);
    22652306    data->setSerialNumber(++qt_pixmap_serial);
    2266     data->read_only = true;
     2307    data->flags = QX11PixmapData::Readonly;
    22672308    data->share_mode = mode;
    2268     data->uninit = false;
    22692309    data->w = width;
    22702310    data->h = height;
     2311    data->is_null = (width <= 0 || height <= 0);
    22712312    data->d = depth;
    22722313    data->hd = pixmap;
  • trunk/src/gui/image/qpixmap_x11_p.h

    r2 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**
     
    7272    ~QX11PixmapData();
    7373
     74    QPixmapData *createCompatiblePixmapData() const;
     75
    7476    void resize(int width, int height);
    7577    void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
    7678    void copy(const QPixmapData *data, const QRect &rect);
     79    bool scroll(int dx, int dy, const QRect &rect);
    7780
    7881    void fill(const QColor &color);
     
    99102    friend class QX11WindowSurface;
    100103    friend class QRasterWindowSurface;
     104    friend class QGLContextPrivate; // Needs to access xinfo, gl_surface & flags
     105    friend class QEglContext; // Needs gl_surface
     106    friend class QX11GLPixmapData; // Needs gl_surface
     107    friend bool  qt_createEGLSurfaceForPixmap(QPixmapData*, bool); // Needs gl_surface
    101108
    102109    void release();
     
    108115    Qt::HANDLE hd;
    109116
    110     int w, h;
    111     short d;
    112     uint uninit : 1;
    113     uint read_only : 1;
     117    enum Flag {
     118         NoFlags = 0x0,
     119         Uninitialized = 0x1,
     120         Readonly = 0x2,
     121         InvertedWhenBoundToTexture = 0x4,
     122         GlSurfaceCreatedWithAlpha = 0x8
     123    };
     124    uint flags;
    114125
    115126    QX11Info xinfo;
     
    118129    Qt::HANDLE mask_picture;
    119130    Qt::HANDLE hd2; // sorted in the default display depth
     131    Qt::HANDLE gl_surface;
    120132#ifndef QT_NO_XRENDER
    121133    void convertToARGB32(bool preserveContents = true);
  • trunk/src/gui/image/qpixmapcache.cpp

    r2 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**
     
    4141
    4242#include "qpixmapcache.h"
    43 #include "qcache.h"
    4443#include "qobject.h"
    4544#include "qdebug.h"
    46 
    47 #include "qpaintengine.h"
    48 #include <private/qimage_p.h>
    49 #include <private/qpixmap_raster_p.h>
     45#include "qpixmapcache_p.h"
    5046
    5147QT_BEGIN_NAMESPACE
     
    5652    \brief The QPixmapCache class provides an application-wide cache for pixmaps.
    5753
    58     \ingroup environment
    59     \ingroup multimedia
     54    \ingroup painting
    6055
    6156    This class is a tool for optimized drawing with QPixmap. You can
     
    6964    object for caching the pixmaps.
    7065
    71     The cache associates a pixmap with a string (key). If two pixmaps
    72     are inserted into the cache using equal keys, then the last pixmap
    73     will hide the first pixmap. The QHash and QCache classes do
    74     exactly the same.
     66    The cache associates a pixmap with a user-provided string as a key,
     67    or with a QPixmapCache::Key that the cache generates.
     68    Using QPixmapCache::Key for keys is faster than using strings. The string API is
     69    very convenient for complex keys but the QPixmapCache::Key API will be very
     70    efficient and convenient for a one-to-one object-to-pixmap mapping \mdash in
     71    this case, you can store the keys as members of an object.
     72
     73    If two pixmaps are inserted into the cache using equal keys then the
     74    last pixmap will replace the first pixmap in the cache. This follows the
     75    behavior of the QHash and QCache classes.
    7576
    7677    The cache becomes full when the total size of all pixmaps in the
    77     cache exceeds cacheLimit(). The initial cache limit is 1024 KB (1
    78     MB); it is changed with setCacheLimit(). A pixmap takes roughly
    79     (\e{width} * \e{height} * \e{depth})/8 bytes of memory.
     78    cache exceeds cacheLimit(). The initial cache limit is
     79    2048 KB (2 MB) on embedded platforms, 10240 KB (10 MB) on desktop
     80    platforms; you can change this by calling setCacheLimit() with the
     81    required value.
     82    A pixmap takes roughly (\e{width} * \e{height} * \e{depth})/8 bytes of
     83    memory.
    8084
    8185    The \e{Qt Quarterly} article
    82     \l{http://doc.trolltech.com/qq/qq12-qpixmapcache.html}{Optimizing
     86    \l{http://qt.nokia.com/doc/qq/qq12-qpixmapcache.html}{Optimizing
    8387    with QPixmapCache} explains how to use QPixmapCache to speed up
    8488    applications by caching the results of painting.
     
    8791*/
    8892
    89 #if defined(Q_WS_QWS) || defined(Q_OS_WINCE)
     93#if defined(Q_OS_SYMBIAN)
     94static int cache_limit = 1024; // 1048 KB cache limit for symbian
     95#elif defined(Q_WS_QWS) || defined(Q_WS_WINCE)
    9096static int cache_limit = 2048; // 2048 KB cache limit for embedded
    9197#else
     
    9399#endif
    94100
    95 // XXX: hw: is this a general concept we need to abstract?
    96 class QDetachedPixmap : public QPixmap
    97 {
    98 public:
    99     QDetachedPixmap(const QPixmap &pix) : QPixmap(pix)
    100     {
    101         if (data && data->classId() == QPixmapData::RasterClass) {
    102             QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data);
    103             if (!d->image.isNull() && d->image.d->paintEngine
    104                 && !d->image.d->paintEngine->isActive())
    105             {
    106                 delete d->image.d->paintEngine;
    107                 d->image.d->paintEngine = 0;
    108             }
    109         }
    110     }
    111 };
    112 
    113 class QPMCache : public QObject, public QCache<qint64, QDetachedPixmap>
     101/*!
     102    \class QPixmapCache::Key
     103    \brief The QPixmapCache::Key class can be used for efficient access
     104    to the QPixmapCache.
     105    \since 4.6
     106
     107    Use QPixmapCache::insert() to receive an instance of Key generated
     108    by the pixmap cache. You can store the key in your own objects for
     109    a very efficient one-to-one object-to-pixmap mapping.
     110*/
     111
     112/*!
     113    Constructs an empty Key object.
     114*/
     115QPixmapCache::Key::Key() : d(0)
     116{
     117}
     118
     119/*!
     120   \internal
     121    Constructs a copy of \a other.
     122*/
     123QPixmapCache::Key::Key(const Key &other)
     124{
     125    if (other.d)
     126        ++(other.d->ref);
     127    d = other.d;
     128}
     129
     130/*!
     131    Destroys the key.
     132*/
     133QPixmapCache::Key::~Key()
     134{
     135    if (d && --(d->ref) == 0)
     136        delete d;
     137}
     138
     139/*!
     140    \internal
     141
     142    Returns true if this key is the same as the given \a key; otherwise returns
     143    false.
     144*/
     145bool QPixmapCache::Key::operator ==(const Key &key) const
     146{
     147    return (d == key.d);
     148}
     149
     150/*!
     151    \fn bool QPixmapCache::Key::operator !=(const Key &key) const
     152    \internal
     153*/
     154
     155/*!
     156    \internal
     157*/
     158QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)
     159{
     160    if (d != other.d) {
     161        if (other.d)
     162            ++(other.d->ref);
     163        if (d && --(d->ref) == 0)
     164            delete d;
     165        d = other.d;
     166    }
     167    return *this;
     168}
     169
     170class QPMCache : public QObject, public QCache<QPixmapCache::Key, QPixmapCacheEntry>
    114171{
    115172    Q_OBJECT
    116173public:
    117     QPMCache()
    118         : QObject(0),
    119           QCache<qint64, QDetachedPixmap>(cache_limit * 1024),
    120           theid(0), ps(0), t(false) { }
    121     ~QPMCache() { }
     174    QPMCache();
     175    ~QPMCache();
    122176
    123177    void timerEvent(QTimerEvent *);
    124178    bool insert(const QString& key, const QPixmap &pixmap, int cost);
     179    QPixmapCache::Key insert(const QPixmap &pixmap, int cost);
     180    bool replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost);
    125181    bool remove(const QString &key);
     182    bool remove(const QPixmapCache::Key &key);
     183
     184    void resizeKeyArray(int size);
     185    QPixmapCache::Key createKey();
     186    void releaseKey(const QPixmapCache::Key &key);
     187    void clear();
    126188
    127189    QPixmap *object(const QString &key) const;
     190    QPixmap *object(const QPixmapCache::Key &key) const;
     191
     192    static inline QPixmapCache::KeyData *get(const QPixmapCache::Key &key)
     193    {return key.d;}
     194
     195    static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);
    128196
    129197private:
    130     QHash<QString, qint64> cacheKeys;
     198    int *keyArray;
    131199    int theid;
    132200    int ps;
     201    int keyArraySize;
     202    int freeKey;
     203    QHash<QString, QPixmapCache::Key> cacheKeys;
    133204    bool t;
    134205};
     206
    135207QT_BEGIN_INCLUDE_NAMESPACE
    136208#include "qpixmapcache.moc"
    137209QT_END_INCLUDE_NAMESPACE
    138210
     211uint qHash(const QPixmapCache::Key &k)
     212{
     213    return qHash(QPMCache::get(k)->key);
     214}
     215
     216QPMCache::QPMCache()
     217    : QObject(0),
     218      QCache<QPixmapCache::Key, QPixmapCacheEntry>(cache_limit * 1024),
     219      keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)
     220{
     221}
     222QPMCache::~QPMCache()
     223{
     224    clear();
     225    free(keyArray);
     226}
     227
    139228/*
    140   This is supposed to cut the cache size down by about 80-90% in a
     229  This is supposed to cut the cache size down by about 25% in a
    141230  minute once the application becomes idle, to let any inserted pixmap
    142231  remain in the cache for some time before it becomes a candidate for
     
    147236  timer so Qt won't keep the CPU from going into sleep mode.
    148237*/
    149 
    150238void QPMCache::timerEvent(QTimerEvent *)
    151239{
     
    156244    ps = totalCost();
    157245
    158     QHash<QString, qint64>::iterator it = cacheKeys.begin();
     246    QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();
    159247    while (it != cacheKeys.end()) {
    160248        if (!contains(it.value())) {
     249            releaseKey(it.value());
    161250            it = cacheKeys.erase(it);
    162251        } else {
     
    177266QPixmap *QPMCache::object(const QString &key) const
    178267{
    179     return QCache<qint64, QDetachedPixmap>::object(cacheKeys.value(key, -1));
    180 }
    181 
     268    QPixmapCache::Key cacheKey = cacheKeys.value(key);
     269    if (!cacheKey.d || !cacheKey.d->isValid) {
     270        const_cast<QPMCache *>(this)->cacheKeys.remove(key);
     271        return 0;
     272    }
     273    QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(cacheKey);
     274     //We didn't find the pixmap in the cache, the key is not valid anymore
     275    if (!ptr) {
     276        const_cast<QPMCache *>(this)->cacheKeys.remove(key);
     277    }
     278    return ptr;
     279}
     280
     281QPixmap *QPMCache::object(const QPixmapCache::Key &key) const
     282{
     283    Q_ASSERT(key.d->isValid);
     284    QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(key);
     285    //We didn't find the pixmap in the cache, the key is not valid anymore
     286    if (!ptr)
     287        const_cast<QPMCache *>(this)->releaseKey(key);
     288    return ptr;
     289}
    182290
    183291bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
    184292{
    185     qint64 cacheKey = pixmap.cacheKey();
    186     if (QCache<qint64, QDetachedPixmap>::object(cacheKey)) {
    187         cacheKeys.insert(key, cacheKey);
    188         return true;
    189     }
    190     bool success = QCache<qint64, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
     293    QPixmapCache::Key cacheKey;
     294    QPixmapCache::Key oldCacheKey = cacheKeys.value(key);
     295    //If for the same key we add already a pixmap we should delete it
     296    if (oldCacheKey.d) {
     297        QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(oldCacheKey);
     298        cacheKeys.remove(key);
     299    }
     300
     301    //we create a new key the old one has been removed
     302    cacheKey = createKey();
     303
     304    bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
    191305    if (success) {
    192306        cacheKeys.insert(key, cacheKey);
     
    195309            t = false;
    196310        }
     311    } else {
     312        //Insertion failed we released the new allocated key
     313        releaseKey(cacheKey);
    197314    }
    198315    return success;
    199316}
    200317
     318QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)
     319{
     320    QPixmapCache::Key cacheKey = createKey();
     321    bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
     322    if (success) {
     323        if (!theid) {
     324            theid = startTimer(30000);
     325            t = false;
     326        }
     327    } else {
     328        //Insertion failed we released the key and return an invalid one
     329        releaseKey(cacheKey);
     330    }
     331    return cacheKey;
     332}
     333
     334bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost)
     335{
     336    Q_ASSERT(key.d->isValid);
     337    //If for the same key we had already an entry so we should delete the pixmap and use the new one
     338    QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
     339
     340    QPixmapCache::Key cacheKey = createKey();
     341
     342    bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
     343    if (success) {
     344        if(!theid) {
     345            theid = startTimer(30000);
     346            t = false;
     347        }
     348        const_cast<QPixmapCache::Key&>(key) = cacheKey;
     349    } else {
     350        //Insertion failed we released the key
     351        releaseKey(cacheKey);
     352    }
     353    return success;
     354}
     355
    201356bool QPMCache::remove(const QString &key)
    202357{
    203     qint64 cacheKey = cacheKeys.value(key, -1);
     358    QPixmapCache::Key cacheKey = cacheKeys.value(key);
     359    //The key was not in the cache
     360    if (!cacheKey.d)
     361        return false;
    204362    cacheKeys.remove(key);
    205     return QCache<qint64, QDetachedPixmap>::remove(cacheKey);
     363    return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
     364}
     365
     366bool QPMCache::remove(const QPixmapCache::Key &key)
     367{
     368    return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
     369}
     370
     371void QPMCache::resizeKeyArray(int size)
     372{
     373    if (size <= keyArraySize || size == 0)
     374        return;
     375    keyArray = q_check_ptr(reinterpret_cast<int *>(realloc(keyArray,
     376                    size * sizeof(int))));
     377    for (int i = keyArraySize; i != size; ++i)
     378        keyArray[i] = i + 1;
     379    keyArraySize = size;
     380}
     381
     382QPixmapCache::Key QPMCache::createKey()
     383{
     384    if (freeKey == keyArraySize)
     385        resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
     386    int id = freeKey;
     387    freeKey = keyArray[id];
     388    QPixmapCache::Key key;
     389    QPixmapCache::KeyData *d = QPMCache::getKeyData(&key);
     390    d->key = ++id;
     391    return key;
     392}
     393
     394void QPMCache::releaseKey(const QPixmapCache::Key &key)
     395{
     396    if (key.d->key > keyArraySize || key.d->key <= 0)
     397        return;
     398    key.d->key--;
     399    keyArray[key.d->key] = freeKey;
     400    freeKey = key.d->key;
     401    key.d->isValid = false;
     402    key.d->key = 0;
     403}
     404
     405void QPMCache::clear()
     406{
     407    free(keyArray);
     408    keyArray = 0;
     409    freeKey = 0;
     410    keyArraySize = 0;
     411    //Mark all keys as invalid
     412    QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QPixmapCacheEntry>::keys();
     413    for (int i = 0; i < keys.size(); ++i)
     414        keys.at(i).d->isValid = false;
     415    QCache<QPixmapCache::Key, QPixmapCacheEntry>::clear();
     416}
     417
     418QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key)
     419{
     420    if (!key->d)
     421        key->d = new QPixmapCache::KeyData;
     422    return key->d;
    206423}
    207424
    208425Q_GLOBAL_STATIC(QPMCache, pm_cache)
    209426
    210 /*!
    211   \obsolete
     427int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize()
     428{
     429    return pm_cache()->size();
     430}
     431
     432QPixmapCacheEntry::~QPixmapCacheEntry()
     433{
     434    pm_cache()->releaseKey(key);
     435}
     436
     437/*!
     438    \obsolete
    212439    \overload
    213440
     
    218445    fast). Subsequent insertions into the cache could cause the
    219446    pointer to become invalid. For this reason, we recommend you use
    220     find(const QString&, QPixmap&) instead.
     447    bool find(const QString&, QPixmap*) instead.
    221448
    222449    Example:
     
    231458
    232459/*!
    233     Looks for a cached pixmap associated with the \a key in the cache.
    234     If the pixmap is found, the function sets \a pm to that pixmap and
    235     returns true; otherwise it leaves \a pm alone and returns false.
     460    \obsolete
     461
     462    Use bool find(const QString&, QPixmap*) instead.
     463*/
     464
     465bool QPixmapCache::find(const QString &key, QPixmap& pixmap)
     466{
     467    return find(key, &pixmap);
     468}
     469
     470/*!
     471    Looks for a cached pixmap associated with the given \a key in the cache.
     472    If the pixmap is found, the function sets \a pixmap to that pixmap and
     473    returns true; otherwise it leaves \a pixmap alone and returns false.
     474
     475    \since 4.6
    236476
    237477    Example:
     
    239479*/
    240480
    241 bool QPixmapCache::find(const QString &key, QPixmap& pm)
     481bool QPixmapCache::find(const QString &key, QPixmap* pixmap)
    242482{
    243483    QPixmap *ptr = pm_cache()->object(key);
    244     if (ptr)
    245         pm = *ptr;
     484    if (ptr && pixmap)
     485        *pixmap = *ptr;
    246486    return ptr != 0;
    247487}
    248488
    249 
    250 /*!
    251     Inserts a copy of the pixmap \a pm associated with the \a key into
     489/*!
     490    Looks for a cached pixmap associated with the given \a key in the cache.
     491    If the pixmap is found, the function sets \a pixmap to that pixmap and
     492    returns true; otherwise it leaves \a pixmap alone and returns false. If
     493    the pixmap is not found, it means that the \a key is no longer valid,
     494    so it will be released for the next insertion.
     495
     496    \since 4.6
     497*/
     498bool QPixmapCache::find(const Key &key, QPixmap* pixmap)
     499{
     500    //The key is not valid anymore, a flush happened before probably
     501    if (!key.d || !key.d->isValid)
     502        return false;
     503    QPixmap *ptr = pm_cache()->object(key);
     504    if (ptr && pixmap)
     505        *pixmap = *ptr;
     506    return ptr != 0;
     507}
     508
     509/*!
     510    Inserts a copy of the pixmap \a pixmap associated with the \a key into
    252511    the cache.
    253512
     
    268527*/
    269528
    270 bool QPixmapCache::insert(const QString &key, const QPixmap &pm)
    271 {
    272     return pm_cache()->insert(key, pm, pm.width() * pm.height() * pm.depth() / 8);
     529bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
     530{
     531    return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
     532}
     533
     534/*!
     535    Inserts a copy of the given \a pixmap into the cache and returns a key
     536    that can be used to retrieve it.
     537
     538    When a pixmap is inserted and the cache is about to exceed its
     539    limit, it removes pixmaps until there is enough room for the
     540    pixmap to be inserted.
     541
     542    The oldest pixmaps (least recently accessed in the cache) are
     543    deleted when more space is needed.
     544
     545    \sa setCacheLimit(), replace()
     546
     547    \since 4.6
     548*/
     549QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
     550{
     551    return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
     552}
     553
     554/*!
     555    Replaces the pixmap associated with the given \a key with the \a pixmap
     556    specified. Returns true if the \a pixmap has been correctly inserted into
     557    the cache; otherwise returns false.
     558
     559    \sa setCacheLimit(), insert()
     560
     561    \since 4.6
     562*/
     563bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)
     564{
     565    //The key is not valid anymore, a flush happened before probably
     566    if (!key.d || !key.d->isValid)
     567        return false;
     568    return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
    273569}
    274570
     
    276572    Returns the cache limit (in kilobytes).
    277573
    278     The default cache limit is 2048 KB for Embedded, 10240 KB for Desktops.
     574    The default cache limit is 2048 KB on embedded platforms, 10240 KB on
     575    desktop platforms.
    279576
    280577    \sa setCacheLimit()
     
    289586    Sets the cache limit to \a n kilobytes.
    290587
    291     The default setting is 1024 kilobytes.
     588    The default setting is 2048 KB on embedded platforms, 10240 KB on
     589    desktop platforms.
    292590
    293591    \sa cacheLimit()
     
    308606}
    309607
     608/*!
     609  Removes the pixmap associated with \a key from the cache and releases
     610  the key for a future insertion.
     611
     612  \since 4.6
     613*/
     614void QPixmapCache::remove(const Key &key)
     615{
     616    //The key is not valid anymore, a flush happened before probably
     617    if (!key.d || !key.d->isValid)
     618        return;
     619    pm_cache()->remove(key);
     620}
    310621
    311622/*!
     
    315626void QPixmapCache::clear()
    316627{
    317     pm_cache()->clear();
     628    QT_TRY {
     629        pm_cache()->clear();
     630    } QT_CATCH(const std::bad_alloc &) {
     631        // if we ran out of memory during pm_cache(), it's no leak,
     632        // so just ignore it.
     633    }
    318634}
    319635
  • trunk/src/gui/image/qpixmapcache.h

    r2 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**
     
    5454{
    5555public:
     56    class KeyData;
     57    class Q_GUI_EXPORT Key
     58    {
     59    public:
     60        Key();
     61        Key(const Key &other);
     62        ~Key();
     63        bool operator ==(const Key &key) const;
     64        inline bool operator !=(const Key &key) const
     65        { return !operator==(key); }
     66        Key &operator =(const Key &other);
     67
     68    private:
     69        KeyData *d;
     70        friend class QPMCache;
     71        friend class QPixmapCache;
     72    };
     73
    5674    static int cacheLimit();
    5775    static void setCacheLimit(int);
    5876    static QPixmap *find(const QString &key);
    59     static bool find(const QString &key, QPixmap&);
    60     static bool insert(const QString &key, const QPixmap&);
     77    static bool find(const QString &key, QPixmap &pixmap);
     78    static bool find(const QString &key, QPixmap *pixmap);
     79    static bool find(const Key &key, QPixmap *pixmap);
     80    static bool insert(const QString &key, const QPixmap &pixmap);
     81    static Key insert(const QPixmap &pixmap);
     82    static bool replace(const Key &key, const QPixmap &pixmap);
    6183    static void remove(const QString &key);
     84    static void remove(const Key &key);
    6285    static void clear();
    6386};
  • trunk/src/gui/image/qpixmapdata.cpp

    r2 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**
     
    4141
    4242#include "qpixmapdata_p.h"
     43#include <QtCore/qbuffer.h>
    4344#include <QtGui/qbitmap.h>
    4445#include <QtGui/qimagereader.h>
     46#include <private/qgraphicssystem_p.h>
     47#include <private/qapplication_p.h>
    4548
    4649QT_BEGIN_NAMESPACE
     
    4952                                     0x10, 0x20, 0x40, 0x80 };
    5053
     54QPixmapData *QPixmapData::create(int w, int h, PixelType type)
     55{
     56    QPixmapData *data;
     57    QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
     58    if (gs)
     59        data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type));
     60    else
     61        data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
     62    data->resize(w, h);
     63    return data;
     64}
     65
     66
    5167QPixmapData::QPixmapData(PixelType pixelType, int objectId)
    52     : ref(0), detach_no(0), type(pixelType), id(objectId), ser_no(0), is_cached(false)
    53 {
    54 
     68    : w(0),
     69      h(0),
     70      d(0),
     71      is_null(true),
     72      ref(0),
     73      detach_no(0),
     74      type(pixelType),
     75      id(objectId),
     76      ser_no(0),
     77      is_cached(false)
     78{
    5579}
    5680
     
    5983}
    6084
    61 void QPixmapData::fromFile(const QString &fileName, const char *format,
     85QPixmapData *QPixmapData::createCompatiblePixmapData() const
     86{
     87    QPixmapData *d;
     88    QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem();
     89    if (gs)
     90        d = gs->createPixmapData(pixelType());
     91    else
     92        d = QGraphicsSystem::createDefaultPixmapData(pixelType());
     93    return d;
     94}
     95
     96static QImage makeBitmapCompliantIfNeeded(QPixmapData *d, const QImage &image, Qt::ImageConversionFlags flags)
     97{
     98    if (d->pixelType() == QPixmapData::BitmapType) {
     99        QImage img = image.convertToFormat(QImage::Format_MonoLSB, flags);
     100
     101        // make sure image.color(0) == Qt::color0 (white)
     102        // and image.color(1) == Qt::color1 (black)
     103        const QRgb c0 = QColor(Qt::black).rgb();
     104        const QRgb c1 = QColor(Qt::white).rgb();
     105        if (img.color(0) == c0 && img.color(1) == c1) {
     106            img.invertPixels();
     107            img.setColor(0, c1);
     108            img.setColor(1, c0);
     109        }
     110        return img;
     111    }
     112
     113    return image;
     114}
     115
     116bool QPixmapData::fromFile(const QString &fileName, const char *format,
    62117                           Qt::ImageConversionFlags flags)
    63118{
    64     const QImage image = QImageReader(fileName, format).read();
     119    QImage image = QImageReader(fileName, format).read();
    65120    if (image.isNull())
    66         return;
    67 
    68     fromImage(image, flags);
     121        return false;
     122    fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
     123    return !isNull();
     124}
     125
     126bool QPixmapData::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
     127{
     128    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);
     129    QBuffer b(&a);
     130    b.open(QIODevice::ReadOnly);
     131    QImage image = QImageReader(&b, format).read();
     132    fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
     133    return !isNull();
    69134}
    70135
     
    72137{
    73138    fromImage(data->toImage().copy(rect), Qt::AutoColor);
     139}
     140
     141bool QPixmapData::scroll(int dx, int dy, const QRect &rect)
     142{
     143    Q_UNUSED(dx);
     144    Q_UNUSED(dy);
     145    Q_UNUSED(rect);
     146    return false;
    74147}
    75148
     
    129202        return QBitmap();
    130203
    131     mask.setNumColors(2);
     204    mask.setColorCount(2);
    132205    mask.setColor(0, QColor(Qt::color0).rgba());
    133206    mask.setColor(1, QColor(Qt::color1).rgba());
     
    177250}
    178251
     252#if defined(Q_OS_SYMBIAN)
     253void* QPixmapData::toNativeType(NativeType /* type */)
     254{
     255    return 0;
     256}
     257
     258void QPixmapData::fromNativeType(void* /* pixmap */, NativeType /* typre */)
     259{
     260    return;
     261}
     262#endif
     263
    179264QT_END_NAMESPACE
  • trunk/src/gui/image/qpixmapdata_p.h

    r2 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**
     
    6767        PixmapType, BitmapType
    6868    };
     69#if defined(Q_OS_SYMBIAN)
     70    enum NativeType {
     71        FbsBitmap,
     72        SgImage
     73    };
     74#endif
    6975    enum ClassId { RasterClass, X11Class, MacClass, DirectFBClass,
    7076                   OpenGLClass, OpenVGClass, CustomClass = 1024 };
    7177
    72     QPixmapData(PixelType pixelpType, int classId);
     78    QPixmapData(PixelType pixelType, int classId);
    7379    virtual ~QPixmapData();
     80
     81    virtual QPixmapData *createCompatiblePixmapData() const;
    7482
    7583    virtual void resize(int width, int height) = 0;
    7684    virtual void fromImage(const QImage &image,
    7785                           Qt::ImageConversionFlags flags) = 0;
    78     virtual void fromFile(const QString &filename, const char *format,
     86
     87    virtual bool fromFile(const QString &filename, const char *format,
    7988                          Qt::ImageConversionFlags flags);
     89    virtual bool fromData(const uchar *buffer, uint len, const char *format,
     90                          Qt::ImageConversionFlags flags);
     91
    8092    virtual void copy(const QPixmapData *data, const QRect &rect);
     93    virtual bool scroll(int dx, int dy, const QRect &rect);
    8194
    8295    virtual int metric(QPaintDevice::PaintDeviceMetric metric) const = 0;
     
    99112    virtual QImage* buffer();
    100113
    101     int width() const { return metric(QPaintDevice::PdmWidth); }
    102     int height() const { return metric(QPaintDevice::PdmHeight); }
    103     int numColors() const { return metric(QPaintDevice::PdmNumColors); }
    104     int depth() const { return metric(QPaintDevice::PdmDepth); }
     114    inline int width() const { return w; }
     115    inline int height() const { return h; }
     116    QT_DEPRECATED inline int numColors() const { return metric(QPaintDevice::PdmNumColors); }
     117    inline int colorCount() const { return metric(QPaintDevice::PdmNumColors); }
     118    inline int depth() const { return d; }
     119    inline bool isNull() const { return is_null; }
     120
     121#if defined(Q_OS_SYMBIAN)
     122    virtual void* toNativeType(NativeType type);
     123    virtual void fromNativeType(void* pixmap, NativeType type);
     124#endif
     125
     126    static QPixmapData *create(int w, int h, PixelType type);
    105127
    106128protected:
    107129    void setSerialNumber(int serNo);
     130    int w;
     131    int h;
     132    int d;
     133    bool is_null;
    108134
    109135private:
    110136    friend class QPixmap;
    111     friend class QGLContextPrivate;
    112137    friend class QX11PixmapData;
     138    friend class QS60PixmapData;
     139    friend class QImagePixmapCleanupHooks; // Needs to set is_cached
     140    friend class QGLTextureCache; //Needs to check the reference count
     141    friend class QExplicitlySharedDataPointer<QPixmapData>;
    113142
    114143    QAtomicInt ref;
     
    120149    uint is_cached;
    121150};
    122 
    123 #ifdef Q_WS_WIN
    124 #ifndef Q_OS_WINCE
    125 QPixmap convertHIconToPixmap( const HICON icon);
    126 #else
    127 QPixmap convertHIconToPixmap( const HICON icon, bool large = false);
    128 #endif
    129 QPixmap loadIconFromShell32( int resourceId, int size );
    130 #endif
    131151
    132152#  define QT_XFORM_TYPE_MSBFIRST 0
  • trunk/src/gui/image/qpixmapdatafactory.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**
     
    4848# include <private/qpixmap_x11_p.h>
    4949#endif
    50 #ifdef Q_WS_WIN
     50#if defined(Q_WS_WIN)
    5151# include <private/qpixmap_raster_p.h>
    5252#endif
     
    5656#ifdef Q_WS_MAC
    5757# include <private/qpixmap_mac_p.h>
     58#endif
     59#ifdef Q_WS_S60
     60# include <private/qpixmap_s60_p.h>
    5861#endif
    5962
     
    8588#elif defined(Q_WS_MAC)
    8689    return new QMacPixmapData(type);
     90#elif defined(Q_WS_S60)
     91    return new QS60PixmapData(type);   
    8792#else
    8893#error QSimplePixmapDataFactory::create() not implemented
     
    9095}
    9196
    92 Q_GLOBAL_STATIC(QSimplePixmapDataFactory, factory);
     97Q_GLOBAL_STATIC(QSimplePixmapDataFactory, factory)
    9398
    9499#endif // !defined(Q_WS_QWS)
  • trunk/src/gui/image/qpixmapdatafactory_p.h

    r2 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**
     
    6666class QPixmapData;
    6767
    68 class Q_GUI_EXPORT QPixmapDataFactory
     68class QPixmapDataFactory
    6969{
    7070public:
  • trunk/src/gui/image/qpixmapfilter.cpp

    r2 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**
     
    5353#include "private/qpaintengineex_p.h"
    5454#include "private/qpaintengine_raster_p.h"
    55 
     55#include "qmath.h"
     56#include "private/qmath_p.h"
     57#include "private/qmemrotate_p.h"
     58#include "private/qdrawhelper_p.h"
     59
     60#ifndef QT_NO_GRAPHICSEFFECT
    5661QT_BEGIN_NAMESPACE
    5762
     
    6671    \class QPixmapFilter
    6772    \since 4.5
    68     \ingroup multimedia
     73    \ingroup painting
    6974
    7075    \brief The QPixmapFilter class provides the basic functionality for
     
    9499                              image. See QPixmapDropShadowFilter for more
    95100                              information.
     101    \value BlurFilter         A filter that is used to blur an image using
     102                              a simple blur radius. See QPixmapBlurFilter
     103                              for more information.
    96104
    97105    \value UserFilter   The first filter type that can be used for
     
    173181    \class QPixmapConvolutionFilter
    174182    \since 4.5
    175     \ingroup multimedia
     183    \ingroup painting
    176184
    177185    \brief The QPixmapConvolutionFilter class provides convolution
     
    294302
    295303/*!
    296     \reimp
    297 
    298304    \internal
    299305*/
     
    402408        yk++;
    403409    }
    404 }
    405 
    406 /*!
    407     \reimp
    408 
     410    delete[] fixedKernel;
     411}
     412
     413/*!
    409414    \internal
    410415*/
     
    419424
    420425    QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
    421         static_cast<QPaintEngineEx *>(painter->paintEngine())->createPixmapFilter(type()) : 0;
     426        static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0;
    422427    QPixmapConvolutionFilter *convolutionFilter = static_cast<QPixmapConvolutionFilter*>(filter);
    423428    if (convolutionFilter) {
     
    425430        convolutionFilter->d_func()->convoluteAlpha = d->convoluteAlpha;
    426431        convolutionFilter->draw(painter, p, src, srcRect);
    427         delete convolutionFilter;
    428432        return;
    429433    }
     
    477481        painter->drawImage(p - offset, result);
    478482    }
     483}
     484
     485/*!
     486    \class QPixmapBlurFilter
     487    \since 4.6
     488    \ingroup multimedia
     489
     490    \brief The QPixmapBlurFilter class provides blur filtering
     491    for pixmaps.
     492
     493    QPixmapBlurFilter implements a blur pixmap filter,
     494    which is applied when \l{QPixmapFilter::}{draw()} is called.
     495
     496    The filter lets you specialize the radius of the blur as well
     497    as hints as to whether to prefer performance or quality.
     498
     499    By default, the blur effect is produced by applying an exponential
     500    filter generated from the specified blurRadius().  Paint engines
     501    may override this with a custom blur that is faster on the
     502    underlying hardware.
     503
     504    \sa {Pixmap Filters Example}, QPixmapConvolutionFilter, QPixmapDropShadowFilter
     505
     506    \internal
     507*/
     508
     509class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate
     510{
     511public:
     512    QPixmapBlurFilterPrivate() : radius(5), hints(QGraphicsBlurEffect::PerformanceHint) {}
     513
     514    qreal radius;
     515    QGraphicsBlurEffect::BlurHints hints;
     516};
     517
     518
     519/*!
     520    Constructs a pixmap blur filter.
     521
     522    \internal
     523*/
     524QPixmapBlurFilter::QPixmapBlurFilter(QObject *parent)
     525    : QPixmapFilter(*new QPixmapBlurFilterPrivate, BlurFilter, parent)
     526{
     527}
     528
     529/*!
     530    Destructor of pixmap blur filter.
     531
     532    \internal
     533*/
     534QPixmapBlurFilter::~QPixmapBlurFilter()
     535{
     536}
     537
     538/*!
     539    Sets the radius of the blur filter. Higher radius produces increased blurriness.
     540
     541    \internal
     542*/
     543void QPixmapBlurFilter::setRadius(qreal radius)
     544{
     545    Q_D(QPixmapBlurFilter);
     546    d->radius = radius;
     547}
     548
     549/*!
     550    Gets the radius of the blur filter.
     551
     552    \internal
     553*/
     554qreal QPixmapBlurFilter::radius() const
     555{
     556    Q_D(const QPixmapBlurFilter);
     557    return d->radius;
     558}
     559
     560/*!
     561    Setting the blur hints to PerformanceHint causes the implementation
     562    to trade off visual quality to blur the image faster.  Setting the
     563    blur hints to QualityHint causes the implementation to improve
     564    visual quality at the expense of speed.
     565
     566    AnimationHint causes the implementation to optimize for animating
     567    the blur radius, possibly by caching blurred versions of the source
     568    pixmap.
     569
     570    The implementation is free to ignore this value if it only has a single
     571    blur algorithm.
     572
     573    \internal
     574*/
     575void QPixmapBlurFilter::setBlurHints(QGraphicsBlurEffect::BlurHints hints)
     576{
     577    Q_D(QPixmapBlurFilter);
     578    d->hints = hints;
     579}
     580
     581/*!
     582    Gets the blur hints of the blur filter.
     583
     584    \internal
     585*/
     586QGraphicsBlurEffect::BlurHints QPixmapBlurFilter::blurHints() const
     587{
     588    Q_D(const QPixmapBlurFilter);
     589    return d->hints;
     590}
     591
     592const qreal radiusScale = qreal(2.5);
     593
     594/*!
     595    \internal
     596*/
     597QRectF QPixmapBlurFilter::boundingRectFor(const QRectF &rect) const
     598{
     599    Q_D(const QPixmapBlurFilter);
     600    const qreal delta = radiusScale * d->radius + 1;
     601    return rect.adjusted(-delta, -delta, delta, delta);
     602}
     603
     604template <int shift>
     605inline int qt_static_shift(int value)
     606{
     607    if (shift == 0)
     608        return value;
     609    else if (shift > 0)
     610        return value << (uint(shift) & 0x1f);
     611    else
     612        return value >> (uint(-shift) & 0x1f);
     613}
     614
     615template<int aprec, int zprec>
     616inline void qt_blurinner(uchar *bptr, int &zR, int &zG, int &zB, int &zA, int alpha)
     617{
     618    QRgb *pixel = (QRgb *)bptr;
     619
     620#define Z_MASK (0xff << zprec)
     621    const int A_zprec = qt_static_shift<zprec - 24>(*pixel) & Z_MASK;
     622    const int R_zprec = qt_static_shift<zprec - 16>(*pixel) & Z_MASK;
     623    const int G_zprec = qt_static_shift<zprec - 8>(*pixel)  & Z_MASK;
     624    const int B_zprec = qt_static_shift<zprec>(*pixel)      & Z_MASK;
     625#undef Z_MASK
     626
     627    const int zR_zprec = zR >> aprec;
     628    const int zG_zprec = zG >> aprec;
     629    const int zB_zprec = zB >> aprec;
     630    const int zA_zprec = zA >> aprec;
     631
     632    zR += alpha * (R_zprec - zR_zprec);
     633    zG += alpha * (G_zprec - zG_zprec);
     634    zB += alpha * (B_zprec - zB_zprec);
     635    zA += alpha * (A_zprec - zA_zprec);
     636
     637#define ZA_MASK (0xff << (zprec + aprec))
     638    *pixel =
     639        qt_static_shift<24 - zprec - aprec>(zA & ZA_MASK)
     640        | qt_static_shift<16 - zprec - aprec>(zR & ZA_MASK)
     641        | qt_static_shift<8 - zprec - aprec>(zG & ZA_MASK)
     642        | qt_static_shift<-zprec - aprec>(zB & ZA_MASK);
     643#undef ZA_MASK
     644}
     645
     646const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
     647
     648template<int aprec, int zprec>
     649inline void qt_blurinner_alphaOnly(uchar *bptr, int &z, int alpha)
     650{
     651    const int A_zprec = int(*(bptr)) << zprec;
     652    const int z_zprec = z >> aprec;
     653    z += alpha * (A_zprec - z_zprec);
     654    *(bptr) = z >> (zprec + aprec);
     655}
     656
     657template<int aprec, int zprec, bool alphaOnly>
     658inline void qt_blurrow(QImage & im, int line, int alpha)
     659{
     660    uchar *bptr = im.scanLine(line);
     661
     662    int zR = 0, zG = 0, zB = 0, zA = 0;
     663
     664    if (alphaOnly && im.format() != QImage::Format_Indexed8)
     665        bptr += alphaIndex;
     666
     667    const int stride = im.depth() >> 3;
     668    const int im_width = im.width();
     669    for (int index = 0; index < im_width; ++index) {
     670        if (alphaOnly)
     671            qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha);
     672        else
     673            qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha);
     674        bptr += stride;
     675    }
     676
     677    bptr -= stride;
     678
     679    for (int index = im_width - 2; index >= 0; --index) {
     680        bptr -= stride;
     681        if (alphaOnly)
     682            qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha);
     683        else
     684            qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha);
     685    }
     686}
     687
     688/*
     689*  expblur(QImage &img, int radius)
     690*
     691*  Based on exponential blur algorithm by Jani Huhtanen
     692*
     693*  In-place blur of image 'img' with kernel
     694*  of approximate radius 'radius'.
     695*
     696*  Blurs with two sided exponential impulse
     697*  response.
     698*
     699*  aprec = precision of alpha parameter
     700*  in fixed-point format 0.aprec
     701*
     702*  zprec = precision of state parameters
     703*  zR,zG,zB and zA in fp format 8.zprec
     704*/
     705template <int aprec, int zprec, bool alphaOnly>
     706void expblur(QImage &img, qreal radius, bool improvedQuality = false, int transposed = 0)
     707{
     708    // halve the radius if we're using two passes
     709    if (improvedQuality)
     710        radius *= qreal(0.5);
     711
     712    Q_ASSERT(img.format() == QImage::Format_ARGB32_Premultiplied
     713             || img.format() == QImage::Format_RGB32);
     714
     715    // choose the alpha such that pixels at radius distance from a fully
     716    // saturated pixel will have an alpha component of no greater than
     717    // the cutOffIntensity
     718    const qreal cutOffIntensity = 2;
     719    int alpha = radius <= qreal(1e-5)
     720        ? ((1 << aprec)-1)
     721        : qRound((1<<aprec)*(1 - qPow(cutOffIntensity * (1 / qreal(255)), 1 / radius)));
     722
     723    int img_height = img.height();
     724    for (int row = 0; row < img_height; ++row) {
     725        for (int i = 0; i <= improvedQuality; ++i)
     726            qt_blurrow<aprec, zprec, alphaOnly>(img, row, alpha);
     727    }
     728
     729    QImage temp(img.height(), img.width(), img.format());
     730    if (transposed >= 0) {
     731        if (img.depth() == 8) {
     732            qt_memrotate270(reinterpret_cast<const quint8*>(img.bits()),
     733                            img.width(), img.height(), img.bytesPerLine(),
     734                            reinterpret_cast<quint8*>(temp.bits()),
     735                            temp.bytesPerLine());
     736        } else {
     737            qt_memrotate270(reinterpret_cast<const quint32*>(img.bits()),
     738                            img.width(), img.height(), img.bytesPerLine(),
     739                            reinterpret_cast<quint32*>(temp.bits()),
     740                            temp.bytesPerLine());
     741        }
     742    } else {
     743        if (img.depth() == 8) {
     744            qt_memrotate90(reinterpret_cast<const quint8*>(img.bits()),
     745                           img.width(), img.height(), img.bytesPerLine(),
     746                           reinterpret_cast<quint8*>(temp.bits()),
     747                           temp.bytesPerLine());
     748        } else {
     749            qt_memrotate90(reinterpret_cast<const quint32*>(img.bits()),
     750                           img.width(), img.height(), img.bytesPerLine(),
     751                           reinterpret_cast<quint32*>(temp.bits()),
     752                           temp.bytesPerLine());
     753        }
     754    }
     755
     756    img_height = temp.height();
     757    for (int row = 0; row < img_height; ++row) {
     758        for (int i = 0; i <= improvedQuality; ++i)
     759            qt_blurrow<aprec, zprec, alphaOnly>(temp, row, alpha);
     760    }
     761
     762    if (transposed == 0) {
     763        qt_memrotate90(reinterpret_cast<const quint32*>(temp.bits()),
     764                       temp.width(), temp.height(), temp.bytesPerLine(),
     765                       reinterpret_cast<quint32*>(img.bits()),
     766                       img.bytesPerLine());
     767    } else {
     768        img = temp;
     769    }
     770}
     771#define AVG(a,b)  ( ((((a)^(b)) & 0xfefefefeUL) >> 1) + ((a)&(b)) )
     772#define AVG16(a,b)  ( ((((a)^(b)) & 0xf7deUL) >> 1) + ((a)&(b)) )
     773
     774Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
     775{
     776    QImage srcImage = source;
     777
     778    if (source.format() == QImage::Format_Indexed8) {
     779        // assumes grayscale
     780        QImage dest(source.width() / 2, source.height() / 2, srcImage.format());
     781
     782        const uchar *src = reinterpret_cast<const uchar*>(const_cast<const QImage &>(srcImage).bits());
     783        int sx = srcImage.bytesPerLine();
     784        int sx2 = sx << 1;
     785
     786        uchar *dst = reinterpret_cast<uchar*>(dest.bits());
     787        int dx = dest.bytesPerLine();
     788        int ww = dest.width();
     789        int hh = dest.height();
     790
     791        for (int y = hh; y; --y, dst += dx, src += sx2) {
     792            const uchar *p1 = src;
     793            const uchar *p2 = src + sx;
     794            uchar *q = dst;
     795            for (int x = ww; x; --x, ++q, p1 += 2, p2 += 2)
     796                *q = ((int(p1[0]) + int(p1[1]) + int(p2[0]) + int(p2[1])) + 2) >> 2;
     797        }
     798
     799        return dest;
     800    } else if (source.format() == QImage::Format_ARGB8565_Premultiplied) {
     801        QImage dest(source.width() / 2, source.height() / 2, srcImage.format());
     802
     803        const uchar *src = reinterpret_cast<const uchar*>(const_cast<const QImage &>(srcImage).bits());
     804        int sx = srcImage.bytesPerLine();
     805        int sx2 = sx << 1;
     806
     807        uchar *dst = reinterpret_cast<uchar*>(dest.bits());
     808        int dx = dest.bytesPerLine();
     809        int ww = dest.width();
     810        int hh = dest.height();
     811
     812        for (int y = hh; y; --y, dst += dx, src += sx2) {
     813            const uchar *p1 = src;
     814            const uchar *p2 = src + sx;
     815            uchar *q = dst;
     816            for (int x = ww; x; --x, q += 3, p1 += 6, p2 += 6) {
     817                // alpha
     818                q[0] = AVG(AVG(p1[0], p1[3]), AVG(p2[0], p2[3]));
     819                // rgb
     820                const quint16 p16_1 = (p1[2] << 8) | p1[1];
     821                const quint16 p16_2 = (p1[5] << 8) | p1[4];
     822                const quint16 p16_3 = (p2[2] << 8) | p2[1];
     823                const quint16 p16_4 = (p2[5] << 8) | p2[4];
     824                const quint16 result = AVG16(AVG16(p16_1, p16_2), AVG16(p16_3, p16_4));
     825                q[1] = result & 0xff;
     826                q[2] = result >> 8;
     827            }
     828        }
     829
     830        return dest;
     831    } else if (source.format() != QImage::Format_ARGB32_Premultiplied
     832               && source.format() != QImage::Format_RGB32)
     833    {
     834        srcImage = source.convertToFormat(QImage::Format_ARGB32_Premultiplied);
     835    }
     836
     837    QImage dest(source.width() / 2, source.height() / 2, srcImage.format());
     838
     839    const quint32 *src = reinterpret_cast<const quint32*>(const_cast<const QImage &>(srcImage).bits());
     840    int sx = srcImage.bytesPerLine() >> 2;
     841    int sx2 = sx << 1;
     842
     843    quint32 *dst = reinterpret_cast<quint32*>(dest.bits());
     844    int dx = dest.bytesPerLine() >> 2;
     845    int ww = dest.width();
     846    int hh = dest.height();
     847
     848    for (int y = hh; y; --y, dst += dx, src += sx2) {
     849        const quint32 *p1 = src;
     850        const quint32 *p2 = src + sx;
     851        quint32 *q = dst;
     852        for (int x = ww; x; --x, q++, p1 += 2, p2 += 2)
     853            *q = AVG(AVG(p1[0], p1[1]), AVG(p2[0], p2[1]));
     854    }
     855
     856    return dest;
     857}
     858
     859Q_GUI_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0)
     860{
     861    if (blurImage.format() != QImage::Format_ARGB32_Premultiplied
     862        && blurImage.format() != QImage::Format_RGB32)
     863    {
     864        blurImage = blurImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
     865    }
     866
     867    qreal scale = 1;
     868    if (radius >= 4) {
     869        blurImage = qt_halfScaled(blurImage);
     870        scale = 2;
     871        radius *= qreal(0.5);
     872    }
     873
     874    if (alphaOnly)
     875        expblur<12, 10, true>(blurImage, radius, quality, transposed);
     876    else
     877        expblur<12, 10, false>(blurImage, radius, quality, transposed);
     878
     879    if (p) {
     880        p->scale(scale, scale);
     881        p->setRenderHint(QPainter::SmoothPixmapTransform);
     882        p->drawImage(QRect(0, 0, blurImage.width(), blurImage.height()), blurImage);
     883    }
     884}
     885
     886Q_GUI_EXPORT void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed = 0)
     887{
     888    if (blurImage.format() == QImage::Format_Indexed8)
     889        expblur<12, 10, true>(blurImage, radius, quality, transposed);
     890    else
     891        expblur<12, 10, false>(blurImage, radius, quality, transposed);
     892}
     893
     894bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
     895
     896/*!
     897    \internal
     898*/
     899void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap &src, const QRectF &rect) const
     900{
     901    Q_D(const QPixmapBlurFilter);
     902    if (!painter->isActive())
     903        return;
     904
     905    QRectF srcRect = rect;
     906    if (srcRect.isNull())
     907        srcRect = src.rect();
     908
     909    if (d->radius <= 1) {
     910        painter->drawPixmap(srcRect.translated(p), src, srcRect);
     911        return;
     912    }
     913
     914    qreal scaledRadius = radiusScale * d->radius;
     915    qreal scale;
     916    if (qt_scaleForTransform(painter->transform(), &scale))
     917        scaledRadius /= scale;
     918
     919    QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
     920        static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0;
     921    QPixmapBlurFilter *blurFilter = static_cast<QPixmapBlurFilter*>(filter);
     922    if (blurFilter) {
     923        blurFilter->setRadius(scaledRadius);
     924        blurFilter->setBlurHints(d->hints);
     925        blurFilter->draw(painter, p, src, srcRect);
     926        return;
     927    }
     928
     929    QImage srcImage;
     930    QImage destImage;
     931
     932    if (srcRect == src.rect()) {
     933        srcImage = src.toImage();
     934    } else {
     935        QRect rect = srcRect.toAlignedRect().intersected(src.rect());
     936        srcImage = src.copy(rect).toImage();
     937    }
     938
     939    QTransform transform = painter->worldTransform();
     940    painter->translate(p);
     941    qt_blurImage(painter, srcImage, scaledRadius, (d->hints & QGraphicsBlurEffect::QualityHint), false);
     942    painter->setWorldTransform(transform);
    479943}
    480944
     
    521985    \class QPixmapColorizeFilter
    522986    \since 4.5
    523     \ingroup multimedia
     987    \ingroup painting
    524988
    525989    \brief The QPixmapColorizeFilter class provides colorizing
     
    5431007public:
    5441008    QColor color;
     1009    qreal strength;
     1010    quint32 opaque : 1;
     1011    quint32 alphaBlend : 1;
     1012    quint32 padding : 30;
    5451013};
    5461014
     
    5551023    : QPixmapFilter(*new QPixmapColorizeFilterPrivate, ColorizeFilter, parent)
    5561024{
    557     d_func()->color = QColor(0, 0, 192);
     1025    Q_D(QPixmapColorizeFilter);
     1026    d->color = QColor(0, 0, 192);
     1027    d->strength = qreal(1);
     1028    d->opaque = true;
     1029    d->alphaBlend = false;
    5581030}
    5591031
     
    5811053
    5821054/*!
    583     \reimp
    584 
     1055    Gets the strength of the colorize filter, 1.0 means full colorized while
     1056    0.0 equals to no filtering at all.
     1057
     1058    \internal
     1059*/
     1060qreal QPixmapColorizeFilter::strength() const
     1061{
     1062    Q_D(const QPixmapColorizeFilter);
     1063    return d->strength;
     1064}
     1065
     1066/*!
     1067    Sets the strength of the colorize filter to \a strength.
     1068
     1069    \internal
     1070*/
     1071void QPixmapColorizeFilter::setStrength(qreal strength)
     1072{
     1073    Q_D(QPixmapColorizeFilter);
     1074    d->strength = qBound(qreal(0), strength, qreal(1));
     1075    d->opaque = !qFuzzyIsNull(d->strength);
     1076    d->alphaBlend = !qFuzzyIsNull(d->strength - 1);
     1077}
     1078
     1079/*!
    5851080    \internal
    5861081*/
     
    5891084    Q_D(const QPixmapColorizeFilter);
    5901085    QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
    591         static_cast<QPaintEngineEx *>(painter->paintEngine())->createPixmapFilter(type()) : 0;
     1086        static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0;
    5921087    QPixmapColorizeFilter *colorizeFilter = static_cast<QPixmapColorizeFilter*>(filter);
    5931088    if (colorizeFilter) {
    5941089        colorizeFilter->setColor(d->color);
     1090        colorizeFilter->setStrength(d->strength);
    5951091        colorizeFilter->draw(painter, dest, src, srcRect);
    596         delete colorizeFilter;
    5971092        return;
    5981093    }
    5991094
    6001095    // falling back to raster implementation
     1096
     1097    if (!d->opaque) {
     1098        painter->drawPixmap(dest, src, srcRect);
     1099        return;
     1100    }
    6011101
    6021102    QImage srcImage;
     
    6221122    destPainter.end();
    6231123
     1124    if (d->alphaBlend) {
     1125        // alpha blending srcImage and destImage
     1126        QImage buffer = srcImage;
     1127        QPainter bufPainter(&buffer);
     1128        bufPainter.setOpacity(d->strength);
     1129        bufPainter.drawImage(0, 0, destImage);
     1130        bufPainter.end();
     1131        destImage = buffer;
     1132    }
     1133
    6241134    if (srcImage.hasAlphaChannel())
    6251135        destImage.setAlphaChannel(srcImage.alphaChannel());
     
    6321142public:
    6331143    QPixmapDropShadowFilterPrivate()
    634             : offset(8, 8),
    635             radius(1),
    636             color(63, 63, 63, 255) {
    637     }
     1144        : offset(8, 8), color(63, 63, 63, 180), radius(1) {}
    6381145
    6391146    QPointF offset;
     1147    QColor color;
    6401148    qreal radius;
    641     QColor color;
    642 
    643     QPixmapConvolutionFilter *convolution;
    6441149};
    6451150
     
    6471152    \class QPixmapDropShadowFilter
    6481153    \since 4.5
    649     \ingroup multimedia
     1154    \ingroup painting
    6501155
    6511156    \brief The QPixmapDropShadowFilter class is a convenience class
     
    6851190    : QPixmapFilter(*new QPixmapDropShadowFilterPrivate, DropShadowFilter, parent)
    6861191{
    687     Q_D(QPixmapDropShadowFilter);
    688     d->convolution = new QPixmapConvolutionFilter;
    689 
    690     setBlurRadius(1);
    6911192}
    6921193
     
    6981199QPixmapDropShadowFilter::~QPixmapDropShadowFilter()
    6991200{
    700     Q_D(QPixmapDropShadowFilter);
    701     delete d->convolution;
    7021201}
    7031202
     
    7291228{
    7301229    Q_D(QPixmapDropShadowFilter);
    731 
    7321230    d->radius = radius;
    733 
    734     int dim = 2 * qRound(radius) + 1;
    735     QVarLengthArray<qreal> arr(dim * dim);
    736     qreal f = 1 / qreal(dim * dim);
    737     for (int i = 0; i < dim * dim; ++i)
    738         arr[i] = f;
    739     d->convolution->setConvolutionKernel(arr.data(), dim, dim);
    7401231}
    7411232
     
    8051296
    8061297/*!
    807     \reimp
    808 
    8091298    \internal
    8101299 */
     
    8121301{
    8131302    Q_D(const QPixmapDropShadowFilter);
    814 
    815     qreal x1 = qMin(rect.left(), rect.left() + d->offset.x() - d->radius);
    816     qreal y1 = qMin(rect.top(), rect.top() + d->offset.y() - d->radius);
    817     qreal x2 = qMax(rect.right(), rect.right() + d->offset.x() + d->radius);
    818     qreal y2 = qMax(rect.bottom(), rect.bottom() + d->offset.y() + d->radius);
    819 
    820     return QRectF(x1, y1, x2 - x1, y2 - y1);
    821 }
    822 
    823 /*!
    824     \reimp
    825 
     1303    return rect.united(rect.translated(d->offset).adjusted(-d->radius, -d->radius, d->radius, d->radius));
     1304}
     1305
     1306/*!
    8261307    \internal
    8271308 */
     
    8321313{
    8331314    Q_D(const QPixmapDropShadowFilter);
    834 
    835     QPixmap tmp = src.isNull() ? px : px.copy(src.toRect());
     1315    QPixmapFilter *filter = p->paintEngine() && p->paintEngine()->isExtended() ?
     1316        static_cast<QPaintEngineEx *>(p->paintEngine())->pixmapFilter(type(), this) : 0;
     1317    QPixmapDropShadowFilter *dropShadowFilter = static_cast<QPixmapDropShadowFilter*>(filter);
     1318    if (dropShadowFilter) {
     1319        dropShadowFilter->setColor(d->color);
     1320        dropShadowFilter->setBlurRadius(d->radius);
     1321        dropShadowFilter->setOffset(d->offset);
     1322        dropShadowFilter->draw(p, pos, px, src);
     1323        return;
     1324    }
     1325
     1326    QImage tmp(px.size(), QImage::Format_ARGB32_Premultiplied);
     1327    tmp.fill(0);
    8361328    QPainter tmpPainter(&tmp);
     1329    tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
     1330    tmpPainter.drawPixmap(d->offset, px);
     1331    tmpPainter.end();
     1332
     1333    // blur the alpha channel
     1334    QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
     1335    blurred.fill(0);
     1336    QPainter blurPainter(&blurred);
     1337    qt_blurImage(&blurPainter, tmp, d->radius, false, true);
     1338    blurPainter.end();
     1339
     1340    tmp = blurred;
    8371341
    8381342    // blacken the image...
     1343    tmpPainter.begin(&tmp);
    8391344    tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
    840     tmpPainter.fillRect(0, 0, tmp.width(), tmp.height(), d->color);
     1345    tmpPainter.fillRect(tmp.rect(), d->color);
    8411346    tmpPainter.end();
    8421347
    8431348    // draw the blurred drop shadow...
    844     d->convolution->draw(p, pos + d->offset, tmp);
     1349    p->drawImage(pos, tmp);
    8451350
    8461351    // Draw the actual pixmap...
    8471352    p->drawPixmap(pos, px, src);
    8481353}
     1354
    8491355QT_END_NAMESPACE
     1356
     1357#endif //QT_NO_GRAPHICSEFFECT
  • trunk/src/gui/image/qpixmapfilter_p.h

    r2 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**
     
    5656#include <QtCore/qnamespace.h>
    5757#include <QtGui/qpixmap.h>
     58#include <QtGui/qgraphicseffect.h>
    5859
     60#ifndef QT_NO_GRAPHICSEFFECT
    5961QT_BEGIN_HEADER
    6062
     
    7981        ColorizeFilter,
    8082        DropShadowFilter,
     83        BlurFilter,
    8184
    8285        UserFilter = 1024
     
    118121};
    119122
     123class QPixmapBlurFilterPrivate;
     124
     125class Q_GUI_EXPORT QPixmapBlurFilter : public QPixmapFilter
     126{
     127    Q_OBJECT
     128    Q_DECLARE_PRIVATE(QPixmapBlurFilter)
     129
     130public:
     131    QPixmapBlurFilter(QObject *parent = 0);
     132    ~QPixmapBlurFilter();
     133
     134    void setRadius(qreal radius);
     135    void setBlurHints(QGraphicsBlurEffect::BlurHints hints);
     136
     137    qreal radius() const;
     138    QGraphicsBlurEffect::BlurHints blurHints() const;
     139
     140    QRectF boundingRectFor(const QRectF &rect) const;
     141    void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const;
     142
     143private:
     144    friend class QGLPixmapBlurFilter;
     145};
     146
    120147class QPixmapColorizeFilterPrivate;
    121148
     
    130157    void setColor(const QColor& color);
    131158    QColor color() const;
     159
     160    void setStrength(qreal strength);
     161    qreal strength() const;
    132162
    133163    void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const;
     
    163193QT_END_HEADER
    164194
     195#endif //QT_NO_GRAPHICSEFFECT
    165196#endif // QPIXMAPFILTER_H
  • trunk/src/gui/image/qpnghandler.cpp

    r2 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**
     
    6767#  define Q_INTERNAL_WIN_NO_THROW
    6868#endif
     69
     70// avoid going through QImage::scanLine() which calls detach
     71#define FAST_SCAN_LINE(data, bpl, y) (data + (y) * bpl)
    6972
    7073/*
     
    172175                    return;
    173176            }
    174             image.setNumColors(2);
     177            image.setColorCount(2);
    175178            image.setColor(1, qRgb(0,0,0));
    176179            image.setColor(0, qRgb(255,255,255));
     
    200203                    return;
    201204            }
    202             image.setNumColors(ncols);
     205            image.setColorCount(ncols);
    203206            for (int i=0; i<ncols; i++) {
    204207                int c = i*255/(ncols-1);
     
    206209            }
    207210            if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
     211#if PNG_LIBPNG_VER_MAJOR < 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR < 4)
    208212                const int g = info_ptr->trans_values.gray;
     213#else
     214                const int g = info_ptr->trans_color.gray;
     215#endif
    209216                if (g < ncols) {
    210217                    image.setColor(g, 0);
     
    227234                return;
    228235        }
    229         image.setNumColors(info_ptr->num_palette);
     236        image.setColorCount(info_ptr->num_palette);
    230237        int i = 0;
    231238        if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
     
    235242                    info_ptr->palette[i].green,
    236243                    info_ptr->palette[i].blue,
     244#if PNG_LIBPNG_VER_MAJOR < 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR < 4)
    237245                    info_ptr->trans[i]
     246#else
     247                    info_ptr->trans_alpha[i]
     248#endif
    238249                   )
    239250               );
     
    501512    if (color_type == PNG_COLOR_TYPE_PALETTE
    502513        && outImage->format() == QImage::Format_Indexed8) {
    503         int color_table_size = outImage->numColors();
     514        int color_table_size = outImage->colorCount();
    504515        for (int y=0; y<(int)height; ++y) {
    505             uchar *p = outImage->scanLine(y);
     516            uchar *p = FAST_SCAN_LINE(data, bpl, y);
    506517            uchar *end = p + width;
    507518            while (p < end) {
     
    755766    png_colorp palette = 0;
    756767    png_bytep copy_trans = 0;
    757     if (image.numColors()) {
     768    if (image.colorCount()) {
    758769        // Paletted
    759         int num_palette = image.numColors();
     770        int num_palette = image.colorCount();
    760771        palette = new png_color[num_palette];
    761772        png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
     
    845856        0, 0, 0);
    846857
    847     const uchar *data = image.bits();
     858    const uchar *data = (static_cast<const QImage *>(&image))->bits();
    848859    int bpl = image.bytesPerLine();
    849860    row_pointers = new png_bytep[height];
     
    957968{
    958969    if (option == Gamma)
    959         d->gamma = value.toDouble();
     970        d->gamma = value.toFloat();
    960971    else if (option == Quality)
    961972        d->quality = value.toInt();
  • trunk/src/gui/image/qpnghandler_p.h

    r2 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**
  • trunk/src/gui/image/qppmhandler.cpp

    r2 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**
     
    8181            continue;
    8282        else if (c == '#')
    83             d->readLine(buf, buflen);
     83            (void)d->readLine(buf, buflen);
    8484        else
    8585            break;
     
    243243
    244244    if (nbits == 1) {                                // bitmap
    245         outImage->setNumColors(2);
     245        outImage->setColorCount(2);
    246246        outImage->setColor(0, qRgb(255,255,255)); // white
    247247        outImage->setColor(1, qRgb(0,0,0));        // black
    248248    } else if (nbits == 8) {                        // graymap
    249         outImage->setNumColors(maxc+1);
     249        outImage->setColorCount(maxc+1);
    250250        for (int i=0; i<=maxc; i++)
    251251            outImage->setColor(i, qRgb(i*255/maxc,i*255/maxc,i*255/maxc));
     
    265265
    266266    if (format == "pbm") {
    267         image = image.convertToFormat(QImage::Format_MonoLSB);
     267        image = image.convertToFormat(QImage::Format_Mono);
    268268    } else if (image.depth() == 1) {
    269269        image = image.convertToFormat(QImage::Format_Indexed8);
     
    288288    }
    289289
    290     if (image.depth() == 1 && image.numColors() == 2) {
     290    if (image.depth() == 1 && image.colorCount() == 2) {
    291291        if (qGray(image.color(0)) < qGray(image.color(1))) {
    292292            // 0=dark/black, 1=light/white - invert
  • trunk/src/gui/image/qppmhandler_p.h

    r2 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**
  • trunk/src/gui/image/qxbmhandler.cpp

    r2 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**
     
    136136    }
    137137
    138     outImage->setNumColors(2);
     138    outImage->setColorCount(2);
    139139    outImage->setColor(0, qRgb(255,255,255));        // white
    140140    outImage->setColor(1, qRgb(0,0,0));                // black
  • trunk/src/gui/image/qxbmhandler_p.h

    r2 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**
  • trunk/src/gui/image/qxpmhandler.cpp

    r2 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**
     
    896896                return false;
    897897        }
    898         image.setNumColors(ncols);
     898        image.setColorCount(ncols);
    899899    }
    900900
     
    11471147    s << "/* XPM */" << endl
    11481148      << "static char *" << fbname(fileName) << "[]={" << endl
    1149       << "\"" << w << " " << h << " " << ncolors << " " << cpp << "\"";
     1149      << '\"' << w << ' ' << h << ' ' << ncolors << ' ' << cpp << '\"';
    11501150
    11511151    // write palette
     
    11631163                          qBlue(color));
    11641164        ++c;
    1165         s << "," << endl << line;
     1165        s << ',' << endl << line;
    11661166    }
    11671167
     
    11851185            }
    11861186        }
    1187         s << "," << endl << "\"" << line << "\"";
     1187        s << ',' << endl << '\"' << line << '\"';
    11881188    }
    11891189    s << "};" << endl;
  • trunk/src/gui/image/qxpmhandler_p.h

    r2 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**
Note: See TracChangeset for help on using the changeset viewer.