diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-20 06:56:58 +0200 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-20 06:56:58 +0200 |
| commit | f455246fde086dda0cb61b92c84a5146a831a2bf (patch) | |
| tree | 09b5e97ee5f84e495bbd0646e1ad0e3e2fbfb9af /tools/barcode_ref.py | |
| parent | 2df98d1ba129f95a10c6b81665671d3b12560c79 (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/barcode_ref.py')
| -rw-r--r-- | tools/barcode_ref.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/barcode_ref.py b/tools/barcode_ref.py index 2e58b5e..f56a7c3 100644 --- a/tools/barcode_ref.py +++ b/tools/barcode_ref.py @@ -16,6 +16,7 @@ from PIL import Image QR, CODE128, CODE39, EAN13, EAN8, UPCA, UPCE, ITF, CODABAR = range(9) FORMATS = { + QR: zxingcpp.BarcodeFormat.QRCode, CODE128: zxingcpp.BarcodeFormat.Code128, CODE39: zxingcpp.BarcodeFormat.Code39, EAN13: zxingcpp.BarcodeFormat.EAN13, @@ -54,6 +55,18 @@ def render_linear(modules: str, scale: int, height: int = 40) -> Image.Image: READ_FORMATS = {**FORMATS, CODE39: zxingcpp.BarcodeFormat.Code39Std, UPCA: zxingcpp.BarcodeFormat.EAN13} +def render_matrix(packed: bytes, size: int, scale: int, quiet: int) -> Image.Image: + """A square matrix (row-major bits, 8 per byte) as black modules on white with a quiet zone.""" + side = (size + 2 * quiet) * scale + image = Image.new("L", (side, side), 255) + for i in range(size * size): + if packed[i // 8] & (0x80 >> (i % 8)): + x, y = i % size, i // size + left, top = (quiet + x) * scale, (quiet + y) * scale + image.paste(0, (left, top, left + scale, top + scale)) + return image + + def decode(image: Image.Image, symbology: int | None = None) -> list[str]: """Texts zxing-cpp reads in image (only as `symbology` when given).""" if symbology is None: |
