From 18b7a593bd55ea26f8d568ef68766f78752d8306 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Thu, 30 Oct 2025 12:18:05 -0500 Subject: [PATCH] tools: add zbuf_decode.py --- tools/zbuf_decode.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tools/zbuf_decode.py diff --git a/tools/zbuf_decode.py b/tools/zbuf_decode.py new file mode 100644 index 0000000..5fb4517 --- /dev/null +++ b/tools/zbuf_decode.py @@ -0,0 +1,38 @@ +import sys +import struct + +with open(sys.argv[1], 'rb') as f: + buf = memoryview(f.read()) + +print("P2") +print("1600 1200") +print("65535") + +min_n = None +max_n = None + +for i in range(len(buf) // 4): + b = buf[i*4:i*4+4] + + num, = struct.unpack("> 8 + depth16 = num >> 16 + + if i == 0: + min_n = depth24 + max_n = depth24 + + if min_n == 0 or (depth24 < min_n and depth24 != 0): + min_n = depth24 + if depth24 > max_n: + max_n = depth24 + + print(depth16, end='') + if i % 128 == 127: + print("", end='\n') + else: + print("", end=" ") + + +print(min_n, max_n, file=sys.stderr)