mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 16:22:22 +03:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
c3457f10eb
commit
906890bfe8
|
@ -63,7 +63,7 @@ def test_get_mipmap_count(size: Tuple[int, int], expected_count: int):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_texture_size(
|
def test_get_texture_size(
|
||||||
pixel_format: VtfPF, size: Tuple[int, int], expected_size: int
|
pixel_format: VtfPF, size: Tuple[int, int], expected_size: int
|
||||||
):
|
):
|
||||||
assert _get_texture_size(pixel_format, *size) == expected_size
|
assert _get_texture_size(pixel_format, *size) == expected_size
|
||||||
|
|
||||||
|
@ -82,9 +82,7 @@ def test_get_texture_size(
|
||||||
("Tests/images/vtf_rgba8888.png", "Tests/images/vtf_rgba8888.vtf", "RGBA", 0),
|
("Tests/images/vtf_rgba8888.png", "Tests/images/vtf_rgba8888.vtf", "RGBA", 0),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_vtf_read(
|
def test_vtf_read(etalon_path: str, file_path: str, expected_mode: str, epsilon: float):
|
||||||
etalon_path: str, file_path: str, expected_mode: str, epsilon: float
|
|
||||||
):
|
|
||||||
e = Image.open(etalon_path)
|
e = Image.open(etalon_path)
|
||||||
f = Image.open(file_path)
|
f = Image.open(file_path)
|
||||||
assert f.mode == expected_mode
|
assert f.mode == expected_mode
|
||||||
|
@ -109,8 +107,9 @@ def test_vtf_read(
|
||||||
(VtfPF.RGBA8888, "Tests/images/vtf_rgba8888.png", "RGBA", 0),
|
(VtfPF.RGBA8888, "Tests/images/vtf_rgba8888.png", "RGBA", 0),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_vtf_save(pixel_format: VtfPF, file_path: str,
|
def test_vtf_save(
|
||||||
expected_mode: str, epsilon: float, tmp_path):
|
pixel_format: VtfPF, file_path: str, expected_mode: str, epsilon: float, tmp_path
|
||||||
|
):
|
||||||
f: Image.Image = Image.open(file_path)
|
f: Image.Image = Image.open(file_path)
|
||||||
out = (tmp_path / "tmp.vtf").as_posix()
|
out = (tmp_path / "tmp.vtf").as_posix()
|
||||||
f.save(out, pixel_format=pixel_format)
|
f.save(out, pixel_format=pixel_format)
|
||||||
|
|
|
@ -137,7 +137,10 @@ def _get_texture_size(pixel_format: VtfPF, width, height):
|
||||||
return width * height // 2
|
return width * height // 2
|
||||||
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5):
|
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5):
|
||||||
return width * height
|
return width * height
|
||||||
elif pixel_format in (VtfPF.A8, VtfPF.I8,):
|
elif pixel_format in (
|
||||||
|
VtfPF.A8,
|
||||||
|
VtfPF.I8,
|
||||||
|
):
|
||||||
return width * height
|
return width * height
|
||||||
elif pixel_format in (VtfPF.UV88, VtfPF.IA88):
|
elif pixel_format in (VtfPF.UV88, VtfPF.IA88):
|
||||||
return width * height * 2
|
return width * height * 2
|
||||||
|
@ -205,7 +208,7 @@ def _write_image(fp: BufferedIOBase, im: Image.Image, pixel_format: VtfPF):
|
||||||
|
|
||||||
def _closest_power(x):
|
def _closest_power(x):
|
||||||
possible_results = round(log(x, 2)), ceil(log(x, 2))
|
possible_results = round(log(x, 2)), ceil(log(x, 2))
|
||||||
return 2 ** min(possible_results, key=lambda z: abs(x - 2 ** z))
|
return 2 ** min(possible_results, key=lambda z: abs(x - 2**z))
|
||||||
|
|
||||||
|
|
||||||
class VtfImageFile(ImageFile.ImageFile):
|
class VtfImageFile(ImageFile.ImageFile):
|
||||||
|
@ -246,8 +249,15 @@ class VtfImageFile(ImageFile.ImageFile):
|
||||||
# flags = CompiledVtfFlags(header.flags)
|
# flags = CompiledVtfFlags(header.flags)
|
||||||
pixel_format = VtfPF(header.pixel_format)
|
pixel_format = VtfPF(header.pixel_format)
|
||||||
low_format = VtfPF(header.low_pixel_format)
|
low_format = VtfPF(header.low_pixel_format)
|
||||||
if pixel_format in (VtfPF.DXT1_ONEBITALPHA, VtfPF.DXT1, VtfPF.DXT3, VtfPF.DXT5,
|
if pixel_format in (
|
||||||
VtfPF.RGBA8888, VtfPF.BGRA8888,VtfPF.A8):
|
VtfPF.DXT1_ONEBITALPHA,
|
||||||
|
VtfPF.DXT1,
|
||||||
|
VtfPF.DXT3,
|
||||||
|
VtfPF.DXT5,
|
||||||
|
VtfPF.RGBA8888,
|
||||||
|
VtfPF.BGRA8888,
|
||||||
|
VtfPF.A8,
|
||||||
|
):
|
||||||
self.mode = "RGBA"
|
self.mode = "RGBA"
|
||||||
elif pixel_format in (VtfPF.RGB888, VtfPF.BGR888, VtfPF.UV88):
|
elif pixel_format in (VtfPF.RGB888, VtfPF.BGR888, VtfPF.UV88):
|
||||||
self.mode = "RGB"
|
self.mode = "RGB"
|
||||||
|
@ -309,9 +319,14 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
if pixel_format == VtfPF.DXT1_ONEBITALPHA:
|
if pixel_format == VtfPF.DXT1_ONEBITALPHA:
|
||||||
flags |= CompiledVtfFlags.ONEBITALPHA
|
flags |= CompiledVtfFlags.ONEBITALPHA
|
||||||
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5,
|
elif pixel_format in (
|
||||||
VtfPF.RGBA8888, VtfPF.BGRA8888,
|
VtfPF.DXT3,
|
||||||
VtfPF.A8, VtfPF.IA88):
|
VtfPF.DXT5,
|
||||||
|
VtfPF.RGBA8888,
|
||||||
|
VtfPF.BGRA8888,
|
||||||
|
VtfPF.A8,
|
||||||
|
VtfPF.IA88,
|
||||||
|
):
|
||||||
flags |= CompiledVtfFlags.EIGHTBITALPHA
|
flags |= CompiledVtfFlags.EIGHTBITALPHA
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user