diff --git a/system/lib/features/place_sprites.py b/system/lib/features/place_sprites.py index 0a039a7..2cf8171 100644 --- a/system/lib/features/place_sprites.py +++ b/system/lib/features/place_sprites.py @@ -85,9 +85,9 @@ def place_sprites( f'{folder}{"/overwrite" if overwrite else ""}/{filename}' ).convert("RGBA") if region_info.is_mirrored: - tmp_region = tmp_region.transpose(Image.FLIP_LEFT_RIGHT) + tmp_region = tmp_region.transpose(Image.Transpose.FLIP_LEFT_RIGHT) tmp_region = tmp_region.rotate(region_info.rotation, expand=True) - tmp_region = tmp_region.resize((width, height), Image.ANTIALIAS) + tmp_region = tmp_region.resize((width, height), Image.Resampling.LANCZOS) sheets[region_info.texture_id].paste( Image.new("RGBA", (width, height)), (left, top), img_mask.crop(bbox) diff --git a/system/lib/features/sc/__init__.py b/system/lib/features/sc/__init__.py index f07e999..94b0f6f 100644 --- a/system/lib/features/sc/__init__.py +++ b/system/lib/features/sc/__init__.py @@ -35,7 +35,7 @@ def compile_sc( if Console.question(locale.resize_qu): logger.info(locale.resizing) - sheet = sheet.resize(sheet_info.size, Image.ANTIALIAS) + sheet = sheet.resize(sheet_info.size, Image.Resampling.LANCZOS) width, height = sheet.size pixel_size = get_byte_count_by_pixel_type(pixel_type) diff --git a/system/lib/objects/movie_clip.py b/system/lib/objects/movie_clip.py index 148c635..196ea9a 100644 --- a/system/lib/objects/movie_clip.py +++ b/system/lib/objects/movie_clip.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from math import ceil from typing import TYPE_CHECKING, List, Tuple @@ -53,7 +55,7 @@ def __init__(self): self.binds: List[int] = [] self.matrix_bank_index: int = 0 - def load(self, swf: "SupercellSWF", tag: int): + def load(self, swf: SupercellSWF, tag: int): self.id = swf.reader.read_ushort() self.fps = swf.reader.read_char() @@ -115,7 +117,7 @@ def load(self, swf: "SupercellSWF", tag: int): else: swf.reader.read(frame_length) - def render(self, swf: "SupercellSWF", matrix=None) -> Image.Image: + def render(self, swf: SupercellSWF, matrix=None) -> Image.Image: if self in CACHE: return CACHE[self].copy() @@ -150,7 +152,7 @@ def render(self, swf: "SupercellSWF", matrix=None) -> Image.Image: return image - def get_sides(self, swf: "SupercellSWF") -> Tuple[float, float, float, float]: + def get_sides(self, swf: SupercellSWF) -> Tuple[float, float, float, float]: matrix_bank: MatrixBank = swf.get_matrix_bank(self.matrix_bank_index) left = 0 diff --git a/system/lib/objects/shape.py b/system/lib/objects/shape.py index 42d45b8..3949442 100644 --- a/system/lib/objects/shape.py +++ b/system/lib/objects/shape.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from math import atan2, ceil, degrees from typing import TYPE_CHECKING, List, Optional, Tuple @@ -17,7 +19,7 @@ def __init__(self): self.id = 0 self.regions: List[Region] = [] - def load(self, swf: "SupercellSWF", tag: int): + def load(self, swf: SupercellSWF, tag: int): self.id = swf.reader.read_ushort() swf.reader.read_ushort() # regions_count @@ -101,7 +103,7 @@ def __init__(self): self.texture: SWFTexture - def load(self, swf: "SupercellSWF", tag: int): + def load(self, swf: SupercellSWF, tag: int): self.texture_index = swf.reader.read_uchar() self.texture = swf.textures[self.texture_index] @@ -161,10 +163,10 @@ def render(self, use_original_size: bool = False) -> Image.Image: rendered_region = rendered_region.rotate(-self.rotation, expand=True) if self.is_mirrored: - rendered_region = rendered_region.transpose(Image.FLIP_LEFT_RIGHT) + rendered_region = rendered_region.transpose(Image.Transpose.FLIP_LEFT_RIGHT) if use_original_size: return rendered_region - return rendered_region.resize((width, height), Image.ANTIALIAS) + return rendered_region.resize((width, height), Image.Resampling.LANCZOS) def get_image(self) -> Image.Image: left, top, right, bottom = get_sides(self._uv_points) diff --git a/system/lib/pvr_tex_tool.py b/system/lib/pvr_tex_tool.py index 8ed85e1..e2b162c 100644 --- a/system/lib/pvr_tex_tool.py +++ b/system/lib/pvr_tex_tool.py @@ -7,20 +7,31 @@ from system import run from system.exceptions.tool_not_found import ToolNotFoundException -TOOL_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) -COLOR_SPACE = "sRGB" -KTX_FORMAT = "ETC1,UBN,lRGB" -QUALITY = "etcfast" -CLI_PATH = f"{TOOL_DIR}/system/bin/PVRTexToolCLI" +_main_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) +_color_space = "sRGB" +_format = "ETC1,UBN,lRGB" +_quality = "etcfast" # Note: a solution from # https://stackoverflow.com/questions/11210104/check-if-a-program-exists-from-a-python-script -def can_use_pvr_tex_tool() -> bool: +def _get_executable_path(*paths: str) -> str | None: from distutils.spawn import find_executable - executable_path = find_executable(CLI_PATH) - return executable_path is not None + for path in paths: + executable_path = find_executable(path) + if executable_path is not None: + return executable_path + + return None + + +_cli_name = "PVRTexToolCLI" +_cli_path = _get_executable_path(_cli_name, f"{_main_dir}/system/bin/{_cli_name}") + + +def can_use_pvr_tex_tool() -> bool: + return _cli_path is not None def get_image_from_ktx_data(data: bytes) -> Image.Image: @@ -52,7 +63,9 @@ def convert_ktx_to_png(filepath: Path, output_folder: Path | None = None) -> Pat if output_folder is not None: output_filepath = output_folder / output_filepath.name - run(f"{CLI_PATH} -noout -ics {COLOR_SPACE} -i {filepath!s} -d {output_filepath!s}") + run( + f"{_cli_path} -noout -ics {_color_space} -i {filepath!s} -d {output_filepath!s}" + ) return output_filepath @@ -65,7 +78,7 @@ def convert_png_to_ktx(filepath: Path, output_folder: Path | None = None) -> Pat output_filepath = output_folder / output_filepath.name run( - f"{CLI_PATH} -f {KTX_FORMAT} -q {QUALITY} " + f"{_cli_path} -f {_format} -q {_quality} " f"-i {filepath!s} -o {output_filepath!s}" )