1
0
mirror of https://git.code.sf.net/p/zint/code synced 2025-12-21 20:07:06 +00:00

general: prefix all INTERNAL funcs/tables with zint_, except

those in "backend/common.h", which are prefixed by `z_` - makes
  symbol clashes more unlikely when zint is statically linked
  (ticket #337, props Ulrich Becker)
DOTCODE: fix padding allowance (10 -> 52 - probable max 35) to
  cover cases with large no. of columns requested and little data,
  to prevent `codeword_array` buffer overflow
AZTEC/CODEONE: some code fiddling
general_field: prefix defines with `GF_`, shorten static funcs
  prefix `general_field_` -> `gf_`
This commit is contained in:
gitlost
2025-08-26 23:48:00 +01:00
parent e18b047a45
commit 39380d6767
106 changed files with 4477 additions and 4360 deletions

View File

@@ -54,12 +54,12 @@
#define ZFONT_UPCEAN_TEXT 4 /* Helper flag to indicate dealing with EAN/UPC */
#ifndef ZINT_NO_PNG
INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int zint_png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
#endif /* ZINT_NO_PNG */
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int zint_bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int zint_gif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf);
static const char ultra_colour[] = "0CBMRYGKW";
@@ -93,12 +93,12 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
const size_t bm_bitmap_width = (size_t) symbol->bitmap_width * 3;
const size_t bm_bitmap_size = bm_bitmap_width * symbol->bitmap_height;
if (out_colour_get_rgb(symbol->fgcolour, &map[DEFAULT_INK][0], &map[DEFAULT_INK][1], &map[DEFAULT_INK][2],
if (zint_out_colour_get_rgb(symbol->fgcolour, &map[DEFAULT_INK][0], &map[DEFAULT_INK][1], &map[DEFAULT_INK][2],
&alpha[0])) {
plot_alpha = 1;
}
if (out_colour_get_rgb(symbol->bgcolour, &map[DEFAULT_PAPER][0], &map[DEFAULT_PAPER][1], &map[DEFAULT_PAPER][2],
&alpha[1])) {
if (zint_out_colour_get_rgb(symbol->bgcolour, &map[DEFAULT_PAPER][0], &map[DEFAULT_PAPER][1],
&map[DEFAULT_PAPER][2], &alpha[1])) {
plot_alpha = 1;
}
@@ -113,7 +113,7 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
}
if (!(symbol->bitmap = (unsigned char *) raster_malloc(bm_bitmap_size, 0 /*prev_size*/))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 661, "Insufficient memory for bitmap buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 661, "Insufficient memory for bitmap buffer");
}
#ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */
memset(symbol->bitmap, 0, bm_bitmap_size);
@@ -122,7 +122,7 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
if (plot_alpha) {
const size_t alpha_size = (size_t) symbol->bitmap_width * symbol->bitmap_height;
if (!(symbol->alphamap = (unsigned char *) raster_malloc(alpha_size, bm_bitmap_size))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 662, "Insufficient memory for alphamap buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 662, "Insufficient memory for alphamap buffer");
}
for (row = 0; row < symbol->bitmap_height; row++) {
size_t p = (size_t) symbol->bitmap_width * row;
@@ -183,7 +183,7 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image
if (rotate_angle) {
size_t image_size = (size_t) image_width * image_height;
if (!(rotated_pixbuf = (unsigned char *) raster_malloc((size_t) image_size, 0 /*prev_size*/))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 650, "Insufficient memory for pixel buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 650, "Insufficient memory for pixel buffer");
}
#ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */
memset(rotated_pixbuf, DEFAULT_PAPER, image_size);
@@ -244,7 +244,7 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image
break;
case OUT_PNG_FILE:
#ifndef ZINT_NO_PNG
error_number = png_pixel_plot(symbol, rotated_pixbuf);
error_number = zint_png_pixel_plot(symbol, rotated_pixbuf);
#else
error_number = ZINT_ERROR_INVALID_OPTION;
#endif
@@ -255,16 +255,16 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
case OUT_PCX_FILE:
error_number = pcx_pixel_plot(symbol, rotated_pixbuf);
error_number = zint_pcx_pixel_plot(symbol, rotated_pixbuf);
break;
case OUT_GIF_FILE:
error_number = gif_pixel_plot(symbol, rotated_pixbuf);
error_number = zint_gif_pixel_plot(symbol, rotated_pixbuf);
break;
case OUT_TIF_FILE:
error_number = tif_pixel_plot(symbol, rotated_pixbuf);
error_number = zint_tif_pixel_plot(symbol, rotated_pixbuf);
break;
default:
error_number = bmp_pixel_plot(symbol, rotated_pixbuf);
error_number = zint_bmp_pixel_plot(symbol, rotated_pixbuf);
break;
#if defined(__GNUC__) && !defined(__clang__) && defined(NDEBUG) && defined(ZINT_NO_PNG)
#pragma GCC diagnostic pop
@@ -460,7 +460,7 @@ static void draw_string(unsigned char *pixelbuf, const unsigned char input_strin
letter_width += letter_gap;
if (length == -1) {
length = (int) ustrlen(input_string);
length = (int) z_ustrlen(input_string);
}
if (textflags & ZFONT_HALIGN_LEFT) {
@@ -688,7 +688,7 @@ static void draw_bind_box(const struct zint_symbol *symbol, unsigned char *pixel
if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND | BARCODE_BIND_TOP))) {
const int no_extend = symbol->symbology == BARCODE_CODABLOCKF || symbol->symbology == BARCODE_HIBC_BLOCKF
|| symbol->symbology == BARCODE_DPD;
const int horz_outside = is_fixed_ratio(symbol->symbology);
const int horz_outside = z_is_fixed_ratio(symbol->symbology);
const int bwidth_si = symbol->border_width * si;
int ybind_top = yoffset_si - bwidth_si;
int ybind_bot = yoffset_si + symbol_height_si + dot_overspill_si;
@@ -757,8 +757,9 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang
}
scaler *= 10.0f;
out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset, &boffset,
NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, NULL /*qz_right_si*/);
zint_out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset,
&boffset, NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si,
NULL /*qz_right_si*/);
hex_width = (int) roundf(scaler); /* Short diameter, X in ISO/IEC 16023:2000 Figure 8 (same as W) */
hex_height = (int) roundf(scaler * two_div_sqrt3); /* Long diameter, V in Figure 8 */
@@ -786,14 +787,14 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang
image_size = (size_t) image_width * image_height;
if (!(pixelbuf = (unsigned char *) raster_malloc(image_size, 0 /*prev_size*/))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 655, "Insufficient memory for pixel buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 655, "Insufficient memory for pixel buffer");
}
memset(pixelbuf, DEFAULT_PAPER, image_size);
hex_size = (size_t) hex_width * hex_height;
if (!(scaled_hexagon = (unsigned char *) raster_malloc(hex_size, image_size))) {
free(pixelbuf);
return errtxt(ZINT_ERROR_MEMORY, symbol, 656, "Insufficient memory for pixel buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 656, "Insufficient memory for pixel buffer");
}
memset(scaled_hexagon, DEFAULT_PAPER, hex_size);
@@ -805,7 +806,7 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang
const int xposn_offset = (odd_row ? hex_width / 2 : 0) + xoffset_si - hx_start;
for (column = 0; column < symbol->width - odd_row; column++) {
const int xposn = column * hex_width + xposn_offset;
if (module_is_set(symbol, row, column)) {
if (z_module_is_set(symbol, row, column)) {
draw_hexagon(pixelbuf, image_width, image_height, scaled_hexagon, hex_width, hex_height, xposn,
yposn);
}
@@ -829,7 +830,7 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang
const float max_ratio = 1.177984f; /* 27.93 / 23.71 */
const float size_ratio = (float) hex_image_width / hex_image_height;
if (size_ratio < min_ratio || size_ratio > max_ratio) {
return errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 663, "Size not within the minimum/maximum ranges");
return z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 663, "Size not within the minimum/maximum ranges");
}
}
return error_number;
@@ -857,8 +858,9 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
dot_radius_s = (symbol->dot_size * scaler) / 2.0f;
dot_radius_si = (int) dot_radius_s;
out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset, &boffset,
NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, NULL /*qz_right_si*/);
zint_out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset,
&boffset, NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si,
NULL /*qz_right_si*/);
/* TODO: Revisit this overspill stuff, it's hacky */
if (symbol->dot_size < 1.0f) {
@@ -879,7 +881,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
/* Apply scale options by creating pixel buffer */
if (!(scaled_pixelbuf = (unsigned char *) raster_malloc(scale_size, 0 /*prev_size*/))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 657, "Insufficient memory for pixel buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 657, "Insufficient memory for pixel buffer");
}
memset(scaled_pixelbuf, DEFAULT_PAPER, scale_size);
@@ -887,7 +889,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
for (r = 0; r < symbol->rows; r++) {
int row_si = (int) (r * scaler + yoffset_si + dot_offset_s);
for (i = 0; i < symbol->width; i++) {
if (module_is_set(symbol, r, i)) {
if (z_module_is_set(symbol, r, i)) {
draw_circle(scaled_pixelbuf, scale_width, scale_height,
(int) (i * scaler + xoffset_si + dot_offset_s),
row_si, dot_radius_si, DEFAULT_INK);
@@ -911,7 +913,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
static void to_iso8859_1(const unsigned char source[], unsigned char preprocessed[]) {
int j, i, input_length;
input_length = (int) ustrlen(source);
input_length = (int) z_ustrlen(source);
j = 0;
i = 0;
@@ -985,29 +987,29 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
scaler = 0.5f;
}
/* If half-integer scaling, then set integer scaler `si` to avoid scaling at end */
half_int_scaling = isfintf(scaler * 2.0f);
half_int_scaling = z_isfintf(scaler * 2.0f);
if (half_int_scaling) {
si = (int) (scaler * 2.0f);
} else {
si = 2;
}
(void) out_large_bar_height(symbol, si /*(scale and round)*/, row_heights_si, &symbol_height_si);
(void) zint_out_large_bar_height(symbol, si /*(scale and round)*/, row_heights_si, &symbol_height_si);
main_width = symbol->width;
if (is_composite(symbol->symbology)) {
while (!module_is_set(symbol, symbol->rows - 1, comp_xoffset)) {
if (z_is_composite(symbol->symbology)) {
while (!z_module_is_set(symbol, symbol->rows - 1, comp_xoffset)) {
comp_xoffset++;
}
}
if (is_upcean(symbol->symbology)) {
upceanflag = out_process_upcean(symbol, comp_xoffset, &main_width, addon, &addon_len, &addon_gap);
if (z_is_upcean(symbol->symbology)) {
upceanflag = zint_out_process_upcean(symbol, comp_xoffset, &main_width, addon, &addon_len, &addon_gap);
}
hide_text = !symbol->show_hrt || symbol->text_length == 0 || scaler < 1.0f;
out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset,
zint_out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset,
NULL /*qz_right*/, si, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, &qz_right_si);
xoffset_comp_si = xoffset_si + comp_xoffset * si;
@@ -1044,7 +1046,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
image_size = (size_t) image_width * image_height;
if (!(pixelbuf = (unsigned char *) raster_malloc(image_size, 0 /*prev_size*/))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 658, "Insufficient memory for pixel buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 658, "Insufficient memory for pixel buffer");
}
memset(pixelbuf, DEFAULT_PAPER, image_size);
@@ -1056,9 +1058,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
const int row_height_si = row_heights_si[r];
for (i = 0; i < symbol->width; i += block_width) {
const int fill = module_colour_is_set(symbol, r, i);
const int fill = z_module_colour_is_set(symbol, r, i);
for (block_width = 1; (i + block_width < symbol->width)
&& module_colour_is_set(symbol, r, i + block_width) == fill; block_width++);
&& z_module_colour_is_set(symbol, r, i + block_width) == fill; block_width++);
if (fill) {
/* a colour block */
draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, yposn_si, image_width,
@@ -1075,9 +1077,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
int row_height_si = row_heights_si[r];
for (i = 0; i < symbol->width; i += block_width) {
const int fill = module_is_set(symbol, r, i);
const int fill = z_module_is_set(symbol, r, i);
for (block_width = 1; (i + block_width < symbol->width)
&& module_is_set(symbol, r, i + block_width) == fill; block_width++);
&& z_module_is_set(symbol, r, i + block_width) == fill; block_width++);
if ((r == (symbol->rows - 1)) && (i > main_width) && (addon_latch == 0)) {
int addon_row_height_si;
const int addon_row_adj_si = (int) ceilf((font_height + symbol->text_gap) * si);
@@ -1123,9 +1125,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
}
for (i = 0; i < symbol->width; i += block_width) {
const int fill = module_is_set(symbol, r, i);
const int fill = z_module_is_set(symbol, r, i);
for (block_width = 1; (i + block_width < symbol->width)
&& module_is_set(symbol, r, i + block_width) == fill; block_width++);
&& z_module_is_set(symbol, r, i + block_width) == fill; block_width++);
if (fill) {
/* a bar */
draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, yposn_si, image_width,
@@ -1160,9 +1162,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
} else if (upceanflag == 12) { /* UPC-A */
for (i = 0 + comp_xoffset; i < 11 + comp_xoffset; i += block_width) {
const int fill = module_is_set(symbol, symbol->rows - 1, i);
const int fill = z_module_is_set(symbol, symbol->rows - 1, i);
for (block_width = 1; (i + block_width < symbol->width)
&& module_is_set(symbol, symbol->rows - 1, i + block_width) == fill;
&& z_module_is_set(symbol, symbol->rows - 1, i + block_width) == fill;
block_width++);
if (fill) {
draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, guard_yoffset_si, image_width,
@@ -1172,9 +1174,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
draw_bar_line(pixelbuf, 46 * si + xoffset_comp_si, 1 * si, guard_yoffset_si, image_width, DEFAULT_INK);
draw_bar_line(pixelbuf, 48 * si + xoffset_comp_si, 1 * si, guard_yoffset_si, image_width, DEFAULT_INK);
for (i = 85 + comp_xoffset; i < 96 + comp_xoffset; i += block_width) {
const int fill = module_is_set(symbol, symbol->rows - 1, i);
const int fill = z_module_is_set(symbol, symbol->rows - 1, i);
for (block_width = 1; (i + block_width < symbol->width)
&& module_is_set(symbol, symbol->rows - 1, i + block_width) == fill;
&& z_module_is_set(symbol, symbol->rows - 1, i + block_width) == fill;
block_width++);
if (fill) {
draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, guard_yoffset_si, image_width,
@@ -1341,7 +1343,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
}
/* Separator binding for stacked barcodes */
if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && is_bindable(symbol->symbology)) {
if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && z_is_bindable(symbol->symbology)) {
int sep_xoffset_si = xoffset_si;
int sep_width_si = symbol->width * si;
int sep_height_si, sep_yoffset_si;
@@ -1369,26 +1371,26 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
if (!half_int_scaling) {
size_t prev_image_row;
unsigned char *scaled_pixelbuf;
const int scale_width = (int) stripf(image_width * scaler);
const int scale_height = (int) stripf(image_height * scaler);
const int scale_width = (int) z_stripf(image_width * scaler);
const int scale_height = (int) z_stripf(image_height * scaler);
/* Apply scale options by creating another pixel buffer */
if (!(scaled_pixelbuf = (unsigned char *) raster_malloc((size_t) scale_width * scale_height, image_size))) {
free(pixelbuf);
return errtxt(ZINT_ERROR_MEMORY, symbol, 659, "Insufficient memory for scaled pixel buffer");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 659, "Insufficient memory for scaled pixel buffer");
}
memset(scaled_pixelbuf, DEFAULT_PAPER, (size_t) scale_width * scale_height);
/* Interpolate */
for (r = 0; r < scale_height; r++) {
size_t scaled_row = (size_t) scale_width * r;
size_t image_row = (size_t) stripf(r / scaler) * image_width;
size_t image_row = (size_t) z_stripf(r / scaler) * image_width;
if (r && (image_row == prev_image_row
|| memcmp(pixelbuf + image_row, pixelbuf + prev_image_row, image_width) == 0)) {
memcpy(scaled_pixelbuf + scaled_row, scaled_pixelbuf + scaled_row - scale_width, scale_width);
} else {
for (i = 0; i < scale_width; i++) {
*(scaled_pixelbuf + scaled_row + i) = *(pixelbuf + image_row + (int) stripf(i / scaler));
*(scaled_pixelbuf + scaled_row + i) = *(pixelbuf + image_row + (int) z_stripf(i / scaler));
}
}
prev_image_row = image_row;
@@ -1410,21 +1412,21 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
return error_number ? error_number : warn_number;
}
INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type) {
INTERNAL int zint_plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type) {
int error;
#ifdef ZINT_NO_PNG
if (file_type == OUT_PNG_FILE) {
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 660, "PNG format disabled at compile time");
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 660, "PNG format disabled at compile time");
}
#endif /* ZINT_NO_PNG */
error = out_check_colour_options(symbol);
error = zint_out_check_colour_options(symbol);
if (error != 0) {
return error;
}
if (symbol->rows <= 0) {
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 664, "No rows");
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 664, "No rows");
}
if (symbol->symbology == BARCODE_MAXICODE) {