zxing_cpp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.rdoc +6 -0
  5. data/Gemfile +3 -0
  6. data/Manifest.txt +331 -0
  7. data/README.rdoc +138 -0
  8. data/Rakefile +28 -0
  9. data/bin/zxd +87 -0
  10. data/bin/zxe +53 -0
  11. data/ext/zxing/extconf.rb +27 -0
  12. data/ext/zxing/zxing-cpp/.gitignore +4 -0
  13. data/ext/zxing/zxing-cpp/AUTHORS +115 -0
  14. data/ext/zxing/zxing-cpp/CMakeLists.txt +84 -0
  15. data/ext/zxing/zxing-cpp/COPYING +201 -0
  16. data/ext/zxing/zxing-cpp/NOTICE +65 -0
  17. data/ext/zxing/zxing-cpp/README.md +50 -0
  18. data/ext/zxing/zxing-cpp/cli/src/ImageReaderSource.cpp +112 -0
  19. data/ext/zxing/zxing-cpp/cli/src/ImageReaderSource.h +40 -0
  20. data/ext/zxing/zxing-cpp/cli/src/jpgd.cpp +3174 -0
  21. data/ext/zxing/zxing-cpp/cli/src/jpgd.h +319 -0
  22. data/ext/zxing/zxing-cpp/cli/src/lodepng.cpp +6261 -0
  23. data/ext/zxing/zxing-cpp/cli/src/lodepng.h +1695 -0
  24. data/ext/zxing/zxing-cpp/cli/src/main.cpp +297 -0
  25. data/ext/zxing/zxing-cpp/cmake/FindCPPUNIT.cmake +54 -0
  26. data/ext/zxing/zxing-cpp/cmake/FindIconv.cmake +57 -0
  27. data/ext/zxing/zxing-cpp/core/src/bigint/.gitignore +6 -0
  28. data/ext/zxing/zxing-cpp/core/src/bigint/BigInteger.cc +405 -0
  29. data/ext/zxing/zxing-cpp/core/src/bigint/BigInteger.hh +215 -0
  30. data/ext/zxing/zxing-cpp/core/src/bigint/BigIntegerAlgorithms.cc +70 -0
  31. data/ext/zxing/zxing-cpp/core/src/bigint/BigIntegerAlgorithms.hh +25 -0
  32. data/ext/zxing/zxing-cpp/core/src/bigint/BigIntegerLibrary.hh +8 -0
  33. data/ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.cc +50 -0
  34. data/ext/zxing/zxing-cpp/core/src/bigint/BigIntegerUtils.hh +72 -0
  35. data/ext/zxing/zxing-cpp/core/src/bigint/BigUnsigned.cc +697 -0
  36. data/ext/zxing/zxing-cpp/core/src/bigint/BigUnsigned.hh +418 -0
  37. data/ext/zxing/zxing-cpp/core/src/bigint/BigUnsignedInABase.cc +125 -0
  38. data/ext/zxing/zxing-cpp/core/src/bigint/BigUnsignedInABase.hh +122 -0
  39. data/ext/zxing/zxing-cpp/core/src/bigint/ChangeLog +146 -0
  40. data/ext/zxing/zxing-cpp/core/src/bigint/Makefile +73 -0
  41. data/ext/zxing/zxing-cpp/core/src/bigint/NumberlikeArray.hh +177 -0
  42. data/ext/zxing/zxing-cpp/core/src/bigint/README +71 -0
  43. data/ext/zxing/zxing-cpp/core/src/win32/zxing/iconv.h +14 -0
  44. data/ext/zxing/zxing-cpp/core/src/win32/zxing/stdint.h +247 -0
  45. data/ext/zxing/zxing-cpp/core/src/win32/zxing/win_iconv.c +2035 -0
  46. data/ext/zxing/zxing-cpp/core/src/zxing/BarcodeFormat.cpp +40 -0
  47. data/ext/zxing/zxing-cpp/core/src/zxing/BarcodeFormat.h +60 -0
  48. data/ext/zxing/zxing-cpp/core/src/zxing/Binarizer.cpp +45 -0
  49. data/ext/zxing/zxing-cpp/core/src/zxing/Binarizer.h +50 -0
  50. data/ext/zxing/zxing-cpp/core/src/zxing/BinaryBitmap.cpp +70 -0
  51. data/ext/zxing/zxing-cpp/core/src/zxing/BinaryBitmap.h +56 -0
  52. data/ext/zxing/zxing-cpp/core/src/zxing/ChecksumException.cpp +28 -0
  53. data/ext/zxing/zxing-cpp/core/src/zxing/ChecksumException.h +34 -0
  54. data/ext/zxing/zxing-cpp/core/src/zxing/DecodeHints.cpp +142 -0
  55. data/ext/zxing/zxing-cpp/core/src/zxing/DecodeHints.h +85 -0
  56. data/ext/zxing/zxing-cpp/core/src/zxing/Exception.cpp +43 -0
  57. data/ext/zxing/zxing-cpp/core/src/zxing/Exception.h +51 -0
  58. data/ext/zxing/zxing-cpp/core/src/zxing/FormatException.cpp +41 -0
  59. data/ext/zxing/zxing-cpp/core/src/zxing/FormatException.h +37 -0
  60. data/ext/zxing/zxing-cpp/core/src/zxing/IllegalStateException.h +35 -0
  61. data/ext/zxing/zxing-cpp/core/src/zxing/InvertedLuminanceSource.cpp +68 -0
  62. data/ext/zxing/zxing-cpp/core/src/zxing/InvertedLuminanceSource.h +48 -0
  63. data/ext/zxing/zxing-cpp/core/src/zxing/LuminanceSource.cpp +86 -0
  64. data/ext/zxing/zxing-cpp/core/src/zxing/LuminanceSource.h +59 -0
  65. data/ext/zxing/zxing-cpp/core/src/zxing/MultiFormatReader.cpp +124 -0
  66. data/ext/zxing/zxing-cpp/core/src/zxing/MultiFormatReader.h +48 -0
  67. data/ext/zxing/zxing-cpp/core/src/zxing/NotFoundException.h +35 -0
  68. data/ext/zxing/zxing-cpp/core/src/zxing/Reader.cpp +31 -0
  69. data/ext/zxing/zxing-cpp/core/src/zxing/Reader.h +40 -0
  70. data/ext/zxing/zxing-cpp/core/src/zxing/ReaderException.h +37 -0
  71. data/ext/zxing/zxing-cpp/core/src/zxing/Result.cpp +61 -0
  72. data/ext/zxing/zxing-cpp/core/src/zxing/Result.h +55 -0
  73. data/ext/zxing/zxing-cpp/core/src/zxing/ResultIO.cpp +34 -0
  74. data/ext/zxing/zxing-cpp/core/src/zxing/ResultPoint.cpp +108 -0
  75. data/ext/zxing/zxing-cpp/core/src/zxing/ResultPoint.h +55 -0
  76. data/ext/zxing/zxing-cpp/core/src/zxing/ResultPointCallback.cpp +26 -0
  77. data/ext/zxing/zxing-cpp/core/src/zxing/ResultPointCallback.h +39 -0
  78. data/ext/zxing/zxing-cpp/core/src/zxing/ZXing.h +133 -0
  79. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/AztecDetectorResult.cpp +54 -0
  80. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/AztecDetectorResult.h +48 -0
  81. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/AztecReader.cpp +68 -0
  82. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/AztecReader.h +49 -0
  83. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/decoder/Decoder.cpp +489 -0
  84. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/decoder/Decoder.h +69 -0
  85. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/detector/Detector.cpp +548 -0
  86. data/ext/zxing/zxing-cpp/core/src/zxing/aztec/detector/Detector.h +92 -0
  87. data/ext/zxing/zxing-cpp/core/src/zxing/common/Array.h +170 -0
  88. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitArray.cpp +155 -0
  89. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitArray.h +81 -0
  90. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitArrayIO.cpp +31 -0
  91. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitMatrix.cpp +143 -0
  92. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitMatrix.h +91 -0
  93. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitSource.cpp +76 -0
  94. data/ext/zxing/zxing-cpp/core/src/zxing/common/BitSource.h +74 -0
  95. data/ext/zxing/zxing-cpp/core/src/zxing/common/CharacterSetECI.cpp +104 -0
  96. data/ext/zxing/zxing-cpp/core/src/zxing/common/CharacterSetECI.h +53 -0
  97. data/ext/zxing/zxing-cpp/core/src/zxing/common/Counted.h +140 -0
  98. data/ext/zxing/zxing-cpp/core/src/zxing/common/DecoderResult.cpp +46 -0
  99. data/ext/zxing/zxing-cpp/core/src/zxing/common/DecoderResult.h +51 -0
  100. data/ext/zxing/zxing-cpp/core/src/zxing/common/DetectorResult.cpp +39 -0
  101. data/ext/zxing/zxing-cpp/core/src/zxing/common/DetectorResult.h +43 -0
  102. data/ext/zxing/zxing-cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp +212 -0
  103. data/ext/zxing/zxing-cpp/core/src/zxing/common/GlobalHistogramBinarizer.h +48 -0
  104. data/ext/zxing/zxing-cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp +80 -0
  105. data/ext/zxing/zxing-cpp/core/src/zxing/common/GreyscaleLuminanceSource.h +53 -0
  106. data/ext/zxing/zxing-cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp +81 -0
  107. data/ext/zxing/zxing-cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.h +46 -0
  108. data/ext/zxing/zxing-cpp/core/src/zxing/common/GridSampler.cpp +122 -0
  109. data/ext/zxing/zxing-cpp/core/src/zxing/common/GridSampler.h +45 -0
  110. data/ext/zxing/zxing-cpp/core/src/zxing/common/HybridBinarizer.cpp +226 -0
  111. data/ext/zxing/zxing-cpp/core/src/zxing/common/HybridBinarizer.h +67 -0
  112. data/ext/zxing/zxing-cpp/core/src/zxing/common/IllegalArgumentException.cpp +27 -0
  113. data/ext/zxing/zxing-cpp/core/src/zxing/common/IllegalArgumentException.h +36 -0
  114. data/ext/zxing/zxing-cpp/core/src/zxing/common/PerspectiveTransform.cpp +107 -0
  115. data/ext/zxing/zxing-cpp/core/src/zxing/common/PerspectiveTransform.h +49 -0
  116. data/ext/zxing/zxing-cpp/core/src/zxing/common/Point.h +47 -0
  117. data/ext/zxing/zxing-cpp/core/src/zxing/common/Str.cpp +61 -0
  118. data/ext/zxing/zxing-cpp/core/src/zxing/common/Str.h +51 -0
  119. data/ext/zxing/zxing-cpp/core/src/zxing/common/StringUtils.cpp +198 -0
  120. data/ext/zxing/zxing-cpp/core/src/zxing/common/StringUtils.h +52 -0
  121. data/ext/zxing/zxing-cpp/core/src/zxing/common/detector/JavaMath.h +43 -0
  122. data/ext/zxing/zxing-cpp/core/src/zxing/common/detector/MathUtils.h +57 -0
  123. data/ext/zxing/zxing-cpp/core/src/zxing/common/detector/MonochromeRectangleDetector.cpp +174 -0
  124. data/ext/zxing/zxing-cpp/core/src/zxing/common/detector/MonochromeRectangleDetector.h +62 -0
  125. data/ext/zxing/zxing-cpp/core/src/zxing/common/detector/WhiteRectangleDetector.cpp +330 -0
  126. data/ext/zxing/zxing-cpp/core/src/zxing/common/detector/WhiteRectangleDetector.h +59 -0
  127. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/GenericGF.cpp +150 -0
  128. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/GenericGF.h +73 -0
  129. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/GenericGFPoly.cpp +218 -0
  130. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/GenericGFPoly.h +56 -0
  131. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp +174 -0
  132. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h +49 -0
  133. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/ReedSolomonException.cpp +30 -0
  134. data/ext/zxing/zxing-cpp/core/src/zxing/common/reedsolomon/ReedSolomonException.h +33 -0
  135. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/DataMatrixReader.cpp +54 -0
  136. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/DataMatrixReader.h +45 -0
  137. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/Version.cpp +199 -0
  138. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/Version.h +87 -0
  139. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/BitMatrixParser.cpp +361 -0
  140. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/BitMatrixParser.h +59 -0
  141. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/DataBlock.cpp +113 -0
  142. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/DataBlock.h +49 -0
  143. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/DecodedBitStreamParser.cpp +416 -0
  144. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/DecodedBitStreamParser.h +104 -0
  145. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/Decoder.cpp +93 -0
  146. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/decoder/Decoder.h +49 -0
  147. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/detector/CornerPoint.cpp +46 -0
  148. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/detector/CornerPoint.h +43 -0
  149. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/detector/Detector.cpp +446 -0
  150. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/detector/Detector.h +94 -0
  151. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/detector/DetectorException.cpp +23 -0
  152. data/ext/zxing/zxing-cpp/core/src/zxing/datamatrix/detector/DetectorException.h +23 -0
  153. data/ext/zxing/zxing-cpp/core/src/zxing/multi/ByQuadrantReader.cpp +75 -0
  154. data/ext/zxing/zxing-cpp/core/src/zxing/multi/ByQuadrantReader.h +42 -0
  155. data/ext/zxing/zxing-cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp +137 -0
  156. data/ext/zxing/zxing-cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.h +51 -0
  157. data/ext/zxing/zxing-cpp/core/src/zxing/multi/MultipleBarcodeReader.cpp +29 -0
  158. data/ext/zxing/zxing-cpp/core/src/zxing/multi/MultipleBarcodeReader.h +41 -0
  159. data/ext/zxing/zxing-cpp/core/src/zxing/multi/qrcode/QRCodeMultiReader.cpp +58 -0
  160. data/ext/zxing/zxing-cpp/core/src/zxing/multi/qrcode/QRCodeMultiReader.h +36 -0
  161. data/ext/zxing/zxing-cpp/core/src/zxing/multi/qrcode/detector/MultiDetector.cpp +47 -0
  162. data/ext/zxing/zxing-cpp/core/src/zxing/multi/qrcode/detector/MultiDetector.h +37 -0
  163. data/ext/zxing/zxing-cpp/core/src/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp +236 -0
  164. data/ext/zxing/zxing-cpp/core/src/zxing/multi/qrcode/detector/MultiFinderPatternFinder.h +47 -0
  165. data/ext/zxing/zxing-cpp/core/src/zxing/oned/CodaBarReader.cpp +340 -0
  166. data/ext/zxing/zxing-cpp/core/src/zxing/oned/CodaBarReader.h +57 -0
  167. data/ext/zxing/zxing-cpp/core/src/zxing/oned/Code128Reader.cpp +496 -0
  168. data/ext/zxing/zxing-cpp/core/src/zxing/oned/Code128Reader.h +48 -0
  169. data/ext/zxing/zxing-cpp/core/src/zxing/oned/Code39Reader.cpp +328 -0
  170. data/ext/zxing/zxing-cpp/core/src/zxing/oned/Code39Reader.h +63 -0
  171. data/ext/zxing/zxing-cpp/core/src/zxing/oned/Code93Reader.cpp +293 -0
  172. data/ext/zxing/zxing-cpp/core/src/zxing/oned/Code93Reader.h +58 -0
  173. data/ext/zxing/zxing-cpp/core/src/zxing/oned/EAN13Reader.cpp +85 -0
  174. data/ext/zxing/zxing-cpp/core/src/zxing/oned/EAN13Reader.h +49 -0
  175. data/ext/zxing/zxing-cpp/core/src/zxing/oned/EAN8Reader.cpp +65 -0
  176. data/ext/zxing/zxing-cpp/core/src/zxing/oned/EAN8Reader.h +47 -0
  177. data/ext/zxing/zxing-cpp/core/src/zxing/oned/ITFReader.cpp +337 -0
  178. data/ext/zxing/zxing-cpp/core/src/zxing/oned/ITFReader.h +54 -0
  179. data/ext/zxing/zxing-cpp/core/src/zxing/oned/MultiFormatOneDReader.cpp +96 -0
  180. data/ext/zxing/zxing-cpp/core/src/zxing/oned/MultiFormatOneDReader.h +38 -0
  181. data/ext/zxing/zxing-cpp/core/src/zxing/oned/MultiFormatUPCEANReader.cpp +110 -0
  182. data/ext/zxing/zxing-cpp/core/src/zxing/oned/MultiFormatUPCEANReader.h +41 -0
  183. data/ext/zxing/zxing-cpp/core/src/zxing/oned/OneDReader.cpp +227 -0
  184. data/ext/zxing/zxing-cpp/core/src/zxing/oned/OneDReader.h +81 -0
  185. data/ext/zxing/zxing-cpp/core/src/zxing/oned/OneDResultPoint.cpp +28 -0
  186. data/ext/zxing/zxing-cpp/core/src/zxing/oned/OneDResultPoint.h +35 -0
  187. data/ext/zxing/zxing-cpp/core/src/zxing/oned/UPCAReader.cpp +71 -0
  188. data/ext/zxing/zxing-cpp/core/src/zxing/oned/UPCAReader.h +50 -0
  189. data/ext/zxing/zxing-cpp/core/src/zxing/oned/UPCEANReader.cpp +309 -0
  190. data/ext/zxing/zxing-cpp/core/src/zxing/oned/UPCEANReader.h +88 -0
  191. data/ext/zxing/zxing-cpp/core/src/zxing/oned/UPCEReader.cpp +146 -0
  192. data/ext/zxing/zxing-cpp/core/src/zxing/oned/UPCEReader.h +47 -0
  193. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/PDF417Reader.cpp +170 -0
  194. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/PDF417Reader.h +49 -0
  195. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/BitMatrixParser.cpp +997 -0
  196. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/BitMatrixParser.h +84 -0
  197. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/DecodedBitStreamParser.cpp +563 -0
  198. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/DecodedBitStreamParser.h +84 -0
  199. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/Decoder.cpp +118 -0
  200. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/Decoder.h +62 -0
  201. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/ec/ErrorCorrection.cpp +214 -0
  202. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/ec/ErrorCorrection.h +71 -0
  203. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/ec/ModulusGF.cpp +120 -0
  204. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/ec/ModulusGF.h +72 -0
  205. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/ec/ModulusPoly.cpp +284 -0
  206. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/decoder/ec/ModulusPoly.h +68 -0
  207. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/detector/Detector.cpp +664 -0
  208. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/detector/Detector.h +106 -0
  209. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp +714 -0
  210. data/ext/zxing/zxing-cpp/core/src/zxing/pdf417/detector/LinesSampler.h +122 -0
  211. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/ErrorCorrectionLevel.cpp +65 -0
  212. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/ErrorCorrectionLevel.h +52 -0
  213. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/FormatInformation.cpp +117 -0
  214. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/FormatInformation.h +54 -0
  215. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/QRCodeReader.cpp +52 -0
  216. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/QRCodeReader.h +48 -0
  217. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/Version.cpp +560 -0
  218. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/Version.h +85 -0
  219. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/BitMatrixParser.cpp +183 -0
  220. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/BitMatrixParser.h +56 -0
  221. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/DataBlock.cpp +118 -0
  222. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/DataBlock.h +50 -0
  223. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/DataMask.cpp +159 -0
  224. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/DataMask.h +50 -0
  225. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp +425 -0
  226. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.h +72 -0
  227. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/Decoder.cpp +107 -0
  228. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/Decoder.h +46 -0
  229. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/Mode.cpp +90 -0
  230. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/decoder/Mode.h +57 -0
  231. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/AlignmentPattern.cpp +47 -0
  232. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/AlignmentPattern.h +45 -0
  233. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp +208 -0
  234. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h +68 -0
  235. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/Detector.cpp +314 -0
  236. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/Detector.h +69 -0
  237. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/FinderPattern.cpp +69 -0
  238. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/FinderPattern.h +48 -0
  239. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp +559 -0
  240. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.h +76 -0
  241. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/FinderPatternInfo.cpp +41 -0
  242. data/ext/zxing/zxing-cpp/core/src/zxing/qrcode/detector/FinderPatternInfo.h +47 -0
  243. data/ext/zxing/zxing-cpp/core/tests/src/TestRunner.cpp +30 -0
  244. data/ext/zxing/zxing-cpp/core/tests/src/common/BitArrayTest.cpp +216 -0
  245. data/ext/zxing/zxing-cpp/core/tests/src/common/BitArrayTest.h +61 -0
  246. data/ext/zxing/zxing-cpp/core/tests/src/common/BitMatrixTest.cpp +106 -0
  247. data/ext/zxing/zxing-cpp/core/tests/src/common/BitMatrixTest.h +55 -0
  248. data/ext/zxing/zxing-cpp/core/tests/src/common/BitSourceTest.cpp +49 -0
  249. data/ext/zxing/zxing-cpp/core/tests/src/common/BitSourceTest.h +42 -0
  250. data/ext/zxing/zxing-cpp/core/tests/src/common/CountedTest.cpp +58 -0
  251. data/ext/zxing/zxing-cpp/core/tests/src/common/CountedTest.h +46 -0
  252. data/ext/zxing/zxing-cpp/core/tests/src/common/PerspectiveTransformTest.cpp +69 -0
  253. data/ext/zxing/zxing-cpp/core/tests/src/common/PerspectiveTransformTest.h +47 -0
  254. data/ext/zxing/zxing-cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp +129 -0
  255. data/ext/zxing/zxing-cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.h +62 -0
  256. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/ErrorCorrectionLevelTest.cpp +47 -0
  257. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/ErrorCorrectionLevelTest.h +45 -0
  258. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/FormatInformationTest.cpp +88 -0
  259. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/FormatInformationTest.h +47 -0
  260. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/VersionTest.cpp +88 -0
  261. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/VersionTest.h +49 -0
  262. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/decoder/DataMaskTest.cpp +132 -0
  263. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/decoder/DataMaskTest.h +91 -0
  264. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/decoder/ModeTest.cpp +52 -0
  265. data/ext/zxing/zxing-cpp/core/tests/src/qrcode/decoder/ModeTest.h +47 -0
  266. data/ext/zxing/zxing.cc +224 -0
  267. data/lib/zxing.rb +50 -0
  268. data/lib/zxing/.gitignore +2 -0
  269. data/lib/zxing/aztec.rb +5 -0
  270. data/lib/zxing/aztec/aztec_reader.rb +14 -0
  271. data/lib/zxing/bad_image_exception.rb +4 -0
  272. data/lib/zxing/binarizer.rb +8 -0
  273. data/lib/zxing/binary_bitmap.rb +15 -0
  274. data/lib/zxing/checksum_exception.rb +4 -0
  275. data/lib/zxing/common.rb +7 -0
  276. data/lib/zxing/common/bit_matrix.rb +9 -0
  277. data/lib/zxing/common/hybrid_binarizer.rb +17 -0
  278. data/lib/zxing/common/illegal_argument_exception.rb +4 -0
  279. data/lib/zxing/datamatrix.rb +5 -0
  280. data/lib/zxing/datamatrix/data_matrix_reader.rb +14 -0
  281. data/lib/zxing/decodable.rb +11 -0
  282. data/lib/zxing/exception.rb +4 -0
  283. data/lib/zxing/ffi.rb +20 -0
  284. data/lib/zxing/ffi/aztec.rb +6 -0
  285. data/lib/zxing/ffi/aztec/aztec_reader.rb +9 -0
  286. data/lib/zxing/ffi/binarizer.rb +25 -0
  287. data/lib/zxing/ffi/binary_bitmap.rb +15 -0
  288. data/lib/zxing/ffi/common.rb +8 -0
  289. data/lib/zxing/ffi/common/bit_matrix.rb +12 -0
  290. data/lib/zxing/ffi/common/greyscale_luminance_source.rb +30 -0
  291. data/lib/zxing/ffi/common/hybrid_binarizer.rb +10 -0
  292. data/lib/zxing/ffi/datamatrix.rb +6 -0
  293. data/lib/zxing/ffi/datamatrix/data_matrix_reader.rb +9 -0
  294. data/lib/zxing/ffi/library.rb +102 -0
  295. data/lib/zxing/ffi/luminance_source.rb +18 -0
  296. data/lib/zxing/ffi/multi_format_reader.rb +9 -0
  297. data/lib/zxing/ffi/oned.rb +6 -0
  298. data/lib/zxing/ffi/oned/code_39_reader.rb +10 -0
  299. data/lib/zxing/ffi/qrcode.rb +8 -0
  300. data/lib/zxing/ffi/qrcode/decoder.rb +10 -0
  301. data/lib/zxing/ffi/qrcode/detector.rb +10 -0
  302. data/lib/zxing/ffi/reader.rb +58 -0
  303. data/lib/zxing/ffi/result.rb +23 -0
  304. data/lib/zxing/format_exception.rb +4 -0
  305. data/lib/zxing/illegal_argument_exception.rb +4 -0
  306. data/lib/zxing/image.rb +15 -0
  307. data/lib/zxing/luminance_source.rb +18 -0
  308. data/lib/zxing/multi_format_reader.rb +11 -0
  309. data/lib/zxing/not_found_exception.rb +4 -0
  310. data/lib/zxing/oned.rb +5 -0
  311. data/lib/zxing/oned/code_39_reader.rb +15 -0
  312. data/lib/zxing/qrcode.rb +8 -0
  313. data/lib/zxing/qrcode/decoder.rb +14 -0
  314. data/lib/zxing/qrcode/detector.rb +14 -0
  315. data/lib/zxing/qrcode/encoder.rb +8 -0
  316. data/lib/zxing/qrcode/encoder/byte_matrix.rb +18 -0
  317. data/lib/zxing/qrcode/encoder/encoder.rb +9 -0
  318. data/lib/zxing/qrcode/encoder/qrcode.rb +18 -0
  319. data/lib/zxing/reader.rb +8 -0
  320. data/lib/zxing/reader_exception.rb +4 -0
  321. data/lib/zxing/reed_solomon_exception.rb +2 -0
  322. data/lib/zxing/result.rb +18 -0
  323. data/lib/zxing/rmagick.rb +5 -0
  324. data/lib/zxing/rmagick/image.rb +104 -0
  325. data/lib/zxing/version.rb +33 -0
  326. data/test/qrcode.png +0 -0
  327. data/test/test_helper.rb +5 -0
  328. data/test/test_zxing.rb +58 -0
  329. data/test/vendor.rb +360 -0
  330. data/test/zxing/test_decodable.rb +38 -0
  331. data/zxing_cpp.gemspec +48 -0
  332. metadata +473 -0
