2009-10-06 19:03:00 +00:00
/* pdf417.c - Handles PDF417 stacked symbology */
2022-06-24 14:38:48 +01:00
/*
libzint - the open source barcode library
2023-06-12 01:25:55 +01:00
Copyright ( C ) 2008 - 2023 Robin Stuart < rstuart114 @ gmail . com >
2009-10-06 19:03:00 +00:00
Portions Copyright ( C ) 2004 Grandzebu
Bug Fixes thanks to KL Chin < klchin @ users . sourceforge . net >
2013-05-16 19:26:38 +02:00
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions
are met :
2016-02-20 10:50:15 +00:00
1. Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
2013-05-16 19:26:38 +02:00
2. Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in the
2016-02-20 10:50:15 +00:00
documentation and / or other materials provided with the distribution .
2013-05-16 19:26:38 +02:00
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
2016-02-20 10:50:15 +00:00
without specific prior written permission .
2013-05-16 19:26:38 +02:00
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
2016-02-20 10:50:15 +00:00
OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
2013-05-16 19:26:38 +02:00
SUCH DAMAGE .
2016-02-20 10:50:15 +00:00
*/
2022-06-24 14:38:48 +01:00
/* SPDX-License-Identifier: BSD-3-Clause */
2009-10-06 19:03:00 +00:00
/* This code is adapted from "Code barre PDF 417 / PDF 417 barcode" v2.5.0
which is Copyright ( C ) 2004 ( Grandzebu ) .
2022-11-06 22:25:19 +00:00
The original code ( file pdf417 . frm ) can be downloaded from https : //grandzebu.net/informatique/codbar/pdf417.zip */
2009-10-06 19:03:00 +00:00
/* NOTE: symbol->option_1 is used to specify the security level (i.e. control the
number of check codewords )
symbol - > option_2 is used to adjust the width of the resulting symbol ( i . e . the
2021-10-30 22:00:31 +01:00
number of codeword columns not including row start and end data )
symbol - > option_3 is used to adjust the rows of the resulting symbol */
2009-10-06 19:03:00 +00:00
2020-11-01 18:32:55 +00:00
# include <assert.h>
2022-11-06 22:25:19 +00:00
# include <limits.h>
2022-07-14 16:01:30 +01:00
# include <math.h>
# include <stdio.h>
2009-10-06 19:03:00 +00:00
# include "common.h"
2020-11-01 18:32:55 +00:00
# include "pdf417.h"
2021-10-30 22:00:31 +01:00
# include "pdf417_tabs.h"
2020-11-01 18:32:55 +00:00
2022-08-18 22:25:09 +01:00
/* Modes */
2022-11-06 22:25:19 +00:00
# define PDF_ALP 1 /* Treating TEX sub-modes as pseudo-modes (minimal encode) */
# define PDF_LOW 2
# define PDF_MIX 3
# define PDF_PNC 4
# define PDF_TEX 4 /* Real modes */
# define PDF_BYT 5
# define PDF_NUM 6
2020-11-01 18:32:55 +00:00
2022-11-06 22:25:19 +00:00
# define PDF_NUM_MODES 6
/* Mode indicators including TEX pseudo-modes */
static const char pdf_smodes [ ] = { ' ? ' , ' A ' , ' L ' , ' M ' , ' P ' , ' B ' , ' N ' } ;
/* Return (real) mode text */
static const char * pdf_mode_str ( const int mode ) {
static const char * modes [ 3 ] = { " Text " , " Byte " , " Number " } ;
return mode > = PDF_TEX & & mode < = PDF_NUM ? modes [ mode - PDF_TEX ] : " ERROR " ;
}
# define PDF_REAL_MODE(m) ((m) <= PDF_TEX ? PDF_TEX : (m))
/* TEX mode OR-able sub-modes (tables) */
# define T_ALPHA 1
# define T_LOWER 2
# define T_MIXED 4
# define T_PUNCT 8
# define T_ALWMX (T_ALPHA | T_LOWER | T_MIXED)
# define T_MXPNC (T_MIXED | T_PUNCT)
# define PDF_TABLE_TO_MODE(t) (((t) >> 1) + !!((t) & 0x07)) /* Hack to map 1,2,4,8 to 1,2,3,4 */
2022-08-18 22:25:09 +01:00
2016-02-20 10:50:15 +00:00
/*
2009-10-06 19:03:00 +00:00
Three figure numbers in comments give the location of command equivalents in the
original Visual Basic source code file pdf417 . frm
this code retains some original ( French ) procedure and variable names to ease conversion */
/* text mode processing tables */
2022-08-18 22:25:09 +01:00
/* TEX sub-mode assignments */
2021-10-30 22:00:31 +01:00
static const char pdf_asciix [ 127 ] = {
2022-11-06 22:25:19 +00:00
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 00-07 */
0 , T_MXPNC , T_PUNCT , 0 , 0 , T_MXPNC , 0 , 0 , /* 08-0F .<HT><LF>..<CR>.. */
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 10-17 */
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 18-1F */
T_ALWMX , T_PUNCT , T_PUNCT , T_MIXED , T_MXPNC , T_MIXED , T_MIXED , T_PUNCT , /* 20-27 <SP>!"#$%&' */
T_PUNCT , T_PUNCT , T_MXPNC , T_MIXED , T_MXPNC , T_MXPNC , T_MXPNC , T_MXPNC , /* 28-2F ()*+,-./ */
T_MIXED , T_MIXED , T_MIXED , T_MIXED , T_MIXED , T_MIXED , T_MIXED , T_MIXED , /* 30-37 01234567 */
T_MIXED , T_MIXED , T_MXPNC , T_PUNCT , T_PUNCT , T_MIXED , T_PUNCT , T_PUNCT , /* 38-3F 89:;<=>? */
T_PUNCT , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , /* 40-47 @ABCDEFG */
T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , /* 48-4F HIJKLMNO */
T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , T_ALPHA , /* 50-57 PQRSTUVW */
T_ALPHA , T_ALPHA , T_ALPHA , T_PUNCT , T_PUNCT , T_PUNCT , T_MIXED , T_PUNCT , /* 58-5F XYZ[\]^_ */
T_PUNCT , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , /* 60-67 `abcdefg */
T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , /* 68-6F hijklmno */
T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , T_LOWER , /* 70-77 pqrstuvw */
T_LOWER , T_LOWER , T_LOWER , T_PUNCT , T_PUNCT , T_PUNCT , T_PUNCT /* 78-7E xyz{|}~ */
2016-02-20 10:50:15 +00:00
} ;
2009-10-06 19:03:00 +00:00
2022-08-18 22:25:09 +01:00
/* TEX sub-mode values */
2021-10-30 22:00:31 +01:00
static const char pdf_asciiy [ 127 ] = {
2022-11-06 22:25:19 +00:00
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 00-07 */
0 , 12 , 15 , 0 , 0 , 11 , 0 , 0 , /* 08-0F */
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 10-17 */
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , /* 18-1F */
26 , 10 , 20 , 15 , 18 , 21 , 10 , 28 , /* 20-27 */
23 , 24 , 22 , 20 , 13 , 16 , 17 , 19 , /* 28-2F */
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , /* 30-37 */
8 , 9 , 14 , 0 , 1 , 23 , 2 , 25 , /* 38-3F */
3 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , /* 40-47 */
7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , /* 48-4F */
15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , /* 50-57 */
23 , 24 , 25 , 4 , 5 , 6 , 24 , 7 , /* 58-5F */
8 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , /* 60-67 */
7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , /* 68-6F */
15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , /* 70-77 */
23 , 24 , 25 , 26 , 21 , 27 , 9 /* 78-7F */
2016-02-20 10:50:15 +00:00
} ;
2009-10-06 19:03:00 +00:00
/* Automatic sizing table */
2021-10-30 22:00:31 +01:00
static const char pdf_MicroAutosize [ 56 ] = {
2016-02-20 10:50:15 +00:00
4 , 6 , 7 , 8 , 10 , 12 , 13 , 14 , 16 , 18 , 19 , 20 , 24 , 29 , 30 , 33 , 34 , 37 , 39 , 46 , 54 , 58 , 70 , 72 , 82 , 90 , 108 , 126 ,
1 , 14 , 2 , 7 , 3 , 25 , 8 , 16 , 5 , 17 , 9 , 6 , 10 , 11 , 28 , 12 , 19 , 13 , 29 , 20 , 30 , 21 , 22 , 31 , 23 , 32 , 33 , 34
2009-10-06 19:03:00 +00:00
} ;
2020-12-23 10:57:24 +00:00
/* ISO/IEC 15438:2015 5.1.1 c) 3) Max possible number of characters at error correction level 0
( Numeric Compaction mode ) */
2021-10-30 22:00:31 +01:00
# define PDF_MAX_LEN 2710
2020-12-23 10:57:24 +00:00
/* ISO/IEC 24728:2006 5.1.1 c) 3) Max possible number of characters (Numeric Compaction mode) */
2021-10-30 22:00:31 +01:00
# define MICRO_PDF_MAX_LEN 366
2020-03-28 15:10:53 +00:00
2009-10-06 19:03:00 +00:00
/* 866 */
2022-11-06 22:25:19 +00:00
/* Initial non-compressed categorization of input */
2021-10-30 22:00:31 +01:00
static int pdf_quelmode ( const unsigned char codeascii ) {
2022-06-24 14:38:48 +01:00
if ( z_isdigit ( codeascii ) ) {
2022-11-06 22:25:19 +00:00
return PDF_NUM ;
2019-09-04 21:34:20 +01:00
}
2021-10-30 22:00:31 +01:00
if ( codeascii < 127 & & pdf_asciix [ codeascii ] ) {
2022-11-06 22:25:19 +00:00
return PDF_TEX ;
2016-02-20 10:50:15 +00:00
}
/* 876 */
2009-10-06 19:03:00 +00:00
2022-11-06 22:25:19 +00:00
return PDF_BYT ;
}
/* Helper to switch TEX mode sub-mode */
static int pdf_textprocess_switch ( const int curtable , const int newtable , int chainet [ PDF_MAX_LEN ] , int wnet ) {
switch ( curtable ) {
case T_ALPHA :
switch ( newtable ) {
case T_LOWER : chainet [ wnet + + ] = 27 ; /* LL */
break ;
case T_MIXED : chainet [ wnet + + ] = 28 ; /* ML */
break ;
case T_PUNCT : chainet [ wnet + + ] = 28 ; /* ML+PL */
chainet [ wnet + + ] = 25 ;
break ;
}
break ;
case T_LOWER :
switch ( newtable ) {
case T_ALPHA : chainet [ wnet + + ] = 28 ; /* ML+AL */
chainet [ wnet + + ] = 28 ;
break ;
case T_MIXED : chainet [ wnet + + ] = 28 ; /* ML */
break ;
case T_PUNCT : chainet [ wnet + + ] = 28 ; /* ML+PL */
chainet [ wnet + + ] = 25 ;
break ;
}
break ;
case T_MIXED :
switch ( newtable ) {
case T_ALPHA : chainet [ wnet + + ] = 28 ; /* AL */
break ;
case T_LOWER : chainet [ wnet + + ] = 27 ; /* LL */
break ;
case T_PUNCT : chainet [ wnet + + ] = 25 ; /* PL */
break ;
}
break ;
case T_PUNCT :
switch ( newtable ) {
case T_ALPHA : chainet [ wnet + + ] = 29 ; /* AL */
break ;
case T_LOWER : chainet [ wnet + + ] = 29 ; /* AL+LL */
chainet [ wnet + + ] = 27 ;
break ;
case T_MIXED : chainet [ wnet + + ] = 29 ; /* AL+ML */
chainet [ wnet + + ] = 28 ;
break ;
}
break ;
}
return wnet ;
2009-10-06 19:03:00 +00:00
}
2022-08-18 22:25:09 +01:00
/* Check consecutive segments for text/num and return the length */
2022-08-18 22:33:27 +01:00
static int pdf_text_num_length ( int liste [ 3 ] [ PDF_MAX_LEN ] , const int indexliste , const int start ) {
2022-08-10 13:40:40 -05:00
int i , len = 0 ;
2022-08-18 22:25:09 +01:00
for ( i = start ; i < indexliste ; i + + ) {
2022-11-06 22:25:19 +00:00
if ( liste [ 1 ] [ i ] = = PDF_BYT )
2022-08-10 13:40:40 -05:00
break ;
len + = liste [ 0 ] [ i ] ;
2022-08-18 22:25:09 +01:00
if ( len > = 5 ) /* we don't care if it's longer than 5 */
2022-08-10 13:40:40 -05:00
break ;
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
return len ;
2009-10-06 19:03:00 +00:00
}
2022-08-18 22:25:09 +01:00
/* Calculate length of TEX allowing for sub-mode switches (no-output version of `pdf_textprocess()`) */
static int pdf_text_submode_length ( const unsigned char chaine [ ] , const int start , const int length , int * p_curtable ) {
2022-11-06 22:25:19 +00:00
int j , indexlistet , curtable = * p_curtable , listet [ PDF_MAX_LEN ] , chainet [ PDF_MAX_LEN ] , wnet = 0 ;
2022-08-18 22:25:09 +01:00
for ( indexlistet = 0 ; indexlistet < length ; indexlistet + + ) {
listet [ indexlistet ] = pdf_asciix [ chaine [ start + indexlistet ] ] ;
}
for ( j = 0 ; j < length ; j + + ) {
if ( listet [ j ] & curtable ) {
/* The character is in the current table */
wnet + + ;
} else {
/* Obliged to change table */
int newtable ;
if ( j = = ( length - 1 ) | | ! ( listet [ j ] & listet [ j + 1 ] ) ) {
/* we change only one character - look for temporary switch */
if ( ( listet [ j ] & T_ALPHA ) & & ( curtable = = T_LOWER ) ) {
wnet + = 2 ; /* AS+char */
continue ;
}
if ( listet [ j ] & T_PUNCT ) { /* (T_PUNCT and T_ALPHA not both possible) */
wnet + = 2 ; /* PS+char */
continue ;
}
/* No temporary switch available */
newtable = listet [ j ] ;
} else {
newtable = listet [ j ] & listet [ j + 1 ] ;
}
/* 599 */
/* Maintain the first if several tables are possible */
2022-11-06 22:25:19 +00:00
if ( newtable = = T_ALWMX ) { /* (T_ALPHA | T_LOWER | T_MIXED) */
2022-08-18 22:25:09 +01:00
newtable = T_ALPHA ;
2022-11-06 22:25:19 +00:00
} else if ( newtable = = T_MXPNC ) { /* (T_MIXED | T_PUNCT) */
2022-08-18 22:25:09 +01:00
newtable = T_MIXED ;
}
/* 619 - select the switch */
2022-11-06 22:25:19 +00:00
wnet = pdf_textprocess_switch ( curtable , newtable , chainet , wnet ) ;
2022-08-18 22:25:09 +01:00
curtable = newtable ;
2022-11-06 22:25:19 +00:00
/* 659 - at last we add the character */
2022-08-18 22:25:09 +01:00
wnet + + ;
}
}
* p_curtable = curtable ;
return wnet ;
}
/* Whether to stay in numeric mode or not */
2022-08-18 22:33:27 +01:00
static int pdf_num_stay ( const unsigned char * chaine , const int indexliste , int liste [ 3 ] [ PDF_MAX_LEN ] , const int i ) {
2022-08-18 22:25:09 +01:00
int curtable , last_len , last_ml , next_len , num_cws , tex_cws ;
if ( liste [ 0 ] [ i ] > = 13 | | ( indexliste = = 1 & & liste [ 0 ] [ i ] > 5 ) ) {
return 1 ;
}
if ( liste [ 0 ] [ i ] < 11 ) {
return 0 ;
}
curtable = T_ALPHA ;
last_len = i = = 0 ? 0 : pdf_text_submode_length ( chaine , liste [ 2 ] [ i - 1 ] , liste [ 0 ] [ i - 1 ] , & curtable ) ;
last_ml = curtable = = T_MIXED ;
curtable = T_ALPHA ; /* Next len if after NUM, sub-mode will be alpha */
next_len = i = = indexliste - 1 ? 0 : pdf_text_submode_length ( chaine , liste [ 2 ] [ i + 1 ] , liste [ 0 ] [ i + 1 ] , & curtable ) ;
2022-11-06 22:25:19 +00:00
num_cws = ( ( last_len + 1 ) > > 1 ) + 1 + 4 + ( liste [ 0 ] [ i ] > 11 ) + 1 + ( ( next_len + 1 ) > > 1 ) ;
2022-08-18 22:25:09 +01:00
curtable = T_MIXED ; /* Next len if stay TEX, sub-mode will be mixed */
next_len = i = = indexliste - 1 ? 0 : pdf_text_submode_length ( chaine , liste [ 2 ] [ i + 1 ] , liste [ 0 ] [ i + 1 ] , & curtable ) ;
2022-11-06 22:25:19 +00:00
tex_cws = ( last_len + ! last_ml + liste [ 0 ] [ i ] + next_len + 1 ) > > 1 ;
2022-08-18 22:25:09 +01:00
if ( num_cws > tex_cws ) {
return 0 ;
}
return 1 ;
}
/* Pack segments using the method described in Appendix D of the AIM specification (ISO/IEC 15438:2015 Annex N) */
2022-11-06 22:25:19 +00:00
static void pdf_appendix_d_encode ( const unsigned char * chaine , int liste [ 3 ] [ PDF_MAX_LEN ] , int * p_indexliste ,
2022-08-18 22:25:09 +01:00
const int debug_print ) {
2022-11-06 22:25:19 +00:00
const int indexliste = * p_indexliste ;
2022-08-10 13:40:40 -05:00
int i = 0 , next , last = 0 , stayintext = 0 ;
2016-02-20 10:50:15 +00:00
2022-11-06 22:25:19 +00:00
while ( i < indexliste ) {
2022-08-10 13:40:40 -05:00
if ( debug_print ) {
printf ( " Encoding block %d = %d (%d) \n " , i , liste [ 1 ] [ i ] , liste [ 0 ] [ i ] ) ;
2016-02-20 10:50:15 +00:00
}
2022-11-06 22:25:19 +00:00
if ( ( liste [ 1 ] [ i ] = = PDF_NUM ) & & pdf_num_stay ( chaine , indexliste , liste , i ) ) {
2022-08-10 13:40:40 -05:00
/* leave as numeric */
liste [ 0 ] [ last ] = liste [ 0 ] [ i ] ;
2022-11-06 22:25:19 +00:00
liste [ 1 ] [ last ] = PDF_NUM ;
2022-08-18 22:25:09 +01:00
liste [ 2 ] [ last ] = liste [ 2 ] [ i ] ;
2022-08-10 13:40:40 -05:00
stayintext = 0 ;
last + + ;
2022-11-06 22:25:19 +00:00
} else if ( ( ( liste [ 1 ] [ i ] = = PDF_TEX ) | | ( liste [ 1 ] [ i ] = = PDF_NUM ) )
& & ( stayintext | | i = = indexliste - 1 | | ( liste [ 0 ] [ i ] > = 5 )
| | ( pdf_text_num_length ( liste , indexliste , i ) > = 5 ) ) ) {
2022-08-10 13:40:40 -05:00
/* set to text and combine additional text/short numeric segments */
liste [ 0 ] [ last ] = liste [ 0 ] [ i ] ;
2022-11-06 22:25:19 +00:00
liste [ 1 ] [ last ] = PDF_TEX ;
2022-08-18 22:25:09 +01:00
liste [ 2 ] [ last ] = liste [ 2 ] [ i ] ;
2022-08-10 13:40:40 -05:00
stayintext = 0 ;
next = i + 1 ;
2022-11-06 22:25:19 +00:00
while ( next < indexliste ) {
if ( ( liste [ 1 ] [ next ] = = PDF_NUM ) & & pdf_num_stay ( chaine , indexliste , liste , next ) ) {
2022-08-10 13:40:40 -05:00
break ;
2022-11-06 22:25:19 +00:00
} else if ( liste [ 1 ] [ next ] = = PDF_BYT ) {
2022-08-10 13:40:40 -05:00
break ;
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
liste [ 0 ] [ last ] + = liste [ 0 ] [ next ] ;
next + + ;
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
last + + ;
i = next ;
continue ;
2016-02-20 10:50:15 +00:00
} else {
2022-08-10 13:40:40 -05:00
/* build byte segment, including combining numeric/text segments that aren't long enough on their own */
liste [ 0 ] [ last ] = liste [ 0 ] [ i ] ;
2022-11-06 22:25:19 +00:00
liste [ 1 ] [ last ] = PDF_BYT ;
2022-08-18 22:25:09 +01:00
liste [ 2 ] [ last ] = liste [ 2 ] [ i ] ;
2022-08-10 13:40:40 -05:00
stayintext = 0 ;
next = i + 1 ;
2022-11-06 22:25:19 +00:00
while ( next < indexliste ) {
if ( liste [ 1 ] [ next ] ! = PDF_BYT ) {
2022-08-10 13:40:40 -05:00
/* check for case of a single byte shift from text mode */
2022-11-06 22:25:19 +00:00
if ( ( liste [ 0 ] [ last ] = = 1 ) & & ( last > 0 ) & & ( liste [ 1 ] [ last - 1 ] = = PDF_TEX ) ) {
2022-08-10 13:40:40 -05:00
stayintext = 1 ;
break ;
}
2016-02-20 10:50:15 +00:00
2022-11-06 22:25:19 +00:00
if ( ( liste [ 0 ] [ next ] > = 5 ) | | ( pdf_text_num_length ( liste , indexliste , next ) > = 5 ) ) {
2022-08-10 13:40:40 -05:00
break ;
}
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
liste [ 0 ] [ last ] + = liste [ 0 ] [ next ] ;
next + + ;
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
last + + ;
i = next ;
continue ;
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
i + + ;
2016-02-20 10:50:15 +00:00
}
2022-08-10 13:40:40 -05:00
/* set the size of the list based on the last consolidated segment */
2022-11-06 22:25:19 +00:00
* p_indexliste = last ;
}
/* Helper to pad TEX mode, allowing for whether last segment or not, writing out `chainet` */
static void pdf_textprocess_end ( int * chainemc , int * p_mclength , const int is_last_seg , int chainet [ PDF_MAX_LEN ] ,
int wnet , int * p_curtable , int * p_tex_padded ) {
int i ;
* p_tex_padded = wnet & 1 ;
if ( * p_tex_padded ) {
if ( is_last_seg ) {
chainet [ wnet + + ] = 29 ; /* PS or AL */
} else { /* Can't use PS as may carry over to following segment */
/* This is sub-optimal if curtable T_ALPHA and following seg lower, or if curtable T_MIXED
and following seg is lower or punct ; TODO : need peek - ahead to table of following seg */
chainet [ wnet + + ] = 28 + ( * p_curtable = = T_PUNCT ) ; /* ML (T_ALPHA/T_LOWER) or AL (T_MIXED/T_PUNCT) */
* p_curtable = * p_curtable = = T_ALPHA | | * p_curtable = = T_LOWER ? T_MIXED : T_ALPHA ;
}
}
/* Now translate the string chainet into codewords */
for ( i = 0 ; i < wnet ; i + = 2 ) {
chainemc [ ( * p_mclength ) + + ] = ( 30 * chainet [ i ] ) + chainet [ i + 1 ] ;
}
2009-10-06 19:03:00 +00:00
}
/* 547 */
2022-11-06 22:25:19 +00:00
/* Text compaction */
static void pdf_textprocess ( int * chainemc , int * p_mclength , const unsigned char chaine [ ] , const int start ,
const int length , const int lastmode , const int is_last_seg , int * p_curtable , int * p_tex_padded ) {
const int real_lastmode = PDF_REAL_MODE ( lastmode ) ;
int j , indexlistet ;
int curtable = real_lastmode = = PDF_TEX ? * p_curtable : T_ALPHA ; /* Set default table upper alpha */
int listet [ 2 ] [ PDF_MAX_LEN ] = { { 0 } } , chainet [ PDF_MAX_LEN ] ;
int wnet = 0 ;
2016-02-20 10:50:15 +00:00
2022-11-06 22:25:19 +00:00
/* add mode indicator if needed */
if ( real_lastmode ! = PDF_TEX ) {
chainemc [ ( * p_mclength ) + + ] = 900 ;
}
2016-02-20 10:50:15 +00:00
/* listet will contain the table numbers and the value of each characters */
for ( indexlistet = 0 ; indexlistet < length ; indexlistet + + ) {
2021-10-30 22:00:31 +01:00
const int codeascii = chaine [ start + indexlistet ] ;
listet [ 0 ] [ indexlistet ] = pdf_asciix [ codeascii ] ;
listet [ 1 ] [ indexlistet ] = pdf_asciiy [ codeascii ] ;
2016-02-20 10:50:15 +00:00
}
/* 570 */
2022-08-10 13:40:40 -05:00
2016-02-20 10:50:15 +00:00
for ( j = 0 ; j < length ; j + + ) {
2022-08-18 22:25:09 +01:00
if ( listet [ 0 ] [ j ] & curtable ) {
2016-02-20 10:50:15 +00:00
/* The character is in the current table */
2021-10-30 22:00:31 +01:00
chainet [ wnet + + ] = listet [ 1 ] [ j ] ;
2016-02-20 10:50:15 +00:00
} else {
/* Obliged to change table */
2021-10-30 22:00:31 +01:00
int newtable ;
if ( j = = ( length - 1 ) | | ! ( listet [ 0 ] [ j ] & listet [ 0 ] [ j + 1 ] ) ) {
2016-02-20 10:50:15 +00:00
/* we change only one character - look for temporary switch */
2022-08-18 22:25:09 +01:00
if ( ( listet [ 0 ] [ j ] & T_ALPHA ) & & ( curtable = = T_LOWER ) ) {
chainet [ wnet + + ] = 27 ; /* AS */
2021-10-30 22:00:31 +01:00
chainet [ wnet + + ] = listet [ 1 ] [ j ] ;
continue ;
}
2022-08-18 22:25:09 +01:00
if ( listet [ 0 ] [ j ] & T_PUNCT ) { /* (T_PUNCT and T_ALPHA not both possible) */
chainet [ wnet + + ] = 29 ; /* PS */
2021-10-30 22:00:31 +01:00
chainet [ wnet + + ] = listet [ 1 ] [ j ] ;
continue ;
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
/* No temporary switch available */
newtable = listet [ 0 ] [ j ] ;
} else {
newtable = listet [ 0 ] [ j ] & listet [ 0 ] [ j + 1 ] ;
2016-02-20 10:50:15 +00:00
}
/* 599 */
2021-10-30 22:00:31 +01:00
/* Maintain the first if several tables are possible */
2022-11-06 22:25:19 +00:00
if ( newtable = = T_ALWMX ) { /* (T_ALPHA | T_LOWER | T_MIXED) */
2022-08-18 22:25:09 +01:00
newtable = T_ALPHA ;
2022-11-06 22:25:19 +00:00
} else if ( newtable = = T_MXPNC ) { /* (T_MIXED | T_PUNCT) */
2022-08-18 22:25:09 +01:00
newtable = T_MIXED ;
2021-10-30 22:00:31 +01:00
}
2016-02-20 10:50:15 +00:00
2021-10-30 22:00:31 +01:00
/* 619 - select the switch */
2022-11-06 22:25:19 +00:00
wnet = pdf_textprocess_switch ( curtable , newtable , chainet , wnet ) ;
2022-08-18 22:25:09 +01:00
curtable = newtable ;
2021-10-30 22:00:31 +01:00
/* 659 - at last we add the character */
chainet [ wnet + + ] = listet [ 1 ] [ j ] ;
2016-02-20 10:50:15 +00:00
}
}
/* 663 */
2022-11-06 22:25:19 +00:00
* p_curtable = curtable ;
pdf_textprocess_end ( chainemc , p_mclength , is_last_seg , chainet , wnet , p_curtable , p_tex_padded ) ;
}
/* Minimal text compaction */
static void pdf_textprocess_minimal ( int * chainemc , int * p_mclength , const unsigned char chaine [ ] ,
int liste [ 3 ] [ PDF_MAX_LEN ] , const int indexliste , const int lastmode , const int is_last_seg ,
int * p_curtable , int * p_tex_padded , int * p_i ) {
const int real_lastmode = PDF_REAL_MODE ( lastmode ) ;
int i , j , k ;
int curtable = real_lastmode = = PDF_TEX ? * p_curtable : T_ALPHA ; /* Set default table upper alpha */
int chainet [ PDF_MAX_LEN ] ;
int wnet = 0 ;
2020-07-17 16:39:01 +01:00
2022-08-10 13:40:40 -05:00
/* add mode indicator if needed */
2022-11-06 22:25:19 +00:00
if ( real_lastmode ! = PDF_TEX ) {
chainemc [ ( * p_mclength ) + + ] = 900 ;
}
for ( i = * p_i ; i < indexliste & & PDF_REAL_MODE ( liste [ 1 ] [ i ] ) = = PDF_TEX ; i + + ) {
static const int newtables [ 5 ] = { 0 , T_ALPHA , T_LOWER , T_MIXED , T_PUNCT } ;
const int newtable = newtables [ liste [ 1 ] [ i ] ] ;
const int from = liste [ 2 ] [ i ] ;
for ( j = 0 ; j < liste [ 0 ] [ i ] ; j + + ) {
const int c = chaine [ from + j ] ;
const int t_table = c < 127 ? pdf_asciix [ c ] : 0 ;
if ( ! t_table ) { /* BYT Shift? */
if ( wnet & 1 ) {
chainet [ wnet + + ] = 29 ; /* PS or AL (T_PUNCT) */
if ( curtable = = T_PUNCT ) {
curtable = T_ALPHA ;
}
}
for ( k = 0 ; k < wnet ; k + = 2 ) {
chainemc [ ( * p_mclength ) + + ] = ( 30 * chainet [ k ] ) + chainet [ k + 1 ] ;
}
chainemc [ ( * p_mclength ) + + ] = 913 ; /* BYT Shift */
chainemc [ ( * p_mclength ) + + ] = c ;
wnet = 0 ;
continue ;
}
2016-02-20 10:50:15 +00:00
2022-11-06 22:25:19 +00:00
if ( newtable ! = curtable ) {
wnet = pdf_textprocess_switch ( curtable , newtable , chainet , wnet ) ;
curtable = newtable ;
}
if ( curtable = = T_LOWER & & t_table = = T_ALPHA ) {
chainet [ wnet + + ] = 27 ; /* AS */
} else if ( curtable ! = T_PUNCT & & ( t_table & T_PUNCT ) & & ( curtable ! = T_MIXED | | ! ( t_table & T_MIXED ) ) ) {
chainet [ wnet + + ] = 29 ; /* PS */
}
/* At last we add the character */
chainet [ wnet + + ] = pdf_asciiy [ c ] ;
}
2016-02-20 10:50:15 +00:00
}
2022-11-06 22:25:19 +00:00
* p_i = i ? i - 1 : 0 ;
2022-08-18 22:25:09 +01:00
* p_curtable = curtable ;
2022-11-06 22:25:19 +00:00
pdf_textprocess_end ( chainemc , p_mclength , is_last_seg , chainet , wnet , p_curtable , p_tex_padded ) ;
2009-10-06 19:03:00 +00:00
}
/* 671 */
2022-11-06 22:25:19 +00:00
/* Byte compaction */
INTERNAL void pdf_byteprocess ( int * chainemc , int * p_mclength , const unsigned char chaine [ ] , int start ,
const int length , const int lastmode , const int debug_print ) {
const int real_lastmode = PDF_REAL_MODE ( lastmode ) ;
2012-12-31 14:41:59 +01:00
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) printf ( " \n Entering byte mode at position %d \n " , start ) ;
2016-02-20 10:50:15 +00:00
if ( length = = 1 ) {
2022-08-10 13:40:40 -05:00
/* shift or latch depending on previous mode */
2022-11-06 22:25:19 +00:00
chainemc [ ( * p_mclength ) + + ] = real_lastmode = = PDF_TEX ? 913 : 901 ;
chainemc [ ( * p_mclength ) + + ] = chaine [ start ] ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) {
2022-11-06 22:25:19 +00:00
printf ( " %s %d \n " , real_lastmode = = PDF_TEX ? " 913 " : " 901 " , chaine [ start ] ) ;
2016-02-20 10:50:15 +00:00
}
} else {
2017-10-23 21:34:31 +02:00
int len ;
2016-02-20 10:50:15 +00:00
/* select the switch for multiple of 6 bytes */
if ( length % 6 = = 0 ) {
2022-11-06 22:25:19 +00:00
chainemc [ ( * p_mclength ) + + ] = 924 ;
2023-06-12 01:25:55 +01:00
if ( debug_print ) fputs ( " 924 " , stdout ) ;
2016-02-20 10:50:15 +00:00
} else {
2020-12-23 10:57:24 +00:00
/* Default mode for MICROPDF417 is Byte Compaction (ISO/IEC 24728:2006 5.4.3), but not emitting it
* depends on whether an ECI has been emitted previously ( or not ) it appears , so simpler and safer
* to always emit it . */
2022-11-06 22:25:19 +00:00
chainemc [ ( * p_mclength ) + + ] = 901 ;
2023-06-12 01:25:55 +01:00
if ( debug_print ) fputs ( " 901 " , stdout ) ;
2016-02-20 10:50:15 +00:00
}
2017-10-16 19:26:54 +02:00
len = 0 ;
2017-09-10 12:03:09 -03:00
2017-10-23 21:34:31 +02:00
while ( len < length ) {
2020-03-28 15:10:53 +00:00
uint64_t total ;
2017-09-10 12:03:09 -03:00
unsigned int chunkLen = length - len ;
2020-07-17 16:39:01 +01:00
if ( 6 < = chunkLen ) { /* Take groups of 6 */
2016-02-20 10:50:15 +00:00
chunkLen = 6 ;
len + = chunkLen ;
2017-10-16 19:26:54 +02:00
total = 0 ;
2009-10-06 19:03:00 +00:00
2016-02-20 10:50:15 +00:00
while ( chunkLen - - ) {
2021-10-30 22:00:31 +01:00
const uint64_t mantisa = chaine [ start + + ] ;
2020-07-17 16:39:01 +01:00
total | = mantisa < < ( chunkLen * 8 ) ;
2016-02-20 10:50:15 +00:00
}
2009-10-06 19:03:00 +00:00
2016-02-20 10:50:15 +00:00
chunkLen = 5 ;
2009-10-06 19:03:00 +00:00
2016-02-20 10:50:15 +00:00
while ( chunkLen - - ) {
2022-11-06 22:25:19 +00:00
chainemc [ * p_mclength + chunkLen ] = ( int ) ( total % 900 ) ;
2016-02-20 10:50:15 +00:00
total / = 900 ;
}
2022-11-06 22:25:19 +00:00
* p_mclength + = 5 ;
2020-07-17 16:39:01 +01:00
} else { /* If there remains a group of less than 6 bytes */
2016-02-20 10:50:15 +00:00
len + = chunkLen ;
while ( chunkLen - - ) {
2022-11-06 22:25:19 +00:00
chainemc [ ( * p_mclength ) + + ] = chaine [ start + + ] ;
2016-02-20 10:50:15 +00:00
}
}
}
}
2009-10-06 19:03:00 +00:00
}
/* 712 */
2022-11-06 22:25:19 +00:00
/* Numeric compaction */
static void pdf_numbprocess ( int * chainemc , int * p_mclength , const unsigned char chaine [ ] , const int start ,
2022-08-18 22:25:09 +01:00
const int length ) {
int j ;
2016-02-20 10:50:15 +00:00
2022-11-06 22:25:19 +00:00
chainemc [ ( * p_mclength ) + + ] = 902 ;
2016-02-20 10:50:15 +00:00
j = 0 ;
while ( j < length ) {
2017-09-10 12:03:09 -03:00
int dumlength = 0 ;
2022-08-18 22:25:09 +01:00
int p , len , loop , nombre , dummy [ 50 ] ;
char chainemod [ 45 ] ;
int longueur = length - j ;
2016-02-20 10:50:15 +00:00
if ( longueur > 44 ) {
longueur = 44 ;
}
2021-10-30 22:00:31 +01:00
len = longueur + 1 ;
chainemod [ 0 ] = 1 ;
for ( loop = 1 ; loop < len ; loop + + ) {
chainemod [ loop ] = ctoi ( chaine [ start + loop + j - 1 ] ) ;
2016-02-20 10:50:15 +00:00
}
do {
/* 877 - gosub Modulo */
2020-11-01 18:32:55 +00:00
p = 0 ;
2016-02-20 10:50:15 +00:00
nombre = 0 ;
2021-10-30 22:00:31 +01:00
for ( loop = 0 ; loop < len ; loop + + ) {
2016-02-20 10:50:15 +00:00
nombre * = 10 ;
2021-10-30 22:00:31 +01:00
nombre + = chainemod [ loop ] ;
2022-08-18 22:25:09 +01:00
if ( nombre < 900 ) {
2020-11-01 18:32:55 +00:00
if ( p ) {
2021-10-30 22:00:31 +01:00
chainemod [ p + + ] = 0 ;
2016-02-20 10:50:15 +00:00
}
} else {
2022-08-18 22:25:09 +01:00
chainemod [ p ] = ( nombre / 900 ) ;
nombre - = chainemod [ p + + ] * 900 ; /* nombre % 900 */
2016-02-20 10:50:15 +00:00
}
}
/* return to 723 */
2022-08-18 22:25:09 +01:00
dummy [ dumlength + + ] = nombre ;
2021-10-30 22:00:31 +01:00
len = p ;
2020-11-01 18:32:55 +00:00
} while ( p ) ;
for ( loop = dumlength - 1 ; loop > = 0 ; loop - - ) {
2022-11-06 22:25:19 +00:00
chainemc [ ( * p_mclength ) + + ] = dummy [ loop ] ;
2016-02-20 10:50:15 +00:00
}
j + = longueur ;
}
2009-10-06 19:03:00 +00:00
}
2022-08-18 22:25:09 +01:00
# ifdef ZINT_TEST /* Wrapper for direct testing */
2022-11-06 22:25:19 +00:00
INTERNAL void pdf_numbprocess_test ( int * chainemc , int * p_mclength , const unsigned char chaine [ ] , const int start ,
2022-08-18 22:25:09 +01:00
const int length ) {
2022-11-06 22:25:19 +00:00
pdf_numbprocess ( chainemc , p_mclength , chaine , start , length ) ;
2022-08-18 22:25:09 +01:00
}
# endif
2022-11-06 22:25:19 +00:00
/* Minimal encoding */
/* Return number of consecutive chars from `position` in table `t_table` */
static int pdf_table_length ( const unsigned char source [ ] , const int length , const int position , const int t_table ) {
int i ;
for ( i = position ; i < length & & source [ i ] < 127 & & ( pdf_asciix [ source [ i ] ] & t_table ) ; i + + ) ;
return i - position ;
}
struct pdf_edge {
unsigned char mode ;
unsigned short from ; /* Position in input data, 0-based */
unsigned short len ;
unsigned short units ; /* Cumulative TEX/NUM/BYT units since entering TEX/NUM/BYT mode */
unsigned short unit_size ; /* Number of codewords based on units since entering TEX/NUM/BYT mode */
unsigned short size ; /* Cumulative number of codewords in previous TEX/NUM/BYT modes */
unsigned short previous ; /* Index into edges array */
} ;
/* Note 1st row of edges not used so valid previous cannot point there, i.e. won't be zero */
# define PDF_PREVIOUS(edges, edge) \
( ( edge ) - > previous ? ( edges ) + ( edge ) - > previous : NULL )
#if 0
# define PDF_TRACE
# endif
# include "pdf417_trace.h"
/* Initialize a new edge */
static int pdf_new_Edge ( struct pdf_edge * edges , const int mode , const int from , const int len , const int t_table ,
const int lastmode , struct pdf_edge * previous , struct pdf_edge * edge ) {
const int real_mode = PDF_REAL_MODE ( mode ) ;
int previousMode , real_previousMode ;
int units ;
int unit_size = 0 ; /* Suppress clang-tidy clang-analyzer-core.uninitialized.Assign warning */
int dv , md ;
edge - > mode = mode ;
edge - > from = from ;
edge - > len = len ;
if ( previous ) {
assert ( previous - > mode & & previous - > len & & ( previous - > unit_size + previous - > size ) ) ;
previousMode = previous - > mode ;
real_previousMode = PDF_REAL_MODE ( previousMode ) ;
edge - > previous = previous - edges ;
if ( real_mode ! = real_previousMode ) {
edge - > size = previous - > size + previous - > unit_size + 1 ; /* + TEX/NUM/BYT switch */
units = 0 ;
} else {
edge - > size = previous - > size ;
units = previous - > units ;
}
} else {
previousMode = lastmode ;
real_previousMode = PDF_REAL_MODE ( previousMode ) ;
edge - > previous = 0 ;
edge - > size = real_mode ! = real_previousMode | | real_previousMode ! = PDF_TEX ? 1 : 0 ;
units = 0 ;
}
switch ( mode ) {
case PDF_ALP :
assert ( ! t_table | | ( t_table & ( T_ALPHA | T_PUNCT ) ) ) ;
if ( t_table ) {
if ( previousMode ! = mode & & real_previousMode = = PDF_TEX ) {
units + = 1 + ( previousMode = = PDF_LOW ) ; /* AL or ML+AL */
}
units + = ( 1 + ! ( t_table & T_ALPHA ) ) * len ; /* chars or PS + char */
} else { /* Binary shift */
assert ( len = = 1 ) ;
if ( units & 1 ) {
units + + ; /* PS or AL pad */
}
if ( previousMode ! = mode & & real_previousMode = = PDF_TEX ) {
units + = 1 + ( previousMode = = PDF_LOW ) ; /* AL or ML+AL */
}
units + = 4 ; /* BYT SHIFT 913 (2 units) + byte (2 units) */
}
unit_size = ( units + 1 ) > > 1 ;
break ;
case PDF_LOW :
assert ( ! t_table | | ( t_table & ( T_LOWER | T_PUNCT | T_ALPHA ) ) ) ;
if ( t_table ) {
if ( previousMode ! = mode ) {
units + = 1 + ( previousMode = = PDF_PNC ) ; /* LL or AL+LL */
}
units + = ( 1 + ! ( t_table & T_LOWER ) ) * len ; /* chars or PS/AS + char */
} else { /* Binary shift */
assert ( len = = 1 ) ;
if ( units & 1 ) {
units + + ; /* PS or AL pad */
}
if ( previousMode ! = mode ) {
units + = 1 + ( previousMode = = PDF_PNC ) ; /* LL or AL+LL */
}
units + = 4 ; /* BYT SHIFT 913 (2 units) + byte (2 units) */
}
unit_size = ( units + 1 ) > > 1 ;
break ;
case PDF_MIX :
assert ( ! t_table | | ( t_table & ( T_MIXED | T_PUNCT ) ) ) ;
if ( t_table ) {
if ( previousMode ! = mode ) {
units + = 1 + ( previousMode = = PDF_PNC ) ; /* ML or AL+ML */
}
units + = ( 1 + ! ( t_table & T_MIXED ) ) * len ; /* chars or PS + char */
} else { /* Binary shift */
assert ( len = = 1 ) ;
if ( units & 1 ) {
units + + ; /* PS pad */
}
if ( previousMode ! = mode ) {
units + = 1 + ( previousMode = = PDF_PNC ) ; /* ML or AL+ML */
}
units + = 4 ; /* BYT SHIFT 913 (2 units) + byte (2 units) */
}
unit_size = ( units + 1 ) > > 1 ;
break ;
case PDF_PNC :
assert ( ! t_table | | ( t_table & T_PUNCT ) ) ;
if ( t_table ) {
if ( previousMode ! = mode ) {
units + = 1 + ( previousMode ! = PDF_MIX ) ; /* PL or ML+PL */
}
units + = len ; /* chars */
} else { /* Binary shift */
assert ( len = = 1 ) ;
if ( units & 1 ) {
units + = 3 ; /* AL pad + (after BYT SHIFT) ML+PL to return to PNC */
} else if ( previousMode ! = mode ) {
units + = 1 + ( previousMode ! = PDF_MIX ) ; /* PL or ML+PL */
}
units + = 4 ; /* BYT SHIFT 913 (2 units) + byte (2 units) */
}
unit_size = ( units + 1 ) > > 1 ;
break ;
case PDF_BYT :
units + = len ;
dv = units / 6 ;
unit_size = dv * 5 + ( units - dv * 6 ) ;
break ;
case PDF_NUM :
units + = len ;
dv = units / 44 ;
md = units - dv * 44 ;
unit_size = dv * 15 + ( md ? md / 3 + 1 : 0 ) ;
break ;
}
edge - > units = units ;
edge - > unit_size = unit_size ;
return edge - > size + edge - > unit_size ;
}
/* Whether `new_units` likely to result in less (fractional) codewords than `existing_units`, allowing for `mode` */
static int pdf_new_units_better ( const int mode , const int existing_units , const int new_units ) {
if ( PDF_REAL_MODE ( mode ) = = PDF_TEX ) {
if ( ( new_units & 1 ) ! = ( existing_units & 1 ) ) {
return ( existing_units & 1 ) ;
}
} else if ( mode = = PDF_BYT ) {
const int existing_md = existing_units % 6 ;
if ( new_units % 6 ! = existing_md ) {
return existing_md ;
}
}
return new_units < existing_units ;
}
/* Add an edge for a mode at a vertex if no existing edge or if more optimal than existing edge */
static void pdf_addEdge ( const unsigned char * source , const int length , struct pdf_edge * edges , const int mode ,
const int from , const int len , const int t_table , const int lastmode , struct pdf_edge * previous ) {
struct pdf_edge edge ;
const int new_size = pdf_new_Edge ( edges , mode , from , len , t_table , lastmode , previous , & edge ) ;
const int vertexIndex = from + len ;
const int v_ij = vertexIndex * PDF_NUM_MODES + mode - 1 ;
const int v_size = edges [ v_ij ] . size + edges [ v_ij ] . unit_size ;
if ( edges [ v_ij ] . mode = = 0 | | v_size > new_size
| | ( v_size = = new_size & & pdf_new_units_better ( mode , edge . units , edges [ v_ij ] . units ) ) ) {
PDF_TRACE_AddEdge ( source , length , edges , previous , vertexIndex , t_table , & edge ) ;
edges [ v_ij ] = edge ;
} else {
PDF_TRACE_NotAddEdge ( source , length , edges , previous , vertexIndex , t_table , & edge ) ;
}
}
/* Add edges for the various modes at a vertex */
static void pdf_addEdges ( const unsigned char source [ ] , const int length , const int lastmode , struct pdf_edge * edges ,
const int from , struct pdf_edge * previous ) {
const unsigned char c = source [ from ] ;
const int t_table = c < 127 ? pdf_asciix [ c ] : 0 ;
if ( t_table & T_ALPHA ) {
const int len = pdf_table_length ( source , length , from , T_ALPHA ) ;
pdf_addEdge ( source , length , edges , PDF_ALP , from , len , T_ALPHA , lastmode , previous ) ;
}
if ( ! t_table | | ( t_table & T_PUNCT ) ) { /* Binary shift or PS */
pdf_addEdge ( source , length , edges , PDF_ALP , from , 1 /*len*/ , t_table & ~ T_ALPHA , lastmode , previous ) ;
}
if ( t_table & T_LOWER ) {
const int len = pdf_table_length ( source , length , from , T_LOWER ) ;
pdf_addEdge ( source , length , edges , PDF_LOW , from , len , T_LOWER , lastmode , previous ) ;
}
if ( ! t_table | | ( t_table & ( T_PUNCT | T_ALPHA ) ) ) { /* Binary shift or PS/AS */
pdf_addEdge ( source , length , edges , PDF_LOW , from , 1 /*len*/ , t_table & ~ T_LOWER , lastmode , previous ) ;
}
if ( t_table & T_MIXED ) {
const int len = pdf_table_length ( source , length , from , T_MIXED ) ;
pdf_addEdge ( source , length , edges , PDF_MIX , from , len , T_MIXED , lastmode , previous ) ;
if ( len > 1 & & z_isdigit ( source [ from + 1 ] ) ) { /* Add single-length edge before digit to compare to NUM */
pdf_addEdge ( source , length , edges , PDF_MIX , from , 1 /*len*/ , T_MIXED , lastmode , previous ) ;
}
}
if ( ! t_table | | ( t_table & T_PUNCT ) ) { /* Binary shift or PS */
pdf_addEdge ( source , length , edges , PDF_MIX , from , 1 /*len*/ , t_table & ~ T_MIXED , lastmode , previous ) ;
}
if ( t_table & T_PUNCT ) {
const int len = pdf_table_length ( source , length , from , T_PUNCT ) ;
pdf_addEdge ( source , length , edges , PDF_PNC , from , len , T_PUNCT , lastmode , previous ) ;
}
if ( ! t_table ) { /* Binary shift */
pdf_addEdge ( source , length , edges , PDF_PNC , from , 1 /*len*/ , t_table , lastmode , previous ) ;
}
if ( z_isdigit ( c ) ) {
const int len = cnt_digits ( source , length , from , - 1 /*all*/ ) ;
pdf_addEdge ( source , length , edges , PDF_NUM , from , len , 0 /*t_table*/ , lastmode , previous ) ;
}
pdf_addEdge ( source , length , edges , PDF_BYT , from , 1 /*len*/ , 0 /*t_table*/ , lastmode , previous ) ;
}
/* Calculate optimized encoding modes */
static int pdf_define_mode ( int liste [ 3 ] [ PDF_MAX_LEN ] , int * p_indexliste , const unsigned char source [ ] ,
const int length , const int lastmode , const int debug_print ) {
int i , j , v_i ;
int minimalJ , minimalSize ;
struct pdf_edge * edge ;
int mode_start , mode_len ;
struct pdf_edge * edges = ( struct pdf_edge * ) calloc ( ( length + 1 ) * PDF_NUM_MODES , sizeof ( struct pdf_edge ) ) ;
if ( ! edges ) {
return 0 ;
}
pdf_addEdges ( source , length , lastmode , edges , 0 , NULL ) ;
PDF_TRACE_Edges ( " DEBUG Initial situation \n " , source , length , edges , 0 ) ;
for ( i = 1 ; i < length ; i + + ) {
v_i = i * PDF_NUM_MODES ;
for ( j = 0 ; j < PDF_NUM_MODES ; j + + ) {
if ( edges [ v_i + j ] . mode ) {
pdf_addEdges ( source , length , lastmode , edges , i , edges + v_i + j ) ;
}
}
PDF_TRACE_Edges ( " DEBUG situation after adding edges to vertices at position %d \n " , source , length , edges , i ) ;
}
PDF_TRACE_Edges ( " DEBUG Final situation \n " , source , length , edges , length ) ;
v_i = length * PDF_NUM_MODES ;
minimalJ = - 1 ;
minimalSize = INT_MAX ;
for ( j = 0 ; j < PDF_NUM_MODES ; j + + ) {
edge = edges + v_i + j ;
if ( edge - > mode ) {
const int edge_size = edge - > size + edge - > unit_size ;
if ( debug_print ) {
printf ( " edges[%d][%d][0] size %d(%d,%d) \n " , length , j , edge_size , edge - > unit_size , edge - > size ) ;
}
if ( edge_size < minimalSize ) {
minimalSize = edge_size ;
minimalJ = j ;
if ( debug_print ) printf ( " set minimalJ %d \n " , minimalJ ) ;
}
} else {
if ( debug_print ) printf ( " edges[%d][%d][0] NULL \n " , length , j ) ;
}
}
assert ( minimalJ > = 0 ) ;
edge = edges + v_i + minimalJ ;
mode_len = 0 ;
mode_start = length ;
while ( edge ) {
const int current_mode = edge - > mode ;
const int current_from = edge - > from ;
mode_len + = edge - > len ;
edge = PDF_PREVIOUS ( edges , edge ) ;
if ( ! edge | | edge - > mode ! = current_mode ) {
mode_start - - ;
liste [ 0 ] [ mode_start ] = mode_len ;
liste [ 1 ] [ mode_start ] = current_mode ;
liste [ 2 ] [ mode_start ] = current_from ;
mode_len = 0 ;
}
}
* p_indexliste = length - mode_start ;
if ( mode_start ) {
memmove ( liste [ 0 ] , liste [ 0 ] + mode_start , sizeof ( int ) * ( * p_indexliste ) ) ;
memmove ( liste [ 1 ] , liste [ 1 ] + mode_start , sizeof ( int ) * ( * p_indexliste ) ) ;
memmove ( liste [ 2 ] , liste [ 2 ] + mode_start , sizeof ( int ) * ( * p_indexliste ) ) ;
}
if ( debug_print ) {
printf ( " modes (%d): " , * p_indexliste ) ;
for ( i = 0 ; i < * p_indexliste ; i + + ) printf ( " %c(%d,%d) " , pdf_smodes [ liste [ 1 ] [ i ] ] , liste [ 2 ] [ i ] , liste [ 0 ] [ i ] ) ;
2023-06-12 01:25:55 +01:00
fputc ( ' \n ' , stdout ) ;
2022-11-06 22:25:19 +00:00
}
free ( edges ) ;
return 1 ;
2022-08-18 22:25:09 +01:00
}
Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility
Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
static get_zint_version() method, use QStringLiteral (QSL shorthand),
use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
add saveAs shortcut, add main menu, context menus and actions, add help,
reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
lessen triggering of update_preview(), shorten names of getters/setters,
simplify/shorten some update_preview() logic in switch,
CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
2021-10-09 00:13:39 +01:00
/* Initial processing of data, shared by `pdf417()` and `micropdf417()` */
2022-08-18 22:25:09 +01:00
static int pdf_initial ( struct zint_symbol * symbol , const unsigned char chaine [ ] , const int length , const int eci ,
2022-11-06 22:25:19 +00:00
const int is_micro , const int is_last_seg , int * p_lastmode , int * p_curtable , int * p_tex_padded ,
int chainemc [ PDF_MAX_LEN ] , int * p_mclength ) {
int i , indexchaine = 0 , indexliste = 0 ;
2022-08-18 22:25:09 +01:00
int liste [ 3 ] [ PDF_MAX_LEN ] = { { 0 } } ;
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
int mclength ;
2021-10-30 22:00:31 +01:00
const int debug_print = symbol - > debug & ZINT_DEBUG_PRINT ;
2022-11-06 22:25:19 +00:00
const int fast_encode = symbol - > input_mode & FAST_MODE ;
2020-03-28 15:10:53 +00:00
2016-02-20 10:50:15 +00:00
/* 456 */
2022-11-06 22:25:19 +00:00
if ( fast_encode ) {
int mode = pdf_quelmode ( chaine [ 0 ] ) ;
/* 463 */
do {
liste [ 1 ] [ indexliste ] = mode ;
liste [ 2 ] [ indexliste ] = indexchaine ;
while ( ( liste [ 1 ] [ indexliste ] = = mode ) & & ( indexchaine < length ) ) {
liste [ 0 ] [ indexliste ] + + ;
indexchaine + + ;
mode = pdf_quelmode ( chaine [ indexchaine ] ) ;
}
indexliste + + ;
} while ( indexchaine < length ) ;
2016-02-20 10:50:15 +00:00
2022-11-06 22:25:19 +00:00
if ( debug_print ) {
2023-06-12 01:25:55 +01:00
fputs ( " \n Initial block pattern: \n " , stdout ) ;
2022-11-06 22:25:19 +00:00
for ( i = 0 ; i < indexliste ; i + + ) {
printf ( " Start: %d Len: %d Type: %s \n " , liste [ 2 ] [ i ] , liste [ 0 ] [ i ] , pdf_mode_str ( liste [ 1 ] [ i ] ) ) ;
}
2016-02-20 10:50:15 +00:00
}
2022-11-06 22:25:19 +00:00
pdf_appendix_d_encode ( chaine , liste , & indexliste , debug_print ) ;
} else {
if ( ! pdf_define_mode ( liste , & indexliste , chaine , length , * p_lastmode , debug_print ) ) {
strcpy ( symbol - > errtxt , " 749: Insufficient memory for mode buffers " ) ;
return ZINT_ERROR_MEMORY ;
2022-08-10 13:40:40 -05:00
}
}
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) {
2023-06-12 01:25:55 +01:00
fputs ( " \n Compacted block pattern: \n " , stdout ) ;
2016-02-20 10:50:15 +00:00
for ( i = 0 ; i < indexliste ; i + + ) {
2022-11-06 22:25:19 +00:00
printf ( " Start: %d Len: %d Type: %s \n " , liste [ 2 ] [ i ] , liste [ 0 ] [ i ] ,
pdf_mode_str ( PDF_REAL_MODE ( liste [ 1 ] [ i ] ) ) ) ;
2016-02-20 10:50:15 +00:00
}
}
/* 541 - now compress the data */
indexchaine = 0 ;
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
mclength = * p_mclength ;
if ( mclength = = 0 & & ! is_micro ) {
mclength + + ; /* Allow for length descriptor for full symbol */
}
if ( * p_mclength = = 0 & & ( symbol - > output_options & READER_INIT ) ) {
chainemc [ mclength + + ] = 921 ; /* Reader Initialisation */
}
if ( eci ! = 0 ) {
if ( eci > 811799 ) {
strcpy ( symbol - > errtxt , " 472: Invalid ECI " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
/* Encoding ECI assignment number, according to Table 8 */
if ( eci < = 899 ) {
chainemc [ mclength + + ] = 927 ; /* ECI */
chainemc [ mclength + + ] = eci ;
} else if ( eci < = 810899 ) {
chainemc [ mclength + + ] = 926 ; /* ECI */
chainemc [ mclength + + ] = ( eci / 900 ) - 1 ;
chainemc [ mclength + + ] = eci % 900 ;
} else {
chainemc [ mclength + + ] = 925 ; /* ECI */
chainemc [ mclength + + ] = eci - 810900 ;
}
}
for ( i = 0 ; i < indexliste ; i + + ) {
2022-11-06 22:25:19 +00:00
const int real_mode = PDF_REAL_MODE ( liste [ 1 ] [ i ] ) ;
switch ( real_mode ) {
case PDF_TEX : /* 547 - text mode */
if ( fast_encode ) {
pdf_textprocess ( chainemc , & mclength , chaine , indexchaine , liste [ 0 ] [ i ] , * p_lastmode , is_last_seg ,
p_curtable , p_tex_padded ) ;
indexchaine + = liste [ 0 ] [ i ] ;
* p_lastmode = PDF_ALP ;
} else {
pdf_textprocess_minimal ( chainemc , & mclength , chaine , liste , indexliste , * p_lastmode , is_last_seg ,
p_curtable , p_tex_padded , & i ) ;
indexchaine = i + 1 < indexliste ? liste [ 2 ] [ i + 1 ] : length ;
* p_lastmode = PDF_TABLE_TO_MODE ( * p_curtable ) ;
}
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
break ;
2022-11-06 22:25:19 +00:00
case PDF_BYT : /* 670 - octet stream mode */
2022-08-18 22:25:09 +01:00
pdf_byteprocess ( chainemc , & mclength , chaine , indexchaine , liste [ 0 ] [ i ] , * p_lastmode , debug_print ) ;
2022-08-21 15:15:27 +01:00
/* don't switch mode on single byte shift from text mode */
2022-11-06 22:25:19 +00:00
if ( PDF_REAL_MODE ( * p_lastmode ) ! = PDF_TEX | | liste [ 0 ] [ i ] ! = 1 ) {
* p_lastmode = PDF_BYT ;
2022-08-18 22:25:09 +01:00
} else if ( * p_curtable = = T_PUNCT & & * p_tex_padded ) { /* If T_PUNCT and padded with AL */
/* Then need to reset to alpha - ISO/IEC 15438:2015 5.4.2.4 b) 2) */
* p_curtable = T_ALPHA ;
2022-08-10 13:40:40 -05:00
}
2022-11-06 22:25:19 +00:00
indexchaine + = liste [ 0 ] [ i ] ;
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
break ;
2022-11-06 22:25:19 +00:00
case PDF_NUM : /* 712 - numeric mode */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
pdf_numbprocess ( chainemc , & mclength , chaine , indexchaine , liste [ 0 ] [ i ] ) ;
2022-11-06 22:25:19 +00:00
* p_lastmode = PDF_NUM ;
indexchaine + = liste [ 0 ] [ i ] ;
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
break ;
}
}
* p_mclength = mclength ;
return 0 ;
}
/* Call `pdf_initial()` for each segment, dealing with Structured Append beforehand */
static int pdf_initial_segs ( struct zint_symbol * symbol , struct zint_seg segs [ ] , const int seg_count ,
const int is_micro , int chainemc [ PDF_MAX_LEN ] , int * p_mclength , int structapp_cws [ 18 ] ,
int * p_structapp_cp ) {
int i ;
int error_number = 0 ;
int structapp_cp = 0 ;
2022-08-18 22:25:09 +01:00
int lastmode ;
int curtable ;
int tex_padded ;
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
* p_mclength = 0 ;
2017-10-23 21:37:52 +02:00
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( symbol - > structapp . count ) {
int id_cnt = 0 , ids [ 10 ] ;
if ( symbol - > structapp . count < 2 | | symbol - > structapp . count > 99999 ) {
strcpy ( symbol - > errtxt , " 740: Structured Append count out of range (2-99999) " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
if ( symbol - > structapp . index < 1 | | symbol - > structapp . index > symbol - > structapp . count ) {
sprintf ( symbol - > errtxt , " 741: Structured Append index out of range (1-%d) " , symbol - > structapp . count ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
if ( symbol - > structapp . id [ 0 ] ) {
int id_len ;
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-02 21:39:01 +00:00
for ( id_len = 1 ; id_len < 31 & & symbol - > structapp . id [ id_len ] ; id_len + + ) ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( id_len > 30 ) { /* 10 triplets */
strcpy ( symbol - > errtxt , " 742: Structured Append ID too long (30 digit maximum) " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
for ( i = 0 ; i < id_len ; i + = 3 , id_cnt + + ) {
2021-10-30 22:00:31 +01:00
const int triplet_len = i + 3 < id_len ? 3 : id_len - i ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
ids [ id_cnt ] = to_int ( ( const unsigned char * ) ( symbol - > structapp . id + i ) , triplet_len ) ;
if ( ids [ id_cnt ] = = - 1 ) {
strcpy ( symbol - > errtxt , " 743: Invalid Structured Append ID (digits only) " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
if ( ids [ id_cnt ] > 899 ) {
sprintf ( symbol - > errtxt , " 744: Structured Append ID triplet %d '%03d' out of range (000-899) " ,
id_cnt + 1 , ids [ id_cnt ] ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
}
}
structapp_cws [ structapp_cp + + ] = 928 ; /* Macro marker */
structapp_cws [ structapp_cp + + ] = ( 100000 + symbol - > structapp . index - 1 ) / 900 ; /* Segment index 1 */
structapp_cws [ structapp_cp + + ] = ( 100000 + symbol - > structapp . index - 1 ) % 900 ; /* Segment index 2 */
for ( i = 0 ; i < id_cnt ; i + + ) {
structapp_cws [ structapp_cp + + ] = ids [ i ] ;
}
structapp_cws [ structapp_cp + + ] = 923 ; /* Optional field */
structapp_cws [ structapp_cp + + ] = 1 ; /* Segment count tag */
structapp_cws [ structapp_cp + + ] = ( 100000 + symbol - > structapp . count ) / 900 ; /* Segment count 1 */
structapp_cws [ structapp_cp + + ] = ( 100000 + symbol - > structapp . count ) % 900 ; /* Segment count 2 */
if ( symbol - > structapp . index = = symbol - > structapp . count ) {
structapp_cws [ structapp_cp + + ] = 922 ; /* Special last segment terminator */
}
}
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
* p_structapp_cp = structapp_cp ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
2022-08-18 22:25:09 +01:00
/* Default mode for PDF417 is Text Compaction Alpha (ISO/IEC 15438:2015 5.4.2.1), and for MICROPDF417 is Byte
* Compaction ( ISO / IEC 24728 : 2006 5.4 .3 ) */
2022-11-06 22:25:19 +00:00
lastmode = is_micro ? PDF_BYT : PDF_ALP ;
2022-08-18 22:25:09 +01:00
/* Start in upper alpha - tracked across calls to `pdf_textprocess()` to allow for interleaving byte shifts */
curtable = T_ALPHA ;
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
for ( i = 0 ; i < seg_count ; i + + ) {
2022-11-06 22:25:19 +00:00
error_number = pdf_initial ( symbol , segs [ i ] . source , segs [ i ] . length , segs [ i ] . eci , is_micro , i + 1 = = seg_count ,
& lastmode , & curtable , & tex_padded , chainemc , p_mclength ) ;
if ( error_number ) { /* Only errors >= ZINT_ERROR returned */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
return error_number ;
2016-02-20 10:50:15 +00:00
}
}
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
return error_number ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
}
/* 366 */
2022-11-06 22:25:19 +00:00
/* Encode PDF417 */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
static int pdf_enc ( struct zint_symbol * symbol , struct zint_seg segs [ ] , const int seg_count ) {
2021-10-30 22:00:31 +01:00
int i , j , longueur , loop , mccorrection [ 520 ] = { 0 } , offset ;
int total , chainemc [ PDF_MAX_LEN ] , mclength , c1 , c2 , c3 , dummy [ 35 ] ;
int rows , cols , ecc , ecc_cws , padding ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
char pattern [ 580 ] ;
int bp = 0 ;
int structapp_cws [ 18 ] = { 0 } ; /* 3 (Index) + 10 (ID) + 4 (Count) + 1 (Last) */
int structapp_cp = 0 ;
int error_number ;
2021-10-30 22:00:31 +01:00
const int debug_print = symbol - > debug & ZINT_DEBUG_PRINT ;
static const int ecc_num_cws [ ] = { 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 } ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
if ( segs_length ( segs , seg_count ) > PDF_MAX_LEN ) {
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
strcpy ( symbol - > errtxt , " 463: Input string too long " ) ;
return ZINT_ERROR_TOO_LONG ;
}
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
error_number = pdf_initial_segs ( symbol , segs , seg_count , 0 /*is_micro*/ , chainemc , & mclength , structapp_cws ,
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
& structapp_cp ) ;
2021-10-30 22:00:31 +01:00
if ( error_number ) { /* Only errors return >= ZINT_ERROR */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
return error_number ;
}
if ( debug_print ) {
2021-10-30 22:00:31 +01:00
printf ( " \n Compressed data stream (%d): \n " , mclength - 1 ) ;
for ( i = 1 ; i < mclength ; i + + ) { /* Skip unset length descriptor */
2016-02-20 10:50:15 +00:00
printf ( " %d " , chainemc [ i ] ) ;
}
2023-06-12 01:25:55 +01:00
fputs ( " \n \n " , stdout ) ;
2016-02-20 10:50:15 +00:00
}
/* 752 - Now take care of the number of CWs per row */
2021-10-30 22:00:31 +01:00
/* ECC */
ecc = symbol - > option_1 ;
if ( ecc < 0 ) { /* If not specified, set ECC depending on no. of codewords */
const int data_cws = mclength - 1 + structapp_cp ; /* -1 for length descriptor */
/* ISO/IEC 15438:2015 Annex E Table E.1 Recommended minima */
if ( data_cws < = 40 ) {
ecc = 2 ;
} else if ( data_cws < = 160 ) {
ecc = 3 ;
} else if ( data_cws < = 320 ) {
ecc = 4 ;
} else if ( data_cws < = 863 ) {
ecc = 5 ;
2020-11-01 18:32:55 +00:00
} else {
2021-10-30 22:00:31 +01:00
ecc = 6 ; /* Not mentioned in Table E.1 */
2016-02-20 10:50:15 +00:00
}
}
2021-10-30 22:00:31 +01:00
ecc_cws = ecc_num_cws [ ecc ] ;
longueur = mclength + structapp_cp + ecc_cws ;
if ( debug_print ) printf ( " Total No. of Codewords: %d, ECC %d, No. of ECC Codewords: %d \n " , longueur , ecc , ecc_cws ) ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( longueur > 928 ) {
2016-02-20 10:50:15 +00:00
/* Enforce maximum codeword limit */
2020-07-17 16:39:01 +01:00
strcpy ( symbol - > errtxt , " 464: Input string too long " ) ;
return ZINT_ERROR_TOO_LONG ;
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
cols = symbol - > option_2 ;
rows = symbol - > option_3 ;
if ( rows ) { /* Rows given */
if ( cols < 1 ) { /* Cols automatic */
cols = ( longueur + rows - 1 ) / rows ;
if ( cols < = 1 ) {
cols = 1 ;
} else {
/* Increase rows if would need > 30 columns */
for ( ; cols > 30 & & rows < 90 ; rows + + , cols = ( longueur + rows - 1 ) / rows ) ;
assert ( cols < = 30 ) ;
/* Increase rows if multiple too big */
for ( ; cols > = 1 & & rows < 90 & & rows * cols > 928 ; rows + + , cols = ( longueur + rows - 1 ) / rows ) ;
if ( rows * cols > 928 ) {
strcpy ( symbol - > errtxt , " 465: Data too long for specified number of rows " ) ;
return ZINT_ERROR_TOO_LONG ;
}
}
} else { /* Cols given */
/* Increase rows if multiple too big */
for ( ; rows < = 90 & & rows * cols < longueur ; rows + + ) ;
if ( rows > 90 | | rows * cols > 928 ) {
strcpy ( symbol - > errtxt , " 745: Data too long for specified number of columns " ) ;
return ZINT_ERROR_TOO_LONG ;
}
}
if ( rows ! = symbol - > option_3 ) {
sprintf ( symbol - > errtxt , " 746: Rows increased from %d to %d " , symbol - > option_3 , rows ) ;
error_number = ZINT_WARN_INVALID_OPTION ;
}
} else { /* Rows automatic, cols automatic or given */
if ( cols < 1 ) { /* Cols automatic */
cols = ( int ) round ( sqrt ( ( longueur - 1 ) / 3.0 ) ) ; /* -1 (length descriptor) for back-compatibility */
}
rows = ( longueur + cols - 1 ) / cols ;
if ( rows < = 3 ) {
rows = 3 ;
} else {
/* Increase cols if would need > 90 rows - do this even if cols specified for better back-compatibility
( though previously only increased once ) */
for ( ; rows > 90 & & cols < 30 ; cols + + , rows = ( longueur + cols - 1 ) / cols ) ;
assert ( rows < = 90 ) ;
/* Increase cols if multiple too big */
for ( ; rows > = 3 & & cols < 30 & & rows * cols > 928 ; cols + + , rows = ( longueur + cols - 1 ) / cols ) ;
if ( rows * cols > 928 ) {
strcpy ( symbol - > errtxt , " 747: Data too long for specified number of columns " ) ;
return ZINT_ERROR_TOO_LONG ;
}
if ( symbol - > option_2 & & cols ! = symbol - > option_2 ) { /* Note previously did not warn if cols auto-upped */
sprintf ( symbol - > errtxt , " 748: Columns increased from %d to %d " , symbol - > option_2 , cols ) ;
error_number = ZINT_WARN_INVALID_OPTION ;
}
2020-11-01 18:32:55 +00:00
}
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
assert ( rows * cols > = longueur ) ;
2016-02-20 10:50:15 +00:00
/* 781 - Padding calculation */
2021-10-30 22:00:31 +01:00
padding = rows * cols - longueur ;
2016-02-20 10:50:15 +00:00
/* We add the padding */
2021-10-30 22:00:31 +01:00
for ( i = 0 ; i < padding ; i + + ) {
chainemc [ mclength + + ] = 900 ;
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
if ( debug_print ) printf ( " Padding: %d \n " , padding ) ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
/* We add the Structured Append Macro Control Block if any */
if ( structapp_cp ) {
for ( i = 0 ; i < structapp_cp ; i + + ) {
chainemc [ mclength + + ] = structapp_cws [ i ] ;
}
}
2021-10-30 22:00:31 +01:00
/* Set the length descriptor */
chainemc [ 0 ] = mclength ;
2016-02-20 10:50:15 +00:00
/* 796 - we now take care of the Reed Solomon codes */
2021-10-30 22:00:31 +01:00
switch ( ecc ) {
2016-02-20 10:50:15 +00:00
case 1 : offset = 2 ;
break ;
case 2 : offset = 6 ;
break ;
case 3 : offset = 14 ;
break ;
case 4 : offset = 30 ;
break ;
case 5 : offset = 62 ;
break ;
case 6 : offset = 126 ;
break ;
case 7 : offset = 254 ;
break ;
case 8 : offset = 510 ;
break ;
default : offset = 0 ;
break ;
}
2021-10-30 22:00:31 +01:00
for ( i = 0 ; i < mclength ; i + + ) {
total = ( chainemc [ i ] + mccorrection [ ecc_cws - 1 ] ) % 929 ;
for ( j = ecc_cws - 1 ; j > 0 ; j - - ) {
mccorrection [ j ] = ( mccorrection [ j - 1 ] + 929 - ( total * pdf_coefrs [ offset + j ] ) % 929 ) % 929 ;
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
mccorrection [ 0 ] = ( 929 - ( total * pdf_coefrs [ offset ] ) % 929 ) % 929 ;
2016-02-20 10:50:15 +00:00
}
/* we add these codes to the string */
2021-10-30 22:00:31 +01:00
for ( i = ecc_cws - 1 ; i > = 0 ; i - - ) {
2016-02-20 10:50:15 +00:00
chainemc [ mclength + + ] = mccorrection [ i ] ? 929 - mccorrection [ i ] : 0 ;
}
2021-09-26 23:55:16 +01:00
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) {
2021-08-05 16:34:45 +01:00
printf ( " Complete CW string (%d): \n " , mclength ) ;
2019-09-04 21:34:20 +01:00
for ( i = 0 ; i < mclength ; i + + ) {
printf ( " %d " , chainemc [ i ] ) ;
}
2023-06-12 01:25:55 +01:00
fputc ( ' \n ' , stdout ) ;
2019-09-04 21:34:20 +01:00
}
2020-07-17 16:39:01 +01:00
# ifdef ZINT_TEST
if ( symbol - > debug & ZINT_DEBUG_TEST ) {
debug_test_codeword_dump_int ( symbol , chainemc , mclength ) ;
}
# endif
2016-02-20 10:50:15 +00:00
2021-10-30 22:00:31 +01:00
if ( debug_print ) printf ( " \n Symbol size: \n %d columns x %d rows \n " , cols , rows ) ;
2021-08-05 16:34:45 +01:00
2016-02-20 10:50:15 +00:00
/* 818 - The CW string is finished */
2021-10-30 22:00:31 +01:00
c1 = ( rows - 1 ) / 3 ;
c2 = ecc * 3 + ( rows - 1 ) % 3 ;
c3 = cols - 1 ;
2016-02-20 10:50:15 +00:00
/* we now encode each row */
2021-10-30 22:00:31 +01:00
for ( i = 0 ; i < rows ; i + + ) {
const int k = ( i / 3 ) * 30 ;
2020-12-23 10:57:24 +00:00
bp = 0 ;
2021-10-30 22:00:31 +01:00
for ( j = 0 ; j < cols ; j + + ) {
dummy [ j + 1 ] = chainemc [ i * cols + j ] ;
2016-02-20 10:50:15 +00:00
}
switch ( i % 3 ) {
case 0 :
dummy [ 0 ] = k + c1 ;
2021-10-30 22:00:31 +01:00
dummy [ cols + 1 ] = k + c3 ;
2017-06-09 22:00:22 +01:00
offset = 0 ; /* cluster(0) */
2016-02-20 10:50:15 +00:00
break ;
case 1 :
dummy [ 0 ] = k + c2 ;
2021-10-30 22:00:31 +01:00
dummy [ cols + 1 ] = k + c1 ;
2017-06-09 22:00:22 +01:00
offset = 929 ; /* cluster(3) */
2016-02-20 10:50:15 +00:00
break ;
case 2 :
dummy [ 0 ] = k + c3 ;
2021-10-30 22:00:31 +01:00
dummy [ cols + 1 ] = k + c2 ;
2017-06-09 22:00:22 +01:00
offset = 1858 ; /* cluster(6) */
2016-02-20 10:50:15 +00:00
break ;
}
2020-12-23 10:57:24 +00:00
bp = bin_append_posn ( 0x1FEA8 , 17 , pattern , bp ) ; /* Row start */
2017-06-09 22:00:22 +01:00
2021-10-30 22:00:31 +01:00
for ( j = 0 ; j < = cols ; j + + ) {
2020-12-23 10:57:24 +00:00
bp = bin_append_posn ( pdf_bitpattern [ offset + dummy [ j ] ] , 16 , pattern , bp ) ;
pattern [ bp + + ] = ' 0 ' ;
2017-06-09 22:00:22 +01:00
}
2017-10-23 21:37:52 +02:00
2020-07-29 22:35:31 +01:00
if ( symbol - > symbology ! = BARCODE_PDF417COMP ) {
2020-12-23 10:57:24 +00:00
bp = bin_append_posn ( pdf_bitpattern [ offset + dummy [ j ] ] , 16 , pattern , bp ) ;
pattern [ bp + + ] = ' 0 ' ;
bp = bin_append_posn ( 0x3FA29 , 18 , pattern , bp ) ; /* Row Stop */
2020-07-17 16:39:01 +01:00
} else {
2020-12-23 10:57:24 +00:00
pattern [ bp + + ] = ' 1 ' ; /* Compact PDF417 Stop pattern */
2016-02-20 10:50:15 +00:00
}
2017-10-23 21:37:52 +02:00
2020-12-23 10:57:24 +00:00
for ( loop = 0 ; loop < bp ; loop + + ) {
2016-02-20 10:50:15 +00:00
if ( pattern [ loop ] = = ' 1 ' ) {
set_module ( symbol , i , loop ) ;
}
}
}
2020-12-23 10:57:24 +00:00
symbol - > width = bp ;
2021-10-30 22:00:31 +01:00
symbol - > rows = rows ;
2021-09-26 23:55:16 +01:00
2021-06-19 13:11:23 +01:00
/* ISO/IEC 15438:2015 Section 5.8.2 3X minimum row height */
2021-10-30 22:00:31 +01:00
if ( error_number ) {
( void ) set_height ( symbol , 3.0f , 0.0f , 0.0f , 1 /*no_errtxt*/ ) ;
} else {
error_number = set_height ( symbol , 3.0f , 0.0f , 0.0f , 0 /*no_errtxt*/ ) ;
}
2016-02-20 10:50:15 +00:00
/* 843 */
2020-09-30 12:19:12 +01:00
return error_number ;
2009-10-06 19:03:00 +00:00
}
/* 345 */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
INTERNAL int pdf417 ( struct zint_symbol * symbol , struct zint_seg segs [ ] , const int seg_count ) {
2016-02-20 10:50:15 +00:00
int codeerr , error_number ;
error_number = 0 ;
if ( ( symbol - > option_1 < - 1 ) | | ( symbol - > option_1 > 8 ) ) {
2017-07-27 16:01:53 +01:00
strcpy ( symbol - > errtxt , " 460: Security value out of range " ) ;
2020-08-22 11:09:57 +01:00
if ( symbol - > warn_level = = WARN_FAIL_ALL ) {
return ZINT_ERROR_INVALID_OPTION ;
}
2021-08-05 16:34:45 +01:00
symbol - > option_1 = - 1 ;
error_number = ZINT_WARN_INVALID_OPTION ;
2016-02-20 10:50:15 +00:00
}
if ( ( symbol - > option_2 < 0 ) | | ( symbol - > option_2 > 30 ) ) {
2021-10-30 22:00:31 +01:00
strcpy ( symbol - > errtxt , " 461: Number of columns out of range (1 to 30) " ) ;
2020-08-22 11:09:57 +01:00
if ( symbol - > warn_level = = WARN_FAIL_ALL ) {
return ZINT_ERROR_INVALID_OPTION ;
}
2021-08-05 16:34:45 +01:00
symbol - > option_2 = 0 ;
error_number = ZINT_WARN_INVALID_OPTION ;
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
if ( symbol - > option_3 & & ( symbol - > option_3 < 3 | | symbol - > option_3 > 90 ) ) {
strcpy ( symbol - > errtxt , " 466: Number of rows out of range (3 to 90) " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
if ( symbol - > option_2 & & symbol - > option_3 & & symbol - > option_2 * symbol - > option_3 > 928 ) {
strcpy ( symbol - > errtxt , " 475: Columns x rows out of range (1 to 928) " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
2016-02-20 10:50:15 +00:00
/* 349 */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
codeerr = pdf_enc ( symbol , segs , seg_count ) ;
2016-02-20 10:50:15 +00:00
/* 352 */
if ( codeerr ! = 0 ) {
2020-07-17 16:39:01 +01:00
error_number = codeerr ;
2016-02-20 10:50:15 +00:00
}
/* 364 */
return error_number ;
2009-10-06 19:03:00 +00:00
}
2016-02-20 10:50:15 +00:00
/* like PDF417 only much smaller! */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
INTERNAL int micropdf417 ( struct zint_symbol * symbol , struct zint_seg segs [ ] , const int seg_count ) {
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
int i , k , j , longueur , mccorrection [ 50 ] = { 0 } , offset ;
2021-10-30 22:00:31 +01:00
int total , chainemc [ PDF_MAX_LEN ] , mclength , error_number = 0 ;
2017-06-09 22:00:22 +01:00
char pattern [ 580 ] ;
2020-12-23 10:57:24 +00:00
int bp = 0 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
int structapp_cws [ 18 ] = { 0 } ; /* 3 (Index) + 10 (ID) + 4 (Count) + 1 (Last) */
int structapp_cp = 0 ;
2022-11-06 22:25:19 +00:00
int variant ;
2021-06-19 13:11:23 +01:00
int LeftRAP , CentreRAP , RightRAP , Cluster , loop ;
2021-10-30 22:00:31 +01:00
const int debug_print = symbol - > debug & ZINT_DEBUG_PRINT ;
2016-02-20 10:50:15 +00:00
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
if ( segs_length ( segs , seg_count ) > MICRO_PDF_MAX_LEN ) {
2020-03-28 15:10:53 +00:00
strcpy ( symbol - > errtxt , " 474: Input data too long " ) ;
return ZINT_ERROR_TOO_LONG ;
}
2021-10-30 22:00:31 +01:00
if ( symbol - > option_3 ) {
strcpy ( symbol - > errtxt , " 476: Cannot specify rows for MicroPDF417 " ) ;
return ZINT_ERROR_INVALID_OPTION ;
}
2020-03-28 15:10:53 +00:00
2016-02-20 10:50:15 +00:00
/* Encoding starts out the same as PDF417, so use the same code */
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
error_number = pdf_initial_segs ( symbol , segs , seg_count , 1 /*is_micro*/ , chainemc , & mclength , structapp_cws ,
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
& structapp_cp ) ;
2021-10-30 22:00:31 +01:00
if ( error_number ) { /* Only errors return >= ZINT_ERROR */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
return error_number ;
2016-02-20 10:50:15 +00:00
}
/* This is where it all changes! */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( mclength + structapp_cp > 126 ) {
2017-07-27 16:01:53 +01:00
strcpy ( symbol - > errtxt , " 467: Input data too long " ) ;
2016-02-20 10:50:15 +00:00
return ZINT_ERROR_TOO_LONG ;
}
if ( symbol - > option_2 > 4 ) {
2017-07-27 16:01:53 +01:00
strcpy ( symbol - > errtxt , " 468: Specified width out of range " ) ;
2020-08-22 11:09:57 +01:00
if ( symbol - > warn_level = = WARN_FAIL_ALL ) {
return ZINT_ERROR_INVALID_OPTION ;
}
2021-08-05 16:34:45 +01:00
symbol - > option_2 = 0 ;
error_number = ZINT_WARN_INVALID_OPTION ;
2016-02-20 10:50:15 +00:00
}
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) {
2021-08-05 16:34:45 +01:00
printf ( " \n Encoded Data Stream (%d): \n " , mclength ) ;
2016-02-20 10:50:15 +00:00
for ( i = 0 ; i < mclength ; i + + ) {
2020-07-17 16:39:01 +01:00
printf ( " %3d " , chainemc [ i ] ) ;
2016-02-20 10:50:15 +00:00
}
2023-06-12 01:25:55 +01:00
fputc ( ' \n ' , stdout ) ;
2016-02-20 10:50:15 +00:00
}
/* Now figure out which variant of the symbol to use and load values accordingly */
variant = 0 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( ( symbol - > option_2 = = 1 ) & & ( mclength + structapp_cp > 20 ) ) {
2016-02-20 10:50:15 +00:00
/* the user specified 1 column but the data doesn't fit - go to automatic */
2017-07-27 16:01:53 +01:00
strcpy ( symbol - > errtxt , " 469: Specified symbol size too small for data " ) ;
2020-08-22 11:09:57 +01:00
if ( symbol - > warn_level = = WARN_FAIL_ALL ) {
return ZINT_ERROR_INVALID_OPTION ;
}
2021-08-05 16:34:45 +01:00
symbol - > option_2 = 0 ;
error_number = ZINT_WARN_INVALID_OPTION ;
2016-02-20 10:50:15 +00:00
}
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( ( symbol - > option_2 = = 2 ) & & ( mclength + structapp_cp > 37 ) ) {
2016-02-20 10:50:15 +00:00
/* the user specified 2 columns but the data doesn't fit - go to automatic */
2017-07-27 16:01:53 +01:00
strcpy ( symbol - > errtxt , " 470: Specified symbol size too small for data " ) ;
2020-08-22 11:09:57 +01:00
if ( symbol - > warn_level = = WARN_FAIL_ALL ) {
return ZINT_ERROR_INVALID_OPTION ;
}
2021-08-05 16:34:45 +01:00
symbol - > option_2 = 0 ;
error_number = ZINT_WARN_INVALID_OPTION ;
2016-02-20 10:50:15 +00:00
}
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( ( symbol - > option_2 = = 3 ) & & ( mclength + structapp_cp > 82 ) ) {
2016-02-20 10:50:15 +00:00
/* the user specified 3 columns but the data doesn't fit - go to automatic */
2017-07-27 16:01:53 +01:00
strcpy ( symbol - > errtxt , " 471: Specified symbol size too small for data " ) ;
2020-08-22 11:09:57 +01:00
if ( symbol - > warn_level = = WARN_FAIL_ALL ) {
return ZINT_ERROR_INVALID_OPTION ;
}
2021-08-05 16:34:45 +01:00
symbol - > option_2 = 0 ;
error_number = ZINT_WARN_INVALID_OPTION ;
2016-02-20 10:50:15 +00:00
}
if ( symbol - > option_2 = = 1 ) {
/* the user specified 1 column and the data does fit */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( mclength + structapp_cp < = 4 ) {
2016-02-20 10:50:15 +00:00
variant = 1 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 7 ) {
2020-12-23 10:57:24 +00:00
variant = 2 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 10 ) {
2020-12-23 10:57:24 +00:00
variant = 3 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 12 ) {
2020-12-23 10:57:24 +00:00
variant = 4 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 16 ) {
2020-12-23 10:57:24 +00:00
variant = 5 ;
} else {
variant = 6 ;
2016-02-20 10:50:15 +00:00
}
2020-12-23 10:57:24 +00:00
} else if ( symbol - > option_2 = = 2 ) {
2016-02-20 10:50:15 +00:00
/* the user specified 2 columns and the data does fit */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( mclength + structapp_cp < = 8 ) {
2016-02-20 10:50:15 +00:00
variant = 7 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 13 ) {
2020-12-23 10:57:24 +00:00
variant = 8 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 19 ) {
2020-12-23 10:57:24 +00:00
variant = 9 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 24 ) {
2020-12-23 10:57:24 +00:00
variant = 10 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 29 ) {
2020-12-23 10:57:24 +00:00
variant = 11 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 33 ) {
2020-12-23 10:57:24 +00:00
variant = 12 ;
} else {
variant = 13 ;
2016-02-20 10:50:15 +00:00
}
2020-12-23 10:57:24 +00:00
} else if ( symbol - > option_2 = = 3 ) {
2016-02-20 10:50:15 +00:00
/* the user specified 3 columns and the data does fit */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( mclength + structapp_cp < = 6 ) {
2016-02-20 10:50:15 +00:00
variant = 14 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 10 ) {
2020-12-23 10:57:24 +00:00
variant = 15 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 14 ) {
2020-12-23 10:57:24 +00:00
variant = 16 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 18 ) {
2020-12-23 10:57:24 +00:00
variant = 17 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 24 ) {
2020-12-23 10:57:24 +00:00
variant = 18 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 34 ) {
2020-12-23 10:57:24 +00:00
variant = 19 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 46 ) {
2020-12-23 10:57:24 +00:00
variant = 20 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 58 ) {
2020-12-23 10:57:24 +00:00
variant = 21 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 70 ) {
2020-12-23 10:57:24 +00:00
variant = 22 ;
} else {
variant = 23 ;
2016-02-20 10:50:15 +00:00
}
2020-12-23 10:57:24 +00:00
} else if ( symbol - > option_2 = = 4 ) {
2016-02-20 10:50:15 +00:00
/* the user specified 4 columns and the data does fit */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( mclength + structapp_cp < = 8 ) {
2016-02-20 10:50:15 +00:00
variant = 24 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 12 ) {
2020-12-23 10:57:24 +00:00
variant = 25 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 18 ) {
2020-12-23 10:57:24 +00:00
variant = 26 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 24 ) {
2020-12-23 10:57:24 +00:00
variant = 27 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 30 ) {
2020-12-23 10:57:24 +00:00
variant = 28 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 39 ) {
2020-12-23 10:57:24 +00:00
variant = 29 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 54 ) {
2020-12-23 10:57:24 +00:00
variant = 30 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 72 ) {
2020-12-23 10:57:24 +00:00
variant = 31 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 90 ) {
2020-12-23 10:57:24 +00:00
variant = 32 ;
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
} else if ( mclength + structapp_cp < = 108 ) {
2020-12-23 10:57:24 +00:00
variant = 33 ;
} else {
variant = 34 ;
2016-02-20 10:50:15 +00:00
}
2020-12-23 10:57:24 +00:00
} else {
2016-02-20 10:50:15 +00:00
/* Zint can choose automatically from all available variations */
for ( i = 27 ; i > = 0 ; i - - ) {
2021-10-30 22:00:31 +01:00
/* Note mclength + structapp_cp <= 126 and pdf_MicroAutosize[27] == 126 so variant will be set */
if ( pdf_MicroAutosize [ i ] > = mclength + structapp_cp ) {
variant = pdf_MicroAutosize [ i + 28 ] ;
2020-12-23 10:57:24 +00:00
} else {
break ;
2016-02-20 10:50:15 +00:00
}
}
}
2021-10-30 22:00:31 +01:00
assert ( variant > 0 ) ; /* Suppress clang-tidy clang-analyzer-core.uninitialized.Assign */
2016-02-20 10:50:15 +00:00
/* Now we have the variant we can load the data */
variant - - ;
2021-10-30 22:00:31 +01:00
symbol - > option_2 = pdf_MicroVariants [ variant ] ; /* columns */
symbol - > rows = pdf_MicroVariants [ variant + 34 ] ; /* rows */
k = pdf_MicroVariants [ variant + 68 ] ; /* number of EC CWs */
2016-02-20 10:50:15 +00:00
longueur = ( symbol - > option_2 * symbol - > rows ) - k ; /* number of non-EC CWs */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
i = longueur - ( mclength + structapp_cp ) ; /* amount of padding required */
2021-10-30 22:00:31 +01:00
offset = pdf_MicroVariants [ variant + 102 ] ; /* coefficient offset */
2016-02-20 10:50:15 +00:00
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) {
2023-06-12 01:25:55 +01:00
fputs ( " \n Choose symbol size: \n " , stdout ) ;
2021-08-05 16:34:45 +01:00
printf ( " %d columns x %d rows, variant %d \n " , symbol - > option_2 , symbol - > rows , variant + 1 ) ;
2016-02-20 10:50:15 +00:00
printf ( " %d data codewords (including %d pads), %d ecc codewords \n " , longueur , i , k ) ;
2023-06-12 01:25:55 +01:00
fputc ( ' \n ' , stdout ) ;
2016-02-20 10:50:15 +00:00
}
/* We add the padding */
while ( i > 0 ) {
2021-10-30 22:00:31 +01:00
chainemc [ mclength + + ] = 900 ;
2016-02-20 10:50:15 +00:00
i - - ;
}
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
/* We add the Structured Append Macro Control Block if any */
if ( structapp_cp ) {
for ( i = 0 ; i < structapp_cp ; i + + ) {
chainemc [ mclength + + ] = structapp_cws [ i ] ;
}
}
2016-02-20 10:50:15 +00:00
/* Reed-Solomon error correction */
longueur = mclength ;
for ( i = 0 ; i < longueur ; i + + ) {
total = ( chainemc [ i ] + mccorrection [ k - 1 ] ) % 929 ;
for ( j = k - 1 ; j > = 0 ; j - - ) {
if ( j = = 0 ) {
2021-10-30 22:00:31 +01:00
mccorrection [ j ] = ( 929 - ( total * pdf_Microcoeffs [ offset + j ] ) % 929 ) % 929 ;
2016-02-20 10:50:15 +00:00
} else {
2021-10-30 22:00:31 +01:00
mccorrection [ j ] = ( mccorrection [ j - 1 ] + 929 - ( total * pdf_Microcoeffs [ offset + j ] ) % 929 ) % 929 ;
2016-02-20 10:50:15 +00:00
}
}
}
for ( j = 0 ; j < k ; j + + ) {
if ( mccorrection [ j ] ! = 0 ) {
mccorrection [ j ] = 929 - mccorrection [ j ] ;
}
}
/* we add these codes to the string */
for ( i = k - 1 ; i > = 0 ; i - - ) {
2021-10-30 22:00:31 +01:00
chainemc [ mclength + + ] = mccorrection [ i ] ;
2016-02-20 10:50:15 +00:00
}
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) {
2021-08-05 16:34:45 +01:00
printf ( " Encoded Data Stream with ECC (%d): \n " , mclength ) ;
2016-02-20 10:50:15 +00:00
for ( i = 0 ; i < mclength ; i + + ) {
2020-07-17 16:39:01 +01:00
printf ( " %3d " , chainemc [ i ] ) ;
2016-02-20 10:50:15 +00:00
}
2023-06-12 01:25:55 +01:00
fputc ( ' \n ' , stdout ) ;
2016-02-20 10:50:15 +00:00
}
2020-07-17 16:39:01 +01:00
# ifdef ZINT_TEST
if ( symbol - > debug & ZINT_DEBUG_TEST ) {
debug_test_codeword_dump_int ( symbol , chainemc , mclength ) ;
}
# endif
2016-02-20 10:50:15 +00:00
/* Now get the RAP (Row Address Pattern) start values */
2022-11-06 22:25:19 +00:00
LeftRAP = pdf_RAPTable [ variant ] ;
CentreRAP = pdf_RAPTable [ variant + 34 ] ;
RightRAP = pdf_RAPTable [ variant + 68 ] ;
Cluster = pdf_RAPTable [ variant + 102 ] / 3 ;
2016-02-20 10:50:15 +00:00
/* That's all values loaded, get on with the encoding */
/* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */
2023-06-12 01:25:55 +01:00
if ( debug_print ) fputs ( " \n Internal row representation: \n " , stdout ) ;
2016-02-20 10:50:15 +00:00
for ( i = 0 ; i < symbol - > rows ; i + + ) {
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) printf ( " row %d: " , i ) ;
2020-12-23 10:57:24 +00:00
bp = 0 ;
2016-02-20 10:50:15 +00:00
offset = 929 * Cluster ;
2020-12-23 10:57:24 +00:00
k = i * symbol - > option_2 ;
2016-02-20 10:50:15 +00:00
/* Copy the data into codebarre */
2021-10-30 22:00:31 +01:00
bp = bin_append_posn ( pdf_rap_side [ LeftRAP - 1 ] , 10 , pattern , bp ) ;
2020-12-23 10:57:24 +00:00
bp = bin_append_posn ( pdf_bitpattern [ offset + chainemc [ k ] ] , 16 , pattern , bp ) ;
pattern [ bp + + ] = ' 0 ' ;
2016-02-20 10:50:15 +00:00
if ( symbol - > option_2 > = 2 ) {
2020-12-23 10:57:24 +00:00
if ( symbol - > option_2 = = 3 ) {
2021-10-30 22:00:31 +01:00
bp = bin_append_posn ( pdf_rap_centre [ CentreRAP - 1 ] , 10 , pattern , bp ) ;
2020-12-23 10:57:24 +00:00
}
bp = bin_append_posn ( pdf_bitpattern [ offset + chainemc [ k + 1 ] ] , 16 , pattern , bp ) ;
pattern [ bp + + ] = ' 0 ' ;
if ( symbol - > option_2 > = 3 ) {
if ( symbol - > option_2 = = 4 ) {
2021-10-30 22:00:31 +01:00
bp = bin_append_posn ( pdf_rap_centre [ CentreRAP - 1 ] , 10 , pattern , bp ) ;
2020-12-23 10:57:24 +00:00
}
bp = bin_append_posn ( pdf_bitpattern [ offset + chainemc [ k + 2 ] ] , 16 , pattern , bp ) ;
pattern [ bp + + ] = ' 0 ' ;
if ( symbol - > option_2 = = 4 ) {
bp = bin_append_posn ( pdf_bitpattern [ offset + chainemc [ k + 3 ] ] , 16 , pattern , bp ) ;
pattern [ bp + + ] = ' 0 ' ;
}
}
2016-02-20 10:50:15 +00:00
}
2021-10-30 22:00:31 +01:00
bp = bin_append_posn ( pdf_rap_side [ RightRAP - 1 ] , 10 , pattern , bp ) ;
2020-12-23 10:57:24 +00:00
pattern [ bp + + ] = ' 1 ' ; /* stop */
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-28 21:42:44 +01:00
if ( debug_print ) printf ( " %.*s \n " , bp , pattern ) ;
2016-02-20 10:50:15 +00:00
/* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
2020-12-23 10:57:24 +00:00
for ( loop = 0 ; loop < bp ; loop + + ) {
2016-02-20 10:50:15 +00:00
if ( pattern [ loop ] = = ' 1 ' ) {
set_module ( symbol , i , loop ) ;
}
}
/* Set up RAPs and Cluster for next row */
LeftRAP + + ;
CentreRAP + + ;
RightRAP + + ;
Cluster + + ;
if ( LeftRAP = = 53 ) {
LeftRAP = 1 ;
}
if ( CentreRAP = = 53 ) {
CentreRAP = 1 ;
}
if ( RightRAP = = 53 ) {
RightRAP = 1 ;
}
if ( Cluster = = 3 ) {
Cluster = 0 ;
}
}
2020-12-23 10:57:24 +00:00
symbol - > width = bp ;
2021-09-26 23:55:16 +01:00
2021-06-19 13:11:23 +01:00
/* ISO/IEC 24728:2006 Section 5.8.2 2X minimum row height */
if ( error_number ) {
( void ) set_height ( symbol , 2.0f , 0.0f , 0.0f , 1 /*no_errtxt*/ ) ;
} else {
error_number = set_height ( symbol , 2.0f , 0.0f , 0.0f , 0 /*no_errtxt*/ ) ;
2019-09-03 19:53:01 +01:00
}
2016-02-20 10:50:15 +00:00
2021-06-19 13:11:23 +01:00
return error_number ;
2009-10-06 19:03:00 +00:00
}
2021-10-30 22:00:31 +01:00
2022-08-18 22:25:09 +01:00
# undef T_ALPHA
# undef T_LOWER
# undef T_MIXED
# undef T_PUNCT
2022-11-06 22:25:19 +00:00
# undef T_ALWMX
# undef T_MXPNC
2022-08-18 22:25:09 +01:00
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA
RMQR: fix ECI encoding (wrong bit length for indicator)
MICROQR: check versions M1 and M2 for allowed characters so as to give
better error messages
DOTCODE: some small optimizations
common.c: add is_chr(), segs_length(), segs_cpy()
CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add
namespace prefixes to static funcs/data
includes: use Z_ prefix, unuse double underscore prefixes (guard defines)
manual.txt: compress some tables using double/treble column sets
2022-05-09 19:50:50 +01:00
/* vim: set ts=4 sw=4 et : */