From b003627908297b13030452b31cffe9817cd2296b Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Fri, 25 Nov 2016 22:21:30 +0000 Subject: [PATCH] Interpret 4-bit codewords as big-endian for error correction affects microQR symbol sizes M1 and M3 bug reported by Milton Neal --- backend/qr.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/backend/qr.c b/backend/qr.c index f9017649..4585f568 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -2128,7 +2128,7 @@ void micro_qr_m1(char binary_data[]) { data_blocks[2] = 0; for (j = 0; j < 4; j++) { if (binary_data[16 + j] == '1') { - data_blocks[2] += 0x08 >> j; + data_blocks[2] += 0x80 >> j; } } @@ -2302,33 +2302,19 @@ void micro_qr_m3(char binary_data[], int ecc_mode) { if (ecc_mode == LEVEL_L) { data_blocks[10] = 0; - if (binary_data[80] == '1') { - data_blocks[10] += 0x08; - } - if (binary_data[81] == '1') { - data_blocks[10] += 0x04; - } - if (binary_data[82] == '1') { - data_blocks[10] += 0x02; - } - if (binary_data[83] == '1') { - data_blocks[10] += 0x01; + for (j = 0; j < 4; j++) { + if (binary_data[80 + j] == '1') { + data_blocks[10] += 0x80 >> j; + } } } if (ecc_mode == LEVEL_M) { data_blocks[8] = 0; - if (binary_data[64] == '1') { - data_blocks[8] += 0x08; - } - if (binary_data[65] == '1') { - data_blocks[8] += 0x04; - } - if (binary_data[66] == '1') { - data_blocks[8] += 0x02; - } - if (binary_data[67] == '1') { - data_blocks[8] += 0x01; + for (j = 0; j < 4; j++) { + if (binary_data[64 + j] == '1') { + data_blocks[8] += 0x80 >> j; + } } }