Files
metin2-client/tests/host/rgb_target_blend_test.py
T

26 lines
1.3 KiB
Python

"""GPU regression: python3 rgb_target_blend_test.py <host_blend_state_test> <mt_native_render>."""
import pathlib
import struct
import subprocess
import sys
import tempfile
with tempfile.TemporaryDirectory(prefix="metin2-rgb-blend-") as directory:
capture = pathlib.Path(directory) / "destalpha.capture"
screenshot = pathlib.Path(directory) / "destalpha.bmp"
subprocess.run([sys.argv[1], str(capture)], check=True)
subprocess.run([sys.argv[2], "--capture", str(capture), "--frames", "1",
"--width", "320", "--height", "240", "--screenshot-out", str(screenshot)],
check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
data = screenshot.read_bytes()
offset = struct.unpack_from("<I", data, 10)[0]
width, height = struct.unpack_from("<ii", data, 18)
bits = struct.unpack_from("<H", data, 28)[0]
assert bits in (24, 32), f"unsupported screenshot format: {bits}"
stride = ((width * bits + 31) // 32) * 4
pixel = offset + (abs(height) // 2) * stride + (width // 2) * (bits // 8)
actual = tuple(data[pixel:pixel + 3][::-1])
expected = (128, 128, 160) # source * 128/255 + background * 1
assert all(abs(a - b) <= 1 for a, b in zip(actual, expected)), (actual, expected)
print(f"PASS XRGB SRCALPHA/DESTALPHA GPU pixel: {actual}")