summaryrefslogtreecommitdiff
path: root/barcode_gen.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2024-06-23 23:13:34 +0200
committerjaseg <git@jaseg.de>2024-06-23 23:13:34 +0200
commit66e0f462d379b1cb3f42e988eb8ccca614d967d5 (patch)
tree948a643e90855176d06788201b610ae726b71ea3 /barcode_gen.py
parent8c5c8aee5113dd1249f71530c372c7eff3e7f5ef (diff)
downloadbarcode-main.tar.gz
barcode-main.tar.bz2
barcode-main.zip
Add test data and working manchester decodermain
Diffstat (limited to 'barcode_gen.py')
-rw-r--r--barcode_gen.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/barcode_gen.py b/barcode_gen.py
index 7dfb677..5a9aa30 100644
--- a/barcode_gen.py
+++ b/barcode_gen.py
@@ -5,7 +5,7 @@ import itertools
import textwrap
import click
-from reedmuller import reedmuller
+from reedmuller.reedmuller import ReedMuller
class Tag:
@@ -81,15 +81,19 @@ class Tag:
@click.argument('outfile', type=click.File('w'), default='-')
def cli(data, outfile, height, text, font, font_size, bar_width, margin, color, text_color, dpi):
data = int(data, 16)
+ data &= 0x3ffffff
text_color = text_color or color
- NUM_BITS = 26
+ rm = ReedMuller(3, 5)
- data_bits = [bool(data & (1<<i)) for i in range(NUM_BITS)]
+ data_bits = [bool(data & (1<<i)) for i in range(rm.message_length())]
+ data_bits = rm.encode(data_bits)
+ print('Payload bits:', ''.join([str(int(x)) for x in data_bits]))
data_encoded = itertools.chain(*[
(a, not a) for a in data_bits
])
data_encoded = [True, False, True, False, *data_encoded, False, True, True, False, True]
+ print('Encoded data:', ''.join([str(int(x)) for x in data_encoded]))
width = len(data_encoded) * bar_width
# 1 px = 0.75 pt