Performance improvements for linear encoding and raster output

- use fixed-length string tables (mostly) instead of (char *) pointer ones
   (saves ~40K)
 - re-use C128Table for CODABLOCKF and CODE16K
   (required removal of Stop character and extra CODE16K-only entry)
 - use pointer to destination and copy (memcpy/strcpy(), bin_append_posn())
   instead of concatenating (strcat()) (mostly)
 - replace last remaining bin_append()s with bin_append_posn();
   bin_append() removed
 - add length arg to toupper() and expand() (avoids strlen())
 - change is_sane() to use table-based flags (avoids an iteration)
 - rename lookup() to is_sane_lookup() and change to check and return posns
   and use in pointer to destination loops (avoids strcat()s)
 - remove special case PHARMA in expand() (dealt with in pharma())
 - make #define SILVER/CALCIUM/TECHNETIUM/KRSET etc static strings
 - replace strchr() -> posn()
 - CODE128: populate destination once in checksum loop; re-use and export
   some more routines (c128_set_a/b/c(), c128_put_in_set()) for sharing;
   prefix defines (SHIFTA -> C128_SHIFTA etc) and existing exported routines
 - use factor XOR toggle trick in checksum calcs (avoids branch)
 - raster.c: fill out single 1-pixel row and copy using new draw_bar_line(),
   copy_bar_line() routines; similarly in buffer_plot compare previous line &
   copy if same (same technique as used to improve non-half-integer scaling,
   significant performance increase, (c) codemonkey82);
   also done for PNG (BMP/GIF/PCX/TIFF not done)
 - raster/vector/output.c: shorten "output_" prefix -> "out_";
   sync vector to other raster changes to try to keep source files similar
 - 2of5.c: prefix "c25_"
JAPANPOST: return error if input data truncated (backward incompatible)
DAFT: max chars 50 -> 100
common.c: istwodigit() -> is_twodigit()
common.c/emf.c/output.c: use some further stripf()s (MSVC6 float variations)
library.c: new check_output_args() helper
zint.h: add BARCODE_LAST marker and use in library.c
QRCODE: remove a NOLINT (requires clang-tidy-13), one remaining
CMake: separate no-optimize from ZINT_DEBUG into new ZINT_NOOPT option
This commit is contained in:
gitlost 2021-10-20 23:05:30 +01:00
parent e8b59aa696
commit fab7435fac
72 changed files with 3501 additions and 2380 deletions

View file

@ -49,7 +49,7 @@
#include "large.h"
#include "reedsol.h"
#define RUBIDIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
#define RUBIDIUM_F (IS_NUM_F | IS_UPR_F | IS_SPC_F) /* RUBIDIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " */
// Allowed character values from Table 3
#define SET_F "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@ -57,8 +57,10 @@
#define SET_N "0123456789"
#define SET_S " "
static const char *postcode_format[6] = {
"FNFNLLNLS", "FFNNLLNLS", "FFNNNLLNL", "FFNFNLLNL", "FNNLLNLSS", "FNNNLLNLS"
static const char postcode_format[6][9] = {
{'F','N','F','N','L','L','N','L','S'}, {'F','F','N','N','L','L','N','L','S'},
{'F','F','N','N','N','L','L','N','L'}, {'F','F','N','F','N','L','L','N','L'},
{'F','N','N','L','L','N','L','S','S'}, {'F','N','N','N','L','L','N','L','S'}
};
// Data/Check Symbols from Table 5
@ -109,9 +111,7 @@ static int verify_character(char input, char type) {
static int verify_postcode(char *postcode, int type) {
int i;
char pattern[11];
strcpy(pattern, postcode_format[type - 1]);
const char *const pattern = postcode_format[type - 1];
for (i = 0; i < 9; i++) {
if (!(verify_character(postcode[i], pattern[i]))) {
@ -122,7 +122,7 @@ static int verify_postcode(char *postcode, int type) {
return 0;
}
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height);
INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height);
/* Royal Mail Mailmark */
INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
@ -135,7 +135,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
unsigned int item_id;
char postcode[10];
int postcode_type;
char pattern[10];
const char *pattern;
large_int destination_postcode;
large_int b;
large_int cdv;
@ -144,6 +144,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
unsigned char check[7];
unsigned int extender[27];
char bar[80];
char *d = bar;
int check_count;
int i, j, len;
rs_t rs;
@ -170,13 +171,13 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
length = 26;
}
to_upper((unsigned char *) local_source);
to_upper((unsigned char *) local_source, length);
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Producing Mailmark %s\n", local_source);
}
if (is_sane(RUBIDIUM, (unsigned char *) local_source, length) != 0) {
if (!is_sane(RUBIDIUM_F, (unsigned char *) local_source, length)) {
strcpy(symbol->errtxt, "581: Invalid character in data (alphanumerics and space only)");
return ZINT_ERROR_INVALID_DATA;
}
@ -285,7 +286,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
large_load_u64(&destination_postcode, 0);
if (postcode_type != 7) {
strcpy(pattern, postcode_format[postcode_type - 1]);
pattern = postcode_format[postcode_type - 1];
large_load_u64(&b, 0);
@ -440,45 +441,42 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
}
// Conversion from Extender Groups to Bar Identifiers
strcpy(bar, "");
for (i = 0; i < length; i++) {
for (j = 0; j < 3; j++) {
switch (extender[i] & 0x24) {
case 0x24:
strcat(bar, "F");
*d++ = 'F';
break;
case 0x20:
if (i % 2) {
strcat(bar, "D");
*d++ = 'D';
} else {
strcat(bar, "A");
*d++ = 'A';
}
break;
case 0x04:
if (i % 2) {
strcat(bar, "A");
*d++ = 'A';
} else {
strcat(bar, "D");
*d++ = 'D';
}
break;
default:
strcat(bar, "T");
*d++ = 'T';
break;
}
extender[i] = extender[i] << 1;
}
}
bar[(length * 3)] = '\0';
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Bar pattern: %s\n", bar);
printf("Bar pattern: %.*s\n", (int) (d - bar), bar);
}
/* Translate 4-state data pattern to symbol */
j = 0;
for (i = 0, len = (int) strlen(bar); i < len; i++) {
for (i = 0, len = d - bar; i < len; i++) {
if ((bar[i] == 'F') || (bar[i] == 'A')) {
set_module(symbol, 0, j);
}