@@ -53,7 +53,7 @@ def _accept(prefix: bytes) -> bool:
53
53
54
54
55
55
def _dib_accept (prefix ):
56
- return i32 (prefix ) in [12 , 40 , 64 , 108 , 124 ]
56
+ return i32 (prefix ) in [12 , 40 , 52 , 56 , 64 , 108 , 124 ]
57
57
58
58
59
59
# =============================================================================
@@ -83,8 +83,9 @@ def _bitmap(self, header=0, offset=0):
83
83
# read the rest of the bmp header, without its size
84
84
header_data = ImageFile ._safe_read (self .fp , file_info ["header_size" ] - 4 )
85
85
86
- # -------------------------------------------------- IBM OS/2 Bitmap v1
86
+ # ------------------------------- Windows Bitmap v2, IBM OS/2 Bitmap v1
87
87
# ----- This format has different offsets because of width/height types
88
+ # 12: BITMAPCOREHEADER/OS21XBITMAPHEADER
88
89
if file_info ["header_size" ] == 12 :
89
90
file_info ["width" ] = i16 (header_data , 0 )
90
91
file_info ["height" ] = i16 (header_data , 2 )
@@ -93,9 +94,14 @@ def _bitmap(self, header=0, offset=0):
93
94
file_info ["compression" ] = self .RAW
94
95
file_info ["palette_padding" ] = 3
95
96
96
- # --------------------------------------------- Windows Bitmap v2 to v5
97
- # v3, OS/2 v2, v4, v5
98
- elif file_info ["header_size" ] in (40 , 64 , 108 , 124 ):
97
+ # --------------------------------------------- Windows Bitmap v3 to v5
98
+ # 40: BITMAPINFOHEADER
99
+ # 52: BITMAPV2HEADER
100
+ # 56: BITMAPV3HEADER
101
+ # 64: BITMAPCOREHEADER2/OS22XBITMAPHEADER
102
+ # 108: BITMAPV4HEADER
103
+ # 124: BITMAPV5HEADER
104
+ elif file_info ["header_size" ] in (40 , 52 , 56 , 64 , 108 , 124 ):
99
105
file_info ["y_flip" ] = header_data [7 ] == 0xFF
100
106
file_info ["direction" ] = 1 if file_info ["y_flip" ] else - 1
101
107
file_info ["width" ] = i32 (header_data , 0 )
@@ -117,10 +123,13 @@ def _bitmap(self, header=0, offset=0):
117
123
file_info ["palette_padding" ] = 4
118
124
self .info ["dpi" ] = tuple (x / 39.3701 for x in file_info ["pixels_per_meter" ])
119
125
if file_info ["compression" ] == self .BITFIELDS :
120
- if len (header_data ) >= 52 :
121
- for idx , mask in enumerate (
122
- ["r_mask" , "g_mask" , "b_mask" , "a_mask" ]
123
- ):
126
+ masks = ["r_mask" , "g_mask" , "b_mask" ]
127
+ if len (header_data ) >= 48 :
128
+ if len (header_data ) >= 52 :
129
+ masks .append ("a_mask" )
130
+ else :
131
+ file_info ["a_mask" ] = 0x0
132
+ for idx , mask in enumerate (masks ):
124
133
file_info [mask ] = i32 (header_data , 36 + idx * 4 )
125
134
else :
126
135
# 40 byte headers only have the three components in the
@@ -132,7 +141,7 @@ def _bitmap(self, header=0, offset=0):
132
141
# location, but it is listed as a reserved component,
133
142
# and it is not generally an alpha channel
134
143
file_info ["a_mask" ] = 0x0
135
- for mask in [ "r_mask" , "g_mask" , "b_mask" ] :
144
+ for mask in masks :
136
145
file_info [mask ] = i32 (read (4 ))
137
146
file_info ["rgb_mask" ] = (
138
147
file_info ["r_mask" ],
@@ -175,9 +184,11 @@ def _bitmap(self, header=0, offset=0):
175
184
32 : [
176
185
(0xFF0000 , 0xFF00 , 0xFF , 0x0 ),
177
186
(0xFF000000 , 0xFF0000 , 0xFF00 , 0x0 ),
187
+ (0xFF000000 , 0xFF00 , 0xFF , 0x0 ),
178
188
(0xFF000000 , 0xFF0000 , 0xFF00 , 0xFF ),
179
189
(0xFF , 0xFF00 , 0xFF0000 , 0xFF000000 ),
180
190
(0xFF0000 , 0xFF00 , 0xFF , 0xFF000000 ),
191
+ (0xFF000000 , 0xFF00 , 0xFF , 0xFF0000 ),
181
192
(0x0 , 0x0 , 0x0 , 0x0 ),
182
193
],
183
194
24 : [(0xFF0000 , 0xFF00 , 0xFF )],
@@ -186,9 +197,11 @@ def _bitmap(self, header=0, offset=0):
186
197
MASK_MODES = {
187
198
(32 , (0xFF0000 , 0xFF00 , 0xFF , 0x0 )): "BGRX" ,
188
199
(32 , (0xFF000000 , 0xFF0000 , 0xFF00 , 0x0 )): "XBGR" ,
200
+ (32 , (0xFF000000 , 0xFF00 , 0xFF , 0x0 )): "BGXR" ,
189
201
(32 , (0xFF000000 , 0xFF0000 , 0xFF00 , 0xFF )): "ABGR" ,
190
202
(32 , (0xFF , 0xFF00 , 0xFF0000 , 0xFF000000 )): "RGBA" ,
191
203
(32 , (0xFF0000 , 0xFF00 , 0xFF , 0xFF000000 )): "BGRA" ,
204
+ (32 , (0xFF000000 , 0xFF00 , 0xFF , 0xFF0000 )): "BGAR" ,
192
205
(32 , (0x0 , 0x0 , 0x0 , 0x0 )): "BGRA" ,
193
206
(24 , (0xFF0000 , 0xFF00 , 0xFF )): "BGR" ,
194
207
(16 , (0xF800 , 0x7E0 , 0x1F )): "BGR;16" ,
0 commit comments