diff --git a/UnityPy/export/Texture2DConverter.py b/UnityPy/export/Texture2DConverter.py index a46eed5f..90d82c70 100644 --- a/UnityPy/export/Texture2DConverter.py +++ b/UnityPy/export/Texture2DConverter.py @@ -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)), diff --git a/tests/test_texture2d_r16.py b/tests/test_texture2d_r16.py new file mode 100644 index 00000000..bb42e4c5 --- /dev/null +++ b/tests/test_texture2d_r16.py @@ -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])