RSS_EXPSTACK: #200 use num_columns logic for right-to-left logic

This commit is contained in:
gitlost 2020-07-15 11:41:09 +01:00
parent c1fb51ba42
commit e90c273165
2 changed files with 78 additions and 34 deletions

View File

@ -1510,9 +1510,14 @@ INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int
for (current_row = 1; current_row <= stack_rows; current_row++) {
int special_case_row = 0;
int elements_in_sub;
int sub_elements[235];
for (i = 0; i < 235; i++) {
sub_elements[i] = 0;
int sub_elements[235] = {0};
int num_columns;
/* Number of columns in current row */
if (current_row * symbol->option_2 > codeblocks) {
num_columns = codeblocks - current_block;
} else {
num_columns = symbol->option_2;
}
/* Row Start */
@ -1520,34 +1525,40 @@ INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int
sub_elements[1] = 1;
elements_in_sub = 2;
/* Row Data */
if (((symbol->option_2 & 1) || (current_row & 1)) ||
((current_row == stack_rows) && (codeblocks != (current_row * symbol->option_2)) &&
(((current_row * symbol->option_2) - codeblocks) & 1))) {
/* If last row and is partial and even-numbered, and have even columns (segment pairs), and odd number of finders */
if ((current_row == stack_rows) && (num_columns != symbol->option_2) &&
!(current_row & 1) && !(symbol->option_2 & 1) && (num_columns & 1)) { /* Odd number of finders == odd number of columns */
/* Special case bottom row */
special_case_row = 1;
sub_elements[0] = 2; /* Extra space (latch set below) */
}
/* If odd number of columns or current row odd-numbered or special case last row then left-to-right, else right-to-left */
if ((symbol->option_2 & 1) || (current_row & 1) || special_case_row) {
left_to_right = 1;
} else {
left_to_right = 0;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
if (current_row == stack_rows) {
printf("Last row: number of columns: %d / %d, left to right: %d, special case: %d\n", num_columns, symbol->option_2, left_to_right, special_case_row);
}
}
/* Row Data */
reader = 0;
do {
if (left_to_right) {
/* left to right */
i = 2 + (current_block * 21);
for (j = 0; j < 21; j++) {
if ((i + j) < pattern_width) {
i = 2 + (current_block * 21);
for (j = 0; j < 21; j++) {
if ((i + j) < pattern_width) {
if (left_to_right) {
sub_elements[j + (reader * 21) + 2] = elements[i + j];
} else {
sub_elements[(20 - j) + (num_columns - 1 - reader) * 21 + 2] = elements[i + j];
}
elements_in_sub++;
}
} else {
/* right to left */
i = 2 + (((current_row * symbol->option_2) - reader - 1) * 21);
for (j = 0; j < 21; j++) {
if ((i + j) < pattern_width) {
sub_elements[(20 - j) + (reader * 21) + 2] = elements[i + j];
}
elements_in_sub++;
}
elements_in_sub++;
}
reader++;
current_block++;
@ -1558,15 +1569,7 @@ INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int
sub_elements[elements_in_sub + 1] = 1;
elements_in_sub += 2;
latch = (current_row & 1) ? '0' : '1';
if ((current_row == stack_rows) && (codeblocks != (current_row * symbol->option_2)) &&
((current_row & 1) == 0) && ((symbol->option_2 & 1) == 0)) {
/* Special case bottom row */
special_case_row = 1;
sub_elements[0] = 2;
latch = '0';
}
latch = (current_row & 1) || special_case_row ? '0' : '1';
writer = 0;
for (i = 0; i < elements_in_sub; i++) {

View File

@ -589,12 +589,53 @@ static void test_examples(int index, int generate, int debug) {
"00001000111010000101000101010101010100001011000110000"
"01000111000101111010011000000000101011110100111000010"
},
/* 51*/ { BARCODE_RSS_EXPSTACK, 6, "[01]98898765432106[3202]012345[15]991231[3203]001234[17]010203", 5, 298, "#200 David Gredler mostly empty last row, 16 chars, 2 rows, bottom row 4 chars",
"0100011101110001011011111111000010110000100101111101101000000110001010111100000000101001110000001001010011111011100110001111110000101110101000011000011010011100011000101111000000111001111000111101010111110010110000100011110000001010110010000010000111011111000100101011111100001110011110011000100101"
"0000100010001110100100000000101001001111011010000010010111111001110101000010101010010110001111110110101100000100011001010000001010010001010111100111100101100011100111010000101010000110000111000010101000001101001111010100001010100101001101111101111000100000111011010100000010100001100001100111010000"
"0000010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"0000110000010010011000010000000010111110011010001001111010011011100010010101010010101110100011111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
"1010001111101101100111001111111101000001100101110110000101100100011101000000001100010001011100000110100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
/* 52*/ { BARCODE_RSS_EXPSTACK, 3, "[01]98898765432106[3202]012345[15]991231[3203]001234[17]010203", 9, 151, "#200 16 chars, 3 rows, bottom row 4 chars",
"0100011101110001011011111111000010110000100101111101101000000110001010111100000000101001110000001001010011111011100110001111110000101110101000011000010"
"0000100010001110100100000000101001001111011010000010010111111001110101000010101010010110001111110110101100000100011001010000001010010001010111100110000"
"0000010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000"
"0000101100011100111010000101010000110000111000010101000001101001111010100001010100101001101111101111000100000111011010100000010100001100001100111010000"
"1011010011100011000101111000000111001111000111101010111110010110000100011110000001010110010000010000111011111000100101011111100001110011110011000100101"
"0000101100011100111010000101010000110000111000010101000001101001111010100001010100101001101111101111000100000111011010100000010100001100001100111010000"
"0000010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000"
"0000011111000101110101001010101001000111011001011110010001011001111101000000001000011001001000001100000000000000000000000000000000000000000000000000000"
"0101100000111010001000110000000010111000100110100001101110100110000010111111110011100110110111110001010000000000000000000000000000000000000000000000000"
},
/* 53*/ { BARCODE_RSS_EXPSTACK, 4, "[01]98898765432106[3202]012345[15]991231[3203]001234[17]010203", 5, 200, "#200 16 chars, 2 full rows",
"01000111011100010110111111110000101100001001011111011010000001100010101111000000001010011100000010010100111110111001100011111100001011101010000110000110100111000110001011110000001110011110001111010101"
"00001000100011101001000000001010010011110110100000100101111110011101010000101010100101100011111101101011000001000110010100000010100100010101111001111001011000111001110100001010100001100001110000100000"
"00000101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"00001100000100100110000100000000101111100110100010011110100110111000100101010100101011101000111110010110111001100001100001010000001010110111000001000111101111101100101001010100001010111100101100000000"
"10100011111011011001110011111111010000011001011101100001011001000111010000000011000100010111000001101001000110011110011100001111110101001000111110111000010000010011010100000011110001000011010011111010"
},
/* 54*/ { BARCODE_RSS_EXPSTACK, 5, "[01]98898765432106[3202]012345[15]991231[3203]001234[17]010203", 5, 249, "#200 16 chars, 2 rows, bottom row 6 chars",
"010001110111000101101111111100001011000010010111110110100000011000101011110000000010100111000000100101001111101110011000111111000010111010100001100001101001110001100010111100000011100111100011110101011111001011000010001111000000101011001000001000010"
"000010001000111010010000000010100100111101101000001001011111100111010100001010101001011000111111011010110000010001100101000000101001000101011110011110010110001110011101000010101000011000011100001010100000110100111101010000101010010100110111110110000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000"
"000001000001110110101000000101000011000011001110110100111110001011101010010101010010001110110010111100100010110011111010000000010000110010010000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
"101110111110001001010111111000011100111100110001001011000001110100010001100000000101110001001101000011011101001100000101111111100111001101101111100010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
/* 55*/ { BARCODE_RSS_EXPSTACK, 7, "[01]98898765432106[3202]012345[15]991231[3203]001234[17]010203", 5, 347, "#200 16 chars, 2 rows, bottom row 2 chars",
"01000111011100010110111111110000101100001001011111011010000001100010101111000000001010011100000010010100111110111001100011111100001011101010000110000110100111000110001011110000001110011110001111010101111100101100001000111100000010101100100000100001110111110001001010111111000011100111100110001001011000001110100010001100000000101110001001101000010"
"00001000100011101001000000001010010011110110100000100101111110011101010000101010100101100011111101101011000001000110010100000010100100010101111001111001011000111001110100001010100001100001110000101010000011010011110101000010101001010011011111011110001000001110110101000000101000011000011001110110100111110001011101010010101010010001110110010110000"
"00000101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000"
"00001000101100111110100000000100001100100100000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
"10110111010011000001011111111001110011011011111000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
/* 56*/ { BARCODE_RSS_EXPSTACK, 8, "[01]98898765432106[3202]012345[15]991231[3203]001234[17]010203", 1, 396, "#200 16 chars, 1 row",
"010001110111000101101111111100001011000010010111110110100000011000101011110000000010100111000000100101001111101110011000111111000010111010100001100001101001110001100010111100000011100111100011110101011111001011000010001111000000101011001000001000011101111100010010101111110000111001111001100010010110000011101000100011000000001011100010011010000110111010011000001011111111001110011011011111000101"
},
};
int data_size = sizeof(data) / sizeof(struct item);
char bwipp_buf[4096];
char bwipp_msg[1024];
int pix;
for (int i = 0; i < data_size; i++) {
@ -610,8 +651,8 @@ static void test_examples(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
if (generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].option_2, data[i].data, ret, symbol->rows, symbol->width, data[i].comment);
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].option_2, data[i].data, symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
} else {