PDF417/raster: performance large data; common.h inline, module_colour_is_set(); #209

This commit is contained in:
gitlost 2020-11-01 18:32:55 +00:00
parent 6bdd7e8509
commit 44923349f3
26 changed files with 1222 additions and 799 deletions

View file

@ -50,8 +50,14 @@
#include <malloc.h>
#include "ms_stdint.h"
#endif
#include "pdf417.h"
#include <assert.h>
#include "common.h"
#include "pdf417.h"
#define TEX 900
#define BYT 901
#define NUM 902
/*
Three figure numbers in comments give the location of command equivalents in the
original Visual Basic source code file pdf417.frm
@ -59,14 +65,16 @@
/* text mode processing tables */
static const char asciix[95] = {
static const char asciix[127] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 8, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 12, 8, 8, 4, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 8, 8, 8, 8
};
static const char asciiy[95] = {
static const char asciiy[127] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 15, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 4, 5, 6, 24, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
@ -85,17 +93,16 @@ static const char MicroAutosize[56] = {
/* 866 */
static int quelmode(char codeascii) {
int mode = BYT;
if ((codeascii == '\t') || (codeascii == '\n') || (codeascii == '\r') || ((codeascii >= ' ') && (codeascii <= '~'))) {
mode = TEX;
static int quelmode(unsigned char codeascii) {
if ((codeascii <= '9') && (codeascii >= '0')) {
return NUM;
}
if ((codeascii >= '0') && (codeascii <= '9')) {
mode = NUM;
if (codeascii < 127 && asciix[codeascii]) {
return TEX;
}
/* 876 */
return mode;
return BYT;
}
/* 844 */
@ -230,21 +237,9 @@ static void textprocess(int *chainemc, int *mclength, char chaine[], int start,
/* listet will contain the table numbers and the value of each characters */
for (indexlistet = 0; indexlistet < length; indexlistet++) {
char codeascii = chaine[start + indexlistet];
switch (codeascii) {
case '\t': listet[0][indexlistet] = 12;
listet[1][indexlistet] = 12;
break;
case '\n': listet[0][indexlistet] = 8;
listet[1][indexlistet] = 15;
break;
case 13: listet[0][indexlistet] = 12;
listet[1][indexlistet] = 11;
break;
default: listet[0][indexlistet] = asciix[codeascii - 32];
listet[1][indexlistet] = asciiy[codeascii - 32];
break;
}
int codeascii = chaine[start + indexlistet];
listet[0][indexlistet] = asciix[codeascii];
listet[1][indexlistet] = asciiy[codeascii];
}
/* 570 */
@ -271,13 +266,11 @@ static void textprocess(int *chainemc, int *mclength, char chaine[], int start,
chainet[wnet] = 27;
chainet[wnet + 1] = listet[1][j];
wnet += 2;
}
if (listet[0][j] & 8) { /* T_PUN */
} else if (listet[0][j] & 8) { /* T_PUN (T_PUN and T_UPP not both possible) */
chainet[wnet] = 29;
chainet[wnet + 1] = listet[1][j];
wnet += 2;
}
if (!(((listet[0][j] & 1) && (curtable == 2)) || (listet[0][j] & 8))) {
} else {
/* No temporary switch available */
flag = FALSE;
}
@ -298,24 +291,10 @@ static void textprocess(int *chainemc, int *mclength, char chaine[], int start,
}
/* Maintain the first if several tables are possible */
switch (newtable) {
case 3:
case 5:
case 7:
case 9:
case 11:
case 13:
case 15:
newtable = 1;
break;
case 6:
case 10:
case 14:
newtable = 2;
break;
case 12:
newtable = 4;
break;
if (newtable == 7) {
newtable = 1;
} else if (newtable == 12) {
newtable = 4;
}
/* 619 - select the switch */
@ -471,9 +450,7 @@ INTERNAL void byteprocess(int *chainemc, int *mclength, unsigned char chaine[],
/* 712 */
static void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int length) {
int j, loop, dummy[50] = {0}, diviseur, nombre;
char chainemod[50], chainemult[100], temp;
strcpy(chainemod, "");
char chainemod[46], chainemult[46];
chainemc[(*mclength)++] = 902;
@ -481,12 +458,12 @@ static void numbprocess(int *chainemc, int *mclength, char chaine[], int start,
while (j < length) {
int longueur;
int dumlength = 0;
strcpy(chainemod, "");
int p;
longueur = length - j;
if (longueur > 44) {
longueur = 44;
}
strcat(chainemod, "1");
chainemod[0] = '1';
for (loop = 1; loop <= longueur; loop++) {
chainemod[loop] = chaine[start + loop + j - 1];
}
@ -495,36 +472,29 @@ static void numbprocess(int *chainemc, int *mclength, char chaine[], int start,
diviseur = 900;
/* 877 - gosub Modulo */
strcpy(chainemult, "");
p = 0;
chainemult[p] = '\0';
nombre = 0;
while (strlen(chainemod) != 0) {
for (loop = 0; chainemod[loop]; loop++) {
nombre *= 10;
nombre += ctoi(chainemod[0]);
for (loop = 0; loop < (int)strlen(chainemod); loop++) {
chainemod[loop] = chainemod[loop + 1];
}
nombre += ctoi(chainemod[loop]);
if (nombre < diviseur) {
if (strlen(chainemult) != 0) {
strcat(chainemult, "0");
if (p) {
chainemult[p++] = '0';
}
} else {
temp = (nombre / diviseur) + '0';
chainemult[strlen(chainemult) + 1] = '\0';
chainemult[strlen(chainemult)] = temp;
chainemult[p++] = (nombre / diviseur) + '0';
nombre = nombre % diviseur;
}
nombre = nombre % diviseur;
}
chainemult[p] = '\0';
diviseur = nombre;
/* return to 723 */
for (loop = dumlength; loop > 0; loop--) {
dummy[loop] = dummy[loop - 1];
}
dummy[0] = diviseur;
dumlength++;
dummy[dumlength++] = diviseur;
strcpy(chainemod, chainemult);
} while (strlen(chainemult) != 0);
for (loop = 0; loop < dumlength; loop++) {
} while (p);
for (loop = dumlength - 1; loop >= 0; loop--) {
chainemc[(*mclength)++] = dummy[loop];
}
j += longueur;
@ -532,8 +502,8 @@ static void numbprocess(int *chainemc, int *mclength, char chaine[], int start,
}
/* 366 */
static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length) {
int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset;
static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const int length) {
int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520] = {0}, offset;
int total, chainemc[PDF417_MAX_LEN], mclength, c1, c2, c3, dummy[35], calcheight;
int liste[2][PDF417_MAX_LEN] = {{0}};
char pattern[580];
@ -554,13 +524,13 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
/* 463 */
do {
liste[1][indexliste] = mode;
while ((liste[1][indexliste] == mode) && (indexchaine < (int)length)) {
while ((liste[1][indexliste] == mode) && (indexchaine < length)) {
liste[0][indexliste]++;
indexchaine++;
mode = quelmode(chaine[indexchaine]);
}
indexliste++;
} while (indexchaine < (int)length);
} while (indexchaine < length);
/* 474 */
pdfsmooth(liste, &indexliste);
@ -592,22 +562,24 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
}
if (symbol->eci != 0) {
if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "472: Invalid ECI");
return ZINT_ERROR_INVALID_OPTION;
}
/* Encoding ECI assignment number, according to Table 8 */
if (symbol->eci <= 899) {
chainemc[mclength] = 927; /* ECI */
mclength++;
chainemc[mclength] = symbol->eci;
mclength++;
}
if ((symbol->eci >= 900) && (symbol->eci <= 810899)) {
} else if (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) {
} else {
chainemc[mclength] = 925; /* ECI */
mclength++;
chainemc[mclength] = symbol->eci - 810900;
@ -615,11 +587,6 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
}
}
if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "472: Invalid ECI");
return ZINT_ERROR_INVALID_OPTION;
}
for (i = 0; i < indexliste; i++) {
switch (liste[1][i]) {
case TEX: /* 547 - text mode */
@ -634,6 +601,7 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
}
indexchaine = indexchaine + liste[0][i];
}
assert(mclength > 0); /* Suppress clang-analyzer-core.uninitialized.Assign warning */
if (debug) {
printf("\nCompressed data stream:\n");
@ -645,18 +613,16 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
/* 752 - Now take care of the number of CWs per row */
if (symbol->option_1 < 0) {
symbol->option_1 = 6;
if (mclength <= 863) {
symbol->option_1 = 5;
}
if (mclength <= 320) {
symbol->option_1 = 4;
}
if (mclength <= 160) {
symbol->option_1 = 3;
}
if (mclength <= 40) {
symbol->option_1 = 2;
} else if (mclength <= 160) {
symbol->option_1 = 3;
} else if (mclength <= 320) {
symbol->option_1 = 4;
} else if (mclength <= 863) {
symbol->option_1 = 5;
} else {
symbol->option_1 = 6;
}
}
k = 1;
@ -664,26 +630,25 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
k *= 2;
}
longueur = mclength;
if (symbol->option_2 > 30) {
symbol->option_2 = 30;
}
if (symbol->option_2 < 1) {
symbol->option_2 =(int)(0.5 + sqrt((longueur + k) / 3.0));
}
if (((longueur + k) / symbol->option_2) > 90) {
/* stop the symbol from becoming too high */
symbol->option_2 = symbol->option_2 + 1;
}
if (longueur + k > 928) {
/* Enforce maximum codeword limit */
strcpy(symbol->errtxt, "464: Input string too long");
return ZINT_ERROR_TOO_LONG;
}
if (symbol->option_2 > 30) {
symbol->option_2 = 30;
} else if (symbol->option_2 < 1) {
symbol->option_2 = (int) (0.5 + sqrt((longueur + k) / 3.0));
}
if (((longueur + k) / symbol->option_2) > 90) {
strcpy(symbol->errtxt, "465: Data too long for specified number of columns");
return ZINT_ERROR_TOO_LONG;
/* stop the symbol from becoming too high */
symbol->option_2 = symbol->option_2 + 1;
if (((longueur + k) / symbol->option_2) > 90) {
strcpy(symbol->errtxt, "465: Data too long for specified number of columns");
return ZINT_ERROR_TOO_LONG;
}
}
/* 781 - Padding calculation */
@ -732,15 +697,12 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
}
longueur = mclength;
for (loop = 0; loop < 520; loop++) {
mccorrection[loop] = 0;
}
for (i = 0; i < longueur; i++) {
total = (chainemc[i] + mccorrection[k - 1]) % 929;
for (j = k - 1; j > 0; j--) {
mccorrection[j] = (mccorrection[j - 1] + 929 - (total * coefrs[offset + j]) % 929) % 929;
}
mccorrection[0] = (929 - (total * coefrs[offset + j]) % 929) % 929;
mccorrection[0] = (929 - (total * coefrs[offset]) % 929) % 929;
}
/* we add these codes to the string */
@ -762,6 +724,7 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
#endif
symbol->rows = mclength / symbol->option_2;
assert(symbol->rows > 0); /* Suppress clang-analyzer-core.DivideZero warning */
/* 818 - The CW string is finished */
c1 = (symbol->rows - 1) / 3;
@ -770,6 +733,7 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
/* we now encode each row */
for (i = 0; i < symbol->rows; i++) {
int p;
for (j = 0; j < symbol->option_2; j++) {
dummy[j + 1] = chainemc[i * symbol->option_2 + j];
}
@ -791,23 +755,23 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
offset = 1858; /* cluster(6) */
break;
}
strcpy(pattern, "");
bin_append(0x1FEA8, 17, pattern); /* Row start */
p = bin_append_posn(0x1FEA8, 17, pattern, 0); /* Row start */
for (j = 0; j <= symbol->option_2; j++) {
bin_append(pdf_bitpattern[offset + dummy[j]], 16, pattern);
strcat(pattern, "0");
p = bin_append_posn(pdf_bitpattern[offset + dummy[j]], 16, pattern, p);
pattern[p++] = '0';
}
if (symbol->symbology != BARCODE_PDF417COMP) {
bin_append(pdf_bitpattern[offset + dummy[j]], 16, pattern);
strcat(pattern, "0");
bin_append(0x3FA29, 18, pattern); /* Row Stop */
p = bin_append_posn(pdf_bitpattern[offset + dummy[j]], 16, pattern, p);
pattern[p++] = '0';
p = bin_append_posn(0x3FA29, 18, pattern, p); /* Row Stop */
} else {
strcat(pattern, "1"); /* Compact PDF417 Stop pattern */
pattern[p++] = '1'; /* Compact PDF417 Stop pattern */
}
pattern[p] = '\0';
for (loop = 0; loop < (int)strlen(pattern); loop++) {
for (loop = 0; loop < p; loop++) {
if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
@ -831,7 +795,7 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
}
/* 345 */
INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) {
int codeerr, error_number;
error_number = 0;
@ -868,8 +832,8 @@ INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], const
}
/* like PDF417 only much smaller! */
INTERNAL int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length) {
int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset;
INTERNAL int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50] = {0}, offset;
int total, chainemc[PDF417_MAX_LEN], mclength, dummy[5], codeerr;
int liste[2][PDF417_MAX_LEN] = {{0}};
char pattern[580];
@ -894,13 +858,13 @@ INTERNAL int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], co
/* 463 */
do {
liste[1][indexliste] = mode;
while ((liste[1][indexliste] == mode) && (indexchaine < (int)length)) {
while ((liste[1][indexliste] == mode) && (indexchaine < length)) {
liste[0][indexliste]++;
indexchaine++;
mode = quelmode(chaine[indexchaine]);
}
indexliste++;
} while (indexchaine < (int)length);
} while (indexchaine < length);
/* 474 */
pdfsmooth(liste, &indexliste);
@ -1181,9 +1145,6 @@ INTERNAL int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], co
/* Reed-Solomon error correction */
longueur = mclength;
for (loop = 0; loop < 50; loop++) {
mccorrection[loop] = 0;
}
for (i = 0; i < longueur; i++) {
total = (chainemc[i] + mccorrection[k - 1]) % 929;
for (j = k - 1; j >= 0; j--) {