diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2019-04-23 16:30:15 +0200 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2019-04-25 06:07:13 +0000 |
commit | 1d128ed1dfbcf49453ada922e54381c37264fde5 (patch) | |
tree | e6d3b1198be1222e7b34aea5fc1611b0e892a5aa /src/plugins/imageformats/ico/qicohandler.cpp | |
parent | d6c3fa6e0cdb55b9676f1a3f1365d835a039a6e2 (diff) |
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 <allan.jensen@qt.io>
Diffstat (limited to 'src/plugins/imageformats/ico/qicohandler.cpp')
-rw-r--r-- | src/plugins/imageformats/ico/qicohandler.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
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) + } } } } |