From e807dbcd962d9778646daff2fe1f46da9a3575d6 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sun, 15 Mar 2026 17:41:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=88=AA=E5=9B=BE=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=80=E5=87=BA=EF=BC=8C=E6=B7=BB=E5=8A=A0=20compar?= =?UTF-8?q?e=5Fppm.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/D3D12/compare_ppm.py | 75 ++++++++++++++++++++++++++++++++++++++ tests/D3D12/main.cpp | 1 + 2 files changed, 76 insertions(+) create mode 100644 tests/D3D12/compare_ppm.py diff --git a/tests/D3D12/compare_ppm.py b/tests/D3D12/compare_ppm.py new file mode 100644 index 00000000..dcf5de98 --- /dev/null +++ b/tests/D3D12/compare_ppm.py @@ -0,0 +1,75 @@ +import sys +import os + + +def read_ppm(filename): + with open(filename, "rb") as f: + header = f.readline() + if header != b"P6\n": + raise ValueError(f"Not a P6 PPM file: {filename}") + + while True: + line = f.readline() + if not line.startswith(b"#"): + break + + dims = line.split() + width, height = int(dims[0]), int(dims[1]) + + line = f.readline() + maxval = int(line.strip()) + + data = f.read() + return width, height, data + + +def compare_ppm(file1, file2, threshold): + w1, h1, d1 = read_ppm(file1) + w2, h2, d2 = read_ppm(file2) + + if w1 != w2 or h1 != h2: + print(f"ERROR: Size mismatch - {file1}: {w1}x{h1}, {file2}: {w2}x{h2}") + return False + + total_pixels = w1 * h1 + diff_count = 0 + + for i in range(len(d1)): + diff = abs(d1[i] - d2[i]) + if diff > threshold: + diff_count += 1 + + diff_percent = (diff_count / (total_pixels * 3)) * 100 + + print(f"Image 1: {file1} ({w1}x{h1})") + print(f"Image 2: {file2} ({w2}x{h2})") + print(f"Threshold: {threshold}") + print(f"Different pixels: {diff_count} / {total_pixels * 3} ({diff_percent:.2f}%)") + + if diff_percent <= 1.0: + print("PASS: Images match!") + return True + else: + print("FAIL: Images differ!") + return False + + +if __name__ == "__main__": + if len(sys.argv) != 4: + print("Usage: python compare_ppm.py ") + sys.exit(1) + + file1 = sys.argv[1] + file2 = sys.argv[2] + threshold = int(sys.argv[3]) + + if not os.path.exists(file1): + print(f"ERROR: File not found: {file1}") + sys.exit(1) + + if not os.path.exists(file2): + print(f"ERROR: File not found: {file2}") + sys.exit(1) + + result = compare_ppm(file1, file2, threshold) + sys.exit(0 if result else 1) diff --git a/tests/D3D12/main.cpp b/tests/D3D12/main.cpp index 2257ec37..3d3f2080 100644 --- a/tests/D3D12/main.cpp +++ b/tests/D3D12/main.cpp @@ -973,6 +973,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine } else { Log("[DEBUG] Failed to save screenshot!\n"); } + PostQuitMessage(0); } } }