upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/tex_export.py
diff options
context:
space:
mode:
authorbbareth <179921368+BBareth@users.noreply.github.com>2026-11-22 00:13:17 +0100
committerbbareth <179921368+BBareth@users.noreply.github.com>2026-11-22 00:13:17 +0100
commite2edf405c2812f1ce2b516bdaaf99c8a09052c36 (patch)
tree80b7b1e045109c217d51953cd8c89f885aa168cd /tools/tex_export.py
parent8bd0087d2d0e45fc18fa78fb40b70ecfc6648854 (diff)
tex_export.py: score narrow formats and one-dimensional mips
Diffstat (limited to 'tools/tex_export.py')
-rw-r--r--tools/tex_export.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/tools/tex_export.py b/tools/tex_export.py
index 24cd3a6a3..b0868bc73 100644
--- a/tools/tex_export.py
+++ b/tools/tex_export.py
@@ -84,9 +84,10 @@ def score_image(w, h, fmt, payload, bpe):
84 im = Image.open(io.BytesIO(dds_bytes(w, h, DECODE_AS.get(fmt, fmt), payload))).convert("RGB") 84 im = Image.open(io.BytesIO(dds_bytes(w, h, DECODE_AS.get(fmt, fmt), payload))).convert("RGB")
85 a = np.asarray(im.reduce(4) if min(w, h) >= 64 else im, np.float32) 85 a = np.asarray(im.reduce(4) if min(w, h) >= 64 else im, np.float32)
86 else: 86 else:
87 a = np.frombuffer(payload, np.uint8).reshape(-1, bpe)[:, :4].astype(np.float32) 87 block = FMT[fmt][1]
88 a = a.reshape(-1, max(1, (w + 3) // 4 if bpe >= 8 and FMT[fmt][1] == 4 else w), 4) 88 we, he = (w + block - 1) // block, (h + block - 1) // block
89 d = np.abs(np.diff(a, axis=0)).mean() + np.abs(np.diff(a, axis=1)).mean() 89 a = np.frombuffer(payload, np.uint8).reshape(he, we, bpe)[:, :, :4].astype(np.float32)
90 d = sum(np.abs(np.diff(a, axis=axis)).mean() for axis in (0, 1) if a.shape[axis] > 1)
90 return float(d / (a.std() + 1e-6)) 91 return float(d / (a.std() + 1e-6))
91 92
92 93