DBAR_OMN/LTD: replace unnecessary large_uint with uint64_t

DBAR_OMN/LTD/EXP: add helpers `dbar_xxx_group()` to calc groups;
  `dbar_widths()` -> dbar_getWidths()` & make `noNarrow` boolean;
  new helper `dbar_widths()` interleaves;
  various other refactorings, fiddlings etc.
DBAR_EXP: `dbar_date()` -> `dbar_exp_date()`
upcean: make `cc_rows` const
This commit is contained in:
gitlost 2025-04-28 16:18:13 +01:00
parent fcb3f9b422
commit effb13cab8
4 changed files with 446 additions and 556 deletions

View file

@ -70,7 +70,7 @@ INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_
INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int dbar_date(const unsigned char source[], const int length, const int src_posn); INTERNAL int dbar_exp_date(const unsigned char source[], const int length, const int position);
static int cc_min(const int first, const int second) { static int cc_min(const int first, const int second) {
@ -758,7 +758,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
if (length > 1 && source[0] == '1' && (source[1] == '0' || source[1] == '1' || source[1] == '7')) { if (length > 1 && source[0] == '1' && (source[1] == '0' || source[1] == '1' || source[1] == '7')) {
/* Source starts (10), (11) or (17) */ /* Source starts (10), (11) or (17) */
if (source[1] == '0' || dbar_date(source, length, 2) >= 0) { /* Check date valid if (11) or (17) */ if (source[1] == '0' || dbar_exp_date(source, length, 2) >= 0) { /* Check date valid if (11) or (17) */
encoding_method = 2; encoding_method = 2;
} }
} else if (length > 1 && source[0] == '9' && source[1] == '0') { } else if (length > 1 && source[0] == '9' && source[1] == '0') {
@ -781,9 +781,9 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
read_posn = 2; read_posn = 2;
} else { } else {
/* Production Date (11) or Expiration Date (17) */ /* Production Date (11) or Expiration Date (17) */
assert(length >= 8); /* Due to `dbar_date()` check above */ assert(length >= 8); /* Due to `dbar_exp_date()` check above */
bp = bin_append_posn(dbar_date(source, length, 2), 16, binary_string, bp); bp = bin_append_posn(dbar_exp_date(source, length, 2), 16, binary_string, bp);
if (source[1] == '1') { if (source[1] == '1') {
/* Production Date AI 11 */ /* Production Date AI 11 */

View file

@ -30,7 +30,7 @@
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
/* The functions "dbar_combins" and "dbar_widths" are copyright BSI and are /* The functions "dbar_combins" and "dbar_getWidths" are copyright BSI and are
released with permission under the following terms: released with permission under the following terms:
"Copyright subsists in all BSI publications. BSI also holds the copyright, in the "Copyright subsists in all BSI publications. BSI also holds the copyright, in the
@ -58,8 +58,8 @@
* RSS-14 Stacked > GS1 DataBar Stacked * RSS-14 Stacked > GS1 DataBar Stacked
* RSS-14 Stacked Omnidirectional > GS1 DataBar Stacked Omnidirectional * RSS-14 Stacked Omnidirectional > GS1 DataBar Stacked Omnidirectional
* RSS Limited > GS1 DataBar Limited * RSS Limited > GS1 DataBar Limited
* RSS Expanded > GS1 DataBar Expanded Omnidirectional * RSS Expanded > GS1 DataBar Expanded
* RSS Expanded Stacked > GS1 DataBar Expanded Stacked Omnidirectional * RSS Expanded Stacked > GS1 DataBar Expanded Stacked
*/ */
#include <assert.h> #include <assert.h>
@ -67,7 +67,6 @@
#include "common.h" #include "common.h"
#include "general_field.h" #include "general_field.h"
#include "gs1.h" #include "gs1.h"
#include "large.h"
#include "rss.h" #include "rss.h"
/* `combins()' in ISO/IEC 24724:2011 Annex B */ /* `combins()' in ISO/IEC 24724:2011 Annex B */
@ -76,9 +75,9 @@
* Combinations = n! / ((n - r)! * r!) * Combinations = n! / ((n - r)! * r!)
****************************************************************************/ ****************************************************************************/
static int dbar_combins(const int n, const int r) { static int dbar_combins(const int n, const int r) {
int i, j; int i;
int maxDenom, minDenom; int maxDenom, minDenom;
int val; int val = 1, j = 1;
if (n - r > r) { if (n - r > r) {
minDenom = r; minDenom = r;
@ -87,8 +86,6 @@ static int dbar_combins(const int n, const int r) {
minDenom = n - r; minDenom = n - r;
maxDenom = r; maxDenom = r;
} }
val = 1;
j = 1;
for (i = n; i > maxDenom; i--) { for (i = n; i > maxDenom; i--) {
val *= i; val *= i;
if (j <= minDenom) { if (j <= minDenom) {
@ -99,46 +96,43 @@ static int dbar_combins(const int n, const int r) {
for (; j <= minDenom; j++) { for (; j <= minDenom; j++) {
val /= j; val /= j;
} }
return (val); return val;
} }
/* `getRSSwidths()' in ISO/IEC 24724:2011 Annex B, modified to use arg `widths` instead of static */ /* `getRSSwidths()' in ISO/IEC 24724:2011 Annex B, modified to use arg `widths` instead of static,
and with `noNarrow` inverted (0 -> 1) so boolean */
/********************************************************************** /**********************************************************************
* dbar_widths * dbar_getWidths
* routine to generate widths for RSS elements for a given value. * routine to generate widths for DataBar elements for a given value.
* *
* Calling arguments: * Calling arguments:
* int widths[] = element widths * int widths[] = element widths
* val = required value * val = required value
* n = number of modules * n = number of modules
* elements = elements in a set (RSS-14 & Expanded = 4; RSS Limited = 7) * elements = elements in a set (Databar Limited = 7, all others = 4)
* maxWidth = maximum module width of an element * maxWidth = maximum module width of an element
* noNarrow = 0 will skip patterns without a one module wide element * noNarrow = 1 will skip patterns without a one module wide element
* *
**********************************************************************/ **********************************************************************/
static void dbar_widths(int widths[], int val, int n, const int elements, const int maxWidth, const int noNarrow) { static void dbar_getWidths(int widths[], int val, int n, const int elements, const int maxWidth, const int noNarrow) {
int bar; int bar;
int elmWidth; int elmWidth;
int mxwElement; int mxwElement;
int subVal, lessVal; int subVal, lessVal;
int narrowMask = 0; int narrowMask = 0;
for (bar = 0; bar < elements - 1; bar++) { for (bar = 0; bar < elements - 1; bar++) {
for (elmWidth = 1, narrowMask |= (1 << bar); for (elmWidth = 1, narrowMask |= (1 << bar); ; elmWidth++, narrowMask &= ~(1 << bar)) {
;
elmWidth++, narrowMask &= ~(1 << bar)) {
/* Get all combinations */ /* Get all combinations */
subVal = dbar_combins(n - elmWidth - 1, elements - bar - 2); subVal = dbar_combins(n - elmWidth - 1, elements - bar - 2);
/* Less combinations with no single-module element */ /* Less combinations with no single-module element */
if (!noNarrow && !narrowMask if (noNarrow && !narrowMask && (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
&& (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
subVal -= dbar_combins(n - elmWidth - (elements - bar), elements - bar - 2); subVal -= dbar_combins(n - elmWidth - (elements - bar), elements - bar - 2);
} }
/* Less combinations with elements > maxVal */ /* Less combinations with elements > maxVal */
if (elements - bar - 1 > 1) { if (elements - bar - 1 > 1) {
lessVal = 0; lessVal = 0;
for (mxwElement = n - elmWidth - (elements - bar - 2); for (mxwElement = n - elmWidth - (elements - bar - 2); mxwElement > maxWidth; mxwElement--) {
mxwElement > maxWidth;
mxwElement--) {
lessVal += dbar_combins(n - elmWidth - mxwElement - 1, elements - bar - 3); lessVal += dbar_combins(n - elmWidth - mxwElement - 1, elements - bar - 3);
} }
subVal -= lessVal * (elements - 1 - bar); subVal -= lessVal * (elements - 1 - bar);
@ -153,7 +147,36 @@ static void dbar_widths(int widths[], int val, int n, const int elements, const
widths[bar] = elmWidth; widths[bar] = elmWidth;
} }
widths[bar] = n; widths[bar] = n;
return; }
/* Interleave `dbar_getWidths()` */
static void dbar_widths(int *ret_widths, int v_odd, int v_even, int n_odd, int n_even, const int elements,
const int maxWidth, const int noNarrow) {
int widths[2][7];
int i;
assert(elements <= 7);
dbar_getWidths(widths[0], v_odd, n_odd, elements, maxWidth, noNarrow);
dbar_getWidths(widths[1], v_even, n_even, elements, 9 - maxWidth, !noNarrow);
for (i = 0; i < elements; i++) {
ret_widths[i << 1] = widths[0][i];
ret_widths[(i << 1) + 1] = widths[1][i];
}
}
/* Converts decimal string of length <= 19 to 64-bit unsigned int */
static uint64_t dbar_to_uint64(const unsigned char source[], const int length) {
uint64_t val = 0;
int i;
for (i = 0; i < length; i++) {
val *= 10;
val += source[i] - '0';
}
return val;
} }
/* Helper to construct zero-padded GTIN14 with check digit, returning `buf` for convenience */ /* Helper to construct zero-padded GTIN14 with check digit, returning `buf` for convenience */
@ -172,7 +195,7 @@ static unsigned char *dbar_gtin14(const unsigned char *source, const int length,
static void dbar_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int length) { static void dbar_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int length) {
unsigned char buf[14]; unsigned char buf[14];
hrt_cpy_nochk(symbol, (const unsigned char *) "(01)", 4); hrt_cpy_nochk(symbol, ZCUCP("(01)"), 4);
hrt_cat_nochk(symbol, dbar_gtin14(source, length, buf), 14); hrt_cat_nochk(symbol, dbar_gtin14(source, length, buf), 14);
} }
@ -200,7 +223,9 @@ static int dbar_expand(struct zint_symbol *symbol, int writer, int latch, const
return writer; return writer;
} }
/* Adjust top/bottom separator for finder patterns */ /* DataBar Omnidirectional (incl. Truncated/Stacked/Stacked Omnidirectional) stuff */
/* Adjust top/bottom separator for DataBar Omnidirectional finder patterns */
static void dbar_omn_finder_adjust(struct zint_symbol *symbol, const int separator_row, const int above_below, static void dbar_omn_finder_adjust(struct zint_symbol *symbol, const int separator_row, const int above_below,
const int finder_start) { const int finder_start) {
int i, finder_end; int i, finder_end;
@ -225,7 +250,7 @@ static void dbar_omn_finder_adjust(struct zint_symbol *symbol, const int separat
} }
} }
/* Top/bottom separator for DataBar */ /* Top/bottom separator for DataBar Omnidirectional (Composite and DataBar Stacked Omnidirectional) */
static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int separator_row, const int above_below, static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int separator_row, const int above_below,
const int finder_start, const int finder2_start, const int bottom_finder_value_3) { const int finder_start, const int finder2_start, const int bottom_finder_value_3) {
int i, finder_end, finder_value_3_set; int i, finder_end, finder_value_3_set;
@ -260,7 +285,7 @@ static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int
/* Set Databar Stacked height, maintaining 5:7 ratio of the 2 main row heights */ /* Set Databar Stacked height, maintaining 5:7 ratio of the 2 main row heights */
INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row) { INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row) {
float fixed_height = 0.0f; float fixed_height = 0.0f;
int second_row = first_row + 2; /* 2 row separator */ const int second_row = first_row + 2; /* 2 row separator */
int i; int i;
for (i = 0; i < symbol->rows; i++) { for (i = 0; i < symbol->rows; i++) {
@ -292,15 +317,26 @@ INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_
return 0; return 0;
} }
/* GS1 DataBar Omnidirectional/Truncated/Stacked, allowing for composite if `cc_rows` set */ /* Return DataBar Omnidirectional group (outside -1, inside +5-1) */
static int dbar_omn_group(const int val, const int outside) {
const int end = 8 >> outside;
int i;
for (i = outside ? 0 : 5; i < end; i++) {
if (val < dbar_omn_g_sum[i + 1]) {
return i;
}
}
return i;
}
/* GS1 DataBar Omnidirectional/Truncated/Stacked/Stacked Omnidirectional, allowing for composite if `cc_rows` set */
INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) {
int error_number = 0, i; int error_number = 0, i, j;
large_uint accum; uint64_t val;
uint64_t left_pair, right_pair; int left_pair, right_pair;
int data_character[4] = {0}, data_group[4] = {0}; int data_character[4];
int data_widths[8][4], checksum, c_left, c_right, total_widths[46], writer; int data_widths[4][8], checksum, c_left, c_right, total_widths[46], writer;
int separator_row = 0; int separator_row = 0;
int widths[4];
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
/* Allow and ignore any AI prefix */ /* Allow and ignore any AI prefix */
@ -342,97 +378,45 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
break; break;
} }
large_load_str_u64(&accum, source, length); val = dbar_to_uint64(source, length);
if (cc_rows) { if (cc_rows) {
/* Add symbol linkage flag */ /* Add symbol linkage flag */
large_add_u64(&accum, 10000000000000); val += 10000000000000;
} }
/* Calculate left and right pair values */ /* Calculate left and right pair values */
right_pair = large_div_u64(&accum, 4537077); left_pair = (int) (val / 4537077);
left_pair = large_lo(&accum); right_pair = (int) (val % 4537077);
/* Calculate four data characters */ /* Calculate four data characters */
data_character[0] = (int) (left_pair / 1597); data_character[0] = left_pair / 1597;
data_character[1] = (int) (left_pair % 1597); data_character[1] = left_pair % 1597;
data_character[2] = (int) (right_pair / 1597); data_character[2] = right_pair / 1597;
data_character[3] = (int) (right_pair % 1597); data_character[3] = right_pair % 1597;
/* Calculate odd and even subset values */ /* Calculate odd and even subset values */
if (data_character[0] <= 160) {
data_group[0] = 0;
} else if (data_character[0] <= 960) {
data_group[0] = 1;
} else if (data_character[0] <= 2014) {
data_group[0] = 2;
} else if (data_character[0] <= 2714) {
data_group[0] = 3;
} else {
data_group[0] = 4;
}
if (data_character[1] <= 335) {
data_group[1] = 5;
} else if (data_character[1] <= 1035) {
data_group[1] = 6;
} else if (data_character[1] <= 1515) {
data_group[1] = 7;
} else {
data_group[1] = 8;
}
if (data_character[3] <= 335) {
data_group[3] = 5;
} else if (data_character[3] <= 1035) {
data_group[3] = 6;
} else if (data_character[3] <= 1515) {
data_group[3] = 7;
} else {
data_group[3] = 8;
}
if (data_character[2] <= 160) {
data_group[2] = 0;
} else if (data_character[2] <= 960) {
data_group[2] = 1;
} else if (data_character[2] <= 2014) {
data_group[2] = 2;
} else if (data_character[2] <= 2714) {
data_group[2] = 3;
} else {
data_group[2] = 4;
}
/* Use DataBar subset width algorithm */ /* Use DataBar subset width algorithm */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
const int dg = data_group[i]; /* Counting 1-based 1, 2, 4, 3, i.e. 0-based 0, 1, 3, 2, so 0 & 2 outside */
const int v = data_character[i] - dbar_g_sum_table[dg]; const int group = dbar_omn_group(data_character[i], !(i & 1) /*outside*/);
const int v_div = v / dbar_t_table[dg]; const int v = data_character[i] - dbar_omn_g_sum[group];
const int v_mod = v % dbar_t_table[dg]; const int v_div = v / dbar_omn_t_even_odd[group];
dbar_widths(widths, !(i & 1) ? v_div : v_mod, dbar_modules_odd[dg], 4, dbar_widest_odd[dg], !(i & 1)); const int v_mod = v % dbar_omn_t_even_odd[group];
data_widths[0][i] = widths[0]; dbar_widths(data_widths[i], !(i & 1) ? v_div : v_mod, i & 1 ? v_div : v_mod, dbar_omn_modules[group],
data_widths[2][i] = widths[1]; dbar_omn_modules[group + 9], 4 /*elements*/, dbar_omn_widest[group], i & 1 /*noNarrow*/);
data_widths[4][i] = widths[2];
data_widths[6][i] = widths[3];
dbar_widths(widths, i & 1 ? v_div : v_mod, dbar_modules_even[dg], 4, dbar_widest_even[dg], i & 1);
data_widths[1][i] = widths[0];
data_widths[3][i] = widths[1];
data_widths[5][i] = widths[2];
data_widths[7][i] = widths[3];
} }
checksum = 0; checksum = 0;
/* Calculate the checksum */ /* Calculate the checksum */
for (i = 0; i < 8; i++) { for (i = 0; i < 4; i++) {
checksum += dbar_checksum_weight[i] * data_widths[i][0]; for (j = 0; j < 8; j++) {
checksum += dbar_checksum_weight[i + 8] * data_widths[i][1]; checksum += dbar_omn_checksum_weight[i][j] * data_widths[i][j];
checksum += dbar_checksum_weight[i + 16] * data_widths[i][2]; }
checksum += dbar_checksum_weight[i + 24] * data_widths[i][3];
} }
checksum %= 79; checksum %= 79;
@ -456,14 +440,14 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
total_widths[44] = 1; total_widths[44] = 1;
total_widths[45] = 1; total_widths[45] = 1;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
total_widths[i + 2] = data_widths[i][0]; total_widths[i + 2] = data_widths[0][i];
total_widths[i + 15] = data_widths[7 - i][1]; total_widths[i + 15] = data_widths[1][7 - i];
total_widths[i + 23] = data_widths[i][3]; total_widths[i + 23] = data_widths[3][i];
total_widths[i + 36] = data_widths[7 - i][2]; total_widths[i + 36] = data_widths[2][7 - i];
} }
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
total_widths[i + 10] = dbar_finder_pattern[i + (5 * c_left)]; total_widths[i + 10] = dbar_omn_finder_pattern[c_left][i];
total_widths[i + 31] = dbar_finder_pattern[(4 - i) + (5 * c_right)]; total_widths[i + 31] = dbar_omn_finder_pattern[c_right][4 - i];
} }
/* Put this data into the symbol */ /* Put this data into the symbol */
@ -605,16 +589,32 @@ INTERNAL int dbar_omn(struct zint_symbol *symbol, unsigned char source[], int le
return dbar_omn_cc(symbol, source, length, 0 /*cc_rows*/); return dbar_omn_cc(symbol, source, length, 0 /*cc_rows*/);
} }
/* DataBar Limited stuff */
/* Return DataBar Limited group (-1) */
static int dbar_ltd_group(int *p_val) {
static int g_sum[7] = {
0, 183064, 820064, 1000776, 1491021, 1979845, 1996939
};
int i;
for (i = 6; i > 0; i--) {
if (*p_val >= g_sum[i]) {
*p_val -= g_sum[i];
return i;
}
}
return 0;
}
/* GS1 DataBar Limited, allowing for composite if `cc_rows` set */ /* GS1 DataBar Limited, allowing for composite if `cc_rows` set */
INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) {
int error_number = 0, i; int error_number = 0, i;
large_uint accum; uint64_t val;
uint64_t left_character, right_character; int pair_vals[2];
int left_group, right_group, left_odd, left_even, right_odd, right_even; int pair_widths[2][14];
int left_widths[14], right_widths[14]; int checksum, total_widths[47], writer;
int checksum, check_elements[14], total_widths[47], writer; const char *checksum_finder_pattern;
int separator_row = 0; int separator_row = 0;
int widths[7];
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
/* Allow and ignore any AI prefix */ /* Allow and ignore any AI prefix */
@ -654,82 +654,24 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
symbol->row_height[separator_row] = 1; symbol->row_height[separator_row] = 1;
} }
large_load_str_u64(&accum, source, length); val = dbar_to_uint64(source, length);
if (cc_rows) { if (cc_rows) {
/* Add symbol linkage flag */ /* Add symbol linkage flag */
large_add_u64(&accum, 2015133531096); val += 2015133531096;
} }
/* Calculate left and right pair values */ /* Calculate left (0) and right (1) pair values */
right_character = large_div_u64(&accum, 2013571); pair_vals[0] = (int) (val / 2013571);
left_character = large_lo(&accum); pair_vals[1] = (int) (val % 2013571);
if (left_character >= 1996939) { for (i = 0; i < 2; i++) {
left_group = 6; const int group = dbar_ltd_group(&pair_vals[i]);
left_character -= 1996939; const int odd = pair_vals[i] / dbar_ltd_t_even[group];
} else if (left_character >= 1979845) { const int even = pair_vals[i] % dbar_ltd_t_even[group];
left_group = 5; dbar_widths(pair_widths[i], odd, even, dbar_ltd_modules[group], 26 - dbar_ltd_modules[group], 7 /*elements*/,
left_character -= 1979845; dbar_ltd_widest[group], 0 /*noNarrow*/);
} else if (left_character >= 1491021) {
left_group = 4;
left_character -= 1491021;
} else if (left_character >= 1000776) {
left_group = 3;
left_character -= 1000776;
} else if (left_character >= 820064) {
left_group = 2;
left_character -= 820064;
} else if (left_character >= 183064) {
left_group = 1;
left_character -= 183064;
} else {
left_group = 0;
}
if (right_character >= 1996939) {
right_group = 6;
right_character -= 1996939;
} else if (right_character >= 1979845) {
right_group = 5;
right_character -= 1979845;
} else if (right_character >= 1491021) {
right_group = 4;
right_character -= 1491021;
} else if (right_character >= 1000776) {
right_group = 3;
right_character -= 1000776;
} else if (right_character >= 820064) {
right_group = 2;
right_character -= 820064;
} else if (right_character >= 183064) {
right_group = 1;
right_character -= 183064;
} else {
right_group = 0;
}
left_odd = (int) (left_character / dbar_ltd_t_even[left_group]);
left_even = (int) (left_character % dbar_ltd_t_even[left_group]);
right_odd = (int) (right_character / dbar_ltd_t_even[right_group]);
right_even = (int) (right_character % dbar_ltd_t_even[right_group]);
dbar_widths(widths, left_odd, dbar_ltd_modules_odd[left_group], 7, dbar_ltd_widest_odd[left_group], 1);
for (i = 0; i <= 6; i++) {
left_widths[i * 2] = widths[i];
}
dbar_widths(widths, left_even, dbar_ltd_modules_even[left_group], 7, dbar_ltd_widest_even[left_group], 0);
for (i = 0; i <= 6; i++) {
left_widths[i * 2 + 1] = widths[i];
}
dbar_widths(widths, right_odd, dbar_ltd_modules_odd[right_group], 7, dbar_ltd_widest_odd[right_group], 1);
for (i = 0; i <= 6; i++) {
right_widths[i * 2] = widths[i];
}
dbar_widths(widths, right_even, dbar_ltd_modules_even[right_group], 7, dbar_ltd_widest_even[right_group], 0);
for (i = 0; i <= 6; i++) {
right_widths[i * 2 + 1] = widths[i];
} }
checksum = 0; checksum = 0;
@ -738,14 +680,12 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
#if defined(_MSC_VER) && _MSC_VER == 1900 && defined(_WIN64) /* MSVC 2015 x64 */ #if defined(_MSC_VER) && _MSC_VER == 1900 && defined(_WIN64) /* MSVC 2015 x64 */
checksum %= 89; /* Hack to get around optimizer bug */ checksum %= 89; /* Hack to get around optimizer bug */
#endif #endif
checksum += dbar_ltd_checksum_weight[i] * left_widths[i]; checksum += dbar_ltd_checksum_weight[0][i] * pair_widths[0][i];
checksum += dbar_ltd_checksum_weight[i + 14] * right_widths[i]; checksum += dbar_ltd_checksum_weight[1][i] * pair_widths[1][i];
} }
checksum %= 89; checksum %= 89;
for (i = 0; i < 14; i++) { checksum_finder_pattern = dbar_ltd_finder_pattern[checksum];
check_elements[i] = dbar_ltd_finder_pattern[i + (checksum * 14)];
}
total_widths[0] = 1; total_widths[0] = 1;
total_widths[1] = 1; total_widths[1] = 1;
@ -753,9 +693,9 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
total_widths[45] = 1; total_widths[45] = 1;
total_widths[46] = 5; total_widths[46] = 5;
for (i = 0; i < 14; i++) { for (i = 0; i < 14; i++) {
total_widths[i + 2] = left_widths[i]; total_widths[i + 2] = pair_widths[0][i];
total_widths[i + 16] = check_elements[i]; total_widths[i + 16] = checksum_finder_pattern[i];
total_widths[i + 30] = right_widths[i]; total_widths[i + 30] = pair_widths[1][i];
} }
writer = dbar_expand(symbol, 0 /*writer*/, 0 /*latch*/, total_widths, 0 /*start*/, 47 /*end*/); writer = dbar_expand(symbol, 0 /*writer*/, 0 /*latch*/, total_widths, 0 /*start*/, 47 /*end*/);
@ -767,7 +707,7 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Add separator pattern if composite symbol */ /* Add separator pattern if composite symbol */
if (symbol->symbology == BARCODE_DBAR_LTD_CC) { if (symbol->symbology == BARCODE_DBAR_LTD_CC) {
for (i = 4; i < 70; i++) { for (i = 4; i < 70; i++) {
if (!(module_is_set(symbol, separator_row + 1, i))) { if (!module_is_set(symbol, separator_row + 1, i)) {
set_module(symbol, separator_row, i); set_module(symbol, separator_row, i);
} }
} }
@ -802,16 +742,18 @@ INTERNAL int dbar_ltd(struct zint_symbol *symbol, unsigned char source[], int le
return dbar_ltd_cc(symbol, source, length, 0 /*cc_rows*/); return dbar_ltd_cc(symbol, source, length, 0 /*cc_rows*/);
} }
/* Check and convert date to DataBar date value */ /* DataBar Expanded stuff */
INTERNAL int dbar_date(const unsigned char source[], const int length, const int src_posn) {
/* Check and convert date to DataBar Expanded date value */
INTERNAL int dbar_exp_date(const unsigned char source[], const int length, const int position) {
int yy, mm, dd; int yy, mm, dd;
if (src_posn + 4 + 2 > length) { if (position + 4 + 2 > length) {
return -1; return -1;
} }
yy = to_int(source + src_posn, 2); yy = to_int(source + position, 2);
mm = to_int(source + src_posn + 2, 2); mm = to_int(source + position + 2, 2);
dd = to_int(source + src_posn + 4, 2); dd = to_int(source + position + 4, 2);
/* Month can't be zero but day can (means last day of month, /* Month can't be zero but day can (means last day of month,
GS1 General Specifications Sections 3.4.2 to 3.4.7) */ GS1 General Specifications Sections 3.4.2 to 3.4.7) */
@ -821,18 +763,18 @@ INTERNAL int dbar_date(const unsigned char source[], const int length, const int
return yy * 384 + (mm - 1) * 32 + dd; return yy * 384 + (mm - 1) * 32 + dd;
} }
/* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */ /* Handles all data encodation for DataBar Expanded, section 7.2.5 of ISO/IEC 24724:2011 */
static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned char source[], const int length, static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned char source[], const int length,
char binary_string[], int *p_cols_per_row, const int max_rows, int *p_bp) { char binary_string[], int *p_cols_per_row, const int max_rows, int *p_bp) {
int encoding_method, i, j, read_posn, mode = NUMERIC; int encoding_method, i, j, read_posn, mode = NUMERIC;
char last_digit = '\0'; char last_digit = '\0';
int symbol_characters, characters_per_row = *p_cols_per_row * 2; int symbol_characters, characters_per_row = *p_cols_per_row * 2;
int min_cols_per_row = 0; int min_cols_per_row = 0;
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
char *general_field = (char *) z_alloca(length + 1); char *general_field = (char *) z_alloca(length + 1);
int bp = *p_bp; int bp = *p_bp;
int remainder, d1, d2; int remainder;
int cdf_bp_start; /* Compressed data field start - debug only */ int cdf_bp_start; /* Compressed data field start - debug only */
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
if (length > 77) { /* ISO/IEC 24724:2011 4.2.d.2 */ if (length > 77) { /* ISO/IEC 24724:2011 4.2.d.2 */
/* Caught below anyway but catch here also for better feedback */ /* Caught below anyway but catch here also for better feedback */
@ -877,7 +819,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
} else if (length == 34 && source[26] == '1' } else if (length == 34 && source[26] == '1'
&& (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
&& dbar_date(source, length, 28) >= 0) { && dbar_exp_date(source, length, 28) >= 0) {
/* (01), (310x) and (11) - metric weight and production date */ /* (01), (310x) and (11) - metric weight and production date */
/* (01), (310x) and (13) - metric weight and packaging date */ /* (01), (310x) and (13) - metric weight and packaging date */
@ -908,7 +850,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
} else if (length == 34 && source[26] == '1' } else if (length == 34 && source[26] == '1'
&& (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
&& dbar_date(source, length, 28) >= 0) { && dbar_exp_date(source, length, 28) >= 0) {
/* (01), (320x) and (11) - English weight and production date */ /* (01), (320x) and (11) - English weight and production date */
/* (01), (320x) and (13) - English weight and packaging date */ /* (01), (320x) and (13) - English weight and packaging date */
@ -966,14 +908,12 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
/* Verify that the data to be placed in the compressed data field is all numeric data /* Verify that the data to be placed in the compressed data field is all numeric data
before carrying out compression */ before carrying out compression */
for (i = 0; i < read_posn; i++) { for (i = 0; i < read_posn; i++) {
if (!z_isdigit(source[i])) { if (!z_isdigit(source[i]) && source[i] != '\x1D') {
if (source[i] != '\x1D') {
/* Something is wrong */ /* Something is wrong */
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 385, return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 385,
"Invalid character in Compressed Field data (digits only)"); "Invalid character in Compressed Field data (digits only)");
} }
} }
}
/* Now encode the compressed data field */ /* Now encode the compressed data field */
@ -1037,7 +977,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
if (length == 34) { if (length == 34) {
/* Date information is included */ /* Date information is included */
group_val = dbar_date(source, length, 28); group_val = dbar_exp_date(source, length, 28);
} else { } else {
group_val = 38400; group_val = 38400;
} }
@ -1055,14 +995,13 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
j = 0; j = 0;
for (i = read_posn; i < length; i++) { for (i = read_posn; i < length; i++) {
general_field[j] = source[i]; general_field[j++] = source[i];
j++;
} }
general_field[j] = '\0';
if (debug_print) printf("General field data = %s\n", general_field); if (debug_print) printf("General field data (%d): %.*s\n", j, j, general_field);
if (j != 0) { /* If general field not empty */ if (j != 0) { /* If general field not empty */
general_field[j] = '\0';
if (!general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) { if (!general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) {
/* Will happen if character not in CSET 82 + space */ /* Will happen if character not in CSET 82 + space */
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 386, "Invalid character in General Field data"); return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 386, "Invalid character in General Field data");
@ -1099,12 +1038,10 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
if (debug_print) fputs("Adding extra (odd) numeric digit\n", stdout); if (debug_print) fputs("Adding extra (odd) numeric digit\n", stdout);
if (remainder >= 4 && remainder <= 6) { if (remainder >= 4 && remainder <= 6) {
bp = bin_append_posn(ctoi(last_digit) + 1, 4, binary_string, bp); bp = bin_append_posn(ctoi(last_digit) + 1, 4, binary_string, bp); /* 7.2.5.5.1 (c) (2) */
} else { } else {
d1 = ctoi(last_digit); /* 7.2.5.5.1 (c) (1) */
d2 = 10; bp = bin_append_posn(ctoi(last_digit) * 11 + 10 /*FNC1*/ + 8, 7, binary_string, bp);
bp = bin_append_posn((11 * d1) + d2 + 8, 7, binary_string, bp);
} }
remainder = 12 - (bp % 12); remainder = 12 - (bp % 12);
@ -1152,25 +1089,23 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
bp = bin_append_posn(4, 5, binary_string, bp); /* "00100" */ bp = bin_append_posn(4, 5, binary_string, bp); /* "00100" */
} }
if (encoding_method == 1 || encoding_method == 2 || encoding_method == 5 || encoding_method == 6) {
/* Patch variable length symbol bit field */ /* Patch variable length symbol bit field */
d1 = symbol_characters & 1; const char variable_bit1 = symbol_characters & 1 ? '1' : '0';
const char variable_bit2 = symbol_characters > 14 ? '1' : '0';
if (symbol_characters <= 14) {
d2 = 0;
} else {
d2 = 1;
}
if (encoding_method == 1) { if (encoding_method == 1) {
binary_string[2] = d1 ? '1' : '0'; binary_string[2] = variable_bit1;
binary_string[3] = d2 ? '1' : '0'; binary_string[3] = variable_bit2;
} else if (encoding_method == 2) { } else if (encoding_method == 2) {
binary_string[3] = d1 ? '1' : '0'; binary_string[3] = variable_bit1;
binary_string[4] = d2 ? '1' : '0'; binary_string[4] = variable_bit2;
} else if (encoding_method == 5 || encoding_method == 6) { } else {
binary_string[6] = d1 ? '1' : '0'; binary_string[6] = variable_bit1;
binary_string[7] = d2 ? '1' : '0'; binary_string[7] = variable_bit2;
} }
}
if (debug_print) { if (debug_print) {
printf(" Final binary (%d): %.*s\n Symbol chars: %d, Remainder: %d\n", printf(" Final binary (%d): %.*s\n Symbol chars: %d, Remainder: %d\n",
bp, bp, binary_string, symbol_characters, remainder); bp, bp, binary_string, symbol_characters, remainder);
@ -1259,26 +1194,34 @@ static void dbar_exp_hrt(struct zint_symbol *symbol, unsigned char source[], con
} }
} }
/* Return DataBar Expanded group (-1) */
static int dbar_exp_group(const int val) {
int i;
for (i = 0; i < ARRAY_SIZE(dbar_exp_g_sum) - 1; i++) {
if (val < dbar_exp_g_sum[i + 1]) {
return i;
}
}
return i;
}
/* GS1 DataBar Expanded, setting linkage for composite if `cc_rows` set */ /* GS1 DataBar Expanded, setting linkage for composite if `cc_rows` set */
INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) {
int error_number, warn_number; int error_number, warn_number;
int i, j, k, p, codeblocks, data_chars, vs, group, v_odd, v_even; int i, j, p, codeblocks, data_chars, symbol_chars, group;
int latch; int char_widths[21][8], checksum, check_widths[8];
int char_widths[21][8], checksum, check_widths[8], c_group; int check_char, odd, even, elements[235], pattern_width, reader, writer;
int check_char, c_odd, c_even, elements[235], pattern_width, reader, writer;
int separator_row = 0; int separator_row = 0;
/* Allow for 8 bits + 5-bit latch per char + 200 bits overhead/padding */
unsigned int bin_len = 13 * length + 200 + 1;
int widths[4];
int bp = 0; int bp = 0;
int cols_per_row = 0; int cols_per_row = 0;
int max_rows = 0; int max_rows = 0;
int stack_rows = 1; int stack_rows = 1;
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
unsigned char *reduced = (unsigned char *) z_alloca(length + 1); unsigned char *reduced = (unsigned char *) z_alloca(length + 1);
int reduced_length; int reduced_length;
char *binary_string = (char *) z_alloca(bin_len); /* Allow for 8 bits + 5-bit latch per char + 200 bits overhead/padding */
char *binary_string = (char *) z_alloca(13 * length + 200 + 1);
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
error_number = gs1_verify(symbol, source, &length, reduced, &reduced_length); error_number = gs1_verify(symbol, source, &length, reduced, &reduced_length);
if (error_number >= ZINT_ERROR) { if (error_number >= ZINT_ERROR) {
@ -1334,42 +1277,25 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
} }
data_chars = bp / 12; data_chars = bp / 12;
symbol_chars = data_chars + 1; /* Plus check char */
if (debug_print) fputs("Data:", stdout); if (debug_print) fputs("Data:", stdout);
for (i = 0; i < data_chars; i++) { for (i = 0; i < data_chars; i++) {
k = i * 12; const int k = i * 12;
vs = 0; int vs = 0;
for (j = 0; j < 12; j++) { for (j = 0; j < 12; j++) {
if (binary_string[k + j] == '1') { if (binary_string[k + j] == '1') {
vs |= (0x800 >> j); vs |= (0x800 >> j);
} }
} }
if (vs <= 347) {
group = 1;
} else if (vs <= 1387) {
group = 2;
} else if (vs <= 2947) {
group = 3;
} else if (vs <= 3987) {
group = 4;
} else {
group = 5;
}
v_odd = (vs - dbar_exp_g_sum[group - 1]) / dbar_exp_t_even[group - 1];
v_even = (vs - dbar_exp_g_sum[group - 1]) % dbar_exp_t_even[group - 1];
if (debug_print) printf("%s%d", i == 0 || (i & 1) ? " " : ",", vs); if (debug_print) printf("%s%d", i == 0 || (i & 1) ? " " : ",", vs);
dbar_widths(widths, v_odd, dbar_exp_modules_odd[group - 1], 4, dbar_exp_widest_odd[group - 1], 0); group = dbar_exp_group(vs);
char_widths[i][0] = widths[0]; odd = (vs - dbar_exp_g_sum[group]) / dbar_exp_t_even[group];
char_widths[i][2] = widths[1]; even = (vs - dbar_exp_g_sum[group]) % dbar_exp_t_even[group];
char_widths[i][4] = widths[2];
char_widths[i][6] = widths[3]; dbar_widths(char_widths[i], odd, even, dbar_exp_modules[group], 17 - dbar_exp_modules[group], 4 /*elements*/,
dbar_widths(widths, v_even, dbar_exp_modules_even[group - 1], 4, dbar_exp_widest_even[group - 1], 1); dbar_exp_widest[group], 1 /*noNarrow*/);
char_widths[i][1] = widths[0];
char_widths[i][3] = widths[1];
char_widths[i][5] = widths[2];
char_widths[i][7] = widths[3];
} }
if (debug_print) fputc('\n', stdout); if (debug_print) fputc('\n', stdout);
@ -1378,56 +1304,38 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
elements in the data characters. */ elements in the data characters. */
checksum = 0; checksum = 0;
for (i = 0; i < data_chars; i++) { for (i = 0; i < data_chars; i++) {
int row = dbar_exp_weight_rows[(((data_chars - 2) / 2) * 21) + i]; const int row = dbar_exp_weight_rows[(data_chars - 2) / 2][i];
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
checksum += (char_widths[i][j] * dbar_exp_checksum_weight[(row * 8) + j]); checksum += char_widths[i][j] * dbar_exp_checksum_weight[row][j];
} }
} }
check_char = (211 * ((data_chars + 1) - 4)) + (checksum % 211); check_char = 211 * (symbol_chars - 4) + checksum % 211;
if (debug_print) { if (debug_print) {
printf("Data chars: %d, Check char: %d\n", data_chars, check_char); printf("Data chars: %d, Check char: %d\n", data_chars, check_char);
} }
if (check_char <= 347) { group = dbar_exp_group(check_char);
c_group = 1;
} else if (check_char <= 1387) {
c_group = 2;
} else if (check_char <= 2947) {
c_group = 3;
} else if (check_char <= 3987) {
c_group = 4;
} else {
c_group = 5;
}
c_odd = (check_char - dbar_exp_g_sum[c_group - 1]) / dbar_exp_t_even[c_group - 1]; odd = (check_char - dbar_exp_g_sum[group]) / dbar_exp_t_even[group];
c_even = (check_char - dbar_exp_g_sum[c_group - 1]) % dbar_exp_t_even[c_group - 1]; even = (check_char - dbar_exp_g_sum[group]) % dbar_exp_t_even[group];
dbar_widths(widths, c_odd, dbar_exp_modules_odd[c_group - 1], 4, dbar_exp_widest_odd[c_group - 1], 0); dbar_widths(check_widths, odd, even, dbar_exp_modules[group], 17 - dbar_exp_modules[group], 4 /*elements*/,
check_widths[0] = widths[0]; dbar_exp_widest[group], 1 /*noNarrow*/);
check_widths[2] = widths[1];
check_widths[4] = widths[2];
check_widths[6] = widths[3];
dbar_widths(widths, c_even, dbar_exp_modules_even[c_group - 1], 4, dbar_exp_widest_even[c_group - 1], 1);
check_widths[1] = widths[0];
check_widths[3] = widths[1];
check_widths[5] = widths[2];
check_widths[7] = widths[3];
/* Initialise element array */ /* Initialise element array */
codeblocks = (data_chars + 1) / 2 + ((data_chars + 1) & 1); codeblocks = (symbol_chars + 1) / 2;
pattern_width = (codeblocks * 5) + ((data_chars + 1) * 8) + 4; pattern_width = codeblocks * 5 + symbol_chars * 8 + 4;
memset(elements, 0, sizeof(int) * pattern_width); memset(elements, 0, sizeof(int) * pattern_width);
/* Put finder patterns in element array */ /* Put finder patterns in element array */
p = (((((data_chars + 1) - 2) / 2) + ((data_chars + 1) & 1)) - 1) * 11; p = (symbol_chars - 1) / 2 - 1;
for (i = 0; i < codeblocks; i++) { for (i = 0; i < codeblocks; i++) {
k = p + i; const int k = dbar_exp_finder_sequence[p][i] - 1;
for (j = 0; j < 5; j++) { for (j = 0; j < 5; j++) {
elements[(21 * i) + j + 10] = dbar_exp_finder_pattern[((dbar_exp_finder_sequence[k] - 1) * 5) + j]; elements[(21 * i) + j + 10] = dbar_exp_finder_pattern[k][j];
} }
} }
@ -1438,7 +1346,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Put forward reading data characters in element array */ /* Put forward reading data characters in element array */
for (i = 1; i < data_chars; i += 2) { for (i = 1; i < data_chars; i += 2) {
k = (((i - 1) / 2) * 21) + 23; const int k = ((i - 1) / 2) * 21 + 23;
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
elements[k + j] = char_widths[i][j]; elements[k + j] = char_widths[i][j];
} }
@ -1446,7 +1354,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Put reversed data characters in element array */ /* Put reversed data characters in element array */
for (i = 0; i < data_chars; i += 2) { for (i = 0; i < data_chars; i += 2) {
k = ((i / 2) * 21) + 15; const int k = (i / 2) * 21 + 15;
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
elements[k + j] = char_widths[i][7 - j]; elements[k + j] = char_widths[i][7 - j];
} }
@ -1490,22 +1398,18 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
current_block = 0; current_block = 0;
for (current_row = 1; current_row <= stack_rows; current_row++) { for (current_row = 1; current_row <= stack_rows; current_row++) {
int special_case_row = 0; int elements_in_sub = 2;
int elements_in_sub;
int sub_elements[235] = {0}; int sub_elements[235] = {0};
int special_case_row = 0;
int num_columns; int num_columns;
int latch;
/* Number of columns in current row */ /* Number of columns in current row */
if (current_row * cols_per_row > codeblocks) { num_columns = current_row * cols_per_row > codeblocks ? codeblocks - current_block : cols_per_row;
num_columns = codeblocks - current_block;
} else {
num_columns = cols_per_row;
}
/* Row Start */ /* Row Start */
sub_elements[0] = 1; /* Left guard */ sub_elements[0] = 1; /* Left guard */
sub_elements[1] = 1; sub_elements[1] = 1;
elements_in_sub = 2;
/* If last row and is partial and even-numbered, and have even columns (segment pairs), /* If last row and is partial and even-numbered, and have even columns (segment pairs),
and odd number of finders (== odd number of columns) */ and odd number of finders (== odd number of columns) */
@ -1518,11 +1422,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
/* If odd number of columns or current row odd-numbered or special case last row then left-to-right, /* If odd number of columns or current row odd-numbered or special case last row then left-to-right,
else right-to-left */ else right-to-left */
if ((cols_per_row & 1) || (current_row & 1) || special_case_row) { left_to_right = (cols_per_row & 1) || (current_row & 1) || special_case_row;
left_to_right = 1;
} else {
left_to_right = 0;
}
if (debug_print) { if (debug_print) {
if (current_row == stack_rows) { if (current_row == stack_rows) {
@ -1550,11 +1450,10 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
} while ((reader < cols_per_row) && (current_block < codeblocks)); } while ((reader < cols_per_row) && (current_block < codeblocks));
/* Row Stop */ /* Row Stop */
sub_elements[elements_in_sub] = 1; /* Right guard */ sub_elements[elements_in_sub++] = 1; /* Right guard */
sub_elements[elements_in_sub + 1] = 1; sub_elements[elements_in_sub++] = 1;
elements_in_sub += 2;
latch = (current_row & 1) || special_case_row ? 0 : 1; latch = !((current_row & 1) || special_case_row);
writer = dbar_expand(symbol, 0 /*writer*/, latch, sub_elements, 0 /*start*/, elements_in_sub /*end*/); writer = dbar_expand(symbol, 0 /*writer*/, latch, sub_elements, 0 /*start*/, elements_in_sub /*end*/);
if (symbol->width < writer) { if (symbol->width < writer) {

View file

@ -1,7 +1,7 @@
/* rss.h - Data tables for Reduced Space Symbology */ /* rss.h - Data tables for DataBar (previously Reduced Space Symbology) */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2007-2024 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2007-2025 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -33,171 +33,168 @@
#ifndef Z_RSS_H #ifndef Z_RSS_H
#define Z_RSS_H #define Z_RSS_H
/* RSS-14 Tables */ /* DataBar Omnidirectional Tables */
static const unsigned short dbar_g_sum_table[9] = {
0, 161, 961, 2015, 2715, 0, 336, 1036, 1516 /* Tables 1 (outside) & 2 (inside) */
static const unsigned short dbar_omn_g_sum[9] = {
0, 161, 961, 2015, 2715, /* Outside Gsum */
0, 336, 1036, 1516 /* Inside Gsum */
}; };
static const char dbar_t_table[9] = { static const char dbar_omn_t_even_odd[9] = {
1, 10, 34, 70, 126, 4, 20, 48, 81 1, 10, 34, 70, 126, /* Outside Teven */
4, 20, 48, 81 /* Inside Todd */
}; };
static const char dbar_modules_odd[9] = { static const char dbar_omn_modules[18] = {
12, 10, 8, 6, 4, 5, 7, 9, 11 12, 10, 8, 6, 4, /* Outside odd */
5, 7, 9, 11, /* Inside odd */
4, 6, 8, 10, 12, /* Outside even (16 - outside odd) */
10, 8, 6, 4 /* Inside even (15 - inside odd) */
}; };
static const char dbar_modules_even[9] = { static const char dbar_omn_widest[9] = {
4, 6, 8, 10, 12, 10, 8, 6, 4 8, 6, 4, 3, 1, 2, 4, 6, 8 /* Odd, even is 9 - odd */
}; };
static const char dbar_widest_odd[9] = { /* Table 4 */
8, 6, 4, 3, 1, 2, 4, 6, 8 static const char dbar_omn_finder_pattern[9][5] = {
}; { 3, 8, 2, 1, 1 },
{ 3, 5, 5, 1, 1 },
static const char dbar_widest_even[9] = { { 3, 3, 7, 1, 1 },
1, 3, 5, 6, 8, 7, 5, 3, 1 { 3, 1, 9, 1, 1 },
}; { 2, 7, 4, 1, 1 },
{ 2, 5, 6, 1, 1 },
static const char dbar_finder_pattern[45] = { { 2, 3, 8, 1, 1 },
3, 8, 2, 1, 1, { 1, 5, 7, 1, 1 },
3, 5, 5, 1, 1, { 1, 3, 9, 1, 1 },
3, 3, 7, 1, 1,
3, 1, 9, 1, 1,
2, 7, 4, 1, 1,
2, 5, 6, 1, 1,
2, 3, 8, 1, 1,
1, 5, 7, 1, 1,
1, 3, 9, 1, 1
}; };
/* Table 5 */ /* Table 5 */
static const char dbar_checksum_weight[32] = { static const char dbar_omn_checksum_weight[4][8] = {
1, 3, 9, 27, 2, 6, 18, 54, { 1, 3, 9, 27, 2, 6, 18, 54 },
4, 12, 36, 29, 8, 24, 72, 58, { 4, 12, 36, 29, 8, 24, 72, 58 },
16, 48, 65, 37, 32, 17, 51, 74, { 16, 48, 65, 37, 32, 17, 51, 74 },
64, 34, 23, 69, 49, 68, 46, 59 { 64, 34, 23, 69, 49, 68, 46, 59 },
}; };
/* RSS Limited Tables */ /* DataBar Limited Tables */
/* Table 6 */
static const unsigned short dbar_ltd_t_even[7] = { static const unsigned short dbar_ltd_t_even[7] = {
28, 728, 6454, 203, 2408, 1, 16632 28, 728, 6454, 203, 2408, 1, 16632
}; };
static const char dbar_ltd_modules_odd[7] = { static const char dbar_ltd_modules[7] = {
17, 13, 9, 15, 11, 19, 7 17, 13, 9, 15, 11, 19, 7 /* Odd, even is 26 - odd */
}; };
static const char dbar_ltd_modules_even[7] = { static const char dbar_ltd_widest[7] = {
9, 13, 17, 11, 15, 7, 19 6, 5, 3, 5, 4, 8, 1 /* Odd, even is 9 - odd */
};
static const char dbar_ltd_widest_odd[7] = {
6, 5, 3, 5, 4, 8, 1
};
static const char dbar_ltd_widest_even[7] = {
3, 4, 6, 4, 5, 1, 8
}; };
/* Table 7 */ /* Table 7 */
static const char dbar_ltd_checksum_weight[28] = { static const char dbar_ltd_checksum_weight[2][14] = {
1, 3, 9, 27, 81, 65, 17, 51, 64, 14, 42, 37, 22, 66, { 1, 3, 9, 27, 81, 65, 17, 51, 64, 14, 42, 37, 22, 66 },
20, 60, 2, 6, 18, 54, 73, 41, 34, 13, 39, 28, 84, 74 { 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1, 1, 1, 1, 3, 2, 1, 1, 1 },
2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, { 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1 },
2, 1, 1, 1, 1, 1, 1, 3, 1, 1, 2, 1, 1, 1, { 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1 },
2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, { 2, 1, 1, 1, 1, 1, 1, 3, 1, 1, 2, 1, 1, 1 },
2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, { 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1 },
2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, { 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1 },
2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 1 { 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1 },
{ 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 1 },
}; };
/* RSS Expanded Tables */ /* DataBar Expanded Tables */
/* Table 8 */
static const unsigned short dbar_exp_g_sum[5] = { static const unsigned short dbar_exp_g_sum[5] = {
0, 348, 1388, 2948, 3988 0, 348, 1388, 2948, 3988
}; };
@ -206,90 +203,82 @@ static const unsigned char dbar_exp_t_even[5] = {
4, 20, 52, 104, 204 4, 20, 52, 104, 204
}; };
static const char dbar_exp_modules_odd[5] = { static const char dbar_exp_modules[5] = {
12, 10, 8, 6, 4 12, 10, 8, 6, 4 /* Odd, even is 17 - odd */
}; };
static const char dbar_exp_modules_even[5] = { static const char dbar_exp_widest[5] = {
5, 7, 9, 11, 13 7, 5, 4, 3, 1 /* Odd, even is 9 - odd */
}; };
static const char dbar_exp_widest_odd[5] = { /* Table 14 */
7, 5, 4, 3, 1 static const unsigned char dbar_exp_checksum_weight[23][8] = {
}; { 1, 3, 9, 27, 81, 32, 96, 77 },
{ 20, 60, 180, 118, 143, 7, 21, 63 },
static const char dbar_exp_widest_even[5] = { { 189, 145, 13, 39, 117, 140, 209, 205 },
2, 4, 5, 6, 8 { 193, 157, 49, 147, 19, 57, 171, 91 },
}; { 62, 186, 136, 197, 169, 85, 44, 132 },
{ 185, 133, 188, 142, 4, 12, 36, 108 },
/* Table 14 */ { 113, 128, 173, 97, 80, 29, 87, 50 },
static const unsigned char dbar_exp_checksum_weight[184] = { { 150, 28, 84, 41, 123, 158, 52, 156 },
1, 3, 9, 27, 81, 32, 96, 77, { 46, 138, 203, 187, 139, 206, 196, 166 },
20, 60, 180, 118, 143, 7, 21, 63, { 76, 17, 51, 153, 37, 111, 122, 155 },
189, 145, 13, 39, 117, 140, 209, 205, { 43, 129, 176, 106, 107, 110, 119, 146 },
193, 157, 49, 147, 19, 57, 171, 91, { 16, 48, 144, 10, 30, 90, 59, 177 },
62, 186, 136, 197, 169, 85, 44, 132, { 109, 116, 137, 200, 178, 112, 125, 164 },
185, 133, 188, 142, 4, 12, 36, 108, { 70, 210, 208, 202, 184, 130, 179, 115 },
113, 128, 173, 97, 80, 29, 87, 50, { 134, 191, 151, 31, 93, 68, 204, 190 },
150, 28, 84, 41, 123, 158, 52, 156, { 148, 22, 66, 198, 172, 94, 71, 2 },
46, 138, 203, 187, 139, 206, 196, 166, { 6, 18, 54, 162, 64, 192, 154, 40 },
76, 17, 51, 153, 37, 111, 122, 155, { 120, 149, 25, 75, 14, 42, 126, 167 },
43, 129, 176, 106, 107, 110, 119, 146, { 79, 26, 78, 23, 69, 207, 199, 175 },
16, 48, 144, 10, 30, 90, 59, 177, { 103, 98, 83, 38, 114, 131, 182, 124 },
109, 116, 137, 200, 178, 112, 125, 164, { 161, 61, 183, 127, 170, 88, 53, 159 },
70, 210, 208, 202, 184, 130, 179, 115, { 55, 165, 73, 8, 24, 72, 5, 15 },
134, 191, 151, 31, 93, 68, 204, 190, { 45, 135, 194, 160, 58, 174, 100, 89 },
148, 22, 66, 198, 172, 94, 71, 2,
6, 18, 54, 162, 64, 192, 154, 40,
120, 149, 25, 75, 14, 42, 126, 167,
79, 26, 78, 23, 69, 207, 199, 175,
103, 98, 83, 38, 114, 131, 182, 124,
161, 61, 183, 127, 170, 88, 53, 159,
55, 165, 73, 8, 24, 72, 5, 15,
45, 135, 194, 160, 58, 174, 100, 89
}; };
/* Table 15 */ /* Table 15 */
static const char dbar_exp_finder_pattern[60] = { static const char dbar_exp_finder_pattern[12][5] = {
1, 8, 4, 1, 1, { 1, 8, 4, 1, 1 },
1, 1, 4, 8, 1, { 1, 1, 4, 8, 1 },
3, 6, 4, 1, 1, { 3, 6, 4, 1, 1 },
1, 1, 4, 6, 3, { 1, 1, 4, 6, 3 },
3, 4, 6, 1, 1, { 3, 4, 6, 1, 1 },
1, 1, 6, 4, 3, { 1, 1, 6, 4, 3 },
3, 2, 8, 1, 1, { 3, 2, 8, 1, 1 },
1, 1, 8, 2, 3, { 1, 1, 8, 2, 3 },
2, 6, 5, 1, 1, { 2, 6, 5, 1, 1 },
1, 1, 5, 6, 2, { 1, 1, 5, 6, 2 },
2, 2, 9, 1, 1, { 2, 2, 9, 1, 1 },
1, 1, 9, 2, 2 { 1, 1, 9, 2, 2 },
}; };
/* Table 16 */ /* Table 16 */
static const char dbar_exp_finder_sequence[198] = { static const char dbar_exp_finder_sequence[18][11] = {
1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, { 1, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0 },
1, 6, 3, 8, 0, 0, 0, 0, 0, 0, 0, { 1, 6, 3, 8, 0, 0, 0, 0, 0, 0, 0 },
1, 10, 3, 8, 5, 0, 0, 0, 0, 0, 0, { 1, 10, 3, 8, 5, 0, 0, 0, 0, 0, 0 },
1, 10, 3, 8, 7, 12, 0, 0, 0, 0, 0, { 1, 10, 3, 8, 7, 12, 0, 0, 0, 0, 0 },
1, 10, 3, 8, 9, 12, 11, 0, 0, 0, 0, { 1, 10, 3, 8, 9, 12, 11, 0, 0, 0, 0 },
1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0 },
1, 2, 3, 4, 5, 6, 7, 10, 9, 0, 0, { 1, 2, 3, 4, 5, 6, 7, 10, 9, 0, 0 },
1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 0, { 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 0 },
1, 2, 3, 4, 5, 8, 7, 10, 9, 12, 11 { 1, 2, 3, 4, 5, 8, 7, 10, 9, 12, 11 },
}; };
static const char dbar_exp_weight_rows[210] = { static const char dbar_exp_weight_rows[10][21] = {
0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
0, 5, 6, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 5, 6, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
0, 9, 10, 3, 4, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 9, 10, 3, 4, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
0, 17, 18, 3, 4, 13, 14, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 17, 18, 3, 4, 13, 14, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
0, 17, 18, 3, 4, 13, 14, 11, 12, 21, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 17, 18, 3, 4, 13, 14, 11, 12, 21, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
0, 17, 18, 3, 4, 13, 14, 15, 16, 21, 22, 19, 20, 0, 0, 0, 0, 0, 0, 0, 0, { 0, 17, 18, 3, 4, 13, 14, 15, 16, 21, 22, 19, 20, 0, 0, 0, 0, 0, 0, 0, 0 },
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0 },
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 15, 16, 0, 0, 0, 0, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 15, 16, 0, 0, 0, 0 },
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22, 0, 0, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22, 0, 0 },
0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 14, 11, 12, 17, 18, 15, 16, 21, 22, 19, 20 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 14, 11, 12, 17, 18, 15, 16, 21, 22, 19, 20 },
}; };
/* vim: set ts=4 sw=4 et : */ /* vim: set ts=4 sw=4 et : */

