summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qbitmap.cpp2
-rw-r--r--src/gui/image/qbmphandler.cpp22
-rw-r--r--src/gui/image/qicon.cpp2
-rw-r--r--src/gui/image/qicon_p.h3
-rw-r--r--src/gui/image/qiconloader.cpp16
-rw-r--r--src/gui/image/qiconloader_p.h3
-rw-r--r--src/gui/image/qimage.cpp163
-rw-r--r--src/gui/image/qimage.h9
-rw-r--r--src/gui/image/qimagepixmapcleanuphooks.cpp54
-rw-r--r--src/gui/image/qimagepixmapcleanuphooks_p.h21
-rw-r--r--src/gui/image/qnativeimage.cpp10
-rw-r--r--src/gui/image/qpixmap.cpp129
-rw-r--r--src/gui/image/qpixmap.h3
-rw-r--r--src/gui/image/qpixmap_mac.cpp34
-rw-r--r--src/gui/image/qpixmap_mac_p.h2
-rw-r--r--src/gui/image/qpixmap_qws.cpp15
-rw-r--r--src/gui/image/qpixmap_raster.cpp30
-rw-r--r--src/gui/image/qpixmap_raster_p.h2
-rw-r--r--src/gui/image/qpixmap_s60.cpp92
-rw-r--r--src/gui/image/qpixmap_s60_p.h2
-rw-r--r--src/gui/image/qpixmap_win.cpp3
-rw-r--r--src/gui/image/qpixmap_x11.cpp43
-rw-r--r--src/gui/image/qpixmap_x11_p.h3
-rw-r--r--src/gui/image/qpixmapcache.cpp1
-rw-r--r--src/gui/image/qpixmapdata.cpp28
-rw-r--r--src/gui/image/qpixmapdata_p.h12
-rw-r--r--src/gui/image/qpixmapfilter.cpp116
-rw-r--r--src/gui/image/qpixmapfilter_p.h15
-rw-r--r--src/gui/image/qpnghandler.cpp12
-rw-r--r--src/gui/image/qppmhandler.cpp6
-rw-r--r--src/gui/image/qxbmhandler.cpp2
-rw-r--r--src/gui/image/qxpmhandler.cpp2
32 files changed, 573 insertions, 284 deletions
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp
index e081735b69..4b8d4b889d 100644
--- a/src/gui/image/qbitmap.cpp
+++ b/src/gui/image/qbitmap.cpp
@@ -86,7 +86,7 @@ QT_BEGIN_NAMESPACE
object.
Just like the QPixmap class, QBitmap is optimized by the use of
- implicit data sharing. For more information, see the {Implicit
+ implicit data sharing. For more information, see the \l {Implicit
Data Sharing} documentation.
\sa QPixmap, QImage, QImageReader, QImageWriter
diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp
index 4b6fcba384..f3eb7c3fca 100644
--- a/src/gui/image/qbmphandler.cpp
+++ b/src/gui/image/qbmphandler.cpp
@@ -52,9 +52,9 @@ QT_BEGIN_NAMESPACE
static void swapPixel01(QImage *image) // 1-bpp: swap 0 and 1 pixels
{
int i;
- if (image->depth() == 1 && image->numColors() == 2) {
+ if (image->depth() == 1 && image->colorCount() == 2) {
register uint *p = (uint *)image->bits();
- int nbytes = image->numBytes();
+ int nbytes = image->byteCount();
for (i=0; i<nbytes/4; i++) {
*p = ~*p;
p++;
@@ -246,7 +246,7 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int
if (depth != 32) {
ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits;
- image.setNumColors(ncols);
+ image.setColorCount(ncols);
}
image.setDotsPerMeterX(bi.biXPelsPerMeter);
@@ -526,7 +526,7 @@ bool qt_write_dib(QDataStream &s, QImage image)
if (!d->isWritable())
return false;
- if (image.depth() == 8 && image.numColors() <= 16) {
+ if (image.depth() == 8 && image.colorCount() <= 16) {
bpl_bmp = (((bpl+1)/2+3)/4)*4;
nbits = 4;
} else if (image.depth() == 32) {
@@ -554,23 +554,23 @@ bool qt_write_dib(QDataStream &s, QImage image)
bi.biXPelsPerMeter = image.dotsPerMeterX() ? image.dotsPerMeterX()
: 2834; // 72 dpi default
bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834;
- bi.biClrUsed = image.numColors();
- bi.biClrImportant = image.numColors();
+ bi.biClrUsed = image.colorCount();
+ bi.biClrImportant = image.colorCount();
s << bi; // write info header
if (s.status() != QDataStream::Ok)
return false;
if (image.depth() != 32) { // write color table
- uchar *color_table = new uchar[4*image.numColors()];
+ uchar *color_table = new uchar[4*image.colorCount()];
uchar *rgb = color_table;
QVector<QRgb> c = image.colorTable();
- for (int i=0; i<image.numColors(); i++) {
+ for (int i=0; i<image.colorCount(); i++) {
*rgb++ = qBlue (c[i]);
*rgb++ = qGreen(c[i]);
*rgb++ = qRed (c[i]);
*rgb++ = 0;
}
- if (d->write((char *)color_table, 4*image.numColors()) == -1) {
+ if (d->write((char *)color_table, 4*image.colorCount()) == -1) {
delete [] color_table;
return false;
}
@@ -754,7 +754,7 @@ bool QBmpHandler::write(const QImage &img)
int bpl = image.bytesPerLine();
// Code partially repeated in qt_write_dib
- if (image.depth() == 8 && image.numColors() <= 16) {
+ if (image.depth() == 8 && image.colorCount() <= 16) {
bpl_bmp = (((bpl+1)/2+3)/4)*4;
} else if (image.depth() == 32) {
bpl_bmp = ((image.width()*24+31)/32)*4;
@@ -771,7 +771,7 @@ bool QBmpHandler::write(const QImage &img)
// write file header
bf.bfReserved1 = 0;
bf.bfReserved2 = 0;
- bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.numColors() * 4;
+ bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.colorCount() * 4;
bf.bfSize = bf.bfOffBits + bpl_bmp*image.height();
s << bf;
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index e0779a0f65..cff9cd207a 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -66,6 +66,7 @@
#include "private/qkde_p.h"
#endif
+#ifndef QT_NO_ICON
QT_BEGIN_NAMESPACE
/*!
@@ -1217,3 +1218,4 @@ QSize QIcon::pixmapSize(Size which)
*/
QT_END_NAMESPACE
+#endif //QT_NO_ICON
diff --git a/src/gui/image/qicon_p.h b/src/gui/image/qicon_p.h
index fc96a65cde..43a59a6c5c 100644
--- a/src/gui/image/qicon_p.h
+++ b/src/gui/image/qicon_p.h
@@ -60,6 +60,7 @@
#include <QtGui/qicon.h>
#include <QtGui/qiconengine.h>
+#ifndef QT_NO_ICON
QT_BEGIN_NAMESPACE
class QIconPrivate
@@ -134,5 +135,5 @@ private:
};
QT_END_NAMESPACE
-
+#endif //QT_NO_ICON
#endif // QICON_P_H
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 5412e11ce1..15af7a2e4b 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -38,7 +38,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
+#ifndef QT_NO_ICON
#include <private/qiconloader_p.h>
#include <private/qapplication_p.h>
@@ -61,7 +61,6 @@
#ifdef Q_WS_X11
#include <private/qt_x11_p.h>
-#include <private/gtksymbols_p.h>
#endif
QT_BEGIN_NAMESPACE
@@ -78,6 +77,8 @@ static QString fallbackTheme()
return X11->desktopVersion >= 4
? QString::fromLatin1("oxygen")
: QString::fromLatin1("crystalsvg");
+ } else {
+ return QLatin1String("hicolor");
}
#endif
return QString();
@@ -87,12 +88,16 @@ QIconLoader::QIconLoader() :
m_themeKey(1), m_supportsSvg(false)
{
m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
+ if (m_systemTheme.isEmpty())
+ m_systemTheme = fallbackTheme();
+#ifndef QT_NO_LIBRARY
QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
QLatin1String("/iconengines"),
Qt::CaseInsensitive);
if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
m_supportsSvg = true;
+#endif //QT_NO_LIBRARY
}
QIconLoader *QIconLoader::instance()
@@ -107,6 +112,8 @@ void QIconLoader::updateSystemTheme()
// Only change if this is not explicitly set by the user
if (m_userTheme.isEmpty()) {
QString theme = qt_guiPlatformPlugin()->systemIconThemeName();
+ if (theme.isEmpty())
+ theme = fallbackTheme();
if (theme != m_systemTheme) {
m_systemTheme = theme;
invalidateKey();
@@ -154,7 +161,7 @@ QIconTheme::QIconTheme(const QString &themeName)
break;
}
}
-
+#ifndef QT_NO_SETTINGS
if (themeIndex.exists()) {
const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
QStringListIterator keyIterator(indexReader.allKeys());
@@ -207,6 +214,7 @@ QIconTheme::QIconTheme(const QString &themeName)
if (!m_parents.contains(QLatin1String("hicolor")))
m_parents.append(QLatin1String("hicolor"));
}
+#endif //QT_NO_SETTINGS
}
QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName,
@@ -540,3 +548,5 @@ void QIconLoaderEngine::virtual_hook(int id, void *data)
}
QT_END_NAMESPACE
+
+#endif //QT_NO_ICON
diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h
index b152d46071..2a330d33ce 100644
--- a/src/gui/image/qiconloader_p.h
+++ b/src/gui/image/qiconloader_p.h
@@ -42,6 +42,7 @@
#ifndef QDESKTOPICON_P_H
#define QDESKTOPICON_P_H
+#ifndef QT_NO_ICON
//
// W A R N I N G
// -------------
@@ -185,3 +186,5 @@ private:
QT_END_NAMESPACE
#endif // QDESKTOPICON_P_H
+
+#endif //QT_NO_ICON
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 9048387c32..ec8dd88c98 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -377,6 +377,9 @@ bool QImageData::checkForAlphaPixels() const
\note If you would like to load QImage objects in a static build of Qt,
refer to the \l{How To Create Qt Plugins#Static Plugins}{Plugin HowTo}.
+ \warning Painting on a QImage with the format
+ QImage::Format_Indexed8 is not supported.
+
\tableofcontents
\section1 Reading and Writing Image Files
@@ -446,7 +449,7 @@ bool QImageData::checkForAlphaPixels() const
to the pixel() function. The pixel() function returns the color
as a QRgb value indepedent of the image's format.
- In case of monochrome and 8-bit images, the numColors() and
+ In case of monochrome and 8-bit images, the colorCount() and
colorTable() functions provide information about the color
components used to store the image data: The colorTable() function
returns the image's entire color table. To obtain a single entry,
@@ -481,7 +484,7 @@ bool QImageData::checkForAlphaPixels() const
depths are 1 (monochrome), 8 and 32 (for more information see the
\l {QImage#Image Formats}{Image Formats} section).
- The format(), bytesPerLine(), and numBytes() functions provide
+ The format(), bytesPerLine(), and byteCount() functions provide
low-level information about the data stored in the image.
The cacheKey() function returns a number that uniquely
@@ -543,11 +546,7 @@ bool QImageData::checkForAlphaPixels() const
Each pixel stored in a QImage is represented by an integer. The
size of the integer varies depending on the format. QImage
supports several image formats described by the \l Format
- enum. The monochrome (1-bit), 8-bit and 32-bit images are
- available in all versions of Qt. In addition Qt for Embedded Linux
- also supports 2-bit, 4-bit, and 16-bit images. For more information
- about the Qt Extended specific formats, see the documentation of the \l
- Format enum.
+ enum.
Monochrome images are stored using 1-bit indexes into a color table
with at most two colors. There are two different types of
@@ -624,7 +623,7 @@ bool QImageData::checkForAlphaPixels() const
\o Sets the color table used to translate color indexes. Only
monochrome and 8-bit formats.
\row
- \o setNumColors()
+ \o setColorCount()
\o Resizes the color table. Only monochrome and 8-bit formats.
\endtable
@@ -704,9 +703,20 @@ bool QImageData::checkForAlphaPixels() const
packed with the most significant bit (MSB) first.
\value Format_MonoLSB The image is stored using 1-bit per pixel. Bytes are
packed with the less significant bit (LSB) first.
- \value Format_Indexed8 The image is stored using 8-bit indexes into a colormap.
+
+ \value Format_Indexed8 The image is stored using 8-bit indexes
+ into a colormap. \warning Drawing into a
+ QImage with Indexed8 format is not
+ supported.
+
\value Format_RGB32 The image is stored using a 32-bit RGB format (0xffRRGGBB).
- \value Format_ARGB32 The image is stored using a 32-bit ARGB format (0xAARRGGBB).
+
+ \value Format_ARGB32 The image is stored using a 32-bit ARGB
+ format (0xAARRGGBB). \warning Do not
+ render into ARGB32 images using
+ QPainter. Format_ARGB32_Premultiplied is
+ significantly faster.
+
\value Format_ARGB32_Premultiplied The image is stored using a premultiplied 32-bit
ARGB format (0xAARRGGBB), i.e. the red,
green, and blue channels are multiplied
@@ -715,7 +725,9 @@ bool QImageData::checkForAlphaPixels() const
undefined.) Certain operations (such as image composition
using alpha blending) are faster using premultiplied ARGB32
than with plain ARGB32.
+
\value Format_RGB16 The image is stored using a 16-bit RGB format (5-6-5).
+
\value Format_ARGB8565_Premultiplied The image is stored using a
premultiplied 24-bit ARGB format (8-5-6-5).
\value Format_RGB666 The image is stored using a 24-bit RGB format (6-6-6).
@@ -894,7 +906,7 @@ QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QIm
If \a format is an indexed color format, the image color table is
initially empty and must be sufficiently expanded with
- setNumColors() or setColorTable() before the image is used.
+ setColorCount() or setColorTable() before the image is used.
*/
QImage::QImage(uchar* data, int width, int height, Format format)
: QPaintDevice()
@@ -916,7 +928,7 @@ QImage::QImage(uchar* data, int width, int height, Format format)
If \a format is an indexed color format, the image color table is
initially empty and must be sufficiently expanded with
- setNumColors() or setColorTable() before the image is used.
+ setColorCount() or setColorTable() before the image is used.
Unlike the similar QImage constructor that takes a non-const data buffer,
this version will never alter the contents of the buffer. For example,
@@ -942,7 +954,7 @@ QImage::QImage(const uchar* data, int width, int height, Format format)
If \a format is an indexed color format, the image color table is
initially empty and must be sufficiently expanded with
- setNumColors() or setColorTable() before the image is used.
+ setColorCount() or setColorTable() before the image is used.
*/
QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format)
:QPaintDevice()
@@ -962,7 +974,7 @@ QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format form
If \a format is an indexed color format, the image color table is
initially empty and must be sufficiently expanded with
- setNumColors() or setColorTable() before the image is used.
+ setColorCount() or setColorTable() before the image is used.
Unlike the similar QImage constructor that takes a non-const data buffer,
this version will never alter the contents of the buffer. For example,
@@ -1114,7 +1126,7 @@ QImage::QImage(const QImage &image)
Use the constructor that accepts a width, a height and a format
(i.e. specifying the depth and bit order), in combination with the
- setNumColors() function, instead.
+ setColorCount() function, instead.
\oldcode
QImage image(width, height, depth, numColors);
@@ -1123,15 +1135,15 @@ QImage::QImage(const QImage &image)
// For 8 bit images the default number of colors is 256. If
// another number of colors is required it can be specified
- // using the setNumColors() function.
- image.setNumColors(numColors);
+ // using the setColorCount() function.
+ image.setColorCount(numColors);
\endcode
*/
-QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder)
+QImage::QImage(int w, int h, int depth, int colorCount, Endian bitOrder)
: QPaintDevice()
{
- d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), numColors);
+ d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), colorCount);
}
/*!
@@ -1140,7 +1152,7 @@ QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder)
Use the constructor that accepts a size and a format
(i.e. specifying the depth and bit order), in combination with the
- setNumColors() function, instead.
+ setColorCount() function, instead.
\oldcode
QSize mySize(width, height);
@@ -1151,8 +1163,8 @@ QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder)
// For 8 bit images the default number of colors is 256. If
// another number of colors is required it can be specified
- // using the setNumColors() function.
- image.setNumColors(numColors);
+ // using the setColorCount() function.
+ image.setColorCount(numColors);
\endcode
*/
QImage::QImage(const QSize& size, int depth, int numColors, Endian bitOrder)
@@ -1220,7 +1232,7 @@ QImage::QImage(uchar* data, int w, int h, int depth, const QRgb* colortable, int
for (int i = 0; i < numColors; ++i)
d->colortable[i] = colortable[i];
} else if (numColors) {
- setNumColors(numColors);
+ setColorCount(numColors);
}
}
@@ -1271,7 +1283,7 @@ QImage::QImage(uchar* data, int w, int h, int depth, int bpl, const QRgb* colort
for (int i = 0; i < numColors; ++i)
d->colortable[i] = colortable[i];
} else if (numColors) {
- setNumColors(numColors);
+ setColorCount(numColors);
}
}
#endif // Q_WS_QWS
@@ -1580,17 +1592,31 @@ int QImage::depth() const
}
/*!
+ \obsolete
\fn int QImage::numColors() const
Returns the size of the color table for the image.
- Notice that numColors() returns 0 for 32-bpp images because these
+ \sa setColorCount()
+*/
+int QImage::numColors() const
+{
+ return d ? d->colortable.size() : 0;
+}
+
+/*!
+ \since 4.6
+ \fn int QImage::colorCount() const
+
+ Returns the size of the color table for the image.
+
+ Notice that colorCount() returns 0 for 32-bpp images because these
images do not use color tables, but instead encode pixel values as
ARGB quadruplets.
- \sa setNumColors(), {QImage#Image Information}{Image Information}
+ \sa setColorCount(), {QImage#Image Information}{Image Information}
*/
-int QImage::numColors() const
+int QImage::colorCount() const
{
return d ? d->colortable.size() : 0;
}
@@ -1699,7 +1725,7 @@ void QImage::setColorTable(const QVector<QRgb> colors)
Returns a list of the colors contained in the image's color table,
or an empty list if the image does not have a color table
- \sa setColorTable(), numColors(), color()
+ \sa setColorTable(), colorCount(), color()
*/
QVector<QRgb> QImage::colorTable() const
{
@@ -1708,12 +1734,24 @@ QVector<QRgb> QImage::colorTable() const
/*!
+ \obsolete
+ Returns the number of bytes occupied by the image data.
+
+ \sa byteCount()
+*/
+int QImage::numBytes() const
+{
+ return d ? d->nbytes : 0;
+}
+
+/*!
+ \since 4.6
Returns the number of bytes occupied by the image data.
\sa bytesPerLine(), bits(), {QImage#Image Information}{Image
Information}
*/
-int QImage::numBytes() const
+int QImage::byteCount() const
{
return d ? d->nbytes : 0;
}
@@ -1721,7 +1759,7 @@ int QImage::numBytes() const
/*!
Returns the number of bytes per image scanline.
- This is equivalent to numBytes()/ height().
+ This is equivalent to byteCount() / height().
\sa scanLine()
*/
@@ -1744,7 +1782,7 @@ int QImage::bytesPerLine() const
*/
QRgb QImage::color(int i) const
{
- Q_ASSERT(i < numColors());
+ Q_ASSERT(i < colorCount());
return d ? d->colortable.at(i) : QRgb(uint(-1));
}
@@ -1755,9 +1793,9 @@ QRgb QImage::color(int i) const
given to \a colorValue. The color value is an ARGB quadruplet.
If \a index is outside the current size of the color table, it is
- expanded with setNumColors().
+ expanded with setColorCount().
- \sa color(), numColors(), setColorTable(), {QImage#Pixel Manipulation}{Pixel
+ \sa color(), colorCount(), setColorTable(), {QImage#Pixel Manipulation}{Pixel
Manipulation}
*/
void QImage::setColor(int i, QRgb c)
@@ -1775,7 +1813,7 @@ void QImage::setColor(int i, QRgb c)
return;
if (i >= d->colortable.size())
- setNumColors(i+1);
+ setColorCount(i+1);
d->colortable[i] = c;
d->has_alpha_clut |= (qAlpha(c) != 255);
}
@@ -1832,7 +1870,7 @@ const uchar *QImage::scanLine(int i) const
data, thus ensuring that this QImage is the only one using the
current return value.
- \sa scanLine(), numBytes()
+ \sa scanLine(), byteCount()
*/
uchar *QImage::bits()
{
@@ -2013,8 +2051,21 @@ void QImage::invertPixels(InvertMode mode)
#endif
/*!
+ \obsolete
Resizes the color table to contain \a numColors entries.
+ \sa setColorCount()
+*/
+
+void QImage::setNumColors(int numColors)
+{
+ setColorCount(numColors);
+}
+
+/*!
+ \since 4.6
+ Resizes the color table to contain \a colorCount entries.
+
If the color table is expanded, all the extra colors will be set to
transparent (i.e qRgba(0, 0, 0, 0)).
@@ -2022,14 +2073,14 @@ void QImage::invertPixels(InvertMode mode)
have entries for all the pixel/index values present in the image,
otherwise the results are undefined.
- \sa numColors(), colorTable(), setColor(), {QImage#Image
+ \sa colorCount(), colorTable(), setColor(), {QImage#Image
Transformations}{Image Transformations}
*/
-void QImage::setNumColors(int numColors)
+void QImage::setColorCount(int colorCount)
{
if (!d) {
- qWarning("QImage::setNumColors: null image");
+ qWarning("QImage::setColorCount: null image");
return;
}
@@ -2039,17 +2090,16 @@ void QImage::setNumColors(int numColors)
if (!d)
return;
- if (numColors == d->colortable.size())
+ if (colorCount == d->colortable.size())
return;
- if (numColors <= 0) { // use no color table
+ if (colorCount <= 0) { // use no color table
d->colortable = QVector<QRgb>();
return;
}
int nc = d->colortable.size();
- d->colortable.resize(numColors);
- for (int i = nc; i < numColors; ++i)
+ d->colortable.resize(colorCount);
+ for (int i = nc; i < colorCount; ++i)
d->colortable[i] = 0;
-
}
/*!
@@ -3662,7 +3712,7 @@ QRgb QImage::pixel(int x, int y) const
otherwise the parameter must be a QRgb value.
If \a position is not a valid coordinate pair in the image, or if
- \a index_or_rgb >= numColors() in the case of monochrome and
+ \a index_or_rgb >= colorCount() in the case of monochrome and
8-bit images, the result is undefined.
\warning This function is expensive due to the call of the internal
@@ -3823,7 +3873,7 @@ bool QImage::allGray() const
} else {
if (d->colortable.isEmpty())
return true;
- for (int i = 0; i < numColors(); i++)
+ for (int i = 0; i < colorCount(); i++)
if (!qIsGray(d->colortable.at(i)))
return false;
}
@@ -3850,7 +3900,7 @@ bool QImage::isGrayscale() const
case 16:
return allGray();
case 8: {
- for (int i = 0; i < numColors(); i++)
+ for (int i = 0; i < colorCount(); i++)
if (d->colortable.at(i) != qRgb(i,i,i))
return false;
return true;
@@ -4071,7 +4121,8 @@ QImage QImage::createAlphaMask(Qt::ImageConversionFlags flags) const
}
QImage mask(d->width, d->height, Format_MonoLSB);
- dither_to_Mono(mask.d, d, flags, true);
+ if (!mask.isNull())
+ dither_to_Mono(mask.d, d, flags, true);
return mask;
}
@@ -4115,7 +4166,7 @@ QImage QImage::createHeuristicMask(bool clipTight) const
int w = width();
int h = height();
QImage m(w, h, Format_MonoLSB);
- m.setNumColors(2);
+ m.setColorCount(2);
m.setColor(0, QColor(Qt::color0).rgba());
m.setColor(1, QColor(Qt::color1).rgba());
m.fill(0xff);
@@ -5690,7 +5741,7 @@ QImage QImage::alphaChannel() const
int h = d->height;
QImage image(w, h, Format_Indexed8);
- image.setNumColors(256);
+ image.setColorCount(256);
// set up gray scale table.
for (int i=0; i<256; ++i)
@@ -5820,7 +5871,7 @@ static QImage smoothScaled(const QImage &source, int w, int h) {
static QImage rotated90(const QImage &image) {
QImage out(image.height(), image.width(), image.format());
- if (image.numColors() > 0)
+ if (image.colorCount() > 0)
out.setColorTable(image.colorTable());
int w = image.width();
int h = image.height();
@@ -5859,7 +5910,7 @@ static QImage rotated90(const QImage &image) {
break;
default:
for (int y=0; y<h; ++y) {
- if (image.numColors())
+ if (image.colorCount())
for (int x=0; x<w; ++x)
out.setPixel(h-y-1, x, image.pixelIndex(x, y));
else
@@ -5879,7 +5930,7 @@ static QImage rotated180(const QImage &image) {
static QImage rotated270(const QImage &image) {
QImage out(image.height(), image.width(), image.format());
- if (image.numColors() > 0)
+ if (image.colorCount() > 0)
out.setColorTable(image.colorTable());
int w = image.width();
int h = image.height();
@@ -5918,7 +5969,7 @@ static QImage rotated270(const QImage &image) {
break;
default:
for (int y=0; y<h; ++y) {
- if (image.numColors())
+ if (image.colorCount())
for (int x=0; x<w; ++x)
out.setPixel(y, w-x-1, image.pixelIndex(x, y));
else
@@ -6058,16 +6109,16 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode
if (dImage.d->colortable.size() < 256) {
// colors are left in the color table, so pick that one as transparent
dImage.d->colortable.append(0x0);
- memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.numBytes());
+ memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount());
} else {
- memset(dImage.bits(), 0, dImage.numBytes());
+ memset(dImage.bits(), 0, dImage.byteCount());
}
break;
case 1:
case 16:
case 24:
case 32:
- memset(dImage.bits(), 0x00, dImage.numBytes());
+ memset(dImage.bits(), 0x00, dImage.byteCount());
break;
}
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index 1ac56a7de0..d8809ef114 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -165,18 +165,21 @@ public:
QRect rect() const;
int depth() const;
- int numColors() const;
+ QT_DEPRECATED int numColors() const;
+ int colorCount() const;
QRgb color(int i) const;
void setColor(int i, QRgb c);
- void setNumColors(int);
+ QT_DEPRECATED void setNumColors(int);
+ void setColorCount(int);
bool allGray() const;
bool isGrayscale() const;
uchar *bits();
const uchar *bits() const;
- int numBytes() const;
+ QT_DEPRECATED int numBytes() const;
+ int byteCount() const;
uchar *scanLine(int);
const uchar *scanLine(int) const;
diff --git a/src/gui/image/qimagepixmapcleanuphooks.cpp b/src/gui/image/qimagepixmapcleanuphooks.cpp
index d08d3ef738..35322e9811 100644
--- a/src/gui/image/qimagepixmapcleanuphooks.cpp
+++ b/src/gui/image/qimagepixmapcleanuphooks.cpp
@@ -40,7 +40,8 @@
****************************************************************************/
#include "qimagepixmapcleanuphooks_p.h"
-#include "qpixmapdata_p.h"
+#include "private/qpixmapdata_p.h"
+#include "private/qimage_p.h"
QT_BEGIN_NAMESPACE
@@ -70,19 +71,30 @@ QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance()
return qt_image_and_pixmap_cleanup_hooks;
}
-void QImagePixmapCleanupHooks::addPixmapHook(_qt_pixmap_cleanup_hook_pm hook)
+void QImagePixmapCleanupHooks::addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
{
- pixmapHooks.append(hook);
+ pixmapModificationHooks.append(hook);
}
+void QImagePixmapCleanupHooks::addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
+{
+ pixmapDestructionHooks.append(hook);
+}
+
+
void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook)
{
imageHooks.append(hook);
}
-void QImagePixmapCleanupHooks::removePixmapHook(_qt_pixmap_cleanup_hook_pm hook)
+void QImagePixmapCleanupHooks::removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
{
- pixmapHooks.removeAll(hook);
+ pixmapModificationHooks.removeAll(hook);
+}
+
+void QImagePixmapCleanupHooks::removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
+{
+ pixmapDestructionHooks.removeAll(hook);
}
void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
@@ -91,18 +103,29 @@ void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
}
-void QImagePixmapCleanupHooks::executePixmapHooks(QPixmap* pm)
+void QImagePixmapCleanupHooks::executePixmapModificationHooks(QPixmap* pm)
{
- for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->pixmapHooks.count(); ++i)
- qt_image_and_pixmap_cleanup_hooks->pixmapHooks[i](pm);
+ Q_ASSERT(qt_image_and_pixmap_cleanup_hooks);
+ for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->pixmapModificationHooks.count(); ++i)
+ qt_image_and_pixmap_cleanup_hooks->pixmapModificationHooks[i](pm);
if (qt_pixmap_cleanup_hook_64)
qt_pixmap_cleanup_hook_64(pm->cacheKey());
}
+void QImagePixmapCleanupHooks::executePixmapDestructionHooks(QPixmap* pm)
+{
+ Q_ASSERT(qt_image_and_pixmap_cleanup_hooks);
+ for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->pixmapDestructionHooks.count(); ++i)
+ qt_image_and_pixmap_cleanup_hooks->pixmapDestructionHooks[i](pm);
+
+ if (qt_pixmap_cleanup_hook_64)
+ qt_pixmap_cleanup_hook_64(pm->cacheKey());
+}
void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
{
+ Q_ASSERT(qt_image_and_pixmap_cleanup_hooks);
for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->imageHooks.count(); ++i)
qt_image_and_pixmap_cleanup_hooks->imageHooks[i](key);
@@ -110,4 +133,19 @@ void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
qt_image_cleanup_hook_64(key);
}
+void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
+{
+ enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
+}
+
+void QImagePixmapCleanupHooks::enableCleanupHooks(QPixmapData *pixmapData)
+{
+ pixmapData->is_cached = true;
+}
+
+void QImagePixmapCleanupHooks::enableCleanupHooks(const QImage &image)
+{
+ const_cast<QImage &>(image).data_ptr()->is_cached = true;
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/image/qimagepixmapcleanuphooks_p.h b/src/gui/image/qimagepixmapcleanuphooks_p.h
index dd2d0f7716..9e490d701c 100644
--- a/src/gui/image/qimagepixmapcleanuphooks_p.h
+++ b/src/gui/image/qimagepixmapcleanuphooks_p.h
@@ -70,18 +70,31 @@ public:
static QImagePixmapCleanupHooks *instance();
- void addPixmapHook(_qt_pixmap_cleanup_hook_pm);
+ static void enableCleanupHooks(const QImage &image);
+ static void enableCleanupHooks(const QPixmap &pixmap);
+ static void enableCleanupHooks(QPixmapData *pixmapData);
+
+ // Gets called when a pixmap is about to be modified:
+ void addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm);
+
+ // Gets called when a pixmap is about to be destroyed:
+ void addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm);
+
+ // Gets called when an image is about to be modified or destroyed:
void addImageHook(_qt_image_cleanup_hook_64);
- void removePixmapHook(_qt_pixmap_cleanup_hook_pm);
+ void removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm);
+ void removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm);
void removeImageHook(_qt_image_cleanup_hook_64);
- static void executePixmapHooks(QPixmap*);
+ static void executePixmapModificationHooks(QPixmap*);
+ static void executePixmapDestructionHooks(QPixmap*);
static void executeImageHooks(qint64 key);
private:
QList<_qt_image_cleanup_hook_64> imageHooks;
- QList<_qt_pixmap_cleanup_hook_pm> pixmapHooks;
+ QList<_qt_pixmap_cleanup_hook_pm> pixmapModificationHooks;
+ QList<_qt_pixmap_cleanup_hook_pm> pixmapDestructionHooks;
};
QT_END_NAMESPACE
diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp
index 88faea8ff6..e4ea2e9cad 100644
--- a/src/gui/image/qnativeimage.cpp
+++ b/src/gui/image/qnativeimage.cpp
@@ -199,10 +199,12 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format,bool /*
shmctl(xshminfo.shmid, IPC_RMID, 0);
return;
}
- xshmpm = XShmCreatePixmap(X11->display, DefaultRootWindow(X11->display), xshmimg->data,
- &xshminfo, width, height, dd);
- if (!xshmpm) {
- qWarning() << "QNativeImage: Unable to create shared Pixmap.";
+ if (X11->use_mitshm_pixmaps) {
+ xshmpm = XShmCreatePixmap(X11->display, DefaultRootWindow(X11->display), xshmimg->data,
+ &xshminfo, width, height, dd);
+ if (!xshmpm) {
+ qWarning() << "QNativeImage: Unable to create shared Pixmap.";
+ }
}
}
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index 21fb23e5f1..a5416684dd 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -113,13 +113,10 @@ void QPixmap::init(int w, int h, Type type)
void QPixmap::init(int w, int h, int type)
{
- QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
- if (gs)
- data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type));
+ if ((w > 0 && h > 0) || type == QPixmapData::BitmapType)
+ data = QPixmapData::create(w, h, (QPixmapData::PixelType) type);
else
- data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
-
- data->resize(w, h);
+ data = 0;
}
/*!
@@ -307,7 +304,7 @@ QPixmap::QPixmap(const char * const xpm[])
QImage image(xpm);
if (!image.isNull()) {
- if (data->pixelType() == QPixmapData::BitmapType)
+ if (data && data->pixelType() == QPixmapData::BitmapType)
*this = QBitmap::fromImage(image);
else
*this = fromImage(image);
@@ -322,8 +319,9 @@ QPixmap::QPixmap(const char * const xpm[])
QPixmap::~QPixmap()
{
- if (data->is_cached && data->ref == 1)
- QImagePixmapCleanupHooks::executePixmapHooks(this);
+ Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again
+ if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns
+ QImagePixmapCleanupHooks::executePixmapDestructionHooks(this);
}
/*!
@@ -361,13 +359,7 @@ QPixmap QPixmap::copy(const QRect &rect) const
const QRect r = rect.isEmpty() ? QRect(0, 0, width(), height()) : rect;
- QPixmapData *d;
- QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
- if (gs)
- d = gs->createPixmapData(data->pixelType());
- else
- d = QGraphicsSystem::createDefaultPixmapData(data->pixelType());
-
+ QPixmapData *d = data->createCompatiblePixmapData();
d->copy(data.data(), r);
return QPixmap(d);
}
@@ -475,9 +467,11 @@ QPixmap::operator QVariant() const
conversion fails.
If the pixmap has 1-bit depth, the returned image will also be 1
- bit deep. If the pixmap has 2- to 8-bit depth, the returned image
- has 8-bit depth. If the pixmap has greater than 8-bit depth, the
- returned image has 32-bit depth.
+ bit deep. Images with more bits will be returned in a format
+ closely represents the underlying system. Usually this will be
+ QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and
+ QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without
+ alpha.
Note that for the moment, alpha masks on monochrome images are
ignored.
@@ -547,7 +541,7 @@ bool QPixmap::isQBitmap() const
*/
bool QPixmap::isNull() const
{
- return data->isNull();
+ return !data || data->isNull();
}
/*!
@@ -559,7 +553,7 @@ bool QPixmap::isNull() const
*/
int QPixmap::width() const
{
- return data->width();
+ return data ? data->width() : 0;
}
/*!
@@ -571,7 +565,7 @@ int QPixmap::width() const
*/
int QPixmap::height() const
{
- return data->height();
+ return data ? data->height() : 0;
}
/*!
@@ -584,7 +578,7 @@ int QPixmap::height() const
*/
QSize QPixmap::size() const
{
- return QSize(data->width(), data->height());
+ return data ? QSize(data->width(), data->height()) : QSize();
}
/*!
@@ -596,7 +590,7 @@ QSize QPixmap::size() const
*/
QRect QPixmap::rect() const
{
- return QRect(0, 0, data->width(), data->height());
+ return data ? QRect(0, 0, data->width(), data->height()) : QRect();
}
/*!
@@ -612,7 +606,7 @@ QRect QPixmap::rect() const
*/
int QPixmap::depth() const
{
- return data->depth();
+ return data ? data->depth() : 0;
}
/*!
@@ -642,16 +636,16 @@ void QPixmap::resize_helper(const QSize &s)
return;
// Create new pixmap
- QPixmap pm(QSize(w, h), data->type);
+ QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType);
bool uninit = false;
#if defined(Q_WS_X11)
- QX11PixmapData *x11Data = data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0;
+ QX11PixmapData *x11Data = data && data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0;
if (x11Data) {
pm.x11SetScreen(x11Data->xinfo.screen());
uninit = x11Data->flags & QX11PixmapData::Uninitialized;
}
#elif defined(Q_WS_MAC)
- QMacPixmapData *macData = data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
+ QMacPixmapData *macData = data && data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
if (macData)
uninit = macData->uninit;
#endif
@@ -731,6 +725,9 @@ void QPixmap::setMask(const QBitmap &mask)
return;
}
+ if (isNull())
+ return;
+
if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask
return;
@@ -829,11 +826,14 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
QFileInfo info(fileName);
QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') +
- QString::number(info.size()) + QLatin1Char('_') + QString::number(data->pixelType());
+ QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType);
if (QPixmapCache::find(key, *this))
return true;
+ if (!data)
+ data = QPixmapData::create(0, 0, QPixmapData::PixmapType);
+
if (data->fromFile(fileName, format, flags)) {
QPixmapCache::insert(key, *this);
return true;
@@ -863,6 +863,12 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
{
+ if (len == 0 || buf == 0)
+ return false;
+
+ if (!data)
+ data = QPixmapData::create(0, 0, QPixmapData::PixmapType);
+
return data->fromData(buf, len, format, flags);
}
@@ -947,6 +953,9 @@ bool QPixmap::doImageIO(QImageWriter *writer, int quality) const
/*!
Fills the pixmap with the given \a color.
+ The effect of this function is undefined when the pixmap is
+ being painted on.
+
\sa {QPixmap#Pixmap Transformations}{Pixmap Transformations}
*/
@@ -955,7 +964,24 @@ void QPixmap::fill(const QColor &color)
if (isNull())
return;
- detach();
+ // Some people are probably already calling fill while a painter is active, so to not break
+ // their programs, only print a warning and return when the fill operation could cause a crash.
+ if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) {
+ qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on");
+ return;
+ }
+
+ if (data->ref == 1) {
+ // detach() will also remove this pixmap from caches, so
+ // it has to be called even when ref == 1.
+ detach();
+ } else {
+ // Don't bother to make a copy of the data object, since
+ // it will be filled with new pixel data anyway.
+ QPixmapData *d = data->createCompatiblePixmapData();
+ d->resize(data->width(), data->height());
+ data = d;
+ }
data->fill(color);
}
@@ -988,6 +1014,9 @@ int QPixmap::serialNumber() const
*/
qint64 QPixmap::cacheKey() const
{
+ if (isNull())
+ return 0;
+
int classKey = data->classId();
if (classKey >= 1024)
classKey = -(classKey >> 10);
@@ -1204,7 +1233,7 @@ QPixmap::QPixmap(const QImage& image)
QPixmap &QPixmap::operator=(const QImage &image)
{
- if (data->pixelType() == QPixmapData::BitmapType)
+ if (data && data->pixelType() == QPixmapData::BitmapType)
*this = QBitmap::fromImage(image);
else
*this = fromImage(image);
@@ -1234,7 +1263,7 @@ bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Color
*/
bool QPixmap::convertFromImage(const QImage &image, ColorMode mode)
{
- if (data->pixelType() == QPixmapData::BitmapType)
+ if (data && data->pixelType() == QPixmapData::BitmapType)
*this = QBitmap::fromImage(image, colorModeToFlags(mode));
else
*this = fromImage(image, colorModeToFlags(mode));
@@ -1321,7 +1350,7 @@ Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy,
bool QPixmap::isDetached() const
{
- return data->ref == 1;
+ return data && data->ref == 1;
}
/*! \internal
@@ -1663,10 +1692,10 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
identifies the contents of the QPixmap object.
The x11Info() function returns information about the configuration
- of the X display used to display the widget. The
- x11PictureHandle() function returns the X11 Picture handle of the
- pixmap for XRender support. Note that the two latter functions are
- only available on x11.
+ of the X display used by the screen to which the pixmap currently
+ belongs. The x11PictureHandle() function returns the X11 Picture
+ handle of the pixmap for XRender support. Note that the two latter
+ functions are only available on x11.
\endtable
@@ -1733,7 +1762,7 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
*/
bool QPixmap::hasAlpha() const
{
- return (data->hasAlphaChannel() || !data->mask().isNull());
+ return data && (data->hasAlphaChannel() || !data->mask().isNull());
}
/*!
@@ -1744,7 +1773,7 @@ bool QPixmap::hasAlpha() const
*/
bool QPixmap::hasAlphaChannel() const
{
- return data->hasAlphaChannel();
+ return data && data->hasAlphaChannel();
}
/*!
@@ -1752,7 +1781,7 @@ bool QPixmap::hasAlphaChannel() const
*/
int QPixmap::metric(PaintDeviceMetric metric) const
{
- return data->metric(metric);
+ return data ? data->metric(metric) : 0;
}
/*!
@@ -1824,7 +1853,7 @@ void QPixmap::setAlphaChannel(const QPixmap &alphaChannel)
*/
QPixmap QPixmap::alphaChannel() const
{
- return data->alphaChannel();
+ return data ? data->alphaChannel() : QPixmap();
}
/*!
@@ -1832,7 +1861,7 @@ QPixmap QPixmap::alphaChannel() const
*/
QPaintEngine *QPixmap::paintEngine() const
{
- return data->paintEngine();
+ return data ? data->paintEngine() : 0;
}
/*!
@@ -1847,7 +1876,7 @@ QPaintEngine *QPixmap::paintEngine() const
*/
QBitmap QPixmap::mask() const
{
- return data->mask();
+ return data ? data->mask() : QBitmap();
}
/*!
@@ -1898,6 +1927,9 @@ int QPixmap::defaultDepth()
*/
void QPixmap::detach()
{
+ if (!data)
+ return;
+
QPixmapData::ClassId id = data->classId();
if (id == QPixmapData::RasterClass) {
QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
@@ -1905,7 +1937,7 @@ void QPixmap::detach()
}
if (data->is_cached && data->ref == 1)
- QImagePixmapCleanupHooks::executePixmapHooks(this);
+ QImagePixmapCleanupHooks::executePixmapModificationHooks(this);
#if defined(Q_WS_MAC)
QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
@@ -2086,7 +2118,7 @@ QPixmapData* QPixmap::pixmapData() const
/*! \fn const QX11Info &QPixmap::x11Info() const
\bold{X11 only:} Returns information about the configuration of
- the X display used to display the widget.
+ the X display used by the screen to which the pixmap currently belongs.
\warning This function is only available on X11.
@@ -2120,6 +2152,13 @@ QPixmapData* QPixmap::pixmapData() const
*/
/*! \fn int QPixmap::numCols() const
+ \obsolete
+ \internal
+ \sa colorCount()
+*/
+
+/*! \fn int QPixmap::colorCount() const
+ \since 4.6
\internal
*/
diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h
index d11bd03565..d95b4eead8 100644
--- a/src/gui/image/qpixmap.h
+++ b/src/gui/image/qpixmap.h
@@ -185,7 +185,8 @@ public:
const uchar *qwsBits() const;
int qwsBytesPerLine() const;
QRgb *clut() const;
- int numCols() const;
+ QT_DEPRECATED int numCols() const;
+ int colorCount() const;
#elif defined(Q_WS_MAC)
Qt::HANDLE macQDHandle() const;
Qt::HANDLE macQDAlphaHandle() const;
diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp
index de532fd5a8..6175931f80 100644
--- a/src/gui/image/qpixmap_mac.cpp
+++ b/src/gui/image/qpixmap_mac.cpp
@@ -166,6 +166,11 @@ QMacPixmapData::QMacPixmapData(PixelType type)
{
}
+QPixmapData *QMacPixmapData::createCompatiblePixmapData() const
+{
+ return new QMacPixmapData(pixelType());
+}
+
#define BEST_BYTE_ALIGNMENT 16
#define COMPTUE_BEST_BYTES_PER_ROW(bpr) \
(((bpr) + (BEST_BYTE_ALIGNMENT - 1)) & ~(BEST_BYTE_ALIGNMENT - 1))
@@ -243,7 +248,7 @@ void QMacPixmapData::fromImage(const QImage &img,
} else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) {
conv8 = d == 1; // native depth wanted
} else if (d == 1) {
- if (image.numColors() == 2) {
+ if (image.colorCount() == 2) {
QRgb c0 = image.color(0); // Auto: convert to best
QRgb c1 = image.color(1);
conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255);
@@ -300,11 +305,15 @@ void QMacPixmapData::fromImage(const QImage &img,
}
break;
}
- case QImage::Format_Indexed8:
- for (int x = 0; x < w; ++x) {
- *(drow+x) = PREMUL(image.color(*(srow + x)));
+ case QImage::Format_Indexed8: {
+ int numColors = image.numColors();
+ if (numColors > 0) {
+ for (int x = 0; x < w; ++x) {
+ int index = *(srow + x);
+ *(drow+x) = PREMUL(image.color(qMin(index, numColors)));
+ }
}
- break;
+ } break;
case QImage::Format_RGB32:
for (int x = 0; x < w; ++x)
*(drow+x) = *(((quint32*)srow) + x) | 0xFF000000;
@@ -330,7 +339,7 @@ void QMacPixmapData::fromImage(const QImage &img,
bool alphamap = image.depth() == 32;
if (sfmt == QImage::Format_Indexed8) {
const QVector<QRgb> rgb = image.colorTable();
- for (int i = 0, count = image.numColors(); i < count; ++i) {
+ for (int i = 0, count = image.colorCount(); i < count; ++i) {
const int alpha = qAlpha(rgb[i]);
if (alpha != 0xff) {
alphamap = true;
@@ -346,13 +355,13 @@ void QMacPixmapData::fromImage(const QImage &img,
int get_index(QImage * qi,QRgb mycol)
{
int loopc;
- for(loopc=0;loopc<qi->numColors();loopc++) {
+ for(loopc=0;loopc<qi->colorCount();loopc++) {
if(qi->color(loopc)==mycol)
return loopc;
}
- qi->setNumColors(qi->numColors()+1);
- qi->setColor(qi->numColors(),mycol);
- return qi->numColors();
+ qi->setColorCount(qi->colorCount()+1);
+ qi->setColor(qi->colorCount(),mycol);
+ return qi->colorCount();
}
QImage QMacPixmapData::toImage() const
@@ -367,7 +376,7 @@ QImage QMacPixmapData::toImage() const
const uint sbpr = bytesPerRow;
if (format == QImage::Format_MonoLSB) {
image.fill(0);
- image.setNumColors(2);
+ image.setColorCount(2);
image.setColor(0, QColor(Qt::color0).rgba());
image.setColor(1, QColor(Qt::color1).rgba());
for (int y = 0; y < h; ++y) {
@@ -960,6 +969,9 @@ Qt::HANDLE QPixmap::macQDAlphaHandle() const
Qt::HANDLE QPixmap::macCGHandle() const
{
+ if (isNull())
+ return 0;
+
if (data->classId() == QPixmapData::MacClass) {
QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data());
if (!d->cg_data)
diff --git a/src/gui/image/qpixmap_mac_p.h b/src/gui/image/qpixmap_mac_p.h
index 528dd1f346..a3fb95f847 100644
--- a/src/gui/image/qpixmap_mac_p.h
+++ b/src/gui/image/qpixmap_mac_p.h
@@ -65,6 +65,8 @@ public:
QMacPixmapData(PixelType type);
~QMacPixmapData();
+ QPixmapData *createCompatiblePixmapData() const;
+
void resize(int width, int height);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp
index 6b4283ecc8..69626edb83 100644
--- a/src/gui/image/qpixmap_qws.cpp
+++ b/src/gui/image/qpixmap_qws.cpp
@@ -114,7 +114,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
QRgb* QPixmap::clut() const
{
- if (data->classId() == QPixmapData::RasterClass) {
+ if (data && data->classId() == QPixmapData::RasterClass) {
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.colorTable().data();
}
@@ -124,9 +124,14 @@ QRgb* QPixmap::clut() const
int QPixmap::numCols() const
{
- if (data->classId() == QPixmapData::RasterClass) {
+ return colorCount();
+}
+
+int QPixmap::colorCount() const
+{
+ if (data && data->classId() == QPixmapData::RasterClass) {
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
- return d->image.numColors();
+ return d->image.colorCount();
}
return 0;
@@ -134,7 +139,7 @@ int QPixmap::numCols() const
const uchar* QPixmap::qwsBits() const
{
- if (data->classId() == QPixmapData::RasterClass) {
+ if (data && data->classId() == QPixmapData::RasterClass) {
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.bits();
}
@@ -144,7 +149,7 @@ const uchar* QPixmap::qwsBits() const
int QPixmap::qwsBytesPerLine() const
{
- if (data->classId() == QPixmapData::RasterClass) {
+ if (data && data->classId() == QPixmapData::RasterClass) {
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.bytesPerLine();
}
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index ad68b07e96..1b01e6f3bb 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -55,6 +55,29 @@ QT_BEGIN_NAMESPACE
const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80 };
+QPixmap qt_toRasterPixmap(const QImage &image)
+{
+ QPixmapData *data =
+ new QRasterPixmapData(image.depth() == 1
+ ? QPixmapData::BitmapType
+ : QPixmapData::PixmapType);
+
+ data->fromImage(image, Qt::AutoColor);
+
+ return QPixmap(data);
+}
+
+QPixmap qt_toRasterPixmap(const QPixmap &pixmap)
+{
+ if (pixmap.isNull())
+ return QPixmap();
+
+ if (QPixmap(pixmap).data_ptr()->classId() == QPixmapData::RasterClass)
+ return pixmap;
+
+ return qt_toRasterPixmap(pixmap.toImage());
+}
+
QRasterPixmapData::QRasterPixmapData(PixelType type)
: QPixmapData(type, RasterClass)
{
@@ -64,6 +87,11 @@ QRasterPixmapData::~QRasterPixmapData()
{
}
+QPixmapData *QRasterPixmapData::createCompatiblePixmapData() const
+{
+ return new QRasterPixmapData(pixelType());
+}
+
void QRasterPixmapData::resize(int width, int height)
{
QImage::Format format;
@@ -91,7 +119,7 @@ void QRasterPixmapData::resize(int width, int height)
is_null = (w <= 0 || h <= 0);
if (pixelType() == BitmapType && !image.isNull()) {
- image.setNumColors(2);
+ image.setColorCount(2);
image.setColor(0, QColor(Qt::color0).rgba());
image.setColor(1, QColor(Qt::color1).rgba());
}
diff --git a/src/gui/image/qpixmap_raster_p.h b/src/gui/image/qpixmap_raster_p.h
index da0405e9f7..1553940cd8 100644
--- a/src/gui/image/qpixmap_raster_p.h
+++ b/src/gui/image/qpixmap_raster_p.h
@@ -68,6 +68,8 @@ public:
QRasterPixmapData(PixelType type);
~QRasterPixmapData();
+ QPixmapData *createCompatiblePixmapData() const;
+
void resize(int width, int height);
void fromFile(const QString &filename, Qt::ImageConversionFlags flags);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp
index 9ae8d7291d..17baa50dcf 100644
--- a/src/gui/image/qpixmap_s60.cpp
+++ b/src/gui/image/qpixmap_s60.cpp
@@ -4,7 +4,7 @@
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
-** This file is part of the QtGui of the Qt Toolkit.
+** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
@@ -73,27 +73,27 @@ const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
used to lock the global bitmap heap. Only used in
S60 v3.1 and S60 v3.2.
*/
+_LIT(KFBSERVLargeBitmapAccessName,"FbsLargeBitmapAccess");
class QSymbianFbsClient
{
public:
- QSymbianFbsClient() : heapLock(0), heapLocked(false)
+ QSymbianFbsClient() : heapLocked(false)
{
- QT_TRAP_THROWING(heapLock = new(ELeave) CFbsBitmap);
- heapLock->Create(TSize(0,0), S60->screenDevice()->DisplayMode());
+ heapLock.OpenGlobal(KFBSERVLargeBitmapAccessName);
}
~QSymbianFbsClient()
{
- delete heapLock;
+ heapLock.Close();
}
bool lockHeap()
{
bool wasLocked = heapLocked;
- if (heapLock && !heapLocked) {
- heapLock->LockHeap(ETrue);
+ if (heapLock.Handle() && !heapLocked) {
+ heapLock.Wait();
heapLocked = true;
}
@@ -104,8 +104,8 @@ public:
{
bool wasLocked = heapLocked;
- if (heapLock && heapLocked) {
- heapLock->UnlockHeap(ETrue);
+ if (heapLock.Handle() && heapLocked) {
+ heapLock.Signal();
heapLocked = false;
}
@@ -115,7 +115,7 @@ public:
private:
- CFbsBitmap *heapLock;
+ RMutex heapLock;
bool heapLocked;
};
@@ -169,7 +169,7 @@ public:
inline void beginDataAccess(CFbsBitmap *bitmap)
{
- if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3)
+ if (symbianVersion == QSysInfo::SV_9_2)
heapWasLocked = qt_symbianFbsClient()->lockHeap();
else
bitmap->LockHeap(ETrue);
@@ -177,7 +177,7 @@ public:
inline void endDataAccess(CFbsBitmap *bitmap)
{
- if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3) {
+ if (symbianVersion == QSysInfo::SV_9_2) {
if (!heapWasLocked)
qt_symbianFbsClient()->unlockHeap();
} else {
@@ -311,7 +311,7 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h)
CFbsBitmap *QPixmap::toSymbianCFbsBitmap() const
{
QPixmapData *data = pixmapData();
- if (data->isNull())
+ if (!data || data->isNull())
return 0;
return reinterpret_cast<CFbsBitmap*>(data->toNativeType(QPixmapData::FbsBitmap));
@@ -337,8 +337,9 @@ QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap)
if (!bitmap)
return QPixmap();
- QPixmap pixmap;
- pixmap.pixmapData()->fromNativeType(reinterpret_cast<void*>(bitmap), QPixmapData::FbsBitmap);
+ QScopedPointer<QS60PixmapData> data(new QS60PixmapData(QPixmapData::PixmapType));
+ data->fromNativeType(reinterpret_cast<void*>(bitmap), QPixmapData::FbsBitmap);
+ QPixmap pixmap(data.take());
return pixmap;
}
@@ -348,7 +349,8 @@ QS60PixmapData::QS60PixmapData(PixelType type) : QRasterPixmapData(type),
bitmapDevice(0),
bitmapGc(0),
pengine(0),
- bytes(0)
+ bytes(0),
+ formatLocked(false)
{
}
@@ -424,11 +426,12 @@ void QS60PixmapData::release()
}
/*!
- * Takes ownership of bitmap
+ * Takes ownership of bitmap. Used by window surface
*/
void QS60PixmapData::fromSymbianBitmap(CFbsBitmap* bitmap)
{
cfbsBitmap = bitmap;
+ formatLocked = true;
if(!initSymbianBitmapContext()) {
qWarning("Could not create CBitmapContext");
@@ -442,7 +445,7 @@ void QS60PixmapData::fromSymbianBitmap(CFbsBitmap* bitmap)
// Create default palette if needed
if (cfbsBitmap->DisplayMode() == EGray2) {
- image.setNumColors(2);
+ image.setColorCount(2);
image.setColor(0, QColor(Qt::color0).rgba());
image.setColor(1, QColor(Qt::color1).rgba());
@@ -496,11 +499,12 @@ void QS60PixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags
mode = EColor16MU;
break;
case QImage::Format_ARGB32_Premultiplied:
-#if !defined(__SERIES60_31__) && !defined(__S60_32__)
- mode = EColor16MAP;
- break;
-#endif
- destFormat = QImage::Format_ARGB32;
+ if (S60->supportsPremultipliedAlpha) {
+ mode = Q_SYMBIAN_ECOLOR16MAP;
+ break;
+ } else {
+ destFormat = QImage::Format_ARGB32;
+ }
// Fall through intended
case QImage::Format_ARGB32:
mode = EColor16MA;
@@ -524,13 +528,13 @@ void QS60PixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags
const uchar *sptr = const_cast<const QImage &>(sourceImage).bits();
symbianBitmapDataAccess->beginDataAccess(cfbsBitmap);
uchar *dptr = (uchar*)cfbsBitmap->DataAddress();
- Mem::Copy(dptr, sptr, sourceImage.numBytes());
+ Mem::Copy(dptr, sptr, sourceImage.byteCount());
symbianBitmapDataAccess->endDataAccess(cfbsBitmap);
UPDATE_BUFFER();
if (destFormat == QImage::Format_MonoLSB) {
- image.setNumColors(2);
+ image.setColorCount(2);
image.setColor(0, QColor(Qt::color0).rgba());
image.setColor(1, QColor(Qt::color1).rgba());
} else {
@@ -683,14 +687,19 @@ void QS60PixmapData::beginDataAccess()
uchar* newBytes = (uchar*)cfbsBitmap->DataAddress();
- if (newBytes == bytes)
- return;
+ TSize size = cfbsBitmap->SizeInPixels();
+ if (newBytes == bytes && image.width() == size.iWidth && image.height() == size.iHeight)
+ return;
bytes = newBytes;
TDisplayMode mode = cfbsBitmap->DisplayMode();
QImage::Format format = qt_TDisplayMode2Format(mode);
- TSize size = cfbsBitmap->SizeInPixels();
+ // On S60 3.1, premultiplied alpha pixels are stored in a bitmap with 16MA type.
+ // S60 window surface needs backing store pixmap for transparent window in ARGB32 format.
+ // In that case formatLocked is true.
+ if (!formatLocked && format == QImage::Format_ARGB32)
+ format = QImage::Format_ARGB32_Premultiplied; // pixel data is actually in premultiplied format
QVector<QRgb> savedColorTable;
if (!image.isNull())
@@ -747,9 +756,9 @@ QPixmap QPixmap::fromSymbianRSgImage(RSgImage *sgImage)
if (!sgImage)
return QPixmap();
- QPixmap pixmap;
- pixmap.pixmapData()->fromNativeType(reinterpret_cast<void*>(sgImage), QPixmapData::SgImage);
-
+ QScopedPointer<QS60PixmapData> data(new QS60PixmapData(QPixmapData::PixmapType));
+ data->fromNativeType(reinterpret_cast<void*>(sgImage), QPixmapData::SgImage);
+ QPixmap pixmap(data.take());
return pixmap;
}
@@ -794,8 +803,8 @@ void* QS60PixmapData::toNativeType(NativeType type)
bool needsCopy = false;
QSysInfo::SymbianVersion symbianVersion = QSysInfo::symbianVersion();
- if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3) {
- // Convert argb32_premultiplied to argb32 since Symbian 9.2 and Symbian 9.3 do
+ if (!(S60->supportsPremultipliedAlpha)) {
+ // Convert argb32_premultiplied to argb32 since Symbian 9.2 does
// not support premultipied format.
if (image.format() == QImage::Format_ARGB32_Premultiplied) {
@@ -830,7 +839,7 @@ void* QS60PixmapData::toNativeType(NativeType type)
symbianBitmapDataAccess->beginDataAccess(newBitmap);
uchar *dptr = (uchar*)newBitmap->DataAddress();
- Mem::Copy(dptr, sptr, source.numBytes());
+ Mem::Copy(dptr, sptr, source.byteCount());
symbianBitmapDataAccess->endDataAccess(newBitmap);
@@ -930,18 +939,21 @@ void QS60PixmapData::fromNativeType(void* pixmap, NativeType nativeType)
da.beginDataAccess(sourceBitmap);
uchar *bytes = (uchar*)sourceBitmap->DataAddress();
QImage img = QImage(bytes, size.iWidth, size.iHeight, format);
+ img = img.copy();
da.endDataAccess(sourceBitmap);
- fromImage(img, Qt::AutoColor);
-
- if(deleteSourceBitmap)
- delete sourceBitmap;
-
if(displayMode == EGray2) {
//Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid
//So invert mono bitmaps so that masks work correctly.
- image.invertPixels();
+ img.invertPixels();
+ } else if(displayMode == EColor16M) {
+ img = img.rgbSwapped(); // EColor16M is BGR
}
+
+ fromImage(img, Qt::AutoColor);
+
+ if(deleteSourceBitmap)
+ delete sourceBitmap;
} else {
CFbsBitmap* duplicate = 0;
QT_TRAP_THROWING(duplicate = new (ELeave) CFbsBitmap);
diff --git a/src/gui/image/qpixmap_s60_p.h b/src/gui/image/qpixmap_s60_p.h
index b23961a148..b1b58248d6 100644
--- a/src/gui/image/qpixmap_s60_p.h
+++ b/src/gui/image/qpixmap_s60_p.h
@@ -118,6 +118,8 @@ private:
QPaintEngine *pengine;
uchar* bytes;
+ bool formatLocked;
+
friend class QPixmap;
friend class QS60WindowSurface;
friend class QS60PaintEngine;
diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp
index 1b6148479d..04027c156a 100644
--- a/src/gui/image/qpixmap_win.cpp
+++ b/src/gui/image/qpixmap_win.cpp
@@ -121,6 +121,9 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h )
HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const
{
+ if (isNull())
+ return 0;
+
HBITMAP bitmap = 0;
if (data->classId() == QPixmapData::RasterClass) {
QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp
index 74543a034a..7008fbd4a1 100644
--- a/src/gui/image/qpixmap_x11.cpp
+++ b/src/gui/image/qpixmap_x11.cpp
@@ -319,6 +319,11 @@ QX11PixmapData::QX11PixmapData(PixelType type)
{
}
+QPixmapData *QX11PixmapData::createCompatiblePixmapData() const
+{
+ return new QX11PixmapData(pixelType());
+}
+
void QX11PixmapData::resize(int width, int height)
{
setSerialNumber(++qt_pixmap_serial);
@@ -411,6 +416,11 @@ void QX11PixmapData::fromImage(const QImage &img,
d = img.depth();
is_null = (w <= 0 || h <= 0);
+ if (is_null) {
+ w = h = 0;
+ return;
+ }
+
if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
QX11InfoData* xd = xinfo.getX11Data(true);
xd->screen = defaultScreen;
@@ -459,7 +469,7 @@ void QX11PixmapData::fromImage(const QImage &img,
} else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) {
conv8 = (d == 1); // native depth wanted
} else if (d == 1) {
- if (image.numColors() == 2) {
+ if (image.colorCount() == 2) {
QRgb c0 = image.color(0); // Auto: convert to best
QRgb c1 = image.color(1);
conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255);
@@ -484,7 +494,7 @@ void QX11PixmapData::fromImage(const QImage &img,
Visual *visual = (Visual *)xinfo.visual();
XImage *xi = 0;
bool trucol = (visual->c_class >= TrueColor);
- int nbytes = image.numBytes();
+ int nbytes = image.byteCount();
uchar *newbits= 0;
#ifndef QT_NO_XRENDER
@@ -626,7 +636,7 @@ void QX11PixmapData::fromImage(const QImage &img,
if (d8) { // setup pixel translation
QVector<QRgb> ctable = cimage.colorTable();
- for (int i=0; i < cimage.numColors(); i++) {
+ for (int i=0; i < cimage.colorCount(); i++) {
int r = qRed (ctable[i]);
int g = qGreen(ctable[i]);
int b = qBlue (ctable[i]);
@@ -952,8 +962,8 @@ void QX11PixmapData::fromImage(const QImage &img,
if (d == 8 && !trucol) { // 8 bit pixmap
int pop[256]; // pixel popularity
- if (image.numColors() == 0)
- image.setNumColors(1);
+ if (image.colorCount() == 0)
+ image.setColorCount(1);
const QImage &cimage = image;
memset(pop, 0, sizeof(int)*256); // reset popularity array
@@ -983,11 +993,11 @@ void QX11PixmapData::fromImage(const QImage &img,
int mindist;
};
int ncols = 0;
- for (int i=0; i< cimage.numColors(); i++) { // compute number of colors
+ for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors
if (pop[i] > 0)
ncols++;
}
- for (int i = cimage.numColors(); i < 256; i++) // ignore out-of-range pixels
+ for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels
pop[i] = 0;
// works since we make sure above to have at least
@@ -1646,7 +1656,7 @@ QImage QX11PixmapData::toImage() const
}
if (d == 1) { // bitmap
- image.setNumColors(2);
+ image.setColorCount(2);
image.setColor(0, qRgb(255,255,255));
image.setColor(1, qRgb(0,0,0));
} else if (!trucol) { // pixmap with colormap
@@ -1702,10 +1712,10 @@ QImage QX11PixmapData::toImage() const
int trans;
if (ncols < 256) {
trans = ncols++;
- image.setNumColors(ncols); // create color table
+ image.setColorCount(ncols); // create color table
image.setColor(trans, 0x00000000);
} else {
- image.setNumColors(ncols); // create color table
+ image.setColorCount(ncols); // create color table
// oh dear... no spare "transparent" pixel.
// use first pixel in image (as good as any).
trans = image.scanLine(0)[0];
@@ -1728,7 +1738,7 @@ QImage QX11PixmapData::toImage() const
}
}
} else {
- image.setNumColors(ncols); // create color table
+ image.setColorCount(ncols); // create color table
}
QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap();
int j = 0;
@@ -1911,8 +1921,8 @@ QPixmap QX11PixmapData::transformed(const QTransform &transform,
free(dptr);
return bm;
} else { // color pixmap
- QPixmap pm;
- QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pm.data.data());
+ QX11PixmapData *x11Data = new QX11PixmapData(QPixmapData::PixmapType);
+ QPixmap pm(x11Data);
x11Data->flags &= ~QX11PixmapData::Uninitialized;
x11Data->xinfo = xinfo;
x11Data->d = d;
@@ -1971,6 +1981,9 @@ void QPixmap::x11SetScreen(int screen)
return;
}
+ if (isNull())
+ return;
+
if (data->classId() != QPixmapData::X11Class)
return;
@@ -2073,7 +2086,7 @@ bool QX11PixmapData::hasAlphaChannel() const
const QX11Info &QPixmap::x11Info() const
{
- if (data->classId() == QPixmapData::X11Class)
+ if (data && data->classId() == QPixmapData::X11Class)
return static_cast<QX11PixmapData*>(data.data())->xinfo;
else {
static QX11Info nullX11Info;
@@ -2130,7 +2143,7 @@ QPaintEngine* QX11PixmapData::paintEngine() const
Qt::HANDLE QPixmap::x11PictureHandle() const
{
#ifndef QT_NO_XRENDER
- if (data->classId() == QPixmapData::X11Class)
+ if (data && data->classId() == QPixmapData::X11Class)
return static_cast<const QX11PixmapData*>(data.data())->picture;
else
return 0;
diff --git a/src/gui/image/qpixmap_x11_p.h b/src/gui/image/qpixmap_x11_p.h
index e34e690c67..8ce7c0d053 100644
--- a/src/gui/image/qpixmap_x11_p.h
+++ b/src/gui/image/qpixmap_x11_p.h
@@ -71,6 +71,8 @@ public:
// Qt::ImageConversionFlags flags);
~QX11PixmapData();
+ QPixmapData *createCompatiblePixmapData() const;
+
void resize(int width, int height);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
@@ -101,6 +103,7 @@ private:
friend class QRasterWindowSurface;
friend class QGLContextPrivate; // Needs to access xinfo, gl_surface & flags
friend class QEglContext; // Needs gl_surface
+ friend class QX11GLPixmapData; // Needs gl_surface
friend bool qt_createEGLSurfaceForPixmap(QPixmapData*, bool); // Needs gl_surface
void release();
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index f12d3976b6..b0b7d728fe 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -221,6 +221,7 @@ QPMCache::QPMCache()
}
QPMCache::~QPMCache()
{
+ clear();
free(keyArray);
}
diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp
index 93fc2ebe21..38f6b5d550 100644
--- a/src/gui/image/qpixmapdata.cpp
+++ b/src/gui/image/qpixmapdata.cpp
@@ -43,12 +43,27 @@
#include <QtCore/qbuffer.h>
#include <QtGui/qbitmap.h>
#include <QtGui/qimagereader.h>
+#include <private/qgraphicssystem_p.h>
+#include <private/qapplication_p.h>
QT_BEGIN_NAMESPACE
const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80 };
+QPixmapData *QPixmapData::create(int w, int h, PixelType type)
+{
+ QPixmapData *data;
+ QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
+ if (gs)
+ data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type));
+ else
+ data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
+ data->resize(w, h);
+ return data;
+}
+
+
QPixmapData::QPixmapData(PixelType pixelType, int objectId)
: w(0),
h(0),
@@ -67,6 +82,17 @@ QPixmapData::~QPixmapData()
{
}
+QPixmapData *QPixmapData::createCompatiblePixmapData() const
+{
+ QPixmapData *d;
+ QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem();
+ if (gs)
+ d = gs->createPixmapData(pixelType());
+ else
+ d = QGraphicsSystem::createDefaultPixmapData(pixelType());
+ return d;
+}
+
static QImage makeBitmapCompliantIfNeeded(QPixmapData *d, const QImage &image, Qt::ImageConversionFlags flags)
{
if (d->pixelType() == QPixmapData::BitmapType) {
@@ -175,7 +201,7 @@ QBitmap QPixmapData::mask() const
if (mask.isNull()) // allocation failed
return QBitmap();
- mask.setNumColors(2);
+ mask.setColorCount(2);
mask.setColor(0, QColor(Qt::color0).rgba());
mask.setColor(1, QColor(Qt::color1).rgba());
diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h
index c26fba35d5..41e29230f1 100644
--- a/src/gui/image/qpixmapdata_p.h
+++ b/src/gui/image/qpixmapdata_p.h
@@ -75,9 +75,11 @@ public:
enum ClassId { RasterClass, X11Class, MacClass, DirectFBClass,
OpenGLClass, OpenVGClass, CustomClass = 1024 };
- QPixmapData(PixelType pixelpType, int classId);
+ QPixmapData(PixelType pixelType, int classId);
virtual ~QPixmapData();
+ virtual QPixmapData *createCompatiblePixmapData() const;
+
virtual void resize(int width, int height) = 0;
virtual void fromImage(const QImage &image,
Qt::ImageConversionFlags flags) = 0;
@@ -111,7 +113,8 @@ public:
inline int width() const { return w; }
inline int height() const { return h; }
- inline int numColors() const { return metric(QPaintDevice::PdmNumColors); }
+ QT_DEPRECATED inline int numColors() const { return metric(QPaintDevice::PdmNumColors); }
+ inline int colorCount() const { return metric(QPaintDevice::PdmNumColors); }
inline int depth() const { return d; }
inline bool isNull() const { return is_null; }
@@ -120,6 +123,8 @@ public:
virtual void fromNativeType(void* pixmap, NativeType type);
#endif
+ static QPixmapData *create(int w, int h, PixelType type);
+
protected:
void setSerialNumber(int serNo);
int w;
@@ -129,12 +134,11 @@ protected:
private:
friend class QPixmap;
- friend class QGLContextPrivate;
friend class QX11PixmapData;
friend class QS60PixmapData;
+ friend class QImagePixmapCleanupHooks; // Needs to set is_cached
friend class QGLTextureCache; //Needs to check the reference count
friend class QExplicitlySharedDataPointer<QPixmapData>;
- friend bool qt_createEGLSurfaceForPixmap(QPixmapData*, bool); // Needs to set is_cached
QAtomicInt ref;
int detach_no;
diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp
index df445db53a..3723500cd9 100644
--- a/src/gui/image/qpixmapfilter.cpp
+++ b/src/gui/image/qpixmapfilter.cpp
@@ -53,6 +53,7 @@
#include "private/qpaintengineex_p.h"
#include "private/qpaintengine_raster_p.h"
+#ifndef QT_NO_GRAPHICSEFFECT
QT_BEGIN_NAMESPACE
class QPixmapFilterPrivate : public QObjectPrivate
@@ -489,7 +490,7 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q
which is applied when \l{QPixmapFilter::}{draw()} is called.
The filter lets you specialize the radius of the blur as well
- as hint as to whether to prefer performance or quality.
+ as hints as to whether to prefer performance or quality.
By default, the blur effect is produced by applying an exponential
filter generated from the specified blurRadius(). Paint engines
@@ -504,10 +505,10 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q
class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate
{
public:
- QPixmapBlurFilterPrivate() : radius(5), hint(Qt::PerformanceHint) {}
+ QPixmapBlurFilterPrivate() : radius(5), hints(QGraphicsBlurEffect::PerformanceHint) {}
- int radius;
- Qt::RenderHint hint;
+ qreal radius;
+ QGraphicsBlurEffect::BlurHints hints;
};
@@ -535,7 +536,7 @@ QPixmapBlurFilter::~QPixmapBlurFilter()
\internal
*/
-void QPixmapBlurFilter::setRadius(int radius)
+void QPixmapBlurFilter::setRadius(qreal radius)
{
Q_D(QPixmapBlurFilter);
d->radius = radius;
@@ -546,36 +547,42 @@ void QPixmapBlurFilter::setRadius(int radius)
\internal
*/
-int QPixmapBlurFilter::radius() const
+qreal QPixmapBlurFilter::radius() const
{
Q_D(const QPixmapBlurFilter);
return d->radius;
}
/*!
- Setting the blur hint to PerformanceHint causes the implementation
+ Setting the blur hints to PerformanceHint causes the implementation
to trade off visual quality to blur the image faster. Setting the
- blur hint to QualityHint causes the implementation to improve
- visual quality at the expense of speed. The implementation is free
- to ignore this value if it only has a single blur algorithm.
+ blur hints to QualityHint causes the implementation to improve
+ visual quality at the expense of speed.
+
+ AnimationHint causes the implementation to optimize for animating
+ the blur radius, possibly by caching blurred versions of the source
+ pixmap.
+
+ The implementation is free to ignore this value if it only has a single
+ blur algorithm.
\internal
*/
-void QPixmapBlurFilter::setBlurHint(Qt::RenderHint hint)
+void QPixmapBlurFilter::setBlurHints(QGraphicsBlurEffect::BlurHints hints)
{
Q_D(QPixmapBlurFilter);
- d->hint = hint;
+ d->hints = hints;
}
/*!
- Gets the blur hint of the blur filter.
+ Gets the blur hints of the blur filter.
\internal
*/
-Qt::RenderHint QPixmapBlurFilter::blurHint() const
+QGraphicsBlurEffect::BlurHints QPixmapBlurFilter::blurHints() const
{
Q_D(const QPixmapBlurFilter);
- return d->hint;
+ return d->hints;
}
/*!
@@ -584,14 +591,14 @@ Qt::RenderHint QPixmapBlurFilter::blurHint() const
QRectF QPixmapBlurFilter::boundingRectFor(const QRectF &rect) const
{
Q_D(const QPixmapBlurFilter);
- const qreal delta = d->radius * 2;
+ const qreal delta = d->radius + 1;
return rect.adjusted(-delta, -delta, delta, delta);
}
// Blur the image according to the blur radius
// Based on exponential blur algorithm by Jani Huhtanen
// (maximum radius is set to 16)
-static QImage blurred(const QImage& image, const QRect& rect, int radius)
+static QImage blurred(const QImage& image, const QRect& rect, int radius, bool alphaOnly = false)
{
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
@@ -606,47 +613,53 @@ static QImage blurred(const QImage& image, const QRect& rect, int radius)
int rgba[4];
unsigned char* p;
+ int i1 = 0;
+ int i2 = 3;
+
+ if (alphaOnly)
+ i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
+
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r1) + col * 4;
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p += bpl;
for (int j = r1; j < r2; j++, p += bpl)
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c1 * 4;
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p += 4;
for (int j = c1; j < c2; j++, p += 4)
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r2) + col * 4;
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p -= bpl;
for (int j = r1; j < r2; j++, p -= bpl)
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c2 * 4;
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p -= 4;
for (int j = c1; j < c2; j++, p -= 4)
- for (int i = 0; i < 4; i++)
+ for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
@@ -662,7 +675,7 @@ void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap
if (!painter->isActive())
return;
- if (d->radius == 0) {
+ if (d->radius <= 0) {
painter->drawPixmap(srcRect.translated(p), src, srcRect);
return;
}
@@ -672,7 +685,7 @@ void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap
QPixmapBlurFilter *blurFilter = static_cast<QPixmapBlurFilter*>(filter);
if (blurFilter) {
blurFilter->setRadius(d->radius);
- blurFilter->setBlurHint(d->hint);
+ blurFilter->setBlurHints(d->hints);
blurFilter->draw(painter, p, src, srcRect);
return;
}
@@ -682,12 +695,12 @@ void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap
if (srcRect.isNull()) {
srcImage = src.toImage();
- destImage = blurred(srcImage, srcImage.rect(), d->radius);
+ destImage = blurred(srcImage, srcImage.rect(), qRound(d->radius));
} else {
QRect rect = srcRect.toAlignedRect().intersected(src.rect());
srcImage = src.copy(rect).toImage();
- destImage = blurred(srcImage, srcImage.rect(), d->radius);
+ destImage = blurred(srcImage, srcImage.rect(), qRound(d->radius));
}
painter->drawImage(p, destImage);
@@ -892,11 +905,11 @@ class QPixmapDropShadowFilterPrivate : public QPixmapFilterPrivate
{
public:
QPixmapDropShadowFilterPrivate()
- : offset(8, 8), color(63, 63, 63, 180), blurFilter(new QPixmapBlurFilter) {}
+ : offset(8, 8), color(63, 63, 63, 180), radius(1) {}
QPointF offset;
QColor color;
- QPixmapBlurFilter *blurFilter;
+ qreal radius;
};
/*!
@@ -940,8 +953,6 @@ public:
QPixmapDropShadowFilter::QPixmapDropShadowFilter(QObject *parent)
: QPixmapFilter(*new QPixmapDropShadowFilterPrivate, DropShadowFilter, parent)
{
- Q_D(QPixmapDropShadowFilter);
- d->blurFilter->setRadius(1);
}
/*!
@@ -951,8 +962,6 @@ QPixmapDropShadowFilter::QPixmapDropShadowFilter(QObject *parent)
*/
QPixmapDropShadowFilter::~QPixmapDropShadowFilter()
{
- Q_D(QPixmapDropShadowFilter);
- delete d->blurFilter;
}
/*!
@@ -964,10 +973,10 @@ QPixmapDropShadowFilter::~QPixmapDropShadowFilter()
\internal
*/
-int QPixmapDropShadowFilter::blurRadius() const
+qreal QPixmapDropShadowFilter::blurRadius() const
{
Q_D(const QPixmapDropShadowFilter);
- return d->blurFilter->radius();
+ return d->radius;
}
/*!
@@ -979,10 +988,10 @@ int QPixmapDropShadowFilter::blurRadius() const
\internal
*/
-void QPixmapDropShadowFilter::setBlurRadius(int radius)
+void QPixmapDropShadowFilter::setBlurRadius(qreal radius)
{
Q_D(QPixmapDropShadowFilter);
- d->blurFilter->setRadius(radius);
+ d->radius = radius;
}
/*!
@@ -1055,14 +1064,7 @@ void QPixmapDropShadowFilter::setOffset(const QPointF &offset)
QRectF QPixmapDropShadowFilter::boundingRectFor(const QRectF &rect) const
{
Q_D(const QPixmapDropShadowFilter);
-
- const qreal delta = qreal(d->blurFilter->radius() * 2);
- qreal x1 = qMin(rect.left(), rect.left() + d->offset.x() - delta);
- qreal y1 = qMin(rect.top(), rect.top() + d->offset.y() - delta);
- qreal x2 = qMax(rect.right(), rect.right() + d->offset.x() + delta);
- qreal y2 = qMax(rect.bottom(), rect.bottom() + d->offset.y() + delta);
-
- return QRectF(x1, y1, x2 - x1, y2 - y1);
+ return rect.united(rect.translated(d->offset).adjusted(-d->radius, -d->radius, d->radius, d->radius));
}
/*!
@@ -1079,27 +1081,35 @@ void QPixmapDropShadowFilter::draw(QPainter *p,
QPixmapDropShadowFilter *dropShadowFilter = static_cast<QPixmapDropShadowFilter*>(filter);
if (dropShadowFilter) {
dropShadowFilter->setColor(d->color);
- dropShadowFilter->setBlurRadius(d->blurFilter->radius());
+ dropShadowFilter->setBlurRadius(d->radius);
dropShadowFilter->setOffset(d->offset);
dropShadowFilter->draw(p, pos, px, src);
return;
}
- QImage tmp = src.isNull() ? px.toImage() : px.copy(src.toRect()).toImage();
+ QImage tmp(px.size(), QImage::Format_ARGB32_Premultiplied);
+ tmp.fill(0);
QPainter tmpPainter(&tmp);
+ tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
+ tmpPainter.drawPixmap(d->offset, px);
+ tmpPainter.end();
+
+ // blur the alpha channel
+ tmp = blurred(tmp, tmp.rect(), qRound(d->radius), true);
// blacken the image...
+ tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
- tmpPainter.fillRect(0, 0, tmp.width(), tmp.height(), d->color);
+ tmpPainter.fillRect(tmp.rect(), d->color);
tmpPainter.end();
- const QPixmap pixTmp = QPixmap::fromImage(tmp);
-
// draw the blurred drop shadow...
- d->blurFilter->draw(p, pos + d->offset, pixTmp);
+ p->drawImage(pos, tmp);
// Draw the actual pixmap...
p->drawPixmap(pos, px, src);
}
QT_END_NAMESPACE
+
+#endif //QT_NO_GRAPHICSEFFECT
diff --git a/src/gui/image/qpixmapfilter_p.h b/src/gui/image/qpixmapfilter_p.h
index 8a2207aa53..46e744e729 100644
--- a/src/gui/image/qpixmapfilter_p.h
+++ b/src/gui/image/qpixmapfilter_p.h
@@ -55,7 +55,9 @@
#include <QtCore/qnamespace.h>
#include <QtGui/qpixmap.h>
+#include <QtGui/qgraphicseffect.h>
+#ifndef QT_NO_GRAPHICSEFFECT
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -129,11 +131,11 @@ public:
QPixmapBlurFilter(QObject *parent = 0);
~QPixmapBlurFilter();
- void setRadius(int radius);
- void setBlurHint(Qt::RenderHint hint);
+ void setRadius(qreal radius);
+ void setBlurHints(QGraphicsBlurEffect::BlurHints hints);
- int radius() const;
- Qt::RenderHint blurHint() const;
+ qreal radius() const;
+ QGraphicsBlurEffect::BlurHints blurHints() const;
QRectF boundingRectFor(const QRectF &rect) const;
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const;
@@ -175,8 +177,8 @@ public:
QRectF boundingRectFor(const QRectF &rect) const;
void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src = QRectF()) const;
- int blurRadius() const;
- void setBlurRadius(int radius);
+ qreal blurRadius() const;
+ void setBlurRadius(qreal radius);
QColor color() const;
void setColor(const QColor &color);
@@ -190,4 +192,5 @@ QT_END_NAMESPACE
QT_END_HEADER
+#endif //QT_NO_GRAPHICSEFFECT
#endif // QPIXMAPFILTER_H
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index 44d689d80f..14c863b2e3 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -171,7 +171,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, float scre
if (image.isNull())
return;
}
- image.setNumColors(2);
+ image.setColorCount(2);
image.setColor(1, qRgb(0,0,0));
image.setColor(0, qRgb(255,255,255));
} else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
@@ -199,7 +199,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, float scre
if (image.isNull())
return;
}
- image.setNumColors(ncols);
+ image.setColorCount(ncols);
for (int i=0; i<ncols; i++) {
int c = i*255/(ncols-1);
image.setColor(i, qRgba(c,c,c,0xff));
@@ -230,7 +230,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, float scre
if (image.isNull())
return;
}
- image.setNumColors(info_ptr->num_palette);
+ image.setColorCount(info_ptr->num_palette);
int i = 0;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
while (i < info_ptr->num_trans) {
@@ -508,7 +508,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage)
// sanity check palette entries
if (color_type == PNG_COLOR_TYPE_PALETTE
&& outImage->format() == QImage::Format_Indexed8) {
- int color_table_size = outImage->numColors();
+ int color_table_size = outImage->colorCount();
for (int y=0; y<(int)height; ++y) {
uchar *p = outImage->scanLine(y);
uchar *end = p + width;
@@ -762,9 +762,9 @@ bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image_in,
png_colorp palette = 0;
png_bytep copy_trans = 0;
- if (image.numColors()) {
+ if (image.colorCount()) {
// Paletted
- int num_palette = image.numColors();
+ int num_palette = image.colorCount();
palette = new png_color[num_palette];
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
int* trans = new int[num_palette];
diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp
index 28e4a2ac25..8ec9efbe08 100644
--- a/src/gui/image/qppmhandler.cpp
+++ b/src/gui/image/qppmhandler.cpp
@@ -242,11 +242,11 @@ static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, Q
}
if (nbits == 1) { // bitmap
- outImage->setNumColors(2);
+ outImage->setColorCount(2);
outImage->setColor(0, qRgb(255,255,255)); // white
outImage->setColor(1, qRgb(0,0,0)); // black
} else if (nbits == 8) { // graymap
- outImage->setNumColors(maxc+1);
+ outImage->setColorCount(maxc+1);
for (int i=0; i<=maxc; i++)
outImage->setColor(i, qRgb(i*255/maxc,i*255/maxc,i*255/maxc));
}
@@ -287,7 +287,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy
}
}
- if (image.depth() == 1 && image.numColors() == 2) {
+ if (image.depth() == 1 && image.colorCount() == 2) {
if (qGray(image.color(0)) < qGray(image.color(1))) {
// 0=dark/black, 1=light/white - invert
image.detach();
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp
index 1c74351ee0..0d76ea0910 100644
--- a/src/gui/image/qxbmhandler.cpp
+++ b/src/gui/image/qxbmhandler.cpp
@@ -135,7 +135,7 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
return false;
}
- outImage->setNumColors(2);
+ outImage->setColorCount(2);
outImage->setColor(0, qRgb(255,255,255)); // white
outImage->setColor(1, qRgb(0,0,0)); // black
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index 4bdd16eeee..ac4711a66e 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -895,7 +895,7 @@ static bool read_xpm_body(
if (image.isNull())
return false;
}
- image.setNumColors(ncols);
+ image.setColorCount(ncols);
}
QMap<quint64, int> colorMap;