From 915df6c7cf79007849a5c78972f5e81a6497850a Mon Sep 17 00:00:00 2001 From: jlwoolf Date: Tue, 27 Sep 2022 12:30:32 -0600 Subject: [PATCH] fixed bug regarding bitmap (added alpha flag) --- src/PIL/AniImagePlugin.py | 6 ++++-- src/PIL/BmpImagePlugin.py | 7 +++++-- src/PIL/CurImagePlugin.py | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/PIL/AniImagePlugin.py b/src/PIL/AniImagePlugin.py index d4ec37da4..9e25cded4 100644 --- a/src/PIL/AniImagePlugin.py +++ b/src/PIL/AniImagePlugin.py @@ -58,13 +58,15 @@ def _save_frame(im: Image.Image, fp: BytesIO, filename: str, info: dict): image_io = BytesIO() if bmp: - frame.save(image_io, "dib") - if bits != 32: and_mask = Image.new("1", size) ImageFile._save( and_mask, image_io, [("raw", (0, 0) + size, 0, ("1", 0, -1))] ) + else: + frame.alpha = True + + frame.save(image_io, "dib") else: frame.save(image_io, "png") image_io.seek(0) diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index bc81f3274..8e69acd36 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -209,8 +209,11 @@ class BmpImageFile(ImageFile.ImageFile): else: raise OSError("Unsupported BMP bitfields layout") elif file_info["compression"] == self.RAW: - if file_info["bits"] == 32: # 32-bit has transparency - raw_mode, self.mode = "BGRA", "RGBA" + try: + if file_info["bits"] == 32 and self.alpha: + raw_mode, self.mode = "BGRA", "RGBA" + except AttributeError: + pass elif file_info["compression"] == self.RLE8: decoder_name = "bmp_rle" else: diff --git a/src/PIL/CurImagePlugin.py b/src/PIL/CurImagePlugin.py index 9e60ecc1f..ba11d08cc 100644 --- a/src/PIL/CurImagePlugin.py +++ b/src/PIL/CurImagePlugin.py @@ -76,13 +76,15 @@ def _save(im: Image.Image, fp: BytesIO, filename: str): image_io = BytesIO() if bmp: - frame.save(image_io, "dib") - if bits != 32: and_mask = Image.new("1", size) ImageFile._save( and_mask, image_io, [("raw", (0, 0) + size, 0, ("1", 0, -1))] ) + else: + frame.alpha = True + + frame.save(image_io, "dib") else: frame.save(image_io, "png") image_io.seek(0)