fixed bug regarding bitmap (added alpha flag)

This commit is contained in:
jlwoolf 2022-09-27 12:30:32 -06:00
parent 8aa0a864fe
commit 915df6c7cf
3 changed files with 13 additions and 6 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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)