aboutsummaryrefslogtreecommitdiff
path: root/tools/check_codes.py
diff options
context:
space:
mode:
authorcirakg <cirakg@cirakg.xyz>2026-10-20 11:24:58 +0200
committercirakg <cirakg@cirakg.xyz>2026-10-20 11:24:58 +0200
commit1251aab9f8f9f38aa5bdefd4fed1f58236166cf8 (patch)
treed9824a2430cff9f6659a5b14b6e437d6b1568b87 /tools/check_codes.py
parentd94eb32c80d2dbf00a45d7e69804f8247240a769 (diff)
test(codes): compare Data Matrix and PDF417 with references and decode them, also from screenshots
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/check_codes.py')
-rw-r--r--tools/check_codes.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/check_codes.py b/tools/check_codes.py
index 53e30f0..7ec47b4 100644
--- a/tools/check_codes.py
+++ b/tools/check_codes.py
@@ -20,6 +20,8 @@ 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]+)")
+# Any 2D code: symbology, width, stored rows, row height, quiet zone, text as hex, modules as hex.
+MATRIX_DUMP = re.compile(r"MATRIXDUMP (\d+) (\d+) (\d+) (\d+) (\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
@@ -43,10 +45,22 @@ def check_log(path: Path) -> tuple[int, list[str]]:
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)
+ got = ref.decode(ref.render_matrix(packed, (size, 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
+ for match in MATRIX_DUMP.finditer(path.read_text(encoding="utf-8", errors="replace")):
+ symbology, width, height, row_height, quiet = (int(match.group(k)) for k in range(1, 6))
+ text = bytes.fromhex(match.group(6)).decode("utf-8")
+ packed = bytes.fromhex(match.group(7))
+ for scale in QR_SCALES:
+ image = ref.render_matrix(packed, (width, height), scale, quiet=max(quiet, 2), row_height=row_height)
+ got = ref.decode(image, symbology)
+ if text not in got:
+ failures.append(
+ f"symbology {symbology} {width}x{height} '{text[:30]}' at {scale} px/module: read {got}"
+ )
+ checked += 1
return checked, failures