1 /*====================================================================*
2  -  Copyright (C) 2001 Leptonica.  All rights reserved.
3  -  This software is distributed in the hope that it will be
4  -  useful, but with NO WARRANTY OF ANY KIND.
5  -  No author or distributor accepts responsibility to anyone for the
6  -  consequences of using this software, or for whether it serves any
7  -  particular purpose or works at all, unless he or she says so in
8  -  writing.  Everyone is granted permission to copy, modify and
9  -  redistribute this source code, for commercial or non-commercial
10  -  purposes, with the following restrictions: (1) the origin of this
11  -  source code must not be misrepresented; (2) modified versions must
12  -  be plainly marked as such; and (3) this notice may not be removed
13  -  or altered from any source or modified source distribution.
14  *====================================================================*/
15 
16 #ifndef  LEPTONICA_READBARCODE_H
17 #define  LEPTONICA_READBARCODE_H
18 
19     /* ----------------------------------------------------------------- *
20      *            Flags for method of extracting barcode widths          *
21      * ----------------------------------------------------------------- */
22 enum {
23     L_USE_WIDTHS = 1,           /* use histogram of barcode widths           */
24     L_USE_WINDOWS = 2           /* find best window for decoding transitions */
25 };
26 
27     /* ----------------------------------------------------------------- *
28      *                     Flags for barcode formats                     *
29      * These are used both to identify a barcode format and to identify  *
30      * the decoding method to use on a barcode.                          *
31      * ----------------------------------------------------------------- */
32 enum {
33     L_BF_UNKNOWN = 0,           /* unknown format                            */
34     L_BF_ANY = 1,               /* try decoding with all known formats       */
35     L_BF_CODE128 = 2,           /* decode with Code128 format                */
36     L_BF_EAN8 = 3,              /* decode with EAN8 format                   */
37     L_BF_EAN13 = 4,             /* decode with EAN13 format                  */
38     L_BF_CODE2OF5 = 5,          /* decode with Code 2 of 5 format            */
39     L_BF_CODEI2OF5 = 6,         /* decode with Interleaved 2 of 5 format     */
40     L_BF_CODE39 = 7,            /* decode with Code39 format                 */
41     L_BF_CODE93 = 8,            /* decode with Code93 format                 */
42     L_BF_CODABAR = 9,           /* decode with Code93 format                 */
43     L_BF_UPCA = 10              /* decode with UPC A format                  */
44 };
45 
46     /* ----------------------------------------------------------------- *
47      *                  Currently supported formats                      *
48      *            Update these arrays as new formats are added.          *
49      * ----------------------------------------------------------------- */
50 static const l_int32  SupportedBarcodeFormat[] = {
51     L_BF_CODE2OF5,
52     L_BF_CODEI2OF5,
53     L_BF_CODE93,
54     L_BF_CODE39,
55     L_BF_CODABAR,
56     L_BF_UPCA,
57     L_BF_EAN13
58 };
59 static const char  *SupportedBarcodeFormatName[] = {
60     "Code2of5",
61     "CodeI2of5",
62     "Code93",
63     "Code39",
64     "Codabar",
65     "Upca",
66     "Ean13"
67 };
68 static const l_int32  NumSupportedBarcodeFormats = 7;
69 
70 
71     /* ----------------------------------------------------------------- *
72      *                       Code 2 of 5 symbology                       *
73      * ----------------------------------------------------------------- */
74 static const char *Code2of5[] = {
75     "111121211", "211111112", "112111112", "212111111",   /* 0 - 3 */
76     "111121112", "211121111", "112121111", "111111212",   /* 4 - 7 */
77     "211111211", "112111211",                             /* 8 - 9 */
78     "21211", "21112"                                      /* Start, Stop */
79 };
80 
81 static const l_int32  C25_START = 10;
82 static const l_int32  C25_STOP =  11;
83 
84 
85     /* ----------------------------------------------------------------- *
86      *                Code Interleaved 2 of 5 symbology                  *
87      * ----------------------------------------------------------------- */
88 static const char *CodeI2of5[] = {
89     "11221", "21112", "12112", "22111", "11212",    /*  0 - 4 */
90     "21211", "12211", "11122", "21121", "12121",    /*  5 - 9 */
91     "1111", "211"                                   /*  start, stop */
92 };
93 
94 static const l_int32  CI25_START = 10;
95 static const l_int32  CI25_STOP =  11;
96 
97 
98     /* ----------------------------------------------------------------- *
99      *                         Code 93 symbology                         *
100      * ----------------------------------------------------------------- */
101 static const char *Code93[] = {
102     "131112", "111213", "111312", "111411", "121113", /* 0: 0 - 4 */
103     "121212", "121311", "111114", "131211", "141111", /* 5: 5 - 9 */
104     "211113", "211212", "211311", "221112", "221211", /* 10: A - E */
105     "231111", "112113", "112212", "112311", "122112", /* 15: F - J */
106     "132111", "111123", "111222", "111321", "121122", /* 20: K - O */
107     "131121", "212112", "212211", "211122", "211221", /* 25: P - T */
108     "221121", "222111", "112122", "112221", "122121", /* 30: U - Y */
109     "123111", "121131", "311112", "311211", "321111", /* 35: Z,-,.,SP,$ */
110     "112131", "113121", "211131", "131221", "312111", /* 40: /,+,%,($),(%) */
111     "311121", "122211", "111141"                      /* 45: (/),(+), Start */
112 };
113 
114     /* Use "[]{}#" to represent special codes 43-47 */
115 static const char Code93Val[] =
116     "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%[]{}#";
117 
118 static const l_int32  C93_START = 47;
119 static const l_int32  C93_STOP =  47;
120 
121 
122     /* ----------------------------------------------------------------- *
123      *                         Code 39 symbology                         *
124      * ----------------------------------------------------------------- */
125 static const char *Code39[] = {
126     "111221211", "211211112", "112211112", "212211111",  /* 0: 0 - 3      */
127     "111221112", "211221111", "112221111", "111211212",  /* 4: 4 - 7      */
128     "211211211", "112211211", "211112112", "112112112",  /* 8: 8 - B      */
129     "212112111", "111122112", "211122111", "112122111",  /* 12: C - F     */
130     "111112212", "211112211", "112112211", "111122211",  /* 16: G - J     */
131     "211111122", "112111122", "212111121", "111121122",  /* 20: K - N     */
132     "211121121", "112121121", "111111222", "211111221",  /* 24: O - R     */
133     "112111221", "111121221", "221111112", "122111112",  /* 28: S - V     */
134     "222111111", "121121112", "221121111", "122121111",  /* 32: W - Z     */
135     "121111212", "221111211", "122111211", "121212111",  /* 36: -,.,SP,$  */
136     "121211121", "121112121", "111212121", "121121211"   /* 40: /,+,%,*   */
137 };
138 
139     /* Use "*" to represent the Start and Stop codes (43) */
140 static const char Code39Val[] =
141     "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";
142 
143 static const l_int32  C39_START = 43;
144 static const l_int32  C39_STOP =  43;
145 
146 
147     /* ----------------------------------------------------------------- *
148      *                         Codabar symbology                         *
149      * ----------------------------------------------------------------- */
150 static const char *Codabar[] = {
151     "1111122", "1111221", "1112112", "2211111", "1121121", /* 0: 0 - 4      */
152     "2111121", "1211112", "1211211", "1221111", "2112111", /* 5: 5 - 9      */
153     "1112211", "1122111", "2111212", "2121112", "2121211", /* 10: -,$,:,/,. */
154     "1121212", "1122121", "1212112", "1112122", "1112221"  /* 15: +,A,B,C,D */
155 };
156 
157     /* Ascii representations for codes 16-19: (A or T), (B or N), (C or *),
158      * (D or E).  These are used in pairs for the Start and Stop codes. */
159 static const char CodabarVal[] = "0123456789-$:/.+ABCD";
160 
161 
162     /* ----------------------------------------------------------------- *
163      *                          UPC-A symbology                          *
164      * ----------------------------------------------------------------- */
165 static const char *Upca[] = {
166     "3211", "2221", "2122", "1411", "1132",  /* 0: 0 - 4              */
167     "1231", "1114", "1312", "1213", "3112",  /* 5: 5 - 9              */
168     "111", "111", "11111"                    /* 10: Start, Stop, Mid  */
169 };
170 
171 static const l_int32  UPCA_START = 10;
172 static const l_int32  UPCA_STOP =  11;
173 static const l_int32  UPCA_MID =   12;
174 
175 
176     /* ----------------------------------------------------------------- *
177      *                         Code128 symbology                         *
178      * ----------------------------------------------------------------- */
179 static const char *Code128[] = {
180     "212222", "222122", "222221", "121223", "121322",    /*  0 - 4 */
181     "131222", "122213", "122312", "132212", "221213",    /*  5 - 9 */
182     "221312", "231212", "112232", "122132", "122231",    /* 10 - 14 */
183     "113222", "123122", "123221", "223211", "221132",    /* 15 - 19 */
184     "221231", "213212", "223112", "312131", "311222",    /* 20 - 24 */
185     "321122", "321221", "312212", "322112", "322211",    /* 25 - 29 */
186     "212123", "212321", "232121", "111323", "131123",    /* 30 - 34 */
187     "131321", "112313", "132113", "132311", "211313",    /* 35 - 39 */
188     "231113", "231311", "112133", "112331", "132131",    /* 40 - 44 */
189     "113123", "113321", "133121", "313121", "211331",    /* 45 - 49 */
190     "231131", "213113", "213311", "213131", "311123",    /* 50 - 54 */
191     "311321", "331121", "312113", "312311", "332111",    /* 55 - 59 */
192     "314111", "221411", "431111", "111224", "111422",    /* 60 - 64 */
193     "121124", "121421", "141122", "141221", "112214",    /* 65 - 69 */
194     "112412", "122114", "122411", "142112", "142211",    /* 70 - 74 */
195     "241211", "221114", "413111", "241112", "134111",    /* 75 - 79 */
196     "111242", "121142", "121241", "114212", "124112",    /* 80 - 84 */
197     "124211", "411212", "421112", "421211", "212141",    /* 85 - 89 */
198     "214121", "412121", "111143", "111341", "131141",    /* 90 - 94 */
199     "114113", "114311", "411113", "411311", "113141",    /* 95 - 99 */
200     "114131", "311141", "411131", "211412", "211214",    /* 100 - 104 */
201     "211232", "2331112"                                  /* 105 - 106 */
202 };
203 
204 static const l_int32  C128_FUN_3 =    96;   /* in A or B only; in C it is 96 */
205 static const l_int32  C128_FUNC_2 =   97;   /* in A or B only; in C it is 97 */
206 static const l_int32  C128_SHIFT =    98;   /* in A or B only; in C it is 98 */
207 static const l_int32  C128_GOTO_C =   99;   /* in A or B only; in C it is 99 */
208 static const l_int32  C128_GOTO_B =  100;
209 static const l_int32  C128_GOTO_A =  101;
210 static const l_int32  C128_FUNC_1 =  102;
211 static const l_int32  C128_START_A = 103;
212 static const l_int32  C128_START_B = 104;
213 static const l_int32  C128_START_C = 105;
214 static const l_int32  C128_STOP =    106;
215     /* code 128 symbols are 11 units */
216 static const l_int32  C128_SYMBOL_WIDTH = 11;
217 
218 
219 
220 #endif  /* LEPTONICA_READBARCODE_H */
221