Changeset 561 for trunk/src/gui/image
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 57 edited
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/image/image.pri
r95 r561 7 7 image/qbitmap.h \ 8 8 image/qicon.h \ 9 image/qicon_p.h \ 10 image/qiconloader_p.h \ 9 11 image/qiconengine.h \ 10 12 image/qiconengineplugin.h \ … … 23 25 image/qpixmap_raster_p.h \ 24 26 image/qpixmapcache.h \ 27 image/qpixmapcache_p.h \ 25 28 image/qpixmapdata_p.h \ 26 29 image/qpixmapdatafactory_p.h \ 27 image/qpixmapfilter_p.h 30 image/qpixmapfilter_p.h \ 31 image/qimagepixmapcleanuphooks_p.h \ 32 28 33 29 34 SOURCES += \ 30 35 image/qbitmap.cpp \ 31 36 image/qicon.cpp \ 37 image/qiconloader.cpp \ 32 38 image/qimage.cpp \ 33 39 image/qimageiohandler.cpp \ … … 47 53 image/qpixmap_raster.cpp \ 48 54 image/qnativeimage.cpp \ 55 image/qimagepixmapcleanuphooks.cpp \ 56 49 57 50 58 win32 { … … 64 72 HEADERS += image/qpixmap_mac_p.h 65 73 SOURCES += image/qpixmap_mac.cpp 74 } 75 symbian { 76 HEADERS += image/qpixmap_s60_p.h 77 SOURCES += image/qpixmap_s60.cpp 66 78 } 67 79 … … 85 97 86 98 contains(QT_CONFIG, system-png) { 87 unix:LIBS += -lpng99 unix:LIBS_PRIVATE += -lpng 88 100 win32:LIBS += libpng.lib 89 101 } else { -
trunk/src/gui/image/qbitmap.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 54 54 \brief The QBitmap class provides monochrome (1-bit depth) pixmaps. 55 55 56 \ingroup multimedia56 \ingroup painting 57 57 \ingroup shared 58 58 … … 79 79 80 80 The QBitmap class provides the transformed() function returning a 81 transformed copy of the bitmap; use the Q Matrixargument to81 transformed copy of the bitmap; use the QTransform argument to 82 82 translate, scale, shear, and rotate the bitmap. In addition, 83 83 QBitmap provides the static fromData() function which returns a … … 87 87 88 88 Just like the QPixmap class, QBitmap is optimized by the use of 89 implicit data sharing. For more information, see the {Implicit89 implicit data sharing. For more information, see the \l {Implicit 90 90 Data Sharing} documentation. 91 91 … … 93 93 */ 94 94 95 /*! \typedef QBitmap::DataPtr 96 \internal 97 */ 95 98 96 99 /*! … … 99 102 \sa QPixmap::isNull() 100 103 */ 101 102 104 QBitmap::QBitmap() 103 105 : QPixmap(QSize(0, 0), QPixmapData::BitmapType) … … 266 268 } 267 269 268 QPixmapData *d;269 270 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()); 277 276 } 278 277 … … 319 318 /*! 320 319 \overload 320 \obsolete 321 321 322 322 This convenience function converts the \a matrix to a QTransform -
trunk/src/gui/image/qbitmap.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 83 83 QT3_SUPPORT QBitmap &operator=(const QImage &image) { *this = fromImage(image); return *this; } 84 84 #endif 85 86 typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr; 85 87 }; 86 88 Q_DECLARE_SHARED(QBitmap) -
trunk/src/gui/image/qbmphandler.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 53 53 { 54 54 int i; 55 if (image->depth() == 1 && image-> numColors() == 2) {55 if (image->depth() == 1 && image->colorCount() == 2) { 56 56 register uint *p = (uint *)image->bits(); 57 int nbytes = image-> numBytes();57 int nbytes = image->byteCount(); 58 58 for (i=0; i<nbytes/4; i++) { 59 59 *p = ~*p; … … 82 82 const int BMP_FILEHDR_SIZE = 14; // size of BMP_FILEHDR data 83 83 84 QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf)84 static QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf) 85 85 { // read file header 86 86 s.readRawData(bf.bfType, 2); … … 89 89 } 90 90 91 QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf)91 static QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf) 92 92 { // write file header 93 93 s.writeRawData(bf.bfType, 2); … … 107 107 108 108 109 QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)109 static QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi) 110 110 { 111 111 s >> bi.biSize; … … 129 129 } 130 130 131 QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)131 static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi) 132 132 { 133 133 s << bi.biSize; … … 247 247 if (depth != 32) { 248 248 ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits; 249 image.set NumColors(ncols);249 image.setColorCount(ncols); 250 250 } 251 251 … … 527 527 return false; 528 528 529 if (image.depth() == 8 && image. numColors() <= 16) {529 if (image.depth() == 8 && image.colorCount() <= 16) { 530 530 bpl_bmp = (((bpl+1)/2+3)/4)*4; 531 531 nbits = 4; … … 555 555 : 2834; // 72 dpi default 556 556 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(); 559 559 s << bi; // write info header 560 560 if (s.status() != QDataStream::Ok) … … 562 562 563 563 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()]; 565 565 uchar *rgb = color_table; 566 566 QVector<QRgb> c = image.colorTable(); 567 for (int i=0; i<image. numColors(); i++) {567 for (int i=0; i<image.colorCount(); i++) { 568 568 *rgb++ = qBlue (c[i]); 569 569 *rgb++ = qGreen(c[i]); … … 571 571 *rgb++ = 0; 572 572 } 573 if (d->write((char *)color_table, 4*image. numColors()) == -1) {573 if (d->write((char *)color_table, 4*image.colorCount()) == -1) { 574 574 delete [] color_table; 575 575 return false; … … 755 755 756 756 // Code partially repeated in qt_write_dib 757 if (image.depth() == 8 && image. numColors() <= 16) {757 if (image.depth() == 8 && image.colorCount() <= 16) { 758 758 bpl_bmp = (((bpl+1)/2+3)/4)*4; 759 759 } else if (image.depth() == 32) { … … 772 772 bf.bfReserved1 = 0; 773 773 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; 775 775 bf.bfSize = bf.bfOffBits + bpl_bmp*image.height(); 776 776 s << bf; -
trunk/src/gui/image/qbmphandler_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qicon.cpp
r261 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "qicon.h" 43 #include "qicon_p.h" 43 44 #include "qiconengine.h" 44 45 #include "qiconengineplugin.h" 45 46 #include "private/qfactoryloader_p.h" 47 #include "private/qiconloader_p.h" 46 48 #include "qapplication.h" 47 49 #include "qstyleoption.h" … … 51 53 #include "qpixmapcache.h" 52 54 #include "qvariant.h" 55 #include "qcache.h" 53 56 #include "qdebug.h" 57 #include "private/qguiplatformplugin_p.h" 54 58 55 59 #ifdef Q_WS_MAC 56 60 #include <private/qt_mac_p.h> 57 #include < Carbon/Carbon.h>61 #include <private/qt_cocoa_helpers_mac_p.h> 58 62 #endif 59 63 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 60 70 QT_BEGIN_NAMESPACE 61 71 … … 95 105 static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1); 96 106 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 }; 107 QIconPrivate::QIconPrivate() 108 : engine(0), ref(1), 109 serialNum(serialNumCounter.fetchAndAddRelaxed(1)), 110 detach_no(0), 111 engine_version(2), 112 v1RefCount(0) 113 { 114 } 164 115 165 116 QPixmapIconEngine::QPixmapIconEngine() … … 179 130 { 180 131 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(); 183 134 #endif 184 135 painter->drawPixmap(rect, pixmap(pixmapSize, mode, state)); … … 316 267 + QString::number(pm.cacheKey()) 317 268 + QString::number(pe->mode) 269 + QString::number(QApplication::palette().cacheKey()) 270 + QLatin1Char('_') 318 271 + QString::number(actualSize.width()) 319 272 + QLatin1Char('_') … … 440 393 in >> mode; 441 394 in >> state; 442 if (pm.isNull()) 395 if (pm.isNull()) { 443 396 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 } 446 402 } 447 403 return true; … … 503 459 and states. 504 460 505 \ingroup multimedia461 \ingroup painting 506 462 \ingroup shared 507 \mainclass 463 508 464 509 465 A QIcon can generate smaller, larger, active, and disabled pixmaps … … 865 821 QImageWriter::supportedImageFormats() functions to retrieve a 866 822 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. 867 826 868 827 \sa addPixmap() … … 922 881 } 923 882 883 /*! 884 \since 4.6 885 886 Sets the search paths for icon themes to \a paths. 887 \sa themeSearchPaths(), fromTheme(), setThemeName() 888 */ 889 void 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 */ 910 QStringList 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 */ 926 void 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 */ 942 QString 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 */ 975 QIcon 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 */ 1003 bool QIcon::hasThemeIcon(const QString &name) 1004 { 1005 QIcon icon = fromTheme(name); 1006 1007 return !icon.isNull(); 1008 } 1009 1010 924 1011 /***************************************************************************** 925 1012 QIcon stream functions … … 931 1018 \since 4.2 932 1019 933 Writes the given \a icon to the thegiven \a stream as a PNG1020 Writes the given \a icon to the given \a stream as a PNG 934 1021 image. If the icon contains more than one image, all images will 935 1022 be written to the stream. Note that writing the stream to a file … … 993 1080 icon.d->engine = engine; 994 1081 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); 995 1087 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) 996 1088 } else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) { … … 1138 1230 1139 1231 QT_END_NAMESPACE 1232 #endif //QT_NO_ICON -
trunk/src/gui/image/qicon.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 98 98 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const; 99 99 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 100 110 #ifdef QT3_SUPPORT 101 111 enum Size { Small, Large, Automatic = Small }; -
trunk/src/gui/image/qiconengine.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 50 50 \brief The QIconEngine class provides an abstract base class for QIcon renderers. 51 51 52 \ingroup multimedia52 \ingroup painting 53 53 54 54 \bold {Use QIconEngineV2 instead.} … … 145 145 \brief The QIconEngineV2 class provides an abstract base class for QIcon renderers. 146 146 147 \ingroup multimedia147 \ingroup painting 148 148 \since 4.3 149 149 -
trunk/src/gui/image/qiconengine.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qiconengineplugin.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qiconengineplugin.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qimage.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 50 50 #include "qstringlist.h" 51 51 #include "qvariant.h" 52 #include "qimagepixmapcleanuphooks_p.h" 52 53 #include <ctype.h> 53 54 #include <stdlib.h> … … 61 62 #include <qhash.h> 62 63 63 #ifdef QT_RASTER_IMAGEENGINE64 64 #include <private/qpaintengine_raster_p.h> 65 #else66 #include <qpaintengine.h>67 #endif68 65 69 66 #include <private/qimage_p.h> … … 106 103 } 107 104 108 109 // ### Qt 5: remove110 typedef void (*_qt_image_cleanup_hook)(int);111 Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook = 0;112 113 // ### Qt 5: rename114 typedef void (*_qt_image_cleanup_hook_64)(qint64);115 Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64 = 0;116 105 117 106 static QImage rotated90(const QImage &src); … … 186 175 } 187 176 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 */ 188 184 QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) 189 185 { … … 224 220 return 0; 225 221 226 Q ImageData *d = new QImageData;222 QScopedPointer<QImageData> d(new QImageData); 227 223 d->colortable.resize(numColors); 228 224 if (depth == 1) { … … 247 243 248 244 if (!d->data) { 249 delete d;250 245 return 0; 251 246 } 252 247 253 248 d->ref.ref(); 254 return d ;249 return d.take(); 255 250 256 251 } … … 258 253 QImageData::~QImageData() 259 254 { 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)); 262 257 delete paintEngine; 263 258 if (data && own_data) … … 345 340 \class QImage 346 341 347 \ingroup multimedia342 \ingroup painting 348 343 \ingroup shared 349 \mainclass 344 350 345 \reentrant 351 346 … … 382 377 \note If you would like to load QImage objects in a static build of Qt, 383 378 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. 384 382 385 383 \tableofcontents … … 452 450 as a QRgb value indepedent of the image's format. 453 451 454 In case of monochrome and 8-bit images, the numColors() and452 In case of monochrome and 8-bit images, the colorCount() and 455 453 colorTable() functions provide information about the color 456 454 components used to store the image data: The colorTable() function … … 487 485 \l {QImage#Image Formats}{Image Formats} section). 488 486 489 The format(), bytesPerLine(), and numBytes() functions provide487 The format(), bytesPerLine(), and byteCount() functions provide 490 488 low-level information about the data stored in the image. 491 489 … … 549 547 size of the integer varies depending on the format. QImage 550 548 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. 556 550 557 551 Monochrome images are stored using 1-bit indexes into a color table … … 591 585 The mirrored() function returns a mirror of the image in the 592 586 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. 596 589 597 590 The scaledToWidth() and scaledToHeight() functions return scaled … … 612 605 \table 613 606 \header \o Function \o Description 614 \row615 \o setAlphaChannel()616 \o Sets the alpha channel of the image.617 607 \row 618 608 \o setDotsPerMeterX() … … 634 624 monochrome and 8-bit formats. 635 625 \row 636 \o set NumColors()626 \o setColorCount() 637 627 \o Resizes the color table. Only monochrome and 8-bit formats. 638 628 … … 707 697 \enum QImage::Format 708 698 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. 710 702 711 703 \value Format_Invalid The image is invalid. … … 714 706 \value Format_MonoLSB The image is stored using 1-bit per pixel. Bytes are 715 707 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 717 712 \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 719 717 \value Format_ARGB32_Premultiplied The image is stored using a premultiplied 32-bit 720 718 ARGB format (0xAARRGGBB), i.e. the red, … … 725 723 using alpha blending) are faster using premultiplied ARGB32 726 724 than with plain ARGB32. 725 727 726 \value Format_RGB16 The image is stored using a 16-bit RGB format (5-6-5). 727 728 728 \value Format_ARGB8565_Premultiplied The image is stored using a 729 729 premultiplied 24-bit ARGB format (8-5-6-5). … … 741 741 \value Format_ARGB4444_Premultiplied The image is stored using a 742 742 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. 743 749 744 750 \sa format(), convertToFormat() … … 904 910 If \a format is an indexed color format, the image color table is 905 911 initially empty and must be sufficiently expanded with 906 set NumColors() or setColorTable() before the image is used.912 setColorCount() or setColorTable() before the image is used. 907 913 */ 908 914 QImage::QImage(uchar* data, int width, int height, Format format) … … 926 932 If \a format is an indexed color format, the image color table is 927 933 initially empty and must be sufficiently expanded with 928 set NumColors() or setColorTable() before the image is used.934 setColorCount() or setColorTable() before the image is used. 929 935 930 936 Unlike the similar QImage constructor that takes a non-const data buffer, … … 952 958 If \a format is an indexed color format, the image color table is 953 959 initially empty and must be sufficiently expanded with 954 set NumColors() or setColorTable() before the image is used.960 setColorCount() or setColorTable() before the image is used. 955 961 */ 956 962 QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format) … … 972 978 If \a format is an indexed color format, the image color table is 973 979 initially empty and must be sufficiently expanded with 974 set NumColors() or setColorTable() before the image is used.980 setColorCount() or setColorTable() before the image is used. 975 981 976 982 Unlike the similar QImage constructor that takes a non-const data buffer, … … 1124 1130 Use the constructor that accepts a width, a height and a format 1125 1131 (i.e. specifying the depth and bit order), in combination with the 1126 set NumColors() function, instead.1132 setColorCount() function, instead. 1127 1133 1128 1134 \oldcode … … 1133 1139 // For 8 bit images the default number of colors is 256. If 1134 1140 // another number of colors is required it can be specified 1135 // using the set NumColors() function.1136 image.set NumColors(numColors);1141 // using the setColorCount() function. 1142 image.setColorCount(numColors); 1137 1143 \endcode 1138 1144 */ 1139 1145 1140 QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder)1146 QImage::QImage(int w, int h, int depth, int colorCount, Endian bitOrder) 1141 1147 : QPaintDevice() 1142 1148 { 1143 d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), numColors);1149 d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), colorCount); 1144 1150 } 1145 1151 … … 1150 1156 Use the constructor that accepts a size and a format 1151 1157 (i.e. specifying the depth and bit order), in combination with the 1152 set NumColors() function, instead.1158 setColorCount() function, instead. 1153 1159 1154 1160 \oldcode … … 1161 1167 // For 8 bit images the default number of colors is 256. If 1162 1168 // another number of colors is required it can be specified 1163 // using the set NumColors() function.1164 image.set NumColors(numColors);1169 // using the setColorCount() function. 1170 image.setColorCount(numColors); 1165 1171 \endcode 1166 1172 */ … … 1230 1236 d->colortable[i] = colortable[i]; 1231 1237 } else if (numColors) { 1232 set NumColors(numColors);1238 setColorCount(numColors); 1233 1239 } 1234 1240 } … … 1281 1287 d->colortable[i] = colortable[i]; 1282 1288 } else if (numColors) { 1283 set NumColors(numColors);1289 setColorCount(numColors); 1284 1290 } 1285 1291 } … … 1347 1353 { 1348 1354 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()); 1351 1357 1352 1358 if (d->ref != 1 || d->ro_data) … … 1590 1596 1591 1597 /*! 1598 \obsolete 1592 1599 \fn int QImage::numColors() const 1593 1600 1594 1601 Returns the size of the color table for the image. 1595 1602 1596 Notice that numColors() returns 0 for 32-bpp images because these 1603 \sa setColorCount() 1604 */ 1605 int 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 1597 1617 images do not use color tables, but instead encode pixel values as 1598 1618 ARGB quadruplets. 1599 1619 1600 \sa set NumColors(), {QImage#Image Information}{Image Information}1601 */ 1602 int QImage:: numColors() const1620 \sa setColorCount(), {QImage#Image Information}{Image Information} 1621 */ 1622 int QImage::colorCount() const 1603 1623 { 1604 1624 return d ? d->colortable.size() : 0; … … 1622 1642 Returns a pointer to the scanline pointer table. This is the 1623 1643 beginning of the data block for the image. 1644 Returns 0 in case of an error. 1624 1645 1625 1646 Use the bits() or scanLine() function instead. … … 1637 1658 if (!d->jumptable) { 1638 1659 d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *)); 1660 if (!d->jumptable) 1661 return 0; 1639 1662 uchar *data = d->data; 1640 1663 int height = d->height; … … 1657 1680 if (!d->jumptable) { 1658 1681 d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *)); 1682 if (!d->jumptable) 1683 return 0; 1659 1684 uchar *data = d->data; 1660 1685 int height = d->height; … … 1692 1717 d->colortable = colors; 1693 1718 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 } 1696 1725 } 1697 1726 … … 1700 1729 or an empty list if the image does not have a color table 1701 1730 1702 \sa setColorTable(), numColors(), color()1731 \sa setColorTable(), colorCount(), color() 1703 1732 */ 1704 1733 QVector<QRgb> QImage::colorTable() const … … 1709 1738 1710 1739 /*! 1740 \obsolete 1741 Returns the number of bytes occupied by the image data. 1742 1743 \sa byteCount() 1744 */ 1745 int QImage::numBytes() const 1746 { 1747 return d ? d->nbytes : 0; 1748 } 1749 1750 /*! 1751 \since 4.6 1711 1752 Returns the number of bytes occupied by the image data. 1712 1753 … … 1714 1755 Information} 1715 1756 */ 1716 int QImage:: numBytes() const1757 int QImage::byteCount() const 1717 1758 { 1718 1759 return d ? d->nbytes : 0; … … 1722 1763 Returns the number of bytes per image scanline. 1723 1764 1724 This is equivalent to numBytes()/ height().1765 This is equivalent to byteCount() / height(). 1725 1766 1726 1767 \sa scanLine() … … 1745 1786 QRgb QImage::color(int i) const 1746 1787 { 1747 Q_ASSERT(i < numColors());1788 Q_ASSERT(i < colorCount()); 1748 1789 return d ? d->colortable.at(i) : QRgb(uint(-1)); 1749 1790 } … … 1756 1797 1757 1798 If \a index is outside the current size of the color table, it is 1758 expanded with set NumColors().1759 1760 \sa color(), numColors(), setColorTable(), {QImage#Pixel Manipulation}{Pixel1799 expanded with setColorCount(). 1800 1801 \sa color(), colorCount(), setColorTable(), {QImage#Pixel Manipulation}{Pixel 1761 1802 Manipulation} 1762 1803 */ … … 1776 1817 1777 1818 if (i >= d->colortable.size()) 1778 set NumColors(i+1);1819 setColorCount(i+1); 1779 1820 d->colortable[i] = c; 1780 1821 d->has_alpha_clut |= (qAlpha(c) != 255); … … 1833 1874 current return value. 1834 1875 1835 \sa scanLine(), numBytes()1876 \sa scanLine(), byteCount() 1836 1877 */ 1837 1878 uchar *QImage::bits() … … 2014 2055 2015 2056 /*! 2057 \obsolete 2016 2058 Resizes the color table to contain \a numColors entries. 2059 2060 \sa setColorCount() 2061 */ 2062 2063 void 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. 2017 2071 2018 2072 If the color table is expanded, all the extra colors will be set to … … 2023 2077 otherwise the results are undefined. 2024 2078 2025 \sa numColors(), colorTable(), setColor(), {QImage#Image2079 \sa colorCount(), colorTable(), setColor(), {QImage#Image 2026 2080 Transformations}{Image Transformations} 2027 2081 */ 2028 2082 2029 void QImage::set NumColors(int numColors)2083 void QImage::setColorCount(int colorCount) 2030 2084 { 2031 2085 if (!d) { 2032 qWarning("QImage::set NumColors: null image");2086 qWarning("QImage::setColorCount: null image"); 2033 2087 return; 2034 2088 } … … 2040 2094 return; 2041 2095 2042 if ( numColors== d->colortable.size())2096 if (colorCount == d->colortable.size()) 2043 2097 return; 2044 if ( numColors<= 0) { // use no color table2098 if (colorCount <= 0) { // use no color table 2045 2099 d->colortable = QVector<QRgb>(); 2046 2100 return; 2047 2101 } 2048 2102 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) 2051 2105 d->colortable[i] = 0; 2052 2053 2106 } 2054 2107 … … 2371 2424 switch (dithermode) { 2372 2425 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; 2375 2429 int bmwidth = (w+7)/8; 2376 2430 … … 2452 2506 } 2453 2507 } 2454 delete [] line1;2455 delete [] line2;2456 2508 } break; 2457 2509 case Ordered: { … … 2594 2646 static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) 2595 2647 { 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); 2600 2651 } 2601 2652 … … 2746 2797 int* line2[3]; 2747 2798 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; 2757 2809 2758 2810 int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian); … … 2817 2869 dest_data += dst->bytes_per_line; 2818 2870 } 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];2828 2871 } else { // OrderedDither 2829 2872 for (int y = 0; y < src->height; y++) { … … 2858 2901 Q_ASSERT(dst->colortable.size() > trans); 2859 2902 dst->colortable[trans] = 0; 2860 Q ImageData *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); 2862 2905 uchar *dst_data = dst->data; 2863 2906 const uchar *mask_data = mask->data; … … 2871 2914 } 2872 2915 dst->has_alpha_clut = true; 2873 delete mask;2874 2916 } 2875 2917 … … 2884 2926 static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) 2885 2927 { 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); 2890 2931 } 2891 2932 … … 2905 2946 2906 2947 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 } 2907 2954 2908 2955 int w = src->width; … … 3607 3654 3608 3655 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. 3609 3659 3610 3660 \sa setPixel(), valid(), {QImage#Pixel Manipulation}{Pixel … … 3666 3716 3667 3717 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 and3718 \a index_or_rgb >= colorCount() in the case of monochrome and 3669 3719 8-bit images, the result is undefined. 3670 3720 … … 3827 3877 if (d->colortable.isEmpty()) 3828 3878 return true; 3829 for (int i = 0; i < numColors(); i++)3879 for (int i = 0; i < colorCount(); i++) 3830 3880 if (!qIsGray(d->colortable.at(i))) 3831 3881 return false; … … 3854 3904 return allGray(); 3855 3905 case 8: { 3856 for (int i = 0; i < numColors(); i++)3906 for (int i = 0; i < colorCount(); i++) 3857 3907 if (d->colortable.at(i) != qRgb(i,i,i)) 3858 3908 return false; … … 3945 3995 return copy(); 3946 3996 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); 3951 3999 return img; 3952 4000 } … … 3975 4023 return QImage(); 3976 4024 3977 QTransform wm;3978 4025 qreal factor = (qreal) w / width(); 3979 wm.scale(factor, factor);4026 QTransform wm = QTransform::fromScale(factor, factor); 3980 4027 return transformed(wm, mode); 3981 4028 } … … 4004 4051 return QImage(); 4005 4052 4006 QTransform wm;4007 4053 qreal factor = (qreal) h / height(); 4008 wm.scale(factor, factor);4054 QTransform wm = QTransform::fromScale(factor, factor); 4009 4055 return transformed(wm, mode); 4010 4056 } … … 4079 4125 4080 4126 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); 4082 4129 return mask; 4083 4130 } … … 4123 4170 int h = height(); 4124 4171 QImage m(w, h, Format_MonoLSB); 4125 m.set NumColors(2);4172 m.setColorCount(2); 4126 4173 m.setColor(0, QColor(Qt::color0).rgba()); 4127 4174 m.setColor(1, QColor(Qt::color1).rgba()); … … 4275 4322 // Create result image, copy colormap 4276 4323 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 4277 4329 result.d->colortable = d->colortable; 4278 4330 result.d->has_alpha_clut = d->has_alpha_clut; … … 4625 4677 specified \a format. If \a format is not specified (which is the default), 4626 4678 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 4633 4692 QImage QImage::fromData(const uchar *data, int size, const char *format) 4634 4693 { … … 4757 4816 return s; 4758 4817 } 4759 #endif 4818 #endif // QT_NO_DATASTREAM 4760 4819 4761 4820 … … 4847 4906 4848 4907 if (d->format != Format_RGB32) { 4849 if (d->colortable != i.d->colortable)4850 return false;4851 4908 if (d->format >= Format_ARGB32) { // all bits defined 4852 4909 const int n = d->width * d->depth / 8; … … 4861 4918 } 4862 4919 } 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; 4865 4924 for (int y=0; y<h; ++y) { 4866 4925 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)]) 4868 4927 return false; 4869 4928 } … … 4994 5053 \fn void QImage::setOffset(const QPoint& offset) 4995 5054 4996 Sets the thenumber of pixels by which the image is intended to be5055 Sets the number of pixels by which the image is intended to be 4997 5056 offset by when positioning relative to other images, to \a offset. 4998 5057 … … 5252 5311 return 0; 5253 5312 5254 #ifdef QT_RASTER_IMAGEENGINE5255 5313 if (!d->paintEngine) { 5256 5314 d->paintEngine = new QRasterPaintEngine(const_cast<QImage *>(this)); 5257 5315 } 5258 #endif 5316 5259 5317 return d->paintEngine; 5260 5318 } … … 5262 5320 5263 5321 /*! 5264 \ reimp5322 \internal 5265 5323 5266 5324 Returns the size for the specified \a metric on the device. … … 5580 5638 format if the function succeeds. 5581 5639 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. 5583 5643 5584 5644 \sa alphaChannel(), {QImage#Image Transformations}{Image … … 5656 5716 5657 5717 /*! 5718 \obsolete 5719 5658 5720 Returns the alpha channel of the image as a new grayscale QImage in which 5659 5721 each pixel's red, green, and blue values are given the alpha value of the … … 5664 5726 this function on QPixmaps. 5665 5727 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 5666 5733 \sa setAlphaChannel(), hasAlphaChannel(), 5667 5734 {QPixmap#Pixmap Information}{Pixmap}, … … 5678 5745 5679 5746 QImage image(w, h, Format_Indexed8); 5680 image.set NumColors(256);5747 image.setColorCount(256); 5681 5748 5682 5749 // set up gray scale table. … … 5730 5797 channel, otherwise returns false. 5731 5798 5732 \sa alphaChannel(),{QImage#Image Information}{Image Information}5799 \sa {QImage#Image Information}{Image Information} 5733 5800 */ 5734 5801 bool QImage::hasAlphaChannel() const … … 5808 5875 static QImage rotated90(const QImage &image) { 5809 5876 QImage out(image.height(), image.width(), image.format()); 5810 if (image. numColors() > 0)5877 if (image.colorCount() > 0) 5811 5878 out.setColorTable(image.colorTable()); 5812 5879 int w = image.width(); … … 5847 5914 default: 5848 5915 for (int y=0; y<h; ++y) { 5849 if (image. numColors())5916 if (image.colorCount()) 5850 5917 for (int x=0; x<w; ++x) 5851 5918 out.setPixel(h-y-1, x, image.pixelIndex(x, y)); … … 5867 5934 static QImage rotated270(const QImage &image) { 5868 5935 QImage out(image.height(), image.width(), image.format()); 5869 if (image. numColors() > 0)5936 if (image.colorCount() > 0) 5870 5937 out.setColorTable(image.colorTable()); 5871 5938 int w = image.width(); … … 5906 5973 default: 5907 5974 for (int y=0; y<h; ++y) { 5908 if (image. numColors())5975 if (image.colorCount()) 5909 5976 for (int x=0; x<w; ++x) 5910 5977 out.setPixel(y, w-x-1, image.pixelIndex(x, y)); … … 6046 6113 // colors are left in the color table, so pick that one as transparent 6047 6114 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()); 6049 6116 } else { 6050 memset(dImage.bits(), 0, dImage. numBytes());6117 memset(dImage.bits(), 0, dImage.byteCount()); 6051 6118 } 6052 6119 break; … … 6055 6122 case 24: 6056 6123 case 32: 6057 memset(dImage.bits(), 0x00, dImage. numBytes());6124 memset(dImage.bits(), 0x00, dImage.byteCount()); 6058 6125 break; 6059 6126 } -
trunk/src/gui/image/qimage.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 166 166 167 167 int depth() const; 168 int numColors() const; 168 #ifdef QT_DEPRECATED 169 QT_DEPRECATED int numColors() const; 170 #endif 171 int colorCount() const; 169 172 170 173 QRgb color(int i) const; 171 174 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); 173 179 174 180 bool allGray() const; … … 177 183 uchar *bits(); 178 184 const uchar *bits() const; 179 int numBytes() const; 185 #ifdef QT_DEPRECATED 186 QT_DEPRECATED int numBytes() const; 187 #endif 188 int byteCount() const; 180 189 181 190 uchar *scanLine(int); … … 315 324 316 325 friend class QRasterPixmapData; 317 friend class Q DetachedPixmap;326 friend class QPixmapCacheEntry; 318 327 friend Q_GUI_EXPORT qint64 qt_image_id(const QImage &image); 319 328 friend const QVector<QRgb> *qt_image_colortable(const QImage &image); -
trunk/src/gui/image/qimage_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 64 64 QT_BEGIN_NAMESPACE 65 65 66 struct Q ImageData { // internal image data66 struct Q_GUI_EXPORT QImageData { // internal image data 67 67 QImageData(); 68 68 ~QImageData(); -
trunk/src/gui/image/qimageiohandler.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 273 273 QImageIOHandler::~QImageIOHandler() 274 274 { 275 delete d_ptr;276 275 } 277 276 -
trunk/src/gui/image/qimageiohandler.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 45 45 #include <QtCore/qplugin.h> 46 46 #include <QtCore/qfactoryinterface.h> 47 #include <QtCore/qscopedpointer.h> 47 48 48 49 QT_BEGIN_HEADER … … 110 111 protected: 111 112 QImageIOHandler(QImageIOHandlerPrivate &dd); 112 Q ImageIOHandlerPrivate *d_ptr;113 QScopedPointer<QImageIOHandlerPrivate> d_ptr; 113 114 private: 114 115 Q_DISABLE_COPY(QImageIOHandler) -
trunk/src/gui/image/qimagereader.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 48 48 49 49 \reentrant 50 \ingroup multimedia50 \ingroup painting 51 51 \ingroup io 52 52 … … 196 196 197 197 static QImageIOHandler *createReadHandlerHelper(QIODevice *device, 198 const QByteArray &format, bool autoDetectImageFormat) 198 const QByteArray &format, 199 bool autoDetectImageFormat, 200 bool ignoresFormatAndExtension) 199 201 { 200 202 if (!autoDetectImageFormat && format.isEmpty()) … … 218 220 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) 219 221 int suffixPluginIndex = -1; 220 if (device && format.isEmpty() && autoDetectImageFormat ) {222 if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) { 221 223 // if there's no format, see if \a device is a file, and if so, find 222 224 // the file suffix and find support for that format among our plugins. … … 241 243 242 244 QByteArray testFormat = !form.isEmpty() ? form : suffix; 245 246 if (ignoresFormatAndExtension) 247 testFormat = QByteArray(); 243 248 244 249 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) … … 259 264 } 260 265 261 if (!handler && !testFormat.isEmpty() && autoDetectImageFormat ) {266 if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) { 262 267 // check if any plugin supports the format (they are not allowed to 263 268 // read from the device yet). … … 316 321 317 322 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) 318 if (!handler && autoDetectImageFormat) {323 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) { 319 324 // check if any of our plugins recognize the file from its contents. 320 325 const qint64 pos = device ? device->pos() : 0; … … 336 341 #endif 337 342 338 if (!handler && autoDetectImageFormat) {343 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) { 339 344 // check if any of our built-in handlers recognize the file from its 340 345 // contents. … … 435 440 QByteArray format; 436 441 bool autoDetectImageFormat; 442 bool ignoresFormatAndExtension; 437 443 QIODevice *device; 438 444 bool deleteDevice; … … 459 465 */ 460 466 QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq) 461 : autoDetectImageFormat(true) 467 : autoDetectImageFormat(true), ignoresFormatAndExtension(false) 462 468 { 463 469 device = 0; … … 466 472 quality = -1; 467 473 imageReaderError = QImageReader::UnknownError; 468 errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error"));469 474 470 475 q = qq; … … 523 528 524 529 // assign a handler 525 if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat )) == 0) {530 if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) { 526 531 imageReaderError = QImageReader::UnsupportedFormatError; 527 532 errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format")); … … 665 670 when trying to read the image. 666 671 667 \endlist 672 \endlist 668 673 669 674 By disabling image format autodetection, QImageReader will only query the … … 682 687 reader; otherwise returns false. By default, autodetection is enabled. 683 688 684 \sa setAutoDetectImageFormat() 689 \sa setAutoDetectImageFormat() 685 690 */ 686 691 bool QImageReader::autoDetectImageFormat() const … … 688 693 return d->autoDetectImageFormat; 689 694 } 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 711 void 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 725 bool QImageReader::decideFormatFromContent() const 726 { 727 return d->ignoresFormatAndExtension; 728 } 729 690 730 691 731 /*! … … 1174 1214 1175 1215 /*! 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() 1181 1222 */ 1182 1223 int QImageReader::loopCount() const … … 1188 1229 1189 1230 /*! 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() 1197 1238 */ 1198 1239 int QImageReader::imageCount() const … … 1204 1245 1205 1246 /*! 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() 1211 1254 */ 1212 1255 int QImageReader::nextImageDelay() const … … 1218 1261 1219 1262 /*! 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() 1225 1270 */ 1226 1271 int QImageReader::currentImageNumber() const … … 1262 1307 QString QImageReader::errorString() const 1263 1308 { 1309 if (d->errorString.isEmpty()) 1310 return QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error")); 1264 1311 return d->errorString; 1265 1312 } … … 1310 1357 { 1311 1358 QByteArray format; 1312 QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true );1359 QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true, false); 1313 1360 if (handler) { 1314 1361 if (handler->canRead()) … … 1338 1385 \row \o XBM \o X11 Bitmap 1339 1386 \row \o XPM \o X11 Pixmap 1387 \row \o SVG \o Scalable Vector Graphics 1340 1388 \endtable 1341 1389 -
trunk/src/gui/image/qimagereader.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 81 81 void setAutoDetectImageFormat(bool enabled); 82 82 bool autoDetectImageFormat() const; 83 84 void setDecideFormatFromContent(bool ignored); 85 bool decideFormatFromContent() const; 83 86 84 87 void setDevice(QIODevice *device); -
trunk/src/gui/image/qimagewriter.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 46 46 47 47 \reentrant 48 \ingroup multimedia48 \ingroup painting 49 49 \ingroup io 50 50 -
trunk/src/gui/image/qimagewriter.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qmovie.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 46 46 with QImageReader. 47 47 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. 49 53 50 54 First, create a QMovie object by passing either the name of a file or a … … 357 361 else 358 362 reader = new QImageReader(absoluteFilePath, format); 359 reader->canRead(); // Provoke a device->open() call363 (void)reader->canRead(); // Provoke a device->open() call 360 364 reader->device()->seek(initialDevicePos); 361 365 reader->setBackgroundColor(bgColor); -
trunk/src/gui/image/qmovie.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qnativeimage.cpp
r115 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 51 51 #include <sys/shm.h> 52 52 #include <qwidget.h> 53 #endif 54 55 #ifdef Q_WS_MAC 56 #include <private/qpaintengine_mac_p.h> 53 57 #endif 54 58 … … 66 70 QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool isTextBuffer, QWidget *) 67 71 { 68 #ifndef Q_ OS_WINCE72 #ifndef Q_WS_WINCE 69 73 Q_UNUSED(isTextBuffer); 70 74 #endif … … 79 83 if (format == QImage::Format_RGB16) { 80 84 bmi.bmiHeader.biBitCount = 16; 81 #ifdef Q_ OS_WINCE85 #ifdef Q_WS_WINCE 82 86 if (isTextBuffer) { 83 87 bmi.bmiHeader.biCompression = BI_RGB; … … 117 121 static_cast<QRasterPaintEngine *>(image.paintEngine())->setDC(hdc); 118 122 119 #ifndef Q_ OS_WINCE123 #ifndef Q_WS_WINCE 120 124 GdiFlush(); 121 125 #endif … … 164 168 165 169 QNativeImage::QNativeImage(int width, int height, QImage::Format format,bool /* isTextBuffer */, QWidget *widget) 170 : xshmimg(0), xshmpm(0) 166 171 { 167 172 if (!X11->use_mitshm) { 168 xshmimg = 0;169 xshmpm = 0;170 173 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; 171 179 return; 172 180 } … … 190 198 xshmimg->data = (char*)shmat(xshminfo.shmid, 0, 0); 191 199 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"; 192 202 ok = (xshminfo.shmaddr != (char*)-1); 193 203 if (ok) … … 211 221 return; 212 222 } 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 } 217 229 } 218 230 } … … 245 257 #elif defined(Q_WS_MAC) 246 258 247 QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget * )259 QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget *widget) 248 260 : image(width, height, format) 249 261 { 250 cgColorSpace = CGColorSpaceCreateDeviceRGB(); 262 263 251 264 uint cgflags = kCGImageAlphaNoneSkipFirst; 252 265 253 266 #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); 259 272 CGContextTranslateCTM(cg, 0, height); 260 273 CGContextScaleCTM(cg, 1, -1); … … 268 281 { 269 282 CGContextRelease(cg); 270 CGColorSpaceRelease(cgColorSpace);271 283 } 272 284 -
trunk/src/gui/image/qnativeimage_p.h
r115 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 71 71 class QWidget; 72 72 73 class Q _GUI_EXPORT QNativeImage73 class QNativeImage 74 74 { 75 75 public: … … 96 96 #elif defined(Q_WS_MAC) 97 97 CGContextRef cg; 98 CGColorSpaceRef cgColorSpace;99 98 #endif 100 99 -
trunk/src/gui/image/qpaintengine_pic.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qpaintengine_pic_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qpicture.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 70 70 replays QPainter commands. 71 71 72 \ingroup multimedia72 \ingroup painting 73 73 \ingroup shared 74 \mainclass 74 75 75 76 76 A picture serializes painter commands to an IO device in a … … 132 132 { 133 133 Q_D(QPicture); 134 d_ptr->q_ptr = this;135 d->paintEngine = 0;136 134 137 135 if (formatVersion == 0) … … 143 141 d->formatMinor = 0; 144 142 d->formatOk = false; 145 } 146 else { 143 } else { 147 144 d->resetFormat(); 148 145 } … … 158 155 : QPaintDevice(), d_ptr(pic.d_ptr) 159 156 { 160 d_func()->ref.ref();161 157 } 162 158 … … 166 162 d_ptr(&dptr) 167 163 { 168 d_ptr->q_ptr = this;169 164 } 170 165 … … 174 169 QPicture::~QPicture() 175 170 { 176 if (!d_func()->ref.deref()) {177 delete d_func()->paintEngine;178 delete d_func();179 }180 171 } 181 172 … … 231 222 void QPicture::detach() 232 223 { 233 if (d_func()->ref != 1) 234 detach_helper(); 224 d_ptr.detach(); 235 225 } 236 226 … … 955 945 956 946 /*! 947 \internal 948 957 949 Internal implementation of the virtual QPaintDevice::metric() 958 950 function. … … 1016 1008 \internal 1017 1009 */ 1010 1011 /*! \internal 1012 ### Qt 5 - remove me 1013 */ 1018 1014 void QPicture::detach_helper() 1019 1015 { 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"); 1036 1020 } 1037 1021 … … 1042 1026 QPicture& QPicture::operator=(const QPicture &p) 1043 1027 { 1044 qAtomicAssign<QPicturePrivate>(d_ptr, p.d_ptr);1028 d_ptr = p.d_ptr; 1045 1029 return *this; 1030 } 1031 1032 /*! 1033 \internal 1034 1035 Constructs a QPicturePrivate 1036 */ 1037 QPicturePrivate::QPicturePrivate() 1038 : in_memory_only(false) 1039 { 1040 } 1041 1042 /*! 1043 \internal 1044 1045 Copy-Constructs a QPicturePrivate. Needed when detaching. 1046 */ 1047 QPicturePrivate::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 } 1046 1060 } 1047 1061 … … 1136 1150 { 1137 1151 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(); 1140 1154 } 1141 1155 … … 1144 1158 *****************************************************************************/ 1145 1159 1160 #ifndef QT_NO_DATASTREAM 1146 1161 /*! 1147 1162 \relates QPicture … … 1189 1204 return s; 1190 1205 } 1206 #endif // QT_NO_DATASTREAM 1191 1207 1192 1208 … … 1295 1311 saving pictures. 1296 1312 1297 \ingroup multimedia1313 \ingroup painting 1298 1314 \ingroup io 1299 1315 -
trunk/src/gui/image/qpicture.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 43 43 #define QPICTURE_H 44 44 45 #include <QtCore/qstringlist.h> 46 #include <QtCore/qsharedpointer.h> 45 47 #include <QtGui/qpaintdevice.h> 46 #include <QtCore/qstringlist.h>47 48 48 49 QT_BEGIN_HEADER … … 107 108 void detach_helper(); 108 109 109 Q PicturePrivate *d_ptr;110 QExplicitlySharedDataPointer<QPicturePrivate> d_ptr; 110 111 friend class QPicturePaintEngine; 111 112 friend class Q3Picture; … … 114 115 115 116 public: 116 typedef Q PicturePrivate*DataPtr;117 typedef QExplicitlySharedDataPointer<QPicturePrivate> DataPtr; 117 118 inline DataPtr &data_ptr() { return d_ptr; } 118 119 }; … … 185 186 *****************************************************************************/ 186 187 188 #ifndef QT_NO_DATASTREAM 187 189 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPicture &); 188 190 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPicture &); 191 #endif 189 192 190 193 #endif // QT_NO_PICTURE -
trunk/src/gui/image/qpicture_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 70 70 extern const char *qt_mfhdr_tag; 71 71 72 class Q _GUI_EXPORT QPicturePrivate72 class QPicturePrivate 73 73 { 74 Q_DECLARE_PUBLIC(QPicture)75 74 friend class QPicturePaintEngine; 76 75 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPicture &r); … … 144 143 }; 145 144 146 inline QPicturePrivate() : in_memory_only(false), q_ptr(0) { ref = 1; } 145 QPicturePrivate(); 146 QPicturePrivate(const QPicturePrivate &other); 147 147 QAtomicInt ref; 148 148 … … 157 157 QRect brect; 158 158 QRect override_rect; 159 Q PaintEngine *paintEngine;159 QScopedPointer<QPaintEngine> paintEngine; 160 160 bool in_memory_only; 161 161 QList<QImage> image_list; … … 163 163 QList<QBrush> brush_list; 164 164 QList<QPen> pen_list; 165 166 QPicture *q_ptr;167 165 }; 168 166 -
trunk/src/gui/image/qpictureformatplugin.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qpictureformatplugin.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qpixmap.cpp
r95 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 44 44 #include "qpixmap.h" 45 45 #include "qpixmapdata_p.h" 46 #include "qimagepixmapcleanuphooks_p.h" 46 47 47 48 #include "qbitmap.h" … … 77 78 #endif 78 79 80 #if defined(Q_OS_SYMBIAN) 81 # include <private/qt_s60_p.h> 82 #endif 83 79 84 #include "qpixmap_raster_p.h" 80 85 81 86 QT_BEGIN_NAMESPACE 82 83 // ### Qt 5: remove84 typedef void (*_qt_pixmap_cleanup_hook)(int);85 Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;86 87 // ### Qt 5: rename88 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);89 Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;90 87 91 88 // ### Qt 5: remove … … 117 114 void QPixmap::init(int w, int h, int type) 118 115 { 119 QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); 120 if (gs) 121 data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type)); 116 if ((w > 0 && h > 0) || type == QPixmapData::BitmapType) 117 data = QPixmapData::create(w, h, (QPixmapData::PixelType) type); 122 118 else 123 data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type)); 124 125 data->resize(w, h); 126 data->ref.ref(); 119 data = 0; 127 120 } 128 121 … … 226 219 : QPaintDevice(), data(d) 227 220 { 228 data->ref.ref();229 221 } 230 222 … … 282 274 } 283 275 if (pixmap.paintingActive()) { // make a deep copy 284 data = 0;285 276 operator=(pixmap.copy()); 286 277 } else { 287 278 data = pixmap.data; 288 data->ref.ref();289 279 } 290 280 } … … 315 305 QImage image(xpm); 316 306 if (!image.isNull()) { 317 if (data ->pixelType() == QPixmapData::BitmapType)307 if (data && data->pixelType() == QPixmapData::BitmapType) 318 308 *this = QBitmap::fromImage(image); 319 309 else … … 330 320 QPixmap::~QPixmap() 331 321 { 332 deref(); 322 Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again 323 if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns 324 QImagePixmapCleanupHooks::executePixmapDestructionHooks(this); 333 325 } 334 326 … … 366 358 return QPixmap(); 367 359 368 const QRect r = rect.isEmpty() ? QRect(0, 0, width(), height()) : rect; 369 370 QPixmapData *d; 371 QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); 372 if (gs) 373 d = gs->createPixmapData(data->pixelType()); 374 else 375 d = QGraphicsSystem::createDefaultPixmapData(data->pixelType()); 376 377 d->copy(data, r); 360 QRect r(0, 0, width(), height()); 361 if (!rect.isEmpty()) 362 r = r.intersected(rect); 363 364 QPixmapData *d = data->createCompatiblePixmapData(); 365 d->copy(data.data(), r); 378 366 return QPixmap(d); 367 } 368 369 /*! 370 \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed) 371 \since 4.6 372 373 This convenience function is equivalent to calling QPixmap::scroll(\a dx, 374 \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed). 375 376 \sa QWidget::scroll(), QGraphicsItem::scroll() 377 */ 378 379 /*! 380 \since 4.6 381 382 Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed 383 region is left unchanged. You can optionally pass a pointer to an empty 384 QRegion to get the region that is \a exposed by the scroll operation. 385 386 \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2 387 388 You cannot scroll while there is an active painter on the pixmap. 389 390 \sa QWidget::scroll(), QGraphicsItem::scroll() 391 */ 392 void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed) 393 { 394 if (isNull() || (dx == 0 && dy == 0)) 395 return; 396 QRect dest = rect & this->rect(); 397 QRect src = dest.translated(-dx, -dy) & dest; 398 if (src.isEmpty()) { 399 if (exposed) 400 *exposed += dest; 401 return; 402 } 403 404 detach(); 405 406 if (!data->scroll(dx, dy, src)) { 407 // Fallback 408 QPixmap pix = *this; 409 QPainter painter(&pix); 410 painter.setCompositionMode(QPainter::CompositionMode_Source); 411 painter.drawPixmap(src.translated(dx, dy), *this, src); 412 painter.end(); 413 *this = pix; 414 } 415 416 if (exposed) { 417 *exposed += dest; 418 *exposed -= src.translated(dx, dy); 419 } 379 420 } 380 421 … … 395 436 *this = pixmap.copy(); 396 437 } else { 397 pixmap.data->ref.ref(); // avoid 'x = x'398 deref();399 438 data = pixmap.data; 400 439 } … … 431 470 432 471 If the pixmap has 1-bit depth, the returned image will also be 1 433 bit deep. If the pixmap has 2- to 8-bit depth, the returned image 434 has 8-bit depth. If the pixmap has greater than 8-bit depth, the 435 returned image has 32-bit depth. 472 bit deep. Images with more bits will be returned in a format 473 closely represents the underlying system. Usually this will be 474 QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and 475 QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without 476 alpha. 436 477 437 478 Note that for the moment, alpha masks on monochrome images are … … 503 544 bool QPixmap::isNull() const 504 545 { 505 return data->width() == 0;546 return !data || data->isNull(); 506 547 } 507 548 … … 515 556 int QPixmap::width() const 516 557 { 517 return data ->width();558 return data ? data->width() : 0; 518 559 } 519 560 … … 527 568 int QPixmap::height() const 528 569 { 529 return data ->height();570 return data ? data->height() : 0; 530 571 } 531 572 … … 540 581 QSize QPixmap::size() const 541 582 { 542 return QSize(data->width(), data->height());583 return data ? QSize(data->width(), data->height()) : QSize(); 543 584 } 544 585 … … 552 593 QRect QPixmap::rect() const 553 594 { 554 return QRect(0, 0, data->width(), data->height());595 return data ? QRect(0, 0, data->width(), data->height()) : QRect(); 555 596 } 556 597 … … 568 609 int QPixmap::depth() const 569 610 { 570 return data ->depth();611 return data ? data->depth() : 0; 571 612 } 572 613 … … 598 639 599 640 // Create new pixmap 600 QPixmap pm(QSize(w, h), data ->type);641 QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType); 601 642 bool uninit = false; 602 643 #if defined(Q_WS_X11) 603 QX11PixmapData *x11Data = data ->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data) : 0;644 QX11PixmapData *x11Data = data && data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0; 604 645 if (x11Data) { 605 646 pm.x11SetScreen(x11Data->xinfo.screen()); 606 uninit = x11Data-> uninit;647 uninit = x11Data->flags & QX11PixmapData::Uninitialized; 607 648 } 608 649 #elif defined(Q_WS_MAC) 609 QMacPixmapData *macData = data ->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data) : 0;650 QMacPixmapData *macData = data && data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; 610 651 if (macData) 611 652 uninit = macData->uninit; … … 619 660 } 620 661 621 #if defined(Q_WS_MAC) 622 #ifndef QT_MAC_NO_QUICKDRAW 623 if(macData && macData->qd_alpha) 624 macData->macQDUpdateAlpha(); 625 #endif 626 #elif defined(Q_WS_X11) 662 #if defined(Q_WS_X11) 627 663 if (x11Data && x11Data->x11_mask) { 628 QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data );664 QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data()); 629 665 pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, 630 666 RootWindow(x11Data->xinfo.display(), … … 675 711 being painted on. 676 712 677 This is potentially an expensive operation.713 \warning This is potentially an expensive operation. 678 714 679 715 \sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations}, … … 691 727 return; 692 728 } 729 730 if (isNull()) 731 return; 693 732 694 733 if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask … … 790 829 QFileInfo info(fileName); 791 830 QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') + 792 QString::number(info.size()) + QLatin1Char('_') + QString::number(data->pixelType());831 QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType); 793 832 794 833 if (QPixmapCache::find(key, *this)) 795 834 return true; 796 835 797 QImage image = QImageReader(fileName, format).read(); 798 if (image.isNull()) 799 return false; 800 QPixmap pm; 801 if (data->pixelType() == QPixmapData::BitmapType) 802 pm = QBitmap::fromImage(image, flags); 803 else 804 pm = fromImage(image, flags); 805 if (!pm.isNull()) { 806 *this = pm; 836 QPixmapData *tmp = QPixmapData::create(0, 0, QPixmapData::PixmapType); 837 if (tmp->fromFile(fileName, format, flags)) { 838 data = tmp; 807 839 QPixmapCache::insert(key, *this); 808 840 return true; 809 841 } 842 delete tmp; 810 843 return false; 811 844 } … … 832 865 bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) 833 866 { 834 QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len); 835 QBuffer b(&a); 836 b.open(QIODevice::ReadOnly); 837 838 QImage image = QImageReader(&b, format).read(); 839 QPixmap pm; 840 if (data->pixelType() == QPixmapData::BitmapType) 841 pm = QBitmap::fromImage(image, flags); 842 else 843 pm = fromImage(image, flags); 844 if (!pm.isNull()) { 845 *this = pm; 846 return true; 847 } 848 return false; 867 if (len == 0 || buf == 0) 868 return false; 869 870 if (!data) 871 data = QPixmapData::create(0, 0, QPixmapData::PixmapType); 872 873 return data->fromData(buf, len, format, flags); 849 874 } 850 875 … … 930 955 Fills the pixmap with the given \a color. 931 956 957 The effect of this function is undefined when the pixmap is 958 being painted on. 959 932 960 \sa {QPixmap#Pixmap Transformations}{Pixmap Transformations} 933 961 */ … … 938 966 return; 939 967 940 detach(); 968 // Some people are probably already calling fill while a painter is active, so to not break 969 // their programs, only print a warning and return when the fill operation could cause a crash. 970 if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) { 971 qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on"); 972 return; 973 } 974 975 if (data->ref == 1) { 976 // detach() will also remove this pixmap from caches, so 977 // it has to be called even when ref == 1. 978 detach(); 979 } else { 980 // Don't bother to make a copy of the data object, since 981 // it will be filled with new pixel data anyway. 982 QPixmapData *d = data->createCompatiblePixmapData(); 983 d->resize(data->width(), data->height()); 984 data = d; 985 } 941 986 data->fill(color); 942 987 } … … 971 1016 qint64 QPixmap::cacheKey() const 972 1017 { 1018 if (isNull()) 1019 return 0; 1020 973 1021 int classKey = data->classId(); 974 1022 if (classKey >= 1024) … … 1119 1167 { 1120 1168 #if defined(Q_WS_X11) 1121 if (data ->classId() == QPixmapData::X11Class)1122 return static_cast< QX11PixmapData*>(data)->handle();1169 if (data && data->classId() == QPixmapData::X11Class) 1170 return static_cast<const QX11PixmapData*>(data.constData())->handle(); 1123 1171 #endif 1124 1172 return 0; … … 1170 1218 return; 1171 1219 1172 if (data ->pixelType() == QPixmapData::BitmapType)1220 if (data && data->pixelType() == QPixmapData::BitmapType) 1173 1221 *this = QBitmap::fromImage(image); 1174 1222 else … … 1187 1235 QPixmap &QPixmap::operator=(const QImage &image) 1188 1236 { 1189 if (data ->pixelType() == QPixmapData::BitmapType)1237 if (data && data->pixelType() == QPixmapData::BitmapType) 1190 1238 *this = QBitmap::fromImage(image); 1191 1239 else … … 1217 1265 bool QPixmap::convertFromImage(const QImage &image, ColorMode mode) 1218 1266 { 1219 if (data ->pixelType() == QPixmapData::BitmapType)1267 if (data && data->pixelType() == QPixmapData::BitmapType) 1220 1268 *this = QBitmap::fromImage(image, colorModeToFlags(mode)); 1221 1269 else … … 1233 1281 \relates QPixmap 1234 1282 1235 Writes the given \a pixmap to the thegiven \a stream as a PNG1283 Writes the given \a pixmap to the given \a stream as a PNG 1236 1284 image. Note that writing the stream to a file will not produce a 1237 1285 valid image file. … … 1268 1316 } 1269 1317 1270 #endif // QT_NO_DATASTREAM1318 #endif // QT_NO_DATASTREAM 1271 1319 1272 1320 #ifdef QT3_SUPPORT … … 1304 1352 bool QPixmap::isDetached() const 1305 1353 { 1306 return data->ref == 1; 1307 } 1308 1354 return data && data->ref == 1; 1355 } 1356 1357 /*! \internal 1358 ### Qt5 - remove me. 1359 */ 1309 1360 void QPixmap::deref() 1310 1361 { 1311 if (data && !data->ref.deref()) { // Destroy image if last ref 1312 #if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN) 1313 if (data->classId() == QPixmapData::RasterClass) { 1314 QRasterPixmapData *rData = static_cast<QRasterPixmapData*>(data); 1315 if (rData->texture) 1316 rData->texture->Release(); 1317 rData->texture = 0; 1318 } 1319 #endif 1320 if (data->is_cached && qt_pixmap_cleanup_hook_64) 1321 qt_pixmap_cleanup_hook_64(cacheKey()); 1322 delete data; 1323 data = 0; 1324 } 1362 Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!"); 1325 1363 } 1326 1364 … … 1381 1419 pixmap. 1382 1420 1421 1422 In some cases it can be more beneficial to draw the pixmap to a 1423 painter with a scale set rather than scaling the pixmap. This is 1424 the case when the painter is for instance based on OpenGL or when 1425 the scale factor changes rapidly. 1426 1383 1427 \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap 1384 1428 Transformations} … … 1399 1443 return *this; 1400 1444 1401 QPixmap pix; 1402 QTransform wm; 1403 wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); 1404 pix = transformed(wm, mode); 1445 QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), 1446 (qreal)newSize.height() / height()); 1447 QPixmap pix = transformed(wm, mode); 1405 1448 return pix; 1406 1449 } … … 1429 1472 return QPixmap(); 1430 1473 1431 QTransform wm;1432 1474 qreal factor = (qreal) w / width(); 1433 wm.scale(factor, factor);1475 QTransform wm = QTransform::fromScale(factor, factor); 1434 1476 return transformed(wm, mode); 1435 1477 } … … 1458 1500 return QPixmap(); 1459 1501 1460 QTransform wm;1461 1502 qreal factor = (qreal) h / height(); 1462 wm.scale(factor, factor);1503 QTransform wm = QTransform::fromScale(factor, factor); 1463 1504 return transformed(wm, mode); 1464 1505 } … … 1515 1556 that can be used as a paint device. 1516 1557 1517 \ingroup multimedia1558 \ingroup painting 1518 1559 \ingroup shared 1519 \mainclass 1560 1520 1561 1521 1562 Qt provides four classes for handling image data: QImage, QPixmap, … … 1525 1566 only a convenience class that inherits QPixmap, ensuring a depth 1526 1567 of 1. The isQBitmap() function returns true if a QPixmap object is 1527 really a bitmap, otherwise returns false. Finally, the QPicture class is a1528 paint device that records and replays QPainter commands.1568 really a bitmap, otherwise returns false. Finally, the QPicture class 1569 is a paint device that records and replays QPainter commands. 1529 1570 1530 1571 A QPixmap can easily be displayed on the screen using QLabel or 1531 1572 one of QAbstractButton's subclasses (such as QPushButton and 1532 1573 QToolButton). QLabel has a pixmap property, whereas 1533 QAbstractButton has an icon property. And because QPixmap is a 1534 QPaintDevice subclass, QPainter can be used to draw directly onto 1535 pixmaps. 1574 QAbstractButton has an icon property. 1536 1575 1537 1576 In addition to the ordinary constructors, a QPixmap can be 1538 1577 constructed using the static grabWidget() and grabWindow() 1539 1578 functions which creates a QPixmap and paints the given widget, or 1540 window, in it. 1541 1542 Note that the pixel data in a pixmap is internal and is managed by 1543 the underlying window system. Pixels can only be accessed through 1544 QPainter functions or by converting the QPixmap to a QImage. 1579 window, into it. 1580 1581 QPixmap objects can be passed around by value since the QPixmap 1582 class uses implicit data sharing. For more information, see the \l 1583 {Implicit Data Sharing} documentation. QPixmap objects can also be 1584 streamed. 1585 1545 1586 Depending on the system, QPixmap is stored using a RGB32 or a 1546 1587 premultiplied alpha format. If the image has an alpha channel, and 1547 1588 if the system allows, the preferred format is premultiplied alpha. 1548 1589 Note also that QPixmap, unlike QImage, may be hardware dependent. 1549 On X11 and Mac, a QPixmap is stored on the server side while a1550 QImage is stored on the client side (on Windows, these two classes1590 On X11, Mac and Symbian, a QPixmap is stored on the server side while 1591 a QImage is stored on the client side (on Windows, these two classes 1551 1592 have an equivalent internal representation, i.e. both QImage and 1552 1593 QPixmap are stored on the client side and don't use any GDI 1553 1594 resources). 1595 1596 Note that the pixel data in a pixmap is internal and is managed by 1597 the underlying window system. Because QPixmap is a QPaintDevice 1598 subclass, QPainter can be used to draw directly onto pixmaps. 1599 Pixels can only be accessed through QPainter functions or by 1600 converting the QPixmap to a QImage. However, the fill() function 1601 is available for initializing the entire pixmap with a given color. 1554 1602 1555 1603 There are functions to convert between QImage and … … 1560 1608 file can be loaded directly into a QPixmap. On Windows, the 1561 1609 QPixmap class also supports conversion between \c HBITMAP and 1562 QPixmap. 1610 QPixmap. On Symbian, the QPixmap class also supports conversion 1611 between CFbsBitmap and QPixmap. 1563 1612 1564 1613 QPixmap provides a collection of functions that can be used to … … 1566 1615 there are several functions that enables transformation of the 1567 1616 pixmap. 1568 1569 QPixmap objects can be passed around by value since the QPixmap1570 class uses implicit data sharing. For more information, see the \l1571 {Implicit Data Sharing} documentation. QPixmap objects can also be1572 streamed.1573 1617 1574 1618 \tableofcontents … … 1628 1672 respects the alpha channel, otherwise returns false, while the 1629 1673 hasAlpha() function returns true if the pixmap has an alpha 1630 channel \e or a mask (otherwise false). 1631 1632 The alphaChannel() function returns the alpha channel as a new 1633 QPixmap object, while the mask() function returns the mask as a 1634 QBitmap object. The alpha channel and mask can be set using the 1635 setAlphaChannel() and setMask() functions, respectively. 1636 1637 \row 1638 \o Low-level information 1639 \o 1640 1641 The depth() function returns the depth of the pixmap. The 1642 defaultDepth() function returns the default depth, i.e. the depth 1643 used by the application on the given screen. 1644 1645 The cacheKey() function returns a number that uniquely 1646 identifies the contents of the QPixmap object. 1647 1648 The x11Info() function returns information about the configuration 1649 of the X display used to display the widget. The 1650 x11PictureHandle() function returns the X11 Picture handle of the 1651 pixmap for XRender support. Note that the two latter functions are 1652 only available on x11. 1653 1654 \endtable 1655 1656 \section1 Pixmap Conversion 1657 1658 A QPixmap object can be converted into a QImage using the 1659 toImage() function. Likewise, a QImage can be converted into a 1660 QPixmap using the fromImage(). If this is too expensive an 1661 operation, you can use QBitmap::fromImage() instead. 1662 1663 In addition, on Windows, the QPixmap class supports conversion to 1664 and from HBitmap: the toWinHBITMAP() function creates a HBITMAP 1665 equivalent to the QPixmap, based on the given HBitmapFormat, and 1666 returns the HBITMAP handle. The fromWinHBITMAP() function returns 1667 a QPixmap that is equivalent to the given bitmap which has the 1668 specified format. 1669 1670 \section1 Pixmap Transformations 1671 1672 QPixmap supports a number of functions for creating a new pixmap 1673 that is a transformed version of the original: The 1674 createHeuristicMask() function creates and returns a 1-bpp 1674 channel \e or a mask (otherwise false). The mask() function returns 1675 the mask as a QBitmap object, which can be set using setMask(). 1676 1677 The createHeuristicMask() function creates and returns a 1-bpp 1675 1678 heuristic mask (i.e. a QBitmap) for this pixmap. It works by 1676 1679 selecting a color from one of the corners and then chipping away … … 1679 1682 QBitmap) for the pixmap based on a given color. 1680 1683 1684 \row 1685 \o Low-level information 1686 \o 1687 1688 The depth() function returns the depth of the pixmap. The 1689 defaultDepth() function returns the default depth, i.e. the depth 1690 used by the application on the given screen. 1691 1692 The cacheKey() function returns a number that uniquely 1693 identifies the contents of the QPixmap object. 1694 1695 The x11Info() function returns information about the configuration 1696 of the X display used by the screen to which the pixmap currently 1697 belongs. The x11PictureHandle() function returns the X11 Picture 1698 handle of the pixmap for XRender support. Note that the two latter 1699 functions are only available on x11. 1700 1701 \endtable 1702 1703 \section1 Pixmap Conversion 1704 1705 A QPixmap object can be converted into a QImage using the 1706 toImage() function. Likewise, a QImage can be converted into a 1707 QPixmap using the fromImage(). If this is too expensive an 1708 operation, you can use QBitmap::fromImage() instead. 1709 1710 In addition, on Windows, the QPixmap class supports conversion to 1711 and from HBITMAP: the toWinHBITMAP() function creates a HBITMAP 1712 equivalent to the QPixmap, based on the given HBitmapFormat, and 1713 returns the HBITMAP handle. The fromWinHBITMAP() function returns 1714 a QPixmap that is equivalent to the given bitmap which has the 1715 specified format. The QPixmap class also supports conversion to 1716 and from HICON: the toWinHICON() function creates a HICON equivalent 1717 to the QPixmap, and returns the HICON handle. The fromWinHICON() 1718 function returns a QPixmap that is equivalent to the given icon. 1719 1720 In addition, on Symbian, the QPixmap class supports conversion to 1721 and from CFbsBitmap: the toSymbianCFbsBitmap() function creates 1722 CFbsBitmap equivalent to the QPixmap, based on given mode and returns 1723 a CFbsBitmap object. The fromSymbianCFbsBitmap() function returns a 1724 QPixmap that is equivalent to the given bitmap and given mode. 1725 1726 \section1 Pixmap Transformations 1727 1728 QPixmap supports a number of functions for creating a new pixmap 1729 that is a transformed version of the original: 1681 1730 1682 1731 The scaled(), scaledToWidth() and scaledToHeight() functions … … 1693 1742 pixmap. 1694 1743 1695 There are also functions for changing attributes of a pixmap.1696 in-place: The fill() function fills the entire image with the1697 given color, the setMask() function sets a mask bitmap, and the1698 setAlphaChannel() function sets the pixmap's alpha channel.1699 1700 1744 \sa QBitmap, QImage, QImageReader, QImageWriter 1701 1745 */ … … 1716 1760 mask, otherwise returns false. 1717 1761 1718 \sa hasAlphaChannel(), alphaChannel(),mask()1762 \sa hasAlphaChannel(), mask() 1719 1763 */ 1720 1764 bool QPixmap::hasAlpha() const 1721 1765 { 1722 return (data->hasAlphaChannel() || !data->mask().isNull());1766 return data && (data->hasAlphaChannel() || !data->mask().isNull()); 1723 1767 } 1724 1768 … … 1727 1771 channel, otherwise returns false. 1728 1772 1729 \sa alphaChannel(),hasAlpha()1773 \sa hasAlpha() 1730 1774 */ 1731 1775 bool QPixmap::hasAlphaChannel() const 1732 1776 { 1733 return data ->hasAlphaChannel();1734 } 1735 1736 /*! 1737 \reimp1777 return data && data->hasAlphaChannel(); 1778 } 1779 1780 /*! 1781 \internal 1738 1782 */ 1739 1783 int QPixmap::metric(PaintDeviceMetric metric) const 1740 1784 { 1741 return data ->metric(metric);1785 return data ? data->metric(metric) : 0; 1742 1786 } 1743 1787 1744 1788 /*! 1745 1789 \fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) 1790 \obsolete 1746 1791 1747 1792 Sets the alpha channel of this pixmap to the given \a alphaChannel … … 1751 1796 The effect of this function is undefined when the pixmap is being 1752 1797 painted on. 1798 1799 \warning This is potentially an expensive operation. Most usecases 1800 for this function are covered by QPainter and compositionModes 1801 which will normally execute faster. 1753 1802 1754 1803 \sa alphaChannel(), {QPixmap#Pixmap Transformations}{Pixmap … … 1777 1826 1778 1827 /*! 1828 \obsolete 1829 1779 1830 Returns the alpha channel of the pixmap as a new grayscale QPixmap in which 1780 1831 each pixel's red, green, and blue values are given the alpha value of the … … 1794 1845 \image alphachannelimage.png The pixmap and channelImage QPixmaps 1795 1846 1847 \warning This is an expensive operation. The alpha channel of the 1848 pixmap is extracted dynamically from the pixeldata. Most usecases of this 1849 function are covered by QPainter and compositionModes which will normally 1850 execute faster. 1851 1796 1852 \sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap 1797 1853 Information} … … 1799 1855 QPixmap QPixmap::alphaChannel() const 1800 1856 { 1801 return data ->alphaChannel();1802 } 1803 1804 /*! 1805 \reimp1857 return data ? data->alphaChannel() : QPixmap(); 1858 } 1859 1860 /*! 1861 \internal 1806 1862 */ 1807 1863 QPaintEngine *QPixmap::paintEngine() const 1808 1864 { 1809 return data ->paintEngine();1865 return data ? data->paintEngine() : 0; 1810 1866 } 1811 1867 … … 1813 1869 \fn QBitmap QPixmap::mask() const 1814 1870 1815 Extracts a bitmap mask from the pixmap's alphachannel. 1816 1817 This is potentially an expensive operation. 1871 Extracts a bitmap mask from the pixmap's alpha channel. 1872 1873 \warning This is potentially an expensive operation. The mask of 1874 the pixmap is extracted dynamically from the pixeldata. 1818 1875 1819 1876 \sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information} … … 1821 1878 QBitmap QPixmap::mask() const 1822 1879 { 1823 return data ->mask();1880 return data ? data->mask() : QBitmap(); 1824 1881 } 1825 1882 … … 1840 1897 #elif defined(Q_WS_X11) 1841 1898 return QX11Info::appDepth(); 1842 #elif defined(Q_ OS_WINCE)1899 #elif defined(Q_WS_WINCE) 1843 1900 return QColormap::instance().depth(); 1844 1901 #elif defined(Q_WS_WIN) … … 1848 1905 #elif defined(Q_WS_MAC) 1849 1906 return 32; 1907 #elif defined(Q_OS_SYMBIAN) 1908 return S60->screenDepth; 1850 1909 #endif 1851 1910 } 1852 1853 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);1854 extern _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64;1855 1911 1856 1912 /*! … … 1873 1929 void QPixmap::detach() 1874 1930 { 1931 if (!data) 1932 return; 1933 1875 1934 QPixmapData::ClassId id = data->classId(); 1876 1935 if (id == QPixmapData::RasterClass) { 1877 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data );1936 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); 1878 1937 rasterData->image.detach(); 1879 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D) 1880 if (rasterData->texture) { 1881 rasterData->texture->Release(); 1882 rasterData->texture = 0; 1883 } 1884 #endif 1885 } 1886 1887 if (data->is_cached && qt_pixmap_cleanup_hook_64 && data->ref == 1) 1888 qt_pixmap_cleanup_hook_64(cacheKey()); 1938 } 1939 1940 if (data->is_cached && data->ref == 1) 1941 QImagePixmapCleanupHooks::executePixmapModificationHooks(this); 1889 1942 1890 1943 #if defined(Q_WS_MAC) 1891 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data ) : 0;1944 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; 1892 1945 if (macData) { 1893 1946 if (macData->cg_mask) { … … 1900 1953 if (data->ref != 1) { 1901 1954 *this = copy(); 1902 #if defined(Q_WS_MAC) && !defined(QT_MAC_NO_QUICKDRAW)1903 if (id == QPixmapData::MacClass) {1904 macData->qd_alpha = 0;1905 }1906 #endif1907 1955 } 1908 1956 ++data->detach_no; … … 1910 1958 #if defined(Q_WS_X11) 1911 1959 if (data->classId() == QPixmapData::X11Class) { 1912 QX11PixmapData *d = static_cast<QX11PixmapData*>(data );1913 d-> uninit = false;1960 QX11PixmapData *d = static_cast<QX11PixmapData*>(data.data()); 1961 d->flags &= ~QX11PixmapData::Uninitialized; 1914 1962 1915 1963 // reset the cache data … … 1947 1995 return QPixmap(); 1948 1996 1949 QPixmapData *data;1950 1997 QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); 1951 if (gs) 1952 data = gs->createPixmapData(QPixmapData::PixmapType); 1953 else 1954 data = QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType); 1955 1998 QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType) 1999 : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType)); 1956 2000 data->fromImage(image, flags); 1957 return QPixmap(data );2001 return QPixmap(data.take()); 1958 2002 } 1959 2003 … … 2000 2044 QPixmapData* QPixmap::pixmapData() const 2001 2045 { 2002 return data; 2003 } 2046 return data.data(); 2047 } 2048 2049 /*! 2050 \enum QPixmap::HBitmapFormat 2051 2052 \bold{Win32 only:} This enum defines how the conversion between \c 2053 HBITMAP and QPixmap is performed. 2054 2055 \warning This enum is only available on Windows. 2056 2057 \value NoAlpha The alpha channel is ignored and always treated as 2058 being set to fully opaque. This is preferred if the \c HBITMAP is 2059 used with standard GDI calls, such as \c BitBlt(). 2060 2061 \value PremultipliedAlpha The \c HBITMAP is treated as having an 2062 alpha channel and premultiplied colors. This is preferred if the 2063 \c HBITMAP is accessed through the \c AlphaBlend() GDI function. 2064 2065 \value Alpha The \c HBITMAP is treated as having a plain alpha 2066 channel. This is the preferred format if the \c HBITMAP is going 2067 to be used as an application icon or systray icon. 2068 2069 \sa fromWinHBITMAP(), toWinHBITMAP() 2070 */ 2071 2072 /*! \fn HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const 2073 \bold{Win32 only:} Creates a \c HBITMAP equivalent to the QPixmap, 2074 based on the given \a format. Returns the \c HBITMAP handle. 2075 2076 It is the caller's responsibility to free the \c HBITMAP data 2077 after use. 2078 2079 \warning This function is only available on Windows. 2080 2081 \sa fromWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2082 */ 2083 2084 /*! \fn QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) 2085 \bold{Win32 only:} Returns a QPixmap that is equivalent to the 2086 given \a bitmap. The conversion is based on the specified \a 2087 format. 2088 2089 \warning This function is only available on Windows. 2090 2091 \sa toWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2092 2093 */ 2094 2095 /*! \fn HICON QPixmap::toWinHICON() const 2096 \since 4.6 2097 2098 \bold{Win32 only:} Creates a \c HICON equivalent to the QPixmap. 2099 Returns the \c HICON handle. 2100 2101 It is the caller's responsibility to free the \c HICON data after use. 2102 2103 \warning This function is only available on Windows. 2104 2105 \sa fromWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2106 */ 2107 2108 /*! \fn QPixmap QPixmap::fromWinHICON(HICON icon) 2109 \since 4.6 2110 2111 \bold{Win32 only:} Returns a QPixmap that is equivalent to the given 2112 \a icon. 2113 2114 \warning This function is only available on Windows. 2115 2116 \sa toWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2117 2118 */ 2119 2120 /*! \fn const QX11Info &QPixmap::x11Info() const 2121 \bold{X11 only:} Returns information about the configuration of 2122 the X display used by the screen to which the pixmap currently belongs. 2123 2124 \warning This function is only available on X11. 2125 2126 \sa {QPixmap#Pixmap Information}{Pixmap Information} 2127 */ 2128 2129 /*! \fn Qt::HANDLE QPixmap::x11PictureHandle() const 2130 \bold{X11 only:} Returns the X11 Picture handle of the pixmap for 2131 XRender support. 2132 2133 This function will return 0 if XRender support is not compiled 2134 into Qt, if the XRender extension is not supported on the X11 2135 display, or if the handle could not be created. Use of this 2136 function is not portable. 2137 2138 \warning This function is only available on X11. 2139 2140 \sa {QPixmap#Pixmap Information}{Pixmap Information} 2141 */ 2142 2143 /*! \fn int QPixmap::x11SetDefaultScreen(int screen) 2144 \internal 2145 */ 2146 2147 /*! \fn void QPixmap::x11SetScreen(int screen) 2148 \internal 2149 */ 2150 2151 /*! \fn QRgb* QPixmap::clut() const 2152 \internal 2153 */ 2154 2155 /*! \fn int QPixmap::numCols() const 2156 \obsolete 2157 \internal 2158 \sa colorCount() 2159 */ 2160 2161 /*! \fn int QPixmap::colorCount() const 2162 \since 4.6 2163 \internal 2164 */ 2165 2166 /*! \fn const uchar* QPixmap::qwsBits() const 2167 \internal 2168 \since 4.1 2169 */ 2170 2171 /*! \fn int QPixmap::qwsBytesPerLine() const 2172 \internal 2173 \since 4.1 2174 */ 2004 2175 2005 2176 QT_END_NAMESPACE -
trunk/src/gui/image/qpixmap.h
r342 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 47 47 #include <QtCore/qnamespace.h> 48 48 #include <QtCore/qstring.h> // char*->QString conversion 49 #include <QtCore/qsharedpointer.h> 49 50 #include <QtGui/qimage.h> 50 51 #include <QtGui/qtransform.h> 51 52 52 53 QT_BEGIN_HEADER 54 55 #if defined(Q_OS_SYMBIAN) 56 class CFbsBitmap; 57 class RSgImage; 58 #endif 53 59 54 60 QT_BEGIN_NAMESPACE … … 60 66 class QVariant; 61 67 class QX11Info; 68 69 #if defined(Q_WS_PM) 62 70 class QIcon; 71 #endif 63 72 64 73 class QPixmapData; … … 81 90 operator QVariant() const; 82 91 83 bool isNull() const; 92 bool isNull() const; // ### Qt 5: make inline 84 93 int devType() const; 85 94 86 int width() const; 87 int height() const; 95 int width() const; // ### Qt 5: make inline 96 int height() const; // ### Qt 5: make inline 88 97 QSize size() const; 89 98 QRect rect() const; … … 146 155 147 156 HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const; 157 HICON toWinHICON() const; 158 148 159 static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha); 160 static QPixmap fromWinHICON(HICON hicon); 149 161 #endif 150 162 … … 162 174 #endif 163 175 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 164 183 inline QPixmap copy(int x, int y, int width, int height) const; 165 184 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); 166 188 167 189 int serialNumber() const; … … 177 199 int qwsBytesPerLine() const; 178 200 QRgb *clut() const; 179 int numCols() const; 201 #ifdef QT_DEPRECATED 202 QT_DEPRECATED int numCols() const; 203 #endif 204 int colorCount() const; 180 205 #elif defined(Q_WS_MAC) 181 206 Qt::HANDLE macQDHandle() const; … … 226 251 227 252 private: 228 Q PixmapData *data;253 QExplicitlySharedDataPointer<QPixmapData> data; 229 254 230 255 bool doImageIO(QImageWriter *io, int quality) const; … … 252 277 friend class QX11PixmapData; 253 278 friend class QMacPixmapData; 279 friend class QS60PixmapData; 254 280 friend class QBitmap; 255 281 friend class QPaintDevice; … … 261 287 friend class QRasterPaintEngine; 262 288 friend class QRasterBuffer; 263 friend class QDirect3DPaintEngine; 264 friend class QDirect3DPaintEnginePrivate; 265 friend class QDetachedPixmap; 289 friend class QPixmapCacheEntry; 266 290 #if !defined(QT_NO_DATASTREAM) 267 291 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); … … 273 297 274 298 public: 275 typedef Q PixmapData *DataPtr;299 typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr; 276 300 inline DataPtr &data_ptr() { return data; } 277 301 }; … … 282 306 { 283 307 return copy(QRect(ax, ay, awidth, aheight)); 308 } 309 310 inline 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); 284 313 } 285 314 -
trunk/src/gui/image/qpixmap_mac.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** 40 40 ****************************************************************************/ 41 //#define QT_RASTER_PAINTENGINE42 41 43 42 #include "qpixmap.h" … … 53 52 #include <private/qpixmap_mac_p.h> 54 53 #include <private/qpixmap_raster_p.h> 55 #ifdef QT_RASTER_PAINTENGINE56 # include <private/qpaintengine_raster_p.h>57 #endif58 54 #include <private/qpaintengine_mac_p.h> 59 55 #include <private/qt_mac_p.h> … … 78 74 Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix) 79 75 { 80 return static_cast<QMacPixmapData*>(pix->data )->pixels;76 return static_cast<QMacPixmapData*>(pix->data.data())->pixels; 81 77 } 82 78 83 79 Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix) 84 80 { 85 return static_cast<QMacPixmapData*>(pix->data )->bytesPerRow;81 return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow; 86 82 } 87 83 … … 120 116 0); 121 117 122 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)123 118 uint cgflags = kCGImageAlphaPremultipliedFirst; 124 119 #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; 130 121 #endif 131 122 … … 169 160 170 161 QMacPixmapData::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), 177 165 pengine(0) 178 166 { 167 } 168 169 QPixmapData *QMacPixmapData::createCompatiblePixmapData() const 170 { 171 return new QMacPixmapData(pixelType()); 179 172 } 180 173 … … 189 182 w = width; 190 183 h = height; 184 is_null = (w <= 0 || h <= 0); 191 185 d = (pixelType() == BitmapType ? 1 : 32); 192 186 bool make_null = w <= 0 || h <= 0; // create null pixmap … … 194 188 w = 0; 195 189 h = 0; 190 is_null = true; 196 191 d = 0; 197 192 if (!make_null) … … 232 227 w = img.width(); 233 228 h = img.height(); 229 is_null = (w <= 0 || h <= 0); 234 230 d = (pixelType() == BitmapType ? 1 : img.depth()); 235 231 … … 253 249 conv8 = d == 1; // native depth wanted 254 250 } else if (d == 1) { 255 if (image. numColors() == 2) {251 if (image.colorCount() == 2) { 256 252 QRgb c0 = image.color(0); // Auto: convert to best 257 253 QRgb c1 = image.color(1); … … 310 306 break; 311 307 } 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 } 315 315 } 316 316 } break; 317 317 case QImage::Format_RGB32: 318 318 for (int x = 0; x < w; ++x) … … 340 340 if (sfmt == QImage::Format_Indexed8) { 341 341 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) { 343 343 const int alpha = qAlpha(rgb[i]); 344 344 if (alpha != 0xff) { … … 356 356 { 357 357 int loopc; 358 for(loopc=0;loopc<qi-> numColors();loopc++) {358 for(loopc=0;loopc<qi->colorCount();loopc++) { 359 359 if(qi->color(loopc)==mycol) 360 360 return loopc; 361 361 } 362 qi->set NumColors(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(); 365 365 } 366 366 … … 377 377 if (format == QImage::Format_MonoLSB) { 378 378 image.fill(0); 379 image.set NumColors(2);379 image.setColorCount(2); 380 380 image.setColor(0, QColor(Qt::color0).rgba()); 381 381 image.setColor(1, QColor(Qt::color1).rgba()); … … 431 431 { 432 432 has_mask = true; 433 QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data );433 QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data()); 434 434 macSetAlphaChannel(alphaData, false); 435 435 } … … 459 459 has_alpha = false; 460 460 has_mask = true; 461 QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data );461 QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data()); 462 462 macSetAlphaChannel(maskData, true); 463 463 } … … 497 497 { 498 498 validDataPointers.remove(this); 499 #ifndef QT_MAC_NO_QUICKDRAW500 macQDDisposeAlpha();501 if (qd_data) {502 DisposeGWorld(qd_data);503 qd_data = 0;504 }505 #endif506 499 if (cg_mask) { 507 500 CGImageRelease(cg_mask); … … 592 585 { 593 586 has_alpha = b; 594 #ifndef QT_MAC_NO_QUICKDRAW595 macQDDisposeAlpha(); //let it get created lazily596 #endif597 587 macReleaseCGImageRef(); 598 588 } 599 600 #ifndef QT_MAC_NO_QUICKDRAW601 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 pixmap612 if (!has_alpha && !has_mask)613 return;614 615 //setup616 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 #endif635 589 636 590 void QMacPixmapData::macCreateCGImageRef() … … 643 597 qt_mac_cgimage_data_free); 644 598 validDataPointers.insert(this); 645 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)646 599 uint cgflags = kCGImageAlphaPremultipliedFirst; 647 600 #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; 653 602 #endif 654 603 cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace, … … 689 638 690 639 if (pixels) 691 memcpy(base_pixels, pixels, numBytes);640 memcpy(base_pixels, pixels, pixelsSize); 692 641 pixels = base_pixels; 642 pixelsSize = numBytes; 693 643 } 694 644 … … 891 841 } 892 842 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, using904 // 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_4914 if(CGBitmapContextGetBitmapInfo)915 bitmapInfo = CGBitmapContextGetBitmapInfo(c);916 else917 #endif918 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 925 843 // Returns a pixmap containing the screen contents at rect. 926 844 static QPixmap qt_mac_grabScreenRect(const QRect &rect) … … 956 874 QCoreGraphicsPaintEngine::macGenericColorSpace(), 957 875 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); 971 878 } 972 879 … … 1030 937 1031 938 \warning This function is only available on Mac OS X. 939 \warning As of Qt 4.6, this function \e{always} returns zero. 1032 940 */ 1033 941 1034 942 Qt::HANDLE QPixmap::macQDHandle() const 1035 943 { 1036 #ifndef QT_MAC_NO_QUICKDRAW1037 QMacPixmapData *d = static_cast<QMacPixmapData*>(data);1038 if (!d->qd_data) { //create the qd data1039 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 this1046 //makes our merge much simpler, at some point the hacks will go away1047 //because QD will be removed, but until that day this keeps them coexisting1048 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)1049 qdformat = k32BGRAPixelFormat;1050 #if 01051 qdflags |= kNativeEndianPixMap;1052 #endif1053 }1054 #endif1055 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 #else1061 944 return 0; 1062 #endif1063 945 } 1064 946 … … 1070 952 1071 953 \warning This function is only available on Mac OS X. 954 \warning As of Qt 4.6, this function \e{always} returns zero. 1072 955 */ 1073 956 1074 957 Qt::HANDLE QPixmap::macQDAlphaHandle() const 1075 958 { 1076 #ifndef QT_MAC_NO_QUICKDRAW1077 QMacPixmapData *d = static_cast<QMacPixmapData*>(data);1078 if (d->has_alpha || d->has_mask) {1079 if (!d->qd_alpha) //lazily created1080 d->macQDUpdateAlpha();1081 return d->qd_alpha;1082 }1083 #endif1084 959 return 0; 1085 960 } … … 1096 971 Qt::HANDLE QPixmap::macCGHandle() const 1097 972 { 973 if (isNull()) 974 return 0; 975 1098 976 if (data->classId() == QPixmapData::MacClass) { 1099 QMacPixmapData *d = static_cast<QMacPixmapData *>(data );977 QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data()); 1100 978 if (!d->cg_data) 1101 979 d->macCreateCGImageRef(); … … 1104 982 return ret; 1105 983 } 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); 1107 985 } 1108 986 return 0; … … 1116 994 CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr) 1117 995 { 1118 QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data );996 QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data()); 1119 997 if (px->cg_mask) { 1120 998 if (px->cg_mask_rect == sr) { … … 1151 1029 return 0; 1152 1030 1153 QMacSavedPortInfo pi; //save the current state1154 1031 //create icon 1155 1032 IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0)); … … 1226 1103 #endif 1227 1104 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 1247 1105 /*! \internal */ 1248 1106 QPaintEngine* QMacPixmapData::paintEngine() const … … 1250 1108 if (!pengine) { 1251 1109 QMacPixmapData *that = const_cast<QMacPixmapData*>(this); 1252 #ifdef QT_RASTER_PAINTENGINE1253 if (qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())1254 that->pengine = new QRasterPaintEngine();1255 else1256 that->pengine = new QCoreGraphicsPaintEngine();1257 #else1258 1110 that->pengine = new QCoreGraphicsPaintEngine(); 1259 #endif1260 1111 } 1261 1112 return pengine; … … 1291 1142 } 1292 1143 1144 bool 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 1293 1152 /*! 1294 1153 \since 4.2 … … 1322 1181 h = CGImageGetHeight(image); 1323 1182 QPixmap ret(w, h); 1183 ret.fill(Qt::transparent); 1324 1184 CGRect rect = CGRectMake(0, 0, w, h); 1325 1185 CGContextRef ctx = qt_mac_cg_context(&ret); -
trunk/src/gui/image/qpixmap_mac_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 66 66 ~QMacPixmapData(); 67 67 68 QPixmapData *createCompatiblePixmapData() const; 69 68 70 void resize(int width, int height); 69 71 void fromImage(const QImage &image, Qt::ImageConversionFlags flags); 70 72 void copy(const QPixmapData *data, const QRect &rect); 73 bool scroll(int dx, int dy, const QRect &rect); 71 74 72 75 int metric(QPaintDevice::PaintDeviceMetric metric) const; … … 83 86 84 87 private: 85 int w, h, d;86 88 87 89 uint has_alpha : 1, has_mask : 1, uninit : 1; … … 106 108 */ 107 109 quint32 *pixels; 110 uint pixelsSize; 108 111 quint32 *pixelsToFree; 109 112 uint bytesPerRow; 110 113 QRectF cg_mask_rect; 111 114 CGImageRef cg_data, cg_dataBeingReleased, cg_mask; 112 #ifndef QT_MAC_NO_QUICKDRAW113 GWorldPtr qd_data, qd_alpha;114 void macQDDisposeAlpha();115 void macQDUpdateAlpha();116 #endif117 115 static QSet<QMacPixmapData*> validDataPointers; 118 116 -
trunk/src/gui/image/qpixmap_raster.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 51 51 #include <private/qdrawhelper_p.h> 52 52 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 #endif58 59 53 QT_BEGIN_NAMESPACE 60 54 … … 62 56 0x10, 0x20, 0x40, 0x80 }; 63 57 58 QPixmap 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 70 QPixmap 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 64 81 QRasterPixmapData::QRasterPixmapData(PixelType type) 65 82 : QPixmapData(type, RasterClass) 66 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)67 , texture(0)68 #endif69 83 { 70 84 } … … 72 86 QRasterPixmapData::~QRasterPixmapData() 73 87 { 88 } 89 90 QPixmapData *QRasterPixmapData::createCompatiblePixmapData() const 91 { 92 return new QRasterPixmapData(pixelType()); 74 93 } 75 94 … … 95 114 96 115 image = QImage(width, height, format); 116 w = width; 117 h = height; 118 d = image.depth(); 119 is_null = (w <= 0 || h <= 0); 97 120 98 121 if (pixelType() == BitmapType && !image.isNull()) { 99 image.set NumColors(2);122 image.setColorCount(2); 100 123 image.setColor(0, QColor(Qt::color0).rgba()); 101 124 image.setColor(1, QColor(Qt::color1).rgba()); … … 178 201 } 179 202 #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); 180 211 181 212 setSerialNumber(image.serialNumber()); 213 } 214 215 // from qwindowsurface.cpp 216 extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); 217 218 bool 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; 182 223 } 183 224 … … 322 363 int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const 323 364 { 365 QImageData *d = image.d; 366 if (!d) 367 return 0; 368 324 369 // 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));327 370 switch (metric) { 371 case QPaintDevice::PdmWidth: 372 return w; 373 case QPaintDevice::PdmHeight: 374 return h; 328 375 case QPaintDevice::PdmWidthMM: 329 return qRound( image.width() * 1000 / dpmX);376 return qRound(d->width * 25.4 / qt_defaultDpiX()); 330 377 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 336 384 case QPaintDevice::PdmPhysicalDpiX: 337 return qRound(dpmX * qreal(0.0254)); 385 return qt_defaultDpiX(); 386 case QPaintDevice::PdmDpiY: // fall-through 338 387 case QPaintDevice::PdmPhysicalDpiY: 339 return q Round(dpmY * qreal(0.0254));388 return qt_defaultDpiY(); 340 389 default: 341 return image.metric(metric); 342 } 390 qWarning("QRasterPixmapData::metric(): Unhandled metric type %d", metric); 391 break; 392 } 393 394 return 0; 343 395 } 344 396 -
trunk/src/gui/image/qpixmap_raster_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 59 59 #ifdef Q_WS_WIN 60 60 # include "qt_windows.h" 61 # ifndef QT_NO_DIRECT3D62 # include <d3d9.h>63 # endif64 61 #endif 65 62 … … 72 69 ~QRasterPixmapData(); 73 70 71 QPixmapData *createCompatiblePixmapData() const; 72 74 73 void resize(int width, int height); 75 74 void fromFile(const QString &filename, Qt::ImageConversionFlags flags); 76 75 void fromImage(const QImage &image, Qt::ImageConversionFlags flags); 77 76 77 bool scroll(int dx, int dy, const QRect &rect); 78 78 void fill(const QColor &color); 79 79 void setMask(const QBitmap &mask); … … 86 86 protected: 87 87 int metric(QPaintDevice::PaintDeviceMetric metric) const; 88 QImage image; 88 89 89 90 private: 90 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)91 friend class QDirect3DPaintEnginePrivate;92 IDirect3DTexture9 *texture;93 #endif94 91 friend class QPixmap; 95 92 friend class QBitmap; 96 friend class Q DetachedPixmap;93 friend class QPixmapCacheEntry; 97 94 friend class QRasterPaintEngine; 98 QImage image;99 95 }; 100 96 -
trunk/src/gui/image/qpixmap_win.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 60 60 #include "qt_windows.h" 61 61 62 #if defined(Q_ OS_WINCE)62 #if defined(Q_WS_WINCE) 63 63 #include <winbase.h> 64 64 #include "qguifunctions_wince.h" … … 81 81 if (h < 0) h = r.bottom - r.top; 82 82 83 #ifdef Q_ OS_WINCE_WM83 #ifdef Q_WS_WINCE_WM 84 84 if (qt_wince_is_pocket_pc()) { 85 85 QWidget *widget = QWidget::find(winId); … … 102 102 HDC window_dc = GetDC(winId); 103 103 BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY 104 #ifndef Q_ OS_WINCE104 #ifndef Q_WS_WINCE 105 105 | CAPTUREBLT 106 106 #endif … … 120 120 } 121 121 122 123 124 /*!125 \enum QPixmap::HBitmapFormat126 127 This enum defines how the conversion between \c HBITMAP128 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 as133 being set to fully opaque. This is preferred if the \c HBITMAP is134 used with standard GDI calls, such as \c BitBlt().135 136 \value PremultipliedAlpha The \c HBITMAP is treated as having an137 alpha channel and premultiplied colors. This is preferred if the138 \c HBITMAP is accessed through the \c AlphaBlend() GDI function.139 140 \value Alpha The \c HBITMAP is treated as having a plain alpha141 channel. This is the preferred format if the \c HBITMAP is going142 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 given149 \a format. Returns the \c HBITMAP handle.150 151 It is the caller's responsibility to free the \c HBITMAP data152 after use.153 154 \warning This function is only available on Windows.155 156 \sa fromWinHBITMAP()157 */158 122 HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const 159 123 { 124 if (isNull()) 125 return 0; 126 160 127 HBITMAP bitmap = 0; 161 128 if (data->classId() == QPixmapData::RasterClass) { 162 QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data );129 QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data()); 163 130 int w = d->image.width(); 164 131 int h = d->image.height(); … … 210 177 } 211 178 212 /*!213 Returns a QPixmap that is equivalent to the given \a bitmap. The214 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 */221 179 QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) 222 180 { … … 225 183 memset(&bitmap_info, 0, sizeof(BITMAP)); 226 184 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); 234 186 if (!res) { 235 187 qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info"); … … 288 240 } 289 241 242 HBITMAP 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 257 HICON 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 290 280 #ifdef Q_WS_WIN 291 #ifndef Q_ OS_WINCE281 #ifndef Q_WS_WINCE 292 282 293 283 static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) … … 320 310 qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits"); 321 311 } 312 qFree(data); 322 313 323 314 return image; 324 315 } 325 316 326 QPixmap convertHIconToPixmap( constHICON icon)317 QPixmap QPixmap::fromWinHICON(HICON icon) 327 318 { 328 319 bool foundAlpha = false; … … 334 325 bool result = GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center 335 326 if (!result) 336 qWarning(" convertHIconToPixmap(), failed to GetIconInfo()");327 qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()"); 337 328 338 329 int w = iconinfo.xHotspot * 2; … … 392 383 return QPixmap::fromImage(image); 393 384 } 394 #else //ifndef Q_ OS_WINCE395 QPixmap convertHIconToPixmap( const HICON icon, bool large)385 #else //ifndef Q_WS_WINCE 386 QPixmap QPixmap::fromWinHICON(HICON icon) 396 387 { 397 388 HDC screenDevice = GetDC(0); … … 399 390 ReleaseDC(0, screenDevice); 400 391 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; 402 417 403 418 BITMAPINFO bmi; 404 419 memset(&bmi, 0, sizeof(bmi)); 405 420 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; 408 423 bmi.bmiHeader.biPlanes = 1; 409 424 bmi.bmiHeader.biBitCount = 32; 410 425 bmi.bmiHeader.biCompression = BI_RGB; 411 bmi.bmiHeader.biSizeImage = size*size*4;426 bmi.bmiHeader.biSizeImage = dwImageSize; 412 427 413 428 uchar* bits; … … 415 430 HBITMAP winBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &bits, 0, 0); 416 431 if (winBitmap ) 417 memset(bits, 0xff, size*size*4);432 memset(bits, 0xff, dwImageSize); 418 433 if (!winBitmap) { 419 qWarning(" convertHIconToPixmap(), failed to CreateDIBSection()");434 qWarning("QPixmap::fromWinHICON(), failed to CreateDIBSection()"); 420 435 return QPixmap(); 421 436 } 422 437 423 438 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()"); 426 441 427 442 uint mask = 0xff000000; 428 443 // Create image and copy data into image. 429 QImage image( size, size, QImage::Format_ARGB32);444 QImage image(w, h, QImage::Format_ARGB32); 430 445 431 446 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) { 434 449 QRgb *dest = (QRgb *) image.scanLine(y); 435 450 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) { 437 452 dest[x] = src[x]; 438 453 } 439 454 } 440 455 } 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()"); 443 458 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) { 446 461 QRgb *dest = (QRgb *) image.scanLine(y); 447 462 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) { 449 464 if (!src[x]) 450 465 dest[x] = dest[x] | mask; … … 457 472 return QPixmap::fromImage(image); 458 473 } 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 480 476 481 477 QT_END_NAMESPACE -
trunk/src/gui/image/qpixmap_x11.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 68 68 #include "qx11info_x11.h" 69 69 #include <private/qdrawhelper_p.h> 70 #include <private/qimage_p.h> 70 71 71 72 #include <stdlib.h> … … 313 314 314 315 QX11PixmapData::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), 317 318 share_mode(QPixmap::ImplicitlyShared), pengine(0) 318 319 { 320 } 321 322 QPixmapData *QX11PixmapData::createCompatiblePixmapData() const 323 { 324 return new QX11PixmapData(pixelType()); 319 325 } 320 326 … … 325 331 w = width; 326 332 h = height; 333 is_null = (w <= 0 || h <= 0); 327 334 328 335 if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { … … 348 355 w = 0; 349 356 h = 0; 357 is_null = true; 350 358 hd = 0; 351 359 picture = 0; … … 368 376 } 369 377 378 struct 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 370 409 void QX11PixmapData::fromImage(const QImage &img, 371 410 Qt::ImageConversionFlags flags) … … 376 415 h = img.height(); 377 416 d = img.depth(); 417 is_null = (w <= 0 || h <= 0); 418 419 if (is_null) { 420 w = h = 0; 421 return; 422 } 378 423 379 424 if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { … … 396 441 if (uint(w) >= 32768 || uint(h) >= 32768) { 397 442 w = h = 0; 443 is_null = true; 398 444 return; 399 445 } 400 446 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 402 450 if (qt_x11_preferred_pixmap_depth) 403 451 dd = qt_x11_preferred_pixmap_depth; … … 422 470 conv8 = (d == 1); // native depth wanted 423 471 } else if (d == 1) { 424 if (image. numColors() == 2) {472 if (image.colorCount() == 2) { 425 473 QRgb c0 = image.color(0); // Auto: convert to best 426 474 QRgb c1 = image.color(1); … … 447 495 XImage *xi = 0; 448 496 bool trucol = (visual->c_class >= TrueColor); 449 int nbytes = image. numBytes();497 int nbytes = image.byteCount(); 450 498 uchar *newbits= 0; 451 499 452 500 #ifndef QT_NO_XRENDER 453 if ( X11->use_xrender && image.hasAlphaChannel()) {501 if (alphaCheck.hasXRenderAndAlpha()) { 454 502 const QImage &cimage = image; 455 503 … … 589 637 if (d8) { // setup pixel translation 590 638 QVector<QRgb> ctable = cimage.colorTable(); 591 for (int i=0; i < cimage. numColors(); i++) {639 for (int i=0; i < cimage.colorCount(); i++) { 592 640 int r = qRed (ctable[i]); 593 641 int g = qGreen(ctable[i]); … … 915 963 int pop[256]; // pixel popularity 916 964 917 if (image. numColors() == 0)918 image.set NumColors(1);965 if (image.colorCount() == 0) 966 image.setColorCount(1); 919 967 920 968 const QImage &cimage = image; … … 946 994 }; 947 995 int ncols = 0; 948 for (int i=0; i< cimage. numColors(); i++) { // compute number of colors996 for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors 949 997 if (pop[i] > 0) 950 998 ncols++; 951 999 } 952 for (int i = cimage. numColors(); i < 256; i++) // ignore out-of-range pixels1000 for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels 953 1001 pop[i] = 0; 954 1002 … … 1088 1136 #endif 1089 1137 1090 if ( image.hasAlphaChannel()) {1138 if (alphaCheck.hasAlpha()) { 1091 1139 QBitmap m = QBitmap::fromImage(image.createAlphaMask(flags)); 1092 1140 setMask(m); … … 1110 1158 h = img.height(); 1111 1159 d = 1; 1160 is_null = (w <= 0 || h <= 0); 1112 1161 int bpl = (w + 7) / 8; 1113 1162 int ibpl = img.bytesPerLine(); … … 1213 1262 hd2 = 0; 1214 1263 } 1215 if (! read_only)1264 if (!(flags & Readonly)) 1216 1265 XFreePixmap(xinfo.display(), hd); 1217 1266 hd = 0; … … 1221 1270 QPixmap QX11PixmapData::alphaChannel() const 1222 1271 { 1223 if (!hasAlphaChannel()) 1224 return QPixmap(); 1272 if (!hasAlphaChannel()) { 1273 QPixmap pm(w, h); 1274 pm.fill(Qt::white); 1275 return pm; 1276 } 1225 1277 QImage im(toImage()); 1226 1278 return QPixmap::fromImage(im.alphaChannel(), Qt::OrderedDither); … … 1438 1490 // we may have to swap the byte order 1439 1491 if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst) 1440 || (QSysInfo::ByteOrder == QSysInfo::BigEndian ))1492 || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst)) 1441 1493 { 1442 1494 for (int i=0; i < image.height(); i++) { … … 1605 1657 1606 1658 if (d == 1) { // bitmap 1607 image.set NumColors(2);1659 image.setColorCount(2); 1608 1660 image.setColor(0, qRgb(255,255,255)); 1609 1661 image.setColor(1, qRgb(0,0,0)); … … 1661 1713 if (ncols < 256) { 1662 1714 trans = ncols++; 1663 image.set NumColors(ncols); // create color table1715 image.setColorCount(ncols); // create color table 1664 1716 image.setColor(trans, 0x00000000); 1665 1717 } else { 1666 image.set NumColors(ncols); // create color table1718 image.setColorCount(ncols); // create color table 1667 1719 // oh dear... no spare "transparent" pixel. 1668 1720 // use first pixel in image (as good as any). … … 1687 1739 } 1688 1740 } else { 1689 image.set NumColors(ncols); // create color table1741 image.setColorCount(ncols); // create color table 1690 1742 } 1691 1743 QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap(); … … 1870 1922 return bm; 1871 1923 } else { // color pixmap 1872 Q Pixmap pm;1873 Q X11PixmapData *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; 1875 1927 x11Data->xinfo = xinfo; 1876 1928 x11Data->d = d; 1877 1929 x11Data->w = w; 1878 1930 x11Data->h = h; 1931 x11Data->is_null = (w <= 0 || h <= 0); 1879 1932 x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display, 1880 1933 RootWindow(X11->display, xinfo.screen()), 1881 1934 w, h, d); 1935 x11Data->setSerialNumber(++qt_pixmap_serial); 1936 1882 1937 #ifndef QT_NO_XRENDER 1883 1938 if (X11->use_xrender) { … … 1915 1970 } 1916 1971 1917 /*!1918 \internal1919 */1920 1972 int QPixmap::x11SetDefaultScreen(int screen) 1921 1973 { … … 1925 1977 } 1926 1978 1927 /*!1928 \internal1929 */1930 1979 void QPixmap::x11SetScreen(int screen) 1931 1980 { … … 1935 1984 } 1936 1985 1986 if (isNull()) 1987 return; 1988 1937 1989 if (data->classId() != QPixmapData::X11Class) 1938 1990 return; … … 1941 1993 screen = QX11Info::appScreen(); 1942 1994 1943 QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data );1995 QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data.data()); 1944 1996 if (screen == x11Data->xinfo.screen()) 1945 1997 return; // nothing to do … … 2019 2071 QPixmap pm(data); 2020 2072 2021 data-> uninit = false;2073 data->flags &= ~QX11PixmapData::Uninitialized; 2022 2074 pm.x11SetScreen(scr); 2023 2075 … … 2035 2087 } 2036 2088 2037 /*!2038 Returns information about the configuration of the X display used to display2039 the widget.2040 2041 \warning This function is only available on X11.2042 2043 \sa {QPixmap#Pixmap Information}{Pixmap Information}2044 */2045 2089 const QX11Info &QPixmap::x11Info() const 2046 2090 { 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; 2049 2093 else { 2050 2094 static QX11Info nullX11Info; … … 2069 2113 QX11PixmapData *that = const_cast<QX11PixmapData*>(this); 2070 2114 2071 if ( read_only&& share_mode == QPixmap::ImplicitlyShared) {2115 if ((flags & Readonly) && share_mode == QPixmap::ImplicitlyShared) { 2072 2116 // if someone wants to draw onto us, copy the shared contents 2073 2117 // and turn it into a fully fledged QPixmap … … 2091 2135 } 2092 2136 that->hd = hd_copy; 2093 that-> read_only = false;2137 that->flags &= ~QX11PixmapData::Readonly; 2094 2138 } 2095 2139 … … 2099 2143 } 2100 2144 2101 /*!2102 Returns the X11 Picture handle of the pixmap for XRender2103 support.2104 2105 This function will return 0 if XRender support is not compiled2106 into Qt, if the XRender extension is not supported on the X112107 display, or if the handle could not be created. Use of this2108 function is not portable.2109 2110 \warning This function is only available on X11.2111 2112 \sa {QPixmap#Pixmap Information}{Pixmap Information}2113 */2114 2115 2145 Qt::HANDLE QPixmap::x11PictureHandle() const 2116 2146 { 2117 2147 #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; 2120 2150 else 2121 2151 return 0; … … 2156 2186 setSerialNumber(++qt_pixmap_serial); 2157 2187 2158 uninit = false;2188 flags &= ~Uninitialized; 2159 2189 xinfo = x11Data->xinfo; 2160 2190 d = x11Data->d; 2161 2191 w = rect.width(); 2162 2192 h = rect.height(); 2193 is_null = (w <= 0 || h <= 0); 2163 2194 hd = (Qt::HANDLE)XCreatePixmap(X11->display, 2164 2195 RootWindow(X11->display, x11Data->xinfo.screen()), … … 2206 2237 } 2207 2238 2239 bool 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 2208 2249 #if !defined(QT_NO_XRENDER) 2209 2250 void QX11PixmapData::convertToARGB32(bool preserveContents) … … 2213 2254 2214 2255 // Q_ASSERT(count == 1); 2215 if ( read_only&& share_mode == QPixmap::ExplicitlyShared)2256 if ((flags & Readonly) && share_mode == QPixmap::ExplicitlyShared) 2216 2257 return; 2217 2258 … … 2223 2264 if (preserveContents) 2224 2265 XRenderComposite(X11->display, PictOpSrc, picture, 0, p, 0, 0, 0, 0, 0, 0, w, h); 2225 if (! read_only)2266 if (!(flags & Readonly)) 2226 2267 XRenderFreePicture(X11->display, picture); 2227 2268 } 2228 if (hd && ! read_only)2269 if (hd && !(flags & Readonly)) 2229 2270 XFreePixmap(X11->display, hd); 2230 2271 if (x11_mask) { … … 2264 2305 QX11PixmapData *data = new QX11PixmapData(depth == 1 ? QPixmapData::BitmapType : QPixmapData::PixmapType); 2265 2306 data->setSerialNumber(++qt_pixmap_serial); 2266 data-> read_only = true;2307 data->flags = QX11PixmapData::Readonly; 2267 2308 data->share_mode = mode; 2268 data->uninit = false;2269 2309 data->w = width; 2270 2310 data->h = height; 2311 data->is_null = (width <= 0 || height <= 0); 2271 2312 data->d = depth; 2272 2313 data->hd = pixmap; -
trunk/src/gui/image/qpixmap_x11_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 72 72 ~QX11PixmapData(); 73 73 74 QPixmapData *createCompatiblePixmapData() const; 75 74 76 void resize(int width, int height); 75 77 void fromImage(const QImage &image, Qt::ImageConversionFlags flags); 76 78 void copy(const QPixmapData *data, const QRect &rect); 79 bool scroll(int dx, int dy, const QRect &rect); 77 80 78 81 void fill(const QColor &color); … … 99 102 friend class QX11WindowSurface; 100 103 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 101 108 102 109 void release(); … … 108 115 Qt::HANDLE hd; 109 116 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; 114 125 115 126 QX11Info xinfo; … … 118 129 Qt::HANDLE mask_picture; 119 130 Qt::HANDLE hd2; // sorted in the default display depth 131 Qt::HANDLE gl_surface; 120 132 #ifndef QT_NO_XRENDER 121 133 void convertToARGB32(bool preserveContents = true); -
trunk/src/gui/image/qpixmapcache.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "qpixmapcache.h" 43 #include "qcache.h"44 43 #include "qobject.h" 45 44 #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" 50 46 51 47 QT_BEGIN_NAMESPACE … … 56 52 \brief The QPixmapCache class provides an application-wide cache for pixmaps. 57 53 58 \ingroup environment 59 \ingroup multimedia 54 \ingroup painting 60 55 61 56 This class is a tool for optimized drawing with QPixmap. You can … … 69 64 object for caching the pixmaps. 70 65 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. 75 76 76 77 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. 80 84 81 85 The \e{Qt Quarterly} article 82 \l{http:// doc.trolltech.com/qq/qq12-qpixmapcache.html}{Optimizing86 \l{http://qt.nokia.com/doc/qq/qq12-qpixmapcache.html}{Optimizing 83 87 with QPixmapCache} explains how to use QPixmapCache to speed up 84 88 applications by caching the results of painting. … … 87 91 */ 88 92 89 #if defined(Q_WS_QWS) || defined(Q_OS_WINCE) 93 #if defined(Q_OS_SYMBIAN) 94 static int cache_limit = 1024; // 1048 KB cache limit for symbian 95 #elif defined(Q_WS_QWS) || defined(Q_WS_WINCE) 90 96 static int cache_limit = 2048; // 2048 KB cache limit for embedded 91 97 #else … … 93 99 #endif 94 100 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 */ 115 QPixmapCache::Key::Key() : d(0) 116 { 117 } 118 119 /*! 120 \internal 121 Constructs a copy of \a other. 122 */ 123 QPixmapCache::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 */ 133 QPixmapCache::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 */ 145 bool 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 */ 158 QPixmapCache::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 170 class QPMCache : public QObject, public QCache<QPixmapCache::Key, QPixmapCacheEntry> 114 171 { 115 172 Q_OBJECT 116 173 public: 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(); 122 176 123 177 void timerEvent(QTimerEvent *); 124 178 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); 125 181 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(); 126 188 127 189 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); 128 196 129 197 private: 130 QHash<QString, qint64> cacheKeys;198 int *keyArray; 131 199 int theid; 132 200 int ps; 201 int keyArraySize; 202 int freeKey; 203 QHash<QString, QPixmapCache::Key> cacheKeys; 133 204 bool t; 134 205 }; 206 135 207 QT_BEGIN_INCLUDE_NAMESPACE 136 208 #include "qpixmapcache.moc" 137 209 QT_END_INCLUDE_NAMESPACE 138 210 211 uint qHash(const QPixmapCache::Key &k) 212 { 213 return qHash(QPMCache::get(k)->key); 214 } 215 216 QPMCache::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 } 222 QPMCache::~QPMCache() 223 { 224 clear(); 225 free(keyArray); 226 } 227 139 228 /* 140 This is supposed to cut the cache size down by about 80-90% in a229 This is supposed to cut the cache size down by about 25% in a 141 230 minute once the application becomes idle, to let any inserted pixmap 142 231 remain in the cache for some time before it becomes a candidate for … … 147 236 timer so Qt won't keep the CPU from going into sleep mode. 148 237 */ 149 150 238 void QPMCache::timerEvent(QTimerEvent *) 151 239 { … … 156 244 ps = totalCost(); 157 245 158 QHash<QString, qint64>::iterator it = cacheKeys.begin();246 QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin(); 159 247 while (it != cacheKeys.end()) { 160 248 if (!contains(it.value())) { 249 releaseKey(it.value()); 161 250 it = cacheKeys.erase(it); 162 251 } else { … … 177 266 QPixmap *QPMCache::object(const QString &key) const 178 267 { 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 281 QPixmap *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 } 182 290 183 291 bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) 184 292 { 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); 191 305 if (success) { 192 306 cacheKeys.insert(key, cacheKey); … … 195 309 t = false; 196 310 } 311 } else { 312 //Insertion failed we released the new allocated key 313 releaseKey(cacheKey); 197 314 } 198 315 return success; 199 316 } 200 317 318 QPixmapCache::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 334 bool 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 201 356 bool QPMCache::remove(const QString &key) 202 357 { 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; 204 362 cacheKeys.remove(key); 205 return QCache<qint64, QDetachedPixmap>::remove(cacheKey); 363 return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey); 364 } 365 366 bool QPMCache::remove(const QPixmapCache::Key &key) 367 { 368 return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key); 369 } 370 371 void 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 382 QPixmapCache::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 394 void 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 405 void 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 418 QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key) 419 { 420 if (!key->d) 421 key->d = new QPixmapCache::KeyData; 422 return key->d; 206 423 } 207 424 208 425 Q_GLOBAL_STATIC(QPMCache, pm_cache) 209 426 210 /*! 211 \obsolete 427 int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize() 428 { 429 return pm_cache()->size(); 430 } 431 432 QPixmapCacheEntry::~QPixmapCacheEntry() 433 { 434 pm_cache()->releaseKey(key); 435 } 436 437 /*! 438 \obsolete 212 439 \overload 213 440 … … 218 445 fast). Subsequent insertions into the cache could cause the 219 446 pointer to become invalid. For this reason, we recommend you use 220 find(const QString&, QPixmap&) instead.447 bool find(const QString&, QPixmap*) instead. 221 448 222 449 Example: … … 231 458 232 459 /*! 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 465 bool 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 236 476 237 477 Example: … … 239 479 */ 240 480 241 bool QPixmapCache::find(const QString &key, QPixmap & pm)481 bool QPixmapCache::find(const QString &key, QPixmap* pixmap) 242 482 { 243 483 QPixmap *ptr = pm_cache()->object(key); 244 if (ptr )245 pm= *ptr;484 if (ptr && pixmap) 485 *pixmap = *ptr; 246 486 return ptr != 0; 247 487 } 248 488 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 */ 498 bool 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 252 511 the cache. 253 512 … … 268 527 */ 269 528 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); 529 bool 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 */ 549 QPixmapCache::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 */ 563 bool 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); 273 569 } 274 570 … … 276 572 Returns the cache limit (in kilobytes). 277 573 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. 279 576 280 577 \sa setCacheLimit() … … 289 586 Sets the cache limit to \a n kilobytes. 290 587 291 The default setting is 1024 kilobytes. 588 The default setting is 2048 KB on embedded platforms, 10240 KB on 589 desktop platforms. 292 590 293 591 \sa cacheLimit() … … 308 606 } 309 607 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 */ 614 void 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 } 310 621 311 622 /*! … … 315 626 void QPixmapCache::clear() 316 627 { 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 } 318 634 } 319 635 -
trunk/src/gui/image/qpixmapcache.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 54 54 { 55 55 public: 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 56 74 static int cacheLimit(); 57 75 static void setCacheLimit(int); 58 76 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); 61 83 static void remove(const QString &key); 84 static void remove(const Key &key); 62 85 static void clear(); 63 86 }; -
trunk/src/gui/image/qpixmapdata.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "qpixmapdata_p.h" 43 #include <QtCore/qbuffer.h> 43 44 #include <QtGui/qbitmap.h> 44 45 #include <QtGui/qimagereader.h> 46 #include <private/qgraphicssystem_p.h> 47 #include <private/qapplication_p.h> 45 48 46 49 QT_BEGIN_NAMESPACE … … 49 52 0x10, 0x20, 0x40, 0x80 }; 50 53 54 QPixmapData *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 51 67 QPixmapData::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 { 55 79 } 56 80 … … 59 83 } 60 84 61 void QPixmapData::fromFile(const QString &fileName, const char *format, 85 QPixmapData *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 96 static 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 116 bool QPixmapData::fromFile(const QString &fileName, const char *format, 62 117 Qt::ImageConversionFlags flags) 63 118 { 64 constQImage image = QImageReader(fileName, format).read();119 QImage image = QImageReader(fileName, format).read(); 65 120 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 126 bool 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(); 69 134 } 70 135 … … 72 137 { 73 138 fromImage(data->toImage().copy(rect), Qt::AutoColor); 139 } 140 141 bool 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; 74 147 } 75 148 … … 129 202 return QBitmap(); 130 203 131 mask.set NumColors(2);204 mask.setColorCount(2); 132 205 mask.setColor(0, QColor(Qt::color0).rgba()); 133 206 mask.setColor(1, QColor(Qt::color1).rgba()); … … 177 250 } 178 251 252 #if defined(Q_OS_SYMBIAN) 253 void* QPixmapData::toNativeType(NativeType /* type */) 254 { 255 return 0; 256 } 257 258 void QPixmapData::fromNativeType(void* /* pixmap */, NativeType /* typre */) 259 { 260 return; 261 } 262 #endif 263 179 264 QT_END_NAMESPACE -
trunk/src/gui/image/qpixmapdata_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 67 67 PixmapType, BitmapType 68 68 }; 69 #if defined(Q_OS_SYMBIAN) 70 enum NativeType { 71 FbsBitmap, 72 SgImage 73 }; 74 #endif 69 75 enum ClassId { RasterClass, X11Class, MacClass, DirectFBClass, 70 76 OpenGLClass, OpenVGClass, CustomClass = 1024 }; 71 77 72 QPixmapData(PixelType pixel pType, int classId);78 QPixmapData(PixelType pixelType, int classId); 73 79 virtual ~QPixmapData(); 80 81 virtual QPixmapData *createCompatiblePixmapData() const; 74 82 75 83 virtual void resize(int width, int height) = 0; 76 84 virtual void fromImage(const QImage &image, 77 85 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, 79 88 Qt::ImageConversionFlags flags); 89 virtual bool fromData(const uchar *buffer, uint len, const char *format, 90 Qt::ImageConversionFlags flags); 91 80 92 virtual void copy(const QPixmapData *data, const QRect &rect); 93 virtual bool scroll(int dx, int dy, const QRect &rect); 81 94 82 95 virtual int metric(QPaintDevice::PaintDeviceMetric metric) const = 0; … … 99 112 virtual QImage* buffer(); 100 113 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); 105 127 106 128 protected: 107 129 void setSerialNumber(int serNo); 130 int w; 131 int h; 132 int d; 133 bool is_null; 108 134 109 135 private: 110 136 friend class QPixmap; 111 friend class QGLContextPrivate;112 137 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>; 113 142 114 143 QAtomicInt ref; … … 120 149 uint is_cached; 121 150 }; 122 123 #ifdef Q_WS_WIN124 #ifndef Q_OS_WINCE125 QPixmap convertHIconToPixmap( const HICON icon);126 #else127 QPixmap convertHIconToPixmap( const HICON icon, bool large = false);128 #endif129 QPixmap loadIconFromShell32( int resourceId, int size );130 #endif131 151 132 152 # define QT_XFORM_TYPE_MSBFIRST 0 -
trunk/src/gui/image/qpixmapdatafactory.cpp
r95 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 48 48 # include <private/qpixmap_x11_p.h> 49 49 #endif 50 #if def Q_WS_WIN50 #if defined(Q_WS_WIN) 51 51 # include <private/qpixmap_raster_p.h> 52 52 #endif … … 56 56 #ifdef Q_WS_MAC 57 57 # include <private/qpixmap_mac_p.h> 58 #endif 59 #ifdef Q_WS_S60 60 # include <private/qpixmap_s60_p.h> 58 61 #endif 59 62 … … 85 88 #elif defined(Q_WS_MAC) 86 89 return new QMacPixmapData(type); 90 #elif defined(Q_WS_S60) 91 return new QS60PixmapData(type); 87 92 #else 88 93 #error QSimplePixmapDataFactory::create() not implemented … … 90 95 } 91 96 92 Q_GLOBAL_STATIC(QSimplePixmapDataFactory, factory) ;97 Q_GLOBAL_STATIC(QSimplePixmapDataFactory, factory) 93 98 94 99 #endif // !defined(Q_WS_QWS) -
trunk/src/gui/image/qpixmapdatafactory_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 66 66 class QPixmapData; 67 67 68 class Q _GUI_EXPORT QPixmapDataFactory68 class QPixmapDataFactory 69 69 { 70 70 public: -
trunk/src/gui/image/qpixmapfilter.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 53 53 #include "private/qpaintengineex_p.h" 54 54 #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 56 61 QT_BEGIN_NAMESPACE 57 62 … … 66 71 \class QPixmapFilter 67 72 \since 4.5 68 \ingroup multimedia73 \ingroup painting 69 74 70 75 \brief The QPixmapFilter class provides the basic functionality for … … 94 99 image. See QPixmapDropShadowFilter for more 95 100 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. 96 104 97 105 \value UserFilter The first filter type that can be used for … … 173 181 \class QPixmapConvolutionFilter 174 182 \since 4.5 175 \ingroup multimedia183 \ingroup painting 176 184 177 185 \brief The QPixmapConvolutionFilter class provides convolution … … 294 302 295 303 /*! 296 \reimp297 298 304 \internal 299 305 */ … … 402 408 yk++; 403 409 } 404 } 405 406 /*! 407 \reimp 408 410 delete[] fixedKernel; 411 } 412 413 /*! 409 414 \internal 410 415 */ … … 419 424 420 425 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; 422 427 QPixmapConvolutionFilter *convolutionFilter = static_cast<QPixmapConvolutionFilter*>(filter); 423 428 if (convolutionFilter) { … … 425 430 convolutionFilter->d_func()->convoluteAlpha = d->convoluteAlpha; 426 431 convolutionFilter->draw(painter, p, src, srcRect); 427 delete convolutionFilter;428 432 return; 429 433 } … … 477 481 painter->drawImage(p - offset, result); 478 482 } 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 509 class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate 510 { 511 public: 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 */ 524 QPixmapBlurFilter::QPixmapBlurFilter(QObject *parent) 525 : QPixmapFilter(*new QPixmapBlurFilterPrivate, BlurFilter, parent) 526 { 527 } 528 529 /*! 530 Destructor of pixmap blur filter. 531 532 \internal 533 */ 534 QPixmapBlurFilter::~QPixmapBlurFilter() 535 { 536 } 537 538 /*! 539 Sets the radius of the blur filter. Higher radius produces increased blurriness. 540 541 \internal 542 */ 543 void 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 */ 554 qreal 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 */ 575 void 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 */ 586 QGraphicsBlurEffect::BlurHints QPixmapBlurFilter::blurHints() const 587 { 588 Q_D(const QPixmapBlurFilter); 589 return d->hints; 590 } 591 592 const qreal radiusScale = qreal(2.5); 593 594 /*! 595 \internal 596 */ 597 QRectF 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 604 template <int shift> 605 inline 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 615 template<int aprec, int zprec> 616 inline 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 646 const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3); 647 648 template<int aprec, int zprec> 649 inline 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 657 template<int aprec, int zprec, bool alphaOnly> 658 inline 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 */ 705 template <int aprec, int zprec, bool alphaOnly> 706 void 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 774 Q_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 859 Q_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 886 Q_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 894 bool qt_scaleForTransform(const QTransform &transform, qreal *scale); 895 896 /*! 897 \internal 898 */ 899 void 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); 479 943 } 480 944 … … 521 985 \class QPixmapColorizeFilter 522 986 \since 4.5 523 \ingroup multimedia987 \ingroup painting 524 988 525 989 \brief The QPixmapColorizeFilter class provides colorizing … … 543 1007 public: 544 1008 QColor color; 1009 qreal strength; 1010 quint32 opaque : 1; 1011 quint32 alphaBlend : 1; 1012 quint32 padding : 30; 545 1013 }; 546 1014 … … 555 1023 : QPixmapFilter(*new QPixmapColorizeFilterPrivate, ColorizeFilter, parent) 556 1024 { 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; 558 1030 } 559 1031 … … 581 1053 582 1054 /*! 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 */ 1060 qreal 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 */ 1071 void 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 /*! 585 1080 \internal 586 1081 */ … … 589 1084 Q_D(const QPixmapColorizeFilter); 590 1085 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; 592 1087 QPixmapColorizeFilter *colorizeFilter = static_cast<QPixmapColorizeFilter*>(filter); 593 1088 if (colorizeFilter) { 594 1089 colorizeFilter->setColor(d->color); 1090 colorizeFilter->setStrength(d->strength); 595 1091 colorizeFilter->draw(painter, dest, src, srcRect); 596 delete colorizeFilter;597 1092 return; 598 1093 } 599 1094 600 1095 // falling back to raster implementation 1096 1097 if (!d->opaque) { 1098 painter->drawPixmap(dest, src, srcRect); 1099 return; 1100 } 601 1101 602 1102 QImage srcImage; … … 622 1122 destPainter.end(); 623 1123 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 624 1134 if (srcImage.hasAlphaChannel()) 625 1135 destImage.setAlphaChannel(srcImage.alphaChannel()); … … 632 1142 public: 633 1143 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) {} 638 1145 639 1146 QPointF offset; 1147 QColor color; 640 1148 qreal radius; 641 QColor color;642 643 QPixmapConvolutionFilter *convolution;644 1149 }; 645 1150 … … 647 1152 \class QPixmapDropShadowFilter 648 1153 \since 4.5 649 \ingroup multimedia1154 \ingroup painting 650 1155 651 1156 \brief The QPixmapDropShadowFilter class is a convenience class … … 685 1190 : QPixmapFilter(*new QPixmapDropShadowFilterPrivate, DropShadowFilter, parent) 686 1191 { 687 Q_D(QPixmapDropShadowFilter);688 d->convolution = new QPixmapConvolutionFilter;689 690 setBlurRadius(1);691 1192 } 692 1193 … … 698 1199 QPixmapDropShadowFilter::~QPixmapDropShadowFilter() 699 1200 { 700 Q_D(QPixmapDropShadowFilter);701 delete d->convolution;702 1201 } 703 1202 … … 729 1228 { 730 1229 Q_D(QPixmapDropShadowFilter); 731 732 1230 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);740 1231 } 741 1232 … … 805 1296 806 1297 /*! 807 \reimp808 809 1298 \internal 810 1299 */ … … 812 1301 { 813 1302 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 /*! 826 1307 \internal 827 1308 */ … … 832 1313 { 833 1314 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); 836 1328 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; 837 1341 838 1342 // blacken the image... 1343 tmpPainter.begin(&tmp); 839 1344 tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); 840 tmpPainter.fillRect( 0, 0, tmp.width(), tmp.height(), d->color);1345 tmpPainter.fillRect(tmp.rect(), d->color); 841 1346 tmpPainter.end(); 842 1347 843 1348 // draw the blurred drop shadow... 844 d->convolution->draw(p, pos + d->offset, tmp);1349 p->drawImage(pos, tmp); 845 1350 846 1351 // Draw the actual pixmap... 847 1352 p->drawPixmap(pos, px, src); 848 1353 } 1354 849 1355 QT_END_NAMESPACE 1356 1357 #endif //QT_NO_GRAPHICSEFFECT -
trunk/src/gui/image/qpixmapfilter_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 56 56 #include <QtCore/qnamespace.h> 57 57 #include <QtGui/qpixmap.h> 58 #include <QtGui/qgraphicseffect.h> 58 59 60 #ifndef QT_NO_GRAPHICSEFFECT 59 61 QT_BEGIN_HEADER 60 62 … … 79 81 ColorizeFilter, 80 82 DropShadowFilter, 83 BlurFilter, 81 84 82 85 UserFilter = 1024 … … 118 121 }; 119 122 123 class QPixmapBlurFilterPrivate; 124 125 class Q_GUI_EXPORT QPixmapBlurFilter : public QPixmapFilter 126 { 127 Q_OBJECT 128 Q_DECLARE_PRIVATE(QPixmapBlurFilter) 129 130 public: 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 143 private: 144 friend class QGLPixmapBlurFilter; 145 }; 146 120 147 class QPixmapColorizeFilterPrivate; 121 148 … … 130 157 void setColor(const QColor& color); 131 158 QColor color() const; 159 160 void setStrength(qreal strength); 161 qreal strength() const; 132 162 133 163 void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const; … … 163 193 QT_END_HEADER 164 194 195 #endif //QT_NO_GRAPHICSEFFECT 165 196 #endif // QPIXMAPFILTER_H -
trunk/src/gui/image/qpnghandler.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 67 67 # define Q_INTERNAL_WIN_NO_THROW 68 68 #endif 69 70 // avoid going through QImage::scanLine() which calls detach 71 #define FAST_SCAN_LINE(data, bpl, y) (data + (y) * bpl) 69 72 70 73 /* … … 172 175 return; 173 176 } 174 image.set NumColors(2);177 image.setColorCount(2); 175 178 image.setColor(1, qRgb(0,0,0)); 176 179 image.setColor(0, qRgb(255,255,255)); … … 200 203 return; 201 204 } 202 image.set NumColors(ncols);205 image.setColorCount(ncols); 203 206 for (int i=0; i<ncols; i++) { 204 207 int c = i*255/(ncols-1); … … 206 209 } 207 210 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) 208 212 const int g = info_ptr->trans_values.gray; 213 #else 214 const int g = info_ptr->trans_color.gray; 215 #endif 209 216 if (g < ncols) { 210 217 image.setColor(g, 0); … … 227 234 return; 228 235 } 229 image.set NumColors(info_ptr->num_palette);236 image.setColorCount(info_ptr->num_palette); 230 237 int i = 0; 231 238 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { … … 235 242 info_ptr->palette[i].green, 236 243 info_ptr->palette[i].blue, 244 #if PNG_LIBPNG_VER_MAJOR < 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR < 4) 237 245 info_ptr->trans[i] 246 #else 247 info_ptr->trans_alpha[i] 248 #endif 238 249 ) 239 250 ); … … 501 512 if (color_type == PNG_COLOR_TYPE_PALETTE 502 513 && outImage->format() == QImage::Format_Indexed8) { 503 int color_table_size = outImage-> numColors();514 int color_table_size = outImage->colorCount(); 504 515 for (int y=0; y<(int)height; ++y) { 505 uchar *p = outImage->scanLine(y);516 uchar *p = FAST_SCAN_LINE(data, bpl, y); 506 517 uchar *end = p + width; 507 518 while (p < end) { … … 755 766 png_colorp palette = 0; 756 767 png_bytep copy_trans = 0; 757 if (image. numColors()) {768 if (image.colorCount()) { 758 769 // Paletted 759 int num_palette = image. numColors();770 int num_palette = image.colorCount(); 760 771 palette = new png_color[num_palette]; 761 772 png_set_PLTE(png_ptr, info_ptr, palette, num_palette); … … 845 856 0, 0, 0); 846 857 847 const uchar *data = image.bits();858 const uchar *data = (static_cast<const QImage *>(&image))->bits(); 848 859 int bpl = image.bytesPerLine(); 849 860 row_pointers = new png_bytep[height]; … … 957 968 { 958 969 if (option == Gamma) 959 d->gamma = value.to Double();970 d->gamma = value.toFloat(); 960 971 else if (option == Quality) 961 972 d->quality = value.toInt(); -
trunk/src/gui/image/qpnghandler_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qppmhandler.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 81 81 continue; 82 82 else if (c == '#') 83 d->readLine(buf, buflen);83 (void)d->readLine(buf, buflen); 84 84 else 85 85 break; … … 243 243 244 244 if (nbits == 1) { // bitmap 245 outImage->set NumColors(2);245 outImage->setColorCount(2); 246 246 outImage->setColor(0, qRgb(255,255,255)); // white 247 247 outImage->setColor(1, qRgb(0,0,0)); // black 248 248 } else if (nbits == 8) { // graymap 249 outImage->set NumColors(maxc+1);249 outImage->setColorCount(maxc+1); 250 250 for (int i=0; i<=maxc; i++) 251 251 outImage->setColor(i, qRgb(i*255/maxc,i*255/maxc,i*255/maxc)); … … 265 265 266 266 if (format == "pbm") { 267 image = image.convertToFormat(QImage::Format_Mono LSB);267 image = image.convertToFormat(QImage::Format_Mono); 268 268 } else if (image.depth() == 1) { 269 269 image = image.convertToFormat(QImage::Format_Indexed8); … … 288 288 } 289 289 290 if (image.depth() == 1 && image. numColors() == 2) {290 if (image.depth() == 1 && image.colorCount() == 2) { 291 291 if (qGray(image.color(0)) < qGray(image.color(1))) { 292 292 // 0=dark/black, 1=light/white - invert -
trunk/src/gui/image/qppmhandler_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qxbmhandler.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 136 136 } 137 137 138 outImage->set NumColors(2);138 outImage->setColorCount(2); 139 139 outImage->setColor(0, qRgb(255,255,255)); // white 140 140 outImage->setColor(1, qRgb(0,0,0)); // black -
trunk/src/gui/image/qxbmhandler_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/src/gui/image/qxpmhandler.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 896 896 return false; 897 897 } 898 image.set NumColors(ncols);898 image.setColorCount(ncols); 899 899 } 900 900 … … 1147 1147 s << "/* XPM */" << endl 1148 1148 << "static char *" << fbname(fileName) << "[]={" << endl 1149 << "\"" << w << " " << h << " " << ncolors << " " << cpp << "\"";1149 << '\"' << w << ' ' << h << ' ' << ncolors << ' ' << cpp << '\"'; 1150 1150 1151 1151 // write palette … … 1163 1163 qBlue(color)); 1164 1164 ++c; 1165 s << ","<< endl << line;1165 s << ',' << endl << line; 1166 1166 } 1167 1167 … … 1185 1185 } 1186 1186 } 1187 s << "," << endl << "\"" << line << "\"";1187 s << ',' << endl << '\"' << line << '\"'; 1188 1188 } 1189 1189 s << "};" << endl; -
trunk/src/gui/image/qxpmhandler_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 **
Note:
See TracChangeset
for help on using the changeset viewer.