@@ -0,0 +1,68 @@
1
+ #ifndef __MODULUS_GFPOLY_PDF_H__
2
+ #define __MODULUS_GFPOLY_PDF_H__
3
+
4
+ /*
5
+ * Copyright 2012 ZXing authors
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * 2012-09-17 HFN translation from Java into C++
20
+ */
21
+
22
+ #include <zxing/common/Counted.h>
23
+ #include <zxing/common/Array.h>
24
+ #include <zxing/common/DecoderResult.h>
25
+ #include <zxing/common/BitMatrix.h>
26
+
27
+ namespace zxing {
28
+ namespace pdf417 {
29
+ namespace decoder {
30
+ namespace ec {
31
+
32
+ class ModulusGF;
33
+
34
+ /**
35
+ * @author Sean Owen
36
+ * @see com.google.zxing.common.reedsolomon.GenericGFPoly
37
+ */
38
+ class ModulusPoly: public Counted {
39
+
40
+ private:
41
+ ModulusGF &field_;
42
+ ArrayRef<int> coefficients_;
43
+ public:
44
+ ModulusPoly(ModulusGF& field, ArrayRef<int> coefficients);
45
+ ~ModulusPoly();
46
+ ArrayRef<int> getCoefficients();
47
+ int getDegree();
48
+ bool isZero();
49
+ int getCoefficient(int degree);
50
+ int evaluateAt(int a);
51
+ Ref<ModulusPoly> add(Ref<ModulusPoly> other);
52
+ Ref<ModulusPoly> subtract(Ref<ModulusPoly> other);
53
+ Ref<ModulusPoly> multiply(Ref<ModulusPoly> other);
54
+ Ref<ModulusPoly> negative();
55
+ Ref<ModulusPoly> multiply(int scalar);
56
+ Ref<ModulusPoly> multiplyByMonomial(int degree, int coefficient);
57
+ std::vector<Ref<ModulusPoly> > divide(Ref<ModulusPoly> other);
58
+ #if 0
59
+ public String toString();
60
+ #endif
61
+ };
62
+
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ #endif /* __MODULUS_GFPOLY_PDF_H__ */
@@ -0,0 +1,664 @@
1
+ // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
2
+ /*
3
+ * Copyright 2010 ZXing authors All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include <limits>
19
+ #include <zxing/pdf417/detector/Detector.h>
20
+ #include <zxing/pdf417/detector/LinesSampler.h>
21
+ #include <zxing/common/GridSampler.h>
22
+ #include <zxing/common/detector/JavaMath.h>
23
+ #include <zxing/common/detector/MathUtils.h>
24
+
25
+ using std::max;
26
+ using std::abs;
27
+ using std::numeric_limits;
28
+ using zxing::pdf417::detector::Detector;
29
+ using zxing::common::detector::Math;
30
+ using zxing::common::detector::MathUtils;
31
+ using zxing::Ref;
32
+ using zxing::ArrayRef;
33
+ using zxing::DetectorResult;
34
+ using zxing::ResultPoint;
35
+ using zxing::Point;
36
+ using zxing::BitMatrix;
37
+ using zxing::GridSampler;
38
+
39
+ // VC++
40
+
41
+ using zxing::BinaryBitmap;
42
+ using zxing::DecodeHints;
43
+ using zxing::Line;
44
+
45
+ /**
46
+ * <p>Encapsulates logic that can detect a PDF417 Code in an image, even if the
47
+ * PDF417 Code is rotated or skewed, or partially obscured.</p>
48
+ *
49
+ * @author SITA Lab (kevin.osullivan@sita.aero)
50
+ * @author Daniel Switkin (dswitkin@google.com)
51
+ * @author Schweers Informationstechnologie GmbH (hartmut.neubauer@schweers.de)
52
+ * @author creatale GmbH (christoph.schulz@creatale.de)
53
+ */
54
+
55
+ const int Detector::MAX_AVG_VARIANCE= (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
56
+ const int Detector::MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.8f);
57
+
58
+ // B S B S B S B S Bar/Space pattern
59
+ // 11111111 0 1 0 1 0 1 000
60
+ const int Detector::START_PATTERN[] = {8, 1, 1, 1, 1, 1, 1, 3};
61
+ const int Detector::START_PATTERN_LENGTH = sizeof(START_PATTERN) / sizeof(int);
62
+
63
+ // 11111111 0 1 0 1 0 1 000
64
+ const int Detector::START_PATTERN_REVERSE[] = {3, 1, 1, 1, 1, 1, 1, 8};
65
+ const int Detector::START_PATTERN_REVERSE_LENGTH = sizeof(START_PATTERN_REVERSE) / sizeof(int);
66
+
67
+ // 1111111 0 1 000 1 0 1 00 1
68
+ const int Detector::STOP_PATTERN[] = {7, 1, 1, 3, 1, 1, 1, 2, 1};
69
+ const int Detector::STOP_PATTERN_LENGTH = sizeof(STOP_PATTERN) / sizeof(int);
70
+
71
+ // B S B S B S B S B Bar/Space pattern
72
+ // 1111111 0 1 000 1 0 1 00 1
73
+ const int Detector::STOP_PATTERN_REVERSE[] = {1, 2, 1, 1, 1, 3, 1, 1, 7};
74
+ const int Detector::STOP_PATTERN_REVERSE_LENGTH = sizeof(STOP_PATTERN_REVERSE) / sizeof(int);
75
+
76
+ Detector::Detector(Ref<BinaryBitmap> image) : image_(image) {}
77
+
78
+ Ref<DetectorResult> Detector::detect() {
79
+ return detect(DecodeHints());
80
+ }
81
+
82
+ Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
83
+ (void)hints;
84
+ // Fetch the 1 bit matrix once up front.
85
+ Ref<BitMatrix> matrix = image_->getBlackMatrix();
86
+
87
+ // Try to find the vertices assuming the image is upright.
88
+ const int rowStep = 8;
89
+ ArrayRef< Ref<ResultPoint> > vertices (findVertices(matrix, rowStep));
90
+ if (!vertices) {
91
+ // Maybe the image is rotated 180 degrees?
92
+ vertices = findVertices180(matrix, rowStep);
93
+ if (vertices) {
94
+ correctVertices(matrix, vertices, true);
95
+ }
96
+ } else {
97
+ correctVertices(matrix, vertices, false);
98
+ }
99
+
100
+ if (!vertices) {
101
+ throw NotFoundException("No vertices found.");
102
+ }
103
+
104
+ float moduleWidth = computeModuleWidth(vertices);
105
+ if (moduleWidth < 1.0f) {
106
+ throw NotFoundException("Bad module width.");
107
+ }
108
+
109
+ int dimension = computeDimension(vertices[12], vertices[14],
110
+ vertices[13], vertices[15], moduleWidth);
111
+ if (dimension < 1) {
112
+ throw NotFoundException("Bad dimension.");
113
+ }
114
+
115
+ int yDimension = max(computeYDimension(vertices[12], vertices[14],
116
+ vertices[13], vertices[15], moduleWidth), dimension);
117
+
118
+ // Deskew and sample lines from image.
119
+ Ref<BitMatrix> linesMatrix = sampleLines(vertices, dimension, yDimension);
120
+ Ref<BitMatrix> linesGrid(LinesSampler(linesMatrix, dimension).sample());
121
+
122
+ ArrayRef< Ref<ResultPoint> > points(4);
123
+ points[0] = vertices[5];
124
+ points[1] = vertices[4];
125
+ points[2] = vertices[6];
126
+ points[3] = vertices[7];
127
+ return Ref<DetectorResult>(new DetectorResult(linesGrid, points));
128
+ }
129
+
130
+ /**
131
+ * Locate the vertices and the codewords area of a black blob using the Start
132
+ * and Stop patterns as locators.
133
+ *
134
+ * @param matrix the scanned barcode image.
135
+ * @param rowStep the step size for iterating rows (every n-th row).
136
+ * @return an array containing the vertices:
137
+ * vertices[0] x, y top left barcode
138
+ * vertices[1] x, y bottom left barcode
139
+ * vertices[2] x, y top right barcode
140
+ * vertices[3] x, y bottom right barcode
141
+ * vertices[4] x, y top left codeword area
142
+ * vertices[5] x, y bottom left codeword area
143
+ * vertices[6] x, y top right codeword area
144
+ * vertices[7] x, y bottom right codeword area
145
+ */
146
+ ArrayRef< Ref<ResultPoint> > Detector::findVertices(Ref<BitMatrix> matrix, int rowStep)
147
+ {
148
+ const int height = matrix->getHeight();
149
+ const int width = matrix->getWidth();
150
+
151
+ ArrayRef< Ref<ResultPoint> > result(16);
152
+ bool found = false;
153
+
154
+ ArrayRef<int> counters(new Array<int>(START_PATTERN_LENGTH));
155
+
156
+ // Top Left
157
+ for (int i = 0; i < height; i += rowStep) {
158
+ ArrayRef<int> loc = findGuardPattern(matrix, 0, i, width, false, START_PATTERN,
159
+ START_PATTERN_LENGTH, counters);
160
+ if (loc) {
161
+ result[0] = new ResultPoint((float)loc[0], (float)i);
162
+ result[4] = new ResultPoint((float)loc[1], (float)i);
163
+ found = true;
164
+ break;
165
+ }
166
+ }
167
+ // Bottom left
168
+ if (found) { // Found the Top Left vertex
169
+ found = false;
170
+ for (int i = height - 1; i > 0; i -= rowStep) {
171
+ ArrayRef<int> loc = findGuardPattern(matrix, 0, i, width, false, START_PATTERN,
172
+ START_PATTERN_LENGTH, counters);
173
+ if (loc) {
174
+ result[1] = new ResultPoint((float)loc[0], (float)i);
175
+ result[5] = new ResultPoint((float)loc[1], (float)i);
176
+ found = true;
177
+ break;
178
+ }
179
+ }
180
+ }
181
+
182
+ counters = new Array<int>(STOP_PATTERN_LENGTH);
183
+
184
+ // Top right
185
+ if (found) { // Found the Bottom Left vertex
186
+ found = false;
187
+ for (int i = 0; i < height; i += rowStep) {
188
+ ArrayRef<int> loc = findGuardPattern(matrix, 0, i, width, false, STOP_PATTERN,
189
+ STOP_PATTERN_LENGTH, counters);
190
+ if (loc) {
191
+ result[2] = new ResultPoint((float)loc[1], (float)i);
192
+ result[6] = new ResultPoint((float)loc[0], (float)i);
193
+ found = true;
194
+ break;
195
+ }
196
+ }
197
+ }
198
+ // Bottom right
199
+ if (found) { // Found the Top right vertex
200
+ found = false;
201
+ for (int i = height - 1; i > 0; i -= rowStep) {
202
+ ArrayRef<int> loc = findGuardPattern(matrix, 0, i, width, false, STOP_PATTERN,
203
+ STOP_PATTERN_LENGTH, counters);
204
+ if (loc) {
205
+ result[3] = new ResultPoint((float)loc[1], (float)i);
206
+ result[7] = new ResultPoint((float)loc[0], (float)i);
207
+ found = true;
208
+ break;
209
+ }
210
+ }
211
+ }
212
+
213
+ return found ? result : ArrayRef< Ref<ResultPoint> >();
214
+ }
215
+
216
+ ArrayRef< Ref<ResultPoint> > Detector::findVertices180(Ref<BitMatrix> matrix, int rowStep) {
217
+ const int height = matrix->getHeight();
218
+ const int width = matrix->getWidth();
219
+ const int halfWidth = width >> 1;
220
+
221
+ ArrayRef< Ref<ResultPoint> > result(16);
222
+ bool found = false;
223
+
224
+ ArrayRef<int> counters = new Array<int>(START_PATTERN_REVERSE_LENGTH);
225
+
226
+ // Top Left
227
+ for (int i = height - 1; i > 0; i -= rowStep) {
228
+ ArrayRef<int> loc =
229
+ findGuardPattern(matrix, halfWidth, i, halfWidth, true, START_PATTERN_REVERSE,
230
+ START_PATTERN_REVERSE_LENGTH, counters);
231
+ if (loc) {
232
+ result[0] = new ResultPoint((float)loc[1], (float)i);
233
+ result[4] = new ResultPoint((float)loc[0], (float)i);
234
+ found = true;
235
+ break;
236
+ }
237
+ }
238
+ // Bottom Left
239
+ if (found) { // Found the Top Left vertex
240
+ found = false;
241
+ for (int i = 0; i < height; i += rowStep) {
242
+ ArrayRef<int> loc =
243
+ findGuardPattern(matrix, halfWidth, i, halfWidth, true, START_PATTERN_REVERSE,
244
+ START_PATTERN_REVERSE_LENGTH, counters);
245
+ if (loc) {
246
+ result[1] = new ResultPoint((float)loc[1], (float)i);
247
+ result[5] = new ResultPoint((float)loc[0], (float)i);
248
+ found = true;
249
+ break;
250
+ }
251
+ }
252
+ }
253
+
254
+ counters = new Array<int>(STOP_PATTERN_REVERSE_LENGTH);
255
+
256
+ // Top Right
257
+ if (found) { // Found the Bottom Left vertex
258
+ found = false;
259
+ for (int i = height - 1; i > 0; i -= rowStep) {
260
+ ArrayRef<int> loc = findGuardPattern(matrix, 0, i, halfWidth, false, STOP_PATTERN_REVERSE,
261
+ STOP_PATTERN_REVERSE_LENGTH, counters);
262
+ if (loc) {
263
+ result[2] = new ResultPoint((float)loc[0], (float)i);
264
+ result[6] = new ResultPoint((float)loc[1], (float)i);
265
+ found = true;
266
+ break;
267
+ }
268
+ }
269
+ }
270
+ // Bottom Right
271
+ if (found) { // Found the Top Right vertex
272
+ found = false;
273
+ for (int i = 0; i < height; i += rowStep) {
274
+ ArrayRef<int> loc = findGuardPattern(matrix, 0, i, halfWidth, false, STOP_PATTERN_REVERSE,
275
+ STOP_PATTERN_REVERSE_LENGTH, counters);
276
+ if (loc) {
277
+ result[3] = new ResultPoint((float)loc[0], (float)i);
278
+ result[7] = new ResultPoint((float)loc[1], (float)i);
279
+ found = true;
280
+ break;
281
+ }
282
+ }
283
+ }
284
+
285
+ return found ? result : ArrayRef< Ref<ResultPoint> >();
286
+ }
287
+
288
+ /**
289
+ * @param matrix row of black/white values to search
290
+ * @param column x position to start search
291
+ * @param row y position to start search
292
+ * @param width the number of pixels to search on this row
293
+ * @param pattern pattern of counts of number of black and white pixels that are
294
+ * being searched for as a pattern
295
+ * @param counters array of counters, as long as pattern, to re-use
296
+ * @return start/end horizontal offset of guard pattern, as an array of two ints.
297
+ */
298
+ ArrayRef<int> Detector::findGuardPattern(Ref<BitMatrix> matrix,
299
+ int column,
300
+ int row,
301
+ int width,
302
+ bool whiteFirst,
303
+ const int pattern[],
304
+ int patternSize,
305
+ ArrayRef<int>& counters) {
306
+ counters->values().assign(counters->size(), 0);
307
+ int patternLength = patternSize;
308
+ bool isWhite = whiteFirst;
309
+
310
+ int counterPosition = 0;
311
+ int patternStart = column;
312
+ for (int x = column; x < column + width; x++) {
313
+ bool pixel = matrix->get(x, row);
314
+ if (pixel ^ isWhite) {
315
+ counters[counterPosition]++;
316
+ } else {
317
+ if (counterPosition == patternLength - 1) {
318
+ if (patternMatchVariance(counters, pattern,
319
+ MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
320
+ ArrayRef<int> result = new Array<int>(2);
321
+ result[0] = patternStart;
322
+ result[1] = x;
323
+ return result;
324
+ }
325
+ patternStart += counters[0] + counters[1];
326
+ for(int i = 0; i < patternLength - 2; ++i)
327
+ counters[i] = counters[ i + 2];
328
+ counters[patternLength - 2] = 0;
329
+ counters[patternLength - 1] = 0;
330
+ counterPosition--;
331
+ } else {
332
+ counterPosition++;
333
+ }
334
+ counters[counterPosition] = 1;
335
+ isWhite = !isWhite;
336
+ }
337
+ }
338
+ return ArrayRef<int>();
339
+ }
340
+
341
+ /**
342
+ * Determines how closely a set of observed counts of runs of black/white
343
+ * values matches a given target pattern. This is reported as the ratio of
344
+ * the total variance from the expected pattern proportions across all
345
+ * pattern elements, to the length of the pattern.
346
+ *
347
+ * @param counters observed counters
348
+ * @param pattern expected pattern
349
+ * @param maxIndividualVariance The most any counter can differ before we give up
350
+ * @return ratio of total variance between counters and pattern compared to
351
+ * total pattern size, where the ratio has been multiplied by 256.
352
+ * So, 0 means no variance (perfect match); 256 means the total
353
+ * variance between counters and patterns equals the pattern length,
354
+ * higher values mean even more variance
355
+ */
356
+ int Detector::patternMatchVariance(ArrayRef<int>& counters,
357
+ const int pattern[],
358
+ int maxIndividualVariance)
359
+ {
360
+ int numCounters = counters->size();
361
+ int total = 0;
362
+ int patternLength = 0;
363
+ for (int i = 0; i < numCounters; i++) {
364
+ total += counters[i];
365
+ patternLength += pattern[i];
366
+ }
367
+ if (total < patternLength) {
368
+ // If we don't even have one pixel per unit of bar width, assume this
369
+ // is too small to reliably match, so fail:
370
+ return numeric_limits<int>::max();
371
+ }
372
+ // We're going to fake floating-point math in integers. We just need to use more bits.
373
+ // Scale up patternLength so that intermediate values below like scaledCounter will have
374
+ // more "significant digits".
375
+ int unitBarWidth = (total << 8) / patternLength;
376
+ maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> 8;
377
+
378
+ int totalVariance = 0;
379
+ for (int x = 0; x < numCounters; x++) {
380
+ int counter = counters[x] << 8;
381
+ int scaledPattern = pattern[x] * unitBarWidth;
382
+ int variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter;
383
+ if (variance > maxIndividualVariance) {
384
+ return numeric_limits<int>::max();
385
+ }
386
+ totalVariance += variance;
387
+ }
388
+ return totalVariance / total;
389
+ }
390
+
391
+ /**
392
+ * <p>Correct the vertices by searching for top and bottom vertices of wide
393
+ * bars, then locate the intersections between the upper and lower horizontal
394
+ * line and the inner vertices vertical lines.</p>
395
+ *
396
+ * @param matrix the scanned barcode image.
397
+ * @param vertices the vertices vector is extended and the new members are:
398
+ * vertices[ 8] x,y point on upper border of left wide bar
399
+ * vertices[ 9] x,y point on lower border of left wide bar
400
+ * vertices[10] x,y point on upper border of right wide bar
401
+ * vertices[11] x,y point on lower border of right wide bar
402
+ * vertices[12] x,y final top left codeword area
403
+ * vertices[13] x,y final bottom left codeword area
404
+ * vertices[14] x,y final top right codeword area
405
+ * vertices[15] x,y final bottom right codeword area
406
+ * @param upsideDown true if rotated by 180 degree.
407
+ */
408
+ void Detector::correctVertices(Ref<BitMatrix> matrix,
409
+ ArrayRef< Ref<ResultPoint> >& vertices,
410
+ bool upsideDown)
411
+ {
412
+ bool isLowLeft = abs(vertices[4]->getY() - vertices[5]->getY()) < 20.0;
413
+ bool isLowRight = abs(vertices[6]->getY() - vertices[7]->getY()) < 20.0;
414
+ if (isLowLeft || isLowRight) {
415
+ throw NotFoundException("Cannot find enough PDF417 guard patterns!");
416
+ } else {
417
+ findWideBarTopBottom(matrix, vertices, 0, 0, 8, 17, upsideDown ? 1 : -1);
418
+ findWideBarTopBottom(matrix, vertices, 1, 0, 8, 17, upsideDown ? -1 : 1);
419
+ findWideBarTopBottom(matrix, vertices, 2, 11, 7, 18, upsideDown ? 1 : -1);
420
+ findWideBarTopBottom(matrix, vertices, 3, 11, 7, 18, upsideDown ? -1 : 1);
421
+ findCrossingPoint(vertices, 12, 4, 5, 8, 10, matrix);
422
+ findCrossingPoint(vertices, 13, 4, 5, 9, 11, matrix);
423
+ findCrossingPoint(vertices, 14, 6, 7, 8, 10, matrix);
424
+ findCrossingPoint(vertices, 15, 6, 7, 9, 11, matrix);
425
+ }
426
+ }
427
+
428
+ /**
429
+ * <p>Locate the top or bottom of one of the two wide black bars of a guard pattern.</p>
430
+ *
431
+ * <p>Warning: it only searches along the y axis, so the return points would not be
432
+ * right if the barcode is too curved.</p>
433
+ *
434
+ * @param matrix The bit matrix.
435
+ * @param vertices The 16 vertices located by findVertices(); the result
436
+ * points are stored into vertices[8], ... , vertices[11].
437
+ * @param offsetVertice The offset of the outer vertice and the inner
438
+ * vertice (+ 4) to be corrected and (+ 8) where the result is stored.
439
+ * @param startWideBar start of a wide bar.
440
+ * @param lenWideBar length of wide bar.
441
+ * @param lenPattern length of the pattern.
442
+ * @param rowStep +1 if corner should be exceeded towards the bottom, -1 towards the top.
443
+ */
444
+ void Detector::findWideBarTopBottom(Ref<BitMatrix> matrix,
445
+ ArrayRef< Ref<ResultPoint> > &vertices,
446
+ int offsetVertice,
447
+ int startWideBar,
448
+ int lenWideBar,
449
+ int lenPattern,
450
+ int rowStep)
451
+ {
452
+ Ref<ResultPoint> verticeStart(vertices[offsetVertice]);
453
+ Ref<ResultPoint> verticeEnd(vertices[offsetVertice + 4]);
454
+
455
+ // Start horizontally at the middle of the bar.
456
+ int endWideBar = startWideBar + lenWideBar;
457
+ float barDiff = verticeEnd->getX() - verticeStart->getX();
458
+ float barStart = verticeStart->getX() + barDiff * (float)startWideBar / (float)lenPattern;
459
+ float barEnd = verticeStart->getX() + barDiff * (float)endWideBar / (float)lenPattern;
460
+ int x = Math::round((barStart + barEnd) / 2.0f);
461
+
462
+ // Start vertically between the preliminary vertices.
463
+ int yStart = Math::round(verticeStart->getY());
464
+ int y = yStart;
465
+
466
+ // Find offset of thin bar to the right as additional safeguard.
467
+ int nextBarX = int(max(barStart, barEnd) + 1);
468
+ for (; nextBarX < matrix->getWidth(); nextBarX++)
469
+ if (!matrix->get(nextBarX - 1, y) && matrix->get(nextBarX, y)) break;
470
+ nextBarX -= x;
471
+
472
+ bool isEnd = false;
473
+ while (!isEnd) {
474
+ if (matrix->get(x, y)) {
475
+ // If the thin bar to the right ended, stop as well
476
+ isEnd = !matrix->get(x + nextBarX, y) && !matrix->get(x + nextBarX + 1, y);
477
+ y += rowStep;
478
+ if (y <= 0 || y >= (int)matrix->getHeight() - 1) {
479
+ // End of barcode image reached.
480
+ isEnd = true;
481
+ }
482
+ } else {
483
+ // Look sidewise whether black bar continues? (in the case the image is skewed)
484
+ if (x > 0 && matrix->get(x - 1, y)) {
485
+ x--;
486
+ } else if (x < (int)matrix->getWidth() - 1 && matrix->get(x + 1, y)) {
487
+ x++;
488
+ } else {
489
+ // End of pattern regarding big bar and big gap reached.
490
+ isEnd = true;
491
+ if (y != yStart) {
492
+ // Turn back one step, because target has been exceeded.
493
+ y -= rowStep;
494
+ }
495
+ }
496
+ }
497
+ }
498
+
499
+ vertices[offsetVertice + 8] = new ResultPoint((float)x, (float)y);
500
+ }
501
+
502
+ /**
503
+ * <p>Finds the intersection of two lines.</p>
504
+ *
505
+ * @param vertices The reference of the vertices vector
506
+ * @param idxResult Index of result point inside the vertices vector.
507
+ * @param idxLineA1
508
+ * @param idxLineA2 Indices two points inside the vertices vector that define the first line.
509
+ * @param idxLineB1
510
+ * @param idxLineB2 Indices two points inside the vertices vector that define the second line.
511
+ * @param matrix: bit matrix, here only for testing whether the result is inside the matrix.
512
+ * @return Returns true when the result is valid and lies inside the matrix. Otherwise throws an
513
+ * exception.
514
+ **/
515
+ void Detector::findCrossingPoint(ArrayRef< Ref<ResultPoint> >& vertices,
516
+ int idxResult,
517
+ int idxLineA1, int idxLineA2,
518
+ int idxLineB1, int idxLineB2,
519
+ Ref<BitMatrix>& matrix)
520
+ {
521
+ Point p1(vertices[idxLineA1]->getX(), vertices[idxLineA1]->getY());
522
+ Point p2(vertices[idxLineA2]->getX(), vertices[idxLineA2]->getY());
523
+ Point p3(vertices[idxLineB1]->getX(), vertices[idxLineB1]->getY());
524
+ Point p4(vertices[idxLineB2]->getX(), vertices[idxLineB2]->getY());
525
+
526
+ Point result(intersection(Line(p1, p2), Line(p3, p4)));
527
+ if (result.x == numeric_limits<float>::infinity() ||
528
+ result.y == numeric_limits<float>::infinity()) {
529
+ throw NotFoundException("PDF:Detector: cannot find the crossing of parallel lines!");
530
+ }
531
+
532
+ int x = Math::round(result.x);
533
+ int y = Math::round(result.y);
534
+ if (x < 0 || x >= (int)matrix->getWidth() || y < 0 || y >= (int)matrix->getHeight()) {
535
+ throw NotFoundException("PDF:Detector: crossing points out of region!");
536
+ }
537
+
538
+ vertices[idxResult] = Ref<ResultPoint>(new ResultPoint(result.x, result.y));
539
+ }
540
+
541
+ /**
542
+ * Computes the intersection between two lines.
543
+ */
544
+ Point Detector::intersection(Line a, Line b) {
545
+ float dxa = a.start.x - a.end.x;
546
+ float dxb = b.start.x - b.end.x;
547
+ float dya = a.start.y - a.end.y;
548
+ float dyb = b.start.y - b.end.y;
549
+
550
+ float p = a.start.x * a.end.y - a.start.y * a.end.x;
551
+ float q = b.start.x * b.end.y - b.start.y * b.end.x;
552
+ float denom = dxa * dyb - dya * dxb;
553
+ if(abs(denom) < 1e-12) // Lines don't intersect (replaces "denom == 0")
554
+ return Point(numeric_limits<float>::infinity(),
555
+ numeric_limits<float>::infinity());
556
+
557
+ float x = (p * dxb - dxa * q) / denom;
558
+ float y = (p * dyb - dya * q) / denom;
559
+
560
+ return Point(x, y);
561
+ }
562
+
563
+ /**
564
+ * <p>Estimates module size (pixels in a module) based on the Start and End
565
+ * finder patterns.</p>
566
+ *
567
+ * @param vertices an array of vertices:
568
+ * vertices[0] x, y top left barcode
569
+ * vertices[1] x, y bottom left barcode
570
+ * vertices[2] x, y top right barcode
571
+ * vertices[3] x, y bottom right barcode
572
+ * vertices[4] x, y top left codeword area
573
+ * vertices[5] x, y bottom left codeword area
574
+ * vertices[6] x, y top right codeword area
575
+ * vertices[7] x, y bottom right codeword area
576
+ * @return the module size.
577
+ */
578
+ float Detector::computeModuleWidth(ArrayRef< Ref<ResultPoint> >& vertices) {
579
+ float pixels1 = ResultPoint::distance(vertices[0], vertices[4]);
580
+ float pixels2 = ResultPoint::distance(vertices[1], vertices[5]);
581
+ float moduleWidth1 = (pixels1 + pixels2) / (17 * 2.0f);
582
+ float pixels3 = ResultPoint::distance(vertices[6], vertices[2]);
583
+ float pixels4 = ResultPoint::distance(vertices[7], vertices[3]);
584
+ float moduleWidth2 = (pixels3 + pixels4) / (18 * 2.0f);
585
+ return (moduleWidth1 + moduleWidth2) / 2.0f;
586
+ }
587
+
588
+ /**
589
+ * Computes the dimension (number of modules in a row) of the PDF417 Code
590
+ * based on vertices of the codeword area and estimated module size.
591
+ *
592
+ * @param topLeft of codeword area
593
+ * @param topRight of codeword area
594
+ * @param bottomLeft of codeword area
595
+ * @param bottomRight of codeword are
596
+ * @param moduleWidth estimated module size
597
+ * @return the number of modules in a row.
598
+ */
599
+ int Detector::computeDimension(Ref<ResultPoint> const& topLeft,
600
+ Ref<ResultPoint> const& topRight,
601
+ Ref<ResultPoint> const& bottomLeft,
602
+ Ref<ResultPoint> const& bottomRight,
603
+ float moduleWidth)
604
+ {
605
+ int topRowDimension = MathUtils::round(ResultPoint::distance(topLeft, topRight) / moduleWidth);
606
+ int bottomRowDimension =
607
+ MathUtils::round(ResultPoint::distance(bottomLeft, bottomRight) / moduleWidth);
608
+ return ((((topRowDimension + bottomRowDimension) >> 1) + 8) / 17) * 17;
609
+ }
610
+
611
+ /**
612
+ * Computes the y dimension (number of modules in a column) of the PDF417 Code
613
+ * based on vertices of the codeword area and estimated module size.
614
+ *
615
+ * @param topLeft of codeword area
616
+ * @param topRight of codeword area
617
+ * @param bottomLeft of codeword area
618
+ * @param bottomRight of codeword are
619
+ * @param moduleWidth estimated module size
620
+ * @return the number of modules in a row.
621
+ */
622
+ int Detector::computeYDimension(Ref<ResultPoint> const& topLeft,
623
+ Ref<ResultPoint> const& topRight,
624
+ Ref<ResultPoint> const& bottomLeft,
625
+ Ref<ResultPoint> const& bottomRight,
626
+ float moduleWidth)
627
+ {
628
+ int leftColumnDimension =
629
+ MathUtils::round(ResultPoint::distance(topLeft, bottomLeft) / moduleWidth);
630
+ int rightColumnDimension =
631
+ MathUtils::round(ResultPoint::distance(topRight, bottomRight) / moduleWidth);
632
+ return (leftColumnDimension + rightColumnDimension) >> 1;
633
+ }
634
+
635
+ /**
636
+ * Deskew and over-sample image.
637
+ *
638
+ * @param vertices vertices from findVertices()
639
+ * @param dimension x dimension
640
+ * @param yDimension y dimension
641
+ * @return an over-sampled BitMatrix.
642
+ */
643
+ Ref<BitMatrix> Detector::sampleLines(ArrayRef< Ref<ResultPoint> > const& vertices,
644
+ int dimensionY,
645
+ int dimension) {
646
+ const int sampleDimensionX = dimension * 8;
647
+ const int sampleDimensionY = dimensionY * 4;
648
+ Ref<PerspectiveTransform> transform(
649
+ PerspectiveTransform::quadrilateralToQuadrilateral(
650
+ 0.0f, 0.0f,
651
+ (float)sampleDimensionX, 0.0f,
652
+ 0.0f, (float)sampleDimensionY,
653
+ (float)sampleDimensionX, (float)sampleDimensionY,
654
+ vertices[12]->getX(), vertices[12]->getY(),
655
+ vertices[14]->getX(), vertices[14]->getY(),
656
+ vertices[13]->getX(), vertices[13]->getY(),
657
+ vertices[15]->getX(), vertices[15]->getY()));
658
+
659
+ Ref<BitMatrix> linesMatrix = GridSampler::getInstance().sampleGrid(
660
+ image_->getBlackMatrix(), sampleDimensionX, sampleDimensionY, transform);
661
+
662
+
663
+ return linesMatrix;
664
+ }