1212
1313from __future__ import annotations
1414
15- import io
1615import struct
1716import sys
1817from enum import IntEnum , IntFlag
@@ -340,21 +339,20 @@ def _open(self) -> None:
340339 if header_size != 124 :
341340 msg = f"Unsupported header size { repr (header_size )} "
342341 raise OSError (msg )
343- header_bytes = self .fp .read (header_size - 4 )
344- if len (header_bytes ) != 120 :
345- msg = f"Incomplete header: { len (header_bytes )} bytes"
342+ header = self .fp .read (header_size - 4 )
343+ if len (header ) != 120 :
344+ msg = f"Incomplete header: { len (header )} bytes"
346345 raise OSError (msg )
347- header = io .BytesIO (header_bytes )
348346
349- flags , height , width = struct .unpack ("<3I" , header . read ( 12 ) )
347+ flags , height , width = struct .unpack ("<3I" , header [: 12 ] )
350348 self ._size = (width , height )
351349 extents = (0 , 0 ) + self .size
352350
353- pitch , depth , mipmaps = struct .unpack ("<3I" , header . read ( 12 ) )
354- struct .unpack ("<11I" , header . read ( 44 ) ) # reserved
351+ pitch , depth , mipmaps = struct .unpack ("<3I" , header [ 12 : 24 ] )
352+ struct .unpack ("<11I" , header [ 24 : 68 ] ) # reserved
355353
356354 # pixel format
357- pfsize , pfflags , fourcc , bitcount = struct .unpack ("<4I" , header . read ( 16 ) )
355+ pfsize , pfflags , fourcc , bitcount = struct .unpack ("<4I" , header [ 68 : 84 ] )
358356 n = 0
359357 rawmode = None
360358 if pfflags & DDPF .RGB :
@@ -366,7 +364,7 @@ def _open(self) -> None:
366364 self ._mode = "RGB"
367365 mask_count = 3
368366
369- masks = struct .unpack (f"<{ mask_count } I" , header . read ( mask_count * 4 ) )
367+ masks = struct .unpack (f"<{ mask_count } I" , header [ 84 : 84 + mask_count * 4 ] )
370368 self .tile = [ImageFile ._Tile ("dds_rgb" , extents , 0 , (bitcount , masks ))]
371369 return
372370 elif pfflags & DDPF .LUMINANCE :
0 commit comments