diff options
Diffstat (limited to 'tools/check_codes.py')
| -rw-r--r-- | tools/check_codes.py | 16 |
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 |
