1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-07-31 02:19:50 +00:00

DATAMATRIX: add new options DM_B256_START and DM_C40_START to

`options_3`, allowing forcing of Base 256 or C40 mode a la BWIPP
  for initial no. of characters specified in `option_1`, with 0
  meaning all (CLI "--dmb256=" and "--dmc40=", GUI also (apart
  from MAILMARK_2D, which may be added later);
  export masks `DM_B256_C40_START_MASK` & `DM_SQUARE_DMRE_MASK` in
  "zint.h"
ZBarcode_Encode_File: report filename (possibly truncated) in error
  message on failed open
GUI: uniquify some accelerators and add some child widget getter
  helpers to "mainwindow.cpp"
backend/DEVELOPER -> backend/README, with some expansion
debian/copyright: a few more fixes
BWIPP/pandoc: update to latest
tests/fuzz: adjust for new DATAMATRIX options
This commit is contained in:
gitlost
2026-03-30 21:25:22 +01:00
parent 3c193d7306
commit f9a493522f
40 changed files with 1706 additions and 920 deletions
-158
View File
@@ -1,158 +0,0 @@
2026-03-18
Here is a guide to which bit of source code does what.
library.c:
API entry points
2of5.c:
Code 2 of 5 Standard (Matrix)
Code 2 of 5 Industrial
Code 2 of 5 IATA
Code 2 of 5 Data Logic
2of5inter.c:
Code 2 of 5 Interleaved
2of5inter_based.c:
ITF-14
Deutsche Post Leitcode
Deutsche Post Identcode
auspost.c:
Australia Post Standard Customer
Australia Post Reply Paid
Australia Post Routing
Australia Post Redirection
aztec.c:
Aztec Code
Compact Aztec Code
Aztec Runes
bc412.c:
IBM BC412 (SEMI T1-95)
channel.c:
Channel Code
codabar.c:
Codabar
codablock.c:
Codablock F
code11.c:
Code 11
code128.c:
Code 128
Code 128 (Suppress Code Set C)
GS1-128 (UCC/EAN-128)
code128_based.c:
NVE-18
EAN-14
DPD Code
Universal Postal Union S10
code16k.c:
Code 16k
code.c:
Code 39
LOGMARS
Extended Code 39 (Code 39+)
Code 93
VIN
code1.c:
Code One
code49.c:
Code 49
composite.c:
CC-A Composite Symbology
CC-B Composite Symbology
CC-C Composite Symbology
dotcode.c:
Dot Code
dmatrix.c:
Data Matrix (ECC 200)
Royal Mail 2D Mailmark (CMDM)
dxfilmedge.c:
DX Film Edge Barcode
gridmtx.c:
Grid Matrix
hanxin.c:
Han Xin Code
imail.c:
USPS Intelligent Mail (OneCode)
maxicode.c:
UPS MaxiCode
medical.c:
Pharmacode One-Track
Pharmacode Two-Track
Code 32 (Italian Pharmacode)
Pharmazentral Nummer (PZN)
pdf417.c:
PDF417
Compact PDF417
MicroPDF417
plessey.c:
UK Plessey Code (bidirectional)
MSI Plessey
postal.c:
POSTNET
PLANET
Brazilian CEPNet
Facing Identification Mark (FIM)
Royal Mail 4-State Country Code (RM4SCC)
Dutch Post KIX Code
DAFT Code
Flattermarken
Korean Post Barcode
Japanese Postal Code
qr.c:
QR Code
Micro QR Code
UPNQR
Rectangular Micro QR Code (rMQR)
rss.c:
GS1 DataBar Omnidirectional (RSS-14)
GS1 DataBar Truncated
GS1 DataBar Stacked (RSS-14 Stacked)
GS1 DataBar Stacked Omnidirectional (DataBar-14 Stacked Omnidirectional)
(RSS-14 Stacked Omnidirectional)
GS1 DataBar Limited (RSS Limited)
GS1 DataBar Expanded (RSS Expanded)
GS1 DataBar Expanded Stacked (RSS Expanded Stacked)
telepen.c:
Telepen ASCII
Telepen Numeric
upcean.c:
UPC-A
UPC-E
EAN-2 add-on
EAN-5 add-on
EAN-8
EAN-13
SBN (verification)
ISBN (verification)
ISBN-13 (verification)
+243
View File
@@ -0,0 +1,243 @@
% backend/README 2026-03-30
% vim: set ts=4 sw=4 et :
Here is a guide to which bit of source code does what.
library.c:
API entry points
zint.h:
main include
zintconfig.h:
version defines
Barcodes
--------
2of5.c:
Code 2 of 5 Standard (Matrix)
Code 2 of 5 Industrial
Code 2 of 5 IATA
Code 2 of 5 Data Logic
2of5inter.c:
Code 2 of 5 Interleaved
2of5inter_based.c:
ITF-14
Deutsche Post Leitcode
Deutsche Post Identcode
auspost.c:
Australia Post Standard Customer
Australia Post Reply Paid
Australia Post Routing
Australia Post Redirection
aztec.c:
Aztec Code
Compact Aztec Code
Aztec Runes
bc412.c:
IBM BC412 (SEMI T1-95)
channel.c:
Channel Code
codabar.c:
Codabar
codablock.c:
Codablock F
code11.c:
Code 11
code128.c:
Code 128
Code 128 (Suppress Code Set C)
GS1-128 (UCC/EAN-128)
code128_based.c:
NVE-18
EAN-14
DPD Code
Universal Postal Union S10
code16k.c:
Code 16k
code.c:
Code 39
LOGMARS
Extended Code 39 (Code 39+)
Code 93
VIN
code1.c:
Code One
code49.c:
Code 49
composite.c:
CC-A Composite Symbology
CC-B Composite Symbology
CC-C Composite Symbology
dotcode.c:
Dot Code
dmatrix.c:
Data Matrix (ECC 200)
Royal Mail 2D Mailmark (CMDM)
dxfilmedge.c:
DX Film Edge Barcode
gridmtx.c:
Grid Matrix
hanxin.c:
Han Xin Code
imail.c:
USPS Intelligent Mail (OneCode)
maxicode.c:
UPS MaxiCode
medical.c:
Pharmacode One-Track
Pharmacode Two-Track
Code 32 (Italian Pharmacode)
Pharmazentral Nummer (PZN)
pdf417.c:
PDF417
Compact PDF417
MicroPDF417
plessey.c:
UK Plessey Code (bidirectional)
MSI Plessey
postal.c:
POSTNET
PLANET
Brazilian CEPNet
Facing Identification Mark (FIM)
Royal Mail 4-State Country Code (RM4SCC)
Dutch Post KIX Code
DAFT Code
Flattermarken
Korean Post Barcode
Japanese Postal Code
qr.c:
QR Code
Micro QR Code
UPNQR
Rectangular Micro QR Code (rMQR)
rss.c:
GS1 DataBar Omnidirectional (RSS-14)
GS1 DataBar Truncated
GS1 DataBar Stacked (RSS-14 Stacked)
GS1 DataBar Stacked Omnidirectional (DataBar-14 Stacked Omnidirectional)
(RSS-14 Stacked Omnidirectional)
GS1 DataBar Limited (RSS Limited)
GS1 DataBar Expanded (RSS Expanded)
GS1 DataBar Expanded Stacked (RSS Expanded Stacked)
telepen.c:
Telepen ASCII
Telepen Numeric
upcean.c:
UPC-A
UPC-E
EAN-2 add-on
EAN-5 add-on
EAN-8
EAN-13
SBN (verification)
ISBN (verification)
ISBN-13 (verification)
Common
------
common.c:
general routines used by all
eci.c:
ECI, tables in includes
big5.h, eci_sb.h, gb18030.h, gb2312.h, gbk.h, ksx1001.h, sjis.h
filemem.c:
Memory file (BARCODE_MEMORY_FILE)
general_field.c:
GS1 general field compaction (GS1 DataBar and composites)
gs1.c:
GS1 parsing & verifying, includes
gs1_lint.h, iso3166.h, iso4217.h
large.c:
128-bit arithmetic
reedsol.c:
Reed-Solomon
Output
------
bmp.c:
Windows Bitmap format (BMP)
emf.c:
Enhanced Metafile Format (EMF)
gif.c:
Graphics Interchange Format (GIF)
output.c:
general output routines
pcx.c:
ZSoft Paintbrush Format (PCX)
ps.c:
Encapsulated PostScript Format (EPS)
raster.c:
raster output, sets up bitmap arrays, includes
raster_font.h, zfiletypes.h
svg.c:
Scalable Vector Graphic Format (SVG), includes
fonts/normal_woff2.h, fonts/upcean_woff2.h
tif.c:
Tagged Image File Format (TIF)
vector.c:
vector output, sets up vector linked lists, includes
zfiletypes.h
Windows-only
------------
dllversion.c:
DllGetVersion()
libzint.rc:
resource script
+77 -39
View File
@@ -580,8 +580,6 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
return process_p;
}
#define DM_DMRE_SQUARE_MASK 0x65 /* 101 */
/* Get index of symbol size in codewords array `dm_matrixbytes`, as specified or
else smallest containing `minimum` codewords */
static int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
@@ -595,10 +593,11 @@ static int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
}
for (i = minimum >= 62 ? 23 : 0; minimum > dm_matrixbytes[i]; i++);
if ((symbol->option_3 & DM_DMRE_SQUARE_MASK) == DM_DMRE) {
/* `DM_DMRE` trumps `DM_SQUARE` */
if ((symbol->option_3 & DM_SQUARE_DMRE_MASK) == DM_DMRE) {
return i;
}
if ((symbol->option_3 & DM_DMRE_SQUARE_MASK) == DM_SQUARE) {
if ((symbol->option_3 & DM_SQUARE_DMRE_MASK) == DM_SQUARE) {
/* Skip rectangular symbols in square only mode */
for (; dm_matrixH[i] != dm_matrixW[i]; i++);
return i;
@@ -775,9 +774,9 @@ static int dm_getEndMode(struct zint_symbol *symbol, const unsigned char *source
#endif
/* Return number of C40/TEXT codewords needed to encode characters in full batches of 3 (or less if EOD).
The number of characters encoded is returned in `len` */
The number of characters encoded is returned in `p_len` */
static int dm_getNumberOfC40Words(const unsigned char *source, const int length, const int from, const int mode,
int *len) {
int *p_len) {
int thirdsCount = 0;
int i;
@@ -797,11 +796,11 @@ static int dm_getNumberOfC40Words(const unsigned char *source, const int length,
remainder = thirdsCount % 3;
if (remainder == 0 || (remainder == 2 && i + 1 == length)) {
*len = i - from + 1;
*p_len = i - from + 1;
return ((thirdsCount + 2) / 3) * 2;
}
}
*len = 0;
*p_len = 0;
return 0;
}
@@ -1248,8 +1247,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
/* Encode using algorithm based on ISO/IEC 21471:2020 Annex J (was ISO/IEC 21471:2006 Annex P) */
static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], const int length, int *p_sp,
unsigned char target[], int *p_tp, int process_buffer[8], int *p_process_p, int *p_b256_start,
int *p_current_mode, const int gs1, const int debug_print) {
const int mailmark = symbol->symbology == BARCODE_MAILMARK_2D;
int *p_current_mode, const int gs1, const int b256_end, const int c40_end, const int debug_print) {
int sp = *p_sp;
int tp = *p_tp;
int process_p = *p_process_p;
@@ -1260,21 +1258,17 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
/* step (a) */
int next_mode = DM_ASCII;
if (mailmark) { /* First 45 characters C40 */
assert(length >= 45);
assert(b256_end <= length && c40_end <= length && (b256_end == 0 || c40_end == 0));
if (b256_end) {
/* First characters in Base 256 */
next_mode = DM_BASE256;
tp = dm_switch_mode(next_mode, target, tp, p_b256_start, debug_print);
current_mode = next_mode;
} else if (c40_end) {
/* First characters in C40 */
next_mode = DM_C40;
tp = dm_switch_mode(next_mode, target, tp, p_b256_start, debug_print);
while (sp < 45) {
assert(dm_isc40(source[sp]));
process_buffer[process_p++] = dm_c40_value[source[sp]];
if (process_p >= 3) {
process_p = dm_ctx_buffer_xfer(process_buffer, process_p, target, &tp, debug_print);
}
sp++;
}
current_mode = next_mode;
not_first = 1;
}
while (sp < length) {
@@ -1322,7 +1316,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
} else if (current_mode == DM_C40 || current_mode == DM_TEXT) {
next_mode = current_mode;
if (process_p == 0 && not_first) {
if (process_p == 0 && not_first && (sp >= c40_end)) { /* `c40_end` only set if `current_mode` DM_C40 */
next_mode = dm_look_ahead_test(source, length, sp, current_mode, process_p, gs1, debug_print);
}
@@ -1456,7 +1450,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
next_mode = DM_ASCII;
} else {
next_mode = DM_BASE256;
if (not_first) {
if (not_first && sp >= b256_end) {
next_mode = dm_look_ahead_test(source, length, sp, current_mode, tp - (*p_b256_start + 1), gs1,
debug_print);
}
@@ -1473,12 +1467,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
tp = dm_switch_mode(next_mode, target, tp, p_b256_start, debug_print);
not_first = 0;
} else {
if (gs1 == 2 && source[sp] == '\x1D') {
target[tp++] = 29; /* GS */
} else {
target[tp++] = source[sp];
}
sp++;
target[tp++] = source[sp++];
not_first = 1;
if (debug_print) printf("B%02X ", target[tp - 1]);
}
@@ -1501,8 +1490,9 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
/* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate
Supports encoding FNC1 in supporting systems */
static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], const int length, const int eci,
const int last_seg, const int gs1, unsigned char target[], int *p_tp) {
static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int eci, const int last_seg, const int gs1, const int b256_end, const int c40_end,
unsigned char target[], int *p_tp) {
int sp = 0;
int tp = *p_tp;
int current_mode = DM_ASCII;
@@ -1531,9 +1521,9 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
}
/* If FAST_MODE or MAILMARK_2D, do Annex J-based encodation */
if ((symbol->input_mode & FAST_MODE) || symbol->symbology == BARCODE_MAILMARK_2D) {
if ((symbol->input_mode & FAST_MODE) || b256_end || c40_end) {
error_number = dm_isoenc(symbol, source, length, &sp, target, &tp, process_buffer, &process_p,
&b256_start, &current_mode, gs1, debug_print);
&b256_start, &current_mode, gs1, b256_end, c40_end, debug_print);
} else { /* Do default minimal encodation */
error_number = dm_minimalenc(symbol, source, length, last_seg, &sp, target, &tp, process_buffer, &process_p,
&b256_start, &current_mode, gs1, debug_print);
@@ -1681,8 +1671,9 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
#ifdef ZINT_TEST /* Wrapper for direct testing */
INTERNAL int zint_test_dm_encode(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int eci, const int last_seg, const int gs1, unsigned char target[], int *p_tp) {
return dm_encode(symbol, source, length, eci, last_seg, gs1, target, p_tp);
const int eci, const int last_seg, const int gs1, const int b256_end, const int c40_end,
unsigned char target[], int *p_tp) {
return dm_encode(symbol, source, length, eci, last_seg, gs1, b256_end, c40_end, target, p_tp);
}
#endif
@@ -1694,9 +1685,13 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
int i;
int tp = 0;
int in_macro = 0;
int tot_length = 0, b256_have_fnc1 = 0;
const struct zint_seg *last_seg = &segs[seg_count - 1];
/* gs1 flag values: 0: no GS1, 1: GS1 with FNC1 serparator, 2: GS separator */
const int gs1 = (symbol->input_mode & 0x07) == GS1_MODE ? 1 + !!(symbol->output_options & GS1_GS_SEPARATOR) : 0;
const int mailmark = symbol->symbology == BARCODE_MAILMARK_2D;
const int have_c40 = (symbol->option_3 & DM_C40_START) && symbol->option_1 >= 0;
const int have_b256 = (symbol->option_3 & DM_B256_START) && symbol->option_1 >= 0;
/* Raw text dealt with by `ZBarcode_Encode_Segs()`, except for `eci` feedback.
Note not updating `eci` for GS1 mode as not converted */
const int content_segs = !gs1 && (symbol->output_options & BARCODE_CONTENT_SEGS);
@@ -1803,7 +1798,10 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
}
for (i = 0; i < seg_count; i++) {
const unsigned char *source;
int length;
int src_inc = 0, len_dec = 0;
int b256_end = 0, c40_end = 0;
if (in_macro) {
if (i == 0) {
src_inc = len_dec = 7; /* Skip over macro characters at beginning */
@@ -1812,14 +1810,54 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
len_dec += 2; /* Remove RS + EOT from end */
}
}
if ((error_number = dm_encode(symbol, segs[i].source + src_inc, segs[i].length - len_dec, segs[i].eci,
i + 1 == seg_count, gs1, target, &tp))) {
source = segs[i].source + src_inc;
length = segs[i].length - len_dec;
if (mailmark) {
assert(seg_count == 1);
assert(length >= 45);
c40_end = 45; /* Min */
/* Allow specifying greater than 45 */
if (have_c40 && (symbol->option_1 == 0 || symbol->option_1 > 45)) {
c40_end = symbol->option_1 > 0 && symbol->option_1 < length ? symbol->option_1 : length;
}
/* `DM_C40_START` trumps `DM_B256_START` */
} else if (have_c40) {
if (symbol->option_1 == 0) {
c40_end = length;
} else if (symbol->option_1 < tot_length) {
c40_end = 0;
} else {
c40_end = symbol->option_1 - tot_length < length ? symbol->option_1 - tot_length : length;
}
} else if (have_b256) {
if (b256_have_fnc1) {
b256_end = 0;
} else {
if (symbol->option_1 == 0) {
b256_end = length;
} else if (symbol->option_1 < tot_length) {
b256_end = 0;
} else {
b256_end = symbol->option_1 - tot_length < length ? symbol->option_1 - tot_length : length;
}
if (gs1 == 1) {
/* Stop at first FNC1 */
const int b256_len = b256_end;
for (b256_end = 0; b256_end < b256_len && source[b256_end] != '\x1D'; b256_end++);
b256_have_fnc1 = b256_end != b256_len;
}
}
}
if ((error_number = dm_encode(symbol, source, length, segs[i].eci, i + 1 == seg_count, gs1, b256_end, c40_end,
target, &tp))) {
assert(error_number >= ZINT_ERROR);
return error_number;
}
if (content_segs && segs[i].eci) {
z_ct_set_seg_eci(symbol, i, segs[i].eci);
}
tot_length += length;
}
*p_binlen = tp;
@@ -1973,7 +2011,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
INTERNAL int zint_datamatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) {
if (symbol->option_1 <= 1) {
if (symbol->option_1 <= 1 || (symbol->option_3 & DM_B256_C40_START_MASK)) {
/* ECC 200 */
return dm_ecc200(symbol, segs, seg_count);
}
+8 -1
View File
@@ -1569,7 +1569,14 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, const char *filename) {
file = fopen(filename, "rb");
#endif
if (!file) {
ZEXT z_errtxtf(0, symbol, 229, "Unable to read input file (%1$d: %2$s)", errno, strerror(errno));
const int len = (int) strlen(filename);
if (len > 40) {
ZEXT z_errtxtf(0, symbol, 233, "Unable to read input file \"%1$.10s...%2$.30s\" (%3$d: %4$s)",
filename, filename + (len - 30), errno, strerror(errno));
} else {
ZEXT z_errtxtf(0, symbol, 229, "Unable to read input file \"%1$s\" (%2$d: %3$s)",
filename, errno, strerror(errno));
}
return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL);
}
file_opened = 1;
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
# Copyright (C) 2019-2026 Robin Stuart <rstuart114@gmail.com>
# Adapted from qrencode/tests/CMakeLists.txt
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# vim: set ts=4 sw=4 et :
+1 -1
View File
@@ -235,7 +235,7 @@ static const struct settings_item settings[] = {
{ 68, BARCODE_AUSREDIRECT, GDSET_F, 0, -1, 0, -1, 0, -1, 1, 8 },
{ 69, BARCODE_ISBNX, ISBNX_ADDON_SANE_F, 0, -1, 0, -1, 0, -1, 9, 19 },
{ 70, BARCODE_RM4SCC, KRSET_F, 0, -1, 0, -1, 0, -1, 1, 50 },
{ 71, BARCODE_DATAMATRIX, 0, 0, -1, 0, 48, 128, 128, 1, 3550 },
{ 71, BARCODE_DATAMATRIX, 0, 0, 20, 0, 48, 0, 238, 1, 3550 },
{ 72, BARCODE_EAN14, NEON_F, 0, -1, 0, -1, 0, -1, 1, 13 },
{ 73, BARCODE_VIN, ARSENIC_F, 0, -1, 0, -1, 0, -1, 17, 17 },
{ 74, BARCODE_CODABLOCKF, 0, -1, 44, -1, 67, 4, 4, 1, 2725 },
File diff suppressed because it is too large Load Diff
+20 -4
View File
@@ -1524,9 +1524,12 @@ static void test_encode_file_directory(const testCtx *const p_ctx) {
static void test_encode_file(const testCtx *const p_ctx) {
int ret;
struct zint_symbol *symbol = NULL;
const char *data = "1";
const char *filename = "test_encode_file_in.txt";
const char *outfile = "test_encode_file_out.gif";
const char data[] = "1";
const char filename[] = "test_encode_file_in.txt";
const char outfile[] = "test_encode_file_out.gif";
const char long_filename[] = "test_encode_file_in_1234567890123456789012345678901234567890.txt";
const char long_filename_errtxt[]
= "Error 233: Unable to read input file \"test_encod...56789012345678901234567890.txt\" (";
FILE *fp;
(void)p_ctx;
@@ -1580,6 +1583,19 @@ static void test_encode_file(const testCtx *const p_ctx) {
ZBarcode_Delete(symbol);
}
{
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
strcpy(symbol->outfile, outfile);
ret = ZBarcode_Encode_File_and_Buffer_Vector(symbol, long_filename, 0);
assert_nonzero(ret, "ret %d == 0 (%s)\n", ret, symbol->errtxt);
assert_zero(strncmp(symbol->errtxt, long_filename_errtxt, sizeof(long_filename_errtxt) - 1),
"strncmp(%s, %s) != 0\n", symbol->errtxt, long_filename_errtxt);
ZBarcode_Delete(symbol);
}
ret = testUtilRemove(filename);
assert_zero(ret, "testUtilRemove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
@@ -1632,7 +1648,7 @@ static void test_bad_args(const testCtx *const p_ctx) {
"Error 200: Input segments NULL",
"Error 239: Filename NULL",
"Error 778: No input data",
"Error 229: Unable to read input file (", /* Excluding OS-dependent `errno` stuff */
"Error 229: Unable to read input file \"", /* Excluding filename and OS-dependent `errno` stuff */
"Error 771: Too many input segments (maximum 256)",
"Error 205: No input data",
"Error 777: Input too long",
+85 -13
View File
@@ -463,7 +463,9 @@ static void test_2d_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int option_1;
int option_2;
int option_3;
const char *data;
int ret;
@@ -478,7 +480,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
/* Mailmark Barcode Definition Document 15th Feb 2021 (MBDD)
https://www.royalmailtechnical.com/rmt_docs/User_Guides_2021/Mailmark_Barcode_definition_document_20210215.pdf */
static const struct item data[] = {
/* 0*/ { 8, "JGB 01Z999999900000001EC1A1AA1A0SN35TQ ", 0, 24, 24, 1, "MMRLLL Section 2.4 Code Type Format 7 figure **NOT SAME**, figure switches from C40 to ASC to C40 to ASC contrary to spec",
/* 0*/ { -1, 8, -1, "JGB 01Z999999900000001EC1A1AA1A0SN35TQ ", 0, 24, 24, 1, "MMRLLL Section 2.4 Code Type Format 7 figure **NOT SAME**, figure switches from C40 to ASC to C40 to ASC contrary to spec",
"101010101010101010101010"
"110000010100011001100001"
"101001011100001011111010"
@@ -504,7 +506,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
"100111100000101110001010"
"111111111111111111111111"
},
/* 1*/ { 10, "JGB 01Z999999900000001EC1A1AA1A0SN35TQ ", 0, 32, 32, 1, "MMRLLL Section 2.4 Code Type Format 9 figure **NOT SAME**, figure switches as above",
/* 1*/ { -1, 10, -1, "JGB 01Z999999900000001EC1A1AA1A0SN35TQ ", 0, 32, 32, 1, "MMRLLL Section 2.4 Code Type Format 9 figure **NOT SAME**, figure switches as above",
"10101010101010101010101010101010"
"11000001010001111001100100101111"
"10100101110000101011110000000000"
@@ -538,7 +540,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
"11001101100011101011101000001000"
"11111111111111111111111111111111"
},
/* 2*/ { 30, "JGB 01Z999999900000001EC1A1AA1A0SN35TQ ", 0, 16, 48, 1, "MMRLLL Section 2.4 Code Type Format 29 figure **NOT SAME**, figure switches as above",
/* 2*/ { -1, 30, -1, "JGB 01Z999999900000001EC1A1AA1A0SN35TQ ", 0, 16, 48, 1, "MMRLLL Section 2.4 Code Type Format 29 figure **NOT SAME**, figure switches as above",
"101010101010101010101010101010101010101010101010"
"110000010100011001101111111101100101100100011101"
"101001011100001011100010100100011001100010101100"
@@ -556,7 +558,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
"101101100011101110101010100001111111001010100010"
"111111111111111111111111111111111111111111111111"
},
/* 3*/ { 30, "JGB 012100123412345678AB19XY1A 0 REFERENCE 12300AB", 0, 16, 48, 1, "MBDD Table 4 example",
/* 3*/ { -1, 30, -1, "JGB 012100123412345678AB19XY1A 0 REFERENCE 12300AB", 0, 16, 48, 1, "MBDD Table 4 example",
"101010101010101010101010101010101010101010101010"
"110000010100010110001111111011100000001001111111"
"101001011100011001110010100100010100110011111100"
@@ -574,7 +576,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
"101111100001111111101010100010111101100101001100"
"111111111111111111111111111111111111111111111111"
},
/* 4*/ { 10, "JGB 012100123412345678AB19XY1A 0 www.xyz.com", 0, 32, 32, 1, "MBDD Table 5 (& BWIPP) example",
/* 4*/ { -1, 10, -1, "JGB 012100123412345678AB19XY1A 0 www.xyz.com", 0, 32, 32, 1, "MBDD Table 5 (& BWIPP) example",
"10101010101010101010101010101010"
"11000001010001011111111110001111"
"10100101110001101001111111000000"
@@ -608,7 +610,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
"11000011100001101111110101011100"
"11111111111111111111111111111111"
},
/* 5*/ { 10, "JGB 010100000700009001B707RH1A 0SN35XX ABCDEFGHIJ1234567890ABCDEFGHIJ1234567890A", 0, 32, 32, 1, "TEC-IT example, same",
/* 5*/ { -1, 10, -1, "JGB 010100000700009001B707RH1A 0SN35XX ABCDEFGHIJ1234567890ABCDEFGHIJ1234567890A", 0, 32, 32, 1, "TEC-IT example, same",
"10101010101010101010101010101010"
"11000001010001111000100110110001"
"10100101110000101010110010100000"
@@ -642,7 +644,75 @@ static void test_2d_encode(const testCtx *const p_ctx) {
"10111101100000001010110001010110"
"11111111111111111111111111111111"
},
/* 6*/ { 10, "JGB 010100000700009001B707RH1A 0SN35XX é", 0, 32, 32, 1, "",
/* 6*/ { -1, 10, -1, "JGB 010100000700009001B707RH1A 0SN35XX é", 0, 32, 32, 1, "",
"10101010101010101010101010101010"
"11000001010001111001101100001111"
"10100101110000101011111110000000"
"10101000010110011001101011000101"
"10001100111000101111000111011110"
"10011100011000011100101000100101"
"11001111001000101010010010011110"
"10100101011000111100001100101111"
"10101111010111101100111100110100"
"11001001100100111001110000010111"
"11001000001001001101001111011110"
"11010000001111111011011101101101"
"11001000010000101001101010011010"
"11010111000101011111111101111111"
"10111101100011101110001100110100"
"11111111111111111111111111111111"
"10101010101010101010101010101010"
"11011101100000011000000001110001"
"11110000111100101000011000101010"
"11001011110010011000011101110001"
"11011111000101001011100101011100"
"10010101101100011100010000011101"
"10011001101011101110100111101000"
"11101010110010111001111100100101"
"10011011111101001000101111110100"
"10011101010101111111111000111101"
"11100001010010101011001010000000"
"10011010101011111000011010001001"
"11101001100100001101010001011000"
"10001001100100011011110101100101"
"11001011100001001010111101010100"
"11111111111111111111111111111111"
},
/* 7*/ { 0, 10, DM_C40_START, "JGB 010100000700009001B707RH1A 0SN35XX é", 0, 32, 32, 0, "BWIPP fixes c40headerlength at 45",
"10101010101010101010101010101010"
"11000001010001111000000111101111"
"10100101110000101010011111000000"
"10101000010110011000111011000101"
"10001100111000101111000111011110"
"10011100011000011100101000100101"
"11001111001000101010010010011110"
"10100101011000111100001100101111"
"10101111010111101100111100110100"
"11001001100100111001110000010111"
"11001000001001001101000111010010"
"11010000001111111011011111100001"
"11001000010000101001010110001010"
"11010111000101011111111010110011"
"10111101100011101111010010010000"
"11111111111111111111111111111111"
"10101010101010101010101010101010"
"11011101100000011011100000000001"
"11110000111100001001011110110010"
"11001011110010011010101001010001"
"11011111000110001011101010011000"
"10010101101100011010001110010101"
"10011001101111101011100011110000"
"11101010110000011011000010101101"
"10011011011100101100100000010110"
"10011101010111111011000011110101"
"11100001000100101110110101110000"
"10011000100011011101111110110001"
"11100100110001001010010111001100"
"10001001110001011010101100000001"
"11000001100010101010110110001100"
"11111111111111111111111111111111"
},
/* 8*/ { 40, 10, DM_C40_START, "JGB 010100000700009001B707RH1A 0SN35XX é", 0, 32, 32, 1, "",
"10101010101010101010101010101010"
"11000001010001111001101100001111"
"10100101110000101011111110000000"
@@ -699,7 +769,7 @@ static void test_2d_encode(const testCtx *const p_ctx) {
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_MAILMARK_2D, -1 /*input_mode*/, -1 /*eci*/,
-1 /*option_1*/, data[i].option_2, -1 /*option_3*/, -1 /*output_options*/,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
@@ -707,8 +777,9 @@ static void test_2d_encode(const testCtx *const p_ctx) {
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
printf(" /*%3d*/ { %d, %d, %s, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, data[i].option_1, data[i].option_2, testUtilOption3Name(symbol->symbology, data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
testUtilModulesPrint(symbol, " ", "\n");
printf(" },\n");
@@ -725,15 +796,16 @@ static void test_2d_encode(const testCtx *const p_ctx) {
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n",
i, ret, width, row, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3,
debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, cmp_buf,
sizeof(cmp_buf), NULL);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, data[i].option_3,
data[i].data, length, NULL, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
+22 -8
View File
@@ -624,20 +624,27 @@ const char *testUtilOption3Name(int symbology, int option_3) {
} else {
name = (option_3 & 0xFF) ? "-1" : "0";
}
} else if (symbology == BARCODE_DATAMATRIX || symbology == BARCODE_HIBC_DM) {
} else if (symbology == BARCODE_DATAMATRIX || symbology == BARCODE_HIBC_DM || symbology == BARCODE_MAILMARK_2D) {
if (option_3 > 0) {
if ((option_3 & 0x7F) == DM_SQUARE) {
/* Note only catering for commonly used combinations here */
if ((option_3 & DM_SQUARE_DMRE_MASK) == DM_SQUARE) {
if ((option_3 & DM_ISO_144) == DM_ISO_144) {
name = "DM_SQUARE | DM_ISO_144";
} else {
name = "DM_SQUARE";
}
} else if ((option_3 & 0x7F) == DM_DMRE) {
} else if ((option_3 & DM_SQUARE_DMRE_MASK) == DM_DMRE) {
if ((option_3 & DM_ISO_144) == DM_ISO_144) {
name = "DM_DMRE | DM_ISO_144";
} else {
name = "DM_DMRE";
}
} else if ((option_3 & DM_B256_C40_START_MASK) == DM_B256_C40_START_MASK) {
name = "DM_B256_START | DM_C40_START";
} else if ((option_3 & DM_B256_C40_START_MASK) == DM_B256_START) {
name = "DM_B256_START";
} else if ((option_3 & DM_B256_C40_START_MASK) == DM_C40_START) {
name = "DM_C40_START";
} else if ((option_3 & DM_ISO_144) == DM_ISO_144) {
name = "DM_ISO_144";
} else {
@@ -2380,7 +2387,7 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
{ "", BARCODE_AUSREDIRECT, 68, 0, 0, 0, 0, 0, },
{ "isbn", BARCODE_ISBNX, 69, 0, 1, 0, 0, 1 /*gs1_cvt*/, },
{ "royalmail", BARCODE_RM4SCC, 70, 0, 0, 0, 0, 0, },
{ "datamatrix", BARCODE_DATAMATRIX, 71, 0, 1, 1, 1, 0, },
{ "datamatrix", BARCODE_DATAMATRIX, 71, 1, 1, 1, 1, 0, },
{ "ean14", BARCODE_EAN14, 72, 0, 0, 1 /*GS1CARET*/, 0, 1 /*gs1_cvt*/, },
{ "code39", BARCODE_VIN, 73, 0, 0, 0, 0, 0, },
{ "codablockf", BARCODE_CODABLOCKF, 74, 1, 1, 0, 10 /*linear_row_height*/, 0, },
@@ -2411,7 +2418,7 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
{ "hibccode39", BARCODE_HIBC_39, 99, 0, 0, 0, 0, 0, },
{ "", -1, 100, 0, 0, 0, 0, 0, },
{ "", -1, 101, 0, 0, 0, 0, 0, },
{ "hibcdatamatrix", BARCODE_HIBC_DM, 102, 0, 1, 1, 0, 0, },
{ "hibcdatamatrix", BARCODE_HIBC_DM, 102, 1, 1, 1, 0, 0, },
{ "", -1, 103, 0, 0, 0, 0, 0, },
{ "hibcqrcode", BARCODE_HIBC_QR, 104, 1, 1, 1, 0, 0, },
{ "", -1, 105, 0, 0, 0, 0, 0, },
@@ -2428,7 +2435,7 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
{ "hanxin", BARCODE_HANXIN, 116, 0, 0, 0, 0, 0, },
{ "", -1, 117, 0, 0, 0, 0, 0, },
{ "", -1, 118, 0, 0, 0, 0, 0, },
{ "mailmark", BARCODE_MAILMARK_2D, 119, 0, 1, 0, 0, 0, },
{ "mailmark", BARCODE_MAILMARK_2D, 119, 1, 1, 1, 0, 0, },
{ "code128", BARCODE_UPU_S10, 120, 0, 0, 0, 0, 0, },
{ "", BARCODE_MAILMARK_4S, 121, 0, 0, 0, 0, 0, }, /* Note BWIPP mailmark is BARCODE_MAILMARK_2D above */
{ "", -1, 122, 0, 0, 0, 0, 0, },
@@ -3446,8 +3453,9 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
added_dmre = 1;
}
}
if ((option_3 & 0x7F) != DM_SQUARE && symbol->width != symbol->height) {
if ((option_3 & 0x7F) == DM_DMRE && !added_dmre) {
if ((option_3 == -1 || (option_3 & DM_SQUARE_DMRE_MASK) != DM_SQUARE)
&& symbol->width != symbol->height) {
if (option_3 != -1 && (option_3 & DM_SQUARE_DMRE_MASK) == DM_DMRE && !added_dmre) {
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : "");
/*added_dmre = 1; */
}
@@ -3455,6 +3463,12 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
strlen(bwipp_opts_buf) ? " " : "");
bwipp_opts = bwipp_opts_buf;
}
if (option_3 != -1 && option_1 >= 0 &&
((option_3 & DM_B256_C40_START_MASK) == DM_C40_START
|| (option_3 & DM_B256_C40_START_MASK) == DM_B256_C40_START_MASK)) { /* DM_C40_START trumps */
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sc40headerlength=%d",
strlen(bwipp_opts_buf) ? " " : "", option_1 ? option_1 : 9999);
}
if (option_3 != -1) {
bwipp_opts = bwipp_opts_buf;
}
Binary file not shown.
+1
View File
@@ -103,6 +103,7 @@ static int tif_lzw_putCode(struct filemem *fmp, const int code, const int bitsPe
"manuscript in public domain" according to "Encyclopedia of Graphics File Formats" (2nd edition, 1996)
by James D. Murray and William vanRyper, Chapter 9 "Data Compression", p.178
*/
/* Copyright (C) 1988 Bob Montgomery */
static int tif_lzw_compress(struct filemem *fmp, const unsigned char *bp, const unsigned int blen) {
short suffixes[TIF_LZW_TABLE_SIZE] = {0}; /* "shade[]" in Montgomery diagram */
/* A child is made up of a parent (or prefix) code plus a suffix byte
+9 -3
View File
@@ -332,9 +332,15 @@ extern "C" {
#define ZINT_AZTEC_FULL 128 /* Only consider Full versions on automatic symbol size selection */
/* Data Matrix specific options (`symbol->option_3`) */
#define DM_SQUARE 100 /* Only consider square versions on automatic symbol size selection */
#define DM_DMRE 101 /* Consider DMRE versions on automatic symbol size selection */
#define DM_ISO_144 128 /* Use ISO instead of "de facto" format for 144x144 (i.e. don't skew ECC) */
/* OR-able, but only one of DM_BASE_256_START/DM_C40_START, and only one of DM_SQUARE/DM_DMRE */
#define DM_B256_START 0x02 /* Use Base 256 encodation initially, length given in `option_1` (0 = all) */
#define DM_C40_START 0x08 /* Use C40 encodation initially, length given in `option_1` (0 = all) */
#define DM_SQUARE 0x64 /* Only consider square versions on automatic symbol size selection */
#define DM_DMRE 0x65 /* Consider DMRE versions on automatic symbol size selection */
#define DM_ISO_144 0x80 /* Use ISO instead of "de facto" format for 144x144 (i.e. don't skew ECC) */
/* Masks for testing the exclusive pairs above */
#define DM_B256_C40_START_MASK 0x0A /* DM_B256_START or DM_C40_START */
#define DM_SQUARE_DMRE_MASK 0x65 /* DM_SQUARE or DM_DMRE */
/* QR, Han Xin, Grid Matrix specific options (`symbol->option_3`) */
#define ZINT_FULL_MULTIBYTE 200 /* Enable Kanji/Hanzi compression for Latin-1 & binary data */