Revion of ECI number encoding

This commit is contained in:
Robin Stuart 2017-06-18 13:00:22 +01:00
parent 37ac5e9c54
commit a085bca168
7 changed files with 181 additions and 20 deletions

View File

@ -88,7 +88,7 @@ static int aztec_text_process(const unsigned char source[], const size_t src_len
/* Add FNC1 to beginning of GS1 messages */ /* Add FNC1 to beginning of GS1 messages */
charmap[maplength] = 0; charmap[maplength] = 0;
typemap[maplength++] = PUNC; typemap[maplength++] = PUNC;
charmap[maplength] = 400; charmap[maplength] = 400; // FLG(0)
typemap[maplength++] = PUNC; typemap[maplength++] = PUNC;
} else if (eci != 3) { } else if (eci != 3) {
/* Set ECI mode */ /* Set ECI mode */
@ -99,7 +99,8 @@ static int aztec_text_process(const unsigned char source[], const size_t src_len
typemap[maplength++] = PUNC; typemap[maplength++] = PUNC;
charmap[maplength] = 502 + eci; charmap[maplength] = 502 + eci;
typemap[maplength++] = PUNC; typemap[maplength++] = PUNC;
} else { }
if ((eci >= 10) && (eci <= 99)) {
charmap[maplength] = 402; // FLG(2) charmap[maplength] = 402; // FLG(2)
typemap[maplength++] = PUNC; typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci / 10); charmap[maplength] = 502 + (eci / 10);
@ -107,9 +108,61 @@ static int aztec_text_process(const unsigned char source[], const size_t src_len
charmap[maplength] = 502 + (eci % 10); charmap[maplength] = 502 + (eci % 10);
typemap[maplength++] = PUNC; typemap[maplength++] = PUNC;
} }
if ((eci >= 100) && (eci <= 999)) {
charmap[maplength] = 403; // FLG(3)
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci / 100);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 100) / 10);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci % 10);
typemap[maplength++] = PUNC;
}
if ((eci >= 1000) && (eci <= 9999)) {
charmap[maplength] = 404; // FLG(4)
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci / 1000);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 1000) / 100);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 100) / 10);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci % 10);
typemap[maplength++] = PUNC;
}
if ((eci >= 10000) && (eci <= 99999)) {
charmap[maplength] = 405; // FLG(5)
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci / 10000);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 10000) / 1000);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 1000) / 100);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 100) / 10);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci % 10);
typemap[maplength++] = PUNC;
}
if (eci >= 100000) {
charmap[maplength] = 406; // FLG(6)
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci / 100000);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 100000) / 10000);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 10000) / 1000);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 1000) / 100);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + ((eci % 100) / 10);
typemap[maplength++] = PUNC;
charmap[maplength] = 502 + (eci % 10);
typemap[maplength++] = PUNC;
}
} }
/* Copy the rest of the data into charmap */
for (i = 0; i < (int) src_len; i++) { for (i = 0; i < (int) src_len; i++) {
if ((gs1) && (source[i] == '[')) { if ((gs1) && (source[i] == '[')) {
/* FNC1 represented by FLG(0) */ /* FNC1 represented by FLG(0) */

View File

@ -578,10 +578,27 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
} }
if (symbol->eci > 3) { if (symbol->eci > 3) {
/* Encode ECI numbers according to Table 6 */
target[tp] = 241; /* ECI Character */ target[tp] = 241; /* ECI Character */
tp++; tp++;
target[tp] = (unsigned char) (symbol->eci + 1); if (symbol->eci <= 126) {
target[tp] = (unsigned char) symbol->eci + 1;
tp++; tp++;
}
if ((symbol->eci >= 127) && (symbol->eci <= 16382)) {
target[tp] = (unsigned char) ((symbol->eci - 127) / 254) + 128;
tp++;
target[tp] = (unsigned char) ((symbol->eci - 127) % 254) + 1;
tp++;
}
if (symbol->eci >= 16383) {
target[tp] = (unsigned char) ((symbol->eci - 16383) / 64516) + 192;
tp++;
target[tp] = (unsigned char) (((symbol->eci - 16383) / 254) % 254) + 1;
tp++;
target[tp] = (unsigned char) ((symbol->eci - 16383) % 254) + 1;
tp++;
}
if (debug) printf("ECI %d ", symbol->eci + 1); if (debug) printf("ECI %d ", symbol->eci + 1);
} }

View File

@ -367,8 +367,19 @@ static int gm_encode(int gbdata[], const size_t length, char binary[], int reade
} }
if (eci != 3) { if (eci != 3) {
bin_append(24, 5, binary); /* ECI */ /* ECI assignment according to Table 8 */
bin_append(eci, 10, binary); bin_append(12, 4, binary); /* ECI */
if (eci <= 1023) {
bin_append(eci, 11, binary);
}
if ((eci >= 1024) && (eci <= 32767)) {
strcat(binary, "10");
bin_append(eci, 15, binary);
}
if (eci >= 32768) {
strcat(binary, "11");
bin_append(eci, 20, binary);
}
} }
do { do {

View File

@ -339,9 +339,20 @@ static void calculate_binary(char binary[], char mode[], int source[], const siz
int submode; int submode;
if (eci != 3) { if (eci != 3) {
/* Encoding ECI assignment number, according to Table 5 */
bin_append(8, 4, binary); // ECI bin_append(8, 4, binary); // ECI
if (eci <= 127) {
bin_append(eci, 8, binary); bin_append(eci, 8, binary);
} }
if ((eci >= 128) && (eci <= 16383)) {
strcat(binary, "10");
bin_append(eci, 14, binary);
}
if (eci >= 16384) {
strcat(binary, "110");
bin_append(eci, 21, binary);
}
}
do { do {
block_length = 0; block_length = 0;

View File

@ -820,6 +820,11 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int
#endif #endif
error_number = 0; error_number = 0;
for (i = 0; i < in_length; i++) {
printf("%X ", (int) source[i]);
}
printf("\n");
if (in_length == 0) { if (in_length == 0) {
in_length = (int)ustrlen(source); in_length = (int)ustrlen(source);
} }

View File

@ -452,13 +452,43 @@ int maxi_text_process(int mode, unsigned char source[], int length, int eci) {
} while (i <= 143); } while (i <= 143);
/* Insert ECI at the beginning of message if needed */ /* Insert ECI at the beginning of message if needed */
/* Encode ECI assignment numbers according to table 3 */
if (eci != 3) { if (eci != 3) {
maxi_bump(set, character, 0); maxi_bump(set, character, 0);
character[0] = 27; // ECI character[0] = 27; // ECI
if (eci <= 31) {
maxi_bump(set, character, 1); maxi_bump(set, character, 1);
character[1] = eci; character[1] = eci;
length += 2; length += 2;
} }
if ((eci >= 32) && (eci <= 1023)) {
maxi_bump(set, character, 1);
maxi_bump(set, character, 1);
character[1] = 0x20 + ((eci >> 6) & 0x0F);
character[2] = eci & 0x3F;
length += 3;
}
if ((eci >= 1024) && (eci <= 32767)) {
maxi_bump(set, character, 1);
maxi_bump(set, character, 1);
maxi_bump(set, character, 1);
character[1] = 0x30 + ((eci >> 12) & 0x03);
character[2] = (eci >> 6) & 0x3F;
character[3] = eci & 0x3F;
length += 4;
}
if (eci >= 32768) {
maxi_bump(set, character, 1);
maxi_bump(set, character, 1);
maxi_bump(set, character, 1);
maxi_bump(set, character, 1);
character[1] = 0x38 + ((eci >> 18) & 0x02);
character[2] = (eci >> 12) & 0x3F;
character[3] = (eci >> 6) & 0x3F;
character[4] = eci & 0x3F;
length += 5;
}
}
if (((mode == 2) || (mode == 3)) && (length > 84)) { if (((mode == 2) || (mode == 3)) && (length > 84)) {
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;

View File

@ -616,11 +616,28 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
} }
if (symbol->eci != 3) { if (symbol->eci != 3) {
/* Encoding ECI assignment number, according to Table 8 */
if (symbol->eci <= 899) {
chainemc[mclength] = 927; /* ECI */ chainemc[mclength] = 927; /* ECI */
mclength++; mclength++;
chainemc[mclength] = symbol->eci; chainemc[mclength] = symbol->eci;
mclength++; mclength++;
} }
if ((symbol->eci >= 900) && (symbol->eci <= 810899)) {
chainemc[mclength] = 926; /* ECI */
mclength++;
chainemc[mclength] = (symbol->eci / 900) - 1;
mclength++;
chainemc[mclength] = symbol->eci % 900;
mclength++;
}
if (symbol->eci >= 810900) {
chainemc[mclength] = 925; /* ECI */
mclength++;
chainemc[mclength] = symbol->eci - 810900;
mclength++;
}
}
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
switch (liste[1][i]) { switch (liste[1][i]) {
@ -920,11 +937,28 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_
} }
if (symbol->eci != 3) { if (symbol->eci != 3) {
/* Encoding ECI assignment number, according to Table 8 */
if (symbol->eci <= 899) {
chainemc[mclength] = 927; /* ECI */ chainemc[mclength] = 927; /* ECI */
mclength++; mclength++;
chainemc[mclength] = symbol->eci; chainemc[mclength] = symbol->eci;
mclength++; mclength++;
} }
if ((symbol->eci >= 900) && (symbol->eci <= 810899)) {
chainemc[mclength] = 926; /* ECI */
mclength++;
chainemc[mclength] = (symbol->eci / 900) - 1;
mclength++;
chainemc[mclength] = symbol->eci % 900;
mclength++;
}
if (symbol->eci >= 810900) {
chainemc[mclength] = 925; /* ECI */
mclength++;
chainemc[mclength] = symbol->eci - 810900;
mclength++;
}
}
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
switch (liste[1][i]) { switch (liste[1][i]) {