From 87de3255bae5172e17ba18405484a0abe0f95fe1 Mon Sep 17 00:00:00 2001 From: jravallec <68116084+jravallec@users.noreply.github.com> Date: Wed, 22 Jul 2020 14:34:16 +0200 Subject: [PATCH 1/2] Update aztec_code_generator.py Reviewed part when leaving binary mode to any other mode. Issue for the number of bytes when superior to 31 corrected. --- aztec_code_generator.py | 48 +++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/aztec_code_generator.py b/aztec_code_generator.py index a1f66cc..918508c 100644 --- a/aztec_code_generator.py +++ b/aztec_code_generator.py @@ -265,16 +265,34 @@ def find_optimal_sequence(data): else: if x == 'binary': # TODO: review this + # Reviewed by jravallec if y == back_to[x]: # when return from binary to previous mode, skip mode change cur_seq[y] = cur_seq[x] + ['resume'] + elif y == 'upper': + if back_to[x] == 'lower': + cur_seq[y] = cur_seq[x] + ['resume', 'M/L', 'U/L'] + if back_to[x] == 'mixed': + cur_seq[y] = cur_seq[x] + ['resume', 'U/L'] + back_to[y] = 'upper' + elif y == 'lower': + cur_seq[y] = cur_seq[x] + ['resume', 'L/L'] + back_to[y] = 'lower' + elif y == 'mixed': + cur_seq[y] = cur_seq[x] + ['resume', 'M/L'] + back_to[y] = 'mixed' elif y == 'punct': - cur_seq[y] = cur_seq[x] + ['resume', 'M/L', 'P/L'] + if back_to[x] == 'mixed': + cur_seq[y] = cur_seq[x] + ['resume', 'P/L'] + else: + cur_seq[y] = cur_seq[x] + ['resume', 'M/L', 'P/L'] back_to[y] = 'punct' - elif y == 'upper' and back_to[x] == 'lower': - # when return from binary back to lower and then to upper - cur_seq[y] = cur_seq[x] + ['resume', 'M/L', 'U/L'] - back_to[y] = 'upper' + elif y == 'digit': + if back_to[x] == 'mixed': + cur_seq[y] = cur_seq[x] + ['resume', 'U/L', 'D/L'] + else: + cur_seq[y] = cur_seq[x] + ['resume', 'D/L'] + back_to[y] = 'digit' else: cur_seq[y] = cur_seq[x] + ['resume', '%s/L' % y.upper()[0]] back_to[y] = y @@ -365,13 +383,21 @@ def find_optimal_sequence(data): result_seq = [x for x in result_seq if x != 'resume'] # update binary sequences' extra sizes updated_result_seq = [] + is_binary_length = True for i, c in enumerate(result_seq): - if c == 'B/S': - if result_seq[i + 1] > 31: - updated_result_seq.append(c) + if is_binary_length: + if c > 31: updated_result_seq.append(0) - continue - updated_result_seq.append(c) + updated_result_seq.append(c - 31) + else: + updated_result_seq.append(c) + is_binary_length = False + else: + updated_result_seq.append(c) + + if c == 'B/S': + is_binary_length = True + return updated_result_seq @@ -430,7 +456,7 @@ def optimal_sequence_to_bits(optimal_sequence): if not isinstance(seq_len, numbers.Number): raise Exception('Binary sequence length must be a number') out_bits += bin(seq_len)[2:].zfill(11) - binary_seq_len = seq_len + binary_seq_len = seq_len + 31 binary = True binary_index = 0 # update previous mode From 6830b275f960021e312f990bffabafb4762adc7c Mon Sep 17 00:00:00 2001 From: jravallec <68116084+jravallec@users.noreply.github.com> Date: Wed, 22 Jul 2020 14:48:52 +0200 Subject: [PATCH 2/2] Update aztec_code_generator.py --- aztec_code_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aztec_code_generator.py b/aztec_code_generator.py index 918508c..65bbb28 100644 --- a/aztec_code_generator.py +++ b/aztec_code_generator.py @@ -383,7 +383,7 @@ def find_optimal_sequence(data): result_seq = [x for x in result_seq if x != 'resume'] # update binary sequences' extra sizes updated_result_seq = [] - is_binary_length = True + is_binary_length = False for i, c in enumerate(result_seq): if is_binary_length: if c > 31: