Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 #ifndef LEPTONICA_READBARCODE_H 00017 #define LEPTONICA_READBARCODE_H 00018 00019 /* ----------------------------------------------------------------- * 00020 * Flags for method of extracting barcode widths * 00021 * ----------------------------------------------------------------- */ 00022 enum { 00023 L_USE_WIDTHS = 1, /* use histogram of barcode widths */ 00024 L_USE_WINDOWS = 2 /* find best window for decoding transitions */ 00025 }; 00026 00027 /* ----------------------------------------------------------------- * 00028 * Flags for barcode formats * 00029 * These are used both to identify a barcode format and to identify * 00030 * the decoding method to use on a barcode. * 00031 * ----------------------------------------------------------------- */ 00032 enum { 00033 L_BF_UNKNOWN = 0, /* unknown format */ 00034 L_BF_ANY = 1, /* try decoding with all known formats */ 00035 L_BF_CODE128 = 2, /* decode with Code128 format */ 00036 L_BF_EAN8 = 3, /* decode with EAN8 format */ 00037 L_BF_EAN13 = 4, /* decode with EAN13 format */ 00038 L_BF_CODE2OF5 = 5, /* decode with Code 2 of 5 format */ 00039 L_BF_CODEI2OF5 = 6, /* decode with Interleaved 2 of 5 format */ 00040 L_BF_CODE39 = 7, /* decode with Code39 format */ 00041 L_BF_CODE93 = 8, /* decode with Code93 format */ 00042 L_BF_CODABAR = 9, /* decode with Code93 format */ 00043 L_BF_UPCA = 10 /* decode with UPC A format */ 00044 }; 00045 00046 /* ----------------------------------------------------------------- * 00047 * Currently supported formats * 00048 * Update these arrays as new formats are added. * 00049 * ----------------------------------------------------------------- */ 00050 static const l_int32 SupportedBarcodeFormat[] = { 00051 L_BF_CODE2OF5, 00052 L_BF_CODEI2OF5, 00053 L_BF_CODE93, 00054 L_BF_CODE39, 00055 L_BF_CODABAR, 00056 L_BF_UPCA, 00057 L_BF_EAN13 00058 }; 00059 static const char *SupportedBarcodeFormatName[] = { 00060 "Code2of5", 00061 "CodeI2of5", 00062 "Code93", 00063 "Code39", 00064 "Codabar", 00065 "Upca", 00066 "Ean13" 00067 }; 00068 static const l_int32 NumSupportedBarcodeFormats = 7; 00069 00070 00071 /* ----------------------------------------------------------------- * 00072 * Code 2 of 5 symbology * 00073 * ----------------------------------------------------------------- */ 00074 static const char *Code2of5[] = { 00075 "111121211", "211111112", "112111112", "212111111", /* 0 - 3 */ 00076 "111121112", "211121111", "112121111", "111111212", /* 4 - 7 */ 00077 "211111211", "112111211", /* 8 - 9 */ 00078 "21211", "21112" /* Start, Stop */ 00079 }; 00080 00081 static const l_int32 C25_START = 10; 00082 static const l_int32 C25_STOP = 11; 00083 00084 00085 /* ----------------------------------------------------------------- * 00086 * Code Interleaved 2 of 5 symbology * 00087 * ----------------------------------------------------------------- */ 00088 static const char *CodeI2of5[] = { 00089 "11221", "21112", "12112", "22111", "11212", /* 0 - 4 */ 00090 "21211", "12211", "11122", "21121", "12121", /* 5 - 9 */ 00091 "1111", "211" /* start, stop */ 00092 }; 00093 00094 static const l_int32 CI25_START = 10; 00095 static const l_int32 CI25_STOP = 11; 00096 00097 00098 /* ----------------------------------------------------------------- * 00099 * Code 93 symbology * 00100 * ----------------------------------------------------------------- */ 00101 static const char *Code93[] = { 00102 "131112", "111213", "111312", "111411", "121113", /* 0: 0 - 4 */ 00103 "121212", "121311", "111114", "131211", "141111", /* 5: 5 - 9 */ 00104 "211113", "211212", "211311", "221112", "221211", /* 10: A - E */ 00105 "231111", "112113", "112212", "112311", "122112", /* 15: F - J */ 00106 "132111", "111123", "111222", "111321", "121122", /* 20: K - O */ 00107 "131121", "212112", "212211", "211122", "211221", /* 25: P - T */ 00108 "221121", "222111", "112122", "112221", "122121", /* 30: U - Y */ 00109 "123111", "121131", "311112", "311211", "321111", /* 35: Z,-,.,SP,$ */ 00110 "112131", "113121", "211131", "131221", "312111", /* 40: /,+,%,($),(%) */ 00111 "311121", "122211", "111141" /* 45: (/),(+), Start */ 00112 }; 00113 00114 /* Use "[]{}#" to represent special codes 43-47 */ 00115 static const char Code93Val[] = 00116 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%[]{}#"; 00117 00118 static const l_int32 C93_START = 47; 00119 static const l_int32 C93_STOP = 47; 00120 00121 00122 /* ----------------------------------------------------------------- * 00123 * Code 39 symbology * 00124 * ----------------------------------------------------------------- */ 00125 static const char *Code39[] = { 00126 "111221211", "211211112", "112211112", "212211111", /* 0: 0 - 3 */ 00127 "111221112", "211221111", "112221111", "111211212", /* 4: 4 - 7 */ 00128 "211211211", "112211211", "211112112", "112112112", /* 8: 8 - B */ 00129 "212112111", "111122112", "211122111", "112122111", /* 12: C - F */ 00130 "111112212", "211112211", "112112211", "111122211", /* 16: G - J */ 00131 "211111122", "112111122", "212111121", "111121122", /* 20: K - N */ 00132 "211121121", "112121121", "111111222", "211111221", /* 24: O - R */ 00133 "112111221", "111121221", "221111112", "122111112", /* 28: S - V */ 00134 "222111111", "121121112", "221121111", "122121111", /* 32: W - Z */ 00135 "121111212", "221111211", "122111211", "121212111", /* 36: -,.,SP,$ */ 00136 "121211121", "121112121", "111212121", "121121211" /* 40: /,+,%,* */ 00137 }; 00138 00139 /* Use "*" to represent the Start and Stop codes (43) */ 00140 static const char Code39Val[] = 00141 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; 00142 00143 static const l_int32 C39_START = 43; 00144 static const l_int32 C39_STOP = 43; 00145 00146 00147 /* ----------------------------------------------------------------- * 00148 * Codabar symbology * 00149 * ----------------------------------------------------------------- */ 00150 static const char *Codabar[] = { 00151 "1111122", "1111221", "1112112", "2211111", "1121121", /* 0: 0 - 4 */ 00152 "2111121", "1211112", "1211211", "1221111", "2112111", /* 5: 5 - 9 */ 00153 "1112211", "1122111", "2111212", "2121112", "2121211", /* 10: -,$,:,/,. */ 00154 "1121212", "1122121", "1212112", "1112122", "1112221" /* 15: +,A,B,C,D */ 00155 }; 00156 00157 /* Ascii representations for codes 16-19: (A or T), (B or N), (C or *), 00158 * (D or E). These are used in pairs for the Start and Stop codes. */ 00159 static const char CodabarVal[] = "0123456789-$:/.+ABCD"; 00160 00161 00162 /* ----------------------------------------------------------------- * 00163 * UPC-A symbology * 00164 * ----------------------------------------------------------------- */ 00165 static const char *Upca[] = { 00166 "3211", "2221", "2122", "1411", "1132", /* 0: 0 - 4 */ 00167 "1231", "1114", "1312", "1213", "3112", /* 5: 5 - 9 */ 00168 "111", "111", "11111" /* 10: Start, Stop, Mid */ 00169 }; 00170 00171 static const l_int32 UPCA_START = 10; 00172 static const l_int32 UPCA_STOP = 11; 00173 static const l_int32 UPCA_MID = 12; 00174 00175 00176 /* ----------------------------------------------------------------- * 00177 * Code128 symbology * 00178 * ----------------------------------------------------------------- */ 00179 static const char *Code128[] = { 00180 "212222", "222122", "222221", "121223", "121322", /* 0 - 4 */ 00181 "131222", "122213", "122312", "132212", "221213", /* 5 - 9 */ 00182 "221312", "231212", "112232", "122132", "122231", /* 10 - 14 */ 00183 "113222", "123122", "123221", "223211", "221132", /* 15 - 19 */ 00184 "221231", "213212", "223112", "312131", "311222", /* 20 - 24 */ 00185 "321122", "321221", "312212", "322112", "322211", /* 25 - 29 */ 00186 "212123", "212321", "232121", "111323", "131123", /* 30 - 34 */ 00187 "131321", "112313", "132113", "132311", "211313", /* 35 - 39 */ 00188 "231113", "231311", "112133", "112331", "132131", /* 40 - 44 */ 00189 "113123", "113321", "133121", "313121", "211331", /* 45 - 49 */ 00190 "231131", "213113", "213311", "213131", "311123", /* 50 - 54 */ 00191 "311321", "331121", "312113", "312311", "332111", /* 55 - 59 */ 00192 "314111", "221411", "431111", "111224", "111422", /* 60 - 64 */ 00193 "121124", "121421", "141122", "141221", "112214", /* 65 - 69 */ 00194 "112412", "122114", "122411", "142112", "142211", /* 70 - 74 */ 00195 "241211", "221114", "413111", "241112", "134111", /* 75 - 79 */ 00196 "111242", "121142", "121241", "114212", "124112", /* 80 - 84 */ 00197 "124211", "411212", "421112", "421211", "212141", /* 85 - 89 */ 00198 "214121", "412121", "111143", "111341", "131141", /* 90 - 94 */ 00199 "114113", "114311", "411113", "411311", "113141", /* 95 - 99 */ 00200 "114131", "311141", "411131", "211412", "211214", /* 100 - 104 */ 00201 "211232", "2331112" /* 105 - 106 */ 00202 }; 00203 00204 static const l_int32 C128_FUN_3 = 96; /* in A or B only; in C it is 96 */ 00205 static const l_int32 C128_FUNC_2 = 97; /* in A or B only; in C it is 97 */ 00206 static const l_int32 C128_SHIFT = 98; /* in A or B only; in C it is 98 */ 00207 static const l_int32 C128_GOTO_C = 99; /* in A or B only; in C it is 99 */ 00208 static const l_int32 C128_GOTO_B = 100; 00209 static const l_int32 C128_GOTO_A = 101; 00210 static const l_int32 C128_FUNC_1 = 102; 00211 static const l_int32 C128_START_A = 103; 00212 static const l_int32 C128_START_B = 104; 00213 static const l_int32 C128_START_C = 105; 00214 static const l_int32 C128_STOP = 106; 00215 /* code 128 symbols are 11 units */ 00216 static const l_int32 C128_SYMBOL_WIDTH = 11; 00217 00218 00219 00220 #endif /* LEPTONICA_READBARCODE_H */