Skip to content

Commit e061ef2

Browse files
isHarryhK0lb3
authored andcommitted
chore(Texture2DConverter): fix typo, optimize docstring and types
1 parent 56643b9 commit e061ef2

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

‎UnityPy/export/Texture2DConverter.py‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from io import BytesIO
55
from threading import Lock
66
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
7+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
78

89
import astc_encoder
910
import texture2ddecoder
@@ -117,11 +118,12 @@ def compress_astc(data: bytes, width: int, height: int, target_texture_format: T
117118

118119
def image_to_texture2d(
119120
img: Image.Image,
120-
target_texture_format: Union[TF, int],
121-
platform: int = 0,
121+
target_texture_format: Union[TextureFormat, int],
122+
platform: Union[BuildTarget, int] = 0,
122123
platform_blob: Optional[List[int]] = None,
123124
flip: bool = True,
124125
) -> Tuple[bytes, TextureFormat]:
126+
"""Converts a PIL Image to Texture2D bytes."""
125127
if not isinstance(target_texture_format, TextureFormat):
126128
target_texture_format = TextureFormat(target_texture_format)
127129

@@ -178,7 +180,7 @@ def image_to_texture2d(
178180
elif target_texture_format == TF.Alpha8:
179181
tex_format = TF.Alpha8
180182
pil_mode = "A"
181-
# R - should probably be moerged into #A, as pure R is used as Alpha
183+
# R - should probably be merged into #A, as pure R is used as Alpha
182184
# but need test data for this first
183185
elif target_texture_format in [
184186
TF.R8,
@@ -244,15 +246,7 @@ def get_image_from_texture2d(
244246
texture_2d: Texture2D,
245247
flip: bool = True,
246248
) -> Image.Image:
247-
"""converts the given texture into PIL.Image
248-
249-
:param texture_2d: texture to be converterd
250-
:type texture_2d: Texture2D
251-
:param flip: flips the image back to the original (all Unity textures are flipped by default)
252-
:type flip: bool
253-
:return: PIL.Image object
254-
:rtype: Image
255-
"""
249+
"""Converts the given Texture2D object to PIL Image."""
256250
return parse_image_data(
257251
texture_2d.get_image_data(),
258252
texture_2d.m_Width,
@@ -269,12 +263,13 @@ def parse_image_data(
269263
image_data: Union[bytes, bytearray, memoryview],
270264
width: int,
271265
height: int,
272-
texture_format: Union[int, TextureFormat],
266+
texture_format: Union[TextureFormat, int],
273267
version: Tuple[int, int, int, int],
274-
platform: int,
275-
platform_blob: Optional[bytes] = None,
268+
platform: Union[BuildTarget, int],
269+
platform_blob: Optional[List[int]] = None,
276270
flip: bool = True,
277271
) -> Image.Image:
272+
"""Converts the given image data bytes to PIL Image."""
278273
if not width or not height:
279274
return Image.new("RGBA", (0, 0))
280275

@@ -333,9 +328,7 @@ def parse_image_data(
333328

334329

335330
def swap_bytes_for_xbox(image_data: Union[bytes, bytearray, memoryview]) -> bytearray:
336-
"""swaps the texture bytes
337-
This is required for textures deployed on XBOX360.
338-
"""
331+
"""Swaps the texture bytes for textures deployed on XBOX360."""
339332
image_data = bytearray(image_data)
340333
for i in range(0, len(image_data), 2):
341334
image_data[i : i + 2] = image_data[i : i + 2][::-1]

0 commit comments

Comments
 (0)