diff --git a/Tests/test_file_vtf.py b/Tests/test_file_vtf.py index b0e7321fe48..d84981885b5 100644 --- a/Tests/test_file_vtf.py +++ b/Tests/test_file_vtf.py @@ -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) diff --git a/src/PIL/VtfImagePlugin.py b/src/PIL/VtfImagePlugin.py index 79f82d92e87..bea11ae16ee 100644 --- a/src/PIL/VtfImagePlugin.py +++ b/src/PIL/VtfImagePlugin.py @@ -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 @@ def _open(self): # 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