diff --git a/Tests/images/hopper_mask.ico b/Tests/images/hopper_mask.ico new file mode 100644 index 00000000000..e8d66c689fd Binary files /dev/null and b/Tests/images/hopper_mask.ico differ diff --git a/Tests/images/hopper_mask.png b/Tests/images/hopper_mask.png new file mode 100644 index 00000000000..c7bd2f70842 Binary files /dev/null and b/Tests/images/hopper_mask.png differ diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index 8060d1b763b..317264db646 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -18,6 +18,11 @@ def test_sanity(): assert im.get_format_mimetype() == "image/x-icon" +def test_mask(): + with Image.open("Tests/images/hopper_mask.ico") as im: + assert_image_equal_tofile(im, "Tests/images/hopper_mask.png") + + def test_black_and_white(): with Image.open("Tests/images/black_and_white.ico") as im: assert im.mode == "RGBA" diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index ffb1e873d23..d9ff9b5e731 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -235,8 +235,8 @@ def frame(self, idx): # the total mask data is # padded row size * height / bits per char - and_mask_offset = o + int(im.size[0] * im.size[1] * (bpp / 8.0)) total_bytes = int((w * im.size[1]) / 8) + and_mask_offset = header["offset"] + header["size"] - total_bytes self.buf.seek(and_mask_offset) mask_data = self.buf.read(total_bytes)