From 1f503f2aca93dd14b8f60357b8aad06dfbe1137d Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 6 Aug 2017 09:10:00 +0100 Subject: [PATCH] Dedupe error correction code in Aztec --- backend/aztec.c | 93 +++++++++---------------------------------------- 1 file changed, 16 insertions(+), 77 deletions(-) diff --git a/backend/aztec.c b/backend/aztec.c index 5567c5a0..a1d9168c 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -1338,98 +1338,37 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], const size_t lengt memset(data_part, 0, (data_blocks + 2) * sizeof (int)); memset(ecc_part, 0, (ecc_blocks + 2) * sizeof (int)); - /* Split into codewords and calculate reed-colomon error correction codes */ + /* Split into codewords and calculate reed-solomon error correction codes */ + for (i = 0; i < data_blocks; i++) { + for (p = 0; p < codeword_size; p++) { + if (adjusted_string[i * codeword_size + p] == '1') { + data_part[i] += 0x01 << (codeword_size - (p + 1)); + } + } + } + switch (codeword_size) { case 6: - for (i = 0; i < data_blocks; i++) { - for (p = 0; p < 6; p++) { - if (adjusted_string[i * codeword_size + p] == '1') { - data_part[i] += (0x20 >> p); - } - } - } rs_init_gf(0x43); - rs_init_code(ecc_blocks, 1); - rs_encode_long(data_blocks, data_part, ecc_part); - for (i = (ecc_blocks - 1); i >= 0; i--) { - for (p = 0; p < 6; p++) { - if (ecc_part[i] & (0x20 >> p)) { - strcat(adjusted_string, "1"); - } else { - strcat(adjusted_string, "0"); - } - } - } - rs_free(); break; case 8: - for (i = 0; i < data_blocks; i++) { - for (p = 0; p < 8; p++) { - if (adjusted_string[i * codeword_size + p] == '1') { - data_part[i] += (0x80 >> p); - } - } - } rs_init_gf(0x12d); - rs_init_code(ecc_blocks, 1); - rs_encode_long(data_blocks, data_part, ecc_part); - for (i = (ecc_blocks - 1); i >= 0; i--) { - for (p = 0; p < 8; p++) { - if (ecc_part[i] & (0x80 >> p)) { - strcat(adjusted_string, "1"); - } else { - strcat(adjusted_string, "0"); - } - } - } - rs_free(); break; case 10: - for (i = 0; i < data_blocks; i++) { - for (p = 0; p < 10; p++) { - if (adjusted_string[i * codeword_size + p] == '1') { - data_part[i] += (0x200 >> p); - } - } - } rs_init_gf(0x409); - rs_init_code(ecc_blocks, 1); - rs_encode_long(data_blocks, data_part, ecc_part); - for (i = (ecc_blocks - 1); i >= 0; i--) { - for (p = 0; p < 10; p++) { - if (ecc_part[i] & (0x200 >> p)) { - strcat(adjusted_string, "1"); - } else { - strcat(adjusted_string, "0"); - } - } - } - rs_free(); break; case 12: - for (i = 0; i < data_blocks; i++) { - for (p = 0; p < 12; p++) { - if (adjusted_string[i * codeword_size + p] == '1') { - data_part[i] += (0x800 >> p); - } - } - } rs_init_gf(0x1069); - rs_init_code(ecc_blocks, 1); - rs_encode_long(data_blocks, data_part, ecc_part); - for (i = (ecc_blocks - 1); i >= 0; i--) { - for (p = 0; p < 12; p++) { - if (ecc_part[i] & (0x800 >> p)) { - strcat(adjusted_string, "1"); - } else { - strcat(adjusted_string, "0"); - } - } - } - rs_free(); break; } + rs_init_code(ecc_blocks, 1); + rs_encode_long(data_blocks, data_part, ecc_part); + for (i = (ecc_blocks - 1); i >= 0; i--) { + bin_append(ecc_part[i], codeword_size, adjusted_string); + } + rs_free(); + /* Invert the data so that actual data is on the outside and reed-solomon on the inside */ memset(bit_pattern, '0', 20045);