mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-24 03:56:56 -04:00
DATAMATRIX: some changes to dm_look_ahead_test to allow exiting from B256
other than for digits (worse for TEX 7-11 embedded in extended) and for returning X12/EDI at EOD - will cause changes in encodation; allow for GS1 GS in B256 (should never happen); some re-jigging of dm200encode and fiddling with dm_isXXX; remove some DM_DEBUG from dm_placementbit
This commit is contained in:
parent
21d015a84a
commit
e9b8ee9c1b
5 changed files with 1843 additions and 550 deletions
|
@ -61,21 +61,8 @@ static void dm_placementbit(int *array, const int NR, const int NC, int r, int c
|
|||
}
|
||||
// Necessary for DMRE (ISO/IEC 21471:2020 Annex E)
|
||||
if (r >= NR) {
|
||||
#ifdef DM_DEBUG
|
||||
fprintf(stderr, "r >= NR:%i,%i at r=%i->", p, b, r);
|
||||
#endif
|
||||
r -= NR;
|
||||
#ifdef DM_DEBUG
|
||||
fprintf(stderr, "%i,c=%i\n", r, c);
|
||||
#endif
|
||||
}
|
||||
#ifdef DM_DEBUG
|
||||
if (0 != array[r * NC + c]) {
|
||||
int a = array[r * NC + c];
|
||||
fprintf(stderr, "Double:%i,%i->%i,%i at r=%i,c=%i\n", a >> 3, a & 7, p, b, r, c);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Check index limits
|
||||
assert(r < NR);
|
||||
assert(c < NC);
|
||||
|
@ -216,18 +203,18 @@ static void dm_ecc(unsigned char *binary, const int bytes, const int datablock,
|
|||
|
||||
/* Is basic (non-shifted) C40? */
|
||||
static int dm_isc40(const unsigned char input) {
|
||||
if ((input >= '0' && input <= '9') || (input >= 'A' && input <= 'Z') || input == ' ') {
|
||||
return 1;
|
||||
if (input <= '9') {
|
||||
return input >= '0' || input == ' ';
|
||||
}
|
||||
return 0;
|
||||
return input >= 'A' && input <= 'Z';
|
||||
}
|
||||
|
||||
/* Is basic (non-shifted) TEXT? */
|
||||
static int dm_istext(const unsigned char input) {
|
||||
if ((input >= '0' && input <= '9') || (input >= 'a' && input <= 'z') || input == ' ') {
|
||||
return 1;
|
||||
if (input <= '9') {
|
||||
return input >= '0' || input == ' ';
|
||||
}
|
||||
return 0;
|
||||
return input >= 'a' && input <= 'z';
|
||||
}
|
||||
|
||||
/* Is basic (non-shifted) C40/TEXT? */
|
||||
|
@ -237,25 +224,12 @@ static int dm_isc40text(const int current_mode, const unsigned char input) {
|
|||
|
||||
/* Return true (1) if a character is valid in X12 set */
|
||||
static int dm_isX12(const unsigned char input) {
|
||||
|
||||
if (dm_isc40(input)) {
|
||||
return 1;
|
||||
}
|
||||
if (input == 13 || input == '*' || input == '>') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return dm_isc40(input) || input == 13 || input == '*' || input == '>';
|
||||
}
|
||||
|
||||
/* Return true (1) if a character is valid in EDIFACT set */
|
||||
static int dm_isedifact(const unsigned char input, const int gs1) {
|
||||
|
||||
if ((input >= ' ' && input <= '^') && (!gs1 || input != '[')) { /* Can't encode GS1 FNC1/GS in EDIFACT */
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (input >= ' ' && input <= '^') && (!gs1 || input != '['); /* Can't encode GS1 FNC1/GS in EDIFACT */
|
||||
}
|
||||
|
||||
static int dm_p_r_6_2_1(const unsigned char inputData[], const int position, const int sourcelen) {
|
||||
|
@ -281,11 +255,10 @@ static int dm_p_r_6_2_1(const unsigned char inputData[], const int position, con
|
|||
#define DM_MULT_2_DIV_3 8
|
||||
#define DM_MULT_3_DIV_4 9
|
||||
#define DM_MULT_1 12
|
||||
#define DM_MULT_5_DIV_4 15
|
||||
#define DM_MULT_4_DIV_3 16
|
||||
#define DM_MULT_2 24
|
||||
#define DM_MULT_9_DIV_4 27
|
||||
#define DM_MULT_8_DIV_3 32
|
||||
#define DM_MULT_3 26
|
||||
#define DM_MULT_13_DIV_4 39
|
||||
#define DM_MULT_10_DIV_3 40
|
||||
#define DM_MULT_4 48
|
||||
|
@ -297,27 +270,27 @@ static int dm_p_r_6_2_1(const unsigned char inputData[], const int position, con
|
|||
|
||||
/* 'look ahead test' from Annex P */
|
||||
static int dm_look_ahead_test(const unsigned char inputData[], const int sourcelen, const int position,
|
||||
const int current_mode, const int gs1, const int debug_print) {
|
||||
const int current_mode, const int mode_arg, const int gs1, const int debug_print) {
|
||||
int ascii_count, c40_count, text_count, x12_count, edf_count, b256_count;
|
||||
int ascii_rnded, c40_rnded, text_rnded, x12_rnded, edf_rnded, b256_rnded;
|
||||
int cnt_1;
|
||||
int sp;
|
||||
|
||||
/* step (j) */
|
||||
if (current_mode == DM_ASCII) {
|
||||
if (current_mode == DM_ASCII || current_mode == DM_BASE256) { /* Adjusted to use for DM_BASE256 also */
|
||||
ascii_count = 0;
|
||||
c40_count = DM_MULT_1;
|
||||
text_count = DM_MULT_1;
|
||||
x12_count = DM_MULT_1;
|
||||
edf_count = DM_MULT_1;
|
||||
b256_count = DM_MULT_5_DIV_4; // 1.25
|
||||
b256_count = DM_MULT_2; /* Adjusted from DM_MULT_5_DIV_4 (1.25) */
|
||||
} else {
|
||||
ascii_count = DM_MULT_1;
|
||||
c40_count = DM_MULT_2;
|
||||
text_count = DM_MULT_2;
|
||||
x12_count = DM_MULT_2;
|
||||
edf_count = DM_MULT_2;
|
||||
b256_count = DM_MULT_9_DIV_4; // 2.25
|
||||
b256_count = DM_MULT_3; /* Adjusted from DM_MULT_9_DIV_4 (2.25) */
|
||||
}
|
||||
|
||||
switch (current_mode) {
|
||||
|
@ -329,7 +302,8 @@ static int dm_look_ahead_test(const unsigned char inputData[], const int sourcel
|
|||
break;
|
||||
case DM_EDIFACT: edf_count = 0;
|
||||
break;
|
||||
case DM_BASE256: b256_count = 0;
|
||||
case DM_BASE256:
|
||||
b256_count = mode_arg == 249 ? DM_MULT_1 : 0; /* Adjusted to use no. of bytes written */
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -338,7 +312,7 @@ static int dm_look_ahead_test(const unsigned char inputData[], const int sourcel
|
|||
int is_extended = c & 0x80;
|
||||
|
||||
/* ascii ... step (l) */
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
if ((c <= '9') && (c >= '0')) {
|
||||
ascii_count += DM_MULT_1_DIV_2; // (l)(1)
|
||||
} else {
|
||||
if (is_extended) {
|
||||
|
@ -400,51 +374,60 @@ static int dm_look_ahead_test(const unsigned char inputData[], const int sourcel
|
|||
b256_count += DM_MULT_1; // (q)(2)
|
||||
}
|
||||
|
||||
if (sp >= position + 4) {
|
||||
/* At least 5 data characters processed ... step (r) */
|
||||
/* NOTE: different than spec, where it's at least 4. Following previous behaviour here (and BWIPP) */
|
||||
if (sp >= position + 3) {
|
||||
/* At least 4 data characters processed ... step (r) */
|
||||
/* NOTE: previous behaviour was at least 5 (same as BWIPP) */
|
||||
|
||||
if (debug_print) {
|
||||
printf("\n(%d, %d, %d): ascii_count %d, b256_count %d, edf_count %d, text_count %d"
|
||||
printf("\n(m:%d, p:%d, sp:%d, a:%d): ascii_count %d, b256_count %d, edf_count %d, text_count %d"
|
||||
", x12_count %d, c40_count %d ",
|
||||
current_mode, position, sp, ascii_count, b256_count, edf_count, text_count,
|
||||
current_mode, position, sp, mode_arg, ascii_count, b256_count, edf_count, text_count,
|
||||
x12_count, c40_count);
|
||||
}
|
||||
|
||||
cnt_1 = ascii_count + DM_MULT_1;
|
||||
if (cnt_1 <= b256_count && cnt_1 <= edf_count && cnt_1 <= text_count && cnt_1 <= x12_count
|
||||
/* Adjusted from <= b256_count */
|
||||
if (cnt_1 < b256_count && cnt_1 <= edf_count && cnt_1 <= text_count && cnt_1 <= x12_count
|
||||
&& cnt_1 <= c40_count) {
|
||||
if (debug_print) printf("ASC->");
|
||||
return DM_ASCII; /* step (r)(1) */
|
||||
}
|
||||
cnt_1 = b256_count + DM_MULT_1;
|
||||
if (cnt_1 <= ascii_count || (cnt_1 < edf_count && cnt_1 < text_count && cnt_1 < x12_count
|
||||
&& cnt_1 < c40_count)) {
|
||||
if (debug_print) printf("BAS->");
|
||||
return DM_BASE256; /* step (r)(2) */
|
||||
}
|
||||
cnt_1 = edf_count + DM_MULT_1;
|
||||
if (cnt_1 < ascii_count && cnt_1 < b256_count && cnt_1 < text_count && cnt_1 < x12_count
|
||||
&& cnt_1 < c40_count) {
|
||||
if (debug_print) printf("EDI->");
|
||||
return DM_EDIFACT; /* step (r)(3) */
|
||||
}
|
||||
cnt_1 = text_count + DM_MULT_1;
|
||||
if (cnt_1 < ascii_count && cnt_1 < b256_count && cnt_1 < edf_count && cnt_1 < x12_count
|
||||
&& cnt_1 < c40_count) {
|
||||
if (debug_print) printf("TEX->");
|
||||
return DM_TEXT; /* step (r)(4) */
|
||||
}
|
||||
cnt_1 = x12_count + DM_MULT_1;
|
||||
if (cnt_1 < ascii_count && cnt_1 < b256_count && cnt_1 < edf_count && cnt_1 < text_count
|
||||
&& cnt_1 < c40_count) {
|
||||
if (debug_print) printf("X12->");
|
||||
return DM_X12; /* step (r)(5) */
|
||||
}
|
||||
cnt_1 = c40_count + DM_MULT_1;
|
||||
if (cnt_1 < ascii_count && cnt_1 < b256_count && cnt_1 < edf_count && cnt_1 < text_count) {
|
||||
if (c40_count < x12_count) {
|
||||
if (debug_print) printf("C40->");
|
||||
return DM_C40; /* step (r)(6)(i) */
|
||||
}
|
||||
if (c40_count == x12_count) {
|
||||
if (dm_p_r_6_2_1(inputData, sp, sourcelen) == 1) {
|
||||
if (debug_print) printf("X12->");
|
||||
return DM_X12; /* step (r)(6)(ii)(I) */
|
||||
}
|
||||
if (debug_print) printf("C40->");
|
||||
return DM_C40; /* step (r)(6)(ii)(II) */
|
||||
}
|
||||
}
|
||||
|
@ -460,35 +443,40 @@ static int dm_look_ahead_test(const unsigned char inputData[], const int sourcel
|
|||
x12_rnded = DM_MULT_CEIL(x12_count);
|
||||
c40_rnded = DM_MULT_CEIL(c40_count);
|
||||
if (debug_print) {
|
||||
printf("\nEOD(%d, %d): ascii_rnded %d, b256_rnded %d, edf_rnded %d, text_rnded %d, x12_rnded %d (%d)"
|
||||
", c40_rnded %d (%d) ",
|
||||
current_mode, position, ascii_rnded, b256_rnded, edf_rnded, text_rnded, x12_rnded, x12_count,
|
||||
c40_rnded, c40_count);
|
||||
printf("\nEOD(m:%d, p:%d, a:%d): ascii_rnded %d, b256_rnded %d, edf_rnded %d, text_rnded %d"
|
||||
", x12_rnded %d (%d), c40_rnded %d (%d) ",
|
||||
current_mode, position, mode_arg, ascii_rnded, b256_rnded, edf_rnded, text_rnded,
|
||||
x12_rnded, x12_count, c40_rnded, c40_count);
|
||||
}
|
||||
|
||||
if (ascii_rnded <= b256_rnded && ascii_rnded <= edf_rnded && ascii_rnded <= text_rnded && ascii_rnded <= x12_rnded
|
||||
&& ascii_rnded <= c40_rnded) {
|
||||
if (debug_print) printf("ASC->");
|
||||
return DM_ASCII; /* step (k)(2) */
|
||||
}
|
||||
if (b256_rnded < ascii_rnded && b256_rnded < edf_rnded && b256_rnded < text_rnded && b256_rnded < x12_rnded
|
||||
&& b256_rnded < c40_rnded) {
|
||||
if (debug_print) printf("BAS->");
|
||||
return DM_BASE256; /* step (k)(3) */
|
||||
}
|
||||
if (edf_rnded < ascii_rnded && edf_rnded < b256_rnded && edf_rnded < text_rnded && edf_rnded < x12_rnded
|
||||
/* Adjusted from < x12_rnded */
|
||||
if (edf_rnded < ascii_rnded && edf_rnded < b256_rnded && edf_rnded < text_rnded && edf_rnded <= x12_rnded
|
||||
&& edf_rnded < c40_rnded) {
|
||||
if (debug_print) printf("EDI->");
|
||||
return DM_EDIFACT; /* step (k)(4) */
|
||||
}
|
||||
if (text_rnded < ascii_rnded && text_rnded < b256_rnded && text_rnded < edf_rnded && text_rnded < x12_rnded
|
||||
&& text_rnded < c40_rnded) {
|
||||
if (debug_print) printf("TEX->");
|
||||
return DM_TEXT; /* step (k)(5) */
|
||||
}
|
||||
if (x12_rnded < ascii_rnded && x12_rnded < b256_rnded && x12_rnded < edf_rnded && x12_rnded < text_rnded
|
||||
/* Adjusted from < edf_rnded */
|
||||
if (x12_rnded < ascii_rnded && x12_rnded < b256_rnded && x12_rnded <= edf_rnded && x12_rnded < text_rnded
|
||||
&& x12_rnded < c40_rnded) {
|
||||
if (debug_print) printf("X12->");
|
||||
return DM_X12; /* step (k)(6) */
|
||||
}
|
||||
/* Note the algorithm is particularly sub-optimal here, returning C40 even if X12/EDIFACT (much) better, due to
|
||||
the < comparisons of rounded X12/EDIFACT values to each other above - comparisons would need to be <= or
|
||||
unrounded (cf. very similar Code One algorithm). Not changed to maintain compatibility with spec and BWIPP */
|
||||
if (debug_print) printf("C40->");
|
||||
return DM_C40; /* step (k)(7) */
|
||||
}
|
||||
|
||||
|
@ -562,9 +550,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
|
|||
}
|
||||
} else {
|
||||
target[tp++] = (unsigned char) (process_buffer[i] << 2);
|
||||
if (debug_print) {
|
||||
printf("[%d (%d)] ", process_buffer[i], target[tp - 1]);
|
||||
}
|
||||
if (debug_print) printf("[%d (%d)] ", process_buffer[i], target[tp - 1]);
|
||||
}
|
||||
process_p = 0;
|
||||
}
|
||||
|
@ -576,7 +562,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
|
|||
}
|
||||
|
||||
/* Get symbol size, as specified or else smallest containing `minimum` codewords */
|
||||
static int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
|
||||
STATIC_UNLESS_ZINT_TEST int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
|
||||
int i;
|
||||
|
||||
if ((symbol->option_2 >= 1) && (symbol->option_2 <= DMSIZESCOUNT)) {
|
||||
|
@ -605,14 +591,14 @@ static int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
|
|||
}
|
||||
|
||||
/* Number of codewords remaining in a particular version (may be negative) */
|
||||
static int dm_codewords_remaining(struct zint_symbol *symbol, const int tp, const int process_p) {
|
||||
STATIC_UNLESS_ZINT_TEST int dm_codewords_remaining(struct zint_symbol *symbol, const int tp, const int process_p) {
|
||||
int symbolsize = dm_get_symbolsize(symbol, tp + process_p); /* Allow for the remaining data characters */
|
||||
|
||||
return dm_matrixbytes[symbolsize] - tp;
|
||||
}
|
||||
|
||||
/* Number of C40/TEXT elements needed to encode `input` */
|
||||
static int dm_c40text_cnt(const int current_mode, const int gs1, unsigned char input) {
|
||||
STATIC_UNLESS_ZINT_TEST int dm_c40text_cnt(const int current_mode, const int gs1, unsigned char input) {
|
||||
int cnt;
|
||||
|
||||
if (gs1 && input == '[') {
|
||||
|
@ -631,7 +617,7 @@ static int dm_c40text_cnt(const int current_mode, const int gs1, unsigned char i
|
|||
}
|
||||
|
||||
/* Update Base 256 field length */
|
||||
static int dm_update_b256_field_length(unsigned char target[], int tp, int b256_start) {
|
||||
STATIC_UNLESS_ZINT_TEST int dm_update_b256_field_length(unsigned char target[], int tp, int b256_start) {
|
||||
int b256_count = tp - (b256_start + 1);
|
||||
if (b256_count <= 249) {
|
||||
target[b256_start] = b256_count;
|
||||
|
@ -649,11 +635,12 @@ static int dm_update_b256_field_length(unsigned char target[], int tp, int b256_
|
|||
/* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate
|
||||
Supports encoding FNC1 in supporting systems */
|
||||
static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], unsigned char target[],
|
||||
int *p_length, int *p_binlen) {
|
||||
int *p_length, int *p_binlen) {
|
||||
|
||||
int sp;
|
||||
int tp, i, gs1;
|
||||
int current_mode, next_mode;
|
||||
int not_first = 0;
|
||||
int inputlen = *p_length;
|
||||
int process_buffer[8]; /* holds remaining data to finalised */
|
||||
int process_p = 0; /* number of characters left to finalise */
|
||||
|
@ -806,7 +793,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
|
|||
if (debug_print) printf("N%02d ", target[tp - 1] - 130);
|
||||
sp += 2;
|
||||
} else {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, gs1, debug_print);
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, 0, gs1, debug_print);
|
||||
|
||||
if (next_mode != DM_ASCII) {
|
||||
switch (next_mode) {
|
||||
|
@ -828,6 +815,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
|
|||
if (debug_print) printf("BAS ");
|
||||
break;
|
||||
}
|
||||
not_first = 0;
|
||||
} else {
|
||||
if (source[sp] & 0x80) {
|
||||
target[tp++] = 235; /* FNC4 */
|
||||
|
@ -855,8 +843,8 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
|
|||
} else if (current_mode == DM_C40 || current_mode == DM_TEXT) {
|
||||
|
||||
next_mode = current_mode;
|
||||
if (process_p == 0) {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, gs1, debug_print);
|
||||
if (process_p == 0 && not_first) {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, process_p, gs1, debug_print);
|
||||
}
|
||||
|
||||
if (next_mode != current_mode) {
|
||||
|
@ -904,90 +892,96 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
|
|||
process_p = dm_ctx_buffer_xfer(process_buffer, process_p, target, &tp, debug_print);
|
||||
}
|
||||
sp++;
|
||||
not_first = 1;
|
||||
}
|
||||
|
||||
/* step (e) X12 encodation */
|
||||
} else if (current_mode == DM_X12) {
|
||||
|
||||
if (dm_isX12(source[sp])) {
|
||||
next_mode = DM_X12;
|
||||
if (process_p == 0) {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, gs1, debug_print);
|
||||
}
|
||||
|
||||
if (next_mode != DM_X12) {
|
||||
target[tp++] = 254; /* Unlatch */
|
||||
next_mode = DM_ASCII;
|
||||
} else {
|
||||
static const char x12_nonalphanum_chars[] = "\015*> ";
|
||||
int value = 0;
|
||||
|
||||
if ((source[sp] >= '0') && (source[sp] <= '9')) {
|
||||
value = (source[sp] - '0') + 4;
|
||||
} else if ((source[sp] >= 'A') && (source[sp] <= 'Z')) {
|
||||
value = (source[sp] - 'A') + 14;
|
||||
} else {
|
||||
value = posn(x12_nonalphanum_chars, source[sp]);
|
||||
}
|
||||
|
||||
process_buffer[process_p++] = value;
|
||||
|
||||
if (process_p >= 3) {
|
||||
process_p = dm_ctx_buffer_xfer(process_buffer, process_p, target, &tp, debug_print);
|
||||
}
|
||||
sp++;
|
||||
}
|
||||
if (!dm_isX12(source[sp])) {
|
||||
next_mode = DM_ASCII;
|
||||
} else {
|
||||
next_mode = DM_X12;
|
||||
if (process_p == 0 && not_first) {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, process_p, gs1, debug_print);
|
||||
}
|
||||
}
|
||||
|
||||
if (next_mode != DM_X12) {
|
||||
process_p = 0; /* Throw away buffer if any */
|
||||
target[tp++] = 254; /* Unlatch */
|
||||
next_mode = DM_ASCII;
|
||||
if (debug_print) printf("ASC ");
|
||||
} else {
|
||||
static const char x12_nonalphanum_chars[] = "\015*> ";
|
||||
int value = 0;
|
||||
|
||||
if ((source[sp] <= '9') && (source[sp] >= '0')) {
|
||||
value = (source[sp] - '0') + 4;
|
||||
} else if ((source[sp] >= 'A') && (source[sp] <= 'Z')) {
|
||||
value = (source[sp] - 'A') + 14;
|
||||
} else {
|
||||
value = posn(x12_nonalphanum_chars, source[sp]);
|
||||
}
|
||||
|
||||
process_buffer[process_p++] = value;
|
||||
|
||||
if (process_p >= 3) {
|
||||
process_p = dm_ctx_buffer_xfer(process_buffer, process_p, target, &tp, debug_print);
|
||||
}
|
||||
sp++;
|
||||
not_first = 1;
|
||||
}
|
||||
if (debug_print && next_mode == DM_ASCII) printf("ASC ");
|
||||
|
||||
/* step (f) EDIFACT encodation */
|
||||
} else if (current_mode == DM_EDIFACT) {
|
||||
|
||||
if (dm_isedifact(source[sp], gs1)) {
|
||||
if (!dm_isedifact(source[sp], gs1)) {
|
||||
next_mode = DM_ASCII;
|
||||
} else {
|
||||
next_mode = DM_EDIFACT;
|
||||
if (process_p == 3) {
|
||||
/* Note different then spec Step (f)(1), which suggests checking when 0, but this seems to work
|
||||
better in many cases as the switch to ASCII is "free" */
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, gs1, debug_print);
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, process_p, gs1, debug_print);
|
||||
}
|
||||
}
|
||||
|
||||
if (next_mode != DM_EDIFACT) {
|
||||
process_buffer[process_p++] = 31;
|
||||
process_p = dm_edi_buffer_xfer(process_buffer, process_p, target, &tp, 1 /*empty*/, debug_print);
|
||||
next_mode = DM_ASCII;
|
||||
if (debug_print) printf("ASC ");
|
||||
} else {
|
||||
int value = source[sp];
|
||||
|
||||
if (value >= 64) { // '@'
|
||||
value -= 64;
|
||||
}
|
||||
|
||||
if (next_mode != DM_EDIFACT) {
|
||||
process_buffer[process_p++] = 31;
|
||||
next_mode = DM_ASCII;
|
||||
} else {
|
||||
int value = source[sp];
|
||||
|
||||
if (value >= 64) { // '@'
|
||||
value -= 64;
|
||||
}
|
||||
|
||||
process_buffer[process_p++] = value;
|
||||
sp++;
|
||||
}
|
||||
process_buffer[process_p++] = value;
|
||||
sp++;
|
||||
not_first = 1;
|
||||
|
||||
if (process_p >= 4) {
|
||||
process_p = dm_edi_buffer_xfer(process_buffer, process_p, target, &tp, 0 /*empty*/, debug_print);
|
||||
}
|
||||
} else {
|
||||
process_buffer[process_p++] = 31;
|
||||
process_p = dm_edi_buffer_xfer(process_buffer, process_p, target, &tp, 1 /*empty*/, debug_print);
|
||||
next_mode = DM_ASCII;
|
||||
}
|
||||
if (debug_print && next_mode == DM_ASCII) printf("ASC ");
|
||||
|
||||
/* step (g) Base 256 encodation */
|
||||
} else if (current_mode == DM_BASE256) {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, gs1, debug_print);
|
||||
|
||||
if (next_mode == DM_BASE256) {
|
||||
target[tp++] = source[sp];
|
||||
sp++;
|
||||
if (debug_print) printf("B%02X ", target[tp - 1]);
|
||||
if (gs1 == 1 && source[sp] == '[') {
|
||||
next_mode = DM_ASCII;
|
||||
} else {
|
||||
next_mode = DM_BASE256;
|
||||
if (not_first) {
|
||||
next_mode = dm_look_ahead_test(source, inputlen, sp, current_mode, tp - (b256_start + 1), gs1,
|
||||
debug_print);
|
||||
}
|
||||
}
|
||||
|
||||
if (next_mode != DM_BASE256) {
|
||||
tp = dm_update_b256_field_length(target, tp, b256_start);
|
||||
/* B.2.1 255-state randomising algorithm */
|
||||
for (i = b256_start; i < tp; i++) {
|
||||
|
@ -996,6 +990,15 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
|
|||
}
|
||||
next_mode = DM_ASCII;
|
||||
if (debug_print) printf("ASC ");
|
||||
} else {
|
||||
if (gs1 == 2 && source[sp] == '[') {
|
||||
target[tp++] = 29; /* GS */
|
||||
} else {
|
||||
target[tp++] = source[sp];
|
||||
}
|
||||
sp++;
|
||||
not_first = 1;
|
||||
if (debug_print) printf("B%02X ", target[tp - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1223,9 +1226,9 @@ static int datamatrix_200(struct zint_symbol *symbol, const unsigned char source
|
|||
}
|
||||
#endif
|
||||
{ // placement
|
||||
int x, y, NC, NR, *places;
|
||||
NC = W - 2 * (W / FW);
|
||||
NR = H - 2 * (H / FH);
|
||||
const int NC = W - 2 * (W / FW);
|
||||
const int NR = H - 2 * (H / FH);
|
||||
int x, y, *places;
|
||||
if (!(places = (int *) calloc(NC * NR, sizeof(int)))) {
|
||||
strcpy(symbol->errtxt, "718: Insufficient memory for placement array");
|
||||
return ZINT_ERROR_MEMORY;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue