mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
CHANNEL: use nested loops (CHNCHK) and pre-calculated values for performance
This commit is contained in:
parent
5875305cef
commit
3690c19749
106
backend/channel_precalcs.h
Normal file
106
backend/channel_precalcs.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2020 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.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
/* Channel code precalculated values to avoid excessive looping */
|
||||
/* To generate uncomment CHANNEL_GENERATE_PRECALCS define and run "./test_channel -f generate -g" */
|
||||
/* Paste result below here */
|
||||
static channel_precalc channel_precalcs7[] = {
|
||||
{ 115338, { 1, 3, 1, 1, 1, 1, 5, 1, }, { 1, 1, 1, 2, 1, 2, 3, 3, }, { 1, 7, 5, 5, 5, 5, 5, }, { 1, 7, 7, 7, 6, 6, 5, }, },
|
||||
{ 230676, { 1, 1, 2, 2, 4, 1, 1, 2, }, { 1, 2, 1, 3, 2, 1, 3, 1, }, { 1, 7, 7, 6, 5, 2, 2, }, { 1, 7, 6, 6, 4, 3, 3, }, },
|
||||
{ 346014, { 1, 2, 3, 1, 1, 1, 3, 2, }, { 1, 2, 2, 1, 1, 3, 1, 3, }, { 1, 7, 6, 4, 4, 4, 4, }, { 1, 7, 6, 5, 5, 5, 3, }, },
|
||||
{ 461352, { 1, 2, 1, 1, 1, 2, 2, 4, }, { 1, 3, 1, 1, 3, 2, 2, 1, }, { 1, 7, 6, 6, 6, 6, 5, }, { 1, 7, 5, 5, 5, 3, 2, }, },
|
||||
};
|
||||
static channel_precalc channel_precalcs8[] = {
|
||||
{ 119121, { 2, 1, 3, 2, 1, 3, 2, 1, }, { 1, 1, 1, 4, 3, 2, 1, 2, }, { 8, 7, 7, 5, 4, 4, 2, }, { 8, 8, 8, 8, 5, 3, 2, }, },
|
||||
{ 238242, { 2, 1, 1, 2, 2, 2, 1, 4, }, { 1, 1, 3, 1, 1, 2, 4, 2, }, { 8, 7, 7, 7, 6, 5, 4, }, { 8, 8, 8, 6, 6, 6, 5, }, },
|
||||
{ 357363, { 2, 2, 1, 4, 1, 1, 1, 3, }, { 1, 1, 1, 1, 3, 2, 5, 1, }, { 8, 7, 6, 6, 3, 3, 3, }, { 8, 8, 8, 8, 8, 6, 5, }, },
|
||||
{ 476484, { 2, 2, 1, 1, 3, 2, 3, 1, }, { 1, 1, 3, 1, 2, 2, 3, 2, }, { 8, 7, 6, 6, 6, 4, 3, }, { 8, 8, 8, 6, 6, 5, 4, }, },
|
||||
{ 595605, { 2, 3, 3, 2, 1, 1, 1, 2, }, { 1, 1, 2, 1, 1, 1, 5, 3, }, { 8, 7, 5, 3, 2, 2, 2, }, { 8, 8, 8, 7, 7, 7, 7, }, },
|
||||
{ 714726, { 2, 1, 1, 6, 1, 1, 2, 1, }, { 1, 2, 1, 3, 1, 4, 1, 2, }, { 8, 7, 7, 7, 2, 2, 2, }, { 8, 8, 7, 7, 5, 5, 2, }, },
|
||||
{ 833847, { 2, 1, 1, 3, 1, 3, 3, 1, }, { 1, 2, 3, 1, 1, 3, 2, 2, }, { 8, 7, 7, 7, 5, 5, 3, }, { 8, 8, 7, 5, 5, 5, 3, }, },
|
||||
{ 952968, { 2, 2, 2, 3, 2, 1, 2, 1, }, { 1, 2, 2, 1, 2, 2, 2, 3, }, { 8, 7, 6, 5, 3, 2, 2, }, { 8, 8, 7, 6, 6, 5, 4, }, },
|
||||
{ 1072089, { 2, 5, 1, 1, 2, 2, 1, 1, }, { 1, 2, 1, 3, 1, 3, 3, 1, }, { 8, 7, 3, 3, 3, 2, 1, }, { 8, 8, 7, 7, 5, 5, 3, }, },
|
||||
{ 1191210, { 2, 2, 1, 2, 1, 1, 3, 3, }, { 1, 3, 1, 1, 5, 1, 1, 2, }, { 8, 7, 6, 6, 5, 5, 5, }, { 8, 8, 6, 6, 6, 2, 2, }, },
|
||||
{ 1310331, { 2, 1, 2, 1, 2, 3, 2, 2, }, { 1, 4, 1, 3, 1, 1, 2, 2, }, { 8, 7, 7, 6, 6, 5, 3, }, { 8, 8, 5, 5, 3, 3, 3, }, },
|
||||
{ 1429452, { 2, 2, 1, 2, 2, 3, 2, 1, }, { 1, 5, 3, 1, 2, 1, 1, 1, }, { 8, 7, 6, 6, 5, 4, 2, }, { 8, 8, 4, 2, 2, 1, 1, }, },
|
||||
{ 1548573, { 3, 1, 1, 2, 5, 1, 1, 1, }, { 1, 1, 2, 2, 1, 2, 5, 1, }, { 8, 6, 6, 6, 5, 1, 1, }, { 8, 8, 8, 7, 6, 6, 5, }, },
|
||||
{ 1667694, { 3, 2, 2, 1, 1, 3, 2, 1, }, { 1, 1, 1, 1, 2, 4, 3, 2, }, { 8, 6, 5, 4, 4, 4, 2, }, { 8, 8, 8, 8, 8, 7, 4, }, },
|
||||
{ 1786815, { 3, 4, 2, 1, 2, 1, 1, 1, }, { 1, 1, 2, 1, 1, 2, 1, 6, }, { 8, 6, 3, 2, 2, 1, 1, }, { 8, 8, 8, 7, 7, 7, 6, }, },
|
||||
{ 1905936, { 3, 2, 1, 3, 1, 3, 1, 1, }, { 1, 2, 1, 1, 1, 4, 2, 3, }, { 8, 6, 5, 5, 3, 3, 1, }, { 8, 8, 7, 7, 7, 7, 4, }, },
|
||||
{ 2025057, { 3, 1, 2, 2, 1, 1, 4, 1, }, { 1, 3, 2, 1, 1, 1, 5, 1, }, { 8, 6, 6, 5, 4, 4, 4, }, { 8, 8, 6, 5, 5, 5, 5, }, },
|
||||
{ 2144178, { 3, 1, 2, 1, 2, 2, 2, 2, }, { 1, 5, 1, 1, 4, 1, 1, 1, }, { 8, 6, 6, 5, 5, 4, 3, }, { 8, 8, 4, 4, 4, 1, 1, }, },
|
||||
{ 2263299, { 4, 2, 1, 2, 1, 1, 1, 3, }, { 1, 1, 1, 1, 3, 3, 3, 2, }, { 8, 5, 4, 4, 3, 3, 3, }, { 8, 8, 8, 8, 8, 6, 4, }, },
|
||||
{ 2382420, { 4, 2, 1, 1, 1, 1, 4, 1, }, { 1, 2, 2, 2, 2, 2, 2, 2, }, { 8, 5, 4, 4, 4, 4, 4, }, { 8, 8, 7, 6, 5, 4, 3, }, },
|
||||
{ 2501541, { 5, 1, 1, 2, 2, 1, 1, 2, }, { 1, 1, 2, 3, 3, 1, 1, 3, }, { 8, 4, 4, 4, 3, 2, 2, }, { 8, 8, 8, 7, 5, 3, 3, }, },
|
||||
{ 2620662, { 6, 1, 1, 1, 2, 1, 1, 2, }, { 1, 2, 4, 1, 2, 3, 1, 1, }, { 8, 3, 3, 3, 3, 2, 2, }, { 8, 8, 7, 4, 4, 3, 1, }, },
|
||||
{ 2739783, { 1, 1, 1, 1, 3, 3, 4, 1, }, { 2, 1, 2, 1, 6, 1, 1, 1, }, { 8, 8, 8, 8, 8, 6, 4, }, { 8, 7, 7, 6, 6, 1, 1, }, },
|
||||
{ 2858904, { 1, 1, 2, 3, 3, 1, 3, 1, }, { 2, 1, 3, 1, 3, 1, 2, 2, }, { 8, 8, 8, 7, 5, 3, 3, }, { 8, 7, 7, 5, 5, 3, 3, }, },
|
||||
{ 2978025, { 1, 2, 2, 4, 1, 2, 1, 2, }, { 2, 1, 1, 1, 1, 3, 4, 2, }, { 8, 8, 7, 6, 3, 3, 2, }, { 8, 7, 7, 7, 7, 7, 5, }, },
|
||||
{ 3097146, { 1, 2, 2, 1, 3, 3, 2, 1, }, { 2, 1, 3, 3, 2, 2, 1, 1, }, { 8, 8, 7, 6, 6, 4, 2, }, { 8, 7, 7, 5, 3, 2, 1, }, },
|
||||
{ 3216267, { 1, 3, 1, 1, 1, 3, 1, 4, }, { 2, 1, 3, 2, 3, 2, 1, 1, }, { 8, 8, 6, 6, 6, 6, 4, }, { 8, 7, 7, 5, 4, 2, 1, }, },
|
||||
{ 3335388, { 1, 1, 1, 4, 4, 1, 2, 1, }, { 2, 2, 1, 1, 1, 1, 3, 4, }, { 8, 8, 8, 8, 5, 2, 2, }, { 8, 7, 6, 6, 6, 6, 6, }, },
|
||||
{ 3454509, { 1, 1, 2, 4, 3, 1, 2, 1, }, { 2, 2, 2, 5, 1, 1, 1, 1, }, { 8, 8, 8, 7, 4, 2, 2, }, { 8, 7, 6, 5, 1, 1, 1, }, },
|
||||
{ 3573630, { 1, 2, 1, 3, 1, 2, 3, 2, }, { 2, 2, 2, 1, 1, 4, 2, 1, }, { 8, 8, 7, 7, 5, 5, 4, }, { 8, 7, 6, 5, 5, 5, 2, }, },
|
||||
{ 3692751, { 1, 4, 2, 3, 2, 1, 1, 1, }, { 2, 2, 1, 1, 2, 1, 2, 4, }, { 8, 8, 5, 4, 2, 1, 1, }, { 8, 7, 6, 6, 6, 5, 5, }, },
|
||||
{ 3811872, { 1, 1, 2, 1, 3, 5, 1, 1, }, { 2, 3, 3, 2, 2, 1, 1, 1, }, { 8, 8, 8, 7, 7, 5, 1, }, { 8, 7, 5, 3, 2, 1, 1, }, },
|
||||
{ 3930993, { 1, 1, 1, 1, 6, 2, 2, 1, }, { 2, 4, 1, 2, 1, 3, 1, 1, }, { 8, 8, 8, 8, 8, 3, 2, }, { 8, 7, 4, 4, 3, 3, 1, }, },
|
||||
{ 4050114, { 1, 3, 3, 2, 2, 1, 2, 1, }, { 2, 6, 2, 1, 1, 1, 1, 1, }, { 8, 8, 6, 4, 3, 2, 2, }, { 8, 7, 2, 1, 1, 1, 1, }, },
|
||||
{ 4169235, { 2, 1, 2, 2, 4, 2, 1, 1, }, { 2, 1, 2, 1, 1, 1, 4, 3, }, { 8, 7, 7, 6, 5, 2, 1, }, { 8, 7, 7, 6, 6, 6, 6, }, },
|
||||
{ 4288356, { 2, 2, 2, 1, 1, 3, 3, 1, }, { 2, 1, 1, 4, 2, 1, 1, 3, }, { 8, 7, 6, 5, 5, 5, 3, }, { 8, 7, 7, 7, 4, 3, 3, }, },
|
||||
{ 4407477, { 2, 3, 3, 1, 2, 1, 1, 2, }, { 2, 1, 3, 2, 4, 1, 1, 1, }, { 8, 7, 5, 3, 3, 2, 2, }, { 8, 7, 7, 5, 4, 1, 1, }, },
|
||||
{ 4526598, { 2, 1, 4, 1, 4, 1, 1, 1, }, { 2, 2, 2, 1, 2, 3, 1, 2, }, { 8, 7, 7, 4, 4, 1, 1, }, { 8, 7, 6, 5, 5, 4, 2, }, },
|
||||
{ 4645719, { 2, 4, 2, 1, 1, 2, 1, 2, }, { 2, 2, 1, 1, 3, 2, 3, 1, }, { 8, 7, 4, 3, 3, 3, 2, }, { 8, 7, 6, 6, 6, 4, 3, }, },
|
||||
{ 4764840, { 2, 1, 1, 1, 2, 4, 1, 3, }, { 2, 4, 1, 2, 1, 3, 1, 1, }, { 8, 7, 7, 7, 7, 6, 3, }, { 8, 7, 4, 4, 3, 3, 1, }, },
|
||||
{ 4883961, { 3, 1, 1, 3, 2, 2, 1, 2, }, { 2, 1, 2, 2, 2, 1, 2, 3, }, { 8, 6, 6, 6, 4, 3, 2, }, { 8, 7, 7, 6, 5, 4, 4, }, },
|
||||
{ 5003082, { 3, 3, 3, 1, 1, 1, 2, 1, }, { 2, 1, 2, 1, 1, 3, 1, 4, }, { 8, 6, 4, 2, 2, 2, 2, }, { 8, 7, 7, 6, 6, 6, 4, }, },
|
||||
{ 5122203, { 3, 1, 1, 2, 1, 2, 1, 4, }, { 2, 3, 1, 1, 1, 2, 4, 1, }, { 8, 6, 6, 6, 5, 5, 4, }, { 8, 7, 5, 5, 5, 5, 4, }, },
|
||||
{ 5241324, { 4, 1, 1, 3, 1, 2, 2, 1, }, { 2, 1, 3, 1, 1, 3, 3, 1, }, { 8, 5, 5, 5, 3, 3, 2, }, { 8, 7, 7, 5, 5, 5, 3, }, },
|
||||
{ 5360445, { 4, 3, 1, 1, 2, 1, 1, 2, }, { 2, 4, 1, 3, 2, 1, 1, 1, }, { 8, 5, 3, 3, 3, 2, 2, }, { 8, 7, 4, 4, 2, 1, 1, }, },
|
||||
{ 5479566, { 1, 1, 3, 1, 3, 2, 1, 3, }, { 3, 1, 1, 2, 1, 2, 1, 4, }, { 8, 8, 8, 6, 6, 4, 3, }, { 8, 6, 6, 6, 5, 5, 4, }, },
|
||||
{ 5598687, { 1, 2, 1, 1, 5, 1, 3, 1, }, { 3, 1, 1, 1, 1, 3, 1, 4, }, { 8, 8, 7, 7, 7, 3, 3, }, { 8, 6, 6, 6, 6, 6, 4, }, },
|
||||
{ 5717808, { 1, 3, 1, 2, 1, 3, 1, 3, }, { 3, 1, 1, 2, 4, 1, 1, 2, }, { 8, 8, 6, 6, 5, 5, 3, }, { 8, 6, 6, 6, 5, 2, 2, }, },
|
||||
{ 5836929, { 1, 1, 2, 3, 1, 2, 3, 2, }, { 3, 2, 1, 1, 1, 1, 2, 4, }, { 8, 8, 8, 7, 5, 5, 4, }, { 8, 6, 5, 5, 5, 5, 5, }, },
|
||||
{ 5956050, { 1, 2, 3, 3, 2, 2, 1, 1, }, { 3, 2, 3, 1, 1, 1, 1, 3, }, { 8, 8, 7, 5, 3, 2, 1, }, { 8, 6, 5, 3, 3, 3, 3, }, },
|
||||
{ 6075171, { 1, 3, 1, 1, 3, 3, 2, 1, }, { 3, 3, 1, 1, 3, 1, 2, 1, }, { 8, 8, 6, 6, 6, 4, 2, }, { 8, 6, 4, 4, 4, 2, 2, }, },
|
||||
{ 6194292, { 2, 1, 1, 3, 4, 1, 2, 1, }, { 3, 1, 2, 1, 3, 1, 3, 1, }, { 8, 7, 7, 7, 5, 2, 2, }, { 8, 6, 6, 5, 5, 3, 3, }, },
|
||||
{ 6313413, { 2, 3, 2, 2, 1, 2, 2, 1, }, { 3, 1, 1, 2, 1, 3, 2, 2, }, { 8, 7, 5, 4, 3, 3, 2, }, { 8, 6, 6, 6, 5, 5, 3, }, },
|
||||
{ 6432534, { 2, 3, 1, 1, 2, 2, 3, 1, }, { 3, 2, 1, 2, 3, 1, 2, 1, }, { 8, 7, 5, 5, 5, 4, 3, }, { 8, 6, 5, 5, 4, 2, 2, }, },
|
||||
{ 6551655, { 3, 1, 1, 2, 1, 4, 1, 2, }, { 3, 1, 2, 3, 1, 1, 3, 1, }, { 8, 6, 6, 6, 5, 5, 2, }, { 8, 6, 6, 5, 3, 3, 3, }, },
|
||||
{ 6670776, { 3, 1, 1, 1, 1, 3, 4, 1, }, { 3, 3, 1, 2, 1, 1, 3, 1, }, { 8, 6, 6, 6, 6, 6, 4, }, { 8, 6, 4, 4, 3, 3, 3, }, },
|
||||
{ 6789897, { 5, 2, 1, 1, 2, 1, 2, 1, }, { 3, 1, 1, 1, 2, 2, 3, 2, }, { 8, 4, 3, 3, 3, 2, 2, }, { 8, 6, 6, 6, 6, 5, 4, }, },
|
||||
{ 6909018, { 1, 2, 2, 2, 2, 1, 4, 1, }, { 4, 1, 1, 2, 1, 2, 1, 3, }, { 8, 8, 7, 6, 5, 4, 4, }, { 8, 5, 5, 5, 4, 4, 3, }, },
|
||||
{ 7028139, { 1, 1, 3, 2, 2, 2, 1, 3, }, { 4, 2, 2, 1, 2, 2, 1, 1, }, { 8, 8, 8, 6, 5, 4, 3, }, { 8, 5, 4, 3, 3, 2, 1, }, },
|
||||
{ 7147260, { 2, 1, 4, 3, 2, 1, 1, 1, }, { 4, 1, 1, 1, 4, 1, 1, 2, }, { 8, 7, 7, 4, 2, 1, 1, }, { 8, 5, 5, 5, 5, 2, 2, }, },
|
||||
{ 7266381, { 2, 4, 1, 3, 2, 1, 1, 1, }, { 4, 2, 1, 1, 1, 2, 1, 3, }, { 8, 7, 4, 4, 2, 1, 1, }, { 8, 5, 4, 4, 4, 4, 3, }, },
|
||||
{ 7385502, { 4, 2, 1, 3, 1, 2, 1, 1, }, { 4, 1, 1, 4, 2, 1, 1, 1, }, { 8, 5, 4, 4, 2, 2, 1, }, { 8, 5, 5, 5, 2, 1, 1, }, },
|
||||
{ 7504623, { 1, 1, 3, 4, 3, 1, 1, 1, }, { 5, 2, 1, 1, 1, 1, 1, 3, }, { 8, 8, 8, 6, 3, 1, 1, }, { 8, 4, 3, 3, 3, 3, 3, }, },
|
||||
{ 7623744, { 3, 1, 1, 2, 2, 1, 2, 3, }, { 5, 2, 1, 1, 1, 2, 1, 2, }, { 8, 6, 6, 6, 5, 4, 4, }, { 8, 4, 3, 3, 3, 3, 2, }, },
|
||||
};
|
203
backend/code.c
203
backend/code.c
@ -97,16 +97,6 @@ static const char *C93Table[47] = {
|
||||
"121221", "312111", "311121", "122211"
|
||||
};
|
||||
|
||||
/* Global Variables for Channel Code */
|
||||
static int S[11], B[11];
|
||||
static long value;
|
||||
static long target_value;
|
||||
static char pattern[30];
|
||||
|
||||
/* Function Prototypes */
|
||||
static void NextS(int Chan, int i, int MaxS, int MaxB);
|
||||
static void NextB(int Chan, int i, int MaxB, int MaxS);
|
||||
|
||||
/* *********************** CODE 11 ******************** */
|
||||
INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */
|
||||
|
||||
@ -492,10 +482,46 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* NextS() and NextB() are from ANSI/AIM BC12-1998 and are Copyright (c) AIM 1997 */
|
||||
typedef const struct s_channel_precalc {
|
||||
long value; unsigned char B[8]; unsigned char S[8]; unsigned char bmax[7]; unsigned char smax[7];
|
||||
} channel_precalc;
|
||||
|
||||
/* Their are used here on the understanding that they form part of the specification
|
||||
for Channel Code and therefore their use is permitted under the following terms
|
||||
//#define CHANNEL_GENERATE_PRECALCS
|
||||
|
||||
#ifdef CHANNEL_GENERATE_PRECALCS
|
||||
/* To generate precalc tables uncomment define and run "./test_channel -f generate -g" and place result in "channel_precalcs.h" */
|
||||
static void channel_generate_precalc(int channels, long value, int mod, int last, int B[8], int S[8], int bmax[7], int smax[7]) {
|
||||
int i;
|
||||
if (value == mod) printf("static channel_precalc channel_precalcs%d[] = {\n", channels);
|
||||
printf(" { %7ld, {", value); for (i = 0; i < 8; i++) printf(" %d,", B[i]); printf(" },");
|
||||
printf(" {"); for (i = 0; i < 8; i++) printf(" %d,", S[i]); printf(" },");
|
||||
printf(" {"); for (i = 0; i < 7; i++) printf(" %d,", bmax[i]); printf(" },");
|
||||
printf(" {"); for (i = 0; i < 7; i++) printf(" %d,", smax[i]); printf(" }, },\n");
|
||||
if (value == last) printf("};\n");
|
||||
}
|
||||
#else
|
||||
#include "channel_precalcs.h"
|
||||
#endif
|
||||
|
||||
static long channel_copy_precalc(channel_precalc precalc, int B[8], int S[8], int bmax[7], int smax[7]) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 7; i++) {
|
||||
B[i] = precalc.B[i];
|
||||
S[i] = precalc.S[i];
|
||||
bmax[i] = precalc.bmax[i];
|
||||
smax[i] = precalc.smax[i];
|
||||
}
|
||||
B[7] = precalc.B[7];
|
||||
S[7] = precalc.S[7];
|
||||
|
||||
return precalc.value;
|
||||
}
|
||||
|
||||
/* CHNCHR is adapted from ANSI/AIM BC12-1998 Annex D Figure D5 and is Copyright (c) AIM 1997 */
|
||||
|
||||
/* It is used here on the understanding that it forms part of the specification
|
||||
for Channel Code and therefore its use is permitted under the following terms
|
||||
set out in that document:
|
||||
|
||||
"It is the intent and understanding of AIM [t]hat the symbology presented in this
|
||||
@ -503,55 +529,89 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
licenses and fees. AIM USA, its member companies, or individual officers
|
||||
assume no liability for the use of this document." */
|
||||
|
||||
static void CheckCharacter() {
|
||||
static void CHNCHR(int channels, long target_value, int B[8], int S[8]) {
|
||||
/* Use of initial pre-calculations taken from Barcode Writer in Pure PostScript (bwipp)
|
||||
* Copyright (c) 2004-2020 Terry Burton (MIT/X-Consortium license) */
|
||||
static channel_precalc initial_precalcs[6] = {
|
||||
{ 0, { 1, 1, 1, 1, 1, 2, 1, 2, }, { 1, 1, 1, 1, 1, 1, 1, 3, }, { 1, 1, 1, 1, 1, 3, 2, }, { 1, 1, 1, 1, 1, 3, 3, }, },
|
||||
{ 0, { 1, 1, 1, 1, 2, 1, 1, 3, }, { 1, 1, 1, 1, 1, 1, 1, 4, }, { 1, 1, 1, 1, 4, 3, 3, }, { 1, 1, 1, 1, 4, 4, 4, }, },
|
||||
{ 0, { 1, 1, 1, 2, 1, 1, 2, 3, }, { 1, 1, 1, 1, 1, 1, 1, 5, }, { 1, 1, 1, 5, 4, 4, 4, }, { 1, 1, 1, 5, 5, 5, 5, }, },
|
||||
{ 0, { 1, 1, 2, 1, 1, 2, 1, 4, }, { 1, 1, 1, 1, 1, 1, 1, 6, }, { 1, 1, 6, 5, 5, 5, 4, }, { 1, 1, 6, 6, 6, 6, 6, }, },
|
||||
{ 0, { 1, 2, 1, 1, 2, 1, 1, 5, }, { 1, 1, 1, 1, 1, 1, 1, 7, }, { 1, 7, 6, 6, 6, 5, 5, }, { 1, 7, 7, 7, 7, 7, 7, }, },
|
||||
{ 0, { 2, 1, 1, 2, 1, 1, 2, 5, }, { 1, 1, 1, 1, 1, 1, 1, 8, }, { 8, 7, 7, 7, 6, 6, 6, }, { 8, 8, 8, 8, 8, 8, 8, }, },
|
||||
};
|
||||
int bmax[7], smax[7];
|
||||
long value = 0;
|
||||
|
||||
if (value == target_value) {
|
||||
int i;
|
||||
/* Target reached - save the generated pattern */
|
||||
strcpy(pattern, "11110");
|
||||
for (i = 0; i < 11; i++) {
|
||||
char part[3];
|
||||
part[0] = itoc(S[i]);
|
||||
part[1] = itoc(B[i]);
|
||||
part[2] = '\0';
|
||||
strcat(pattern, part);
|
||||
}
|
||||
channel_copy_precalc(initial_precalcs[channels - 3], B, S, bmax, smax);
|
||||
|
||||
#ifndef CHANNEL_GENERATE_PRECALCS
|
||||
if (channels == 7 && target_value >= channel_precalcs7[0].value) {
|
||||
value = channel_copy_precalc(channel_precalcs7[(target_value / channel_precalcs7[0].value) - 1], B, S, bmax, smax);
|
||||
} else if (channels == 8 && target_value >= channel_precalcs8[0].value) {
|
||||
value = channel_copy_precalc(channel_precalcs8[(target_value / channel_precalcs8[0].value) - 1], B, S, bmax, smax);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NextB(int Chan, int i, int MaxB, int MaxS) {
|
||||
int b;
|
||||
goto chkchr;
|
||||
|
||||
b = (S[i] + B[i - 1] + S[i - 1] + B[i - 2] > 4) ? 1 : 2;
|
||||
if (i < Chan + 2) {
|
||||
for (; b <= MaxB; b++) {
|
||||
B[i] = b;
|
||||
NextS(Chan, i + 1, MaxS, MaxB + 1 - b);
|
||||
}
|
||||
} else if (b <= MaxB) {
|
||||
B[i] = MaxB;
|
||||
CheckCharacter();
|
||||
value++;
|
||||
}
|
||||
}
|
||||
|
||||
static void NextS(int Chan, int i, int MaxS, int MaxB) {
|
||||
int s;
|
||||
|
||||
for (s = (i < Chan + 2) ? 1 : MaxS; s <= MaxS; s++) {
|
||||
S[i] = s;
|
||||
NextB(Chan, i, MaxB, MaxS + 1 - s);
|
||||
}
|
||||
ls0:smax[1] = smax[0] + 1 - S[0]; B[0] = 1;
|
||||
if (S[0] == 1) goto nb0;
|
||||
lb0: bmax[1] = bmax[0] + 1 - B[0]; S[1] = 1;
|
||||
ls1: smax[2] = smax[1] + 1 - S[1]; B[1] = 1;
|
||||
if (S[0] + B[0] + S[1] == 3) goto nb1;
|
||||
lb1: bmax[2] = bmax[1] + 1 - B[1]; S[2] = 1;
|
||||
ls2: smax[3] = smax[2] + 1 - S[2]; B[2] = 1;
|
||||
if (B[0] + S[1] + B[1] + S[2] == 4) goto nb2;
|
||||
lb2: bmax[3] = bmax[2] + 1 - B[2]; S[3] = 1;
|
||||
ls3: smax[4] = smax[3] + 1 - S[3]; B[3] = 1;
|
||||
if (B[1] + S[2] + B[2] + S[3] == 4) goto nb3;
|
||||
lb3: bmax[4] = bmax[3] + 1 - B[3]; S[4] = 1;
|
||||
ls4: smax[5] = smax[4] + 1 - S[4]; B[4] = 1;
|
||||
if (B[2] + S[3] + B[3] + S[4] == 4) goto nb4;
|
||||
lb4: bmax[5] = bmax[4] + 1 - B[4]; S[5] = 1;
|
||||
ls5: smax[6] = smax[5] + 1 - S[5]; B[5] = 1;
|
||||
if (B[3] + S[4] + B[4] + S[5] == 4) goto nb5;
|
||||
lb5: bmax[6] = bmax[5] + 1 - B[5]; S[6] = 1;
|
||||
ls6: S[7] = smax[6] + 1 - S[6]; B[6] = 1;
|
||||
if (B[4] + S[5] + B[5] + S[6] == 4) goto nb6;
|
||||
lb6: B[7] = bmax[6] + 1 - B[6];
|
||||
if (B[5] + S[6] + B[6] + S[7] + B[7] == 5) goto nb6;
|
||||
chkchr:
|
||||
#ifdef CHANNEL_GENERATE_PRECALCS
|
||||
if (channels == 7 && value && value % 115338 == 0) { /* 115338 == (576688 + 2) / 5 */
|
||||
channel_generate_precalc(channels, value, 115338, 115338 * (5 - 1), B, S, bmax, smax);
|
||||
} else if (channels == 8 && value && value % 119121 == 0) { /* 119121 == (7742862 + 3) / 65 */
|
||||
channel_generate_precalc(channels, value, 119121, 119121 * (65 - 1), B, S, bmax, smax);
|
||||
}
|
||||
#endif
|
||||
if (value == target_value) return;
|
||||
value++;
|
||||
nb6: if (++B[6] <= bmax[6]) goto lb6;
|
||||
if (++S[6] <= smax[6]) goto ls6;
|
||||
nb5: if (++B[5] <= bmax[5]) goto lb5;
|
||||
if (++S[5] <= smax[5]) goto ls5;
|
||||
nb4: if (++B[4] <= bmax[4]) goto lb4;
|
||||
if (++S[4] <= smax[4]) goto ls4;
|
||||
nb3: if (++B[3] <= bmax[3]) goto lb3;
|
||||
if (++S[3] <= smax[3]) goto ls3;
|
||||
nb2: if (++B[2] <= bmax[2]) goto lb2;
|
||||
if (++S[2] <= smax[2]) goto ls2;
|
||||
nb1: if (++B[1] <= bmax[1]) goto lb1;
|
||||
if (++S[1] <= smax[1]) goto ls1;
|
||||
nb0: if (++B[0] <= bmax[0]) goto lb0;
|
||||
if (++S[0] <= smax[0]) goto ls0;
|
||||
}
|
||||
|
||||
/* Channel Code - According to ANSI/AIM BC12-1998 */
|
||||
INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int S[8] = {0}, B[8] = {0};
|
||||
long target_value = 0;
|
||||
char pattern[30];
|
||||
int channels, i;
|
||||
int error_number = 0, range = 0, zeroes;
|
||||
int error_number, range = 0, zeroes;
|
||||
char hrt[9];
|
||||
|
||||
target_value = 0;
|
||||
|
||||
if (length > 7) {
|
||||
strcpy(symbol->errtxt, "333: Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
@ -567,18 +627,30 @@ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], in
|
||||
} else {
|
||||
channels = symbol->option_2;
|
||||
}
|
||||
if (channels == 0) {
|
||||
channels = length + 1;
|
||||
}
|
||||
if (channels == 2) {
|
||||
channels = 3;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
target_value *= 10;
|
||||
target_value += ctoi((char) source[i]);
|
||||
}
|
||||
|
||||
if (channels == 0) {
|
||||
channels = length + 1;
|
||||
if (target_value > 576688 && channels < 8) {
|
||||
channels = 8;
|
||||
} else if (target_value > 44072 && channels < 7) {
|
||||
channels = 7;
|
||||
} else if (target_value > 3493 && channels < 6) {
|
||||
channels = 6;
|
||||
} else if (target_value > 292 && channels < 5) {
|
||||
channels = 5;
|
||||
} else if (target_value > 26 && channels < 4) {
|
||||
channels = 4;
|
||||
}
|
||||
}
|
||||
if (channels == 2) {
|
||||
channels = 3;
|
||||
}
|
||||
|
||||
switch (channels) {
|
||||
case 3: if (target_value > 26) {
|
||||
range = 1;
|
||||
@ -610,14 +682,16 @@ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], in
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
for (i = 0; i < 11; i++) {
|
||||
B[i] = 0;
|
||||
S[i] = 0;
|
||||
}
|
||||
CHNCHR(channels, target_value, B, S);
|
||||
|
||||
B[0] = S[1] = B[1] = S[2] = B[2] = 1;
|
||||
value = 0;
|
||||
NextS(channels, 3, channels, channels);
|
||||
strcpy(pattern, "111111111"); /* Finder pattern */
|
||||
for (i = 8 - channels; i < 8; i++) {
|
||||
char part[3];
|
||||
part[0] = itoc(S[i]);
|
||||
part[1] = itoc(B[i]);
|
||||
part[2] = '\0';
|
||||
strcat(pattern, part);
|
||||
}
|
||||
|
||||
zeroes = channels - 1 - length;
|
||||
if (zeroes < 0) {
|
||||
@ -632,7 +706,6 @@ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], in
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
||||
/* Vehicle Identification Number (VIN) */
|
||||
INTERNAL int vin(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length) {
|
||||
|
||||
|
@ -27,43 +27,73 @@
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_encode(int index, int debug) {
|
||||
static void test_input(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char *data;
|
||||
int option_2;
|
||||
int ret_encode;
|
||||
float w;
|
||||
float h;
|
||||
int ret_vector;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { "0", 0, 0, 100, 30, 0 },
|
||||
/* 1*/ { "1", 1, 0, 100, 30, 0 },
|
||||
/* 2*/ { "26", 2, 0, 100, 30, 0 },
|
||||
/* 3*/ { "026", 3, 0, 100, 30, 0 },
|
||||
/* 4*/ { "0026", 3, 0, 100, 30, 0 },
|
||||
/* 5*/ { "1234", 3, ZINT_ERROR_INVALID_DATA, 100, 30, -1 },
|
||||
/* 6*/ { "1234", 4, ZINT_ERROR_INVALID_DATA, 100, 30, -1 },
|
||||
/* 7*/ { "292", 4, 0, 100, 30, 0 },
|
||||
/* 8*/ { "1234", 5, 0, 100, 30, 0 },
|
||||
/* 9*/ { "1234567", 0, 0, 100, 30, 0 },
|
||||
/*10*/ { "576688", 7, 0, 100, 30, 0 },
|
||||
/*11*/ { "576689", 7, ZINT_ERROR_INVALID_DATA, 100, 30, -1 },
|
||||
/*12*/ { "1234567", 0, 0, 100, 30, 0 },
|
||||
/*13*/ { "1234567", 8, 0, 100, 30, 0 },
|
||||
/*14*/ { "7742863", 8, ZINT_ERROR_INVALID_DATA, 100, 30, -1 },
|
||||
/*15*/ { "0000000", 2, 0, 100, 30, 0 },
|
||||
/*16*/ { "12345678", 8, ZINT_ERROR_TOO_LONG, 100, 30, -1 },
|
||||
/* 0*/ { -1, "0", 0, 1, 19 }, // < 3 ignored
|
||||
/* 1*/ { 0, "0", 0, 1, 19, },
|
||||
/* 2*/ { 1, "0", 0, 1, 19, },
|
||||
/* 3*/ { 2, "0", 0, 1, 19, },
|
||||
/* 4*/ { 9, "0", 0, 1, 19, }, // > 8 ignored
|
||||
/* 5*/ { -1, "00", 0, 1, 19 },
|
||||
/* 6*/ { 3, "00", 0, 1, 19 },
|
||||
/* 7*/ { -1, "26", 0, 1, 19, },
|
||||
/* 8*/ { 3, "26", 0, 1, 19, },
|
||||
/* 9*/ { 3, "27", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 10*/ { 3, "000", 0, 1, 19, },
|
||||
/* 11*/ { 3, "001", 0, 1, 19, },
|
||||
/* 12*/ { 3, "026", 0, 1, 19, },
|
||||
/* 13*/ { -1, "026", 0, 1, 23, }, // Defaults to channel 4 due to length
|
||||
/* 14*/ { 3, "0026", 0, 1, 19, },
|
||||
/* 15*/ { 3, "1234", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 16*/ { 4, "000", 0, 1, 23 },
|
||||
/* 17*/ { -1, "000", 0, 1, 23 }, // Defaults to channel 4 due to length
|
||||
/* 18*/ { 4, "026", 0, 1, 23 },
|
||||
/* 19*/ { 4, "0000026", 0, 1, 23 },
|
||||
/* 20*/ { 4, "0000", 0, 1, 23 },
|
||||
/* 21*/ { 4, "292", 0, 1, 23 },
|
||||
/* 22*/ { 4, "293", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 23*/ { 5, "0000", 0, 1, 27 },
|
||||
/* 24*/ { -1, "0000", 0, 1, 27 }, // Defaults to channel 5 due to length
|
||||
/* 25*/ { -1, "3493", 0, 1, 27 },
|
||||
/* 26*/ { 5, "3493", 0, 1, 27 },
|
||||
/* 27*/ { 5, "3494", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 28*/ { 6, "00000", 0, 1, 31 },
|
||||
/* 29*/ { -1, "00000", 0, 1, 31 }, // Defaults to channel 5 due to length
|
||||
/* 30*/ { -1, "44072", 0, 1, 31 },
|
||||
/* 31*/ { 6, "44072", 0, 1, 31 },
|
||||
/* 32*/ { 6, "44073", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 33*/ { -1, "576688", 0, 1, 35 },
|
||||
/* 34*/ { 7, "000000", 0, 1, 35 },
|
||||
/* 35*/ { -1, "000000", 0, 1, 35 }, // Defaults to channel 7 due to length
|
||||
/* 36*/ { 7, "576688", 0, 1, 35 },
|
||||
/* 37*/ { 7, "576689", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 38*/ { 7, "0576688", 0, 1, 35 },
|
||||
/* 39*/ { -1, "1234567", 0, 1, 39 },
|
||||
/* 40*/ { 8, "0000000", 0, 1, 39, },
|
||||
/* 41*/ { -1, "0000000", 0, 1, 39, }, // Defaults to channel 8 due to length
|
||||
/* 42*/ { 8, "1234567", 0, 1, 39, },
|
||||
/* 43*/ { 8, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
/* 44*/ { 8, "01234567", ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 45*/ { 8, "00000000", ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 46*/ { 9, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1 },
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
@ -72,18 +102,14 @@ static void test_encode(int index, int debug) {
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_CHANNEL;
|
||||
symbol->option_2 = data[i].option_2;
|
||||
symbol->debug |= debug;
|
||||
|
||||
int length = strlen(data[i].data);
|
||||
int length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, data[i].data, length);
|
||||
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret_encode);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
|
||||
|
||||
if (data[i].ret_vector != -1) {
|
||||
ret = ZBarcode_Buffer_Vector(symbol, 0);
|
||||
assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d\n", i, ret, data[i].ret_vector);
|
||||
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);
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
@ -92,10 +118,307 @@ static void test_encode(int index, int debug) {
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_encode(int index, int generate, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int option_2;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { -1, "1234", 0, 1, 27, "ANSI/AIM BC12-1998 Figure 1",
|
||||
"101010101001010010011110011"
|
||||
},
|
||||
/* 1*/ { -1, "00", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 top",
|
||||
"1010101010110100011"
|
||||
},
|
||||
/* 2*/ { -1, "02", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 2nd",
|
||||
"1010101010110010011"
|
||||
},
|
||||
/* 3*/ { -1, "05", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 3rd",
|
||||
"1010101010110001101"
|
||||
},
|
||||
/* 4*/ { -1, "08", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 4th",
|
||||
"1010101010111000101"
|
||||
},
|
||||
/* 5*/ { -1, "10", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 5th",
|
||||
"1010101010010110011"
|
||||
},
|
||||
/* 6*/ { -1, "26", 0, 1, 19, "ANSI/AIM BC12-1998 Figure F1 Channel 3 bottom",
|
||||
"1010101010001110101"
|
||||
},
|
||||
/* 7*/ { -1, "000", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 top",
|
||||
"10101010101101010000111"
|
||||
},
|
||||
/* 8*/ { -1, "004", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 2nd",
|
||||
"10101010101101001100011"
|
||||
},
|
||||
/* 9*/ { -1, "007", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 3rd",
|
||||
"10101010101101000110011"
|
||||
},
|
||||
/* 10*/ { -1, "010", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 4th",
|
||||
"10101010101101000011011"
|
||||
},
|
||||
/* 11*/ { -1, "100", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 5th",
|
||||
"10101010100101011100011"
|
||||
},
|
||||
/* 12*/ { -1, "292", 0, 1, 23, "ANSI/AIM BC12-1998 Figure F1 Channel 4 bottom",
|
||||
"10101010100001110110101"
|
||||
},
|
||||
/* 13*/ { -1, "0000", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 top",
|
||||
"101010101011010101100000111"
|
||||
},
|
||||
/* 14*/ { -1, "0005", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 2nd",
|
||||
"101010101011010100111000011"
|
||||
},
|
||||
/* 15*/ { -1, "0010", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 3rd",
|
||||
"101010101011010100011110001"
|
||||
},
|
||||
/* 16*/ { -1, "0100", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 4th",
|
||||
"101010101011010001000111101"
|
||||
},
|
||||
/* 17*/ { -1, "1000", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 5th",
|
||||
"101010101011100001011011001"
|
||||
},
|
||||
/* 18*/ { -1, "3493", 0, 1, 27, "ANSI/AIM BC12-1998 Figure F1 Channel 5 bottom",
|
||||
"101010101000001111010110101"
|
||||
},
|
||||
/* 19*/ { -1, "00000", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 top",
|
||||
"1010101010110101011010000001111"
|
||||
},
|
||||
/* 20*/ { -1, "00010", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 2nd",
|
||||
"1010101010110101011000111000011"
|
||||
},
|
||||
/* 21*/ { -1, "00100", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 3rd",
|
||||
"1010101010110101001100001111001"
|
||||
},
|
||||
/* 22*/ { -1, "01000", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 4th",
|
||||
"1010101010110100110011000100111"
|
||||
},
|
||||
/* 23*/ { -1, "10000", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 5th",
|
||||
"1010101010111011000100010110011"
|
||||
},
|
||||
/* 24*/ { -1, "44072", 0, 1, 31, "ANSI/AIM BC12-1998 Figure F1 Channel 6 bottom",
|
||||
"1010101010000001111101010110101"
|
||||
},
|
||||
/* 25*/ { -1, "000000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 top",
|
||||
"10101010101101010110101000000011111"
|
||||
},
|
||||
/* 26*/ { -1, "000100", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 2nd",
|
||||
"10101010101101010110111110001000001"
|
||||
},
|
||||
/* 27*/ { -1, "001000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 3rd",
|
||||
"10101010101101010010100001111100011"
|
||||
},
|
||||
/* 28*/ { -1, "010000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 4th",
|
||||
"10101010101101001010111111000100001"
|
||||
},
|
||||
/* 29*/ { -1, "100000", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 5th",
|
||||
"10101010101100001001001111101101001"
|
||||
},
|
||||
/* 30*/ { -1, "576688", 0, 1, 35, "ANSI/AIM BC12-1998 Figure F1 Channel 7 bottom",
|
||||
"10101010100000001111101101010110101"
|
||||
},
|
||||
/* 31*/ { -1, "0000000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 top",
|
||||
"101010101011010101101010110000000011111"
|
||||
},
|
||||
/* 32*/ { -1, "0001000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 2nd",
|
||||
"101010101011010101101100010000010011111"
|
||||
},
|
||||
/* 33*/ { -1, "0010000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 3rd",
|
||||
"101010101011010101110000110001101100011"
|
||||
},
|
||||
/* 34*/ { -1, "0100000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 4th",
|
||||
"101010101011010111010110101100000000111"
|
||||
},
|
||||
/* 35*/ { -1, "1000000", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 5th",
|
||||
"101010101011001110100100100001111001011"
|
||||
},
|
||||
/* 36*/ { -1, "7742862", 0, 1, 39, "ANSI/AIM BC12-1998 Figure F1 Channel 8 bottom",
|
||||
"101010101000000001111110101101010110101"
|
||||
},
|
||||
/* 37*/ { -1, "01", 0, 1, 19, "Edge case for initial_precalcs table; verified manually against bwipp",
|
||||
"1010101010110110001"
|
||||
},
|
||||
/* 38*/ { -1, "001", 0, 1, 23, "Edge case for initial_precalcs table; verified manually against bwipp",
|
||||
"10101010101101011000011"
|
||||
},
|
||||
/* 39*/ { -1, "0001", 0, 1, 27, "Edge case for initial_precalcs table; verified manually against bwipp",
|
||||
"101010101011010101110000011"
|
||||
},
|
||||
/* 40*/ { -1, "00001", 0, 1, 31, "Edge case for initial_precalcs table; verified manually against bwipp",
|
||||
"1010101010110101011011000000111"
|
||||
},
|
||||
/* 41*/ { -1, "000001", 0, 1, 35, "Edge case for initial_precalcs table; verified manually against bwipp",
|
||||
"10101010101101010110101100000001111"
|
||||
},
|
||||
/* 42*/ { -1, "0000001", 0, 1, 39, "Edge case for initial_precalcs table; verified manually against bwipp",
|
||||
"101010101011010101101010111000000001111"
|
||||
},
|
||||
/* 43*/ { -1, "115337", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010101110100101001000111100011"
|
||||
},
|
||||
/* 44*/ { -1, "115338", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010101110100101001000111110001"
|
||||
},
|
||||
/* 45*/ { -1, "115339", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010101110100101001000010011111"
|
||||
},
|
||||
/* 46*/ { -1, "230675", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010100101100011001111010011001"
|
||||
},
|
||||
/* 47*/ { -1, "230676", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010100101100011001111010001011"
|
||||
},
|
||||
/* 48*/ { -1, "230677", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010100101100011001111010001101"
|
||||
},
|
||||
/* 49*/ { -1, "346013", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010100110011101010001011000111"
|
||||
},
|
||||
/* 50*/ { -1, "346014", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010100110011101010001011100011"
|
||||
},
|
||||
/* 51*/ { -1, "346015", 0, 1, 35, "Edge case for channel_precalcs7 table; verified manually against bwipp",
|
||||
"10101010100110011101010001011110001"
|
||||
},
|
||||
/* 52*/ { -1, "0119120", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011010111000011000100111010011"
|
||||
},
|
||||
/* 53*/ { -1, "0119121", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011010111000011000100111011001"
|
||||
},
|
||||
/* 54*/ { -1, "0119122", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011010111000011000100111001011"
|
||||
},
|
||||
/* 55*/ { -1, "0238241", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011010001011011001100011110001"
|
||||
},
|
||||
/* 56*/ { -1, "0238242", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011010001011011001100001001111"
|
||||
},
|
||||
/* 57*/ { -1, "0238243", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011010001011011001100001100111"
|
||||
},
|
||||
/* 58*/ { -1, "1072088", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011001111101000101100011001001"
|
||||
},
|
||||
/* 59*/ { -1, "1072089", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011001111101000101100011000101"
|
||||
},
|
||||
/* 60*/ { -1, "1072090", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101011001111101000101100001010011"
|
||||
},
|
||||
/* 61*/ { -1, "4169234", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101001101001101101111011000100001"
|
||||
},
|
||||
/* 62*/ { -1, "4169235", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101001101001101101111011000010001"
|
||||
},
|
||||
/* 63*/ { -1, "4169236", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101001101001101101111011000001001"
|
||||
},
|
||||
/* 64*/ { -1, "6075170", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101000100011101010001110111001011"
|
||||
},
|
||||
/* 65*/ { -1, "6075171", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101000100011101010001110111001101"
|
||||
},
|
||||
/* 66*/ { -1, "6075172", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101000100011101010001110111101001"
|
||||
},
|
||||
/* 67*/ { -1, "7623743", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101000001110010101101100101001111"
|
||||
},
|
||||
/* 68*/ { -1, "7623744", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101000001110010101101100101100111"
|
||||
},
|
||||
/* 69*/ { -1, "7623745", 0, 1, 39, "Edge case for channel_precalcs8 table; verified manually against bwipp",
|
||||
"101010101000001110010101101100101110011"
|
||||
},
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
char escaped[1024];
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
int length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
|
||||
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);
|
||||
|
||||
if (generate) {
|
||||
printf(" /*%3d*/ { %d, \"%s\", %s, %d, %d, \"%s\",\n",
|
||||
i, data[i].option_2, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
// Dummy to generate pre-calculated tables for channels 7/8
|
||||
static void test_generate(int generate) {
|
||||
|
||||
if (!generate) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char *data;
|
||||
};
|
||||
struct item data[] = { { "576688" }, { "7742862" } };
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
int length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, 0);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, data[i].data, length);
|
||||
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
|
||||
{ "test_encode", test_encode, 1, 0, 1 },
|
||||
{ "test_input", test_input, 1, 0, 1 },
|
||||
{ "test_encode", test_encode, 1, 1, 1 },
|
||||
{ "test_generate", test_generate, 0, 1, 0 },
|
||||
};
|
||||
|
||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||
|
@ -54,6 +54,7 @@ SOURCES += qrencode/bitstream.c \
|
||||
|
||||
HEADERS += ../backend/aztec.h \
|
||||
../backend/bmp.h \
|
||||
../backend/channel_precalcs.h \
|
||||
../backend/code128.h \
|
||||
../backend/code49.h \
|
||||
../backend/common.h \
|
||||
|
@ -18,6 +18,7 @@ DEFINES += _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS ZINT_VERSION=\\\"$$
|
||||
}
|
||||
|
||||
HEADERS += ../backend/aztec.h \
|
||||
../backend/channel_precalcs.h \
|
||||
../backend/code1.h \
|
||||
../backend/code49.h \
|
||||
../backend/common.h \
|
||||
|
@ -405,6 +405,10 @@
|
||||
RelativePath="..\backend\aztec.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\backend\channel_precalcs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\backend\code1.h"
|
||||
>
|
||||
|
@ -354,6 +354,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\backend\aztec.h" />
|
||||
<ClInclude Include="..\backend\bmp.h" />
|
||||
<ClInclude Include="..\backend\channel_precalcs.h" />
|
||||
<ClInclude Include="..\backend\code1.h" />
|
||||
<ClInclude Include="..\backend\code128.h" />
|
||||
<ClInclude Include="..\backend\code49.h" />
|
||||
|
@ -104,6 +104,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\backend\aztec.h" />
|
||||
<ClInclude Include="..\..\backend\channel_precalcs.h" />
|
||||
<ClInclude Include="..\..\backend\code1.h" />
|
||||
<ClInclude Include="..\..\backend\code49.h" />
|
||||
<ClInclude Include="..\..\backend\common.h" />
|
||||
@ -133,4 +134,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user