From 6485071e7e999cec8c316a068e0d4fdca88f04e6 Mon Sep 17 00:00:00 2001 From: REDxEYE Date: Fri, 12 Aug 2022 15:11:11 +0300 Subject: [PATCH] Fix flake errors --- src/PIL/VtfImagePlugin.py | 75 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/src/PIL/VtfImagePlugin.py b/src/PIL/VtfImagePlugin.py index e140b0b586a..60086c0b571 100644 --- a/src/PIL/VtfImagePlugin.py +++ b/src/PIL/VtfImagePlugin.py @@ -116,9 +116,9 @@ class VtfPF(IntEnum): ("bumpmap_scale", float), ("pixel_format", int), ("mipmap_count", int), - ("lowres_pixel_format", int), - ("lowres_width", int), - ("lowres_height", int), + ("low_pixel_format", int), + ("low_width", int), + ("low_height", int), # V 7.2+ ("depth", int), # V 7.3+ @@ -142,10 +142,15 @@ class VtfPF(IntEnum): VtfPF.UV88, ) +BLOCK_COMPRESSED = ( + VtfPF.DXT1, + VtfPF.DXT1_ONEBITALPHA, + VtfPF.DXT3, + VtfPF.DXT5) SUPPORTED_FORMATS = RGBA_FORMATS + RGB_FORMATS + LA_FORMATS + L_FORMATS -HEADER_V70_STRUCT = '> mip_id, min_res) mip_height = max(header.height >> mip_id, min_res) @@ -285,25 +286,28 @@ def _save(im, fp, filename): thumb = thumb.resize((closest_power(thumb.width), closest_power(thumb.height))) ImageFile._save(thumb, thumb_buffer, [("bcn", (0, 0) + thumb.size, 0, (1, 'DXT1'))]) - header = VTFHeader(0, width, height, flags, 1, 0, 1.0, 1.0, 1.0, 1.0, pixel_format, mipmap_count, - VtfPF.DXT1, thumb.width, thumb.height, 1, 2) + header = VTFHeader(0, width, height, flags, + 1, 0, 1.0, 1.0, 1.0, + 1.0, pixel_format, mipmap_count, VtfPF.DXT1, + thumb.width, thumb.height, + 1, 2) fp.write( b"VTF\x00" + struct.pack('<2I', *version) ) if version < (7, 2): - size = struct.calcsize(HEADER_V70_STRUCT) + 12 + size = struct.calcsize(HEADER_V70) + 12 header = header._replace(header_size=size + (16 - size % 16)) - fp.write(struct.pack(HEADER_V70_STRUCT, *header[:15])) + fp.write(struct.pack(HEADER_V70, *header[:15])) elif version == (7, 2): - size = struct.calcsize(HEADER_V72_STRUCT) + 12 + size = struct.calcsize(HEADER_V72) + 12 header = header._replace(header_size=size + (16 - size % 16)) - fp.write(struct.pack(HEADER_V72_STRUCT, *header[:16])) + fp.write(struct.pack(HEADER_V72, *header[:16])) elif version > (7, 2): - size = struct.calcsize(HEADER_V73_STRUCT) + 12 + size = struct.calcsize(HEADER_V73) + 12 header = header._replace(header_size=size + (16 - size % 16)) - fp.write(struct.pack(HEADER_V73_STRUCT, *header)) + fp.write(struct.pack(HEADER_V73, *header)) else: raise VTFException(f'Unsupported version {version}') @@ -314,16 +318,19 @@ def _save(im, fp, filename): fp.write(struct.pack('> mip_id) mip_height = max(4, height >> mip_id) mip = im.resize((mip_width, mip_height)) - ImageFile._save(mip, fp, [("bcn", (0, 0) + mip.size, (fp.tell()), (1, 'DXT1'))], mip_width * mip_height // 2) - ImageFile._save(im, fp, [("bcn", (0, 0) + im.size, (fp.tell()), (1, 'DXT1'))], im.width * im.height // 2) + buffer_size = mip_width * mip_height // 2 + extents = (0, 0) + mip.size + ImageFile._save(mip, fp, + [("bcn", extents, fp.tell(), (1, 'DXT1'))], buffer_size) + buffer_size = im.width * im.height // 2 + ImageFile._save(im, fp, + [("bcn", (0, 0) + im.size, fp.tell(), (1, 'DXT1'))], buffer_size) def _accept(prefix):