Reduced duplicate code

This commit is contained in:
Andrew Murray 2024-04-10 19:17:20 +10:00 committed by Jonah Jeleniewski
parent 4b4cdbd40c
commit e2a57263c7

View File

@ -123,8 +123,8 @@ class BmpImageFile(ImageFile.ImageFile):
file_info["palette_padding"] = 4 file_info["palette_padding"] = 4
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"]) self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
if file_info["compression"] == self.BITFIELDS: if file_info["compression"] == self.BITFIELDS:
if len(header_data) >= 48:
masks = ["r_mask", "g_mask", "b_mask"] masks = ["r_mask", "g_mask", "b_mask"]
if len(header_data) >= 48:
if len(header_data) >= 52: if len(header_data) >= 52:
masks.append("a_mask") masks.append("a_mask")
else: else:
@ -141,7 +141,7 @@ class BmpImageFile(ImageFile.ImageFile):
# location, but it is listed as a reserved component, # location, but it is listed as a reserved component,
# and it is not generally an alpha channel # and it is not generally an alpha channel
file_info["a_mask"] = 0x0 file_info["a_mask"] = 0x0
for mask in ["r_mask", "g_mask", "b_mask"]: for mask in masks:
file_info[mask] = i32(read(4)) file_info[mask] = i32(read(4))
file_info["rgb_mask"] = ( file_info["rgb_mask"] = (
file_info["r_mask"], file_info["r_mask"],