mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-15 20:06:28 +03:00
Restored formatting
This commit is contained in:
parent
eda4192618
commit
b87d4e075e
|
@ -277,7 +277,6 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
format = "DDS"
|
format = "DDS"
|
||||||
format_description = "DirectDraw Surface"
|
format_description = "DirectDraw Surface"
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
if not _accept(self.fp.read(4)):
|
if not _accept(self.fp.read(4)):
|
||||||
msg = "not a DDS file"
|
msg = "not a DDS file"
|
||||||
|
@ -316,10 +315,12 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
self.tile = [("raw", extents, 0, (rawmode[::-1], 0, 1))]
|
self.tile = [("raw", extents, 0, (rawmode[::-1], 0, 1))]
|
||||||
elif bitcount == 32 and pfflags & DDPF.ALPHAPIXELS:
|
elif bitcount == 32 and pfflags & DDPF.ALPHAPIXELS:
|
||||||
self.mode = "RGBA"
|
self.mode = "RGBA"
|
||||||
rawmode = (masks[0xFF000000] +
|
rawmode = (
|
||||||
masks[0x00FF0000] +
|
masks[0xFF000000]
|
||||||
masks[0x0000FF00] +
|
+ masks[0x00FF0000]
|
||||||
masks[0x000000FF])
|
+ masks[0x0000FF00]
|
||||||
|
+ masks[0x000000FF]
|
||||||
|
)
|
||||||
self.tile = [("raw", extents, 0, (rawmode[::-1], 0, 1))]
|
self.tile = [("raw", extents, 0, (rawmode[::-1], 0, 1))]
|
||||||
else:
|
else:
|
||||||
raise OSError(f"Unsupported bitcount {bitcount} for {pfflags}")
|
raise OSError(f"Unsupported bitcount {bitcount} for {pfflags}")
|
||||||
|
@ -409,13 +410,10 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
msg = f"Unknown pixel format flags {repr(pfflags)}"
|
msg = f"Unknown pixel format flags {repr(pfflags)}"
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
|
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
def load_seek(self, pos):
|
def load_seek(self, pos):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
if im.mode not in ("RGB", "RGBA", "L", "LA"):
|
if im.mode not in ("RGB", "RGBA", "L", "LA"):
|
||||||
raise OSError(f"cannot write mode {im.mode} as DDS")
|
raise OSError(f"cannot write mode {im.mode} as DDS")
|
||||||
|
@ -430,7 +428,7 @@ def _save(im, fp, filename):
|
||||||
bit_count = 32
|
bit_count = 32
|
||||||
r, g, b, a = im.split()
|
r, g, b, a = im.split()
|
||||||
im = Image.merge("RGBA", (a, r, g, b))
|
im = Image.merge("RGBA", (a, r, g, b))
|
||||||
elif im.mode == 'LA':
|
elif im.mode == "LA":
|
||||||
pixel_flags = DDPF.LUMINANCE | DDPF.ALPHAPIXELS
|
pixel_flags = DDPF.LUMINANCE | DDPF.ALPHAPIXELS
|
||||||
rgba_mask = struct.pack("<4I", 0x000000FF, 0x000000FF, 0x000000FF, 0x0000FF00)
|
rgba_mask = struct.pack("<4I", 0x000000FF, 0x000000FF, 0x000000FF, 0x0000FF00)
|
||||||
bit_count = 16
|
bit_count = 16
|
||||||
|
@ -444,8 +442,16 @@ def _save(im, fp, filename):
|
||||||
stride = (im.width * bit_count + 7) // 8
|
stride = (im.width * bit_count + 7) // 8
|
||||||
fp.write(
|
fp.write(
|
||||||
o32(DDS_MAGIC)
|
o32(DDS_MAGIC)
|
||||||
# header size, flags, height, width, pitch, depth, mipmaps
|
+ struct.pack(
|
||||||
+ struct.pack("<IIIIIII", 124, flags, im.height, im.width, stride, 0, 0, )
|
"<IIIIIII",
|
||||||
|
124, # header size
|
||||||
|
flags, # flags
|
||||||
|
im.height,
|
||||||
|
im.width,
|
||||||
|
stride, # pitch
|
||||||
|
0, # depth
|
||||||
|
0, # mipmaps
|
||||||
|
)
|
||||||
+ struct.pack("11I", *((0,) * 11)) # reserved
|
+ struct.pack("11I", *((0,) * 11)) # reserved
|
||||||
# pfsize, pfflags, fourcc, bitcount
|
# pfsize, pfflags, fourcc, bitcount
|
||||||
+ struct.pack("<IIII", 32, pixel_flags, 0, bit_count)
|
+ struct.pack("<IIII", 32, pixel_flags, 0, bit_count)
|
||||||
|
@ -456,9 +462,6 @@ def _save(im, fp, filename):
|
||||||
ImageFile._save(im, fp, [Image.Tile("raw", (0, 0) + im.size, 0, (mode, 0, 1))])
|
ImageFile._save(im, fp, [Image.Tile("raw", (0, 0) + im.size, 0, (mode, 0, 1))])
|
||||||
|
|
||||||
|
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return prefix[:4] == b"DDS "
|
return prefix[:4] == b"DDS "
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user