aboutsummaryrefslogtreecommitdiff
path: root/tools/check_codes.py
diff options
context:
space:
mode:
authorcirakg <cirakg@cirakg.xyz>2026-10-20 06:56:58 +0200
committercirakg <cirakg@cirakg.xyz>2026-10-20 06:56:58 +0200
commitf455246fde086dda0cb61b92c84a5146a831a2bf (patch)
tree09b5e97ee5f84e495bbd0646e1ad0e3e2fbfb9af /tools/check_codes.py
parent2df98d1ba129f95a10c6b81665671d3b12560c79 (diff)
test(codes): compare QR with segno, decode QR dumps and the QR screenshot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/check_codes.py')
-rw-r--r--tools/check_codes.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/check_codes.py b/tools/check_codes.py
index 22d3033..53e30f0 100644
--- a/tools/check_codes.py
+++ b/tools/check_codes.py
@@ -19,7 +19,9 @@ from pathlib import Path
import barcode_ref as ref
DUMP = re.compile(r"CODEDUMP (\d+) ([0-9a-f]*) ([01]+)")
+QR_DUMP = re.compile(r"QRDUMP (\d+) ([0-9a-f]*) ([0-9a-f]+)")
SCALES = (1, 2, 3)
+QR_SCALES = (2, 3) # README 12.2: 2D codes use at least 2 px per module
def check_log(path: Path) -> tuple[int, list[str]]:
@@ -36,6 +38,15 @@ def check_log(path: Path) -> tuple[int, list[str]]:
if expected not in got:
failures.append(f"symbology {symbology} '{text}' at {scale} px/module: read {got}")
checked += 1
+ for match in QR_DUMP.finditer(path.read_text(encoding="utf-8", errors="replace")):
+ size = int(match.group(1))
+ text = bytes.fromhex(match.group(2)).decode("utf-8")
+ packed = bytes.fromhex(match.group(3))
+ for scale in QR_SCALES:
+ got = ref.decode(ref.render_matrix(packed, size, scale, quiet=4), ref.QR)
+ if text not in got:
+ failures.append(f"QR size {size} '{text[:30]}' at {scale} px/module: read {got}")
+ checked += 1
return checked, failures