diff --git a/Tests/test_file_vtf.py b/Tests/test_file_vtf.py index 7792ea36f..392b77498 100644 --- a/Tests/test_file_vtf.py +++ b/Tests/test_file_vtf.py @@ -110,17 +110,19 @@ def test_vtf_read( (VtfPF.RGBA8888, "Tests/images/vtf_rgba8888.png", "RGBA", 0), ], ) +@pytest.mark.parametrize("version", ((7, 1), (7, 2), (7, 3))) def test_vtf_save( pixel_format: VtfPF, file_path: str, expected_mode: str, epsilon: int, + version: tuple[int, int], tmp_path: Path, ) -> None: im: Image.Image with Image.open(file_path) as im: out = tmp_path / "tmp.vtf" - im.save(out, pixel_format=pixel_format) + im.save(out, pixel_format=pixel_format, version=version) if pixel_format == VtfPF.DXT1: im = im.convert("RGBA") with Image.open(out) as expected: diff --git a/src/PIL/VtfImagePlugin.py b/src/PIL/VtfImagePlugin.py index 5753630e3..e12c35f8b 100644 --- a/src/PIL/VtfImagePlugin.py +++ b/src/PIL/VtfImagePlugin.py @@ -14,7 +14,6 @@ from __future__ import annotations import struct from enum import IntEnum, IntFlag -from io import BytesIO from math import ceil, log from typing import IO, NamedTuple @@ -308,11 +307,9 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: mipmap_count = _get_mipmap_count(width, height) if generate_mips else 0 - thumb_buffer = BytesIO() thumb = im.convert("RGB") thumb.thumbnail((min(16, width), min(16, height))) thumb = thumb.resize((_closest_power(thumb.width), _closest_power(thumb.height))) - _write_image(thumb_buffer, thumb, VtfPF.DXT1) header = VTFHeader( 0, @@ -352,10 +349,16 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: fp.write(b"\x01\x00\x00\x00") fp.write(struct.pack("