raster.c: need ceilf(large_bar_height * si) to avoid zero height rows;

also improve non-half-int interpolation performance
raster/vector.c: use new stripf() func in "common.c" to workaround gcc
  32-bit float calculation variations
gs1.c: allow dummy AI "[]" if GS1NOCHECK_MODE and has data (#204);
  also add note re TPX AI 235 and terminating FNC1
Remove trailing whitespace in various files
This commit is contained in:
gitlost 2021-09-26 23:55:16 +01:00
parent 9884875fd5
commit eb6e5daa2d
18 changed files with 1255 additions and 1081 deletions

View File

@ -22,6 +22,8 @@ Changes
- CLI: allow both e.g. '-height' and '--height' (getopt_long_only())
- UPC/EAN: add guard_descent
- Add output_options BARCODE_QUIET_ZONES and BARCODE_NO_QUIET_ZONES
- Allow dummy AI "[]" if GS1NOCHECK_MODE and has data (#204)
- raster.c: improve non-half-integer interpolation performance
Bugs
----
@ -31,8 +33,11 @@ Bugs
- Suppress some pedantic warnings, props codemonkey82 (#204)
- gs1.c: Allow 0-length AI data if GS1NOCHECK_MODE, props codemonkey82 (#204)
- raster.c: Need ceilf(symbol->height * si) to avoid heap-buffer-overflow;
also ceilf(large_bar_height * si);
also avoid distributive multiplication with floats to lessen chances of
platform variation (#204 ARM-Cortex crash)
- raster/vector.c: use new stripf() func to workaround gcc 32-bit
float variations
- raster.c: Don't allow for text if scale < 1.0

View File

@ -1,7 +1,7 @@
/* bmp.h - header structure for Windows bitmap files
libzint - the open source barcode library
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions

View File

@ -129,6 +129,18 @@ INTERNAL void lookup(const char set_string[], const char *table[], const char da
}
}
/* Returns the position of data in set_string */
INTERNAL int posn(const char set_string[], const char data) {
int i, n = (int) strlen(set_string);
for (i = 0; i < n; i++) {
if (data == set_string[i]) {
return i;
}
}
return -1;
}
/* Convert an integer value to a string representing its binary equivalent */
INTERNAL void bin_append(const int arg, const int length, char *binary) {
int bin_posn = (int) strlen(binary);
@ -155,18 +167,6 @@ INTERNAL int bin_append_posn(const int arg, const int length, char *binary, cons
return bin_posn + length;
}
/* Returns the position of data in set_string */
INTERNAL int posn(const char set_string[], const char data) {
int i, n = (int) strlen(set_string);
for (i = 0; i < n; i++) {
if (data == set_string[i]) {
return i;
}
}
return -1;
}
#ifndef COMMON_INLINE
/* Return true (1) if a module is dark/black, otherwise false (0) */
INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) {
@ -435,6 +435,11 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height,
return error_number;
}
/* Removes excess precision from floats - see https://stackoverflow.com/q/503436/664741 */
INTERNAL float stripf(const float arg) {
return *((volatile const float *) &arg);
}
/* Returns red component if any of ultra colour indexing "0CBMRYGKW" */
INTERNAL int colour_to_red(const int colour) {
int return_val = 0;

View File

@ -114,11 +114,14 @@ extern "C" {
INTERNAL int to_int(const unsigned char source[], const int length);
INTERNAL void to_upper(unsigned char source[]);
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 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);
INTERNAL int posn(const char set_string[], const char data);
#ifndef COMMON_INLINE
INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
INTERNAL void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
@ -128,17 +131,22 @@ extern "C" {
#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 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 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);
INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[],
int *length, const int disallow_4byte);
INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height,
const float max_height, const int set_errtxt);
INTERNAL float stripf(const float arg);
INTERNAL int colour_to_red(const int colour);
INTERNAL int colour_to_green(const int colour);
INTERNAL int colour_to_blue(const int colour);

View File

@ -1,7 +1,7 @@
/* emf.h - header structure for Microsoft EMF
libzint - the open source barcode library
Copyright (C) 2016-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2016-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions

View File

@ -1184,6 +1184,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
unsigned char reduced[]) {
int i, j, last_ai, ai_latch;
int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length;
int ai_no_data;
int ai_count;
int error_value = 0;
char obracket = symbol->input_mode & GS1PARENS_MODE ? '(' : '[';
@ -1231,6 +1232,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
min_ai_length = 5;
j = 0;
ai_latch = 0;
ai_no_data = 0;
for (i = 0; i < src_len; i++) {
ai_length += j;
if (((j == 1) && (source[i] != cbracket)) && ((source[i] < '0') || (source[i] > '9'))) {
@ -1247,6 +1249,9 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
}
j = 0;
ai_length = 0;
if (i + 1 == src_len || source[i + 1] == obracket) { /* Check if no data */
ai_no_data = 1;
}
}
if (bracket_level > max_bracket_level) {
max_bracket_level = bracket_level;
@ -1276,10 +1281,14 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
}
if (min_ai_length <= 1) {
/* Allow too short AI if GS1NOCHECK_MODE and AI is zero-length and all AIs have some data
- permits dummy "[]" workaround for ticket #204 data with no valid AI */
if (!(symbol->input_mode & GS1NOCHECK_MODE) || min_ai_length == 1 || ai_no_data) {
/* AI is too short */
strcpy(symbol->errtxt, "256: Invalid AI in input data (AI too short)");
return ZINT_ERROR_INVALID_DATA;
}
}
if (ai_latch == 1) {
/* Non-numeric data in AI */
@ -1360,7 +1369,9 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
if (
((last_ai >= 0) && (last_ai <= 4))
|| ((last_ai >= 11) && (last_ai <= 20))
|| (last_ai == 23) /* legacy support */
/* NOTE: as noted by Terry Burton the following complies with ISO/IEC 24724:2011 Table D.1,
but clashes with TPX AI [235], introduced May 2019; awaiting feedback from GS1 */
|| (last_ai == 23) /* legacy support */ /* TODO: probably remove */
|| ((last_ai >= 31) && (last_ai <= 36))
|| (last_ai == 41)
) {

View File

@ -267,6 +267,7 @@ static void draw_bar(unsigned char *pixelbuf, const int xpos, const int xlen, co
const int image_width, const int image_height, const char fill) {
int y;
const int ye = ypos + ylen > image_height ? image_height : ypos + ylen; /* Defensive, should never happen */
assert(ypos + ylen <= image_height); // Trigger assert if happens
for (y = ypos; y < ye; y++) {
memset(pixelbuf + ((size_t) image_width * y) + xpos, fill, xlen);
@ -962,7 +963,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
for (r = 0; r < symbol->rows; r++) {
int yposn_si = yposn * si;
float row_height = symbol->row_height[r] ? symbol->row_height[r] : large_bar_height;
int row_height_si = row_height * si;
int row_height_si = (int) ceilf(row_height * si);
i = 0;
@ -1264,9 +1265,10 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
image_width, image_height, si);
if (!half_int_scaling) {
size_t prev_image_row;
unsigned char *scaled_pixelbuf;
int scale_width = (int) (image_width * scaler);
int scale_height = (int) (image_height * scaler);
int scale_width = (int) stripf(image_width * scaler);
int scale_height = (int) stripf(image_height * scaler);
/* Apply scale options by creating another pixel buffer */
if (!(scaled_pixelbuf = (unsigned char *) malloc((size_t) scale_width * scale_height))) {
@ -1276,13 +1278,20 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
}
memset(scaled_pixelbuf, DEFAULT_PAPER, (size_t) scale_width * scale_height);
/* Interpolate */
for (r = 0; r < scale_height; r++) {
int scaled_row = r * scale_width;
int image_row = ((int) (r / scaler)) * image_width;
size_t scaled_row = r * scale_width;
size_t image_row = (size_t) stripf(r / scaler) * image_width;
if (image_row && (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) (i / scaler));
*(scaled_pixelbuf + scaled_row + i) = *(pixelbuf + image_row + (int) stripf(i / scaler));
}
}
prev_image_row = image_row;
}
error_number = save_raster_image_to_file(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle,
file_type);

View File

@ -972,7 +972,8 @@ typedef struct {
static const Summary16 jisx0208_uni2indx_page00[16] = {
/* 0x0000 */
{ 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x0000 },
{ 0, 0x0000 }, { 6843, 0x1000 }, { 0, 0x0000 }, { 0, 0x0000 }, /* ZINT: Patched reverse solidus (backslash) mapping U+005C to 0x815F */
/* ZINT: Patched reverse solidus (backslash) mapping U+005C to 0x815F */
{ 0, 0x0000 }, { 6843, 0x1000 }, { 0, 0x0000 }, { 0, 0x0000 },
{ 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x118c }, { 5, 0x0053 },
{ 9, 0x0000 }, { 9, 0x0080 }, { 10, 0x0000 }, { 10, 0x0080 },
};

File diff suppressed because it is too large Load Diff

View File

@ -927,6 +927,7 @@ static void test_scale(int index, int debug) {
int option_2;
int border_width;
int output_options;
float height;
float scale;
char *data;
char *composite;
@ -944,32 +945,40 @@ static void test_scale(int index, int debug) {
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_PDF417, -1, -1, -1, 0, "1", "", 0, 18, 6, 103, 206, 36, 0, 36, 170, 14 }, // With no scaling
/* 1*/ { BARCODE_PDF417, -1, -1, -1, 0.6, "1", "", 0, 18, 6, 103, 206 * 0.6, 36 * 0.6, 0 /*set_row*/, 36 * 0.6, 170 * 0.6 + 1, 14 * 0.6 }, // +1 set_col due to some scaling inversion difference
/* 2*/ { BARCODE_PDF417, -1, -1, -1, 1.2, "1", "", 0, 18, 6, 103, 206 * 1.2, 36 * 1.2, 0 /*set_row*/, 36 * 1.2, 170 * 1.2 + 1, 14 * 1.2 }, // +1 set_col due to some scaling inversion difference
/* 3*/ { BARCODE_PDF417, -1, -1, -1, 0.5, "1", "", 0, 18, 6, 103, 206 * 0.5, 36 * 0.5, 0 /*set_row*/, 36 * 0.5, 170 * 0.5, 14 * 0.5 },
/* 4*/ { BARCODE_PDF417, -1, -1, -1, 1.0, "1", "", 0, 18, 6, 103, 206 * 1.0, 36 * 1.0, 0 /*set_row*/, 36 * 1.0, 170 * 1.0, 14 * 1.0 },
/* 5*/ { BARCODE_PDF417, -1, -1, -1, 1.5, "1", "", 0, 18, 6, 103, 206 * 1.5, 36 * 1.5, 0 /*set_row*/, 36 * 1.5, 170 * 1.5, 14 * 1.5 },
/* 6*/ { BARCODE_PDF417, -1, -1, -1, 2.0, "1", "", 0, 18, 6, 103, 206 * 2.0, 36 * 2.0, 0 /*set_row*/, 36 * 2.0, 170 * 2.0, 14 * 2.0 },
/* 7*/ { BARCODE_PDF417, -1, -1, -1, 2.5, "1", "", 0, 18, 6, 103, 206 * 2.5, 36 * 2.5, 0 /*set_row*/, 36 * 2.5, 170 * 2.5, 14 * 2.5 },
/* 8*/ { BARCODE_PDF417, -1, -1, -1, 3.0, "1", "", 0, 18, 6, 103, 206 * 3.0, 36 * 3.0, 0 /*set_row*/, 36 * 3.0, 170 * 3.0, 14 * 3.0 },
/* 9*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, "1", "", 0, 18, 6, 103, 218, 48, 0 /*set_row*/, 48, 176, 14 }, // With no scaling
/* 10*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0.6, "1", "", 0, 18, 6, 103, 218 * 0.6, 48 * 0.6, 0 /*set_row*/, 48 * 0.6, 176 * 0.6 + 1, 14 * 0.6 }, // +1 set_col due to some scaling inversion difference
/* 11*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 1.6, "1", "", 0, 18, 6, 103, 218 * 1.6, 48 * 1.6, 0 /*set_row*/, 48 * 1.6, 176 * 1.6 + 1, 14 * 1.6 }, // +1 set_col due to some scaling inversion difference
/* 12*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 1.5, "1", "", 0, 18, 6, 103, 218 * 1.5, 48 * 1.5, 0 /*set_row*/, 48 * 1.5, 176 * 1.5, 14 * 1.5 },
/* 13*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 2.5, "1", "", 0, 18, 6, 103, 218 * 2.5, 48 * 2.5, 0 /*set_row*/, 48 * 2.5, 176 * 2.5, 14 * 2.5 },
/* 14*/ { BARCODE_PDF417, -1, 3, OUT_BUFFER_INTERMEDIATE, 1.3, "1", "", 0, 18, 6, 103, 206 * 1.3, 36 * 1.3, 0 /*set_row*/, 36 * 1.3, 170 * 1.3 + 1, 14 * 1.3 }, // +1 set_col due to some scaling inversion difference
/* 15*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 0, "123456789012", "", 0, 50, 1, 79, 158, 116, 104 /*set_row*/, 114, 20, 2 }, // With no scaling
/* 16*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 1.5, "123456789012", "", 0, 50, 1, 79, 158 * 1.5, 116 * 1.5, 104 * 1.5 /*set_row*/, 114 * 1.5, 20 * 1.5, 1 * 1.5 },
/* 17*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 2.0, "123456789012", "", 0, 50, 1, 79, 158 * 2.0, 116 * 2.0, 104 * 2.0 /*set_row*/, 114 * 2.0, 20 * 2.0, 1 * 2.0 },
/* 18*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 3.5, "123456789012", "", 0, 50, 1, 79, 158 * 3.5, 116 * 3.5, 104 * 3.5 /*set_row*/, 114 * 3.5, 20 * 3.5, 1 * 3.5 },
/* 19*/ { BARCODE_UPCA, -1, -1, -1, 0, "12345678904", "", 0, 50, 1, 95, 226, 116, 104 /*set_row*/, 114, 5, 2 }, // With no scaling
/* 20*/ { BARCODE_UPCA, -1, -1, -1, 2.5, "12345678904", "", 0, 50, 1, 95, 226 * 2.5, 116 * 2.5, 104 * 2.5 /*set_row*/, 114 * 2.5, 5 * 2.5, 2 * 2.5 },
/* 21*/ { BARCODE_UPCA, -1, -1, -1, 4.5, "12345678904", "", 0, 50, 1, 95, 226 * 4.5, 116 * 4.5, 104 * 4.5 /*set_row*/, 114 * 4.5, 5 * 4.5, 2 * 4.5 },
/* 22*/ { BARCODE_UPCE_CC, -1, -1, -1, 0, "1234567", "[17]010615[10]A123456\"", 0, 50, 10, 55, 142, 116, 104 /*set_row*/, 115, 11, 2 }, // With no scaling
/* 23*/ { BARCODE_UPCE_CC, -1, -1, -1, 2.0, "1234567", "[17]010615[10]A123456\"", 0, 50, 10, 55, 142 * 2, 116 * 2, 104 * 2 + 1 /*set_row*/, 115 * 2, 11 * 2, 2 * 2 }, // +1 set_row
/* 24*/ { BARCODE_MAXICODE, -1, -1, -1, 0, "1234567890", "", 0, 165, 33, 30, 299, 298, 3 /*set_row*/, 7, 10, 9 }, // With no scaling
/* 25*/ { BARCODE_MAXICODE, -1, -1, -1, 0.1, "1234567890", "", ZINT_WARN_NONCOMPLIANT, 165, 33, 30, 60, 65, 0 /*set_row*/, 1, 3, 1 },
/* 0*/ { BARCODE_PDF417, -1, -1, -1, 0, 0, "1", "", 0, 18, 6, 103, 206, 36, 0, 36, 170, 14 }, // With no scaling
/* 1*/ { BARCODE_PDF417, -1, -1, -1, 0, 0.6, "1", "", 0, 18, 6, 103, 206 * 0.6, 36 * 0.6, 0 /*set_row*/, 36 * 0.6, 170 * 0.6 + 1, 14 * 0.6 }, // +1 set_col due to some scaling inversion difference
/* 2*/ { BARCODE_PDF417, -1, -1, -1, 0, 1.2, "1", "", 0, 18, 6, 103, 206 * 1.2, 36 * 1.2, 0 /*set_row*/, 36 * 1.2, 170 * 1.2 + 1, 14 * 1.2 }, // +1 set_col due to some scaling inversion difference
/* 3*/ { BARCODE_PDF417, -1, -1, -1, 0, 0.5, "1", "", 0, 18, 6, 103, 206 * 0.5, 36 * 0.5, 0 /*set_row*/, 36 * 0.5, 170 * 0.5, 14 * 0.5 },
/* 4*/ { BARCODE_PDF417, -1, -1, -1, 0, 1.0, "1", "", 0, 18, 6, 103, 206 * 1.0, 36 * 1.0, 0 /*set_row*/, 36 * 1.0, 170 * 1.0, 14 * 1.0 },
/* 5*/ { BARCODE_PDF417, -1, -1, -1, 0, 1.5, "1", "", 0, 18, 6, 103, 206 * 1.5, 36 * 1.5, 0 /*set_row*/, 36 * 1.5, 170 * 1.5, 14 * 1.5 },
/* 6*/ { BARCODE_PDF417, -1, -1, -1, 0, 2.0, "1", "", 0, 18, 6, 103, 206 * 2.0, 36 * 2.0, 0 /*set_row*/, 36 * 2.0, 170 * 2.0, 14 * 2.0 },
/* 7*/ { BARCODE_PDF417, -1, -1, -1, 0, 2.5, "1", "", 0, 18, 6, 103, 206 * 2.5, 36 * 2.5, 0 /*set_row*/, 36 * 2.5, 170 * 2.5, 14 * 2.5 },
/* 8*/ { BARCODE_PDF417, -1, -1, -1, 0, 3.0, "1", "", 0, 18, 6, 103, 206 * 3.0, 36 * 3.0, 0 /*set_row*/, 36 * 3.0, 170 * 3.0, 14 * 3.0 },
/* 9*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, 0, "1", "", 0, 18, 6, 103, 218, 48, 0 /*set_row*/, 48, 176, 14 }, // With no scaling
/* 10*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, 0.6, "1", "", 0, 18, 6, 103, 218 * 0.6, 48 * 0.6, 0 /*set_row*/, 48 * 0.6, 176 * 0.6 + 1, 14 * 0.6 }, // +1 set_col due to some scaling inversion difference
/* 11*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, 1.6, "1", "", 0, 18, 6, 103, 218 * 1.6, 48 * 1.6, 0 /*set_row*/, 48 * 1.6, 176 * 1.6 + 1, 14 * 1.6 }, // +1 set_col due to some scaling inversion difference
/* 12*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, 1.5, "1", "", 0, 18, 6, 103, 218 * 1.5, 48 * 1.5, 0 /*set_row*/, 48 * 1.5, 176 * 1.5, 14 * 1.5 },
/* 13*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, 2.5, "1", "", 0, 18, 6, 103, 218 * 2.5, 48 * 2.5, 0 /*set_row*/, 48 * 2.5, 176 * 2.5, 14 * 2.5 },
/* 14*/ { BARCODE_PDF417, -1, 3, OUT_BUFFER_INTERMEDIATE, 0, 1.3, "1", "", 0, 18, 6, 103, 206 * 1.3, 36 * 1.3, 0 /*set_row*/, 36 * 1.3, 170 * 1.3, 14 * 1.3 },
/* 15*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 0, 0, "123456789012", "", 0, 50, 1, 79, 158, 116, 104 /*set_row*/, 114, 20, 2 }, // With no scaling
/* 16*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 0, 1.5, "123456789012", "", 0, 50, 1, 79, 158 * 1.5, 116 * 1.5, 104 * 1.5 /*set_row*/, 114 * 1.5, 20 * 1.5, 1 * 1.5 },
/* 17*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 0, 2.0, "123456789012", "", 0, 50, 1, 79, 158 * 2.0, 116 * 2.0, 104 * 2.0 /*set_row*/, 114 * 2.0, 20 * 2.0, 1 * 2.0 },
/* 18*/ { BARCODE_DBAR_LTD, -1, -1, BOLD_TEXT, 0, 3.5, "123456789012", "", 0, 50, 1, 79, 158 * 3.5, 116 * 3.5, 104 * 3.5 /*set_row*/, 114 * 3.5, 20 * 3.5, 1 * 3.5 },
/* 19*/ { BARCODE_UPCA, -1, -1, -1, 0, 0, "12345678904", "", 0, 50, 1, 95, 226, 116, 104 /*set_row*/, 114, 5, 2 }, // With no scaling
/* 20*/ { BARCODE_UPCA, -1, -1, -1, 0, 2.5, "12345678904", "", 0, 50, 1, 95, 226 * 2.5, 116 * 2.5, 104 * 2.5 /*set_row*/, 114 * 2.5, 5 * 2.5, 2 * 2.5 },
/* 21*/ { BARCODE_UPCA, -1, -1, -1, 0, 4.5, "12345678904", "", 0, 50, 1, 95, 226 * 4.5, 116 * 4.5, 104 * 4.5 /*set_row*/, 114 * 4.5, 5 * 4.5, 2 * 4.5 },
/* 22*/ { BARCODE_UPCE_CC, -1, -1, -1, 0, 0, "1234567", "[17]010615[10]A123456\"", 0, 50, 10, 55, 142, 116, 104 /*set_row*/, 115, 11, 2 }, // With no scaling
/* 23*/ { BARCODE_UPCE_CC, -1, -1, -1, 0, 2.0, "1234567", "[17]010615[10]A123456\"", 0, 50, 10, 55, 142 * 2, 116 * 2, 104 * 2 + 1 /*set_row*/, 115 * 2, 11 * 2, 2 * 2 }, // +1 set_row
/* 24*/ { BARCODE_MAXICODE, -1, -1, -1, 0, 0, "1234567890", "", 0, 165, 33, 30, 299, 298, 3 /*set_row*/, 7, 10, 9 }, // With no scaling
/* 25*/ { BARCODE_MAXICODE, -1, -1, -1, 0, 0.1, "1234567890", "", ZINT_WARN_NONCOMPLIANT, 165, 33, 30, 60, 65, 0 /*set_row*/, 1, 3, 1 },
/* 26*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, 0, 0, "12345", "", 0, 12, 2, 63, 146, 30, 3 /*set_row*/, 27, 10, 2 }, // With no scaling
/* 27*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, 0, 0.1, "12345", "", 0, 12, 2, 63, 146 * 0.5, 30 * 0.5 - 1, 3 * 0.5 /*set_row*/, 27 * 0.5, 10 * 0.5, 2 * 0.5 }, // -1 height due to yoffset/boffset flooring
/* 28*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, 0, 0.9, "12345", "", 0, 12, 2, 63, 146 * 0.9, 30 * 0.9, 3 * 0.9 + 1 /*set_row*/, 27 * 0.9, 10 * 0.9, 2 * 0.9 + 1 }, // +1's due to interpolation
/* 29*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, 0, 2.3, "12345", "", 0, 12, 2, 63, 146 * 2.3, 30 * 2.3, 3 * 2.3 + 1 /*set_row*/, 27 * 2.3 - 1, 10 * 2.3, 2 * 2.3 + 1 }, // -1/+1's due to interpolation
/* 30*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, 0, 3.1, "12345", "", 0, 12, 2, 63, 146 * 3.1, 30 * 3.1, 3 * 3.1 + 1 /*set_row*/, 27 * 3.1, 10 * 3.1, 2 * 3.2 + 1 }, // +1's due to interpolation
/* 31*/ { BARCODE_ITF14, -1, 4, BARCODE_BIND, 61.8, 0, "12345", "", 0, 62, 1, 135, 310, 156, 8 /*set_row*/, 132, 20, 2 }, // With no scaling
/* 32*/ { BARCODE_ITF14, -1, 4, BARCODE_BIND, 61.8, 2, "12345", "", 0, 61.75, 1, 135, 310 * 2, 156 * 2 - 1, 8 * 2 /*set_row*/, 132 * 2 - 1, 20 * 2, 2 * 2 }, // -1's due to height rounding
/* 33*/ { BARCODE_ITF14, -1, 4, BARCODE_BIND, 61.8, 2.1, "12345", "", 0, 62, 1, 135, 310 * 2.1, 156 * 2.1, 8 * 2.1 /*set_row*/, 132 * 2.1, 20 * 2.1, 2 * 2.1 },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
@ -991,6 +1000,9 @@ static void test_scale(int index, int debug) {
if (data[i].border_width != -1) {
symbol->border_width = data[i].border_width;
}
if (data[i].height) {
symbol->height = data[i].height;
}
if (data[i].scale) {
symbol->scale = data[i].scale;
}
@ -1023,7 +1035,7 @@ static void test_scale(int index, int debug) {
assert_nonzero(symbol->bitmap_height >= data[i].expected_set_rows, "i:%d (%d) symbol->bitmap_height %d < expected_set_rows %d\n",
i, data[i].symbology, symbol->bitmap_height, data[i].expected_set_rows);
assert_nonzero(data[i].expected_set_rows > data[i].expected_set_row, "i:%d (%d) expected_set_rows %d < expected_set_row %d\n",
assert_nonzero(data[i].expected_set_rows > data[i].expected_set_row, "i:%d (%d) expected_set_rows %d <= expected_set_row %d\n",
i, data[i].symbology, data[i].expected_set_rows, data[i].expected_set_row);
for (row = data[i].expected_set_row; row < data[i].expected_set_rows; row++) {
int bits_set = 0;
@ -2196,6 +2208,95 @@ static void test_height(int index, int generate, int debug) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator for scaling
static void test_perf_scale(int index, int debug) {
struct item {
int symbology;
int input_mode;
int border_width;
int output_options;
int option_1;
int option_2;
float height;
float scale;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
struct item data[] = {
/* 0*/ { BARCODE_PDF417, -1, -1, -1, -1, -1, 0, 1.3,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
0, 40, 307, "960 chars, text/numeric" },
/* 1*/ { BARCODE_POSTNET, -1, -1, BARCODE_QUIET_ZONES, -1, -1, 0, 1.1, "12345", 0, 2, 63, "" },
/* 2*/ { BARCODE_ITF14, -1, 4, BARCODE_BIND, -1, -1, 61.8, 3.1, "12345", 0, 1, 135, "" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
for (i = 0; i < data_size; i++) {
int j;
if (index != -1 && i != index) continue;
diff_encode = diff_buffer = 0;
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug);
if (data[i].height) {
symbol->height = data[i].height;
}
if (data[i].scale) {
symbol->scale = data[i].scale;
}
start = clock();
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
@ -2212,6 +2313,7 @@ int main(int argc, char *argv[]) {
{ "test_quiet_zones", test_quiet_zones, 1, 0, 1 },
{ "test_buffer_plot", test_buffer_plot, 1, 1, 1 },
{ "test_height", test_height, 1, 1, 1 },
{ "test_perf_scale", test_perf_scale, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -39,17 +39,17 @@ static struct zint_vector_rect *find_rect(struct zint_symbol *symbol, float x, f
}
for (rect = symbol->vector->rectangles; rect != NULL; rect = rect->next) {
//printf("x %.8g, y %.8g, width %.8g, height %.8g\n", rect->x, rect->y, rect->width, rect->height);
if (rect->x == x && rect->y == y) {
if (rect->x == stripf(x) && rect->y == stripf(y)) {
if (height && width) {
if (rect->height == height && rect->width == width) {
if (rect->height == stripf(height) && rect->width == stripf(width)) {
break;
}
} else if (height) {
if (rect->height == height) {
if (rect->height == stripf(height)) {
break;
}
} else if (width) {
if (rect->width == width) {
if (rect->width == stripf(width)) {
break;
}
} else {
@ -69,9 +69,9 @@ static struct zint_vector_circle *find_circle(struct zint_symbol *symbol, float
}
for (circle = symbol->vector->circles; circle != NULL; circle = circle->next) {
//printf("x %.8g, y %.8g, diamter %.8g\n", circle->x, circle->y, circle->diameter);
if (circle->x == x && circle->y == y) {
if (circle->x == stripf(x) && circle->y == stripf(y)) {
if (diameter) {
if (circle->diameter == diameter) {
if (circle->diameter == stripf(diameter)) {
break;
}
} else {

View File

@ -229,41 +229,41 @@ static void vector_scale(struct zint_symbol *symbol, const int file_type) {
scale *= 20;
}
symbol->vector->width *= scale;
symbol->vector->height *= scale;
symbol->vector->width = stripf(symbol->vector->width * scale);
symbol->vector->height = stripf(symbol->vector->height * scale);
rect = symbol->vector->rectangles;
while (rect) {
rect->x *= scale;
rect->y *= scale;
rect->height *= scale;
rect->width *= scale;
rect->x = stripf(rect->x * scale);
rect->y = stripf(rect->y * scale);
rect->height = stripf(rect->height * scale);
rect->width = stripf(rect->width * scale);
rect = rect->next;
}
hex = symbol->vector->hexagons;
while (hex) {
hex->x *= scale;
hex->y *= scale;
hex->diameter *= scale;
hex->x = stripf(hex->x * scale);
hex->y = stripf(hex->y * scale);
hex->diameter = stripf(hex->diameter * scale);
hex = hex->next;
}
circle = symbol->vector->circles;
while (circle) {
circle->x *= scale;
circle->y *= scale;
circle->diameter *= scale;
circle->width *= scale;
circle->x = stripf(circle->x * scale);
circle->y = stripf(circle->y * scale);
circle->diameter = stripf(circle->diameter * scale);
circle->width = stripf(circle->width * scale);
circle = circle->next;
}
string = symbol->vector->strings;
while (string) {
string->x *= scale;
string->y *= scale;
string->width *= scale;
string->fsize *= scale;
string->x = stripf(string->x * scale);
string->y = stripf(string->y * scale);
string->width = stripf(string->width * scale);
string->fsize = stripf(string->fsize * scale);
string = string->next;
}
}
@ -285,18 +285,18 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
while (rect) {
if (rotate_angle == 90) {
temp = rect->x;
rect->x = symbol->vector->height - (rect->y + rect->height);
rect->x = stripf(symbol->vector->height - (rect->y + rect->height));
rect->y = temp;
temp = rect->width;
rect->width = rect->height;
rect->height = temp;
} else if (rotate_angle == 180) {
rect->x = symbol->vector->width - (rect->x + rect->width);
rect->y = symbol->vector->height - (rect->y + rect->height);
rect->x = stripf(symbol->vector->width - (rect->x + rect->width));
rect->y = stripf(symbol->vector->height - (rect->y + rect->height));
} else if (rotate_angle == 270) {
temp = rect->x;
rect->x = rect->y;
rect->y = symbol->vector->width - (temp + rect->width);
rect->y = stripf(symbol->vector->width - (temp + rect->width));
temp = rect->width;
rect->width = rect->height;
rect->height = temp;
@ -308,17 +308,17 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
while (hex) {
if (rotate_angle == 90) {
temp = hex->x;
hex->x = symbol->vector->height - hex->y;
hex->x = stripf(symbol->vector->height - hex->y);
hex->y = temp;
hex->rotation = 90;
} else if (rotate_angle == 180) {
hex->x = symbol->vector->width - hex->x;
hex->y = symbol->vector->height - hex->y;
hex->x = stripf(symbol->vector->width - hex->x);
hex->y = stripf(symbol->vector->height - hex->y);
hex->rotation = 180;
} else if (rotate_angle == 270) {
temp = hex->x;
hex->x = hex->y;
hex->y = symbol->vector->width - temp;
hex->y = stripf(symbol->vector->width - temp);
hex->rotation = 270;
}
hex = hex->next;
@ -328,15 +328,15 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
while (circle) {
if (rotate_angle == 90) {
temp = circle->x;
circle->x = symbol->vector->height - circle->y;
circle->x = stripf(symbol->vector->height - circle->y);
circle->y = temp;
} else if (rotate_angle == 180) {
circle->x = symbol->vector->width - circle->x;
circle->y = symbol->vector->height - circle->y;
circle->x = stripf(symbol->vector->width - circle->x);
circle->y = stripf(symbol->vector->height - circle->y);
} else if (rotate_angle == 270) {
temp = circle->x;
circle->x = circle->y;
circle->y = symbol->vector->width - temp;
circle->y = stripf(symbol->vector->width - temp);
}
circle = circle->next;
}
@ -345,17 +345,17 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
while (string) {
if (rotate_angle == 90) {
temp = string->x;
string->x = symbol->vector->height - string->y;
string->x = stripf(symbol->vector->height - string->y);
string->y = temp;
string->rotation = 90;
} else if (rotate_angle == 180) {
string->x = symbol->vector->width - string->x;
string->y = symbol->vector->height - string->y;
string->x = stripf(symbol->vector->width - string->x);
string->y = stripf(symbol->vector->height - string->y);
string->rotation = 180;
} else if (rotate_angle == 270) {
temp = string->x;
string->x = string->y;
string->y = symbol->vector->width - temp;
string->y = stripf(symbol->vector->width - temp);
string->rotation = 270;
}
string = string->next;
@ -378,7 +378,7 @@ static void vector_reduce_rectangles(struct zint_symbol *symbol) {
target = prev->next;
while (target) {
if ((rect->x == target->x) && (rect->width == target->width) && ((rect->y + rect->height) == target->y)
if ((rect->x == target->x) && (rect->width == target->width) && (stripf(rect->y + rect->height) == target->y)
&& (rect->colour == target->colour)) {
rect->height += target->height;
prev->next = target->next;