Skip to content

Commit 906890b

Browse files
pre-commit-ci[bot]REDxEYE
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c3457f1 commit 906890b

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

Tests/test_file_vtf.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_get_mipmap_count(size: Tuple[int, int], expected_count: int):
6363
],
6464
)
6565
def test_get_texture_size(
66-
pixel_format: VtfPF, size: Tuple[int, int], expected_size: int
66+
pixel_format: VtfPF, size: Tuple[int, int], expected_size: int
6767
):
6868
assert _get_texture_size(pixel_format, *size) == expected_size
6969

@@ -82,9 +82,7 @@ def test_get_texture_size(
8282
("Tests/images/vtf_rgba8888.png", "Tests/images/vtf_rgba8888.vtf", "RGBA", 0),
8383
],
8484
)
85-
def test_vtf_read(
86-
etalon_path: str, file_path: str, expected_mode: str, epsilon: float
87-
):
85+
def test_vtf_read(etalon_path: str, file_path: str, expected_mode: str, epsilon: float):
8886
e = Image.open(etalon_path)
8987
f = Image.open(file_path)
9088
assert f.mode == expected_mode
@@ -109,8 +107,9 @@ def test_vtf_read(
109107
(VtfPF.RGBA8888, "Tests/images/vtf_rgba8888.png", "RGBA", 0),
110108
],
111109
)
112-
def test_vtf_save(pixel_format: VtfPF, file_path: str,
113-
expected_mode: str, epsilon: float, tmp_path):
110+
def test_vtf_save(
111+
pixel_format: VtfPF, file_path: str, expected_mode: str, epsilon: float, tmp_path
112+
):
114113
f: Image.Image = Image.open(file_path)
115114
out = (tmp_path / "tmp.vtf").as_posix()
116115
f.save(out, pixel_format=pixel_format)

src/PIL/VtfImagePlugin.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ def _get_texture_size(pixel_format: VtfPF, width, height):
137137
return width * height // 2
138138
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5):
139139
return width * height
140-
elif pixel_format in (VtfPF.A8, VtfPF.I8,):
140+
elif pixel_format in (
141+
VtfPF.A8,
142+
VtfPF.I8,
143+
):
141144
return width * height
142145
elif pixel_format in (VtfPF.UV88, VtfPF.IA88):
143146
return width * height * 2
@@ -205,7 +208,7 @@ def _write_image(fp: BufferedIOBase, im: Image.Image, pixel_format: VtfPF):
205208

206209
def _closest_power(x):
207210
possible_results = round(log(x, 2)), ceil(log(x, 2))
208-
return 2 ** min(possible_results, key=lambda z: abs(x - 2 ** z))
211+
return 2 ** min(possible_results, key=lambda z: abs(x - 2**z))
209212

210213

211214
class VtfImageFile(ImageFile.ImageFile):
@@ -246,8 +249,15 @@ def _open(self):
246249
# flags = CompiledVtfFlags(header.flags)
247250
pixel_format = VtfPF(header.pixel_format)
248251
low_format = VtfPF(header.low_pixel_format)
249-
if pixel_format in (VtfPF.DXT1_ONEBITALPHA, VtfPF.DXT1, VtfPF.DXT3, VtfPF.DXT5,
250-
VtfPF.RGBA8888, VtfPF.BGRA8888,VtfPF.A8):
252+
if pixel_format in (
253+
VtfPF.DXT1_ONEBITALPHA,
254+
VtfPF.DXT1,
255+
VtfPF.DXT3,
256+
VtfPF.DXT5,
257+
VtfPF.RGBA8888,
258+
VtfPF.BGRA8888,
259+
VtfPF.A8,
260+
):
251261
self.mode = "RGBA"
252262
elif pixel_format in (VtfPF.RGB888, VtfPF.BGR888, VtfPF.UV88):
253263
self.mode = "RGB"
@@ -309,9 +319,14 @@ def _save(im, fp, filename):
309319

310320
if pixel_format == VtfPF.DXT1_ONEBITALPHA:
311321
flags |= CompiledVtfFlags.ONEBITALPHA
312-
elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5,
313-
VtfPF.RGBA8888, VtfPF.BGRA8888,
314-
VtfPF.A8, VtfPF.IA88):
322+
elif pixel_format in (
323+
VtfPF.DXT3,
324+
VtfPF.DXT5,
325+
VtfPF.RGBA8888,
326+
VtfPF.BGRA8888,
327+
VtfPF.A8,
328+
VtfPF.IA88,
329+
):
315330
flags |= CompiledVtfFlags.EIGHTBITALPHA
316331
else:
317332
pass

0 commit comments

Comments
 (0)