[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2022-08-14 18:12:18 +00:00 committed by REDxEYE
parent c3457f10eb
commit 906890bfe8
2 changed files with 27 additions and 13 deletions

View File

@ -63,7 +63,7 @@ def test_get_mipmap_count(size: Tuple[int, int], expected_count: int):
],
)
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
@ -82,9 +82,7 @@ def test_get_texture_size(
("Tests/images/vtf_rgba8888.png", "Tests/images/vtf_rgba8888.vtf", "RGBA", 0),
],
)
def test_vtf_read(
etalon_path: str, file_path: str, expected_mode: str, epsilon: float
):
def test_vtf_read(etalon_path: str, file_path: str, expected_mode: str, epsilon: float):
e = Image.open(etalon_path)
f = Image.open(file_path)
assert f.mode == expected_mode
@ -109,8 +107,9 @@ def test_vtf_read(
(VtfPF.RGBA8888, "Tests/images/vtf_rgba8888.png", "RGBA", 0),
],
)
def test_vtf_save(pixel_format: VtfPF, file_path: str,
expected_mode: str, epsilon: float, tmp_path):
def test_vtf_save(
pixel_format: VtfPF, file_path: str, expected_mode: str, epsilon: float, tmp_path
):
f: Image.Image = Image.open(file_path)
out = (tmp_path / "tmp.vtf").as_posix()
f.save(out, pixel_format=pixel_format)

View File

@ -137,7 +137,10 @@ def _get_texture_size(pixel_format: VtfPF, width, height):
return width * height // 2
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5):
return width * height
elif pixel_format in (VtfPF.A8, VtfPF.I8,):
elif pixel_format in (
VtfPF.A8,
VtfPF.I8,
):
return width * height
elif pixel_format in (VtfPF.UV88, VtfPF.IA88):
return width * height * 2
@ -205,7 +208,7 @@ def _write_image(fp: BufferedIOBase, im: Image.Image, pixel_format: VtfPF):
def _closest_power(x):
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):
@ -246,8 +249,15 @@ class VtfImageFile(ImageFile.ImageFile):
# flags = CompiledVtfFlags(header.flags)
pixel_format = VtfPF(header.pixel_format)
low_format = VtfPF(header.low_pixel_format)
if pixel_format in (VtfPF.DXT1_ONEBITALPHA, VtfPF.DXT1, VtfPF.DXT3, VtfPF.DXT5,
VtfPF.RGBA8888, VtfPF.BGRA8888,VtfPF.A8):
if pixel_format in (
VtfPF.DXT1_ONEBITALPHA,
VtfPF.DXT1,
VtfPF.DXT3,
VtfPF.DXT5,
VtfPF.RGBA8888,
VtfPF.BGRA8888,
VtfPF.A8,
):
self.mode = "RGBA"
elif pixel_format in (VtfPF.RGB888, VtfPF.BGR888, VtfPF.UV88):
self.mode = "RGB"
@ -309,9 +319,14 @@ def _save(im, fp, filename):
if pixel_format == VtfPF.DXT1_ONEBITALPHA:
flags |= CompiledVtfFlags.ONEBITALPHA
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5,
VtfPF.RGBA8888, VtfPF.BGRA8888,
VtfPF.A8, VtfPF.IA88):
elif pixel_format in (
VtfPF.DXT3,
VtfPF.DXT5,
VtfPF.RGBA8888,
VtfPF.BGRA8888,
VtfPF.A8,
VtfPF.IA88,
):
flags |= CompiledVtfFlags.EIGHTBITALPHA
else:
pass