readbarcode.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions
  6. - are met:
  7. - 1. Redistributions of source code must retain the above copyright
  8. - notice, this list of conditions and the following disclaimer.
  9. - 2. Redistributions in binary form must reproduce the above
  10. - copyright notice, this list of conditions and the following
  11. - disclaimer in the documentation and/or other materials
  12. - provided with the distribution.
  13. -
  14. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  18. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *====================================================================*/
  26. #ifndef LEPTONICA_READBARCODE_H
  27. #define LEPTONICA_READBARCODE_H
  28. /* ----------------------------------------------------------------- *
  29. * Flags for method of extracting barcode widths *
  30. * ----------------------------------------------------------------- */
  31. enum {
  32. L_USE_WIDTHS = 1, /* use histogram of barcode widths */
  33. L_USE_WINDOWS = 2 /* find best window for decoding transitions */
  34. };
  35. /* ----------------------------------------------------------------- *
  36. * Flags for barcode formats *
  37. * These are used both to identify a barcode format and to identify *
  38. * the decoding method to use on a barcode. *
  39. * ----------------------------------------------------------------- */
  40. enum {
  41. L_BF_UNKNOWN = 0, /* unknown format */
  42. L_BF_ANY = 1, /* try decoding with all known formats */
  43. L_BF_CODE128 = 2, /* decode with Code128 format */
  44. L_BF_EAN8 = 3, /* decode with EAN8 format */
  45. L_BF_EAN13 = 4, /* decode with EAN13 format */
  46. L_BF_CODE2OF5 = 5, /* decode with Code 2 of 5 format */
  47. L_BF_CODEI2OF5 = 6, /* decode with Interleaved 2 of 5 format */
  48. L_BF_CODE39 = 7, /* decode with Code39 format */
  49. L_BF_CODE93 = 8, /* decode with Code93 format */
  50. L_BF_CODABAR = 9, /* decode with Code93 format */
  51. L_BF_UPCA = 10 /* decode with UPC A format */
  52. };
  53. /* ----------------------------------------------------------------- *
  54. * Currently supported formats *
  55. * Update these arrays as new formats are added. *
  56. * ----------------------------------------------------------------- */
  57. static const l_int32 SupportedBarcodeFormat[] = {
  58. L_BF_CODE2OF5,
  59. L_BF_CODEI2OF5,
  60. L_BF_CODE93,
  61. L_BF_CODE39,
  62. L_BF_CODABAR,
  63. L_BF_UPCA,
  64. L_BF_EAN13
  65. };
  66. static const char *SupportedBarcodeFormatName[] = {
  67. "Code2of5",
  68. "CodeI2of5",
  69. "Code93",
  70. "Code39",
  71. "Codabar",
  72. "Upca",
  73. "Ean13"
  74. };
  75. static const l_int32 NumSupportedBarcodeFormats = 7;
  76. /* ----------------------------------------------------------------- *
  77. * Code 2 of 5 symbology *
  78. * ----------------------------------------------------------------- */
  79. static const char *Code2of5[] = {
  80. "111121211", "211111112", "112111112", "212111111", /* 0 - 3 */
  81. "111121112", "211121111", "112121111", "111111212", /* 4 - 7 */
  82. "211111211", "112111211", /* 8 - 9 */
  83. "21211", "21112" /* Start, Stop */
  84. };
  85. static const l_int32 C25_START = 10;
  86. static const l_int32 C25_STOP = 11;
  87. /* ----------------------------------------------------------------- *
  88. * Code Interleaved 2 of 5 symbology *
  89. * ----------------------------------------------------------------- */
  90. static const char *CodeI2of5[] = {
  91. "11221", "21112", "12112", "22111", "11212", /* 0 - 4 */
  92. "21211", "12211", "11122", "21121", "12121", /* 5 - 9 */
  93. "1111", "211" /* start, stop */
  94. };
  95. static const l_int32 CI25_START = 10;
  96. static const l_int32 CI25_STOP = 11;
  97. /* ----------------------------------------------------------------- *
  98. * Code 93 symbology *
  99. * ----------------------------------------------------------------- */
  100. static const char *Code93[] = {
  101. "131112", "111213", "111312", "111411", "121113", /* 0: 0 - 4 */
  102. "121212", "121311", "111114", "131211", "141111", /* 5: 5 - 9 */
  103. "211113", "211212", "211311", "221112", "221211", /* 10: A - E */
  104. "231111", "112113", "112212", "112311", "122112", /* 15: F - J */
  105. "132111", "111123", "111222", "111321", "121122", /* 20: K - O */
  106. "131121", "212112", "212211", "211122", "211221", /* 25: P - T */
  107. "221121", "222111", "112122", "112221", "122121", /* 30: U - Y */
  108. "123111", "121131", "311112", "311211", "321111", /* 35: Z,-,.,SP,$ */
  109. "112131", "113121", "211131", "131221", "312111", /* 40: /,+,%,($),(%) */
  110. "311121", "122211", "111141" /* 45: (/),(+), Start */
  111. };
  112. /* Use "[]{}#" to represent special codes 43-47 */
  113. static const char Code93Val[] =
  114. "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%[]{}#";
  115. static const l_int32 C93_START = 47;
  116. static const l_int32 C93_STOP = 47;
  117. /* ----------------------------------------------------------------- *
  118. * Code 39 symbology *
  119. * ----------------------------------------------------------------- */
  120. static const char *Code39[] = {
  121. "111221211", "211211112", "112211112", "212211111", /* 0: 0 - 3 */
  122. "111221112", "211221111", "112221111", "111211212", /* 4: 4 - 7 */
  123. "211211211", "112211211", "211112112", "112112112", /* 8: 8 - B */
  124. "212112111", "111122112", "211122111", "112122111", /* 12: C - F */
  125. "111112212", "211112211", "112112211", "111122211", /* 16: G - J */
  126. "211111122", "112111122", "212111121", "111121122", /* 20: K - N */
  127. "211121121", "112121121", "111111222", "211111221", /* 24: O - R */
  128. "112111221", "111121221", "221111112", "122111112", /* 28: S - V */
  129. "222111111", "121121112", "221121111", "122121111", /* 32: W - Z */
  130. "121111212", "221111211", "122111211", "121212111", /* 36: -,.,SP,$ */
  131. "121211121", "121112121", "111212121", "121121211" /* 40: /,+,%,* */
  132. };
  133. /* Use "*" to represent the Start and Stop codes (43) */
  134. static const char Code39Val[] =
  135. "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";
  136. static const l_int32 C39_START = 43;
  137. static const l_int32 C39_STOP = 43;
  138. /* ----------------------------------------------------------------- *
  139. * Codabar symbology *
  140. * ----------------------------------------------------------------- */
  141. static const char *Codabar[] = {
  142. "1111122", "1111221", "1112112", "2211111", "1121121", /* 0: 0 - 4 */
  143. "2111121", "1211112", "1211211", "1221111", "2112111", /* 5: 5 - 9 */
  144. "1112211", "1122111", "2111212", "2121112", "2121211", /* 10: -,$,:,/,. */
  145. "1121212", "1122121", "1212112", "1112122", "1112221" /* 15: +,A,B,C,D */
  146. };
  147. /* Ascii representations for codes 16-19: (A or T), (B or N), (C or *),
  148. * (D or E). These are used in pairs for the Start and Stop codes. */
  149. static const char CodabarVal[] = "0123456789-$:/.+ABCD";
  150. /* ----------------------------------------------------------------- *
  151. * UPC-A symbology *
  152. * ----------------------------------------------------------------- */
  153. static const char *Upca[] = {
  154. "3211", "2221", "2122", "1411", "1132", /* 0: 0 - 4 */
  155. "1231", "1114", "1312", "1213", "3112", /* 5: 5 - 9 */
  156. "111", "111", "11111" /* 10: Start, Stop, Mid */
  157. };
  158. static const l_int32 UPCA_START = 10;
  159. static const l_int32 UPCA_STOP = 11;
  160. static const l_int32 UPCA_MID = 12;
  161. /* ----------------------------------------------------------------- *
  162. * Code128 symbology *
  163. * ----------------------------------------------------------------- */
  164. static const char *Code128[] = {
  165. "212222", "222122", "222221", "121223", "121322", /* 0 - 4 */
  166. "131222", "122213", "122312", "132212", "221213", /* 5 - 9 */
  167. "221312", "231212", "112232", "122132", "122231", /* 10 - 14 */
  168. "113222", "123122", "123221", "223211", "221132", /* 15 - 19 */
  169. "221231", "213212", "223112", "312131", "311222", /* 20 - 24 */
  170. "321122", "321221", "312212", "322112", "322211", /* 25 - 29 */
  171. "212123", "212321", "232121", "111323", "131123", /* 30 - 34 */
  172. "131321", "112313", "132113", "132311", "211313", /* 35 - 39 */
  173. "231113", "231311", "112133", "112331", "132131", /* 40 - 44 */
  174. "113123", "113321", "133121", "313121", "211331", /* 45 - 49 */
  175. "231131", "213113", "213311", "213131", "311123", /* 50 - 54 */
  176. "311321", "331121", "312113", "312311", "332111", /* 55 - 59 */
  177. "314111", "221411", "431111", "111224", "111422", /* 60 - 64 */
  178. "121124", "121421", "141122", "141221", "112214", /* 65 - 69 */
  179. "112412", "122114", "122411", "142112", "142211", /* 70 - 74 */
  180. "241211", "221114", "413111", "241112", "134111", /* 75 - 79 */
  181. "111242", "121142", "121241", "114212", "124112", /* 80 - 84 */
  182. "124211", "411212", "421112", "421211", "212141", /* 85 - 89 */
  183. "214121", "412121", "111143", "111341", "131141", /* 90 - 94 */
  184. "114113", "114311", "411113", "411311", "113141", /* 95 - 99 */
  185. "114131", "311141", "411131", "211412", "211214", /* 100 - 104 */
  186. "211232", "2331112" /* 105 - 106 */
  187. };
  188. static const l_int32 C128_FUN_3 = 96; /* in A or B only; in C it is 96 */
  189. static const l_int32 C128_FUNC_2 = 97; /* in A or B only; in C it is 97 */
  190. static const l_int32 C128_SHIFT = 98; /* in A or B only; in C it is 98 */
  191. static const l_int32 C128_GOTO_C = 99; /* in A or B only; in C it is 99 */
  192. static const l_int32 C128_GOTO_B = 100;
  193. static const l_int32 C128_GOTO_A = 101;
  194. static const l_int32 C128_FUNC_1 = 102;
  195. static const l_int32 C128_START_A = 103;
  196. static const l_int32 C128_START_B = 104;
  197. static const l_int32 C128_START_C = 105;
  198. static const l_int32 C128_STOP = 106;
  199. /* code 128 symbols are 11 units */
  200. static const l_int32 C128_SYMBOL_WIDTH = 11;
  201. #endif /* LEPTONICA_READBARCODE_H */