summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Blackquill <uhhadd@gmail.com>2021-08-24 14:36:34 -0400
committerIlya Fedin <fedin-ilja2010@ya.ru>2022-01-23 12:28:41 +0400
commit042dec848ae53c222077ea5ba56165da43b001e2 (patch)
tree65a0fcb0653cf7768ad7c6a0c00c2ea9becf2e7d
parent751f701f4f2484b0fbad14904496c9a03cd787a2 (diff)
downloadqtwayland-042dec848ae53c222077ea5ba56165da43b001e2.tar.gz
Correctly detect if image format is supported by QImageWriter
The code queries potential image formats by stripping a mimetype of its 'image/' prefix and making the rest of the mimetype capitalised, such as 'image/png' -> 'PNG'. The problem is that this is then searched for in QImageWriter::supportedImageFormats() by simple equality. The method returns a list of lowercase byte arrays, not uppercase. As the codepath can never match due to checking for an uppercase word in an array of lowercase words, this means that images are effectively always sent as BMP format, even if they should be sent in other formats, such as PNG or JPEG. A simple inspection with GDB (or a qDebug) reveals this: ``` (gdb) p QImageWriter::supportedImageFormats() $31 = {"bmp" = {...}, "bw" = {...}, "cur" = {...}, "eps" = {...}, "epsf" = {...}, "epsi" = {...}, "icns" = {...}, "ico" = {...}, "jp2" = {...}, "jpeg" = {...}, "jpg" = {...}, "pbm" = {...}, "pcx" = {...}, "pgm" = {...}, "pic" = {...}, "png" = {...}, "ppm" = {...}, "rgb" = {...}, "rgba" = {...}, "sgi" = {...}, "tga" = {...}, "tif" = {...}, "tiff" = {...}, "wbmp" = {...}, "webp" = {...}, "xbm" = {...}, "xpm" = {...}} ``` ``` (gdb) p QImageWriter::supportedImageFormats().contains("PNG") $32 = false ``` ``` (gdb) p QImageWriter::supportedImageFormats().contains("png") $33 = true ``` The fix for this is simple: lowercase the remainder of the mimetype, instead of uppercasing it, and we can start hitting the codepath that's supposed to write non-BMP formats. Change-Id: Id3e9b730b7edcabcb2f1b04d8ef0a4c1fb9c9159 Reviewed-by: David Edmundson <davidedmundson@kde.org> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 6072c1dc87e185f30c014f764737ac97b906640f) Reviewed-by: Jan Blackquill <uhhadd@gmail.com>
-rw-r--r--src/shared/qwaylandmimehelper.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/shared/qwaylandmimehelper.cpp b/src/shared/qwaylandmimehelper.cpp
index a5fdd34d..051a91dc 100644
--- a/src/shared/qwaylandmimehelper.cpp
+++ b/src/shared/qwaylandmimehelper.cpp
@@ -60,7 +60,7 @@ QByteArray QWaylandMimeHelper::getByteArray(QMimeData *mimeData, const QString &
buf.open(QIODevice::ReadWrite);
QByteArray fmt = "BMP";
if (mimeType.startsWith(QLatin1String("image/"))) {
- QByteArray imgFmt = mimeType.mid(6).toUpper().toLatin1();
+ QByteArray imgFmt = mimeType.mid(6).toLower().toLatin1();
if (QImageWriter::supportedImageFormats().contains(imgFmt))
fmt = imgFmt;
}