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

@ -42,8 +42,28 @@
#define TRUE 1
#endif
/* `is_sane()` flags */
#define IS_SPC_F 0x0001 /* Space */
#define IS_HSH_F 0x0002 /* Hash sign # */
#define IS_PLS_F 0x0004 /* Plus sign + */
#define IS_MNS_F 0x0008 /* Minus sign - */
#define IS_NUM_F 0x0010 /* Number 0-9 */
#define IS_UPO_F 0x0020 /* Uppercase letter, apart from A-F and X */
#define IS_UHX_F 0x0040 /* Uppercase hex A-F */
#define IS_UX__F 0x0080 /* Uppercase X */
#define IS_LWO_F 0x0100 /* Lowercase letter, apart from a-f and x */
#define IS_LHX_F 0x0200 /* Lowercase hex a-f */
#define IS_LX__F 0x0400 /* Lowercase x */
#define IS_C82_F 0x0800 /* CSET82 punctuation (apart from - and +) */
#define IS_SIL_F 0x1000 /* SILVER/TECHNETIUM punctuation .$/% (apart from space, - and +) */
#define IS_CLI_F 0x2000 /* CALCIUM INNER punctuation $:/. (apart from - and +) (Codabar) */
#define IS_ARS_F 0x4000 /* ARSENIC uppercase subset (VIN) */
#define IS_UPR_F (IS_UPO_F | IS_UHX_F | IS_UX__F) /* Uppercase letters */
#define IS_LWR_F (IS_LWO_F | IS_LHX_F | IS_LX__F) /* Lowercase letters */
/* The most commonly used set */
#define NEON "0123456789"
#define NEON_F IS_NUM_F /* NEON "0123456789" */
#include "zint.h"
#include "zintconfig.h"
@ -83,6 +103,14 @@
# define INTERNAL
#endif
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MINGW32__)
# define INTERNAL_DATA_EXTERN __attribute__ ((visibility ("hidden"))) extern
# define INTERNAL_DATA __attribute__ ((visibility ("hidden")))
#else
# define INTERNAL_DATA_EXTERN extern
# define INTERNAL_DATA
#endif
#ifdef ZINT_TEST
#define STATIC_UNLESS_ZINT_TEST INTERNAL
#else
@ -112,14 +140,14 @@ extern "C" {
INTERNAL int ctoi(const char source);
INTERNAL char itoc(const int source);
INTERNAL int to_int(const unsigned char source[], const int length);
INTERNAL void to_upper(unsigned char source[]);
INTERNAL void to_upper(unsigned char source[], const int length);
INTERNAL int chr_cnt(const unsigned char string[], const int length, const unsigned char c);
INTERNAL int is_sane(const char test_string[], const unsigned char source[], const int length);
INTERNAL void lookup(const char set_string[], const char *table[], const char data, char dest[]);
INTERNAL int is_sane(const unsigned int flg, const unsigned char source[], const int length);
INTERNAL int is_sane_lookup(const char test_string[], const int test_length, const unsigned char source[],
const int length, int *posns);
INTERNAL int posn(const char set_string[], const char data);
INTERNAL void bin_append(const int arg, const int length, char *binary);
INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn);
#ifndef COMMON_INLINE
@ -130,12 +158,14 @@ extern "C" {
const int colour);
#endif
INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
INTERNAL void expand(struct zint_symbol *symbol, const char data[]);
INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length);
INTERNAL int is_stackable(const int symbology);
INTERNAL int is_extendable(const int symbology);
INTERNAL int is_composite(const int symbology);
INTERNAL int istwodigits(const unsigned char source[], const int length, const int position);
INTERNAL int is_twodigits(const unsigned char source[], const int length, const int position);
INTERNAL unsigned int decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte);
INTERNAL int is_valid_utf8(const unsigned char source[], const int length);