From e04f662dc0b9466817e1d02ba14828203371127c Mon Sep 17 00:00:00 2001 From: gitlost Date: Thu, 9 Apr 2020 22:08:54 +0100 Subject: [PATCH] ULTRA: enable compression for GS1_MODE; compression changes; fixes; tests --- backend/common.c | 17 + backend/common.h | 1 + backend/tests/CMakeLists.txt | 1 + backend/tests/data/print/bmp/ultracode_a.bmp | Bin 0 -> 2134 bytes backend/tests/data/print/emf/ultracode_a.emf | Bin 0 -> 2356 bytes backend/tests/data/print/eps/code128_aim.eps | 2 +- .../tests/data/print/eps/dotcode_aim_fig7.eps | 2 +- backend/tests/data/print/eps/qr_v1_m.eps | 2 +- backend/tests/data/print/eps/ultracode_a.eps | 185 ++++++++++ backend/tests/data/print/gif/ultracode_a.gif | Bin 0 -> 216 bytes backend/tests/data/print/pcx/ultracode_a.pcx | Bin 0 -> 1204 bytes backend/tests/data/print/png/ultracode_a.png | Bin 0 -> 249 bytes backend/tests/data/print/svg/ultracode_a.svg | 94 +++++ backend/tests/data/print/tif/ultracode_a.tif | Bin 0 -> 2248 bytes backend/tests/data/print/txt/ultracode_a.txt | 13 + backend/tests/test_common.c | 30 ++ backend/tests/test_print.c | 2 +- backend/tests/test_ultra.c | 329 ++++++++++++++++++ backend/tests/testcommon.c | 14 +- backend/tests/testcommon.h | 1 + backend/ultra.c | 115 +++--- 21 files changed, 762 insertions(+), 46 deletions(-) create mode 100644 backend/tests/data/print/bmp/ultracode_a.bmp create mode 100644 backend/tests/data/print/emf/ultracode_a.emf create mode 100644 backend/tests/data/print/eps/ultracode_a.eps create mode 100644 backend/tests/data/print/gif/ultracode_a.gif create mode 100644 backend/tests/data/print/pcx/ultracode_a.pcx create mode 100644 backend/tests/data/print/png/ultracode_a.png create mode 100644 backend/tests/data/print/svg/ultracode_a.svg create mode 100644 backend/tests/data/print/tif/ultracode_a.tif create mode 100644 backend/tests/data/print/txt/ultracode_a.txt create mode 100644 backend/tests/test_ultra.c diff --git a/backend/common.c b/backend/common.c index 9140ea10..19d8a5fd 100644 --- a/backend/common.c +++ b/backend/common.c @@ -477,4 +477,21 @@ void debug_test_codeword_dump(struct zint_symbol *symbol, unsigned char* codewor } symbol->errtxt[strlen(symbol->errtxt) - 1] = '\0'; /* Zap last space */ } + +void debug_test_codeword_dump_int(struct zint_symbol *symbol, int* codewords, int length) { + int i, max = 0, cnt_len, errtxt_len; + char temp[20]; + errtxt_len = sprintf(symbol->errtxt, "(%d) ", length); /* Place the number of codewords at the front */ + for (i = 0, cnt_len = errtxt_len; i < length; i++) { + cnt_len += sprintf(temp, "%d ", codewords[i]); + if (cnt_len > 92) { + break; + } + max++; + } + for (i = 0; i < max; i++) { + errtxt_len += sprintf(symbol->errtxt + errtxt_len, "%d ", codewords[i]); + } + symbol->errtxt[strlen(symbol->errtxt) - 1] = '\0'; /* Zap last space */ +} #endif diff --git a/backend/common.h b/backend/common.h index c583a13e..99ca234d 100644 --- a/backend/common.h +++ b/backend/common.h @@ -92,6 +92,7 @@ extern "C" { #ifdef ZINT_TEST void debug_test_codeword_dump(struct zint_symbol *symbol, unsigned char* codewords, int length); + void debug_test_codeword_dump_int(struct zint_symbol *symbol, int* codewords, int length); #endif #ifdef __cplusplus diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index e4dee5d0..ed038c32 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -81,5 +81,6 @@ zint_add_test(rss, test_rss) zint_add_test(sjis, test_sjis) zint_add_test(svg, test_svg) zint_add_test(telepen, test_telepen) +zint_add_test(ultra, test_ultra) zint_add_test(upcean, test_upcean) zint_add_test(vector, test_vector) diff --git a/backend/tests/data/print/bmp/ultracode_a.bmp b/backend/tests/data/print/bmp/ultracode_a.bmp new file mode 100644 index 0000000000000000000000000000000000000000..a92290186c30ec07718680f42e5dfc1c7176f136 GIT binary patch literal 2134 zcmcJP%@x8R5QOn&2|g>Z0t@i&)pBVq!u-gtxh0U75LmLqw?mTG`*STgo~?bf>#plk zZiugMYMr}=^)?-4+q6Ikv{*mU{Q9K_LY!%<^r)`&Fd$z;z}aVr#)!#4i9zO@t!J9C z6eF_BIPFdsy8Tq1L!W(-U-OYTn z^;~b)J=V{B$23$GlhJxVI773dwj7Gig?`vxRkcb_$l*;_Ee6aVM%!Z7((WWq_0HBa z&HwwSzX=e`)CVd=l$`EN**|8JHLkGF-ba{aJ!^CZ_n}B{kZuipABv+M{v(mLO3&2| iCmb0xm?LEDwg*R5=5zL#a^#qvOgnuu-)SKU)cOU7w_zdx literal 0 HcmV?d00001 diff --git a/backend/tests/data/print/emf/ultracode_a.emf b/backend/tests/data/print/emf/ultracode_a.emf new file mode 100644 index 0000000000000000000000000000000000000000..dd807eb0c0323cec98baf4d97bc4e39b872fe22f GIT binary patch literal 2356 zcmZA2yKWRg5QX7hu(?J6t|y{^n-Sj5N_F z-&u3@Q_HN;^KpA>u8vq8XVFJzp62Ee+mW-p#r62fbzg6xAAPvl#MyCpbmr(c(#IR< zBR6_A#I(IzKJHG<-3`~LIbH8D^=aielM{|H^E8jnS?|`Ixl`{@F3y_kD^^dB?u*N7 zo_uF`-okG+xn}SdcEt}@3zys6e#B{}8tKnYh%g6Ip;i;=$>l3Tr zZ>PQ-^=VSa8{k;;-d}Sy#qLLwI*Ie%;WW%Vz4N}i`Rz8lOs-lzcewtzdcAW@%#QUj z^_wR)`*DYK=58LHx#VUZ`=c{gbMwg2TTb+RTwe38(YvKlo4z^5u;$S@>z(@_lNrX{ zKK~=^zPXs0KinNKdr>o-kE_#npK#01n?#Ryt>$Xe_s;3XdK~MEv*XmE#hD$4^Retc z+^%rDYQ25p?$vz4EjCZTojuUe_kJeabmr76eQ~imdN&u-_nS_*#q`JeVtq5K{Cxa> D+MGEV literal 0 HcmV?d00001 diff --git a/backend/tests/data/print/eps/code128_aim.eps b/backend/tests/data/print/eps/code128_aim.eps index 5d65ec70..b734344c 100644 --- a/backend/tests/data/print/eps/code128_aim.eps +++ b/backend/tests/data/print/eps/code128_aim.eps @@ -1,5 +1,5 @@ %!PS-Adobe-3.0 EPSF-3.0 -%%Creator: Zint 2.7.1 +%%Creator: Zint 2.8.0 %%Title: Zint Generated Symbol %%Pages: 0 %%BoundingBox: 0 0 136 118 diff --git a/backend/tests/data/print/eps/dotcode_aim_fig7.eps b/backend/tests/data/print/eps/dotcode_aim_fig7.eps index af59ba97..c701551b 100644 --- a/backend/tests/data/print/eps/dotcode_aim_fig7.eps +++ b/backend/tests/data/print/eps/dotcode_aim_fig7.eps @@ -1,5 +1,5 @@ %!PS-Adobe-3.0 EPSF-3.0 -%%Creator: Zint 2.7.1 +%%Creator: Zint 2.8.0 %%Title: Zint Generated Symbol %%Pages: 0 %%BoundingBox: 0 0 26 20 diff --git a/backend/tests/data/print/eps/qr_v1_m.eps b/backend/tests/data/print/eps/qr_v1_m.eps index 361fae1a..1220f2c1 100644 --- a/backend/tests/data/print/eps/qr_v1_m.eps +++ b/backend/tests/data/print/eps/qr_v1_m.eps @@ -1,5 +1,5 @@ %!PS-Adobe-3.0 EPSF-3.0 -%%Creator: Zint 2.7.1 +%%Creator: Zint 2.8.0 %%Title: Zint Generated Symbol %%Pages: 0 %%BoundingBox: 0 0 42 42 diff --git a/backend/tests/data/print/eps/ultracode_a.eps b/backend/tests/data/print/eps/ultracode_a.eps new file mode 100644 index 00000000..cb4cde6d --- /dev/null +++ b/backend/tests/data/print/eps/ultracode_a.eps @@ -0,0 +1,185 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.8.0 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 26 26 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +26.00 0.00 TB 0.00 26.00 TR +TE +0.00 1.00 1.00 setrgbcolor +2.00 22.00 TB 22.00 2.00 TR +TE +2.00 20.00 TB 4.00 2.00 TR +TE +2.00 20.00 TB 14.00 2.00 TR +TE +2.00 18.00 TB 12.00 2.00 TR +TE +2.00 18.00 TB 18.00 2.00 TR +TE +2.00 16.00 TB 14.00 4.00 TR +TE +2.00 14.00 TB 10.00 2.00 TR +TE +2.00 10.00 TB 10.00 4.00 TR +TE +2.00 10.00 TB 18.00 6.00 TR +TE +2.00 8.00 TB 4.00 2.00 TR +TE +2.00 8.00 TB 14.00 2.00 TR +TE +2.00 6.00 TB 10.00 4.00 TR +TE +2.00 6.00 TB 20.00 2.00 TR +TE +2.00 4.00 TB 14.00 2.00 TR +TE +2.00 4.00 TB 22.00 2.00 TR +TE +2.00 2.00 TB 4.00 2.00 TR +TE +1.00 0.00 1.00 setrgbcolor +2.00 22.00 TB 12.00 6.00 TR +TE +2.00 20.00 TB 10.00 2.00 TR +TE +2.00 20.00 TB 18.00 2.00 TR +TE +2.00 16.00 TB 22.00 2.00 TR +TE +2.00 14.00 TB 4.00 2.00 TR +TE +2.00 14.00 TB 12.00 2.00 TR +TE +2.00 14.00 TB 16.00 2.00 TR +TE +2.00 10.00 TB 14.00 2.00 TR +TE +2.00 8.00 TB 10.00 4.00 TR +TE +2.00 8.00 TB 16.00 8.00 TR +TE +2.00 6.00 TB 14.00 2.00 TR +TE +2.00 4.00 TB 4.00 2.00 TR +TE +2.00 4.00 TB 18.00 2.00 TR +TE +2.00 2.00 TB 10.00 4.00 TR +TE +2.00 2.00 TB 16.00 2.00 TR +TE +2.00 2.00 TB 20.00 2.00 TR +TE +1.00 1.00 0.00 setrgbcolor +2.00 22.00 TB 4.00 2.00 TR +TE +2.00 22.00 TB 18.00 4.00 TR +TE +2.00 20.00 TB 12.00 2.00 TR +TE +2.00 18.00 TB 14.00 4.00 TR +TE +2.00 18.00 TB 20.00 4.00 TR +TE +2.00 16.00 TB 4.00 2.00 TR +TE +2.00 16.00 TB 10.00 2.00 TR +TE +2.00 16.00 TB 18.00 2.00 TR +TE +2.00 14.00 TB 20.00 4.00 TR +TE +2.00 6.00 TB 4.00 2.00 TR +TE +2.00 6.00 TB 16.00 4.00 TR +TE +2.00 6.00 TB 22.00 2.00 TR +TE +2.00 4.00 TB 12.00 2.00 TR +TE +2.00 2.00 TB 14.00 2.00 TR +TE +2.00 2.00 TB 22.00 2.00 TR +TE +0.00 1.00 0.00 setrgbcolor +2.00 22.00 TB 10.00 2.00 TR +TE +2.00 20.00 TB 16.00 2.00 TR +TE +2.00 20.00 TB 20.00 4.00 TR +TE +2.00 18.00 TB 4.00 2.00 TR +TE +2.00 18.00 TB 10.00 2.00 TR +TE +2.00 16.00 TB 12.00 2.00 TR +TE +2.00 16.00 TB 20.00 2.00 TR +TE +2.00 14.00 TB 14.00 2.00 TR +TE +2.00 14.00 TB 18.00 2.00 TR +TE +2.00 10.00 TB 4.00 2.00 TR +TE +2.00 10.00 TB 16.00 2.00 TR +TE +2.00 4.00 TB 10.00 2.00 TR +TE +2.00 4.00 TB 16.00 2.00 TR +TE +2.00 4.00 TB 20.00 2.00 TR +TE +2.00 2.00 TB 18.00 2.00 TR +TE +0.00 0.00 0.00 setrgbcolor +2.00 24.00 TB 0.00 26.00 TR +TE +2.00 22.00 TB 0.00 2.00 TR +TE +22.00 2.00 TB 6.00 2.00 TR +TE +10.00 14.00 TB 24.00 2.00 TR +TE +2.00 20.00 TB 0.00 4.00 TR +TE +2.00 18.00 TB 0.00 2.00 TR +TE +2.00 16.00 TB 0.00 4.00 TR +TE +2.00 14.00 TB 0.00 2.00 TR +TE +2.00 12.00 TB 0.00 4.00 TR +TE +2.00 12.00 TB 10.00 2.00 TR +TE +2.00 12.00 TB 14.00 2.00 TR +TE +2.00 12.00 TB 18.00 2.00 TR +TE +2.00 12.00 TB 22.00 4.00 TR +TE +2.00 10.00 TB 0.00 2.00 TR +TE +10.00 2.00 TB 24.00 2.00 TR +TE +2.00 8.00 TB 0.00 4.00 TR +TE +2.00 6.00 TB 0.00 2.00 TR +TE +2.00 4.00 TB 0.00 4.00 TR +TE +2.00 2.00 TB 0.00 2.00 TR +TE +2.00 0.00 TB 0.00 26.00 TR +TE diff --git a/backend/tests/data/print/gif/ultracode_a.gif b/backend/tests/data/print/gif/ultracode_a.gif new file mode 100644 index 0000000000000000000000000000000000000000..c6bb8b56c0ad7757fe016876fd5c7dd9e3aa70bb GIT binary patch literal 216 zcmZ?wbh9u|lwy!#_{7Kn1ph$*NI@Ww1p+!C0;Gn4c`3)PJO2!h3A6;1@EqE`)%9S2 zm{`W#@2z~?0WuK_T9$2nBz?rm<972!%@vnh?DjGRRcQ0|X+J$4cqy_+QM0#dBiDut zZ<*W-S}pb;EZU>}`rKCE8eNl{rRD5T_Z|N|(?ukbHN(HzQq8w1vbDW~TQ5bXKvTv- zO>@drr_k;KkAOL`^IBLI1o2JtGs@KCStXg}xwgN1hE}VM)5Khxoy%f{4jn$i$H`y~ E04?rS8vp9$u1 z=TP&HY|f{Q&2&Ij57mf1PZ?PMM&g8M2Un;yy29l55$5W-oqW;a_z-0D#g(AIc^2?brA{1#BI&cDJtMV`LqBj8vfoA{! literal 0 HcmV?d00001 diff --git a/backend/tests/data/print/png/ultracode_a.png b/backend/tests/data/print/png/ultracode_a.png new file mode 100644 index 0000000000000000000000000000000000000000..f32580c37d1920fe7369b6bf82890d771ca255bd GIT binary patch literal 249 zcmV{YushK>(uWKGBX4a@%7?UEW#u z9K9?pM}_I7X^fR$R`+yv9AfK!0gy!lrY@hk$Q3w@{jFxb68Pz$b>FobC`GNsT{@lcBi}Vs z72Go`t62l-eQ>wmO>zF0P#SO4Z)#j%ckl56LBC}*+WbWy00000NkvXXu0mjfE^und literal 0 HcmV?d00001 diff --git a/backend/tests/data/print/svg/ultracode_a.svg b/backend/tests/data/print/svg/ultracode_a.svg new file mode 100644 index 00000000..7f733427 --- /dev/null +++ b/backend/tests/data/print/svg/ultracode_a.svg @@ -0,0 +1,94 @@ + + + + Zint Generated Symbol + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/tests/data/print/tif/ultracode_a.tif b/backend/tests/data/print/tif/ultracode_a.tif new file mode 100644 index 0000000000000000000000000000000000000000..e943b09efc17bfde735524382fcc4f5108200f2a GIT binary patch literal 2248 zcmdUv%}&EG5QNuFfSxLG0Hn4LfOrlLRN^T)^~jMU55<{uf5!1FRVAQ4K+-hhi9P9lIBUqJg1F+EsIlhUlZyHxAl9S_9 zT)U`Ma)>RBbw4>jOshO|*;Ld#-&QY9+sL4biiJyPkmy5fJStYlYdn=kAb8;#nJSM+ zW8*z+unDbiT110~R{DKE!Tl3Z(}Z@7pkwzD0bg#pBwl# x=2m^{yVC0peO|TCx?H&brg{VYu6j%P_mr>0Wr= 92 (%zu)\n", i, symbol.errtxt, strlen(symbol.errtxt)); + assert_zero(strcmp(symbol.errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (%zu, %zu)\n", i, symbol.errtxt, data[i].expected, strlen(symbol.errtxt), strlen(data[i].expected)); + } + + testFinish(); +} + int main() { test_utf8_to_unicode(); + test_debug_test_codeword_dump_int(); testReport(); diff --git a/backend/tests/test_print.c b/backend/tests/test_print.c index 06bb0631..07d56bb1 100644 --- a/backend/tests/test_print.c +++ b/backend/tests/test_print.c @@ -34,7 +34,6 @@ //#define TEST_PRINT_GENERATE_EXPECTED 1 //#define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt" -//#define TEST_PRINT_OVERWRITE_EXPECTED "gif" static void test_print(void) { @@ -52,6 +51,7 @@ static void test_print(void) /* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "code128_aim" }, /* 1*/ { BARCODE_QRCODE, 2, 1, "1234567890", "qr_v1_m" }, /* 2*/ { BARCODE_DOTCODE, -1, -1, "2741", "dotcode_aim_fig7" }, + /* 3*/ { BARCODE_ULTRA, -1, -1, "A", "ultracode_a" }, }; int data_size = sizeof(data) / sizeof(struct item); diff --git a/backend/tests/test_ultra.c b/backend/tests/test_ultra.c new file mode 100644 index 00000000..e62361e7 --- /dev/null +++ b/backend/tests/test_ultra.c @@ -0,0 +1,329 @@ +/* + libzint - the open source barcode library + Copyright (C) 2020 Robin Stuart + + 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. + */ +/* vim: set ts=4 sw=4 et : */ + +//#define TEST_INPUT_GENERATE_EXPECTED 1 +//#define TEST_ENCODE_GENERATE_EXPECTED 1 + +#include "testcommon.h" + +static void test_input(void) +{ + testStart(""); + + int ret; + struct item { + int input_mode; + int eci; + int option_1; + int option_3; + unsigned char* data; + int ret; + char* expected; + char* comment; + }; + struct item data[] = { + /* 0*/ { UNICODE_MODE, 0, -1, -1, "A", 0, "(2) 257 65", "" }, + /* 1*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "A", 0, "(2) 272 65", "" }, + /* 2*/ { UNICODE_MODE, 0, -1, -1, "ABC", 0, "(4) 257 65 66 67", "" }, + /* 3*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ABC", 0, "(4) 272 65 66 67", "" }, + /* 4*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ULTRACODE_123456789!", 0, "(17) 272 85 76 84 82 65 67 79 68 69 95 140 162 184 206 57 33", "" }, + /* 5*/ { UNICODE_MODE, 0, -1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(250) 257 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "249 chars EC2" }, + /* 6*/ { UNICODE_MODE, 0, -1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ZINT_ERROR_TOO_LONG, "Error 591: Data too long for selected error correction capacity", "250 chars EC2" }, + /* 7*/ { UNICODE_MODE, 0, 1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(274) 257 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "273 chars EC0" }, + /* 8*/ { UNICODE_MODE, 0, 1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ZINT_ERROR_TOO_LONG, "Error 591: Data too long for selected error correction capacity", "274 chars EC0" }, + /* 9*/ { UNICODE_MODE, 0, -1, -1, "é", 0, "(2) 257 233", "" }, + /* 10*/ { UNICODE_MODE, 0, -1, -1, "β", ZINT_WARN_USES_ECI, "Warning (2) 263 226", "" }, + /* 11*/ { UNICODE_MODE, 9, -1, -1, "β", 0, "(2) 263 226", "" }, + /* 12*/ { UNICODE_MODE, 9, -1, -1, "βAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(250) 263 226 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "249 chars EC2" }, + /* 13*/ { UNICODE_MODE, 9, -1, ULTRA_COMPRESSION, "A", 0, "(2) 272 65", "Note ECI ignored and not outputted if ULTRA_COMPRESSION and all ASCII" }, + /* 14*/ { UNICODE_MODE, 15, -1, -1, "Ŗ", 0, "(2) 268 170", "" }, + /* 15*/ { GS1_MODE, 0, -1, -1, "[01]03453120000011[17]20121125[10]ABCD1234", ZINT_ERROR_INVALID_DATA, "Error 259: Invalid data length for AI (17)", "AIMD/TSC15032-43 G.6 Invalid [17] 4-digit year used in example" }, + /* 16*/ { GS1_MODE, 0, -1, -1, "[01]03453120000011[17]121125[10]ABCD1234", 0, "(20) 273 129 131 173 159 148 128 128 139 145 140 139 153 138 65 66 67 68 140 162", "" }, + /* 17*/ { GS1_MODE, 0, -1, -1, "[01]03453120000011[17]121125[10]ABCD1234", 0, "(20) 273 129 131 173 159 148 128 128 139 145 140 139 153 138 65 66 67 68 140 162", "" }, + /* 18*/ { GS1_MODE, 0, -1, -1, "[17]120508[10]ABCD1234[410]9501101020917", 0, "(21) 273 145 140 133 136 138 65 66 67 68 140 162 272 169 137 178 139 129 130 137 145", "" }, + /* 19*/ { GS1_MODE, 0, -1, -1, "[17]120508[10]ABCDEFGHI[410]9501101020917", 0, "(21) 273 145 140 133 136 138 65 66 67 68 140 162 272 169 137 178 139 129 130 137 145", "" }, + /* 20*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://", 0, "(4) 272 280 269 165", "" }, + /* 21*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, ".cgi", 0, "(4) 272 280 274 131", "" }, + /* 22*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://a.cgi", 0, "(6) 272 280 269 165 6 107", "" }, + }; + int data_size = sizeof(data) / sizeof(struct item); + + char escaped[1024]; + + for (int i = 0; i < data_size; i++) { + + struct zint_symbol* symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->symbology = BARCODE_ULTRA; + symbol->input_mode = data[i].input_mode; + symbol->eci = data[i].eci; + if (data[i].option_1 != -1) { + symbol->option_1 = data[i].option_1; + } + if (data[i].option_3 != -1) { + symbol->option_3 = data[i].option_3; + } + //symbol->debug = ZINT_DEBUG_PRINT | ZINT_DEBUG_TEST; + symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt + + int length = strlen(data[i].data); + + ret = ZBarcode_Encode(symbol, data[i].data, length); + assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); + + #ifdef TEST_INPUT_GENERATE_EXPECTED + printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, \"%s\", \"%s\" },\n", + i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), + testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment); + #else + if (ret < 5) { + assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); + } + #endif + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +static void test_encode(void) +{ + testStart(""); + + int ret; + struct item { + int input_mode; + int eci; + int option_1; + int option_3; + unsigned char* data; + int ret; + + int expected_rows; + int expected_width; + char* comment; + char* expected; + }; + struct item data[] = { + /* 0*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ULTRACODE_123456789!", 0, 13, 22, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression", + "7777777777777777777777" + "7057065353533131551057" + "7767053515611616136717" + "7017036661565555363057" + "7767055333616336135717" + "7037036515535515366057" + "7707070707070707070707" + "7067016561133113551017" + "7737035155311665165737" + "7057066561155551653057" + "7767033315616663515717" + "7017051653331136333057" + "7777777777777777777777" + }, + /* 1*/ { UNICODE_MODE, 0, -1, -1, "ULTRACODE_123456789!", 0, 13, 24, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** no compression; verified against bwipp", + "777777777777777777777777" + "705706533153313111101157" + "776703361661161666676617" + "703706115156555511303357" + "775705556561633656175517" + "703701311653551535501657" + "770707070707070707070707" + "706701656113311311101117" + "775703333531166566676537" + "701706651315555113303357" + "773705515161666351175517" + "701706166533113663603357" + "777777777777777777777777" + }, + /* 2*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "HEIMASÍÐA KENNARAHÁSKÓLA ÍSLANDS", 0, 19, 23, "AIMD/TSC15032-43 Figure G.2 **NOT SAME** different compression", + "77777777777777777777777" + "70070663151561555150557" + "77070315565635366667617" + "70070666656561115530357" + "77570535365656556367117" + "70370153656135163550357" + "77170707070707070707077" + "70570156315513136160357" + "77370533531631615537117" + "70070361155313351360657" + "77670515613665166537117" + "70170651131551335150357" + "77570707070707070707077" + "70670535163551333630617" + "77170111531613611567137" + "70070566665531335610357" + "77070151331365561537137" + "70070333656153153360617" + "77777777777777777777777" + }, + /* 3*/ { DATA_MODE, 0, -1, -1, "\110\105\111\115\101\123\315\320\101\040\113\105\116\116\101\122\101\110\301\123\113\323\114\101\040\315\123\114\101\116\104\123", 0, 19, 23, "AIMD/TSC15032-43 Figure G.2 **NOT SAME** no compression; verified against bwipp", + "77777777777777777777777" + "70070633151153313350137" + "77070315666661161167617" + "70070663155553555530557" + "77570531366336136167367" + "70370155555515653350537" + "77170707070707070707077" + "70570135513311133130357" + "77370513331166611617117" + "70070351153555533550557" + "77670613615636356367117" + "70170156336355515530657" + "77570707070707070707077" + "70670615133513355130117" + "77170136511651166517637" + "70070365635335515350557" + "77070613551651656517637" + "70070361115516163130317" + "77777777777777777777777" + }, + /* 4*/ { UNICODE_MODE, 10, -1, ULTRA_COMPRESSION, "אולטרה-קוד1234", 0, 13, 19, "AIMD/TSC15032-43 Figure G.3 Same except DCC correct whereas DCC in Figure G.3 is incorrent", + "7777777777777777777" + "7057065565566616657" + "7737053333613351517" + "7067015155551565167" + "7757053333633356657" + "7037066561515535537" + "7707070707070707077" + "7067013561166666517" + "7737031653311131137" + "7017065336156555357" + "7767016565663636117" + "7017051316355311357" + "7777777777777777777" + }, + /* 5*/ { DATA_MODE, 0, -1, -1, "\340\345\354\350\370\344\055\367\345\343\061\062\063\064", 0, 13, 20, "AIMD/TSC15032-43 Figure G.3 **NOT SAME** no compression; verified against bwipp", + "77777777777777777777" + "70570611115666161157" + "77670333656133516617" + "70170655165515651157" + "77570516516333565617" + "70370163335155353557" + "77070707070707070707" + "70670153311666661117" + "77370315553111316637" + "70570631611565551357" + "77370166136636365117" + "70170613653553116357" + "77777777777777777777" + }, + /* 6*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "https://aimglobal.org/jcrv3tX", 0, 13, 22, "AIMD/TSC15032-43 Figure G.4a **NOT SAME** different compression", + "7777777777777777777777" + "7057065133563156313037" + "7767051556651331566757" + "7017066611513613331017" + "7767053165666351655767" + "7037035651531533133057" + "7707070707070707070707" + "7067015511111161565017" + "7737036635335356151737" + "7057063111116533366057" + "7767031536633116511717" + "7017063363361363356057" + "7777777777777777777777" + }, + /* 7*/ { UNICODE_MODE, 0, -1, -1, "A", 0, 13, 13, "Verified against bwipp", + "7777777777777" + "7057063335517" + "7717035163667" + "7067061551557" + "7757056115637" + "7037013636557" + "7707070707077" + "7067011361117" + "7717033133337" + "7057011355157" + "7737065163617" + "7017033536357" + "7777777777777" + }, + }; + int data_size = sizeof(data) / sizeof(struct item); + + char escaped[1024]; + + for (int i = 0; i < data_size; i++) { + + struct zint_symbol* symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->symbology = BARCODE_ULTRA; + symbol->input_mode = data[i].input_mode; + symbol->eci = data[i].eci; + if (data[i].option_1 != -1) { + symbol->option_1 = data[i].option_1; + } + if (data[i].option_3 != -1) { + symbol->option_3 = data[i].option_3; + } + //symbol->debug = ZINT_DEBUG_PRINT; + + int length = strlen(data[i].data); + + ret = ZBarcode_Encode(symbol, data[i].data, length); + assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); + + #ifdef TEST_ENCODE_GENERATE_EXPECTED + printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, %d, \"%s\",\n", + i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3), + testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); + testUtilModulesDump(symbol, " ", "\n"); + printf(" },\n"); + #else + if (ret < 5) { + 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); + + if (ret == 0) { + int width, row; + ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); + assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); + } + } + #endif + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +int main() +{ + test_input(); + test_encode(); + + testReport(); + + return 0; +} diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index 000772b1..e91b96dc 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -328,6 +328,16 @@ char* testUtilInputModeName(int input_mode) { return data[input_mode].name; } +char* testUtilOption3Name(int option_3) { + switch (option_3) { + case DM_SQUARE: return "DM_SQUARE"; + case DM_DMRE: return "DM_DMRE"; + case ZINT_FULL_MULTIBYTE: return "ZINT_FULL_MULTIBYTE"; + case ULTRA_COMPRESSION: return "ULTRA_COMPRESSION"; + } + return "-1"; +} + int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size) { buffer[0] = '\0'; @@ -680,7 +690,7 @@ void testUtilModulesDump(const struct zint_symbol* symbol, char* prefix, char* p } putchar('"'); for (w = 0; w < symbol->width; w++) { - putchar(module_is_set(symbol, r, w) ? '1' : '0'); + putchar(module_is_set(symbol, r, w) + '0'); } putchar('"'); if (*postfix) { @@ -696,7 +706,7 @@ int testUtilModulesCmp(const struct zint_symbol* symbol, const char* expected, i int r, w = 0; for (r = 0; r < symbol->rows && e < ep; r++) { for (w = 0; w < symbol->width && e < ep; w++) { - if (module_is_set(symbol, r, w) != (*e == '1')) { + if (module_is_set(symbol, r, w) + '0' != *e) { *row = r; *width = w; return 1 /*fail*/; diff --git a/backend/tests/testcommon.h b/backend/tests/testcommon.h index fb5655d8..f11bbf72 100644 --- a/backend/tests/testcommon.h +++ b/backend/tests/testcommon.h @@ -67,6 +67,7 @@ extern void vector_free(struct zint_symbol *symbol); /* Free vector structures * char* testUtilBarcodeName(int symbology); char* testUtilErrorName(int error_number); char* testUtilInputModeName(int input_mode); +char* testUtilOption3Name(int option_3); int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size); char* testUtilEscape(char* buffer, int length, char* escaped, int escaped_size); char* testUtilReadCSVField(char* buffer, char* field, int field_size); diff --git a/backend/ultra.c b/backend/ultra.c index 807ea38a..44c90cc5 100644 --- a/backend/ultra.c +++ b/backend/ultra.c @@ -28,6 +28,7 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* vim: set ts=4 sw=4 et : */ /* This version was developed using AIMD/TSC15032-43 v0.99c Edit 60, dated 4th Nov 2015 */ @@ -209,9 +210,9 @@ int ultra_find_fragment(unsigned char source[], int source_length, int position) for (j = 0; j < 27; j++) { latch = 0; - if ((position + strlen(fragment[j])) <= source_length) { + if ((position + (int) strlen(fragment[j])) <= source_length) { latch = 1; - for (k = 0; k < strlen(fragment[j]); k++) { + for (k = 0; k < (int) strlen(fragment[j]); k++) { if (source[position + k] != fragment[j][k]) { latch = 0; } @@ -261,10 +262,10 @@ float look_ahead_eightbit(unsigned char source[], int in_length, int in_locn, ch } /* Encode character in the ASCII mode/submode (including numeric compression) */ -float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char current_mode, int symbol_mode, int end_char, int cw[], int* cw_len, int gs1){ +float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char current_mode, int symbol_mode, int end_char, int cw[], int* cw_len, int* encoded, int gs1) { int codeword_count = 0; int i; - int first_digit, second_digit; + int first_digit, second_digit, done; int letters_encoded = 0; if (current_mode == EIGHTBIT_MODE) { @@ -284,6 +285,7 @@ float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char i = in_locn; do { /* Check for double digits */ + done = 0; if (in_locn != (in_length - 1)) { first_digit = posn(ultra_digit, source[i]); second_digit = posn(ultra_digit, source[i + 1]); @@ -294,31 +296,36 @@ float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char cw[codeword_count] = (10 * first_digit) + second_digit + 128; codeword_count++; i += 2; + done = 1; } else if ((first_digit >= 0) && (first_digit <= 9) && (second_digit == 10)) { /* Single digit followed by selected decimal point character */ cw[codeword_count] = first_digit + 228; codeword_count++; i += 2; + done = 1; } else if ((first_digit == 10) && (second_digit >= 0) && (second_digit <= 9)) { /* Selected decimal point character followed by single digit */ cw[codeword_count] = second_digit + 238; codeword_count++; i += 2; + done = 1; } else if ((first_digit >= 0) && (first_digit <= 10) && (second_digit == 11)) { /* Single digit or decimal point followed by field deliminator */ cw[codeword_count] = first_digit + 248; codeword_count++; i += 2; + done = 1; } else if ((first_digit == 11) && (second_digit >= 0) && (second_digit <= 10)) { /* Field deliminator followed by single digit or decimal point */ cw[codeword_count] = second_digit + 259; codeword_count++; i += 2; + done = 1; } } } - if (source[i] < 0x7F) { + if (!done && source[i] < 0x80) { if ((source[i] == '[') && gs1) { cw[codeword_count] = 272; // FNC1 } else { @@ -330,6 +337,9 @@ float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char } while ((i < in_length) && (i < end_char) && (source[i] < 0x80)); letters_encoded = i - in_locn; + if (encoded != NULL) { + *encoded = letters_encoded; + } *cw_len = codeword_count; @@ -365,7 +375,7 @@ int get_subset(unsigned char source[], int in_length, int in_locn) { } /* Encode characters in the C43 compaction submode */ -float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char current_mode, int end_char, int cw[], int* cw_len, int gs1){ +float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char current_mode, int end_char, int cw[], int* cw_len, int* encoded, int gs1) { int codeword_count = 0; int subcodeword_count = 0; int i; @@ -481,24 +491,24 @@ float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char cu fragno = -1; } if ((fragno >= 0) && (fragno <= 18)) { - subcw[subcodeword_count] = fragno; + subcw[subcodeword_count] = fragno; // C43 Set 3 codewords 0 to 18 subcodeword_count++; sublocn += strlen(fragment[fragno]); } - if ((fragno >= 18) && (fragno <= 25)) { - subcw[subcodeword_count] = fragno + 17; + if ((fragno >= 19) && (fragno <= 25)) { + subcw[subcodeword_count] = fragno + 17; // C43 Set 3 codewords 36 to 42 subcodeword_count++; sublocn += strlen(fragment[fragno]); } if (fragno == -1) { - subcw[subcodeword_count] = posn(ultra_c43_set3, source[sublocn]); + subcw[subcodeword_count] = posn(ultra_c43_set3, source[sublocn]) + 19; // C43 Set 3 codewords 19 to 35 subcodeword_count++; sublocn++; } subset = unshift_set; } - if (sublocn < in_length) { + if (sublocn < in_length && sublocn < end_char) { new_subset = get_subset(source, in_length, sublocn); if (((subset == 1) && (new_subset == 2)) && ((source[sublocn] == '.') || (source[sublocn] == ','))) { @@ -534,6 +544,9 @@ float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char cu } letters_encoded = sublocn - in_locn; + if (encoded != NULL) { + *encoded = letters_encoded; + } for (i = 0; i < subcodeword_count; i += 3) { base43_value = (43 * 43 * subcw[i]) + (43 * subcw[i + 1]) + subcw[i + 2]; @@ -543,6 +556,7 @@ float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char cu codeword_count++; } + *cw_len = codeword_count; if (codeword_count == 0) { @@ -568,33 +582,39 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou int fragment_length; int fragno; int gs1 = 0; + int ascii_encoded, c43_encoded; #ifndef _MSC_VER unsigned char crop_source[in_length + 1]; char mode[in_length + 1]; - int cw_fragment[in_length + 1]; + int cw_fragment[in_length * 2 + 1]; #else unsigned char * crop_source = (unsigned char *) _alloca((in_length + 1) * sizeof (unsigned char)); char * mode = (char *) _alloca((in_length + 1) * sizeof (char)); - int * cw_fragment = (int *) _alloca((in_length + 1) * sizeof (int)); + int * cw_fragment = (int *) _alloca((in_length * 2 + 1) * sizeof (int)); #endif /* _MSC_VER */ /* Section 7.6.2 indicates that ECI \000003 to \811799 are supported */ /* but this seems to contradict Table 5 which only shows up to \000898 */ if (symbol->eci > 898) { - strcpy(symbol->errtxt, "ECI value out of range"); + strcpy(symbol->errtxt, "592: ECI value out of range"); return ZINT_ERROR_INVALID_OPTION; } + if ((symbol->input_mode & 0x07) == GS1_MODE) { + gs1 = 1; + } + // Decide start character codeword (from Table 5) symbol_mode = ASCII_MODE; - for (i = 0; i < in_length; i++) { + for (i = 0; i < (int) in_length; i++) { if (source[i] >= 0x80) { symbol_mode = EIGHTBIT_MODE; + break; } } - if (symbol->option_3 != ULTRA_COMPRESSION) { + if (symbol->option_3 != ULTRA_COMPRESSION && !gs1) { // Force eight-bit mode by default as other modes are poorly documented symbol_mode = EIGHTBIT_MODE; } @@ -612,7 +632,7 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou } else { /* Calculate start character codeword */ if (symbol_mode == ASCII_MODE) { - if (symbol->input_mode == GS1_MODE) { + if (gs1) { codewords[0] = 273; } else { codewords[0] = 272; @@ -686,33 +706,29 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou } codeword_count++; - for (i = 7; i < (in_length - 2); i++) { + for (i = 7; i < ((int) in_length - 2); i++) { crop_source[i - 7] = source[i]; } crop_length = in_length - 9; crop_source[crop_length] = '\0'; } else { /* Make a cropped version of input data - removes http:// and https:// if needed */ - for (i = input_locn; i < in_length; i++) { + for (i = input_locn; i < (int) in_length; i++) { crop_source[i - input_locn] = source[i]; } crop_length = in_length - input_locn; crop_source[crop_length] = '\0'; } - if ((symbol->input_mode & 0x07) == GS1_MODE) { - gs1 = 1; - } - /* Attempt encoding in all three modes to see which offers best compaction and store results */ - if (symbol->option_3 == ULTRA_COMPRESSION) { + if (symbol->option_3 == ULTRA_COMPRESSION || gs1) { current_mode = symbol_mode; input_locn = 0; do { end_char = input_locn + PREDICT_WINDOW; eightbit_score = look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, end_char, cw_fragment, &fragment_length, gs1); - ascii_score = look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode, end_char, cw_fragment, &fragment_length, gs1); - c43_score = look_ahead_c43(crop_source, crop_length, input_locn, current_mode, end_char, cw_fragment, &fragment_length, gs1); + ascii_score = look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode, end_char, cw_fragment, &fragment_length, &ascii_encoded, gs1); + c43_score = look_ahead_c43(crop_source, crop_length, input_locn, current_mode, end_char, cw_fragment, &fragment_length, &c43_encoded, gs1); mode[input_locn] = 'a'; current_mode = ASCII_MODE; @@ -726,7 +742,19 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou mode[input_locn] = '8'; current_mode = EIGHTBIT_MODE; } - input_locn++; + if (mode[input_locn] == 'a') { + for (i = 0; i < ascii_encoded; i++) { + mode[input_locn + i] = 'a'; + } + input_locn += ascii_encoded; + } else if (mode[input_locn] == 'c') { + for (i = 0; i < c43_encoded; i++) { + mode[input_locn + i] = 'c'; + } + input_locn += c43_encoded; + } else { + input_locn++; + } } while (input_locn < crop_length); } else { // Force eight-bit mode @@ -736,6 +764,10 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou } mode[input_locn] = '\0'; + if (symbol->debug & ZINT_DEBUG_PRINT) { + printf("Mode: %s (%zu)\n", mode, strlen(mode)); + } + /* Use results from test to perform actual mode switching */ current_mode = symbol_mode; input_locn = 0; @@ -747,14 +779,14 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou switch(mode[input_locn]) { case 'a': - ascii_score = look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode, input_locn + block_length, cw_fragment, &fragment_length, gs1); + look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode, input_locn + block_length, cw_fragment, &fragment_length, NULL, gs1); current_mode = ASCII_MODE; break; case 'c': - c43_score = look_ahead_c43(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, cw_fragment, &fragment_length, gs1); + look_ahead_c43(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, cw_fragment, &fragment_length, NULL, gs1); /* Substitute temporary latch if possible */ - if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 261) && (fragment_length >= 5) && (fragment_length <= 11)) { + if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 260) && (fragment_length >= 5) && (fragment_length <= 11)) { /* Temporary latch to submode 1 from Table 11 */ cw_fragment[0] = 256 + ((fragment_length - 5) / 2); } else if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 266) && (fragment_length >= 5) && (fragment_length <= 11)) { @@ -768,7 +800,7 @@ int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned char sou } break; case '8': - eightbit_score = look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, cw_fragment, &fragment_length, gs1); + look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, cw_fragment, &fragment_length, gs1); current_mode = EIGHTBIT_MODE; break; } @@ -792,7 +824,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], int total_cws; int pads; int cw_memalloc; - int codeword[283]; + int codeword[282 + 4]; int i, j, locn; int total_height, total_width; char tilepat[6]; @@ -800,7 +832,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], int dcc; #ifdef _MSC_VER int* data_codewords; - char* pattern; + char* pattern; #endif /* _MSC_VER */ cw_memalloc = in_length * 2; @@ -809,7 +841,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], } if (symbol->eci > 811799) { - strcpy(symbol->errtxt, "ECI value not supported by Ultracode"); + strcpy(symbol->errtxt, "590: ECI value not supported by Ultracode"); return ZINT_ERROR_INVALID_OPTION; } @@ -821,9 +853,12 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], data_cw_count = ultra_generate_codewords(symbol, source, in_length, data_codewords); - if (symbol->debug) { + if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Codewords returned = %d\n", data_cw_count); } + if (symbol->debug & ZINT_DEBUG_TEST) { + debug_test_codeword_dump_int(symbol, data_codewords, data_cw_count); + } /* Default ECC level is EC2 */ if ((symbol->option_1 <= 0) || (symbol->option_1 > 6)) { @@ -845,14 +880,14 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], } acc = qcc - 3; - if (symbol->debug) { + if (symbol->debug & ZINT_DEBUG_PRINT) { printf("ECC codewords: %d\n", qcc); } /* Maximum capacity is 282 codewords */ total_cws = data_cw_count + qcc + 5; if (total_cws > 282) { - strcpy(symbol->errtxt, "Data too long for selected error correction capacity"); + strcpy(symbol->errtxt, "591: Data too long for selected error correction capacity"); return ZINT_ERROR_TOO_LONG; } @@ -871,7 +906,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], columns = (total_cws / rows) + 1; } - if (symbol->debug) { + if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Calculated size is %d rows by %d columns\n", rows, columns); } @@ -903,7 +938,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], } codeword[locn++] = qcc; // QCC - if (symbol->debug) { + if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Rearranged codewords with ECC:\n"); for (i = 0; i < locn; i++) { printf("%d ", codeword[i]); @@ -1004,7 +1039,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], pattern[((tiley + j) * total_width) + tilex] = tilepat[j]; } - if (symbol->debug) { + if (symbol->debug & ZINT_DEBUG_PRINT) { printf("DCC: %d\n", dcc); for (i = 0; i < (total_height * total_width); i++) {