1212
1313from __future__ import annotations
1414
15- import io
1615import struct
1716import sys
1817from enum import IntEnum , IntFlag
@@ -341,21 +340,20 @@ def _open(self) -> None:
341340 if header_size != 124 :
342341 msg = f"Unsupported header size { repr (header_size )} "
343342 raise OSError (msg )
344- header_bytes = self .fp .read (header_size - 4 )
345- if len (header_bytes ) != 120 :
346- msg = f"Incomplete header: { len (header_bytes )} bytes"
343+ header = self .fp .read (header_size - 4 )
344+ if len (header ) != 120 :
345+ msg = f"Incomplete header: { len (header )} bytes"
347346 raise OSError (msg )
348- header = io .BytesIO (header_bytes )
349347
350- flags , height , width = struct .unpack ("<3I" , header . read ( 12 ) )
348+ flags , height , width = struct .unpack ("<3I" , header [: 12 ] )
351349 self ._size = (width , height )
352350 extents = (0 , 0 ) + self .size
353351
354- pitch , depth , mipmaps = struct .unpack ("<3I" , header . read ( 12 ) )
355- struct .unpack ("<11I" , header . read ( 44 ) ) # reserved
352+ pitch , depth , mipmaps = struct .unpack ("<3I" , header [ 12 : 24 ] )
353+ struct .unpack ("<11I" , header [ 24 : 68 ] ) # reserved
356354
357355 # pixel format
358- pfsize , pfflags , fourcc , bitcount = struct .unpack ("<4I" , header . read ( 16 ) )
356+ pfsize , pfflags , fourcc , bitcount = struct .unpack ("<4I" , header [ 68 : 84 ] )
359357 n = 0
360358 rawmode = None
361359 if pfflags & DDPF .RGB :
@@ -367,7 +365,7 @@ def _open(self) -> None:
367365 self ._mode = "RGB"
368366 mask_count = 3
369367
370- masks = struct .unpack (f"<{ mask_count } I" , header . read ( mask_count * 4 ) )
368+ masks = struct .unpack (f"<{ mask_count } I" , header [ 84 : 84 + mask_count * 4 ] )
371369 self .tile = [ImageFile ._Tile ("dds_rgb" , extents , 0 , (bitcount , masks ))]
372370 return
373371 elif pfflags & DDPF .LUMINANCE :
0 commit comments