Commit b99ac773 authored by Nathan/Eilisha Shiraini's avatar Nathan/Eilisha Shiraini
Browse files

Multiple corrections

parent 7c6a7fdb
......@@ -3,6 +3,8 @@ import os
import sys
import importlib
from . import imgen
EXCLUDE_MODULES = [
"imgen",
]
......@@ -57,4 +59,6 @@ def _test():
data = BUILDERS['aztec']['builder'](text).encode()
with open(fname + '.txt', 'wt') as f:
f.write(str(data))
imager = imgen.draw.ImGenerator([data], imgen.interpolate.BWInterpolate.SINGLE, '1', 1, 1)
imager.drawCode()
imager.saveImage(fname + '.png')
......@@ -17,6 +17,8 @@ from . import sizes
from . import positions
from . import reference
MINEC = 0.23
class AztecBuilder(object):
"""
Aztec Code builder class
......@@ -51,6 +53,8 @@ class AztecBuilder(object):
self.__init__(value)
def prepare(self):
if self.__size is None:
self.__size = (None, None)
prepared, layers, compact, wordcount = self.prepareData(self.__data, *self.__size)
self.__prepared = prepared
self.__size = (layers, compact)
......@@ -97,6 +101,7 @@ class AztecBuilder(object):
the second is the number of error-correction code words.
"""
encoded = encoder.Encoder().encode(data, asBits = True)
ecfact = 1 / (1 - MINEC)
if isinstance(forceLayers, int):
wordsize = sizes.WORD_SIZE_FOR_LAYERS[forceLayers]
stuffed = list(reedsolomon.towords(reedsolomon.stuff(encoded, wordsize), wordsize))
......@@ -109,20 +114,20 @@ class AztecBuilder(object):
wordsize = sizes.WORD_SIZE_FOR_LAYERS[i]
stuffed = list(reedsolomon.towords(reedsolomon.stuff(encoded, wordsize), wordsize))
if forceCompact is not None:
if forceCompact and len(stuffed) <= sizes.COMPACT_WORD_COUNT[i]:
if forceCompact and len(stuffed) * ecfact <= sizes.COMPACT_WORD_COUNT[i]:
compact = True
layers = i
break
elif len(stuffed) <= sizes.FULL_WORD_COUNT[i]:
elif len(stuffed) * ecfact <= sizes.FULL_WORD_COUNT[i]:
compact = False
layers = i
break
else:
if i < 5 and len(stuffed) <= sizes.COMPACT_WORD_COUNT[i]:
if i < 5 and len(stuffed) * ecfact <= sizes.COMPACT_WORD_COUNT[i]:
compact = True
layers = i
break
elif len(stuffed) <= sizes.FULL_WORD_COUNT[i]:
elif i > 4 and len(stuffed) * ecfact <= sizes.FULL_WORD_COUNT[i]:
compact = False
layers = i
break
......@@ -217,6 +222,6 @@ class AztecBuilder(object):
reference.layoutModeMessage(data, reference.modeMessage(layers, compact, wordcount[0]), layers, compact)
reference.layoutFinder(data, layers, compact)
reference.layoutOrientation(data, layers, compact)
if compact:
if not compact:
reference.layoutRefGrid(data, layers)
return data, layers, compact, wordcount
......@@ -93,7 +93,7 @@ def _positionList(layers, compact):
for i, row in enumerate(matrix):
for j, cell in enumerate(row):
if cell != -1:
lst[cell] = (i, j)
lst[cell] = (j, i)
del lst[lst.index((-1, -1)):]
return lst
......
......@@ -47,16 +47,24 @@ cdef class _GF(object):
def isMode(self):
return self.minlayers == MODE_MESSAGE
@property
def exptable(self):
return [self.__exptable[i] for i in range(1 << (self.wordsize + 1))]
@property
def logtable(self):
return [self.__exptable[i] for i in range(1 << (self.wordsize))]
cdef uint16_t __mul_nolut(self, uint16_t a, uint16_t b):
cdef uint16_t r = 0
cdef uint16_t fs = self.fieldsize
while b:
if b & 1:
r ^= a
a >>= 1
b <<= 1
a <<= 1
b >>= 1
if a & fs:
a %= self.polynomial
a ^= self.polynomial
return r
cdef void __init_lut(self):
......
......@@ -9,7 +9,10 @@ def stuff(data, wordsize):
stuffone = True
stuffzero = True
for _ in range(wordsize - 1):
bit = data.popleft()
try:
bit = data.popleft()
except IndexError:
bit = False
if bit:
stuffone = False
else:
......@@ -20,11 +23,14 @@ def stuff(data, wordsize):
elif stuffone:
result.append(True)
else:
result.append(data.popleft())
pad = (wordsize - len(result) % wordsize) % wordsize
result.extend([True] * pad)
if pad and all(result[-wordsize:]):
result[-1] = False
try:
result.append(data.popleft())
except IndexError:
result.append(False)
#pad = (wordsize - len(result) % wordsize) % wordsize
#result.extend([True] * pad)
#if pad and all(result[-wordsize:]):
# result[-1] = False
return result
def towords(data, wordsize):
......
......@@ -111,12 +111,14 @@ def modeMessage(layers, compact, wordcount):
if isinstance(wordcount, tuple):
wordcount = wordcount[0]
if compact:
message = ((layers - 1) & 0x3) << 6 + ((wordcount - 1) & 0x3F)
message = (((layers - 1) & 0x3) << 6) + ((wordcount - 1) & 0x3F)
message = [s == '1' for s in '{:08b}'.format(message)]
else:
message = ((layers - 1) & 0x1F) << 11 + ((wordcount - 1) & 0x7FF)
mmwords = rs.towords(message, sz.WORD_SIZE_FOR_LAYERS[0])
rsvalue = sz.GALLOIS_FIELD_FOR_LAYERS[0].gen_rs_code(mmwords, 5 if compact else 6)
result = rs.fromwords(mmwords + rsvalue, sz.WORD_SIZE_FOR_LAYERS[0])
message = (((layers - 1) & 0x1F) << 11) + ((wordcount - 1) & 0x7FF)
message = [s == '1' for s in '{:016b}'.format(message)]
mmwords = list(rs.towords(message, sz.WORD_SIZE_FOR_LAYERS[0]))
rsvalue = list(sz.GALLOIS_FIELD_FOR_LAYERS[0].gen_rs_code(mmwords, 5 if compact else 6))
result = list(rs.fromwords(mmwords + rsvalue, sz.WORD_SIZE_FOR_LAYERS[0]))
return result
def layoutModeMessage(matrix, message, layers, compact):
......@@ -130,9 +132,9 @@ def layoutFinder(matrix, layers, compact):
size = ps.matrixSize(layers, compact)
centerPos = size >> 1
finderSize = 4 if compact else 6
for i in range(finderSize):
for j in range(finderSize):
matrix[i + centerPos, j + centerPos] = max(i, j) & 1 == 0
for i in range(-finderSize, finderSize + 1):
for j in range(-finderSize, finderSize + 1):
matrix[i + centerPos, j + centerPos] = max(abs(i), abs(j)) & 1 == 0
def layoutOrientation(matrix, layers, compact):
size = ps.matrixSize(layers, compact)
......
from . import draw
from . import interpolate
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment