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/qimagereader.cpp') 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