MICROQR: some debug output, test case for ticket #241

This commit is contained in:
gitlost 2021-08-26 17:49:05 +01:00
parent b7adbf4e5b
commit b568201574
2 changed files with 47 additions and 18 deletions

View File

@ -1797,7 +1797,7 @@ static void micro_qr_m1(struct zint_symbol *symbol, char binary_data[]) {
latch = 0; latch = 0;
/* Add terminator */ /* Add terminator */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left <= 3) { if (bits_left <= 3) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -1807,9 +1807,13 @@ static void micro_qr_m1(struct zint_symbol *symbol, char binary_data[]) {
strcat(binary_data, "000"); strcat(binary_data, "000");
} }
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("M1 Terminated binary (%d): %s (bits_left %d)\n", (int) strlen(binary_data), binary_data, bits_left);
}
if (latch == 0) { if (latch == 0) {
/* Manage last (4-bit) block */ /* Manage last (4-bit) block */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left <= 4) { if (bits_left <= 4) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -1829,7 +1833,7 @@ static void micro_qr_m1(struct zint_symbol *symbol, char binary_data[]) {
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left > 4) { if (bits_left > 4) {
remainder = (bits_left - 4) / 8; remainder = (bits_left - 4) / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
@ -1859,8 +1863,6 @@ static void micro_qr_m1(struct zint_symbol *symbol, char binary_data[]) {
} }
#ifdef ZINT_TEST #ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords); if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords);
#else
(void)symbol; /* Unused */
#endif #endif
/* Calculate Reed-Solomon error codewords */ /* Calculate Reed-Solomon error codewords */
@ -1892,7 +1894,7 @@ static void micro_qr_m2(struct zint_symbol *symbol, char binary_data[], const in
else assert(0); else assert(0);
/* Add terminator */ /* Add terminator */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left <= 5) { if (bits_left <= 5) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -1902,6 +1904,10 @@ static void micro_qr_m2(struct zint_symbol *symbol, char binary_data[], const in
bin_append(0, 5, binary_data); bin_append(0, 5, binary_data);
} }
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("M2 Terminated binary (%d): %s (bits_left %d)\n", (int) strlen(binary_data), binary_data, bits_left);
}
if (latch == 0) { if (latch == 0) {
/* Complete current byte */ /* Complete current byte */
int remainder = 8 - (strlen(binary_data) % 8); int remainder = 8 - (strlen(binary_data) % 8);
@ -1913,7 +1919,7 @@ static void micro_qr_m2(struct zint_symbol *symbol, char binary_data[], const in
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
remainder = bits_left / 8; remainder = bits_left / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
strcat(binary_data, (i & 1) ? "00010001" : "11101100"); strcat(binary_data, (i & 1) ? "00010001" : "11101100");
@ -1942,8 +1948,6 @@ static void micro_qr_m2(struct zint_symbol *symbol, char binary_data[], const in
} }
#ifdef ZINT_TEST #ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords); if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords);
#else
(void)symbol; /* Unused */
#endif #endif
/* Calculate Reed-Solomon error codewords */ /* Calculate Reed-Solomon error codewords */
@ -1977,7 +1981,7 @@ static void micro_qr_m3(struct zint_symbol *symbol, char binary_data[], const in
else assert(0); else assert(0);
/* Add terminator */ /* Add terminator */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left <= 7) { if (bits_left <= 7) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -1987,9 +1991,13 @@ static void micro_qr_m3(struct zint_symbol *symbol, char binary_data[], const in
bin_append(0, 7, binary_data); bin_append(0, 7, binary_data);
} }
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("M3 Terminated binary (%d): %s (bits_left %d)\n", (int) strlen(binary_data), binary_data, bits_left);
}
if (latch == 0) { if (latch == 0) {
/* Manage last (4-bit) block */ /* Manage last (4-bit) block */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left <= 4) { if (bits_left <= 4) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2009,7 +2017,7 @@ static void micro_qr_m3(struct zint_symbol *symbol, char binary_data[], const in
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left > 4) { if (bits_left > 4) {
remainder = (bits_left - 4) / 8; remainder = (bits_left - 4) / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
@ -2059,8 +2067,6 @@ static void micro_qr_m3(struct zint_symbol *symbol, char binary_data[], const in
} }
#ifdef ZINT_TEST #ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords); if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords);
#else
(void)symbol; /* Unused */
#endif #endif
/* Calculate Reed-Solomon error codewords */ /* Calculate Reed-Solomon error codewords */
@ -2097,7 +2103,7 @@ static void micro_qr_m4(struct zint_symbol *symbol, char binary_data[], const in
else assert(0); else assert(0);
/* Add terminator */ /* Add terminator */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
if (bits_left <= 9) { if (bits_left <= 9) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2107,6 +2113,10 @@ static void micro_qr_m4(struct zint_symbol *symbol, char binary_data[], const in
bin_append(0, 9, binary_data); bin_append(0, 9, binary_data);
} }
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("M4 Terminated binary (%d): %s (bits_left %d)\n", (int) strlen(binary_data), binary_data, bits_left);
}
if (latch == 0) { if (latch == 0) {
/* Complete current byte */ /* Complete current byte */
int remainder = 8 - (strlen(binary_data) % 8); int remainder = 8 - (strlen(binary_data) % 8);
@ -2118,7 +2128,7 @@ static void micro_qr_m4(struct zint_symbol *symbol, char binary_data[], const in
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - (int)strlen(binary_data); bits_left = bits_total - (int) strlen(binary_data);
remainder = bits_left / 8; remainder = bits_left / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
strcat(binary_data, (i & 1) ? "00010001" : "11101100"); strcat(binary_data, (i & 1) ? "00010001" : "11101100");
@ -2151,8 +2161,6 @@ static void micro_qr_m4(struct zint_symbol *symbol, char binary_data[], const in
} }
#ifdef ZINT_TEST #ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords); if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, data_blocks, data_codewords);
#else
(void)symbol; /* Unused */
#endif #endif
/* Calculate Reed-Solomon error codewords */ /* Calculate Reed-Solomon error codewords */
@ -2562,6 +2570,8 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len
qr_binary((unsigned char *) full_stream, MICROQR_VERSION + version, 0 /*target_codewords*/, mode, jisdata, length, qr_binary((unsigned char *) full_stream, MICROQR_VERSION + version, 0 /*target_codewords*/, mode, jisdata, length,
0 /*gs1*/, 0 /*eci*/, binary_count[version], debug_print); 0 /*gs1*/, 0 /*eci*/, binary_count[version], debug_print);
if (debug_print) printf("Binary (%d): %s\n", (int) strlen(full_stream), full_stream);
switch (version) { switch (version) {
case 0: micro_qr_m1(symbol, full_stream); case 0: micro_qr_m1(symbol, full_stream);
break; break;

View File

@ -2179,6 +2179,25 @@ static void test_microqr_encode(int index, int generate, int debug) {
"01011000000010111" "01011000000010111"
"11001111011101001" "11001111011101001"
}, },
/* 16*/ { UNICODE_MODE | ESCAPE_MODE, 1, -1, -1, "P-5-B223G846\015", 0, 17, 17, 1, "Ticket #241, 2.6.7 dropping off last character if mode different (MR #21)",
"11111110101010101"
"10000010100001100"
"10111010011110010"
"10111010100000101"
"10111010011011111"
"10000010111110100"
"11111110110111101"
"00000000011001000"
"10010111011010100"
"01110111000001110"
"10100011001110111"
"00011111000101010"
"10011111101100110"
"01110000111010100"
"11001010110000000"
"00011110011010001"
"11101010111111111"
},
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;