summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/image.pri8
-rw-r--r--src/gui/image/qbmphandler.cpp4
-rw-r--r--src/gui/image/qicon.cpp28
-rw-r--r--src/gui/image/qiconloader.cpp2
-rw-r--r--src/gui/image/qimage.cpp327
-rw-r--r--src/gui/image/qimage.h150
-rw-r--r--src/gui/image/qimage_conversions.cpp354
-rw-r--r--src/gui/image/qimage_p.h23
-rw-r--r--src/gui/image/qimageiohandler.cpp6
-rw-r--r--src/gui/image/qimageiohandler.h2
-rw-r--r--src/gui/image/qimagereader.cpp14
-rw-r--r--src/gui/image/qimagereaderwriterhelpers.cpp6
-rw-r--r--src/gui/image/qimagewriter.cpp16
-rw-r--r--src/gui/image/qmovie.cpp2
-rw-r--r--src/gui/image/qpaintengine_pic.cpp6
-rw-r--r--src/gui/image/qpicture.cpp10
-rw-r--r--src/gui/image/qpixmap.cpp6
-rw-r--r--src/gui/image/qpixmap.h3
-rw-r--r--src/gui/image/qpixmap_blitter.cpp8
-rw-r--r--src/gui/image/qpixmapcache.cpp14
-rw-r--r--src/gui/image/qplatformpixmap.cpp2
-rw-r--r--src/gui/image/qpnghandler.cpp58
-rw-r--r--src/gui/image/qxpmhandler.cpp4
23 files changed, 268 insertions, 785 deletions
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri
index 085ec90c4b..760b737ec3 100644
--- a/src/gui/image/image.pri
+++ b/src/gui/image/image.pri
@@ -74,6 +74,14 @@ qtConfig(png) {
HEADERS += image/qpnghandler_p.h
SOURCES += image/qpnghandler.cpp
QMAKE_USE_PRIVATE += libpng
+
+ win32:mingw {
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86048
+ GCC_VERSION = "$${QMAKE_GCC_MAJOR_VERSION}.$${QMAKE_GCC_MINOR_VERSION}.$${QMAKE_GCC_PATCH_VERSION}"
+ equals(GCC_VERSION, "8.1.0") {
+ QMAKE_CXXFLAGS += -fno-reorder-blocks-and-partition
+ }
+ }
}
# SIMD
diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp
index 7f8e072322..32b6131309 100644
--- a/src/gui/image/qbmphandler.cpp
+++ b/src/gui/image/qbmphandler.cpp
@@ -414,7 +414,7 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, qint64 offset,
*p++ = tmp >> 4;
}
if ((((c & 3) + 1) & 2) == 2)
- d->getChar(0); // align on word boundary
+ d->getChar(nullptr); // align on word boundary
x += c;
}
} else { // encoded mode
@@ -494,7 +494,7 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, qint64 offset,
if (d->read((char *)p, b) != b)
return false;
if ((b & 1) == 1)
- d->getChar(0); // align on word boundary
+ d->getChar(nullptr); // align on word boundary
x += b;
p += b;
}
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index df8220a0c6..19be066d23 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -132,7 +132,7 @@ static void qt_cleanup_icon_cache()
if Qt::AA_UseHighDpiPixmaps is not set this function
returns 1.0 to keep non-hihdpi aware code working.
*/
-static qreal qt_effective_device_pixel_ratio(QWindow *window = 0)
+static qreal qt_effective_device_pixel_ratio(QWindow *window = nullptr)
{
if (!qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
return qreal(1.0);
@@ -165,6 +165,11 @@ QIconPrivate::QIconPrivate(QIconEngine *e)
qreal QIconPrivate::pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize)
{
QSize targetSize = requestedSize * displayDevicePixelRatio;
+ if ((actualSize.width() == targetSize.width() && actualSize.height() <= targetSize.height()) ||
+ (actualSize.width() <= targetSize.width() && actualSize.height() == targetSize.height())) {
+ // Correctly scaled for dpr, just having different aspect ratio
+ return displayDevicePixelRatio;
+ }
qreal scale = 0.5 * (qreal(actualSize.width()) / qreal(targetSize.width()) +
qreal(actualSize.height() / qreal(targetSize.height())));
return qMax(qreal(1.0), displayDevicePixelRatio *scale);
@@ -185,7 +190,12 @@ QPixmapIconEngine::~QPixmapIconEngine()
void QPixmapIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
{
- QSize pixmapSize = rect.size() * qt_effective_device_pixel_ratio(0);
+ qreal dpr = 1.0;
+ if (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps)) {
+ auto paintDevice = painter->device();
+ dpr = paintDevice ? paintDevice->devicePixelRatioF() : qApp->devicePixelRatio();
+ }
+ const QSize pixmapSize = rect.size() * dpr;
QPixmap px = pixmap(pixmapSize, mode, state);
painter->drawPixmap(rect, px);
}
@@ -218,7 +228,7 @@ static QPixmapIconEngineEntry *bestSizeMatch( const QSize &size, QPixmapIconEngi
QPixmapIconEngineEntry *QPixmapIconEngine::tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
- QPixmapIconEngineEntry *pe = 0;
+ QPixmapIconEngineEntry *pe = nullptr;
for (int i = 0; i < pixmaps.count(); ++i)
if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) {
if (pe)
@@ -664,7 +674,7 @@ QFactoryLoader *qt_iconEngineFactoryLoader()
Constructs a null icon.
*/
QIcon::QIcon() noexcept
- : d(0)
+ : d(nullptr)
{
}
@@ -672,7 +682,7 @@ QIcon::QIcon() noexcept
Constructs an icon from a \a pixmap.
*/
QIcon::QIcon(const QPixmap &pixmap)
- :d(0)
+ :d(nullptr)
{
addPixmap(pixmap);
}
@@ -713,7 +723,7 @@ QIcon::QIcon(const QIcon &other)
complete list of the supported file formats.
*/
QIcon::QIcon(const QString &fileName)
- : d(0)
+ : d(nullptr)
{
addFile(fileName);
}
@@ -828,7 +838,7 @@ QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const
{
if (!d)
return QPixmap();
- return pixmap(0, size, mode, state);
+ return pixmap(nullptr, size, mode, state);
}
/*!
@@ -868,7 +878,7 @@ QSize QIcon::actualSize(const QSize &size, Mode mode, State state) const
{
if (!d)
return QSize();
- return actualSize(0, size, mode, state);
+ return actualSize(nullptr, size, mode, state);
}
/*!
@@ -998,7 +1008,7 @@ void QIcon::detach()
if (d->engine->isNull()) {
if (!d->ref.deref())
delete d;
- d = 0;
+ d = nullptr;
return;
} else if (d->ref.loadRelaxed() != 1) {
QIconPrivate *x = new QIconPrivate(d->engine->clone());
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 27c82bc09f..e67b387981 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -714,7 +714,7 @@ QIconLoaderEngineEntry *QIconLoaderEngine::entryForSize(const QThemeIconInfo &in
// Find the minimum distance icon
int minimalSize = INT_MAX;
- QIconLoaderEngineEntry *closestMatch = 0;
+ QIconLoaderEngineEntry *closestMatch = nullptr;
for (int i = 0; i < numEntries; ++i) {
QIconLoaderEngineEntry *entry = info.entries.at(i);
int distance = directorySizeDistance(entry->dir, iconsize, scale);
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 2779b97fbd..08b1373f96 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE
static inline bool isLocked(QImageData *data)
{
- return data != 0 && data->is_locked;
+ return data != nullptr && data->is_locked;
}
#if defined(Q_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0 >= 50190001)
@@ -99,15 +99,15 @@ static int next_qimage_serial_number()
}
QImageData::QImageData()
- : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(0),
+ : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(nullptr),
format(QImage::Format_ARGB32), bytes_per_line(0),
ser_no(next_qimage_serial_number()),
detach_no(0),
dpmx(qt_defaultDpiX() * 100 / qreal(2.54)),
dpmy(qt_defaultDpiY() * 100 / qreal(2.54)),
offset(0, 0), own_data(true), ro_data(false), has_alpha_clut(false),
- is_cached(false), is_locked(false), cleanupFunction(0), cleanupInfo(0),
- paintEngine(0)
+ is_cached(false), is_locked(false), cleanupFunction(nullptr), cleanupInfo(nullptr),
+ paintEngine(nullptr)
{
}
@@ -170,7 +170,7 @@ QImageData::~QImageData()
delete paintEngine;
if (data && own_data)
free(data);
- data = 0;
+ data = nullptr;
}
#if defined(_M_ARM)
@@ -746,7 +746,7 @@ bool QImageData::checkForAlphaPixels() const
QImage::QImage() noexcept
: QPaintDevice()
{
- d = 0;
+ d = nullptr;
}
/*!
@@ -955,7 +955,7 @@ QImage::QImage(const uchar *data, int width, int height, int bytesPerLine, Forma
QImage::QImage(const QString &fileName, const char *format)
: QPaintDevice()
{
- d = 0;
+ d = nullptr;
load(fileName, format);
}
@@ -981,10 +981,10 @@ extern bool qt_read_xpm_image_or_array(QIODevice *device, const char * const *so
QImage::QImage(const char * const xpm[])
: QPaintDevice()
{
- d = 0;
+ d = nullptr;
if (!xpm)
return;
- if (!qt_read_xpm_image_or_array(0, xpm, *this))
+ if (!qt_read_xpm_image_or_array(nullptr, xpm, *this))
// Issue: Warning because the constructor may be ambigious
qWarning("QImage::QImage(), XPM is not supported");
}
@@ -1003,7 +1003,7 @@ QImage::QImage(const QImage &image)
: QPaintDevice()
{
if (image.paintingActive() || isLocked(image.d)) {
- d = 0;
+ d = nullptr;
image.copy().swap(*this);
} else {
d = image.d;
@@ -1381,11 +1381,7 @@ int QImage::colorCount() const
\sa colorTable(), setColor(), {QImage#Image Transformations}{Image
Transformations}
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
void QImage::setColorTable(const QVector<QRgb> &colors)
-#else
-void QImage::setColorTable(const QVector<QRgb> colors)
-#endif
{
if (!d)
return;
@@ -1395,11 +1391,7 @@ void QImage::setColorTable(const QVector<QRgb> colors)
if (!d)
return;
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
d->colortable = colors;
-#else
- d->colortable = std::move(const_cast<QVector<QRgb>&>(colors));
-#endif
d->has_alpha_clut = false;
for (int i = 0; i < d->colortable.size(); ++i) {
if (qAlpha(d->colortable.at(i)) != 255) {
@@ -1472,25 +1464,6 @@ void QImage::setDevicePixelRatio(qreal scaleFactor)
d->devicePixelRatio = scaleFactor;
}
-#if QT_DEPRECATED_SINCE(5, 10)
-/*!
- \since 4.6
- \obsolete
- Returns the number of bytes occupied by the image data.
-
- Note this method should never be called on an image larger than 2 gigabytes.
- Instead use sizeInBytes().
-
- \sa sizeInBytes(), bytesPerLine(), bits(), {QImage#Image Information}{Image
- Information}
-*/
-int QImage::byteCount() const
-{
- Q_ASSERT(!d || d->nbytes < std::numeric_limits<int>::max());
- return d ? int(d->nbytes) : 0;
-}
-#endif
-
/*!
\since 5.10
Returns the image data size in bytes.
@@ -1510,17 +1483,10 @@ qsizetype QImage::sizeInBytes() const
\sa scanLine()
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
qsizetype QImage::bytesPerLine() const
{
return d ? d->bytes_per_line : 0;
}
-#else
-int QImage::bytesPerLine() const
-{
- return d ? d->bytes_per_line : 0;
-}
-#endif
/*!
@@ -1593,13 +1559,13 @@ void QImage::setColor(int i, QRgb c)
uchar *QImage::scanLine(int i)
{
if (!d)
- return 0;
+ return nullptr;
detach();
// In case detach() ran out of memory
if (!d)
- return 0;
+ return nullptr;
return d->data + i * d->bytes_per_line;
}
@@ -1610,7 +1576,7 @@ uchar *QImage::scanLine(int i)
const uchar *QImage::scanLine(int i) const
{
if (!d)
- return 0;
+ return nullptr;
Q_ASSERT(i >= 0 && i < height());
return d->data + i * d->bytes_per_line;
@@ -1633,7 +1599,7 @@ const uchar *QImage::scanLine(int i) const
const uchar *QImage::constScanLine(int i) const
{
if (!d)
- return 0;
+ return nullptr;
Q_ASSERT(i >= 0 && i < height());
return d->data + i * d->bytes_per_line;
@@ -1653,12 +1619,12 @@ const uchar *QImage::constScanLine(int i) const
uchar *QImage::bits()
{
if (!d)
- return 0;
+ return nullptr;
detach();
// In case detach ran out of memory...
if (!d)
- return 0;
+ return nullptr;
return d->data;
}
@@ -1672,7 +1638,7 @@ uchar *QImage::bits()
*/
const uchar *QImage::bits() const
{
- return d ? d->data : 0;
+ return d ? d->data : nullptr;
}
@@ -1688,7 +1654,7 @@ const uchar *QImage::bits() const
*/
const uchar *QImage::constBits() const
{
- return d ? d->data : 0;
+ return d ? d->data : nullptr;
}
/*!
@@ -1912,10 +1878,10 @@ void QImage::invertPixels(InvertMode mode)
// Inverting premultiplied pixels would produce invalid image data.
if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied) {
if (depth() > 32) {
- if (!d->convertInPlace(QImage::Format_RGBA64, 0))
+ if (!d->convertInPlace(QImage::Format_RGBA64, { }))
*this = convertToFormat(QImage::Format_RGBA64);
} else {
- if (!d->convertInPlace(QImage::Format_ARGB32, 0))
+ if (!d->convertInPlace(QImage::Format_ARGB32, { }))
*this = convertToFormat(QImage::Format_ARGB32);
}
}
@@ -1982,7 +1948,7 @@ void QImage::invertPixels(InvertMode mode)
}
if (originalFormat != d->format) {
- if (!d->convertInPlace(originalFormat, 0))
+ if (!d->convertInPlace(originalFormat, { }))
*this = convertToFormat(originalFormat);
}
}
@@ -2060,27 +2026,6 @@ QImage::Format QImage::format() const
\sa {Image Formats}
*/
-static bool highColorPrecision(QImage::Format format)
-{
- // Formats with higher color precision than ARGB32_Premultiplied.
- switch (format) {
- case QImage::Format_ARGB32:
- case QImage::Format_RGBA8888:
- case QImage::Format_BGR30:
- case QImage::Format_RGB30:
- case QImage::Format_A2BGR30_Premultiplied:
- case QImage::Format_A2RGB30_Premultiplied:
- case QImage::Format_RGBX64:
- case QImage::Format_RGBA64:
- case QImage::Format_RGBA64_Premultiplied:
- case QImage::Format_Grayscale16:
- return true;
- default:
- break;
- }
- return false;
-}
-
/*!
\internal
*/
@@ -2092,9 +2037,11 @@ QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags fl
if (format == Format_Invalid || d->format == Format_Invalid)
return QImage();
+ const QPixelLayout *destLayout = &qPixelLayouts[format];
Image_Converter converter = qimage_converter_map[d->format][format];
if (!converter && format > QImage::Format_Indexed8 && d->format > QImage::Format_Indexed8) {
- if (highColorPrecision(format) && highColorPrecision(d->format)) {
+ if (qt_highColorPrecision(d->format, !destLayout->hasAlphaChannel)
+ && qt_highColorPrecision(format, !hasAlphaChannel())) {
converter = convert_generic_to_rgb64;
} else
converter = convert_generic;
@@ -3046,11 +2993,11 @@ QImage QImage::createHeuristicMask(bool clipTight) const
while(!done) {
done = true;
ypn = m.scanLine(0);
- ypc = 0;
+ ypc = nullptr;
for (y = 0; y < h; y++) {
ypp = ypc;
ypc = ypn;
- ypn = (y == h-1) ? 0 : m.scanLine(y+1);
+ ypn = (y == h-1) ? nullptr : m.scanLine(y+1);
const QRgb *p = (const QRgb *)scanLine(y);
for (x = 0; x < w; x++) {
// slowness here - it's possible to do six of these tests
@@ -3072,11 +3019,11 @@ QImage QImage::createHeuristicMask(bool clipTight) const
if (!clipTight) {
ypn = m.scanLine(0);
- ypc = 0;
+ ypc = nullptr;
for (y = 0; y < h; y++) {
ypp = ypc;
ypc = ypn;
- ypn = (y == h-1) ? 0 : m.scanLine(y+1);
+ ypn = (y == h-1) ? nullptr : m.scanLine(y+1);
const QRgb *p = (const QRgb *)scanLine(y);
for (x = 0; x < w; x++) {
if ((*p & 0x00ffffff) != background) {
@@ -4073,75 +4020,14 @@ void QImage::setText(const QString &key, const QString &value)
}
/*!
- \fn QString QImage::text(const char* key, const char* language) const
- \obsolete
-
- Returns the text recorded for the given \a key in the given \a
- language, or in a default language if \a language is 0.
-
- Use text() instead.
-
- The language the text is recorded in is no longer relevant since
- the text is always set using QString and UTF-8 representation.
-*/
-
-/*!
- \fn QString QImage::text(const QImageTextKeyLang& keywordAndLanguage) const
- \overload
- \obsolete
-
- Returns the text recorded for the given \a keywordAndLanguage.
-
- Use text() instead.
-
- The language the text is recorded in is no longer relevant since
- the text is always set using QString and UTF-8 representation.
-*/
-
-/*!
- \fn void QImage::setText(const char* key, const char* language, const QString& text)
- \obsolete
-
- Sets the image text to the given \a text and associate it with the
- given \a key. The text is recorded in the specified \a language,
- or in a default language if \a language is 0.
-
- Use setText() instead.
-
- The language the text is recorded in is no longer relevant since
- the text is always set using QString and UTF-8 representation.
-
- \omit
- Records string \a for the keyword \a key. The \a key should be
- a portable keyword recognizable by other software - some suggested
- values can be found in
- \l{http://www.libpng.org/pub/png/spec/1.2/png-1.2-pdg.html#C.Anc-text}
- {the PNG specification}. \a s can be any text. \a lang should
- specify the language code (see
- \l{http://www.rfc-editor.org/rfc/rfc1766.txt}{RFC 1766}) or 0.
- \endomit
-*/
-
-/*
- Sets the image bits to the \a pixmap contents and returns a
- reference to the image.
-
- If the image shares data with other images, it will first
- dereference the shared data.
-
- Makes a call to QPixmap::convertToImage().
-*/
-
-/*!
\internal
Used by QPainter to retrieve a paint engine for the image.
*/
-
QPaintEngine *QImage::paintEngine() const
{
if (!d)
- return 0;
+ return nullptr;
if (!d->paintEngine) {
QPaintDevice *paintDevice = const_cast<QImage *>(this);
@@ -4383,22 +4269,6 @@ bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth
#undef IWX_LSB
#undef IWX_PIX
-/*! \fn int QImage::serialNumber() const
- \obsolete
- Returns a number that identifies the contents of this
- QImage object. Distinct QImage objects can only have the same
- serial number if they refer to the same contents (but they don't
- have to).
-
- Use cacheKey() instead.
-
- \warning The serial number doesn't necessarily change when the
- image is altered. This means that it may be dangerous to use
- it as a cache key.
-
- \sa operator==()
-*/
-
/*!
Returns a number that identifies the contents of this QImage
object. Distinct QImage objects can only have the same key if they
@@ -4429,99 +4299,61 @@ bool QImage::isDetached() const
/*!
- \obsolete
Sets the alpha channel of this image to the given \a alphaChannel.
- If \a alphaChannel is an 8 bit grayscale image, the intensity values are
- written into this buffer directly. Otherwise, \a alphaChannel is converted
- to 32 bit and the intensity of the RGB pixel values is used.
+ If \a alphaChannel is an 8 bit alpha image, the alpha values are
+ used directly. Otherwise, \a alphaChannel is converted to 8 bit
+ grayscale and the intensity of the pixel values is used.
- Note that the image will be converted to the Format_ARGB32_Premultiplied
- format if the function succeeds.
+ If the image already has an alpha channel, the existing alpha channel
+ is multiplied with the new one. If the image doesn't have an alpha
+ channel it will be converted to a format that does.
- Use one of the composition modes in QPainter::CompositionMode instead.
+ The operation is similar to painting \a alphaChannel as an alpha image
+ over this image using \c QPainter::CompositionMode_DestinationIn.
- \warning This function is expensive.
-
- \sa alphaChannel(), {QImage#Image Transformations}{Image
- Transformations}, {QImage#Image Formats}{Image Formats}
+ \sa hasAlphaChannel(), alphaChannel(),
+ {QImage#Image Transformations}{Image Transformations},
+ {QImage#Image Formats}{Image Formats}
*/
void QImage::setAlphaChannel(const QImage &alphaChannel)
{
- if (!d)
+ if (!d || alphaChannel.isNull())
return;
- int w = d->width;
- int h = d->height;
-
- if (w != alphaChannel.d->width || h != alphaChannel.d->height) {
- qWarning("QImage::setAlphaChannel: "
- "Alpha channel must have same dimensions as the target image");
- return;
- }
-
if (d->paintEngine && d->paintEngine->isActive()) {
qWarning("QImage::setAlphaChannel: "
"Unable to set alpha channel while image is being painted on");
return;
}
- if (d->format == QImage::Format_ARGB32_Premultiplied)
+ const Format alphaFormat = qt_alphaVersionForPainting(d->format);
+ if (d->format == alphaFormat)
detach();
else
- *this = convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ convertTo(alphaFormat);
if (isNull())
return;
- // Slight optimization since alphachannels are returned as 8-bit grays.
- if (alphaChannel.format() == QImage::Format_Alpha8 ||( alphaChannel.d->depth == 8 && alphaChannel.isGrayscale())) {
- const uchar *src_data = alphaChannel.d->data;
- uchar *dest_data = d->data;
- for (int y=0; y<h; ++y) {
- const uchar *src = src_data;
- QRgb *dest = (QRgb *)dest_data;
- for (int x=0; x<w; ++x) {
- int alpha = *src;
- int destAlpha = qt_div_255(alpha * qAlpha(*dest));
- *dest = ((destAlpha << 24)
- | (qt_div_255(qRed(*dest) * alpha) << 16)
- | (qt_div_255(qGreen(*dest) * alpha) << 8)
- | (qt_div_255(qBlue(*dest) * alpha)));
- ++dest;
- ++src;
- }
- src_data += alphaChannel.d->bytes_per_line;
- dest_data += d->bytes_per_line;
- }
+ QImage sourceImage;
+ if (alphaChannel.format() == QImage::Format_Alpha8 || (alphaChannel.d->depth == 8 && alphaChannel.isGrayscale()))
+ sourceImage = alphaChannel;
+ else
+ sourceImage = alphaChannel.convertToFormat(QImage::Format_Grayscale8);
+ if (!sourceImage.reinterpretAsFormat(QImage::Format_Alpha8))
+ return;
- } else {
- const QImage sourceImage = alphaChannel.convertToFormat(QImage::Format_RGB32);
- if (sourceImage.isNull())
- return;
- const uchar *src_data = sourceImage.d->data;
- uchar *dest_data = d->data;
- for (int y=0; y<h; ++y) {
- const QRgb *src = (const QRgb *) src_data;
- QRgb *dest = (QRgb *) dest_data;
- for (int x=0; x<w; ++x) {
- int alpha = qGray(*src);
- int destAlpha = qt_div_255(alpha * qAlpha(*dest));
- *dest = ((destAlpha << 24)
- | (qt_div_255(qRed(*dest) * alpha) << 16)
- | (qt_div_255(qGreen(*dest) * alpha) << 8)
- | (qt_div_255(qBlue(*dest) * alpha)));
- ++dest;
- ++src;
- }
- src_data += sourceImage.d->bytes_per_line;
- dest_data += d->bytes_per_line;
- }
- }
+ QPainter painter(this);
+ if (sourceImage.size() != size())
+ painter.setRenderHint(QPainter::SmoothPixmapTransform);
+ painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ painter.drawImage(rect(), sourceImage);
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
\obsolete
@@ -4611,6 +4443,7 @@ QImage QImage::alphaChannel() const
return image;
}
+#endif
/*!
Returns \c true if the image has a format that respects the alpha
@@ -5141,50 +4974,6 @@ QDebug operator<<(QDebug dbg, const QImage &i)
}
#endif
-/*!
- \fn void QImage::setNumColors(int n)
- \obsolete
-
- Resizes the color table to contain \a n entries.
-
- \sa setColorCount()
- */
-
-/*!
- \fn int QImage::numBytes() const
- \obsolete
-
- Returns the number of bytes occupied by the image data.
-
- \sa sizeInBytes()
- */
-
-/*!
- \fn QStringList QImage::textLanguages() const
- \obsolete
-
- Returns the language identifiers for which some texts are recorded.
- Note that if you want to iterate over the list, you should iterate over a copy.
-
- The language the text is recorded in is no longer relevant since the text is
- always set using QString and UTF-8 representation.
-
- \sa textKeys()
- */
-
-/*!
- \fn QList<QImageTextKeyLang> QImage::textList() const
- \obsolete
-
- Returns a list of QImageTextKeyLang objects that enumerate all the texts
- key/language pairs set for this image.
-
- The language the text is recorded in is no longer relevant since the text
- is always set using QString and UTF-8 representation.
-
- \sa textKeys()
- */
-
static Q_CONSTEXPR QPixelFormat pixelformats[] = {
//QImage::Format_Invalid:
QPixelFormat(),
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index 73c960f13f..b8df4b83d1 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -50,10 +50,6 @@
#include <QtCore/qrect.h>
#include <QtCore/qstring.h>
-#if QT_DEPRECATED_SINCE(5, 0)
-#include <QtCore/qstringlist.h>
-#endif
-
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(CGImage);
#endif
@@ -71,27 +67,6 @@ class QVariant;
template <class T> class QVector;
struct QImageData;
-class QImageDataMisc; // internal
-#if QT_DEPRECATED_SINCE(5, 0)
-class QImageTextKeyLang {
-public:
- QT_DEPRECATED QImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { }
- QT_DEPRECATED QImageTextKeyLang() { }
-
- QByteArray key;
- QByteArray lang;
-
- bool operator< (const QImageTextKeyLang& other) const
- { return key < other.key || (key==other.key && lang < other.lang); }
- bool operator== (const QImageTextKeyLang& other) const
- { return key==other.key && lang==other.lang; }
- inline bool operator!= (const QImageTextKeyLang &other) const
- { return !operator==(other); }
-private:
- friend class QImage;
- QImageTextKeyLang(bool /*dummy*/) {}
-};
-#endif
typedef void (*QImageCleanupFunction)(void*);
@@ -212,19 +187,12 @@ public:
const uchar *bits() const;
const uchar *constBits() const;
-#if QT_DEPRECATED_SINCE(5, 10)
- QT_DEPRECATED_X("Use sizeInBytes") int byteCount() const;
-#endif
qsizetype sizeInBytes() const;
uchar *scanLine(int);
const uchar *scanLine(int) const;
const uchar *constScanLine(int) const;
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
qsizetype bytesPerLine() const;
-#else
- int bytesPerLine() const;
-#endif
bool valid(int x, int y) const;
bool valid(const QPoint &pt) const;
@@ -245,11 +213,7 @@ public:
void setPixelColor(const QPoint &pt, const QColor &c);
QVector<QRgb> colorTable() const;
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
void setColorTable(const QVector<QRgb> &colors);
-#else
- void setColorTable(const QVector<QRgb> colors);
-#endif
qreal devicePixelRatio() const;
void setDevicePixelRatio(qreal scaleFactor);
@@ -261,7 +225,9 @@ public:
bool hasAlphaChannel() const;
void setAlphaChannel(const QImage &alphaChannel);
- QImage alphaChannel() const;
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED QImage alphaChannel() const;
+#endif
QImage createAlphaMask(Qt::ImageConversionFlags flags = Qt::AutoColor) const;
#ifndef QT_NO_IMAGE_HEURISTIC_MASK
QImage createHeuristicMask(bool clipTight = true) const;
@@ -309,9 +275,6 @@ public:
inline static QImage fromData(const QByteArray &data, const char *format = nullptr)
{ return fromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), format); }
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
-#endif
qint64 cacheKey() const;
QPaintEngine *paintEngine() const override;
@@ -337,20 +300,6 @@ public:
CGImageRef toCGImage() const Q_DECL_CF_RETURNS_RETAINED;
#endif
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline QString text(const char *key, const char *lang = nullptr) const;
- QT_DEPRECATED inline QList<QImageTextKeyLang> textList() const;
- QT_DEPRECATED inline QStringList textLanguages() const;
- QT_DEPRECATED inline QString text(const QImageTextKeyLang&) const;
- QT_DEPRECATED inline void setText(const char* key, const char* lang, const QString&);
-#endif
-
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline int numColors() const;
- QT_DEPRECATED inline void setNumColors(int);
- QT_DEPRECATED inline int numBytes() const;
-#endif
-
protected:
virtual int metric(PaintDeviceMetric metric) const override;
QImage mirrored_helper(bool horizontal, bool vertical) const;
@@ -385,99 +334,6 @@ inline void QImage::setPixel(const QPoint &pt, uint index_or_rgb) { setPixel(pt.
inline QColor QImage::pixelColor(const QPoint &pt) const { return pixelColor(pt.x(), pt.y()); }
inline void QImage::setPixelColor(const QPoint &pt, const QColor &c) { setPixelColor(pt.x(), pt.y(), c); }
-#if QT_DEPRECATED_SINCE(5, 0)
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
-
-inline QString QImage::text(const char* key, const char* lang) const
-{
- if (!d)
- return QString();
- QString k = QString::fromLatin1(key);
- if (lang && *lang)
- k += QLatin1Char('/') + QString::fromLatin1(lang);
- return text(k);
-}
-
-inline QList<QImageTextKeyLang> QImage::textList() const
-{
- QList<QImageTextKeyLang> imageTextKeys;
- if (!d)
- return imageTextKeys;
- QStringList keys = textKeys();
- for (int i = 0; i < keys.size(); ++i) {
- int index = keys.at(i).indexOf(QLatin1Char('/'));
- if (index > 0) {
- QImageTextKeyLang tkl(true);
- tkl.key = keys.at(i).left(index).toLatin1();
- tkl.lang = keys.at(i).mid(index+1).toLatin1();
- imageTextKeys += tkl;
- }
- }
-
- return imageTextKeys;
-}
-
-inline QStringList QImage::textLanguages() const
-{
- if (!d)
- return QStringList();
- QStringList keys = textKeys();
- QStringList languages;
- for (int i = 0; i < keys.size(); ++i) {
- int index = keys.at(i).indexOf(QLatin1Char('/'));
- if (index > 0)
- languages += keys.at(i).mid(index+1);
- }
-
- return languages;
-}
-
-inline QString QImage::text(const QImageTextKeyLang&kl) const
-{
- if (!d)
- return QString();
- QString k = QString::fromLatin1(kl.key.constData());
- if (!kl.lang.isEmpty())
- k += QLatin1Char('/') + QString::fromLatin1(kl.lang.constData());
- return text(k);
-}
-
-inline void QImage::setText(const char* key, const char* lang, const QString &s)
-{
- if (!d)
- return;
- detach();
-
- // In case detach() ran out of memory
- if (!d)
- return;
-
- QString k = QString::fromLatin1(key);
- if (lang && *lang)
- k += QLatin1Char('/') + QString::fromLatin1(lang);
- setText(k, s);
-}
-
-QT_WARNING_POP
-
-inline int QImage::numColors() const
-{
- return colorCount();
-}
-
-inline void QImage::setNumColors(int n)
-{
- setColorCount(n);
-}
-
-inline int QImage::numBytes() const
-{
- return int(sizeInBytes());
-}
-#endif
-
// QImage stream functions
#if !defined(QT_NO_DATASTREAM)
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index 9e1df7058c..27088698ec 100644
--- a/src/gui/image/qimage_conversions.cpp
+++ b/src/gui/image/qimage_conversions.cpp
@@ -198,7 +198,7 @@ void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversio
store = destLayout->storeFromRGB32;
}
QDitherInfo dither;
- QDitherInfo *ditherPtr = 0;
+ QDitherInfo *ditherPtr = nullptr;
if ((flags & Qt::PreferDither) && (flags & Qt::Dither_Mask) != Qt::ThresholdDither)
ditherPtr = &dither;
@@ -212,8 +212,8 @@ void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversio
buffer = reinterpret_cast<uint *>(destData) + x;
else
l = qMin(l, BufferSize);
- const uint *ptr = fetch(buffer, srcData, x, l, 0, ditherPtr);
- store(destData, ptr, x, l, 0, ditherPtr);
+ const uint *ptr = fetch(buffer, srcData, x, l, nullptr, ditherPtr);
+ store(destData, ptr, x, l, nullptr, ditherPtr);
x += l;
}
srcData += src->bytes_per_line;
@@ -257,17 +257,32 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im
// Cannot be used with indexed formats or between formats with different pixel depths.
Q_ASSERT(dst_format > QImage::Format_Indexed8);
Q_ASSERT(data->format > QImage::Format_Indexed8);
- if (data->depth != qt_depthForFormat(dst_format))
+ const int destDepth = qt_depthForFormat(dst_format);
+ if (data->depth < destDepth)
return false;
- uint buf[BufferSize];
- uint *buffer = buf;
const QPixelLayout *srcLayout = &qPixelLayouts[data->format];
const QPixelLayout *destLayout = &qPixelLayouts[dst_format];
+
+ // The precision here is only ARGB32PM so don't convert between higher accuracy
+ // formats (assert instead when we have a convert_generic_over_rgb64_inplace).
+ if (qt_highColorPrecision(data->format, !destLayout->hasAlphaChannel)
+ && qt_highColorPrecision(dst_format, !srcLayout->hasAlphaChannel))
+ return false;
+
+ uint buf[BufferSize];
+ uint *buffer = buf;
uchar *srcData = data->data;
+ uchar *destData = data->data;
- Q_ASSERT(srcLayout->bpp == destLayout->bpp);
- Q_ASSERT(srcLayout->bpp != QPixelLayout::BPP64);
+ QImageData::ImageSizeParameters params = { data->bytes_per_line, data->nbytes };
+ if (data->depth != destDepth) {
+ params = QImageData::calculateImageParameters(data->width, data->height, destDepth);
+ if (!params.isValid())
+ return false;
+ }
+
+ Q_ASSERT(destLayout->bpp != QPixelLayout::BPP64);
FetchAndConvertPixelsFunc fetch = srcLayout->fetchToARGB32PM;
ConvertAndStorePixelsFunc store = destLayout->storeFromARGB32PM;
if (!srcLayout->hasAlphaChannel && destLayout->storeFromRGB32) {
@@ -299,7 +314,7 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im
store = destLayout->storeFromRGB32;
}
QDitherInfo dither;
- QDitherInfo *ditherPtr = 0;
+ QDitherInfo *ditherPtr = nullptr;
if ((flags & Qt::PreferDither) && (flags & Qt::Dither_Mask) != Qt::ThresholdDither)
ditherPtr = &dither;
@@ -309,15 +324,26 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im
while (x < data->width) {
dither.x = x;
int l = data->width - x;
- if (destLayout->bpp == QPixelLayout::BPP32)
+ if (srcLayout->bpp == QPixelLayout::BPP32)
buffer = reinterpret_cast<uint *>(srcData) + x;
else
l = qMin(l, BufferSize);
const uint *ptr = fetch(buffer, srcData, x, l, nullptr, ditherPtr);
- store(srcData, ptr, x, l, nullptr, ditherPtr);
+ store(destData, ptr, x, l, nullptr, ditherPtr);
x += l;
}
srcData += data->bytes_per_line;
+ destData += params.bytesPerLine;
+ }
+ if (params.totalSize != data->nbytes) {
+ Q_ASSERT(params.totalSize < data->nbytes);
+ void *newData = realloc(data->data, params.totalSize);
+ if (newData) {
+ data->data = (uchar *)newData;
+ data->nbytes = params.totalSize;
+ }
+ data->bytes_per_line = params.bytesPerLine;
+ data->depth = destDepth;
}
data->format = dst_format;
return true;
@@ -626,12 +652,13 @@ static bool convert_rgbswap_generic_inplace(QImageData *data, Qt::ImageConversio
}
template<QtPixelOrder PixelOrder, bool RGBA>
-static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
+static void convert_ARGB_to_A2RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
{
- Q_ASSERT(RGBA || src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32);
- Q_ASSERT(!RGBA || src->format == QImage::Format_RGBX8888 || src->format == QImage::Format_RGBA8888);
- Q_ASSERT(dest->format == QImage::Format_BGR30 || dest->format == QImage::Format_RGB30);
+ Q_ASSERT(RGBA || src->format == QImage::Format_ARGB32);
+ Q_ASSERT(!RGBA || src->format == QImage::Format_RGBA8888);
+ Q_ASSERT(dest->format == QImage::Format_A2BGR30_Premultiplied
+ || dest->format == QImage::Format_A2RGB30_Premultiplied);
Q_ASSERT(src->width == dest->width);
Q_ASSERT(src->height == dest->height);
@@ -646,7 +673,9 @@ static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::Im
QRgb c = *src_data;
if (RGBA)
c = RGBA2ARGB(c);
- *dest_data = qConvertRgb32ToRgb30<PixelOrder>(c);
+ const uint alpha = (qAlpha(c) >> 6) * 85;
+ c = BYTE_MUL(c, alpha);
+ *dest_data = (qConvertRgb32ToRgb30<PixelOrder>(c) & 0x3fffffff) | (alpha << 30);
++src_data;
++dest_data;
}
@@ -656,10 +685,10 @@ static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::Im
}
template<QtPixelOrder PixelOrder, bool RGBA>
-static bool convert_RGB_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags)
+static bool convert_ARGB_to_A2RGB30_inplace(QImageData *data, Qt::ImageConversionFlags)
{
- Q_ASSERT(RGBA || (data->format == QImage::Format_RGB32 || data->format == QImage::Format_ARGB32));
- Q_ASSERT(!RGBA || (data->format == QImage::Format_RGBX8888 || data->format == QImage::Format_RGBA8888));
+ Q_ASSERT(RGBA || data->format == QImage::Format_ARGB32);
+ Q_ASSERT(!RGBA || data->format == QImage::Format_RGBA8888);
const int pad = (data->bytes_per_line >> 2) - data->width;
QRgb *rgb_data = (QRgb *) data->data;
@@ -670,13 +699,16 @@ static bool convert_RGB_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFl
QRgb c = *rgb_data;
if (RGBA)
c = RGBA2ARGB(c);
- *rgb_data = qConvertRgb32ToRgb30<PixelOrder>(c);
+ const uint alpha = (qAlpha(c) >> 6) * 85;
+ c = BYTE_MUL(c, alpha);
+ *rgb_data = (qConvertRgb32ToRgb30<PixelOrder>(c) & 0x3fffffff) | (alpha << 30);
++rgb_data;
}
rgb_data += pad;
}
- data->format = (PixelOrder == PixelOrderRGB) ? QImage::Format_RGB30 : QImage::Format_BGR30;
+ data->format = (PixelOrder == PixelOrderRGB) ? QImage::Format_A2RGB30_Premultiplied
+ : QImage::Format_A2BGR30_Premultiplied;
return true;
}
@@ -819,240 +851,6 @@ static bool convert_A2RGB30_PM_to_ARGB_inplace(QImageData *data, Qt::ImageConver
return true;
}
-static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConversionFlags)
-{
- Q_ASSERT(data->format == QImage::Format_Indexed8);
- Q_ASSERT(data->own_data);
-
- const int depth = 32;
- auto params = QImageData::calculateImageParameters(data->width, data->height, depth);
- if (params.bytesPerLine < 0)
- return false;
- uchar *const newData = (uchar *)realloc(data->data, params.totalSize);
- if (!newData)
- return false;
-
- data->data = newData;
-
- // start converting from the end because the end image is bigger than the source
- uchar *src_data = newData + data->nbytes; // end of src
- quint32 *dest_data = (quint32 *) (newData + params.totalSize); // end of dest > end of src
- const int width = data->width;
- const int src_pad = data->bytes_per_line - width;
- const int dest_pad = (params.bytesPerLine >> 2) - width;
- if (data->colortable.size() == 0) {
- data->colortable.resize(256);
- for (int i = 0; i < 256; ++i)
- data->colortable[i] = qRgb(i, i, i);
- } else {
- for (int i = 0; i < data->colortable.size(); ++i)
- data->colortable[i] = qPremultiply(data->colortable.at(i));
-
- // Fill the rest of the table in case src_data > colortable.size()
- const int oldSize = data->colortable.size();
- const QRgb lastColor = data->colortable.at(oldSize - 1);
- data->colortable.insert(oldSize, 256 - oldSize, lastColor);
- }
-
- for (int i = 0; i < data->height; ++i) {
- src_data -= src_pad;
- dest_data -= dest_pad;
- for (int pixI = 0; pixI < width; ++pixI) {
- --src_data;
- --dest_data;
- *dest_data = data->colortable.at(*src_data);
- }
- }
-
- data->colortable = QVector<QRgb>();
- data->format = QImage::Format_ARGB32_Premultiplied;
- data->bytes_per_line = params.bytesPerLine;
- data->depth = depth;
- data->nbytes = params.totalSize;
-
- return true;
-}
-
-static bool convert_indexed8_to_ARGB_inplace(QImageData *data, Qt::ImageConversionFlags)
-{
- Q_ASSERT(data->format == QImage::Format_Indexed8);
- Q_ASSERT(data->own_data);
-
- const int depth = 32;
- auto params = QImageData::calculateImageParameters(data->width, data->height, depth);
- if (params.bytesPerLine < 0)
- return false;
- uchar *const newData = (uchar *)realloc(data->data, params.totalSize);
- if (!newData)
- return false;
-
- data->data = newData;
-
- // start converting from the end because the end image is bigger than the source
- uchar *src_data = newData + data->nbytes;
- quint32 *dest_data = (quint32 *) (newData + params.totalSize);
- const int width = data->width;
- const int src_pad = data->bytes_per_line - width;
- const int dest_pad = (params.bytesPerLine >> 2) - width;
- if (data->colortable.size() == 0) {
- data->colortable.resize(256);
- for (int i = 0; i < 256; ++i)
- data->colortable[i] = qRgb(i, i, i);
- } else {
- // Fill the rest of the table in case src_data > colortable.size()
- const int oldSize = data->colortable.size();
- const QRgb lastColor = data->colortable.at(oldSize - 1);
- data->colortable.insert(oldSize, 256 - oldSize, lastColor);
- }
-
- for (int i = 0; i < data->height; ++i) {
- src_data -= src_pad;
- dest_data -= dest_pad;
- for (int pixI = 0; pixI < width; ++pixI) {
- --src_data;
- --dest_data;
- *dest_data = (quint32) data->colortable.at(*src_data);
- }
- }
-
- data->colortable = QVector<QRgb>();
- data->format = QImage::Format_ARGB32;
- data->bytes_per_line = params.bytesPerLine;
- data->depth = depth;
- data->nbytes = params.totalSize;
-
- return true;
-}
-
-static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversionFlags flags)
-{
- Q_ASSERT(data->format == QImage::Format_Indexed8);
- Q_ASSERT(data->own_data);
-
- if (data->has_alpha_clut) {
- for (int i = 0; i < data->colortable.size(); ++i)
- data->colortable[i] |= 0xff000000;
- }
-
- if (!convert_indexed8_to_ARGB_inplace(data, flags))
- return false;
-
- data->format = QImage::Format_RGB32;
- return true;
-}
-
-static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConversionFlags)
-{
- Q_ASSERT(data->format == QImage::Format_Indexed8);
- Q_ASSERT(data->own_data);
-
- const int depth = 16;
- auto params = QImageData::calculateImageParameters(data->width, data->height, depth);
- if (params.bytesPerLine < 0)
- return false;
- uchar *const newData = (uchar *)realloc(data->data, params.totalSize);
- if (!newData)
- return false;
-
- data->data = newData;
-
- // start converting from the end because the end image is bigger than the source
- uchar *src_data = newData + data->nbytes;
- quint16 *dest_data = (quint16 *) (newData + params.totalSize);
- const int width = data->width;
- const int src_pad = data->bytes_per_line - width;
- const int dest_pad = (params.bytesPerLine >> 1) - width;
-
- quint16 colorTableRGB16[256];
- const int tableSize = data->colortable.size();
- if (tableSize == 0) {
- for (int i = 0; i < 256; ++i)
- colorTableRGB16[i] = qConvertRgb32To16(qRgb(i, i, i));
- } else {
- // 1) convert the existing colors to RGB16
- for (int i = 0; i < tableSize; ++i)
- colorTableRGB16[i] = qConvertRgb32To16(data->colortable.at(i));
- data->colortable = QVector<QRgb>();
-
- // 2) fill the rest of the table in case src_data > colortable.size()
- const quint16 lastColor = colorTableRGB16[tableSize - 1];
- for (int i = tableSize; i < 256; ++i)
- colorTableRGB16[i] = lastColor;
- }
-
- for (int i = 0; i < data->height; ++i) {
- src_data -= src_pad;
- dest_data -= dest_pad;
- for (int pixI = 0; pixI < width; ++pixI) {
- --src_data;
- --dest_data;
- *dest_data = colorTableRGB16[*src_data];
- }
- }
-
- data->format = QImage::Format_RGB16;
- data->bytes_per_line = params.bytesPerLine;
- data->depth = depth;
- data->nbytes = params.totalSize;
-
- return true;
-}
-
-static bool convert_RGB_to_RGB16_inplace(QImageData *data, Qt::ImageConversionFlags)
-{
- Q_ASSERT(data->format == QImage::Format_RGB32);
- Q_ASSERT(data->own_data);
-
- const int depth = 16;
-
- // cannot overflow, since we're shrinking the buffer
- const qsizetype dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2;
- const qsizetype src_bytes_per_line = data->bytes_per_line;
- quint32 *src_data = (quint32 *) data->data;
- quint16 *dst_data = (quint16 *) data->data;
-
- for (int i = 0; i < data->height; ++i) {
- for (int j = 0; j < data->width; ++j)
- dst_data[j] = qConvertRgb32To16(src_data[j]);
- src_data = (quint32 *) (((char*)src_data) + src_bytes_per_line);
- dst_data = (quint16 *) (((char*)dst_data) + dst_bytes_per_line);
- }
- data->format = QImage::Format_RGB16;
- data->bytes_per_line = dst_bytes_per_line;
- data->depth = depth;
- data->nbytes = dst_bytes_per_line * data->height;
- uchar *const newData = (uchar *)realloc(data->data, data->nbytes);
- if (newData)
- data->data = newData;
-
- // can't fail, since we're shrinking
- return true;
-}
-
-static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src)
-{
- Q_ASSERT(src->format == QImage::Format_ARGB32_Premultiplied || src->format == QImage::Format_RGBA8888_Premultiplied);
- Q_ASSERT(dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_RGBA8888);
- Q_ASSERT(src->width == dest->width);
- Q_ASSERT(src->height == dest->height);
-
- const int src_pad = (src->bytes_per_line >> 2) - src->width;
- const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;
- const QRgb *src_data = (QRgb *) src->data;
- QRgb *dest_data = (QRgb *) dest->data;
-
- for (int i = 0; i < src->height; ++i) {
- const QRgb *end = src_data + src->width;
- while (src_data < end) {
- *dest_data = qUnpremultiply(*src_data);
- ++src_data;
- ++dest_data;
- }
- src_data += src_pad;
- dest_data += dest_pad;
- }
-}
-
static void convert_RGBA_to_RGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
{
Q_ASSERT(src->format == QImage::Format_RGBA8888 || src->format == QImage::Format_RGBX8888);
@@ -1719,7 +1517,7 @@ static void convert_X_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageC
static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
{
QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
- convert_ARGB_PM_to_ARGB(tmp.data(), src);
+ convert_generic(tmp.data(), src, Qt::AutoColor);
dither_to_Mono(dst, tmp.data(), flags, false);
}
@@ -1999,7 +1797,7 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
{
QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
- convert_ARGB_PM_to_ARGB(tmp.data(), src);
+ convert_generic(tmp.data(), src, Qt::AutoColor);
convert_RGB_to_Indexed8(dst, tmp.data(), flags);
}
@@ -2353,9 +2151,9 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
0,
0,
0,
- convert_RGB_to_RGB30<PixelOrderBGR, false>,
0,
- convert_RGB_to_RGB30<PixelOrderRGB, false>,
+ 0,
+ 0,
0,
0, 0,
0, 0, 0, 0, 0
@@ -2381,10 +2179,10 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
convert_ARGB_to_RGBx,
convert_ARGB_to_RGBA,
0,
- convert_RGB_to_RGB30<PixelOrderBGR, false>,
0,
- convert_RGB_to_RGB30<PixelOrderRGB, false>,
+ convert_ARGB_to_A2RGB30<PixelOrderBGR, false>,
0,
+ convert_ARGB_to_A2RGB30<PixelOrderRGB, false>,
0, 0,
0,
convert_ARGB32_to_RGBA64<false>,
@@ -2634,9 +2432,9 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
0,
convert_passthrough,
convert_passthrough,
- convert_RGB_to_RGB30<PixelOrderBGR, true>,
0,
- convert_RGB_to_RGB30<PixelOrderRGB, true>,
+ 0,
+ 0,
0,
0, 0,
0, 0, 0, 0, 0
@@ -2661,10 +2459,10 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
mask_alpha_converter_RGBx,
0,
0,
- convert_RGB_to_RGB30<PixelOrderBGR, true>,
0,
- convert_RGB_to_RGB30<PixelOrderRGB, true>,
+ convert_ARGB_to_A2RGB30<PixelOrderBGR, true>,
0,
+ convert_ARGB_to_A2RGB30<PixelOrderRGB, true>,
0, 0,
0,
convert_ARGB32_to_RGBA64<true>,
@@ -2978,10 +2776,10 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
0,
0,
0,
- convert_indexed8_to_RGB_inplace,
- convert_indexed8_to_ARGB_inplace,
- convert_indexed8_to_ARGB_PM_inplace,
- convert_indexed8_to_RGB16_inplace,
+ 0,
+ 0,
+ 0,
+ 0,
0,
0,
0,
@@ -3005,7 +2803,6 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
0,
mask_alpha_converter_inplace<QImage::Format_ARGB32>,
mask_alpha_converter_inplace<QImage::Format_ARGB32_Premultiplied>,
- convert_RGB_to_RGB16_inplace,
0,
0,
0,
@@ -3017,9 +2814,10 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
0,
0,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderBGR, false>,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderRGB, false>,
+ 0,
+ 0,
+ 0,
0,
0, 0,
0, 0, 0, 0, 0
@@ -3044,10 +2842,10 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
convert_ARGB_to_RGBA_inplace<QImage::Format_RGBX8888>,
convert_ARGB_to_RGBA_inplace<QImage::Format_RGBA8888>,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderBGR, false>,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderRGB, false>,
+ convert_ARGB_to_A2RGB30_inplace<PixelOrderBGR, false>,
0,
+ convert_ARGB_to_A2RGB30_inplace<PixelOrderRGB, false>,
0, 0,
0, 0, 0, 0, 0
}, // Format_ARGB32
@@ -3123,9 +2921,9 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
0,
convert_passthrough_inplace<QImage::Format_RGBA8888>,
convert_passthrough_inplace<QImage::Format_RGBA8888_Premultiplied>,
- convert_RGB_to_RGB30_inplace<PixelOrderBGR, true>,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderRGB, true>,
+ 0,
+ 0,
0,
0, 0,
0, 0, 0, 0, 0
@@ -3150,10 +2948,10 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
mask_alpha_converter_rgbx_inplace,
0,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderBGR, true>,
0,
- convert_RGB_to_RGB30_inplace<PixelOrderRGB, true>,
+ convert_ARGB_to_A2RGB30_inplace<PixelOrderBGR, true>,
0,
+ convert_ARGB_to_A2RGB30_inplace<PixelOrderRGB, true>,
0, 0,
0, 0, 0, 0, 0
}, // Format_RGBA8888
diff --git a/src/gui/image/qimage_p.h b/src/gui/image/qimage_p.h
index 2b1720580a..9277472c3c 100644
--- a/src/gui/image/qimage_p.h
+++ b/src/gui/image/qimage_p.h
@@ -276,6 +276,29 @@ inline QImage::Format qt_alphaVersion(QImage::Format format)
return QImage::Format_ARGB32_Premultiplied;
}
+inline bool qt_highColorPrecision(QImage::Format format, bool opaque = false)
+{
+ // Formats with higher color precision than ARGB32_Premultiplied.
+ switch (format) {
+ case QImage::Format_ARGB32:
+ case QImage::Format_RGBA8888:
+ return !opaque;
+ case QImage::Format_BGR30:
+ case QImage::Format_RGB30:
+ case QImage::Format_A2BGR30_Premultiplied:
+ case QImage::Format_A2RGB30_Premultiplied:
+ case QImage::Format_RGBX64:
+ case QImage::Format_RGBA64:
+ case QImage::Format_RGBA64_Premultiplied:
+ case QImage::Format_Grayscale16:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+
inline QImage::Format qt_maybeAlphaVersionWithSameDepth(QImage::Format format)
{
const QImage::Format toFormat = qt_alphaVersion(format);
diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp
index 0e7b541cf2..0c9083a16e 100644
--- a/src/gui/image/qimageiohandler.cpp
+++ b/src/gui/image/qimageiohandler.cpp
@@ -288,7 +288,7 @@ public:
QImageIOHandlerPrivate::QImageIOHandlerPrivate(QImageIOHandler *q)
{
- device = 0;
+ device = nullptr;
q_ptr = q;
}
@@ -416,18 +416,16 @@ QByteArray QImageIOHandler::format() const
\sa read(), QIODevice::peek()
*/
-#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
Use format() instead.
*/
-QByteArray QImageIOHandler::name() const
+QByteArray QImageIOHandler::name() const // ### Qt6: remove
{
return format();
}
-#endif
/*!
Writes the image \a image to the assigned device. Returns \c true on
diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h
index c20b84afbb..a4acf9dfe0 100644
--- a/src/gui/image/qimageiohandler.h
+++ b/src/gui/image/qimageiohandler.h
@@ -69,10 +69,8 @@ public:
void setFormat(const QByteArray &format) const;
QByteArray format() const;
-#if QT_DEPRECATED_SINCE(5, 13)
QT_DEPRECATED_X("Use QImageIOHandler::format() instead")
virtual QByteArray name() const;
-#endif
virtual bool canRead() const = 0;
virtual bool read(QImage *image) = 0;
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index dff24b449a..6139cf99c9 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -179,10 +179,10 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
bool ignoresFormatAndExtension)
{
if (!autoDetectImageFormat && format.isEmpty())
- return 0;
+ return nullptr;
QByteArray form = format.toLower();
- QImageIOHandler *handler = 0;
+ QImageIOHandler *handler = nullptr;
QByteArray suffix;
#ifndef QT_NO_IMAGEFORMATPLUGIN
@@ -450,7 +450,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
qDebug("QImageReader::createReadHandler: no handlers found. giving up.");
#endif
// no handler: give up.
- return 0;
+ return nullptr;
}
handler->setDevice(device);
@@ -500,9 +500,9 @@ public:
QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq)
: autoDetectImageFormat(true), ignoresFormatAndExtension(false)
{
- device = 0;
+ device = nullptr;
deleteDevice = false;
- handler = 0;
+ handler = nullptr;
quality = -1;
imageReaderError = QImageReader::UnknownError;
autoTransform = UsePluginDefault;
@@ -571,7 +571,7 @@ bool QImageReaderPrivate::initHandler()
}
// assign a handler
- if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
+ if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == nullptr) {
imageReaderError = QImageReader::UnsupportedFormatError;
errorString = QImageReader::tr("Unsupported image format");
return false;
@@ -1089,7 +1089,7 @@ QList<QByteArray> QImageReader::supportedSubTypes() const
return QList<QByteArray>();
if (d->handler->supportsOption(QImageIOHandler::SupportedSubTypes))
- return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >();
+ return qvariant_cast<QList<QByteArray> >(d->handler->option(QImageIOHandler::SupportedSubTypes));
return QList<QByteArray>();
}
diff --git a/src/gui/image/qimagereaderwriterhelpers.cpp b/src/gui/image/qimagereaderwriterhelpers.cpp
index a5b7fb6449..dd56d887a7 100644
--- a/src/gui/image/qimagereaderwriterhelpers.cpp
+++ b/src/gui/image/qimagereaderwriterhelpers.cpp
@@ -63,7 +63,7 @@ static void appendImagePluginFormats(QFactoryLoader *loader,
const PluginKeyMap keyMap = loader->keyMap();
const PluginKeyMapConstIterator cend = keyMap.constEnd();
int i = -1;
- QImageIOPlugin *plugin = 0;
+ QImageIOPlugin *plugin = nullptr;
result->reserve(result->size() + keyMap.size());
for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) {
if (it.key() != i) {
@@ -71,7 +71,7 @@ static void appendImagePluginFormats(QFactoryLoader *loader,
plugin = qobject_cast<QImageIOPlugin *>(loader->instance(i));
}
const QByteArray key = it.value().toLatin1();
- if (plugin && (plugin->capabilities(0, key) & cap) != 0)
+ if (plugin && (plugin->capabilities(nullptr, key) & cap) != 0)
result->append(key);
}
}
@@ -92,7 +92,7 @@ static void appendImagePluginMimeTypes(QFactoryLoader *loader,
const int keyCount = keys.size();
for (int k = 0; k < keyCount; ++k) {
const QByteArray key = keys.at(k).toString().toLatin1();
- if (plugin && (plugin->capabilities(0, key) & cap) != 0) {
+ if (plugin && (plugin->capabilities(nullptr, key) & cap) != 0) {
result->append(mimeTypes.at(k).toString().toLatin1());
if (resultKeys)
resultKeys->append(key);
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index ec66588ddf..512da5c432 100644
--- a/src/gui/image/qimagewriter.cpp
+++ b/src/gui/image/qimagewriter.cpp
@@ -139,7 +139,7 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device,
{
QByteArray form = format.toLower();
QByteArray suffix;
- QImageIOHandler *handler = 0;
+ QImageIOHandler *handler = nullptr;
#ifndef QT_NO_IMAGEFORMATPLUGIN
typedef QMultiMap<int, QString> PluginKeyMap;
@@ -226,7 +226,7 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device,
#endif // QT_NO_IMAGEFORMATPLUGIN
if (!handler)
- return 0;
+ return nullptr;
handler->setDevice(device);
if (!testFormat.isEmpty())
@@ -270,9 +270,9 @@ public:
*/
QImageWriterPrivate::QImageWriterPrivate(QImageWriter *qq)
{
- device = 0;
+ device = nullptr;
deleteDevice = false;
- handler = 0;
+ handler = nullptr;
quality = -1;
compression = -1;
gamma = 0.0;
@@ -304,7 +304,7 @@ bool QImageWriterPrivate::canWriteHelper()
errorString = QImageWriter::tr("Device not writable");
return false;
}
- if (!handler && (handler = createWriteHandlerHelper(device, format)) == 0) {
+ if (!handler && (handler = createWriteHandlerHelper(device, format)) == nullptr) {
imageWriterError = QImageWriter::UnsupportedFormatError;
errorString = QImageWriter::tr("Unsupported image format");
return false;
@@ -403,7 +403,7 @@ void QImageWriter::setDevice(QIODevice *device)
d->device = device;
d->deleteDevice = false;
delete d->handler;
- d->handler = 0;
+ d->handler = nullptr;
}
/*!
@@ -561,7 +561,7 @@ QList<QByteArray> QImageWriter::supportedSubTypes() const
{
if (!supportsOption(QImageIOHandler::SupportedSubTypes))
return QList<QByteArray>();
- return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >();
+ return qvariant_cast<QList<QByteArray> >(d->handler->option(QImageIOHandler::SupportedSubTypes));
}
/*!
@@ -823,7 +823,7 @@ QString QImageWriter::errorString() const
*/
bool QImageWriter::supportsOption(QImageIOHandler::ImageOption option) const
{
- if (!d->handler && (d->handler = createWriteHandlerHelper(d->device, d->format)) == 0) {
+ if (!d->handler && (d->handler = createWriteHandlerHelper(d->device, d->format)) == nullptr) {
d->imageWriterError = QImageWriter::UnsupportedFormatError;
d->errorString = QImageWriter::tr("Unsupported image format");
return false;
diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp
index 25fce050a1..79019d0fdf 100644
--- a/src/gui/image/qmovie.cpp
+++ b/src/gui/image/qmovie.cpp
@@ -272,7 +272,7 @@ public:
/*! \internal
*/
QMoviePrivate::QMoviePrivate(QMovie *qq)
- : reader(0), speed(100), movieState(QMovie::NotRunning),
+ : reader(nullptr), speed(100), movieState(QMovie::NotRunning),
currentFrameNumber(-1), nextFrameNumber(0), greatestFrameNumber(-1),
nextDelay(0), playCounter(-1),
cacheMode(QMovie::CacheNone), haveReadAll(false), isFirstIteration(true)
diff --git a/src/gui/image/qpaintengine_pic.cpp b/src/gui/image/qpaintengine_pic.cpp
index 6a87a01a87..e89cac452a 100644
--- a/src/gui/image/qpaintengine_pic.cpp
+++ b/src/gui/image/qpaintengine_pic.cpp
@@ -73,14 +73,14 @@ QPicturePaintEngine::QPicturePaintEngine()
: QPaintEngine(*(new QPicturePaintEnginePrivate), AllFeatures)
{
Q_D(QPicturePaintEngine);
- d->pt = 0;
+ d->pt = nullptr;
}
QPicturePaintEngine::QPicturePaintEngine(QPaintEnginePrivate &dptr)
: QPaintEngine(dptr, AllFeatures)
{
Q_D(QPicturePaintEngine);
- d->pt = 0;
+ d->pt = nullptr;
}
QPicturePaintEngine::~QPicturePaintEngine()
@@ -484,7 +484,7 @@ void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti)
#endif
const QTextItemInt &si = static_cast<const QTextItemInt &>(ti);
- if (si.chars == 0)
+ if (si.chars == nullptr)
QPaintEngine::drawTextItem(p, ti); // Draw as path
if (d->pic_d->formatMajor >= 9) {
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index e119103462..d469ac8aae 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -412,7 +412,7 @@ public:
QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); }
void setDpiX(int dpi) { dpi_x = dpi; }
void setDpiY(int dpi) { dpi_y = dpi; }
- QPaintEngine *paintEngine() const override { return 0; }
+ QPaintEngine *paintEngine() const override { return nullptr; }
int metric(PaintDeviceMetric m) const override
{
switch(m) {
@@ -663,11 +663,11 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords)
QFontMetrics fm(fnt);
QPointF pt(p.x(), p.y() - fm.ascent());
- qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/0,
- str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter);
+ qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/nullptr,
+ str, /*brect=*/nullptr, /*tabstops=*/0, /*...*/nullptr, /*tabarraylen=*/0, painter);
} else {
- qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, /*opt*/0,
- str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter);
+ qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, /*opt*/nullptr,
+ str, /*brect=*/nullptr, /*tabstops=*/0, /*...*/nullptr, /*tabarraylen=*/0, painter);
}
break;
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index b6e41f16a5..3fce64cb20 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -94,7 +94,7 @@ void QPixmap::doInit(int w, int h, int type)
if ((w > 0 && h > 0) || type == QPlatformPixmap::BitmapType)
data = QPlatformPixmap::create(w, h, (QPlatformPixmap::PixelType) type);
else
- data = 0;
+ data = nullptr;
}
/*!
@@ -780,7 +780,7 @@ 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) {
+ if (len == 0 || buf == nullptr) {
data.reset();
return false;
}
@@ -1455,7 +1455,7 @@ int QPixmap::metric(PaintDeviceMetric metric) const
*/
QPaintEngine *QPixmap::paintEngine() const
{
- return data ? data->paintEngine() : 0;
+ return data ? data->paintEngine() : nullptr;
}
/*!
diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h
index 8c1395857e..8a06ebe603 100644
--- a/src/gui/image/qpixmap.h
+++ b/src/gui/image/qpixmap.h
@@ -227,7 +227,10 @@ inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
#if QT_DEPRECATED_SINCE(5, 0)
inline QPixmap QPixmap::alphaChannel() const
{
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
return QPixmap::fromImage(toImage().alphaChannel());
+ QT_WARNING_POP
}
inline void QPixmap::setAlphaChannel(const QPixmap &p)
diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp
index 649a25250c..aeed1e3b34 100644
--- a/src/gui/image/qpixmap_blitter.cpp
+++ b/src/gui/image/qpixmap_blitter.cpp
@@ -92,8 +92,8 @@ void QBlittablePlatformPixmap::setBlittable(QBlittable *blittable)
void QBlittablePlatformPixmap::resize(int width, int height)
{
- m_blittable.reset(0);
- m_engine.reset(0);
+ m_blittable.reset(nullptr);
+ m_engine.reset(nullptr);
d = QGuiApplication::primaryScreen()->depth();
w = width;
h = height;
@@ -145,8 +145,8 @@ void QBlittablePlatformPixmap::fill(const QColor &color)
// if we could just change the format, e.g. when going from
// RGB32 -> ARGB8888.
if (color.alpha() != 255 && !hasAlphaChannel()) {
- m_blittable.reset(0);
- m_engine.reset(0);
+ m_blittable.reset(nullptr);
+ m_engine.reset(nullptr);
m_alpha = true;
}
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 483d6d79a2..9709df9e0c 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -126,7 +126,7 @@ static inline bool qt_pixmapcache_thread_test()
/*!
Constructs an empty Key object.
*/
-QPixmapCache::Key::Key() : d(0)
+QPixmapCache::Key::Key() : d(nullptr)
{
}
@@ -259,9 +259,9 @@ uint qHash(const QPixmapCache::Key &k)
}
QPMCache::QPMCache()
- : QObject(0),
+ : QObject(nullptr),
QCache<QPixmapCache::Key, QPixmapCacheEntry>(cache_limit_default),
- keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)
+ keyArray(nullptr), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)
{
}
QPMCache::~QPMCache()
@@ -325,7 +325,7 @@ QPixmap *QPMCache::object(const QString &key) const
QPixmapCache::Key cacheKey = cacheKeys.value(key);
if (!cacheKey.d || !cacheKey.d->isValid) {
const_cast<QPMCache *>(this)->cacheKeys.remove(key);
- return 0;
+ return nullptr;
}
QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(cacheKey);
//We didn't find the pixmap in the cache, the key is not valid anymore
@@ -453,7 +453,7 @@ void QPMCache::releaseKey(const QPixmapCache::Key &key)
void QPMCache::clear()
{
free(keyArray);
- keyArray = 0;
+ keyArray = nullptr;
freeKey = 0;
keyArraySize = 0;
//Mark all keys as invalid
@@ -539,7 +539,7 @@ bool QPixmapCache::find(const QString &key, QPixmap *pixmap)
QPixmap *ptr = pm_cache()->object(key);
if (ptr && pixmap)
*pixmap = *ptr;
- return ptr != 0;
+ return ptr != nullptr;
}
/*!
@@ -561,7 +561,7 @@ bool QPixmapCache::find(const Key &key, QPixmap *pixmap)
QPixmap *ptr = pm_cache()->object(key);
if (ptr && pixmap)
*pixmap = *ptr;
- return ptr != 0;
+ return ptr != nullptr;
}
/*!
diff --git a/src/gui/image/qplatformpixmap.cpp b/src/gui/image/qplatformpixmap.cpp
index a2e01147c4..493f55514e 100644
--- a/src/gui/image/qplatformpixmap.cpp
+++ b/src/gui/image/qplatformpixmap.cpp
@@ -266,7 +266,7 @@ QImage QPlatformPixmap::toImage(const QRect &rect) const
QImage* QPlatformPixmap::buffer()
{
- return 0;
+ return nullptr;
}
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index d6caf6773a..251f09fe52 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -109,7 +109,7 @@ public:
};
QPngHandlerPrivate(QPngHandler *qq)
- : gamma(0.0), fileGamma(0.0), quality(50), compression(50), colorSpaceState(Undefined), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq)
+ : gamma(0.0), fileGamma(0.0), quality(50), compression(50), colorSpaceState(Undefined), png_ptr(nullptr), info_ptr(nullptr), end_info(nullptr), state(Ready), q(qq)
{ }
float gamma;
@@ -134,18 +134,18 @@ public:
struct AllocatedMemoryPointers {
AllocatedMemoryPointers()
- : row_pointers(0), accRow(0), inRow(0), outRow(0)
+ : row_pointers(nullptr), accRow(nullptr), inRow(nullptr), outRow(nullptr)
{ }
void deallocate()
{
delete [] row_pointers;
- row_pointers = 0;
+ row_pointers = nullptr;
delete [] accRow;
- accRow = 0;
+ accRow = nullptr;
delete [] inRow;
- inRow = 0;
+ inRow = nullptr;
delete [] outRow;
- outRow = 0;
+ outRow = nullptr;
}
png_byte **row_pointers;
@@ -245,13 +245,13 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scal
png_uint_32 height = 0;
int bit_depth = 0;
int color_type = 0;
- png_bytep trans_alpha = 0;
- png_color_16p trans_color_p = 0;
+ png_bytep trans_alpha = nullptr;
+ png_color_16p trans_color_p = nullptr;
int num_trans;
- png_colorp palette = 0;
+ png_colorp palette = nullptr;
int num_palette;
int interlace_method = PNG_INTERLACE_LAST;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, 0, 0);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, nullptr, nullptr);
png_set_interlace_handling(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY) {
@@ -343,7 +343,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scal
if (bit_depth != 1)
png_set_packing(png_ptr);
png_read_update_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr);
QImage::Format format = bit_depth == 1 ? QImage::Format_Mono : QImage::Format_Indexed8;
if (image.size() != QSize(width, height) || image.format() != format) {
image = QImage(width, height, format);
@@ -452,7 +452,7 @@ static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop i
int bit_depth = 0;
int color_type = 0;
int unit_type = PNG_OFFSET_PIXEL;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr);
png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, &unit_type);
uchar *data = outImage->bits();
int bpl = outImage->bytesPerLine();
@@ -478,7 +478,7 @@ static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop i
amp.accRow[i] = rval*amp.inRow[i];
// Accumulate the next input rows
for (rval = iysz-rval; rval > 0; rval-=oysz) {
- png_read_row(png_ptr, amp.inRow, NULL);
+ png_read_row(png_ptr, amp.inRow, nullptr);
quint32 fact = qMin(oysz, quint32(rval));
for (quint32 i=0; i < ibw; i++)
amp.accRow[i] += fact*amp.inRow[i];
@@ -558,11 +558,11 @@ void QPngHandlerPrivate::readPngTexts(png_info *info)
bool QPngHandlerPrivate::readPngHeader()
{
state = Error;
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,nullptr,nullptr,nullptr);
if (!png_ptr)
return false;
- png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
+ png_set_error_fn(png_ptr, nullptr, nullptr, qt_png_warning);
#if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
// Trade off a little bit of memory for better compatibility with existing images
@@ -572,21 +572,21 @@ bool QPngHandlerPrivate::readPngHeader()
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
- png_destroy_read_struct(&png_ptr, 0, 0);
- png_ptr = 0;
+ png_destroy_read_struct(&png_ptr, nullptr, nullptr);
+ png_ptr = nullptr;
return false;
}
end_info = png_create_info_struct(png_ptr);
if (!end_info) {
- png_destroy_read_struct(&png_ptr, &info_ptr, 0);
- png_ptr = 0;
+ png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
+ png_ptr = nullptr;
return false;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- png_ptr = 0;
+ png_ptr = nullptr;
return false;
}
@@ -670,7 +670,7 @@ bool QPngHandlerPrivate::readPngImage(QImage *outImage)
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- png_ptr = 0;
+ png_ptr = nullptr;
amp.deallocate();
state = Error;
return false;
@@ -689,7 +689,7 @@ bool QPngHandlerPrivate::readPngImage(QImage *outImage)
if (outImage->isNull()) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- png_ptr = 0;
+ png_ptr = nullptr;
amp.deallocate();
state = Error;
return false;
@@ -706,7 +706,7 @@ bool QPngHandlerPrivate::readPngImage(QImage *outImage)
int bit_depth = 0;
int color_type = 0;
int unit_type = PNG_OFFSET_PIXEL;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr);
png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, &unit_type);
uchar *data = outImage->bits();
int bpl = outImage->bytesPerLine();
@@ -747,7 +747,7 @@ bool QPngHandlerPrivate::readPngImage(QImage *outImage)
outImage->setText(readTexts.at(i), readTexts.at(i+1));
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- png_ptr = 0;
+ png_ptr = nullptr;
amp.deallocate();
state = Ready;
@@ -767,7 +767,7 @@ QImage::Format QPngHandlerPrivate::readImageFormat()
int bit_depth = 0, color_type = 0;
png_colorp palette;
int num_palette;
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr);
if (color_type == PNG_COLOR_TYPE_GRAY) {
// Black & White or grayscale
if (bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1) {
@@ -910,16 +910,16 @@ bool QPNGImageWriter::writeImage(const QImage& image, int compression_in, const
png_structp png_ptr;
png_infop info_ptr;
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,nullptr,nullptr,nullptr);
if (!png_ptr) {
return false;
}
- png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
+ png_set_error_fn(png_ptr, nullptr, nullptr, qt_png_warning);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
- png_destroy_write_struct(&png_ptr, 0);
+ png_destroy_write_struct(&png_ptr, nullptr);
return false;
}
@@ -1022,7 +1022,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int compression_in, const
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
if (num_trans) {
- png_set_tRNS(png_ptr, info_ptr, trans, num_trans, 0);
+ png_set_tRNS(png_ptr, info_ptr, trans, num_trans, nullptr);
}
}
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index cf105b250a..f9424b62bb 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -1175,7 +1175,7 @@ QXpmHandler::QXpmHandler()
bool QXpmHandler::readHeader()
{
state = Error;
- if (!read_xpm_header(device(), 0, index, buffer, &cpp, &ncols, &width, &height))
+ if (!read_xpm_header(device(), nullptr, index, buffer, &cpp, &ncols, &width, &height))
return false;
state = ReadHeader;
return true;
@@ -1191,7 +1191,7 @@ bool QXpmHandler::readImage(QImage *image)
return false;
}
- if (!read_xpm_body(device(), 0, index, buffer, cpp, ncols, width, height, *image)) {
+ if (!read_xpm_body(device(), nullptr, index, buffer, cpp, ncols, width, height, *image)) {
state = Error;
return false;
}