From 900b849aa8f915461630cf738a2927eca505beb2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 22 Apr 2021 21:18:21 +1000 Subject: [PATCH] Use bpp from header --- Tests/images/black_and_white.ico | Bin 0 -> 198 bytes Tests/test_file_ico.py | 6 ++++++ src/PIL/IcoImagePlugin.py | 8 +------- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 Tests/images/black_and_white.ico diff --git a/Tests/images/black_and_white.ico b/Tests/images/black_and_white.ico new file mode 100644 index 0000000000000000000000000000000000000000..f98d7ac8e8d2234a25ac5b8c90c8c7914733878b GIT binary patch literal 198 xcmZQzU<5(|0VXiLfq{WR42U&=SOAC>fEXl?5B&fCA4OXJ2Ll5!7)29>8~~Bo4=Mlv literal 0 HcmV?d00001 diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index 5ace0c55e..edf3095f7 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -18,6 +18,12 @@ def test_sanity(): assert im.get_format_mimetype() == "image/x-icon" +def test_black_and_white(): + with Image.open("Tests/images/black_and_white.ico") as im: + assert im.mode == "RGBA" + assert im.size == (16, 16) + + def test_invalid_file(): with open("Tests/images/flower.jpg", "rb") as fp: with pytest.raises(SyntaxError): diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index 5634bf8e9..6e15a8bdb 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -190,13 +190,7 @@ class IcoFile: im.tile[0] = d, (0, 0) + im.size, o, a # figure out where AND mask image starts - mode = a[0] - bpp = 8 - for k, v in BmpImagePlugin.BIT2MODE.items(): - if mode == v[1]: - bpp = k - break - + bpp = header["bpp"] if 32 == bpp: # 32-bit color depth icon image allows semitransparent areas # PIL's DIB format ignores transparency bits, recover them.