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

@ -43,6 +43,10 @@
#include "gb2312.h"
#include "eci.h"
static const char EUROPIUM[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
static const char EUROPIUM_UPR[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
static const char EUROPIUM_LWR[] = "abcdefghijklmnopqrstuvwxyz ";
/* define_mode() stuff */
/* Bits multiplied by this for costs, so as to be whole integer divisible by 2 and 3 */
@ -68,7 +72,7 @@ static int in_numeral(const unsigned int gbdata[], const int length, const int i
i++) {
if (gbdata[i] >= '0' && gbdata[i] <= '9') {
digit_cnt++;
} else if (strchr(numeral_nondigits, gbdata[i])) {
} else if (posn(numeral_nondigits, (const char) gbdata[i]) != -1) {
if (nondigit) {
break;
}
@ -282,7 +286,7 @@ static void define_mode(char *mode, const unsigned int gbdata[], const int lengt
/* Get optimal mode for each code point by tracing backwards */
for (i = length - 1, cm_i = i * GM_NUM_MODES; i >= 0; i--, cm_i -= GM_NUM_MODES) {
j = strchr(mode_types, cur_mode) - mode_types;
j = posn(mode_types, cur_mode);
cur_mode = char_modes[cm_i + j];
mode[i] = cur_mode;
}
@ -308,7 +312,7 @@ static int add_shift_char(char binary[], int bp, int shifty, int debug) {
glyph = shifty;
} else {
for (i = 32; i < 64; i++) {
if (shift_set[i] == shifty) {
if (gm_shift_set[i] == shifty) {
glyph = i;
break;
}
@ -577,7 +581,7 @@ static int gm_encode(unsigned int gbdata[], const int length, char binary[], con
if ((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) {
numbuf[p] = gbdata[sp];
p++;
} else if (strchr(numeral_nondigits, gbdata[sp])) {
} else if (posn(numeral_nondigits, (const char) gbdata[sp]) != -1) {
if (ppos != -1) {
break;
}
@ -701,7 +705,7 @@ static int gm_encode(unsigned int gbdata[], const int length, char binary[], con
if (shift == 0) {
/* Upper Case character */
glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", (const char) gbdata[sp]);
glyph = posn(EUROPIUM_UPR, (const char) gbdata[sp]);
if (debug & ZINT_DEBUG_PRINT) {
printf("[%d] ", (int) glyph);
}
@ -726,7 +730,7 @@ static int gm_encode(unsigned int gbdata[], const int length, char binary[], con
if (shift == 0) {
/* Lower Case character */
glyph = posn("abcdefghijklmnopqrstuvwxyz ", (const char) gbdata[sp]);
glyph = posn(EUROPIUM_LWR, (const char) gbdata[sp]);
if (debug & ZINT_DEBUG_PRINT) {
printf("[%d] ", (int) glyph);
}