1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-07-31 02:19:50 +00:00
template, props Dmitry Smirnov (ticket #147, props John Crisp);
  TODO: enable building with the GS1 Syntax Engine;
  this involved auditing copyrights which prompted the next item
  re "tif.c" and will prompt the next next item "pdf417.c"
tif.c: replaced LZW compression with tree-based one due to
  "tif_lzw.h"'s original BSD-TAHOE license which has the equivalent
  of the "advertising clause", new implementation (which is much
  faster anyway) props Harald Kuhr and Bob Montgomery
pdf417.c: TODO: Replace all code adapted from "pdf417.frm" as it
  was released under GPL v2.0 or later
pdf417.h: replace unnecessary "pdf417.frm" references with ISO/IEC
  standard as 1st step re above, some expanded comments
general: Codablock-F -> Codablock F (i.e. lose hyphen)
cmake: frontend/frontend_qt: go back to only setting RPATH on macOS
  as not Debian compatible and it seems it's not a good idea on
  Linux anyway; TODO: check BSD + other Unixes
CLI/GUI: make "--verbose" option official and document
tools/gen_eci_sb_h.php/gen_eci_mb_h.php: add SPDX Unicode-3.0;
  update haible.de/bruno tarball info - "GB18030.TXT" no longer in
  "jdk-1.4.2/" so mention "libiconv-1.11/" version instead (same)
general: add various SPDXs and normalize some Copyrights
reedsol.c: malloced `logt`/`alog` tables int -> short (slight
  performance improvement)
aztec.c: add copyrights, some code fiddling
BWIPP: update to latest
This commit is contained in:
gitlost
2026-03-18 15:08:32 +00:00
parent db03f0b304
commit df64a0f237
70 changed files with 1404 additions and 755 deletions
+5 -5
View File
@@ -1,10 +1,10 @@
Contents
--------
2025-01-21
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
@@ -40,7 +40,7 @@ codabar.c:
Codabar
codablock.c:
Codablock-F
Codablock F
code11.c:
Code 11
+12 -22
View File
@@ -96,9 +96,9 @@ static int az_reduce(char *modes, unsigned char *source, const int length) {
modes[j] = modes[i];
if ((modes[i] == AZ_P || (modes[i] & AZ_PS)) && AZ_DOUBLE_PUNCT_NO_LEN_CHECK(source, i)) {
if (source[i] == '\r') {
source[j] = 'a'; /* "\r\n" */
source[j] = 'a'; /* (CR LF) */
} else {
source[j] = 'b' + 7 - ((source[i] & 0x0F) >> 1); /* ". " -> 'b', ", " -> 'c', ": " -> 'd' */
source[j] = 'b' + 7 - ((source[i] & 0x0F) >> 1); /* (. SP) -> 'b', (, SP) -> 'c', (: SP) -> 'd' */
}
i += 2;
} else {
@@ -124,7 +124,7 @@ static char az_mode_char(const char mode) {
if (mode & AZ_US) {
assert(AZ_MASK(mode) == AZ_L || AZ_MASK(mode) == AZ_D);
return AZ_MASK(mode) == AZ_L ? 'r' : 't';
return AZ_MASK(mode) == AZ_L ? 'K' : 'C';
}
assert(AZ_MASK(mode) < ARRAY_SIZE(mode_chars));
@@ -164,7 +164,7 @@ static int az_text_modes(char modes[], unsigned char source[], int length, const
}
}
/* Deal first with letter combinations which can be combined to one codeword
/* Deal first with letter combinations which can be combined to one codeword.
Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode */
current_mode = initial_mode;
for (i = 0; i + 1 < length; i++) {
@@ -182,26 +182,14 @@ static int az_text_modes(char modes[], unsigned char source[], int length, const
count = az_count_doubles(source, length, i);
next_mode = az_get_next_mode(modes, length, i);
if (current_mode == AZ_U) {
if (next_mode == AZ_D && count <= 5) {
if (next_mode == AZ_D) {
if ((current_mode == AZ_U && count <= 5) || (current_mode == AZ_L && count <= 4)
|| (current_mode == AZ_M && count == 1) || (current_mode == AZ_D && count <= 7)) {
memset(modes + i, AZ_D, 2 * count);
}
} else if (current_mode == AZ_L) {
if (next_mode == AZ_D && count <= 4) {
memset(modes + i, AZ_D, 2 * count);
}
} else if (current_mode == AZ_M) {
if (next_mode == AZ_D && count == 1) {
modes[i] = AZ_D;
modes[i + 1] = AZ_D;
}
} else if (current_mode == AZ_D) {
if ((next_mode != AZ_D && count <= 4) || (next_mode == AZ_D && count <= 7)) {
memset(modes + i, AZ_D, 2 * count);
}
} else if (current_mode == AZ_D && count <= 4) {
memset(modes + i, AZ_D, 2 * count);
}
/* Default is Punct mode */
@@ -976,6 +964,8 @@ static int az_UpdateStateListForChar(struct az_state_list *list, const unsigned
/* Default, optimized encodation algorithm by Frank Yellin and Rustam Abdullaev, adapted from ZXing via zxing-cpp's
`HighLevelEncoder::Encode()` & slightly improved */
/* Copyright 2013 ZXing authors */ /* ZXing */
/* Copyright 2016 Huy Cuong Nguyen */ /* zxing-cpp */
/* SPDX-License-Identifier: Apache-2.0 */
/* Note that a bitstream that is encoded to be shortest based on mode choices may not be so after bit-stuffing */
static int az_binary_string(unsigned char source[], const int length, int bp,
@@ -1002,7 +992,7 @@ static int az_binary_string(unsigned char source[], const int length, int bp,
fprintf(stderr, "index %d\n", (int) i);
#endif
if (AZ_DOUBLE_PUNCT(source, length, i)) {
/* "\r\n" -> 2, ". " -> 3, ", " -> 4, ": " -> 5 */
/* (CR LF) -> 2, (. SP) -> 3, (, SP) -> 4, (: SP) -> 5 */
const int pairCode = source[i] == '\r' ? 2 : 3 + 7 - ((source[i] & 0x0F) >> 1);
if (!az_UpdateStateListForPair(list, i, pairCode)) {
az_state_list_free(list);
+1
View File
@@ -30,6 +30,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_BIG5_H
#define Z_BIG5_H
+3 -3
View File
@@ -1,4 +1,4 @@
/* codablock.c - Handles Codablock-F */
/* codablock.c - Handles Codablock F */
/*
libzint - the open source barcode library
Copyright (C) 2016-2026 Harald Oehlmann
@@ -50,7 +50,7 @@
#define ZTNum (CodeA | CodeB | CodeC)
#define ZTFNC1 (CodeA | CodeB | CodeC | CodeFNC1)
/* ASCII-Extension for Codablock-F */
/* ASCII-Extension for Codablock F */
#define aFNC1 ((uchar) 128)
#define aFNC2 ((uchar) 129)
#define aFNC3 ((uchar) 130)
@@ -513,7 +513,7 @@ static void ASCIIZ128(uchar **ppOutPos, const int CharacterSet, const uchar c1,
A2C128_C(ppOutPos, c1, c2);
}
/* XLate Tables D.2, D.3 and F.1 of Codablock-F Specification and call output
/* XLate Tables D.2, D.3 and F.1 of Codablock F Specification and call output
*/
static void SumASCII(uchar **ppOutPos, const int Sum, const int CharacterSet) {
switch (CharacterSet) {
+1
View File
@@ -697,6 +697,7 @@ INTERNAL unsigned int z_decode_utf8(unsigned int *state, unsigned int *codep, co
See https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
*/
/* SPDX-License-Identifier: Apache-2.0 */
static const unsigned char utf8d[] = {
/* The first part of the table maps bytes to character classes that
+2 -1
View File
@@ -1,7 +1,7 @@
/* composite.c - Handles GS1 Composite Symbols */
/*
libzint - the open source barcode library
Copyright (C) 2008-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -809,6 +809,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
/* So still need FNC1 character but can't do single FNC1 in numeric mode, so insert alphanumeric latch
"0000" and alphanumeric FNC1 "01111" (this implementation detail taken from BWIPP
https://github.com/bwipp/postscriptbarcode Copyright (c) 2004-2019 Terry Burton) */
/* SPDX-License-Identifier: MIT */
bp = z_bin_append_posn(15, 9, binary_string, bp); /* "000001111" */
/* Note an alphanumeric FNC1 is also a numeric latch, so now in numeric mode */
}
+2 -2
View File
@@ -8,8 +8,8 @@
Adrian Kennard, Andrews & Arnold Ltd
with help from Cliff Hones on the RS coding
(c) 2004 Adrian Kennard, Andrews & Arnold Ltd
(c) 2006 Stefan Schmidt <stefan@datenfreihafen.org>
Copyright (c) 2004 Adrian Kennard, Andrews & Arnold Ltd
Copyright (c) 2006 Stefan Schmidt <stefan@datenfreihafen.org>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
+2 -1
View File
@@ -4,7 +4,7 @@
"https://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP125*.TXT" */
/*
libzint - the open source barcode library
Copyright (C) 2021-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -32,6 +32,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_ECI_SB_H
#define Z_ECI_SB_H
+2 -1
View File
@@ -1,5 +1,5 @@
/* gb18030.h - tables for Unicode to GB 18030-2005, generated by "backend/tools/gen_eci_mb_h.php"
from "jdk-1.4.2/GB18030.TXT"
from "libiconv-1.11/GB18030.TXT"
(see https://haible.de/bruno/charsets/conversion-tables/GB18030.tar.bz2) */
/*
libzint - the open source barcode library
@@ -31,6 +31,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_GB18030_H
#define Z_GB18030_H
+1
View File
@@ -31,6 +31,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_GB2312_H
#define Z_GB2312_H
+1
View File
@@ -30,6 +30,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_GBK_H
#define Z_GBK_H
+2 -1
View File
@@ -1,7 +1,7 @@
/* gridmtx.c - Grid Matrix */
/*
libzint - the open source barcode library
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -127,6 +127,7 @@ static int gm_in_numeral(const unsigned int ddata[], const int length, const int
/* Calculate optimized encoding modes. Adapted from Project Nayuki */
/* Copyright (c) Project Nayuki. (MIT License) See qr.c for detailed notice */
/* SPDX-License-Identifier: MIT */
static void gm_define_modes(char *modes, const unsigned int ddata[], const int length, const int debug_print) {
/* Must be in same order as GM_H etc */
static const char mode_types[] = { GM_CHINESE, GM_NUMBER, GM_LOWER, GM_UPPER, GM_MIXED, GM_BYTE, '\0' };
+1 -1
View File
@@ -1758,7 +1758,7 @@ static int gs1se_verify(struct zint_symbol *symbol, const unsigned char source[]
} else if (gs1raw_mode && !is_digital_link) {
if (symbol->symbology == BARCODE_GS1_128 || symbol->symbology == BARCODE_DBAR_EXP
|| symbol->symbology == BARCODE_DBAR_EXPSTK || z_is_fixed_ratio(symbol->symbology)
|| symbol->symbology == BARCODE_CODABLOCKF) { /* Codablock-F will be GS1-enabled in the future */
|| symbol->symbology == BARCODE_CODABLOCKF) { /* Codablock F will be GS1-enabled in the future */
/* Prefix caret */
local_source_buf[0] = '^';
if (source[0] == '\x1D') { /* Allow initial GS */
+2 -1
View File
@@ -1,7 +1,7 @@
/* hanxin.c - Han Xin Code */
/*
libzint - the open source barcode library
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -353,6 +353,7 @@ static int hx_in_fourbyte(const unsigned int ddata[], const int length, const in
/* Calculate optimized encoding modes. Adapted from Project Nayuki */
/* Copyright (c) Project Nayuki. (MIT License) See qr.c for detailed notice */
/* SPDX-License-Identifier: MIT */
static void hx_define_modes(char *modes, const unsigned int ddata[], const int length, const int debug_print) {
/* Must be in same order as HX_N etc */
static const char mode_types[] = { 'n', 't', 'b', '1', '2', 'd', 'f', '\0' };
+1
View File
@@ -30,6 +30,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_KSX1001_H
#define Z_KSX1001_H
+1 -1
View File
@@ -457,7 +457,7 @@ static int hibc(struct zint_symbol *symbol, struct zint_seg segs[], const int se
if (symbol->debug & ZINT_DEBUG_PRINT) printf("HIBC processed source: %s\n", to_process);
/* Code 128, Code 39 & Codablock-F set `content_segs` themselves, but the others don't, so do it now */
/* Code 128, Code 39 & Codablock F set `content_segs` themselves, but the others don't, so do it now */
assert(!symbol->content_segs); /* HIBC symbologies don't satisfy `supports_non_iso8859_1()` */
if (content_segs && symbol->symbology != BARCODE_HIBC_128 && symbol->symbology != BARCODE_HIBC_39
&& symbol->symbology != BARCODE_HIBC_BLOCKF) {
+2 -1
View File
@@ -1,7 +1,7 @@
/* pcx.c - Handles output to ZSoft PCX file */
/*
libzint - the open source barcode library
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -126,6 +126,7 @@ INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char
/* Based on ImageMagick/coders/pcx.c PCXWritePixels()
* Copyright 1999-2020 ImageMagick Studio LLC */
/* SPDX-License-Identifier: ImageMagick */
previous = rle_row[0];
run_count = 1;
for (column = 1; column < bytes_per_line; column++) { /* Note going up to bytes_per_line */
+13 -12
View File
@@ -32,9 +32,16 @@
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/*
*********************************************************************************************
* TODO: Replace all code adapted from "pdf417.frm" as it was released under GPL v2.0 or later
*********************************************************************************************
*/
/* This code is adapted from "Code barre PDF 417 / PDF 417 barcode" v2.5.0
which is Copyright (C) 2004 (Grandzebu).
The original code (file pdf417.frm) can be downloaded from https://grandzebu.net/informatique/codbar/pdf417.zip */
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* NOTE: symbol->option_1 is used to specify the security level (i.e. control the
number of check codewords)
@@ -1432,13 +1439,11 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int
bp = z_bin_append_posn(0x1FEA8, 17, pattern, bp); /* Row start */
for (j = 0; j <= cols; j++) {
bp = z_bin_append_posn(zint_pdf_bitpattern[offset + dummy[j]], 16, pattern, bp);
pattern[bp++] = '0';
bp = z_bin_append_posn(((int) zint_pdf_bitpattern[offset + dummy[j]]) << 1, 17, pattern, bp);
}
if (symbol->symbology != BARCODE_PDF417COMP) {
bp = z_bin_append_posn(zint_pdf_bitpattern[offset + dummy[j]], 16, pattern, bp);
pattern[bp++] = '0';
bp = z_bin_append_posn(((int) zint_pdf_bitpattern[offset + dummy[j]]) << 1, 17, pattern, bp);
bp = z_bin_append_posn(0x3FA29, 18, pattern, bp); /* Row Stop */
} else {
pattern[bp++] = '1'; /* Compact PDF417 Stop pattern */
@@ -1761,23 +1766,19 @@ INTERNAL int zint_micropdf417(struct zint_symbol *symbol, struct zint_seg segs[]
/* Copy the data into codebarre */
bp = z_bin_append_posn(zint_pdf_rap_side[LeftRAP - 1], 10, pattern, bp);
bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k]], 16, pattern, bp);
pattern[bp++] = '0';
bp = z_bin_append_posn(((int) zint_pdf_bitpattern[offset + chainemc[k]]) << 1, 17, pattern, bp);
if (symbol->option_2 >= 2) {
if (symbol->option_2 == 3) {
bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp);
}
bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 1]], 16, pattern, bp);
pattern[bp++] = '0';
bp = z_bin_append_posn(((int) zint_pdf_bitpattern[offset + chainemc[k + 1]]) << 1, 17, pattern, bp);
if (symbol->option_2 >= 3) {
if (symbol->option_2 == 4) {
bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp);
}
bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 2]], 16, pattern, bp);
pattern[bp++] = '0';
bp = z_bin_append_posn(((int) zint_pdf_bitpattern[offset + chainemc[k + 2]]) << 1, 17, pattern, bp);
if (symbol->option_2 == 4) {
bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 3]], 16, pattern, bp);
pattern[bp++] = '0';
bp = z_bin_append_posn(((int) zint_pdf_bitpattern[offset + chainemc[k + 3]]) << 1, 17, pattern, bp);
}
}
}
+20 -17
View File
@@ -1,7 +1,7 @@
/* pdf417_tabs.h - PDF417 tables and coefficients */
/*
libzint - the open source barcode library
Copyright (C) 2008-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008-2026 Robin Stuart <rstuart114@gmail.com>
Portions Copyright (C) 2004 Grandzebu
Redistribution and use in source and binary forms, with or without
@@ -31,9 +31,6 @@
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* this file contains the character table, the pre-calculated coefficients and the
codeword patterns taken from lines 416 to 454 of pdf417.frm */
/* See "pdf417.h" for declarations */
#ifndef Z_PDF417_TABS_H
@@ -43,31 +40,32 @@
extern "C" {
#endif /* __cplusplus */
/* PDF417 error correction coefficients from Grand Zebu */
/* PDF417 error correction coefficients from ISO/IEC 15438:2015 Annex F, Tables F.1 to F.9
k is no. of EC codewords */
INTERNAL_DATA const unsigned short zint_pdf_coefrs[1022] = {
/* k = 2 */
/* Table F.1, k = 2 */
27, 917,
/* k = 4 */
/* Table F.2, k = 4 */
522, 568, 723, 809,
/* k = 8 */
/* Table F.3, k = 8 */
237, 308, 436, 284, 646, 653, 428, 379,
/* k = 16 */
/* Table F.4, k = 16 */
274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65,
/* k = 32 */
/* Table F.5, k = 32 */
361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517,
273, 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410,
/* k = 64 */
/* Table F.6, k = 64 */
539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612,
723, 476, 462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184,
440, 35, 519, 31, 460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502,
648, 733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, 623, 264, 543,
/* k = 128 */
/* Table F.7, k = 128 */
521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415,
822, 93, 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704,
516, 258, 457, 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569,
@@ -77,7 +75,7 @@ INTERNAL_DATA const unsigned short zint_pdf_coefrs[1022] = {
157, 374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, 587, 804, 34,
211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550, 86, 801, 4, 108, 539,
/* k = 256 */
/* Table F.8, k = 256 */
524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720,
858, 194, 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757,
710, 814, 919, 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137,
@@ -95,7 +93,7 @@ INTERNAL_DATA const unsigned short zint_pdf_coefrs[1022] = {
609, 829, 189, 20, 167, 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173,
404, 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, 55, 497, 10,
/* k = 512 */
/* Table F.9, k = 512 */
352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492,
197, 265, 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781,
846, 75, 327, 520, 435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534,
@@ -130,7 +128,11 @@ INTERNAL_DATA const unsigned short zint_pdf_coefrs[1022] = {
63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263
};
INTERNAL_DATA const unsigned short zint_pdf_bitpattern[2787] = {
/* Encoding/decoding table of PDF417 symbol character bar-space sequences from ISO/IEC 15438:2015 Annex A
e.g. 1st entry B SBSBSB S
3 111113 6
11101010111000000 = 1110 1010 1110 0000 with last space implied = 0xEAE0 */
INTERNAL_DATA const unsigned short zint_pdf_bitpattern[2787] = { /* 2787 = 929 * 3 */
0xEAE0, 0xF578, 0xFABE, 0xEA70, 0xF53C, 0xFA9F, 0xD460, 0xEA38, 0xD430, 0xA820,
0xD418, 0xA810, 0xD6E0, 0xEB78, 0xF5BE, 0xD670, 0xEB3C, 0xF59F, 0xAC60, 0xD638,
0xAC30, 0xAEE0, 0xD778, 0xEBBE, 0xAE70, 0xD73C, 0xEB9F, 0xAE38, 0xD71E, 0xAF78,
@@ -412,7 +414,8 @@ INTERNAL_DATA const unsigned short zint_pdf_bitpattern[2787] = {
0xC3EA, 0xC3E9, 0x83CA, 0x87DA, 0x83C9, 0x87D9, 0xE3F5
};
/* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F */
/* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F
Note from Table 1 minimum no. of EC codewords (k) is 7, so don't need the entries for 3 to 6 */
INTERNAL_DATA const unsigned short zint_pdf_Microcoeffs[344] = {
/* k = 7 */
76, 925, 537, 597, 784, 691, 437,
@@ -486,7 +489,7 @@ INTERNAL_DATA const unsigned short zint_pdf_MicroVariants[136] = { /*34*4*/
};
/* rows, columns, error codewords, k-offset */
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */
/* Following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 Tables 10, 11 and 12 */
INTERNAL_DATA const char zint_pdf_RAPTable[136] = { /*34*4*/
1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25,
+1
View File
@@ -230,6 +230,7 @@ static void qr_define_modes(char modes[], const unsigned int ddata[], const int
* - The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
/* SPDX-License-Identifier: MIT */
unsigned int state[11] = {
0 /*N*/, 0 /*A*/, 0 /*B*/, 0 /*K*/, /* Head/switch costs */
0 /*version*/,
+9 -9
View File
@@ -1,10 +1,10 @@
/*
This is a simple Reed-Solomon encoder
(C) Cliff Hones 2004
Copyright (C) Cliff Hones 2004
*/
/*
libzint - the open source barcode library
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -251,17 +251,17 @@ INTERNAL void zint_rs_encode_uint(const rs_t *rs, const int datalen, const unsig
/* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */
INTERNAL int zint_rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) {
int b, p, v;
unsigned int *logt, *alog;
unsigned short *logt, *alog;
b = logmod + 1;
rs_uint->logt = NULL;
rs_uint->alog = NULL;
if (!(logt = (unsigned int *) calloc(b, sizeof(unsigned int)))) {
if (!(logt = (unsigned short *) calloc(b, sizeof(unsigned short)))) {
return 0;
}
if (!(alog = (unsigned int *) calloc(b * 2, sizeof(unsigned int)))) {
if (!(alog = (unsigned short *) calloc(b * 2, sizeof(unsigned short)))) {
free(logt);
return 0;
}
@@ -282,8 +282,8 @@ INTERNAL int zint_rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_p
INTERNAL void zint_rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) {
int i, k;
const unsigned int *const logt = rs_uint->logt;
const unsigned int *const alog = rs_uint->alog;
const unsigned short *const logt = rs_uint->logt;
const unsigned short *const alog = rs_uint->alog;
unsigned short *rspoly = rs_uint->rspoly;
unsigned int *log_rspoly = rs_uint->log_rspoly;
@@ -315,8 +315,8 @@ INTERNAL void zint_rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int ind
INTERNAL void zint_rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data,
unsigned int *res) {
int i, k;
const unsigned int *const logt = rs_uint->logt;
const unsigned int *const alog = rs_uint->alog;
const unsigned short *const logt = rs_uint->logt;
const unsigned short *const alog = rs_uint->alog;
const unsigned short *const rspoly = rs_uint->rspoly;
const unsigned int *const log_rspoly = rs_uint->log_rspoly;
const int nsym = rs_uint->nsym;
+3 -3
View File
@@ -4,7 +4,7 @@
*/
/*
libzint - the open source barcode library
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -51,8 +51,8 @@ typedef struct {
} rs_t;
typedef struct {
unsigned int *logt; /* These are malloced */
unsigned int *alog;
unsigned short *logt; /* These are malloced */
unsigned short *alog;
unsigned short rspoly[4096]; /* Generated poly, 12-bit max - needs to be enlarged if > 12-bit used */
unsigned int log_rspoly[4096]; /* Logs of poly */
int nsym; /* Degree of poly */
+1
View File
@@ -30,6 +30,7 @@
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_SJIS_H
#define Z_SJIS_H
+2 -2
View File
@@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2019-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -45,7 +45,7 @@
INTERNAL int zint_test_u_gb18030_int(const unsigned int u, unsigned int *dest1, unsigned int *dest2);
/* As control convert to GB 18030 using table generated from GB18030.TXT plus simple processing.
The version of GB18030.TXT is jdk-1.4.2/GB18030.TXT taken from
The version of GB18030.TXT is libiconv-1.11/GB18030.TXT taken from
https://haible.de/bruno/charsets/conversion-tables/GB18030.html
The generated file backend/tests/test_gb18030_tab.h does not include U+10000..10FFFF codepoints to save space.
See also backend/tests/tools/data/GB18030.TXT.README and backend/tests/tools/gen_test_tab.php.
+1 -1
View File
@@ -2712,7 +2712,7 @@ static void test_input_mode(const testCtx *const p_ctx) {
/* 40*/ { BARCODE_AZTEC, "^1234", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 41*/ { BARCODE_AZTEC, "1234", GS1_MODE | GS1RAW_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 42*/ { BARCODE_AZTEC, "https://example.com/01/12345678901231", GS1_MODE, -1, 0, 0 },
/* 43*/ { BARCODE_CODABLOCKF, "[01]12345678901231", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 }, /* Codablock-F does not support GS1 */
/* 43*/ { BARCODE_CODABLOCKF, "[01]12345678901231", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 }, /* Codablock F does not support GS1 */
/* 44*/ { BARCODE_CODABLOCKF, "^0112345678901231", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 45*/ { BARCODE_CODABLOCKF, "0112345678901231", GS1_MODE | GS1RAW_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 46*/ { BARCODE_CODABLOCKF, "[01]12345678901231", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
+1 -1
View File
@@ -1036,7 +1036,7 @@ static void test_non_forced(const testCtx *const p_ctx) {
/* 32*/ { BARCODE_AZTEC, GS1_MODE | GS1NOCHECK_MODE, -1, "[02]12345678901231[10]()[37]12345678[00]123456789012345675", 0, "" },
/* 33*/ { BARCODE_AZTEC, GS1_MODE | GS1NOCHECK_MODE, -1, "^021234567890123110()^3712345678^00123456789012345675", 0, "" },
/* 34*/ { BARCODE_AZTEC, GS1_MODE | GS1NOCHECK_MODE | GS1RAW_MODE, -1, "021234567890123110()\0353712345678\03500123456789012345675", 0, "" },
/* 35*/ { BARCODE_CODABLOCKF, GS1_MODE, -1, "[01]12345678901231", ZINT_ERROR_INVALID_OPTION, "Error 220: Selected symbology does not support GS1 mode" }, /* Codablock-F does not support GS1 */
/* 35*/ { BARCODE_CODABLOCKF, GS1_MODE, -1, "[01]12345678901231", ZINT_ERROR_INVALID_OPTION, "Error 220: Selected symbology does not support GS1 mode" }, /* Codablock F does not support GS1 */
/* 36*/ { BARCODE_CODABLOCKF, GS1_MODE | GS1NOCHECK_MODE, -1, "[01]12345678901231", ZINT_ERROR_INVALID_OPTION, "Error 220: Selected symbology does not support GS1 mode" },
/* 37*/ { BARCODE_CODABLOCKF, GS1_MODE, -1, "1234", ZINT_ERROR_INVALID_OPTION, "Error 220: Selected symbology does not support GS1 mode" },
/* 38*/ { BARCODE_CODEONE, GS1_MODE, -1, "[01]12345678901231", 0, "" },
+39 -29
View File
@@ -280,9 +280,12 @@ static void test_reader_init(const testCtx *const p_ctx) {
const char *expected;
const char *comment;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
static const struct item data[] = {
/* 0*/ { BARCODE_PDF417, UNICODE_MODE, READER_INIT, "A", 0, 6, 103, "(12) 4 921 29 900 209 917 46 891 522 472 822 385", "Outputs Test Alpha flag 900" },
/* 1*/ { BARCODE_MICROPDF417, UNICODE_MODE, READER_INIT, "A", 0, 11, 38, "(11) 921 900 29 900 179 499 922 262 777 478 300", "Outputs Test Alpha flag 900" },
/* 0*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, READER_INIT, "A", 0, 6, 103, "(12) 4 921 29 900 209 917 46 891 522 472 822 385", "Outputs Test Alpha flag 900" },
/* 1*/ { BARCODE_PDF417, UNICODE_MODE, READER_INIT, "A", 0, 6, 103, "(12) 4 921 29 900 209 917 46 891 522 472 822 385", "Outputs Test Alpha flag 900" },
/* 2*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, READER_INIT, "A", 0, 11, 38, "(11) 921 900 29 900 179 499 922 262 777 478 300", "Outputs Test Alpha flag 900" },
/* 3*/ { BARCODE_MICROPDF417, UNICODE_MODE, READER_INIT, "A", 0, 11, 38, "(11) 921 900 29 900 179 499 922 262 777 478 300", "Outputs Test Alpha flag 900" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
@@ -434,33 +437,40 @@ static void test_input(const testCtx *const p_ctx) {
/* 54*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 1, -1, { 0, 0, "" }, "A", 0, 0, 6, 86, "(6) 2 29 752 533 551 139", 0, "BWIPP BYTE1" },
/* 55*/ { BARCODE_PDF417, UNICODE_MODE, -1, 1, -1, { 0, 0, "" }, "A", 0, 0, 6, 86, "(6) 2 29 752 533 551 139", 0, "BWIPP BYTE1" },
/* 56*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 2, -1, { 0, 0, "" }, "A", 0, 0, 5, 103, "(10) 2 29 478 509 903 637 74 490 760 21", 0, "BWIPP BYTE1" },
/* 57*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 3, -1, { 0, 0, "" }, "A", 0, 0, 9, 103, "(18) 2 29 290 888 64 789 390 182 22 197 347 41 298 467 387 917 455 196", 0, "BWIPP BYTE1" },
/* 58*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 4, -1, { 0, 0, "" }, "A", 0, 0, 12, 120, "(36) 4 29 900 900 702 212 753 721 695 584 222 459 110 594 813 465 718 912 667 349 852 602", 0, "BWIPP BYTE1" },
/* 59*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 5, -1, { 0, 0, "" }, "A", 0, 0, 14, 154, "(70) 6 29 900 900 900 900 774 599 527 418 850 374 921 763 922 772 572 661 584 902 578 696", 0, "BWIPP BYTE1" },
/* 60*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 6, -1, { 0, 0, "" }, "A", 0, 0, 19, 188, "(133) 5 29 900 900 900 113 261 822 368 600 652 404 869 860 902 184 702 611 323 195 794 566", 0, "BWIPP BYTE1" },
/* 61*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 7, -1, { 0, 0, "" }, "A", 0, 0, 29, 222, "(261) 5 29 900 900 900 384 614 456 20 422 177 78 492 215 859 765 864 755 572 621 891 97 538", 0, "BWIPP BYTE1" },
/* 62*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 0, 0, "" }, "A", 0, 0, 40, 290, "(520) 8 29 900 900 900 900 900 900 255 576 871 499 885 500 866 196 784 681 589 448 428 108", 0, "BWIPP BYTE1" },
/* 63*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 1, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 111 100 17 53 923 1 111 104 903 71", 1, "H.4 example" },
/* 64*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 1, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 111 100 17 53 923 1 111 104 903 71", 1, "H.4 example" },
/* 65*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 4, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 928 111 103 17 53 923 1 111 104 922 772 754", 1, "H.4 example last segment" },
/* 66*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 4, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 928 111 103 17 53 923 1 111 104 922 772 754", 1, "H.4 example last segment" },
/* 67*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 2, 4, "" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 900 900 928 111 101 923 1 111 104 583", 1, "No ID" },
/* 68*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 2, 4, "" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 900 900 928 111 101 923 1 111 104 583", 1, "No ID" },
/* 69*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 99998, 99999, "12345" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 222 197 123 45 923 1 222 199 198", 1, "IDs '123', '045'" },
/* 70*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 99998, 99999, "12345" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 222 197 123 45 923 1 222 199 198", 1, "IDs '123', '045'" },
/* 71*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 1, 4, "017053" }, "A", 0, 0, 6, 99, "(24) 900 29 900 928 111 100 17 53 923 1 111 104 430 136 328 218 796 853 32 421 712 477 363", 1, "H.4 example" },
/* 72*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 1, 4, "017053" }, "A", 0, 0, 6, 99, "(24) 900 29 900 928 111 100 17 53 923 1 111 104 430 136 328 218 796 853 32 421 712 477 363", 1, "H.4 example" },
/* 73*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 4, 4, "017053" }, "A", 0, 0, 6, 99, "(24) 900 29 928 111 103 17 53 923 1 111 104 922 837 837 774 835 701 445 926 428 285 851 334", 1, "H.4 example last segment" },
/* 74*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 3, 4, "" }, "A", 0, 0, 17, 38, "(17) 900 29 900 928 111 102 923 1 111 104 343 717 634 693 618 860 618", 1, "No ID" },
/* 75*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 3, 4, "" }, "A", 0, 0, 17, 38, "(17) 900 29 900 928 111 102 923 1 111 104 343 717 634 693 618 860 618", 1, "No ID" },
/* 76*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 99999, 99999, "100200300" }, "A", 0, 0, 11, 55, "(22) 900 29 928 222 198 100 200 300 923 1 222 199 922 693 699 895 719 637 154 478 399 638", 1, "IDs '100', '200', '300'" },
/* 77*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 99999, 99999, "100200300" }, "A", 0, 0, 11, 55, "(22) 900 29 928 222 198 100 200 300 923 1 222 199 922 693 699 895 719 637 154 478 399 638", 1, "IDs '100', '200', '300'" },
/* 78*/ { BARCODE_PDF417, DATA_MODE | FAST_MODE, -1, -1, -1, { 0, 0, "" }, "123456", 0, 0, 7, 103, "(14) 6 902 1 348 256 900 759 577 359 263 64 409 852 154", 0, "BWIPP BYTE" },
/* 79*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, "123456", 0, 0, 7, 103, "(14) 6 841 63 125 209 900 889 730 746 451 470 371 667 636", 1, "" },
/* 80*/ { BARCODE_PDF417, DATA_MODE | FAST_MODE, -1, -1, -1, { 0, 0, "" }, "12345678901234567890", 0, 0, 9, 103, "(18) 10 902 211 358 354 304 269 753 190 900 327 902 163 367 231 586 808 731", 1, "" },
/* 81*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, "12345678901234567890", 0, 0, 9, 103, "(18) 10 902 211 358 354 304 269 753 190 900 327 902 163 367 231 586 808 731", 1, "" },
/* 82*/ { BARCODE_PDF417, DATA_MODE | FAST_MODE, -1, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 0, 12, 137, "(48) 40 902 491 81 137 450 302 67 15 174 492 862 667 475 869 12 434 685 326 422 57 117 339", 1, "" },
/* 83*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 0, 12, 137, "(48) 40 902 491 81 137 450 302 67 15 174 492 862 667 475 869 12 434 685 326 422 57 117 339", 1, "" },
/* 57*/ { BARCODE_PDF417, UNICODE_MODE, -1, 2, -1, { 0, 0, "" }, "A", 0, 0, 5, 103, "(10) 2 29 478 509 903 637 74 490 760 21", 0, "BWIPP BYTE1" },
/* 58*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 3, -1, { 0, 0, "" }, "A", 0, 0, 9, 103, "(18) 2 29 290 888 64 789 390 182 22 197 347 41 298 467 387 917 455 196", 0, "BWIPP BYTE1" },
/* 59*/ { BARCODE_PDF417, UNICODE_MODE, -1, 3, -1, { 0, 0, "" }, "A", 0, 0, 9, 103, "(18) 2 29 290 888 64 789 390 182 22 197 347 41 298 467 387 917 455 196", 0, "BWIPP BYTE1" },
/* 60*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 4, -1, { 0, 0, "" }, "A", 0, 0, 12, 120, "(36) 4 29 900 900 702 212 753 721 695 584 222 459 110 594 813 465 718 912 667 349 852 602", 0, "BWIPP BYTE1" },
/* 61*/ { BARCODE_PDF417, UNICODE_MODE, -1, 4, -1, { 0, 0, "" }, "A", 0, 0, 12, 120, "(36) 4 29 900 900 702 212 753 721 695 584 222 459 110 594 813 465 718 912 667 349 852 602", 0, "BWIPP BYTE1" },
/* 62*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 5, -1, { 0, 0, "" }, "A", 0, 0, 14, 154, "(70) 6 29 900 900 900 900 774 599 527 418 850 374 921 763 922 772 572 661 584 902 578 696", 0, "BWIPP BYTE1" },
/* 63*/ { BARCODE_PDF417, UNICODE_MODE, -1, 5, -1, { 0, 0, "" }, "A", 0, 0, 14, 154, "(70) 6 29 900 900 900 900 774 599 527 418 850 374 921 763 922 772 572 661 584 902 578 696", 0, "BWIPP BYTE1" },
/* 64*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 6, -1, { 0, 0, "" }, "A", 0, 0, 19, 188, "(133) 5 29 900 900 900 113 261 822 368 600 652 404 869 860 902 184 702 611 323 195 794 566", 0, "BWIPP BYTE1" },
/* 65*/ { BARCODE_PDF417, UNICODE_MODE, -1, 6, -1, { 0, 0, "" }, "A", 0, 0, 19, 188, "(133) 5 29 900 900 900 113 261 822 368 600 652 404 869 860 902 184 702 611 323 195 794 566", 0, "BWIPP BYTE1" },
/* 66*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 7, -1, { 0, 0, "" }, "A", 0, 0, 29, 222, "(261) 5 29 900 900 900 384 614 456 20 422 177 78 492 215 859 765 864 755 572 621 891 97 538", 0, "BWIPP BYTE1" },
/* 67*/ { BARCODE_PDF417, UNICODE_MODE, -1, 7, -1, { 0, 0, "" }, "A", 0, 0, 29, 222, "(261) 5 29 900 900 900 384 614 456 20 422 177 78 492 215 859 765 864 755 572 621 891 97 538", 0, "BWIPP BYTE1" },
/* 68*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 0, 0, "" }, "A", 0, 0, 40, 290, "(520) 8 29 900 900 900 900 900 900 255 576 871 499 885 500 866 196 784 681 589 448 428 108", 0, "BWIPP BYTE1" },
/* 69*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 0, 0, "" }, "A", 0, 0, 40, 290, "(520) 8 29 900 900 900 900 900 900 255 576 871 499 885 500 866 196 784 681 589 448 428 108", 0, "BWIPP BYTE1" },
/* 70*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 1, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 111 100 17 53 923 1 111 104 903 71", 1, "H.4 example" },
/* 71*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 1, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 111 100 17 53 923 1 111 104 903 71", 1, "H.4 example" },
/* 72*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 4, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 928 111 103 17 53 923 1 111 104 922 772 754", 1, "H.4 example last segment" },
/* 73*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 4, 4, "017053" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 928 111 103 17 53 923 1 111 104 922 772 754", 1, "H.4 example last segment" },
/* 74*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 2, 4, "" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 900 900 928 111 101 923 1 111 104 583", 1, "No ID" },
/* 75*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 2, 4, "" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 900 900 928 111 101 923 1 111 104 583", 1, "No ID" },
/* 76*/ { BARCODE_PDF417, UNICODE_MODE | FAST_MODE, -1, 8, -1, { 99998, 99999, "12345" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 222 197 123 45 923 1 222 199 198", 1, "IDs '123', '045'" },
/* 77*/ { BARCODE_PDF417, UNICODE_MODE, -1, 8, -1, { 99998, 99999, "12345" }, "A", 0, 0, 41, 290, "(533) 21 29 900 900 900 900 900 900 900 900 900 900 928 222 197 123 45 923 1 222 199 198", 1, "IDs '123', '045'" },
/* 78*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 1, 4, "017053" }, "A", 0, 0, 6, 99, "(24) 900 29 900 928 111 100 17 53 923 1 111 104 430 136 328 218 796 853 32 421 712 477 363", 1, "H.4 example" },
/* 79*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 1, 4, "017053" }, "A", 0, 0, 6, 99, "(24) 900 29 900 928 111 100 17 53 923 1 111 104 430 136 328 218 796 853 32 421 712 477 363", 1, "H.4 example" },
/* 80*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 4, 4, "017053" }, "A", 0, 0, 6, 99, "(24) 900 29 928 111 103 17 53 923 1 111 104 922 837 837 774 835 701 445 926 428 285 851 334", 1, "H.4 example last segment" },
/* 81*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 3, 4, "" }, "A", 0, 0, 17, 38, "(17) 900 29 900 928 111 102 923 1 111 104 343 717 634 693 618 860 618", 1, "No ID" },
/* 82*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 3, 4, "" }, "A", 0, 0, 17, 38, "(17) 900 29 900 928 111 102 923 1 111 104 343 717 634 693 618 860 618", 1, "No ID" },
/* 83*/ { BARCODE_MICROPDF417, UNICODE_MODE | FAST_MODE, -1, -1, -1, { 99999, 99999, "100200300" }, "A", 0, 0, 11, 55, "(22) 900 29 928 222 198 100 200 300 923 1 222 199 922 693 699 895 719 637 154 478 399 638", 1, "IDs '100', '200', '300'" },
/* 84*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, -1, -1, { 99999, 99999, "100200300" }, "A", 0, 0, 11, 55, "(22) 900 29 928 222 198 100 200 300 923 1 222 199 922 693 699 895 719 637 154 478 399 638", 1, "IDs '100', '200', '300'" },
/* 85*/ { BARCODE_PDF417, DATA_MODE | FAST_MODE, -1, -1, -1, { 0, 0, "" }, "123456", 0, 0, 7, 103, "(14) 6 902 1 348 256 900 759 577 359 263 64 409 852 154", 0, "BWIPP BYTE" },
/* 86*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, "123456", 0, 0, 7, 103, "(14) 6 841 63 125 209 900 889 730 746 451 470 371 667 636", 1, "" },
/* 87*/ { BARCODE_PDF417, DATA_MODE | FAST_MODE, -1, -1, -1, { 0, 0, "" }, "12345678901234567890", 0, 0, 9, 103, "(18) 10 902 211 358 354 304 269 753 190 900 327 902 163 367 231 586 808 731", 1, "" },
/* 88*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, "12345678901234567890", 0, 0, 9, 103, "(18) 10 902 211 358 354 304 269 753 190 900 327 902 163 367 231 586 808 731", 1, "" },
/* 89*/ { BARCODE_PDF417, DATA_MODE | FAST_MODE, -1, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 0, 12, 137, "(48) 40 902 491 81 137 450 302 67 15 174 492 862 667 475 869 12 434 685 326 422 57 117 339", 1, "" },
/* 90*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 0, 12, 137, "(48) 40 902 491 81 137 450 302 67 15 174 492 862 667 475 869 12 434 685 326 422 57 117 339", 1, "" },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
+185 -51
View File
@@ -51,15 +51,23 @@ struct perf_item {
};
static void test_perf(const testCtx *const p_ctx, const int default_iterations, const struct perf_item *data,
const int data_size) {
int debug = p_ctx->debug;
const int data_size, const char *const outfile) {
int debug = p_ctx->debug & 0xFFFF;
/* Hack (use "-d $((256 + (flg << 16)))") to select whether to time (`ZBarcode_Create()` always timed):
1. `ZBarcode_Encode()`
2. `ZBarcode_Buffer()`
4. `ZBarcode_Buffer()` with `OUT_BUFFER_INTERMEDIATE`
8. `ZBarcode_Print()`
16. `ZBarcode_Print()` with `BARCODE_MEMORY_FILE`
with 0 meaning all */
int flg = (p_ctx->debug >> 16) & 0xFF;
int i, length, ret;
struct zint_symbol *symbol = NULL;
clock_t start;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print;
clock_t total_create = 0, total_encode = 0, total_buffer = 0, total_buf_inter = 0, total_print = 0, total_memfile = 0;
clock_t diff_create, diff_encode, diff_buffer, diff_buf_inter, diff_print, diff_memfile;
int comment_max = 0;
const int iterations = p_ctx->arg ? p_ctx->arg : default_iterations; /* Use "-a N" to set iterations */
@@ -83,9 +91,10 @@ static void test_perf(const testCtx *const p_ctx, const int default_iterations,
if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0, diff_memfile = 0;
for (j = 0; j < iterations; j++) {
int have_encoded = 0;
start = clock();
symbol = ZBarcode_Create();
diff_create += clock() - start;
@@ -113,55 +122,104 @@ static void test_perf(const testCtx *const p_ctx, const int default_iterations,
data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/,
text, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, TCU(text), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (!flg || (flg & 1)) {
start = clock();
ret = ZBarcode_Encode(symbol, TCU(text), length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
have_encoded = 1;
}
if (!flg || (flg & 2)) {
if (!have_encoded) {
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
have_encoded = 1;
}
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
}
if (!flg || (flg & 4)) {
if (!have_encoded) {
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
have_encoded = 1;
}
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n",
i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
}
if (!flg || (flg & 8)) {
if (!have_encoded) {
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
have_encoded = 1;
}
if (outfile && strlen(outfile) < 256) {
strcpy(symbol->outfile, outfile);
}
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
}
if (!flg || (flg & 16)) {
if (!have_encoded) {
ret = ZBarcode_Encode(symbol, TCU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
/*have_encoded = 1;*/
}
symbol->output_options |= BARCODE_MEMORY_FILE;
if (outfile && strlen(outfile) < 256) {
strcpy(symbol->outfile, outfile);
}
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_memfile += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print BARCODE_MEMORY_FILE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~BARCODE_MEMORY_FILE; /* Undo */
}
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options |= OUT_BUFFER_INTERMEDIATE;
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n",
i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
diff_print += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Print ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
printf(" %*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n",
printf(" %*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, memfile % 8gms, create % 8gms\n",
comment_max, data[i].comment,
TEST_PERF_TIME(diff_encode), TEST_PERF_TIME(diff_buffer), TEST_PERF_TIME(diff_buf_inter),
TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_create));
TEST_PERF_TIME(diff_print), TEST_PERF_TIME(diff_memfile), TEST_PERF_TIME(diff_create));
total_create += diff_create;
total_encode += diff_encode;
total_buffer += diff_buffer;
total_buf_inter += diff_buf_inter;
total_print += diff_print;
total_memfile += diff_memfile;
}
if (p_ctx->index == -1) {
printf(" %*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n",
printf(" %*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, memfile % 8gms, create % 8gms\n",
comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter),
TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_memfile), TEST_PERF_TIME(total_create));
}
testFinish();
@@ -178,7 +236,7 @@ static void test_2of5(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_aztec(const testCtx *const p_ctx) {
@@ -235,7 +293,7 @@ static void test_aztec(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_aztec_fast(const testCtx *const p_ctx) {
@@ -292,7 +350,7 @@ static void test_aztec_fast(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_code11(const testCtx *const p_ctx) {
@@ -304,7 +362,7 @@ static void test_code11(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_code128(const testCtx *const p_ctx) {
@@ -317,7 +375,7 @@ static void test_code128(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_composite(const testCtx *const p_ctx) {
@@ -344,7 +402,7 @@ static void test_composite(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_dmatrix(const testCtx *const p_ctx) {
@@ -424,7 +482,7 @@ static void test_dmatrix(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_dotcode(const testCtx *const p_ctx) {
@@ -442,7 +500,7 @@ static void test_dotcode(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_gridmtx(const testCtx *const p_ctx) {
@@ -467,7 +525,7 @@ static void test_gridmtx(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_hanxin(const testCtx *const p_ctx) {
@@ -509,7 +567,7 @@ static void test_hanxin(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 1 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_maxicode(const testCtx *const p_ctx) {
@@ -532,7 +590,7 @@ static void test_maxicode(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_pdf417(const testCtx *const p_ctx) {
@@ -582,7 +640,57 @@ static void test_pdf417(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_pdf417_fast(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_PDF417, FAST_MODE, -1, -1, -1, "1234567890", "", 0, 7, 103, "10 numerics" },
/* 1*/ { BARCODE_PDF417, FAST_MODE, -1, -1, -1,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz&,:#-.$/+%*=^ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM"
"NOPQRSTUVWXYZ;<>@[]_`~!||()?{}'123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJK"
"LMNOPQRSTUVWXYZ12345678912345678912345678912345678900001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFG"
"HIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567"
"890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcde"
"fghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",
"", 0, 43, 290, "960 chars, text/numeric" },
/* 2*/ { BARCODE_PDF417, DATA_MODE, -1, -1, -1,
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240"
"\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240",
"", 0, 51, 358, "960 chars, byte" },
/* 3*/ { BARCODE_PDF417, FAST_MODE, -1, -1, -1,
"BP2D+1.00+0005+FLE ESC BV+1.00+3.60*BX2D+1.00+0001+Casual shoes & apparel+90044030118100801265*D_2D+1.02+31351440315981+C910332+02032018+KXXXX CXXXX+UNIT 4 HXXX"
"XXXXX BUSINESS PARK++ST ALBANS+ST ALBANS++AL2 3TA+0001+000001+001+00000000+00++N+N+N+0000++++++N+++N*DS2D+1.01+0001+0001+90044030118100801265+++++07852389322+"
"+E*F_2D+1.00+0005*",
"", 0, 26, 222, "338 chars, text/numeric/byte" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_plessey(const testCtx *const p_ctx) {
@@ -596,7 +704,7 @@ static void test_plessey(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_postal(const testCtx *const p_ctx) {
@@ -609,7 +717,7 @@ static void test_postal(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_qr(const testCtx *const p_ctx) {
@@ -662,7 +770,7 @@ static void test_qr(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_qr_fast(const testCtx *const p_ctx) {
@@ -715,7 +823,7 @@ static void test_qr_fast(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_microqr(const testCtx *const p_ctx) {
@@ -729,7 +837,7 @@ static void test_microqr(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 5 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_upcean(const testCtx *const p_ctx) {
@@ -749,7 +857,29 @@ static void test_upcean(const testCtx *const p_ctx) {
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size);
test_perf(p_ctx, default_iterations, data, data_size, NULL /*outfile*/);
}
static void test_gif(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_CODE128, -1, -1, -1, -1, "123456ABCD", "", 0, 1, 123, "CODE128 10" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size, "out.gif");
}
static void test_tif(const testCtx *const p_ctx) {
static const struct perf_item data[] = {
/* 0*/ { BARCODE_CODE128, -1, -1, -1, -1, "123456ABCD", "", 0, 1, 123, "CODE128 10" },
};
const int data_size = ARRAY_SIZE(data);
const int default_iterations = 10 * 1000;
test_perf(p_ctx, default_iterations, data, data_size, "out.tif");
}
int main(int argc, char *argv[]) {
@@ -767,12 +897,16 @@ int main(int argc, char *argv[]) {
{ "test_hanxin", test_hanxin },
{ "test_maxicode", test_maxicode },
{ "test_pdf417", test_pdf417 },
{ "test_pdf417_fast", test_pdf417_fast },
{ "test_plessey", test_plessey },
{ "test_postal", test_postal },
{ "test_qr", test_qr },
{ "test_qr_fast", test_qr_fast },
{ "test_microqr", test_microqr },
{ "test_upcean", test_upcean },
{ "test_gif", test_gif },
{ "test_tif", test_tif },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
+2 -2
View File
@@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2020-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -34,7 +34,7 @@
INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
/* For overview when debugging: ./test_tiff -f pixel_plot -d 5 */
/* For overview when debugging: ./test_tif -f pixel_plot -d 5 */
static void test_pixel_plot(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
+1 -1
View File
@@ -32,7 +32,7 @@
* Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
*/
/* Due to above: */
/* SPDX-License-Identifier: LGPL-2.1+ */
/* SPDX-License-Identifier: LGPL-2.0-or-later */
#ifdef _WIN32
#include <windows.h>
Binary file not shown.
+2 -2
View File
@@ -2,7 +2,7 @@
/* Generate lookup table from unicode.org mapping file (SHIFTJIS.TXT by default). */
/*
libzint - the open source barcode library
Copyright (C) 2019-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019-2026 Robin Stuart <rstuart114@gmail.com>
*/
/* To create backend/tests/test_sjis_tab.h (from the project root directory):
*
@@ -18,7 +18,7 @@
*
* To create backend/tests/test_gb18030_tab.h (note that backend/tests/tools/data/GB18030.TXT
* will have to be downloaded first from https://haible.de/bruno/charsets/conversion-tables/GB18030.html
* using the version jdk-1.4.2/GB18030.TXT):
* using the version libiconv-1.11/GB18030.TXT):
*
* php backend/tests/tools/gen_test_tab.php -f GB18030.TXT -s gb18030_tab
*
+142 -19
View File
@@ -38,7 +38,6 @@
#include "filemem.h"
#include "output.h"
#include "tif.h"
#include "tif_lzw.h"
/* PhotometricInterpretation */
#define TIF_PMI_WHITEISZERO 0
@@ -51,13 +50,13 @@
#define TIF_NO_COMPRESSION 1
#define TIF_LZW 5
static void to_color_map(const unsigned char rgb[4], tiff_color_t *color_map_entry) {
static void tif_to_color_map(const unsigned char rgb[4], tiff_color_t *color_map_entry) {
color_map_entry->red = (rgb[0] << 8) | rgb[0];
color_map_entry->green = (rgb[1] << 8) | rgb[1];
color_map_entry->blue = (rgb[2] << 8) | rgb[2];
}
static void to_cmyk(const char *colour, unsigned char *cmyk) {
static void tif_to_cmyk(const char *colour, unsigned char *cmyk) {
int cyan, magenta, yellow, black;
unsigned char alpha;
@@ -69,6 +68,134 @@ static void to_cmyk(const char *colour, unsigned char *cmyk) {
cmyk[4] = alpha;
}
/* LZW stuff - see `tif_lzw_compress()` below */
#define TIF_LZW_CLEAR_CODE 256
#define TIF_LZW_EOI_CODE 257 /* EndOfInformation */
#define TIF_LZW_MIN_BITS 9
#define TIF_LZW_MAX_BITS 12
#define TIF_LZW_TABLE_SIZE 4096 /* (1 << TIF_LZW_MAX_BITS) */
/* Write `code` to output `fmp` in 8-bit batches, returning updated `bytes_put` */
static int tif_lzw_putCode(struct filemem *fmp, const int code, const int bitsPerCode, int *p_bits, int bytes_put) {
int bits = *p_bits & 0x0FFF; /* Actual bits in buffer */
int num_bits = (*p_bits >> 16) & 0x0FFF; /* No. of bits in buffer */
bits = (bits << bitsPerCode) | code;
for (num_bits += bitsPerCode; num_bits >= 8; num_bits -= 8) {
zint_fm_putc((bits >> (num_bits - 8)) & 0xFF, fmp);
bytes_put++;
}
bits &= (1 << num_bits) - 1;
*p_bits = (num_bits << 16) | bits;
return bytes_put;
}
/* LZW compression adapted from TwelveMonkeys ImageIO's `LZWEncoder::encode()`, returns no. of bytes written */
/* Copyright (c) 2015, Harald Kuhr */
/* SPDX-License-Identifier: BSD-3-Clause */
/* Tree algorithm from "LZW Compression Used to Encode/Decode a GIF File", Bob Montgomery, 1988, see
https://gingko.homeip.net/docs/file_formats/lzwgif.html#bob
"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
*/
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
and siblings are strings with a common parent (or prefix) and different suffix bytes */
short children[TIF_LZW_TABLE_SIZE] = {0}; /* "child[]" in Montgomery diagram */
short siblings[TIF_LZW_TABLE_SIZE] = {0}; /* "sib[]" in Montgomery diagram */
int parent;
int bitsPerCode = TIF_LZW_MIN_BITS; /* "codesize" in Montgomery diagram, goes from 9 to 12 */
int nextValidCode = TIF_LZW_EOI_CODE + 1; /* "nvc" - next available slot in `suffixes` */
int maxCode = (1 << bitsPerCode) - 1; /* If `nextValidCode` hits this, `bitsPerCode` will have to be adjusted */
int bits = 0; /* Buffer for partial codes, top 16-bits no. of bits, bottom the bits */
int bytes_put = 0; /* No. of bytes output */
const unsigned char *const be = bp + blen;
assert(blen != 0);
/* Init */
bytes_put = tif_lzw_putCode(fmp, TIF_LZW_CLEAR_CODE & maxCode, bitsPerCode, &bits, bytes_put);
parent = *bp++; /* Parent is 1st code */
while (bp < be) {
const int value = *bp++; /* "color" in Montgomery diagram */
int child = children[parent];
/* Does parent have a child? */
if (child) {
/* Is child right value? */
if (suffixes[child] == value) {
parent = child; /* Make new parent */
} else {
int sibling = child; /* Makes loop easier */
/* Try siblings */
for (;;) {
/* Does sibling have a sibling? */
if (siblings[sibling]) {
sibling = siblings[sibling];
/* Is sibling right value? */
if (suffixes[sibling] == value) {
parent = sibling; /* Make new parent */
break;
}
} else {
/* Create one */
siblings[sibling] = (short) nextValidCode;
goto update_child; /* Hack to avoid having func with large no. of args */
}
}
}
/* Parent does not have a child */
} else {
/* Create one */
children[parent] = (short) nextValidCode;
update_child:
suffixes[nextValidCode] = (short) value;
bytes_put = tif_lzw_putCode(fmp, parent & maxCode, bitsPerCode, &bits, bytes_put); /* Put the code */
parent = value;
if (++nextValidCode > maxCode) {
/* Adjust `bitsPerCode` (code size) if required */
if (bitsPerCode == TIF_LZW_MAX_BITS) {
/* Signal reset by writing Clear code */
bytes_put = tif_lzw_putCode(fmp, TIF_LZW_CLEAR_CODE & maxCode, bitsPerCode, &bits, bytes_put);
/* Reset tables */
memset(children, 0, sizeof(short) * TIF_LZW_TABLE_SIZE);
memset(siblings, 0, sizeof(short) * TIF_LZW_TABLE_SIZE);
bitsPerCode = TIF_LZW_MIN_BITS;
nextValidCode = TIF_LZW_EOI_CODE + 1;
} else {
/* Increase code size */
bitsPerCode++;
}
maxCode = (1 << bitsPerCode) - 1;
}
}
}
/* Write EOI when we are done */
bytes_put = tif_lzw_putCode(fmp, parent & maxCode, bitsPerCode, &bits, bytes_put);
bytes_put = tif_lzw_putCode(fmp, TIF_LZW_EOI_CODE & maxCode, bitsPerCode, &bits, bytes_put);
/* Flush partial codes */
if (bits) {
const int num_bits = (bits >> 16) & 0x0FFF;
zint_fm_putc((bits << (8 - num_bits)) & 0xFF, fmp); /* Zero pad */
bytes_put++;
}
return bytes_put;
}
/* TIFF Revision 6.0 https://www.adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf */
INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) {
unsigned char fg[4], bg[4];
@@ -94,7 +221,6 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
struct filemem *const fmp = &fm;
const unsigned char *pb;
int compression = TIF_NO_COMPRESSION;
tif_lzw_state lzw_state;
long file_pos;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
uint32_t *strip_offset;
@@ -134,9 +260,9 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
palette[i][4] = fg[3];
}
map['0'] = 8;
to_cmyk(symbol->bgcolour, palette[8]);
tif_to_cmyk(symbol->bgcolour, palette[8]);
map['1'] = 9;
to_cmyk(symbol->fgcolour, palette[9]);
tif_to_cmyk(symbol->fgcolour, palette[9]);
pmi = TIF_PMI_SEPARATED;
bits_per_sample = 8;
@@ -171,7 +297,7 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
if (fg[3] == 0xff && bg[3] == 0xff) { /* If no alpha */
pmi = TIF_PMI_PALETTE_COLOR;
for (i = 0; i < 10; i++) {
to_color_map(palette[i], &color_map[i]);
tif_to_color_map(palette[i], &color_map[i]);
}
bits_per_sample = 4;
samples_per_pixel = 1;
@@ -188,9 +314,9 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
} else { /* fg/bg only */
if (symbol->output_options & CMYK_COLOUR) {
map['0'] = 0;
to_cmyk(symbol->bgcolour, palette[0]);
tif_to_cmyk(symbol->bgcolour, palette[0]);
map['1'] = 1;
to_cmyk(symbol->fgcolour, palette[1]);
tif_to_cmyk(symbol->fgcolour, palette[1]);
pmi = TIF_PMI_SEPARATED;
bits_per_sample = 8;
@@ -227,7 +353,7 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
pmi = TIF_PMI_PALETTE_COLOR;
for (i = 0; i < 2; i++) {
to_color_map(palette[i], &color_map[i]);
tif_to_color_map(palette[i], &color_map[i]);
}
if (fg[3] == 0xff && bg[3] == 0xff) { /* If no alpha */
bits_per_sample = 4;
@@ -316,7 +442,6 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
}
if (!output_to_stdout) {
compression = TIF_LZW;
tif_lzw_init(&lzw_state);
}
/* Header */
@@ -370,13 +495,13 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
if (strip_row == rows_per_strip || (strip == strip_count - 1 && strip_row == rows_last_strip)) {
/* End of strip */
if (compression == TIF_LZW) {
#ifndef NDEBUG
file_pos = zint_fm_tell(fmp);
if (!tif_lzw_encode(&lzw_state, fmp, strip_buf, bytes_put)) { /* Only fails if can't malloc */
tif_lzw_cleanup(&lzw_state);
(void) zint_fm_close(fmp, symbol);
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 673, "Insufficient memory for TIF LZW hash table");
}
bytes_put = (unsigned int) (zint_fm_tell(fmp) - file_pos);
#endif
bytes_put = tif_lzw_compress(fmp, strip_buf, bytes_put);
#ifndef NDEBUG
assert(bytes_put == (unsigned int) (zint_fm_tell(fmp) - file_pos));
#endif
if (bytes_put != strip_bytes[strip]) {
const int diff = bytes_put - strip_bytes[strip];
strip_bytes[strip] = bytes_put;
@@ -402,8 +527,6 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
}
if (compression == TIF_LZW) {
tif_lzw_cleanup(&lzw_state);
file_pos = zint_fm_tell(fmp);
zint_fm_seek(fmp, 4, SEEK_SET);
free_memory = file_pos;
-382
View File
@@ -1,382 +0,0 @@
/* tif_lzw.h - LZW compression for TIFF */
/*
libzint - the open source barcode library
Copyright (C) 2021-2025 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef Z_TIF_LZW_H
#define Z_TIF_LZW_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* Adapted from TIFF Library 4.2.0 libtiff/tif_lzw.c */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
/*
* TIFF Library.
* Rev 5.0 Lempel-Ziv & Welch Compression Support
*
* This code is derived from the compress program whose code is
* derived from software contributed to Berkeley by James A. Woods,
* derived from original work by Spencer Thomas and Joseph Orost.
*
* The original Berkeley copyright notice appears below in its entirety.
*/
/*
* Copyright (c) 1985, 1986 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* James A. Woods, derived from original work by Spencer Thomas
* and Joseph Orost.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#define MAXCODE(n) ((1L << (n)) - 1)
/*
* The TIFF spec specifies that encoded bit
* strings range from 9 to 12 bits.
*/
#define BITS_MIN 9 /* start with 9 bits */
#define BITS_MAX 12 /* max of 12 bit strings */
/* predefined codes */
#define CODE_CLEAR 256 /* code to clear string table */
#define CODE_EOI 257 /* end-of-information code */
#define CODE_FIRST 258 /* first free code entry */
#define CODE_MAX MAXCODE(BITS_MAX)
#define HSIZE 9001L /* 91% occupancy */
#define HSHIFT (13 - 8)
/*
* Encoding-specific state.
*/
typedef uint16_t tif_lzw_hcode; /* codes fit in 16 bits */
typedef struct {
long hash;
tif_lzw_hcode code;
} tif_lzw_hash;
#define CHECK_GAP 10000 /* ratio check interval */
/*
* State block.
*/
typedef struct {
tif_lzw_hash *enc_hashtab; /* kept separate for small machines */
} tif_lzw_state;
/*
* LZW Encoding.
*/
/*
* Reset encoding hash table.
*/
static void tif_lzw_cl_hash(tif_lzw_state *sp) {
register tif_lzw_hash *hp = &sp->enc_hashtab[HSIZE - 1];
register long i = HSIZE - 8;
do {
i -= 8;
hp[-7].hash = -1;
hp[-6].hash = -1;
hp[-5].hash = -1;
hp[-4].hash = -1;
hp[-3].hash = -1;
hp[-2].hash = -1;
hp[-1].hash = -1;
hp[ 0].hash = -1;
hp -= 8;
} while (i >= 0);
for (i += 8; i > 0; i--, hp--) {
hp->hash = -1;
}
}
#define CALCRATIO(sp, rat) { \
if (incount > 0x007fffff) { /* NB: shift will overflow */ \
rat = outcount >> 8; \
rat = (rat == 0 ? 0x7fffffff : incount / rat); \
} else \
rat = (incount << 8) / outcount; \
}
/* Explicit 0xff masking to make icc -check=conversions happy */
#define PutNextCode(op_fmp, c) { \
nextdata = (nextdata << nbits) | c; \
nextbits += nbits; \
zint_fm_putc((nextdata >> (nextbits - 8)) & 0xff, op_fmp); \
nextbits -= 8; \
if (nextbits >= 8) { \
zint_fm_putc((nextdata >> (nextbits - 8)) & 0xff, op_fmp); \
nextbits -= 8; \
} \
outcount += nbits; \
}
/*
* Encode a chunk of pixels.
*
* Uses an open addressing double hashing (no chaining) on the
* prefix code/next character combination. We do a variant of
* Knuth's algorithm D (vol. 3, sec. 6.4) along with G. Knott's
* relatively-prime secondary probe. Here, the modular division
* first probe is gives way to a faster exclusive-or manipulation.
* Also do block compression with an adaptive reset, whereby the
* code table is cleared when the compression ratio decreases,
* but after the table fills. The variable-length output codes
* are re-sized at this point, and a CODE_CLEAR is generated
* for the decoder.
*/
static int tif_lzw_encode(tif_lzw_state *sp, struct filemem *op_fmp, const unsigned char *bp, int cc) {
register long fcode;
register tif_lzw_hash *hp;
register int h, c;
tif_lzw_hcode ent;
long disp;
int nbits; /* # of bits/code */
int maxcode; /* maximum code for nbits */
int free_ent; /* next free entry in hash table */
unsigned long nextdata; /* next bits of i/o */
long nextbits; /* # of valid bits in nextdata */
long checkpoint; /* point at which to clear table */
long ratio; /* current compression ratio */
long incount; /* (input) data bytes encoded */
long outcount; /* encoded (output) bytes */
/*
* Reset encoding state at the start of a strip.
*/
if (sp->enc_hashtab == NULL) {
sp->enc_hashtab = (tif_lzw_hash *) malloc(HSIZE * sizeof(tif_lzw_hash));
if (sp->enc_hashtab == NULL) {
return 0;
}
}
tif_lzw_cl_hash(sp); /* clear hash table */
nbits = BITS_MIN;
maxcode = MAXCODE(BITS_MIN);
free_ent = CODE_FIRST;
nextdata = 0;
nextbits = 0;
checkpoint = CHECK_GAP;
ratio = 0;
incount = 0;
outcount = 0;
ent = (tif_lzw_hcode) -1;
if (cc > 0) {
PutNextCode(op_fmp, CODE_CLEAR);
ent = *bp++; cc--; incount++;
}
while (cc > 0) {
c = *bp++; cc--; incount++;
fcode = ((long)c << BITS_MAX) + ent;
h = (c << HSHIFT) ^ ent; /* xor hashing */
#ifdef _WINDOWS
/*
* Check hash index for an overflow.
*/
if (h >= HSIZE) {
h -= HSIZE;
}
#endif
hp = &sp->enc_hashtab[h];
if (hp->hash == fcode) {
ent = hp->code;
continue;
}
if (hp->hash >= 0) {
/*
* Primary hash failed, check secondary hash.
*/
disp = HSIZE - h;
if (h == 0) {
disp = 1;
}
do {
/*
* Avoid pointer arithmetic because of
* wraparound problems with segments.
*/
if ((h -= disp) < 0) {
h += HSIZE;
}
hp = &sp->enc_hashtab[h];
if (hp->hash == fcode) {
ent = hp->code;
goto hit;
}
} while (hp->hash >= 0);
}
/*
* New entry, emit code and add to table.
*/
PutNextCode(op_fmp, ent);
ent = (tif_lzw_hcode) c;
hp->code = (tif_lzw_hcode) (free_ent++);
hp->hash = fcode;
if (free_ent == CODE_MAX - 1) {
/* table is full, emit clear code and reset */
tif_lzw_cl_hash(sp);
ratio = 0;
incount = 0;
outcount = 0;
free_ent = CODE_FIRST;
PutNextCode(op_fmp, CODE_CLEAR);
nbits = BITS_MIN;
maxcode = MAXCODE(BITS_MIN);
} else {
/*
* If the next entry is going to be too big for
* the code size, then increase it, if possible.
*/
if (free_ent > maxcode) {
nbits++;
assert(nbits <= BITS_MAX);
maxcode = (int) MAXCODE(nbits);
} else if (incount >= checkpoint) {
long rat;
/*
* Check compression ratio and, if things seem
* to be slipping, clear the hash table and
* reset state. The compression ratio is a
* 24+8-bit fractional number.
*/
checkpoint = incount + CHECK_GAP;
CALCRATIO(sp, rat);
if (rat <= ratio) {
tif_lzw_cl_hash(sp);
ratio = 0;
incount = 0;
outcount = 0;
free_ent = CODE_FIRST;
PutNextCode(op_fmp, CODE_CLEAR);
nbits = BITS_MIN;
maxcode = MAXCODE(BITS_MIN);
} else {
ratio = rat;
}
}
}
hit:
;
}
/*
* Finish off an encoded strip by flushing the last
* string and tacking on an End Of Information code.
*/
if (ent != (tif_lzw_hcode) -1) {
PutNextCode(op_fmp, ent);
free_ent++;
if (free_ent == CODE_MAX - 1) {
/* table is full, emit clear code and reset */
outcount = 0;
PutNextCode(op_fmp, CODE_CLEAR);
nbits = BITS_MIN;
} else {
/*
* If the next entry is going to be too big for
* the code size, then increase it, if possible.
*/
if (free_ent > maxcode) {
nbits++;
assert(nbits <= BITS_MAX);
}
}
}
PutNextCode(op_fmp, CODE_EOI);
/* Explicit 0xff masking to make icc -check=conversions happy */
if (nextbits > 0) {
zint_fm_putc((nextdata << (8 - nextbits)) & 0xff, op_fmp);
}
return 1;
}
static void tif_lzw_cleanup(tif_lzw_state *sp) {
if (sp->enc_hashtab) {
free(sp->enc_hashtab);
}
}
static void tif_lzw_init(tif_lzw_state *sp) {
sp->enc_hashtab = NULL;
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
/* vim: set ts=4 sw=4 et : */
#endif /* Z_TIF_LZW_H */
+4 -3
View File
@@ -2,7 +2,7 @@
/* Generate ECI multibyte tables from unicode.org mapping files */
/*
libzint - the open source barcode library
Copyright (C) 2022-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2022-2026 Robin Stuart <rstuart114@gmail.com>
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/*
@@ -12,7 +12,7 @@
*
* NOTE: backend/tools/data/GB18030.TXT will have to be downloaded first from the tarball
* https://haible.de/bruno/charsets/conversion-tables/GB18030.tar.bz2
* using the version jdk-1.4.2/GB18030.TXT
* using the version libiconv-1.11/GB18030.TXT
*
* NOTE: tools/data/GB2312.TXT will have to be downloaded first from the tarball
* https://haible.de/bruno/charsets/conversion-tables/GB2312.tar.bz2
@@ -48,6 +48,7 @@ $copyright_text = <<<'EOD'
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
EOD;
@@ -573,7 +574,7 @@ file_put_contents($out_dirname . '/gbk.h', implode("\n", $out) . "\n");
$out = array();
out_header($out, 'gb18030', 'GB 18030-2005', 'jdk-1.4.2/GB18030.TXT', 2016,
out_header($out, 'gb18030', 'GB 18030-2005', 'libiconv-1.11/GB18030.TXT', 2016,
'(see https://haible.de/bruno/charsets/conversion-tables/GB18030.tar.bz2)');
$file = $data_dirname . '/' . 'GB18030.TXT';
+3 -2
View File
@@ -2,7 +2,7 @@
/* Generate ECI single-byte tables & routines from unicode.org mapping files */
/*
libzint - the open source barcode library
Copyright (C) 2022-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2022-2026 Robin Stuart <rstuart114@gmail.com>
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/*
@@ -26,7 +26,7 @@ $head = <<<'EOD'
"https://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP125*.TXT" */
/*
libzint - the open source barcode library
Copyright (C) 2021-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -54,6 +54,7 @@ $head = <<<'EOD'
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-License-Identifier: Unicode-3.0 */
#ifndef Z_ECI_SB_H
#define Z_ECI_SB_H
+2 -2
View File
@@ -212,7 +212,7 @@ extern "C" {
#define BARCODE_DATAMATRIX 71 /* Data Matrix (ECC200) */
#define BARCODE_EAN14 72 /* EAN-14 */
#define BARCODE_VIN 73 /* Vehicle Identification Number */
#define BARCODE_CODABLOCKF 74 /* Codablock-F */
#define BARCODE_CODABLOCKF 74 /* Codablock F */
#define BARCODE_NVE18 75 /* NVE-18 (SSCC-18) */
#define BARCODE_JAPANPOST 76 /* Japanese Postal Code */
#define BARCODE_KOREAPOST 77 /* Korea Post */
@@ -244,7 +244,7 @@ extern "C" {
#define BARCODE_HIBC_QR 104 /* HIBC QR Code */
#define BARCODE_HIBC_PDF 106 /* HIBC PDF417 */
#define BARCODE_HIBC_MICPDF 108 /* HIBC MicroPDF417 */
#define BARCODE_HIBC_BLOCKF 110 /* HIBC Codablock-F */
#define BARCODE_HIBC_BLOCKF 110 /* HIBC Codablock F */
#define BARCODE_HIBC_AZTEC 112 /* HIBC Aztec Code */
/* Tbarcode 10 codes */