Dotcode: Add custom height setting and format code

This commit is contained in:
Robin Stuart 2016-08-07 20:11:51 +01:00
parent 0c5f9191e6
commit 674a491a56

View File

@ -177,6 +177,7 @@ int score_array (char Dots[], int Hgt, int Wid) {
// "rsencode(nd,nc)" adds "nc" R-S check words to "nd" data words in wd[] // "rsencode(nd,nc)" adds "nc" R-S check words to "nd" data words in wd[]
// employing Galois Field GF, where GF is prime, with a prime modulus of PM // employing Galois Field GF, where GF is prime, with a prime modulus of PM
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
void rsencode(int nd, int nc, unsigned char *wd) { void rsencode(int nd, int nc, unsigned char *wd) {
int i, j, k, nw, start, step, root[GF], c[GF]; int i, j, k, nw, start, step, root[GF], c[GF];
@ -186,7 +187,8 @@ void rsencode (int nd, int nc, unsigned char *wd) {
root[i] = (PM * root[i - 1]) % GF; root[i] = (PM * root[i - 1]) % GF;
// Here we compute how many interleaved R-S blocks will be needed // Here we compute how many interleaved R-S blocks will be needed
nw = nd + nc; step = (nw + GF - 2)/(GF - 1); nw = nd + nc;
step = (nw + GF - 2) / (GF - 1);
// ...& then for each such block: // ...& then for each such block:
for (start = 0; start < step; start++) { for (start = 0; start < step; start++) {
@ -194,7 +196,8 @@ void rsencode (int nd, int nc, unsigned char *wd) {
// first compute the generator polynomial "c" of order "NC": // first compute the generator polynomial "c" of order "NC":
for (i = 1; i <= NC; i++) for (i = 1; i <= NC; i++)
c[i] = 0; c[0] = 1; c[i] = 0;
c[0] = 1;
for (i = 1; i <= NC; i++) { for (i = 1; i <= NC; i++) {
for (j = NC; j >= 1; j--) { for (j = NC; j >= 1; j--) {
@ -393,14 +396,18 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
// inside_macro only gets set to 97, 98 or 99 if the last two characters are RS/EOT // inside_macro only gets set to 97, 98 or 99 if the last two characters are RS/EOT
input_position += 2; input_position += 2;
done = 1; done = 1;
if (debug) { printf("A "); } if (debug) {
printf("A ");
}
} }
if ((input_position == length - 1) && (inside_macro == 100)) { if ((input_position == length - 1) && (inside_macro == 100)) {
// inside_macro only gets set to 100 if the last character is EOT // inside_macro only gets set to 100 if the last character is EOT
input_position++; input_position++;
done = 1; done = 1;
if (debug) { printf("A "); } if (debug) {
printf("A ");
}
} }
/* Step B1 */ /* Step B1 */
@ -423,7 +430,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
input_position += 7; input_position += 7;
inside_macro = 97; inside_macro = 97;
done = 1; done = 1;
if (debug) { printf("B1/1 "); } if (debug) {
printf("B1/1 ");
}
} }
if ((source[input_position + 4] == '0') && (source[input_position + 5] == '6')) { if ((source[input_position + 4] == '0') && (source[input_position + 5] == '6')) {
@ -432,7 +441,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
input_position += 7; input_position += 7;
inside_macro = 98; inside_macro = 98;
done = 1; done = 1;
if (debug) { printf("B1/2 "); } if (debug) {
printf("B1/2 ");
}
} }
if ((source[input_position + 4] == '1') && (source[input_position + 5] == '2')) { if ((source[input_position + 4] == '1') && (source[input_position + 5] == '2')) {
@ -441,7 +452,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
input_position += 7; input_position += 7;
inside_macro = 99; inside_macro = 99;
done = 1; done = 1;
if (debug) { printf("B1/3 "); } if (debug) {
printf("B1/3 ");
}
} }
} }
@ -451,7 +464,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
input_position += 4; input_position += 4;
inside_macro = 100; inside_macro = 100;
done = 1; done = 1;
if (debug) { printf("B1/4 "); } if (debug) {
printf("B1/4 ");
}
} }
} }
} }
@ -470,7 +485,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
array_length++; array_length++;
input_position += 10; input_position += 10;
done = 1; done = 1;
if (debug) { printf("B2/1 "); } if (debug) {
printf("B2/1 ");
}
} }
} }
@ -485,7 +502,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
} }
array_length++; array_length++;
done = 1; done = 1;
if (debug) { printf("B2/2 "); } if (debug) {
printf("B2/2 ");
}
} }
} }
@ -511,7 +530,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'X'; encoding_mode = 'X';
} }
done = 1; done = 1;
if (debug) { printf("B3 "); } if (debug) {
printf("B3 ");
}
} }
} }
@ -540,7 +561,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
} }
} }
done = 1; done = 1;
if (debug) { printf("B4 "); } if (debug) {
printf("B4 ");
}
} }
/* Step C1 */ /* Step C1 */
@ -562,7 +585,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'C'; encoding_mode = 'C';
} }
done = 1; done = 1;
if (debug) { printf("C1 "); } if (debug) {
printf("C1 ");
}
} }
} }
@ -573,14 +598,18 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
array_length++; array_length++;
input_position++; input_position++;
done = 1; done = 1;
if (debug) { printf("C2/1 "); } if (debug) {
printf("C2/1 ");
}
} else { } else {
if (datum_b(source, input_position, length)) { if (datum_b(source, input_position, length)) {
codeword_array[array_length] = source[input_position] - 32; codeword_array[array_length] = source[input_position] - 32;
array_length++; array_length++;
input_position++; input_position++;
done = 1; done = 1;
if (debug) { printf("C2/2 "); } if (debug) {
printf("C2/2 ");
}
} }
} }
} }
@ -607,7 +636,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'X'; encoding_mode = 'X';
} }
done = 1; done = 1;
if (debug) { printf("C3 "); } if (debug) {
printf("C3 ");
}
} }
} }
@ -629,7 +660,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'A'; encoding_mode = 'A';
} }
done = 1; done = 1;
if (debug) { printf("C4 "); } if (debug) {
printf("C4 ");
}
} }
/* Step D1 */ /* Step D1 */
@ -650,7 +683,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'C'; encoding_mode = 'C';
} }
done = 1; done = 1;
if (debug) { printf("D1 "); } if (debug) {
printf("D1 ");
}
} }
} }
@ -661,7 +696,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
array_length++; array_length++;
input_position++; input_position++;
done = 1; done = 1;
if (debug) { printf("D2/1 "); } if (debug) {
printf("D2/1 ");
}
} else { } else {
if (datum_a(source, input_position, length)) { if (datum_a(source, input_position, length)) {
if (source[input_position] < 32) { if (source[input_position] < 32) {
@ -672,7 +709,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
array_length++; array_length++;
input_position++; input_position++;
done = 1; done = 1;
if (debug) { printf("D2/2 "); } if (debug) {
printf("D2/2 ");
}
} }
} }
} }
@ -699,7 +738,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'X'; encoding_mode = 'X';
} }
done = 1; done = 1;
if (debug) { printf("D3 "); } if (debug) {
printf("D3 ");
}
} }
} }
@ -721,7 +762,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'B'; encoding_mode = 'B';
} }
done = 1; done = 1;
if (debug) { printf("D4 "); } if (debug) {
printf("D4 ");
}
} }
/* Step E1 */ /* Step E1 */
@ -756,7 +799,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
encoding_mode = 'C'; encoding_mode = 'C';
} }
done = 1; done = 1;
if (debug) { printf("E1 "); } if (debug) {
printf("E1 ");
}
} }
} }
@ -789,7 +834,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
} }
input_position++; input_position++;
done = 1; done = 1;
if (debug) { printf("E2 "); } if (debug) {
printf("E2 ");
}
} }
} }
@ -817,11 +864,15 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
} }
array_length++; array_length++;
done = 1; done = 1;
if (debug) { printf("E3 "); } if (debug) {
printf("E3 ");
}
} }
} while (input_position < length); } while (input_position < length);
if (debug) { printf("\n\n"); } if (debug) {
printf("\n\n");
}
return array_length; return array_length;
} }
@ -864,7 +915,8 @@ int make_dotstream(unsigned char masked_array[], int array_length, char dot_stre
} }
/* Determines if a given dot is a reserved corner dot /* Determines if a given dot is a reserved corner dot
* to be used by one of the last six bits */ * to be used by one of the last six bits
*/
int is_corner(int column, int row, int width, int height) { int is_corner(int column, int row, int width, int height) {
int corner = 0; int corner = 0;
@ -1001,18 +1053,28 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) {
min_dots = 9 * (data_length + 3 + (data_length / 2)) + 2; min_dots = 9 * (data_length + 3 + (data_length / 2)) + 2;
//FIXME: Listen to user preferences here if (symbol->option_2 == 0) {
height = sqrt(2 * min_dots); height = sqrt(2 * min_dots);
if ((height % 2) == 1) { if (height % 2) {
height++; height++;
} }
width = (2 * min_dots) / height; width = (2 * min_dots) / height;
if (!(width % 2)) {
if ((width % 2) != 1) {
width++; width++;
} }
} else {
width = symbol->option_2;
height = min_dots / width;
if (!((width + height) % 2)) {
height++;
}
}
n_dots = (height * width) / 2; n_dots = (height * width) / 2;
#ifndef _MSC_VER #ifndef _MSC_VER
@ -1162,5 +1224,7 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) {
symbol->row_height[k] = 1; symbol->row_height[k] = 1;
} }
symbol->barcode_options += BARCODE_DOTTY_MODE;
return 0; return 0;
} }