From dd3229e6724f05c7c61d6ffc92b5ebfa8ece0b23 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 7 Jun 2019 13:02:03 +0200 Subject: Remove a few usages of deprecated API Change-Id: I94bad0b8d3891c6b4a55178836cfff2a4312e330 Reviewed-by: Marc Mutz --- src/gui/image/qmovie.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index 79203c7b98..c9344fe2a1 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -175,6 +175,7 @@ #include "qmovie.h" #include "qglobal.h" +#include "qelapsedtimer.h" #include "qimage.h" #include "qimagereader.h" #include "qpixmap.h" @@ -437,7 +438,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber) */ bool QMoviePrivate::next() { - QTime time; + QElapsedTimer time; time.start(); QFrameInfo info = infoForFrame(nextFrameNumber); if (!info.isValid()) -- cgit v1.2.3 From 3797704c4ff0d91f544efa791973eced07c3ef02 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 14 Jun 2019 13:08:56 +0200 Subject: Generalize image file name @2x suffix handling to higher scale factors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @3x is in use on iOS already, so extend the handling in QImageReader to all single-digit factors, like QIcon does. Fixes: QTBUG-76273 Change-Id: Ic9442731c0549dbe8f797e1ddb1a09d8447e8441 Reviewed-by: Morten Johan Sørvig --- src/gui/image/qimagereader.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 0fb1d808e5..0c75196612 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -1319,10 +1319,12 @@ bool QImageReader::read(QImage *image) } } - // successful read; check for "@2x" file name suffix and set device pixel ratio. - static bool disable2xImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING"); - if (!disable2xImageLoading && QFileInfo(fileName()).baseName().endsWith(QLatin1String("@2x"))) { - image->setDevicePixelRatio(2.0); + // successful read; check for "@Nx" file name suffix and set device pixel ratio. + static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING"); + if (!disableNxImageLoading) { + const QByteArray suffix = QFileInfo(fileName()).baseName().right(3).toLatin1(); + if (suffix.length() == 3 && suffix[0] == '@' && suffix[1] >= '2' && suffix[1] <= '9' && suffix[2] == 'x') + image->setDevicePixelRatio(suffix[1] - '0'); } if (autoTransform()) qt_imageTransform(*image, transformation()); -- cgit v1.2.3 From 84e89c1e9e00d4fab576b876cfa80e92b5602982 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 12 Jun 2019 18:06:23 +0200 Subject: Convert uses of QTime as a timer to QElapsedTimer Change-Id: I2297f61efa5adf9ea5194c7f3ff68574cbcf452c Reviewed-by: Friedemann Kleint --- src/gui/image/qmovie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index c9344fe2a1..4b588527ae 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -180,7 +180,7 @@ #include "qimagereader.h" #include "qpixmap.h" #include "qrect.h" -#include "qdatetime.h" +#include "qelapsedtimer.h" #include "qtimer.h" #include "qpair.h" #include "qmap.h" -- cgit v1.2.3 From 34fe9232dbf6a9fe58ebc4c7680bb67d2f642c40 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 10 Jun 2019 11:08:29 +0200 Subject: Port from QAtomic::load() to loadRelaxed() Semi-automated, just needed ~20 manual fixes: $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)load\(\)/$1loadRelaxed\(\)/g' -i \{\} + $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)store\(/$1storeRelaxed\(/g' -i \{\} + It can be easily improved (e.g. for store check that there are no commas after the opening parens). The most common offender is QLibrary::load, and some code using std::atomic directly. Change-Id: I07c38a3c8ed32c924ef4999e85c7e45cf48f0f6c Reviewed-by: Marc Mutz --- src/gui/image/qicon.cpp | 4 ++-- src/gui/image/qimage.cpp | 8 ++++---- src/gui/image/qpicture.cpp | 2 +- src/gui/image/qpixmap.cpp | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 1d1b6d3c49..df8220a0c6 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -987,7 +987,7 @@ bool QIcon::isNull() const */ bool QIcon::isDetached() const { - return !d || d->ref.load() == 1; + return !d || d->ref.loadRelaxed() == 1; } /*! \internal @@ -1000,7 +1000,7 @@ void QIcon::detach() delete d; d = 0; return; - } else if (d->ref.load() != 1) { + } else if (d->ref.loadRelaxed() != 1) { QIconPrivate *x = new QIconPrivate(d->engine->clone()); if (!d->ref.deref()) delete d; diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 917dde3b0f..61d32b0dec 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1082,10 +1082,10 @@ QImage::operator QVariant() const void QImage::detach() { if (d) { - if (d->is_cached && d->ref.load() == 1) + if (d->is_cached && d->ref.loadRelaxed() == 1) QImagePixmapCleanupHooks::executeImageHooks(cacheKey()); - if (d->ref.load() != 1 || d->ro_data) + if (d->ref.loadRelaxed() != 1 || d->ro_data) *this = copy(); if (d) @@ -4422,7 +4422,7 @@ qint64 QImage::cacheKey() const bool QImage::isDetached() const { - return d && d->ref.load() == 1; + return d && d->ref.loadRelaxed() == 1; } @@ -5087,7 +5087,7 @@ bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFla return true; // No in-place conversion if we have to detach - if (ref.load() > 1 || !own_data) + if (ref.loadRelaxed() > 1 || !own_data) return false; InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat]; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index fe1e4d2c9b..8548f1857e 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -235,7 +235,7 @@ void QPicture::detach() bool QPicture::isDetached() const { - return d_func()->ref.load() == 1; + return d_func()->ref.loadRelaxed() == 1; } /*! diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 399ad7453d..b6e41f16a5 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -262,7 +262,7 @@ QPixmap::QPixmap(const char * const xpm[]) QPixmap::~QPixmap() { - Q_ASSERT(!data || data->ref.load() >= 1); // Catch if ref-counting changes again + Q_ASSERT(!data || data->ref.loadRelaxed() >= 1); // Catch if ref-counting changes again } /*! @@ -910,7 +910,7 @@ void QPixmap::fill(const QColor &color) return; } - if (data->ref.load() == 1) { + if (data->ref.loadRelaxed() == 1) { // detach() will also remove this pixmap from caches, so // it has to be called even when ref == 1. detach(); @@ -1053,7 +1053,7 @@ QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) bool QPixmap::isDetached() const { - return data && data->ref.load() == 1; + return data && data->ref.loadRelaxed() == 1; } /*! @@ -1523,10 +1523,10 @@ void QPixmap::detach() rasterData->image.detach(); } - if (data->is_cached && data->ref.load() == 1) + if (data->is_cached && data->ref.loadRelaxed() == 1) QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data()); - if (data->ref.load() != 1) { + if (data->ref.loadRelaxed() != 1) { *this = copy(); } ++data->detach_no; -- cgit v1.2.3 From 6f2eabb54e3f827ebd2b90f68144b86342933869 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 19 Jun 2019 12:48:04 +0200 Subject: Remove binary compat qimage methods Change-Id: Ic8f1bd6c13468e9a19ff11a23d4b0c29afbcded4 Reviewed-by: Alexandru Croitor --- src/gui/image/image.pri | 3 -- src/gui/image/qimage.h | 9 ------ src/gui/image/qimage_compat.cpp | 66 ----------------------------------------- 3 files changed, 78 deletions(-) delete mode 100644 src/gui/image/qimage_compat.cpp (limited to 'src/gui/image') diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri index 70fccbc378..b482a6e142 100644 --- a/src/gui/image/image.pri +++ b/src/gui/image/image.pri @@ -59,9 +59,6 @@ win32:!winrt: SOURCES += image/qpixmap_win.cpp darwin: OBJECTIVE_SOURCES += image/qimage_darwin.mm -NO_PCH_SOURCES += image/qimage_compat.cpp -false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator - # Built-in image format support HEADERS += \ image/qbmphandler_p.h \ diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 7c68168be8..3f0d900a70 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -178,7 +178,6 @@ public: Format format() const; -#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QIMAGE_COMPAT_CPP) Q_REQUIRED_RESULT Q_ALWAYS_INLINE QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const & { return convertToFormat_helper(f, flags); } Q_REQUIRED_RESULT Q_ALWAYS_INLINE QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) && @@ -188,9 +187,6 @@ public: else return convertToFormat_helper(f, flags); } -#else - Q_REQUIRED_RESULT QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const; -#endif Q_REQUIRED_RESULT QImage convertToFormat(Format f, const QVector &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const; bool reinterpretAsFormat(Format f); @@ -283,7 +279,6 @@ public: static QMatrix trueMatrix(const QMatrix &, int w, int h); QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; static QTransform trueMatrix(const QTransform &, int w, int h); -#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QIMAGE_COMPAT_CPP) QImage mirrored(bool horizontally = false, bool vertically = true) const & { return mirrored_helper(horizontally, vertically); } QImage &&mirrored(bool horizontally = false, bool vertically = true) && @@ -292,10 +287,6 @@ public: { return rgbSwapped_helper(); } QImage &&rgbSwapped() && { rgbSwapped_inplace(); return std::move(*this); } -#else - QImage mirrored(bool horizontally = false, bool vertically = true) const; - QImage rgbSwapped() const; -#endif void invertPixels(InvertMode = InvertRgb); QColorSpace colorSpace() const; diff --git a/src/gui/image/qimage_compat.cpp b/src/gui/image/qimage_compat.cpp deleted file mode 100644 index ba31a9ac9b..0000000000 --- a/src/gui/image/qimage_compat.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifdef QIMAGE_H -# error "This file cannot be used with precompiled headers" -#endif -#define QT_COMPILING_QIMAGE_COMPAT_CPP - -#include "qimage.h" - -QT_BEGIN_NAMESPACE - -// These implementations must be the same as the inline versions in qimage.h - -QImage QImage::convertToFormat(Format f, Qt::ImageConversionFlags flags) const -{ - return convertToFormat_helper(f, flags); -} - -QImage QImage::mirrored(bool horizontally, bool vertically) const -{ - return mirrored_helper(horizontally, vertically); -} - -QImage QImage::rgbSwapped() const -{ - return rgbSwapped_helper(); -} - -QT_END_NAMESPACE -- cgit v1.2.3 From cc13b99781b0bbf5f9d09b2c5b081a085762cd0c Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 24 Jun 2019 17:43:16 +0200 Subject: Do not downscale png when the size is exactly right Don't go through the doScaledRead path (i.e. calling read_image_scaled) when reading an image that the target size is the image of the file we are opening. This makes the loading of the file much faster while keeping the output correct. [ChangeLog][QtGui][QImage] Improve loading time when loading png files that have the same size as the target. Change-Id: I2a33c49fe1ce52ec296c2175ee542b5bcdec2c4b Reviewed-by: Eirik Aavitsland --- src/gui/image/qpnghandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 801b30881d..e7e998efd1 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -394,7 +394,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scal } QSize outSize(width,height); if (!scaledSize.isEmpty() && quint32(scaledSize.width()) <= width && - quint32(scaledSize.height()) <= height && interlace_method == PNG_INTERLACE_NONE) { + quint32(scaledSize.height()) <= height && scaledSize != outSize && interlace_method == PNG_INTERLACE_NONE) { // Do inline downscaling outSize = scaledSize; if (doScaledRead) -- cgit v1.2.3 From 5fb5ec93d69e6bfa918b643f2291503e57d13ad0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 25 Jun 2019 11:20:55 +0200 Subject: QImageWriter/XPM: Fix out of bounds string access Fix warnings: QWWARN : tst_QImageReader::readFromFileAfterJunk(xpm) Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt. QWARN : tst_QImageReader::readFromFileAfterJunk(xpm) Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt. QWARN : tst_QImageReader::readFromFileAfterJunk(xpm) Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt. introduced by qtbase/c2d2757bccc68e1b981df059786c2e76f2969530 (5.14). Refactor write_xpm_image() to use a QByteArray and append(). Change-Id: I25e6270e2e5fcb868d4ee38e3b294afc7ee27dcc Reviewed-by: Eirik Aavitsland --- src/gui/image/qxpmhandler.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index deff56aa58..cf105b250a 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -1125,8 +1125,6 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const break; } - QString line; - // write header QTextStream s(device); s << "/* XPM */" << Qt::endl @@ -1137,35 +1135,29 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const QMap::Iterator c = colorMap.begin(); while (c != colorMap.end()) { QRgb color = c.key(); - if (image.format() != QImage::Format_RGB32 && !qAlpha(color)) - line = QString::asprintf("\"%s c None\"", - xpm_color_name(cpp, *c)); - else - line = QString::asprintf("\"%s c #%02x%02x%02x\"", - xpm_color_name(cpp, *c), - qRed(color), - qGreen(color), - qBlue(color)); + const QString line = image.format() != QImage::Format_RGB32 && !qAlpha(color) + ? QString::asprintf("\"%s c None\"", xpm_color_name(cpp, *c)) + : QString::asprintf("\"%s c #%02x%02x%02x\"", xpm_color_name(cpp, *c), + qRed(color), qGreen(color), qBlue(color)); ++c; s << ',' << Qt::endl << line; } // write pixels, limit to 4 characters per pixel - line.truncate(cpp*w); + QByteArray line; for(y=0; y(image.constScanLine(y)); - int cc = 0; for(x=0; x 1) { - line[cc++] = QLatin1Char(chars[1]); + line.append(chars[1]); if (cpp > 2) { - line[cc++] = QLatin1Char(chars[2]); - if (cpp > 3) { - line[cc++] = QLatin1Char(chars[3]); - } + line.append(chars[2]); + if (cpp > 3) + line.append(chars[3]); } } } -- cgit v1.2.3