diff --git a/src/PIL/VtfImagePlugin.py b/src/PIL/VtfImagePlugin.py index 9621ed291..ecfc3e976 100644 --- a/src/PIL/VtfImagePlugin.py +++ b/src/PIL/VtfImagePlugin.py @@ -116,7 +116,7 @@ VTFHeader = NamedTuple( ("bumpmap_scale", float), ("pixel_format", int), ("mipmap_count", int), - ("lowres_format", int), + ("lowres_pixel_format", int), ("lowres_width", int), ("lowres_height", int), # V 7.2+ @@ -148,17 +148,11 @@ LA_FORMATS = ( SUPPORTED_FORMATS = RGBA_FORMATS + RGB_FORMATS + LA_FORMATS + L_FORMATS +# fmt: off def _get_texture_size(pixel_format: VtfPF, width, height): if pixel_format in (VtfPF.DXT1, VtfPF.DXT1_ONEBITALPHA): return width * height // 2 - elif ( - pixel_format - in ( - VtfPF.DXT3, - VtfPF.DXT5, - ) - + L_FORMATS - ): + elif pixel_format in (VtfPF.DXT3, VtfPF.DXT5,) + L_FORMATS: return width * height elif pixel_format in LA_FORMATS: return width * height * 2 @@ -169,32 +163,32 @@ def _get_texture_size(pixel_format: VtfPF, width, height): raise VTFException(f"Unsupported VTF pixel format: {pixel_format}") +# fmt: on + + class VtfImageFile(ImageFile.ImageFile): format = "VTF" format_description = "Valve Texture Format" + # fmt: off def _open(self): if not _accept(self.fp.read(12)): raise SyntaxError("not a VTF file") self.fp.seek(4) version = struct.unpack("<2I", self.fp.read(8)) if version <= (7, 2): - header = VTFHeader( - *struct.unpack("> mip_id, min_res) mip_height = max(header.height >> mip_id, min_res) data_start += _get_texture_size(pixel_format, mip_width, mip_height) + if pixel_format in (VtfPF.DXT1, VtfPF.DXT1_ONEBITALPHA): tile = ("bcn", (0, 0) + self.size, data_start, (1, "DXT1")) elif pixel_format == VtfPF.DXT3: @@ -247,6 +235,7 @@ class VtfImageFile(ImageFile.ImageFile): else: raise VTFException(f"Unsupported VTF pixel format: {pixel_format}") self.tile = [tile] + # fmt: on def _save(im, fp, filename):