Skip to content

Commit db4591d

Browse files
committed
chore(Texture2DConverter): optimize docstring
1 parent d4a07c4 commit db4591d

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

UnityPy/export/Texture2DConverter.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def image_to_texture2d(
138138
platform_blob: Optional[TextureSwizzler.PlatformBlobType] = None,
139139
flip: bool = True,
140140
) -> Tuple[bytes, TextureFormat]:
141+
"""Converts a PIL Image to Texture2D bytes."""
141142
if not isinstance(platform, BuildTarget):
142143
platform = BuildTarget(platform)
143144

@@ -191,7 +192,7 @@ def image_to_texture2d(
191192
elif target_texture_format == TF.Alpha8:
192193
tex_format = TF.Alpha8
193194
pil_mode = "A"
194-
# R - should probably be moerged into #A, as pure R is used as Alpha
195+
# R - should probably be merged into #A, as pure R is used as Alpha
195196
# but need test data for this first
196197
elif target_texture_format in [
197198
TF.R8,
@@ -257,15 +258,7 @@ def get_image_from_texture2d(
257258
texture_2d: Texture2D,
258259
flip: bool = True,
259260
) -> Image.Image:
260-
"""converts the given texture into PIL.Image
261-
262-
:param texture_2d: texture to be converterd
263-
:type texture_2d: Texture2D
264-
:param flip: flips the image back to the original (all Unity textures are flipped by default)
265-
:type flip: bool
266-
:return: PIL.Image object
267-
:rtype: Image
268-
"""
261+
"""Converts the given Texture2D object to PIL Image."""
269262
return parse_image_data(
270263
texture_2d.get_image_data(),
271264
texture_2d.m_Width,
@@ -288,6 +281,7 @@ def parse_image_data(
288281
platform_blob: Optional[TextureSwizzler.PlatformBlobType] = None,
289282
flip: bool = True,
290283
) -> Image.Image:
284+
"""Converts the given image data bytes to PIL Image."""
291285
if not width or not height:
292286
return Image.new("RGBA", (0, 0))
293287

@@ -349,9 +343,7 @@ def parse_image_data(
349343

350344

351345
def swap_bytes_for_xbox(image_data: Union[bytes, bytearray, memoryview]) -> bytearray:
352-
"""swaps the texture bytes
353-
This is required for textures deployed on XBOX360.
354-
"""
346+
"""Swaps the texture bytes for textures deployed on XBOX360."""
355347
image_data = bytearray(image_data)
356348
for i in range(0, len(image_data), 2):
357349
image_data[i : i + 2] = image_data[i : i + 2][::-1]

UnityPy/helpers/TextureSwizzler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def get_switch_gobs_per_block(platform_blob: Optional[PlatformBlobType]) -> int:
143143

144144

145145
def get_corrected_texture_format(texture_format: TextureFormat) -> TextureFormat:
146+
# In older versions of unity, RGB24 has a platform_blob which shouldn't
147+
# be possible. It turns out in this case, the image is just RGBA32.
146148
if texture_format == TextureFormat.RGB24:
147149
return TextureFormat.RGBA32
148150
elif texture_format == TextureFormat.BGR24:

0 commit comments

Comments
 (0)