diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py index c98d71c24..32481dcb3 100644 --- a/src/PIL/DdsImagePlugin.py +++ b/src/PIL/DdsImagePlugin.py @@ -277,7 +277,6 @@ class DdsImageFile(ImageFile.ImageFile): format = "DDS" format_description = "DirectDraw Surface" - # fmt: off def _open(self): if not _accept(self.fp.read(4)): msg = "not a DDS file" @@ -316,10 +315,12 @@ class DdsImageFile(ImageFile.ImageFile): self.tile = [("raw", extents, 0, (rawmode[::-1], 0, 1))] elif bitcount == 32 and pfflags & DDPF.ALPHAPIXELS: self.mode = "RGBA" - rawmode = (masks[0xFF000000] + - masks[0x00FF0000] + - masks[0x0000FF00] + - masks[0x000000FF]) + rawmode = ( + masks[0xFF000000] + + masks[0x00FF0000] + + masks[0x0000FF00] + + masks[0x000000FF] + ) self.tile = [("raw", extents, 0, (rawmode[::-1], 0, 1))] else: raise OSError(f"Unsupported bitcount {bitcount} for {pfflags}") @@ -409,13 +410,10 @@ class DdsImageFile(ImageFile.ImageFile): msg = f"Unknown pixel format flags {repr(pfflags)}" raise NotImplementedError(msg) - # fmt: on - def load_seek(self, pos): pass -# fmt: off def _save(im, fp, filename): if im.mode not in ("RGB", "RGBA", "L", "LA"): raise OSError(f"cannot write mode {im.mode} as DDS") @@ -430,7 +428,7 @@ def _save(im, fp, filename): bit_count = 32 r, g, b, a = im.split() im = Image.merge("RGBA", (a, r, g, b)) - elif im.mode == 'LA': + elif im.mode == "LA": pixel_flags = DDPF.LUMINANCE | DDPF.ALPHAPIXELS rgba_mask = struct.pack("<4I", 0x000000FF, 0x000000FF, 0x000000FF, 0x0000FF00) bit_count = 16 @@ -444,8 +442,16 @@ def _save(im, fp, filename): stride = (im.width * bit_count + 7) // 8 fp.write( o32(DDS_MAGIC) - # header size, flags, height, width, pitch, depth, mipmaps - + struct.pack("