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

@ -46,7 +46,7 @@
#include "emf.h"
/* Multiply truncating to 3 decimal places (avoids rounding differences on various platforms) */
#define mul3dpf(m, arg) (roundf(m * arg * 1000.0) / 1000.0f)
#define mul3dpf(m, arg) stripf(roundf(m * arg * 1000.0) / 1000.0f)
static int count_rectangles(struct zint_symbol *symbol) {
int rectangles = 0;
@ -453,9 +453,9 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
rectangle[this_rectangle].type = 0x0000002b; // EMR_RECTANGLE
rectangle[this_rectangle].size = 24;
rectangle[this_rectangle].box.top = (int32_t) rect->y;
rectangle[this_rectangle].box.bottom = (int32_t) (rect->y + rect->height);
rectangle[this_rectangle].box.bottom = (int32_t) stripf(rect->y + rect->height);
rectangle[this_rectangle].box.left = (int32_t) rect->x;
rectangle[this_rectangle].box.right = (int32_t) (rect->x + rect->width);
rectangle[this_rectangle].box.right = (int32_t) stripf(rect->x + rect->width);
this_rectangle++;
bytecount += 24;
recordcount++;
@ -475,10 +475,10 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
}
circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE
circle[this_circle].size = 24;
circle[this_circle].box.top = (int32_t) (circ->y - radius);
circle[this_circle].box.bottom = (int32_t) (circ->y + radius);
circle[this_circle].box.left = (int32_t) (circ->x - radius);
circle[this_circle].box.right = (int32_t) (circ->x + radius);
circle[this_circle].box.top = (int32_t) stripf(circ->y - radius);
circle[this_circle].box.bottom = (int32_t) stripf(circ->y + radius);
circle[this_circle].box.left = (int32_t) stripf(circ->x - radius);
circle[this_circle].box.right = (int32_t) stripf(circ->x + radius);
this_circle++;
bytecount += 24;
recordcount++;
@ -487,10 +487,10 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
float inner_radius = radius - circ->width;
circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE
circle[this_circle].size = 24;
circle[this_circle].box.top = (int32_t) (circ->y - inner_radius);
circle[this_circle].box.bottom = (int32_t) (circ->y + inner_radius);
circle[this_circle].box.left = (int32_t) (circ->x - inner_radius);
circle[this_circle].box.right = (int32_t) (circ->x + inner_radius);
circle[this_circle].box.top = (int32_t) stripf(circ->y - inner_radius);
circle[this_circle].box.bottom = (int32_t) stripf(circ->y + inner_radius);
circle[this_circle].box.left = (int32_t) stripf(circ->x - inner_radius);
circle[this_circle].box.right = (int32_t) stripf(circ->x + inner_radius);
this_circle++;
bytecount += 24;
recordcount++;
@ -516,18 +516,18 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
}
/* Note rotation done via world transform */
hexagon[this_hexagon].a_points_a.x = (int32_t) (hex->x);
hexagon[this_hexagon].a_points_a.y = (int32_t) (hex->y + radius);
hexagon[this_hexagon].a_points_b.x = (int32_t) (hex->x + half_sqrt3_radius);
hexagon[this_hexagon].a_points_b.y = (int32_t) (hex->y + half_radius);
hexagon[this_hexagon].a_points_c.x = (int32_t) (hex->x + half_sqrt3_radius);
hexagon[this_hexagon].a_points_c.y = (int32_t) (hex->y - half_radius);
hexagon[this_hexagon].a_points_d.x = (int32_t) (hex->x);
hexagon[this_hexagon].a_points_d.y = (int32_t) (hex->y - radius);
hexagon[this_hexagon].a_points_e.x = (int32_t) (hex->x - half_sqrt3_radius);
hexagon[this_hexagon].a_points_e.y = (int32_t) (hex->y - half_radius);
hexagon[this_hexagon].a_points_f.x = (int32_t) (hex->x - half_sqrt3_radius);
hexagon[this_hexagon].a_points_f.y = (int32_t) (hex->y + half_radius);
hexagon[this_hexagon].a_points_a.x = (int32_t) hex->x;
hexagon[this_hexagon].a_points_a.y = (int32_t) stripf(hex->y + radius);
hexagon[this_hexagon].a_points_b.x = (int32_t) stripf(hex->x + half_sqrt3_radius);
hexagon[this_hexagon].a_points_b.y = (int32_t) stripf(hex->y + half_radius);
hexagon[this_hexagon].a_points_c.x = (int32_t) stripf(hex->x + half_sqrt3_radius);
hexagon[this_hexagon].a_points_c.y = (int32_t) stripf(hex->y - half_radius);
hexagon[this_hexagon].a_points_d.x = (int32_t) hex->x;
hexagon[this_hexagon].a_points_d.y = (int32_t) stripf(hex->y - radius);
hexagon[this_hexagon].a_points_e.x = (int32_t) stripf(hex->x - half_sqrt3_radius);
hexagon[this_hexagon].a_points_e.y = (int32_t) stripf(hex->y - half_radius);
hexagon[this_hexagon].a_points_f.x = (int32_t) stripf(hex->x - half_sqrt3_radius);
hexagon[this_hexagon].a_points_f.y = (int32_t) stripf(hex->y + half_radius);
hexagon[this_hexagon].bounds.top = hexagon[this_hexagon].a_points_d.y;
hexagon[this_hexagon].bounds.bottom = hexagon[this_hexagon].a_points_a.y;