Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UnityPy/export/Texture2DConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def rgb9e5float(image_data: bytes, width: int, height: int) -> Image.Image:
TF.RGB565: (pillow, ("RGB", "raw", "BGR;16")),
TF.BGR24: (pillow, ("RGB", "raw", "BGR")),
TF.R8: (pillow, ("RGB", "raw", "R")),
TF.R16: (pillow, ("RGB", "raw", "R;16")),
TF.R16: (pillow, ("RGB", "raw", "R;16L")),
TF.RG16: (rg, ("RGB", "raw", "RG")),
TF.DXT1: (pillow, ("RGBA", "bcn", 1)),
TF.DXT3: (pillow, ("RGBA", "bcn", 2)),
Expand Down
20 changes: 20 additions & 0 deletions tests/test_texture2d_r16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import struct

from UnityPy.enums import BuildTarget
from UnityPy.enums import TextureFormat as TF
from UnityPy.export.Texture2DConverter import parse_image_data

VERSION = (2021, 3, 56, 0)


def test_r16_decodes_high_byte_into_red():
values = [0x0000, 0x1234, 0x7FFF, 0xFFFF]
data = struct.pack("<4H", *values)

img = parse_image_data(data, 2, 2, TF.R16, VERSION, BuildTarget.StandaloneWindows, flip=False)

assert img.mode == "RGB"
assert img.size == (2, 2)
pixels = img.tobytes()
assert list(pixels[0::3]) == [v >> 8 for v in values]
assert not any(pixels[1::3]) and not any(pixels[2::3])
Loading