mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Improved method for avoiding illegal codewords in Aztec
Fixes #190 reported by Milton Neal
This commit is contained in:
parent
27e211f9d3
commit
737ffd4ce0
119
backend/aztec.c
119
backend/aztec.c
@ -1123,42 +1123,35 @@ INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], const siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
i = 0;
|
count = 0;
|
||||||
do {
|
for (i = 0; i < data_length; i++) {
|
||||||
if ((j + 1) % codeword_size == 0) {
|
|
||||||
/* Last bit of codeword */
|
|
||||||
int t, done = 0;
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* Discover how many '1's in current codeword */
|
|
||||||
for (t = 0; t < (codeword_size - 1); t++) {
|
|
||||||
if (binary_string[(i - (codeword_size - 1)) + t] == '1') count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == (codeword_size - 1)) {
|
|
||||||
adjusted_string[j] = '0';
|
|
||||||
j++;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
adjusted_string[j] = '1';
|
|
||||||
j++;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done == 0) {
|
|
||||||
adjusted_string[j] = binary_string[i];
|
|
||||||
j++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
adjusted_string[j] = binary_string[i];
|
adjusted_string[j] = binary_string[i];
|
||||||
j++;
|
j++;
|
||||||
i++;
|
|
||||||
} while (i <= (data_length + 1));
|
if (binary_string[i] == '1') {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((j + 1) % codeword_size == 0) {
|
||||||
|
// Last bit of codeword
|
||||||
|
|
||||||
|
if (count == (codeword_size - 1)) {
|
||||||
|
// Codeword of all '1's
|
||||||
|
adjusted_string[j] = '0';
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
// Codeword of all '0's
|
||||||
|
adjusted_string[j] = '1';
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
adjusted_string[j] = '\0';
|
adjusted_string[j] = '\0';
|
||||||
adjusted_length = (int) strlen(adjusted_string);
|
adjusted_length = j;
|
||||||
adjustment_size = adjusted_length - data_length;
|
adjustment_size = adjusted_length - data_length;
|
||||||
|
|
||||||
/* Add padding */
|
/* Add padding */
|
||||||
@ -1233,42 +1226,36 @@ INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], const siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
i = 0;
|
count = 0;
|
||||||
do {
|
for (i = 0; i < data_length; i++) {
|
||||||
if ((j + 1) % codeword_size == 0) {
|
|
||||||
/* Last bit of codeword */
|
|
||||||
int t, done = 0;
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* Discover how many '1's in current codeword */
|
|
||||||
for (t = 0; t < (codeword_size - 1); t++) {
|
|
||||||
if (binary_string[(i - (codeword_size - 1)) + t] == '1') count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == (codeword_size - 1)) {
|
|
||||||
adjusted_string[j] = '0';
|
|
||||||
j++;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
adjusted_string[j] = '1';
|
|
||||||
j++;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done == 0) {
|
|
||||||
adjusted_string[j] = binary_string[i];
|
|
||||||
j++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
adjusted_string[j] = binary_string[i];
|
adjusted_string[j] = binary_string[i];
|
||||||
j++;
|
j++;
|
||||||
i++;
|
|
||||||
} while (i <= (data_length + 1));
|
if (binary_string[i] == '1') {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((j + 1) % codeword_size == 0) {
|
||||||
|
// Last bit of codeword
|
||||||
|
|
||||||
|
if (count == (codeword_size - 1)) {
|
||||||
|
// Codeword of all '1's
|
||||||
|
adjusted_string[j] = '0';
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
// Codeword of all '0's
|
||||||
|
adjusted_string[j] = '1';
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
adjusted_string[j] = '\0';
|
adjusted_string[j] = '\0';
|
||||||
adjusted_length = (int) strlen(adjusted_string);
|
adjusted_length = j;
|
||||||
|
adjustment_size = adjusted_length - data_length;
|
||||||
|
|
||||||
remainder = adjusted_length % codeword_size;
|
remainder = adjusted_length % codeword_size;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user