aboutsummaryrefslogtreecommitdiff
path: root/tools/barcode_ref.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/barcode_ref.py')
-rw-r--r--tools/barcode_ref.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/barcode_ref.py b/tools/barcode_ref.py
index f56a7c3..9c4c6d5 100644
--- a/tools/barcode_ref.py
+++ b/tools/barcode_ref.py
@@ -14,9 +14,12 @@ from typing import Any, cast
import zxingcpp
from PIL import Image
-QR, CODE128, CODE39, EAN13, EAN8, UPCA, UPCE, ITF, CODABAR = range(9)
+QR, CODE128, CODE39, EAN13, EAN8, UPCA, UPCE, ITF, CODABAR, DATAMATRIX, PDF417, AZTEC = range(12)
FORMATS = {
QR: zxingcpp.BarcodeFormat.QRCode,
+ DATAMATRIX: zxingcpp.BarcodeFormat.DataMatrix,
+ PDF417: zxingcpp.BarcodeFormat.PDF417,
+ AZTEC: zxingcpp.BarcodeFormat.Aztec,
CODE128: zxingcpp.BarcodeFormat.Code128,
CODE39: zxingcpp.BarcodeFormat.Code39,
EAN13: zxingcpp.BarcodeFormat.EAN13,
@@ -55,15 +58,17 @@ 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):
+def render_matrix(packed: bytes, shape: tuple[int, int], scale: int, *, quiet: int, row_height: int = 1) -> Image.Image:
+ """A matrix (row-major bits, 8 per byte; shape = width and stored rows,
+ each row row_height modules high) as black modules on white with a
+ quiet zone."""
+ size, rows = shape
+ image = Image.new("L", ((size + 2 * quiet) * scale, (rows * row_height + 2 * quiet) * scale), 255)
+ for i in range(size * rows):
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))
+ left, top = (quiet + x) * scale, (quiet + y * row_height) * scale
+ image.paste(0, (left, top, left + scale, top + scale * row_height))
return image