View file

@ -110,7 +110,8 @@ static void upca_set_dest(const unsigned char source[], const int length, char *
} }
/* Make a UPC-A barcode, allowing for composite if `cc_rows` set */ /* Make a UPC-A barcode, allowing for composite if `cc_rows` set */
static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) { static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[],
const int cc_rows) {
const unsigned char *gtin = symbol->text; const unsigned char *gtin = symbol->text;
int error_number = 0; int error_number = 0;
@ -157,7 +158,7 @@ static int upca(struct zint_symbol *symbol, const unsigned char source[], int le
} }
/* Make a UPC-E, allowing for composite if `cc_rows` set */ /* Make a UPC-E, allowing for composite if `cc_rows` set */
static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int length, char *d, int cc_rows, static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int length, char *d, const int cc_rows,
unsigned char equivalent[12]) { unsigned char equivalent[12]) {
int i; int i;
int num_system = 0; int num_system = 0;
@ -390,7 +391,7 @@ static void ean_add_on(const unsigned char source[], const int length, char dest
/* Make an EAN-13, allowing for composite if `cc_rows` set */ /* Make an EAN-13, allowing for composite if `cc_rows` set */
static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char *d, static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char *d,
int cc_rows) { const int cc_rows) {
int i, half_way; int i, half_way;
const char *parity; const char *parity;
const unsigned char *gtin = symbol->text; const unsigned char *gtin = symbol->text;
@ -468,7 +469,8 @@ static int ean13(struct zint_symbol *symbol, const unsigned char source[], int l
} }
/* Make an EAN-8, allowing for composite if `cc_rows` set */ /* Make an EAN-8, allowing for composite if `cc_rows` set */
static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) { static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[],
const int cc_rows) {
/* EAN-8 is basically the same as UPC-A but with fewer digits */ /* EAN-8 is basically the same as UPC-A but with fewer digits */
const unsigned char *gtin = symbol->text; const unsigned char *gtin = symbol->text;
int error_number = 0; int error_number = 0;
@ -862,7 +864,7 @@ INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char
} }
/* Make EAN/UPC and ISBN, allowing for composite if `cc_rows` set */ /* Make EAN/UPC and ISBN, allowing for composite if `cc_rows` set */
INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, int cc_rows) { INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) {
unsigned char first_part[14], second_part[6]; unsigned char first_part[14], second_part[6];
unsigned char local_source[20]; /* Allow 13 + "+" + 5 + 1 */ unsigned char local_source[20]; /* Allow 13 + "+" + 5 + 1 */
unsigned char equivalent[12] = {0}; /* For UPC-E - GTIN-12 equivalent */ unsigned char equivalent[12] = {0}; /* For UPC-E - GTIN-12 equivalent */