From 1d128ed1dfbcf49453ada922e54381c37264fde5 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 23 Apr 2019 16:30:15 +0200 Subject: Fix artifacts when reading certain 32 bit ico files Images in an ico file contains transparency information stored as a 1 bit mask. However, when the depth is 32 bit, it means there is an alpha channel present, and the mask should be ignored. The Qt ico handler failed to do that. This has gone unnoticed, since the mask in such images is typically set to all 0s, and so makes no difference to the result. But ico files exist that contain junk mask data, so fix the reader to ignore it properly. Fixes: QTBUG-75214 Change-Id: I1b4456d71689ec783076a582f2fb215e7dc56e62 Reviewed-by: Allan Sandfeld Jensen --- src/plugins/imageformats/ico/qicohandler.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/plugins/imageformats/ico/qicohandler.cpp') diff --git a/src/plugins/imageformats/ico/qicohandler.cpp b/src/plugins/imageformats/ico/qicohandler.cpp index 30935cacda..4908850cc5 100644 --- a/src/plugins/imageformats/ico/qicohandler.cpp +++ b/src/plugins/imageformats/ico/qicohandler.cpp @@ -523,17 +523,21 @@ QImage ICOReader::iconAt(int index) if (!image.isNull()) { readBMP(image); if (!image.isNull()) { - QImage mask(image.width(), image.height(), QImage::Format_Mono); - if (!mask.isNull()) { - mask.setColorCount(2); - mask.setColor(0, qRgba(255,255,255,0xff)); - mask.setColor(1, qRgba(0 ,0 ,0 ,0xff)); - read1BitBMP(mask); + if (icoAttrib.depth == 32) { + img = std::move(image).convertToFormat(QImage::Format_ARGB32_Premultiplied); + } else { + QImage mask(image.width(), image.height(), QImage::Format_Mono); if (!mask.isNull()) { - img = image; - img.setAlphaChannel(mask); - // (Luckily, it seems that setAlphaChannel() does not ruin the alpha values - // of partially transparent pixels in those icons that have that) + mask.setColorCount(2); + mask.setColor(0, qRgba(255,255,255,0xff)); + mask.setColor(1, qRgba(0 ,0 ,0 ,0xff)); + read1BitBMP(mask); + if (!mask.isNull()) { + img = image; + img.setAlphaChannel(mask); + // (Luckily, it seems that setAlphaChannel() does not ruin the alpha values + // of partially transparent pixels in those icons that have that) + } } } } -- cgit v1.2.3