mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Dotcode: Add custom height setting and format code
This commit is contained in:
parent
0c5f9191e6
commit
674a491a56
@ -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[]
|
||||
// employing Galois Field GF, where GF is prime, with a prime modulus of PM
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void rsencode(int nd, int nc, unsigned char *wd) {
|
||||
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;
|
||||
|
||||
// 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:
|
||||
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":
|
||||
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 (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
|
||||
input_position += 2;
|
||||
done = 1;
|
||||
if (debug) { printf("A "); }
|
||||
if (debug) {
|
||||
printf("A ");
|
||||
}
|
||||
}
|
||||
|
||||
if ((input_position == length - 1) && (inside_macro == 100)) {
|
||||
// inside_macro only gets set to 100 if the last character is EOT
|
||||
input_position++;
|
||||
done = 1;
|
||||
if (debug) { printf("A "); }
|
||||
if (debug) {
|
||||
printf("A ");
|
||||
}
|
||||
}
|
||||
|
||||
/* Step B1 */
|
||||
@ -423,7 +430,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
|
||||
input_position += 7;
|
||||
inside_macro = 97;
|
||||
done = 1;
|
||||
if (debug) { printf("B1/1 "); }
|
||||
if (debug) {
|
||||
printf("B1/1 ");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
inside_macro = 98;
|
||||
done = 1;
|
||||
if (debug) { printf("B1/2 "); }
|
||||
if (debug) {
|
||||
printf("B1/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;
|
||||
inside_macro = 99;
|
||||
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;
|
||||
inside_macro = 100;
|
||||
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++;
|
||||
input_position += 10;
|
||||
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++;
|
||||
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';
|
||||
}
|
||||
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;
|
||||
if (debug) { printf("B4 "); }
|
||||
if (debug) {
|
||||
printf("B4 ");
|
||||
}
|
||||
}
|
||||
|
||||
/* Step C1 */
|
||||
@ -562,7 +585,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
|
||||
encoding_mode = 'C';
|
||||
}
|
||||
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++;
|
||||
input_position++;
|
||||
done = 1;
|
||||
if (debug) { printf("C2/1 "); }
|
||||
if (debug) {
|
||||
printf("C2/1 ");
|
||||
}
|
||||
} else {
|
||||
if (datum_b(source, input_position, length)) {
|
||||
codeword_array[array_length] = source[input_position] - 32;
|
||||
array_length++;
|
||||
input_position++;
|
||||
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';
|
||||
}
|
||||
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';
|
||||
}
|
||||
done = 1;
|
||||
if (debug) { printf("C4 "); }
|
||||
if (debug) {
|
||||
printf("C4 ");
|
||||
}
|
||||
}
|
||||
|
||||
/* Step D1 */
|
||||
@ -650,7 +683,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
|
||||
encoding_mode = 'C';
|
||||
}
|
||||
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++;
|
||||
input_position++;
|
||||
done = 1;
|
||||
if (debug) { printf("D2/1 "); }
|
||||
if (debug) {
|
||||
printf("D2/1 ");
|
||||
}
|
||||
} else {
|
||||
if (datum_a(source, input_position, length)) {
|
||||
if (source[input_position] < 32) {
|
||||
@ -672,7 +709,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
|
||||
array_length++;
|
||||
input_position++;
|
||||
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';
|
||||
}
|
||||
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';
|
||||
}
|
||||
done = 1;
|
||||
if (debug) { printf("D4 "); }
|
||||
if (debug) {
|
||||
printf("D4 ");
|
||||
}
|
||||
}
|
||||
|
||||
/* Step E1 */
|
||||
@ -756,7 +799,9 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i
|
||||
encoding_mode = 'C';
|
||||
}
|
||||
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++;
|
||||
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++;
|
||||
done = 1;
|
||||
if (debug) { printf("E3 "); }
|
||||
if (debug) {
|
||||
printf("E3 ");
|
||||
}
|
||||
}
|
||||
} while (input_position < length);
|
||||
|
||||
if (debug) { printf("\n\n"); }
|
||||
if (debug) {
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
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
|
||||
* 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 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;
|
||||
|
||||
//FIXME: Listen to user preferences here
|
||||
if (symbol->option_2 == 0) {
|
||||
|
||||
height = sqrt(2 * min_dots);
|
||||
if ((height % 2) == 1) {
|
||||
if (height % 2) {
|
||||
height++;
|
||||
}
|
||||
|
||||
width = (2 * min_dots) / height;
|
||||
|
||||
if ((width % 2) != 1) {
|
||||
if (!(width % 2)) {
|
||||
width++;
|
||||
}
|
||||
|
||||
} else {
|
||||
width = symbol->option_2;
|
||||
|
||||
height = min_dots / width;
|
||||
|
||||
if (!((width + height) % 2)) {
|
||||
height++;
|
||||
}
|
||||
}
|
||||
|
||||
n_dots = (height * width) / 2;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
@ -1162,5 +1224,7 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
symbol->row_height[k] = 1;
|
||||
}
|
||||
|
||||
symbol->barcode_options += BARCODE_DOTTY_MODE;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user