react-native-nitro-zxing 0.1.0-alpha.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 (423) hide show
  1. package/README.md +34 -0
  2. package/VisionCameraZxing.podspec +48 -0
  3. package/android/CMakeLists.txt +43 -0
  4. package/android/build.gradle +150 -0
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +3 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +7 -0
  9. package/android/src/main/java/com/margelo/nitro/camera/zxing/VisionCameraZxingPackage.kt +21 -0
  10. package/cpp/BarcodeValueTypeClassifier.cpp +70 -0
  11. package/cpp/BarcodeValueTypeClassifier.hpp +14 -0
  12. package/cpp/FrameImageView.cpp +75 -0
  13. package/cpp/FrameImageView.hpp +34 -0
  14. package/cpp/HybridBarcode.cpp +59 -0
  15. package/cpp/HybridBarcode.hpp +26 -0
  16. package/cpp/HybridBarcodeScanner.cpp +121 -0
  17. package/cpp/HybridBarcodeScanner.hpp +26 -0
  18. package/cpp/HybridBarcodeScannerFactory.cpp +11 -0
  19. package/cpp/HybridBarcodeScannerFactory.hpp +14 -0
  20. package/cpp/ImageDownscaler.cpp +34 -0
  21. package/cpp/ImageDownscaler.hpp +21 -0
  22. package/cpp/ZXingDecoder.cpp +189 -0
  23. package/cpp/ZXingDecoder.hpp +72 -0
  24. package/cpp/zxing-core/LICENSE +202 -0
  25. package/cpp/zxing-core/README.md +156 -0
  26. package/cpp/zxing-core/core/CMakeLists.txt +784 -0
  27. package/cpp/zxing-core/core/Version.h.in +28 -0
  28. package/cpp/zxing-core/core/ZXingConfig.cmake.in +9 -0
  29. package/cpp/zxing-core/core/src/Barcode.cpp +255 -0
  30. package/cpp/zxing-core/core/src/Barcode.h +191 -0
  31. package/cpp/zxing-core/core/src/BarcodeData.h +100 -0
  32. package/cpp/zxing-core/core/src/BarcodeFormat.cpp +286 -0
  33. package/cpp/zxing-core/core/src/BarcodeFormat.h +272 -0
  34. package/cpp/zxing-core/core/src/BinaryBitmap.cpp +111 -0
  35. package/cpp/zxing-core/core/src/BinaryBitmap.h +66 -0
  36. package/cpp/zxing-core/core/src/BitArray.cpp +38 -0
  37. package/cpp/zxing-core/core/src/BitArray.h +181 -0
  38. package/cpp/zxing-core/core/src/BitMatrix.cpp +175 -0
  39. package/cpp/zxing-core/core/src/BitMatrix.h +199 -0
  40. package/cpp/zxing-core/core/src/BitMatrixCursor.h +253 -0
  41. package/cpp/zxing-core/core/src/BitMatrixIO.cpp +101 -0
  42. package/cpp/zxing-core/core/src/BitMatrixIO.h +21 -0
  43. package/cpp/zxing-core/core/src/BitSource.cpp +77 -0
  44. package/cpp/zxing-core/core/src/BitSource.h +72 -0
  45. package/cpp/zxing-core/core/src/ByteArray.h +42 -0
  46. package/cpp/zxing-core/core/src/CharacterSet.cpp +78 -0
  47. package/cpp/zxing-core/core/src/CharacterSet.h +58 -0
  48. package/cpp/zxing-core/core/src/ConcentricFinder.cpp +312 -0
  49. package/cpp/zxing-core/core/src/ConcentricFinder.h +156 -0
  50. package/cpp/zxing-core/core/src/Content.cpp +471 -0
  51. package/cpp/zxing-core/core/src/Content.h +82 -0
  52. package/cpp/zxing-core/core/src/ContentType.h +19 -0
  53. package/cpp/zxing-core/core/src/CreateBarcode.cpp +490 -0
  54. package/cpp/zxing-core/core/src/CreateBarcode.h +132 -0
  55. package/cpp/zxing-core/core/src/DecoderResult.h +92 -0
  56. package/cpp/zxing-core/core/src/DetectorResult.h +44 -0
  57. package/cpp/zxing-core/core/src/ECI.cpp +81 -0
  58. package/cpp/zxing-core/core/src/ECI.h +78 -0
  59. package/cpp/zxing-core/core/src/Error.cpp +29 -0
  60. package/cpp/zxing-core/core/src/Error.h +79 -0
  61. package/cpp/zxing-core/core/src/Flags.h +165 -0
  62. package/cpp/zxing-core/core/src/GTIN.cpp +253 -0
  63. package/cpp/zxing-core/core/src/GTIN.h +58 -0
  64. package/cpp/zxing-core/core/src/GlobalHistogramBinarizer.cpp +197 -0
  65. package/cpp/zxing-core/core/src/GlobalHistogramBinarizer.h +34 -0
  66. package/cpp/zxing-core/core/src/GridSampler.cpp +124 -0
  67. package/cpp/zxing-core/core/src/GridSampler.h +59 -0
  68. package/cpp/zxing-core/core/src/HRI.cpp +343 -0
  69. package/cpp/zxing-core/core/src/HRI.h +16 -0
  70. package/cpp/zxing-core/core/src/HybridBinarizer.cpp +315 -0
  71. package/cpp/zxing-core/core/src/HybridBinarizer.h +40 -0
  72. package/cpp/zxing-core/core/src/ImageView.h +168 -0
  73. package/cpp/zxing-core/core/src/JSON.cpp +154 -0
  74. package/cpp/zxing-core/core/src/JSON.h +66 -0
  75. package/cpp/zxing-core/core/src/LocalGrid.cpp +242 -0
  76. package/cpp/zxing-core/core/src/LocalGrid.h +91 -0
  77. package/cpp/zxing-core/core/src/LogMatrix.h +105 -0
  78. package/cpp/zxing-core/core/src/Matrix.h +125 -0
  79. package/cpp/zxing-core/core/src/MultiFormatReader.cpp +107 -0
  80. package/cpp/zxing-core/core/src/MultiFormatReader.h +34 -0
  81. package/cpp/zxing-core/core/src/MultiFormatWriter.cpp +111 -0
  82. package/cpp/zxing-core/core/src/MultiFormatWriter.h +62 -0
  83. package/cpp/zxing-core/core/src/Pattern.h +472 -0
  84. package/cpp/zxing-core/core/src/PerspectiveTransform.cpp +81 -0
  85. package/cpp/zxing-core/core/src/PerspectiveTransform.h +47 -0
  86. package/cpp/zxing-core/core/src/Point.h +185 -0
  87. package/cpp/zxing-core/core/src/Quadrilateral.h +215 -0
  88. package/cpp/zxing-core/core/src/Range.h +112 -0
  89. package/cpp/zxing-core/core/src/ReadBarcode.cpp +335 -0
  90. package/cpp/zxing-core/core/src/ReadBarcode.h +33 -0
  91. package/cpp/zxing-core/core/src/Reader.h +32 -0
  92. package/cpp/zxing-core/core/src/ReaderOptions.h +210 -0
  93. package/cpp/zxing-core/core/src/ReedSolomon.cpp +100 -0
  94. package/cpp/zxing-core/core/src/ReedSolomon.h +66 -0
  95. package/cpp/zxing-core/core/src/RegressionLine.h +161 -0
  96. package/cpp/zxing-core/core/src/ResultPoint.cpp +20 -0
  97. package/cpp/zxing-core/core/src/ResultPoint.h +35 -0
  98. package/cpp/zxing-core/core/src/StdGenerator.h +121 -0
  99. package/cpp/zxing-core/core/src/StdPrint.h +38 -0
  100. package/cpp/zxing-core/core/src/StdScope.h +55 -0
  101. package/cpp/zxing-core/core/src/StructuredAppend.h +19 -0
  102. package/cpp/zxing-core/core/src/SymbologyIdentifier.h +29 -0
  103. package/cpp/zxing-core/core/src/TextDecoder.cpp +59 -0
  104. package/cpp/zxing-core/core/src/TextDecoder.h +23 -0
  105. package/cpp/zxing-core/core/src/TextEncoder.cpp +75 -0
  106. package/cpp/zxing-core/core/src/TextEncoder.h +31 -0
  107. package/cpp/zxing-core/core/src/ThresholdBinarizer.h +58 -0
  108. package/cpp/zxing-core/core/src/TritMatrix.h +29 -0
  109. package/cpp/zxing-core/core/src/Utf.cpp +276 -0
  110. package/cpp/zxing-core/core/src/Utf.h +26 -0
  111. package/cpp/zxing-core/core/src/WhiteRectDetector.cpp +276 -0
  112. package/cpp/zxing-core/core/src/WhiteRectDetector.h +36 -0
  113. package/cpp/zxing-core/core/src/WriteBarcode.cpp +213 -0
  114. package/cpp/zxing-core/core/src/WriteBarcode.h +72 -0
  115. package/cpp/zxing-core/core/src/ZXAlgorithms.h +353 -0
  116. package/cpp/zxing-core/core/src/ZXConfig.h +17 -0
  117. package/cpp/zxing-core/core/src/ZXTestSupport.h +9 -0
  118. package/cpp/zxing-core/core/src/ZXVersion.h +14 -0
  119. package/cpp/zxing-core/core/src/ZXingC.cpp +460 -0
  120. package/cpp/zxing-core/core/src/ZXingC.h +296 -0
  121. package/cpp/zxing-core/core/src/ZXingCpp.cpp +18 -0
  122. package/cpp/zxing-core/core/src/ZXingCpp.h +76 -0
  123. package/cpp/zxing-core/core/src/ZXingQt.h +606 -0
  124. package/cpp/zxing-core/core/src/aztec/AZDecoder.cpp +376 -0
  125. package/cpp/zxing-core/core/src/aztec/AZDecoder.h +20 -0
  126. package/cpp/zxing-core/core/src/aztec/AZDetector.cpp +508 -0
  127. package/cpp/zxing-core/core/src/aztec/AZDetector.h +25 -0
  128. package/cpp/zxing-core/core/src/aztec/AZDetectorResult.h +51 -0
  129. package/cpp/zxing-core/core/src/aztec/AZEncoder.cpp +318 -0
  130. package/cpp/zxing-core/core/src/aztec/AZEncoder.h +44 -0
  131. package/cpp/zxing-core/core/src/aztec/AZEncodingState.h +40 -0
  132. package/cpp/zxing-core/core/src/aztec/AZHighLevelEncoder.cpp +377 -0
  133. package/cpp/zxing-core/core/src/aztec/AZHighLevelEncoder.h +36 -0
  134. package/cpp/zxing-core/core/src/aztec/AZReader.cpp +45 -0
  135. package/cpp/zxing-core/core/src/aztec/AZReader.h +21 -0
  136. package/cpp/zxing-core/core/src/aztec/AZToken.cpp +44 -0
  137. package/cpp/zxing-core/core/src/aztec/AZToken.h +39 -0
  138. package/cpp/zxing-core/core/src/aztec/AZWriter.cpp +38 -0
  139. package/cpp/zxing-core/core/src/aztec/AZWriter.h +55 -0
  140. package/cpp/zxing-core/core/src/datamatrix/DMBitLayout.cpp +194 -0
  141. package/cpp/zxing-core/core/src/datamatrix/DMBitLayout.h +21 -0
  142. package/cpp/zxing-core/core/src/datamatrix/DMDataBlock.cpp +63 -0
  143. package/cpp/zxing-core/core/src/datamatrix/DMDataBlock.h +41 -0
  144. package/cpp/zxing-core/core/src/datamatrix/DMDecoder.cpp +457 -0
  145. package/cpp/zxing-core/core/src/datamatrix/DMDecoder.h +19 -0
  146. package/cpp/zxing-core/core/src/datamatrix/DMDetector.cpp +1230 -0
  147. package/cpp/zxing-core/core/src/datamatrix/DMDetector.h +23 -0
  148. package/cpp/zxing-core/core/src/datamatrix/DMECEncoder.cpp +137 -0
  149. package/cpp/zxing-core/core/src/datamatrix/DMECEncoder.h +26 -0
  150. package/cpp/zxing-core/core/src/datamatrix/DMEncoderContext.h +128 -0
  151. package/cpp/zxing-core/core/src/datamatrix/DMHighLevelEncoder.cpp +919 -0
  152. package/cpp/zxing-core/core/src/datamatrix/DMHighLevelEncoder.h +29 -0
  153. package/cpp/zxing-core/core/src/datamatrix/DMReader.cpp +40 -0
  154. package/cpp/zxing-core/core/src/datamatrix/DMReader.h +21 -0
  155. package/cpp/zxing-core/core/src/datamatrix/DMSymbolInfo.cpp +141 -0
  156. package/cpp/zxing-core/core/src/datamatrix/DMSymbolInfo.h +78 -0
  157. package/cpp/zxing-core/core/src/datamatrix/DMSymbolShape.h +17 -0
  158. package/cpp/zxing-core/core/src/datamatrix/DMVersion.cpp +82 -0
  159. package/cpp/zxing-core/core/src/datamatrix/DMVersion.h +76 -0
  160. package/cpp/zxing-core/core/src/datamatrix/DMWriter.cpp +114 -0
  161. package/cpp/zxing-core/core/src/datamatrix/DMWriter.h +62 -0
  162. package/cpp/zxing-core/core/src/librscpp/README.md +65 -0
  163. package/cpp/zxing-core/core/src/librscpp/decode.h +258 -0
  164. package/cpp/zxing-core/core/src/librscpp/encode.h +124 -0
  165. package/cpp/zxing-core/core/src/librscpp/field.h +158 -0
  166. package/cpp/zxing-core/core/src/librscpp/poly.h +194 -0
  167. package/cpp/zxing-core/core/src/libzint/2of5inter.c +1 -0
  168. package/cpp/zxing-core/core/src/libzint/2of5inter_based.c +1 -0
  169. package/cpp/zxing-core/core/src/libzint/aztec.c +1 -0
  170. package/cpp/zxing-core/core/src/libzint/aztec.h +1 -0
  171. package/cpp/zxing-core/core/src/libzint/big5.h +1 -0
  172. package/cpp/zxing-core/core/src/libzint/codabar.c +1 -0
  173. package/cpp/zxing-core/core/src/libzint/code.c +1 -0
  174. package/cpp/zxing-core/core/src/libzint/code128.c +1 -0
  175. package/cpp/zxing-core/core/src/libzint/code128.h +1 -0
  176. package/cpp/zxing-core/core/src/libzint/common.c +1 -0
  177. package/cpp/zxing-core/core/src/libzint/common.h +1 -0
  178. package/cpp/zxing-core/core/src/libzint/dmatrix.c +1 -0
  179. package/cpp/zxing-core/core/src/libzint/dmatrix.h +1 -0
  180. package/cpp/zxing-core/core/src/libzint/dxfilmedge.c +1 -0
  181. package/cpp/zxing-core/core/src/libzint/eci.c +1 -0
  182. package/cpp/zxing-core/core/src/libzint/eci.h +1 -0
  183. package/cpp/zxing-core/core/src/libzint/eci_sb.h +1 -0
  184. package/cpp/zxing-core/core/src/libzint/filemem.c +1 -0
  185. package/cpp/zxing-core/core/src/libzint/filemem.h +1 -0
  186. package/cpp/zxing-core/core/src/libzint/fonts/normal_woff2.h +1 -0
  187. package/cpp/zxing-core/core/src/libzint/fonts/upcean_woff2.h +1 -0
  188. package/cpp/zxing-core/core/src/libzint/gb18030.h +1 -0
  189. package/cpp/zxing-core/core/src/libzint/gb2312.h +1 -0
  190. package/cpp/zxing-core/core/src/libzint/gbk.h +1 -0
  191. package/cpp/zxing-core/core/src/libzint/general_field.c +1 -0
  192. package/cpp/zxing-core/core/src/libzint/general_field.h +1 -0
  193. package/cpp/zxing-core/core/src/libzint/gs1.c +1 -0
  194. package/cpp/zxing-core/core/src/libzint/gs1.h +1 -0
  195. package/cpp/zxing-core/core/src/libzint/gs1_lint.h +1 -0
  196. package/cpp/zxing-core/core/src/libzint/iso3166.h +1 -0
  197. package/cpp/zxing-core/core/src/libzint/iso4217.h +1 -0
  198. package/cpp/zxing-core/core/src/libzint/ksx1001.h +1 -0
  199. package/cpp/zxing-core/core/src/libzint/large.c +1 -0
  200. package/cpp/zxing-core/core/src/libzint/large.h +1 -0
  201. package/cpp/zxing-core/core/src/libzint/library.c +1 -0
  202. package/cpp/zxing-core/core/src/libzint/maxicode.c +1 -0
  203. package/cpp/zxing-core/core/src/libzint/maxicode.h +1 -0
  204. package/cpp/zxing-core/core/src/libzint/medical.c +1 -0
  205. package/cpp/zxing-core/core/src/libzint/output.c +1 -0
  206. package/cpp/zxing-core/core/src/libzint/output.h +1 -0
  207. package/cpp/zxing-core/core/src/libzint/pdf417.c +1 -0
  208. package/cpp/zxing-core/core/src/libzint/pdf417.h +1 -0
  209. package/cpp/zxing-core/core/src/libzint/pdf417_tabs.h +1 -0
  210. package/cpp/zxing-core/core/src/libzint/qr.c +1 -0
  211. package/cpp/zxing-core/core/src/libzint/qr.h +1 -0
  212. package/cpp/zxing-core/core/src/libzint/raster.c +1 -0
  213. package/cpp/zxing-core/core/src/libzint/raster_font.h +1 -0
  214. package/cpp/zxing-core/core/src/libzint/reedsol.c +1 -0
  215. package/cpp/zxing-core/core/src/libzint/reedsol.h +1 -0
  216. package/cpp/zxing-core/core/src/libzint/reedsol_logs.h +1 -0
  217. package/cpp/zxing-core/core/src/libzint/rss.c +1 -0
  218. package/cpp/zxing-core/core/src/libzint/rss.h +1 -0
  219. package/cpp/zxing-core/core/src/libzint/sjis.h +1 -0
  220. package/cpp/zxing-core/core/src/libzint/stubs.c +137 -0
  221. package/cpp/zxing-core/core/src/libzint/svg.c +1 -0
  222. package/cpp/zxing-core/core/src/libzint/telepen.c +1 -0
  223. package/cpp/zxing-core/core/src/libzint/upcean.c +1 -0
  224. package/cpp/zxing-core/core/src/libzint/vector.c +1 -0
  225. package/cpp/zxing-core/core/src/libzint/zfiletypes.h +1 -0
  226. package/cpp/zxing-core/core/src/libzint/zint.h +1 -0
  227. package/cpp/zxing-core/core/src/libzint/zintconfig.h +1 -0
  228. package/cpp/zxing-core/core/src/libzueci/README.md +11 -0
  229. package/cpp/zxing-core/core/src/libzueci/zueci.c +1718 -0
  230. package/cpp/zxing-core/core/src/libzueci/zueci.h +179 -0
  231. package/cpp/zxing-core/core/src/libzueci/zueci_big5.h +3884 -0
  232. package/cpp/zxing-core/core/src/libzueci/zueci_common.h +31 -0
  233. package/cpp/zxing-core/core/src/libzueci/zueci_gb18030.h +264 -0
  234. package/cpp/zxing-core/core/src/libzueci/zueci_gb2312.h +2381 -0
  235. package/cpp/zxing-core/core/src/libzueci/zueci_gbk.h +4047 -0
  236. package/cpp/zxing-core/core/src/libzueci/zueci_ksx1001.h +2932 -0
  237. package/cpp/zxing-core/core/src/libzueci/zueci_sb.h +1112 -0
  238. package/cpp/zxing-core/core/src/libzueci/zueci_sjis.h +2286 -0
  239. package/cpp/zxing-core/core/src/maxicode/MCBitMatrixParser.cpp +68 -0
  240. package/cpp/zxing-core/core/src/maxicode/MCBitMatrixParser.h +30 -0
  241. package/cpp/zxing-core/core/src/maxicode/MCDecoder.cpp +329 -0
  242. package/cpp/zxing-core/core/src/maxicode/MCDecoder.h +19 -0
  243. package/cpp/zxing-core/core/src/maxicode/MCReader.cpp +65 -0
  244. package/cpp/zxing-core/core/src/maxicode/MCReader.h +21 -0
  245. package/cpp/zxing-core/core/src/oned/ODCodabarReader.cpp +102 -0
  246. package/cpp/zxing-core/core/src/oned/ODCodabarReader.h +21 -0
  247. package/cpp/zxing-core/core/src/oned/ODCodabarWriter.cpp +136 -0
  248. package/cpp/zxing-core/core/src/oned/ODCodabarWriter.h +34 -0
  249. package/cpp/zxing-core/core/src/oned/ODCode128Patterns.h +130 -0
  250. package/cpp/zxing-core/core/src/oned/ODCode128Reader.cpp +236 -0
  251. package/cpp/zxing-core/core/src/oned/ODCode128Reader.h +21 -0
  252. package/cpp/zxing-core/core/src/oned/ODCode128Writer.cpp +261 -0
  253. package/cpp/zxing-core/core/src/oned/ODCode128Writer.h +34 -0
  254. package/cpp/zxing-core/core/src/oned/ODCode39Reader.cpp +213 -0
  255. package/cpp/zxing-core/core/src/oned/ODCode39Reader.h +26 -0
  256. package/cpp/zxing-core/core/src/oned/ODCode39Writer.cpp +176 -0
  257. package/cpp/zxing-core/core/src/oned/ODCode39Writer.h +34 -0
  258. package/cpp/zxing-core/core/src/oned/ODCode93Patterns.h +80 -0
  259. package/cpp/zxing-core/core/src/oned/ODCode93Reader.cpp +112 -0
  260. package/cpp/zxing-core/core/src/oned/ODCode93Reader.h +21 -0
  261. package/cpp/zxing-core/core/src/oned/ODCode93Writer.cpp +192 -0
  262. package/cpp/zxing-core/core/src/oned/ODCode93Writer.h +32 -0
  263. package/cpp/zxing-core/core/src/oned/ODDXFilmEdgeReader.cpp +246 -0
  264. package/cpp/zxing-core/core/src/oned/ODDXFilmEdgeReader.h +26 -0
  265. package/cpp/zxing-core/core/src/oned/ODDataBarCommon.cpp +172 -0
  266. package/cpp/zxing-core/core/src/oned/ODDataBarCommon.h +204 -0
  267. package/cpp/zxing-core/core/src/oned/ODDataBarExpandedBitDecoder.cpp +253 -0
  268. package/cpp/zxing-core/core/src/oned/ODDataBarExpandedBitDecoder.h +19 -0
  269. package/cpp/zxing-core/core/src/oned/ODDataBarExpandedReader.cpp +383 -0
  270. package/cpp/zxing-core/core/src/oned/ODDataBarExpandedReader.h +25 -0
  271. package/cpp/zxing-core/core/src/oned/ODDataBarLimitedReader.cpp +163 -0
  272. package/cpp/zxing-core/core/src/oned/ODDataBarLimitedReader.h +23 -0
  273. package/cpp/zxing-core/core/src/oned/ODDataBarReader.cpp +240 -0
  274. package/cpp/zxing-core/core/src/oned/ODDataBarReader.h +25 -0
  275. package/cpp/zxing-core/core/src/oned/ODEAN13Writer.cpp +62 -0
  276. package/cpp/zxing-core/core/src/oned/ODEAN13Writer.h +34 -0
  277. package/cpp/zxing-core/core/src/oned/ODEAN8Writer.cpp +51 -0
  278. package/cpp/zxing-core/core/src/oned/ODEAN8Writer.h +34 -0
  279. package/cpp/zxing-core/core/src/oned/ODITFReader.cpp +97 -0
  280. package/cpp/zxing-core/core/src/oned/ODITFReader.h +33 -0
  281. package/cpp/zxing-core/core/src/oned/ODITFWriter.cpp +78 -0
  282. package/cpp/zxing-core/core/src/oned/ODITFWriter.h +34 -0
  283. package/cpp/zxing-core/core/src/oned/ODMultiUPCEANReader.cpp +323 -0
  284. package/cpp/zxing-core/core/src/oned/ODMultiUPCEANReader.h +32 -0
  285. package/cpp/zxing-core/core/src/oned/ODReader.cpp +259 -0
  286. package/cpp/zxing-core/core/src/oned/ODReader.h +35 -0
  287. package/cpp/zxing-core/core/src/oned/ODRowReader.h +222 -0
  288. package/cpp/zxing-core/core/src/oned/ODTelepenReader.cpp +199 -0
  289. package/cpp/zxing-core/core/src/oned/ODTelepenReader.h +25 -0
  290. package/cpp/zxing-core/core/src/oned/ODUPCAWriter.cpp +33 -0
  291. package/cpp/zxing-core/core/src/oned/ODUPCAWriter.h +34 -0
  292. package/cpp/zxing-core/core/src/oned/ODUPCEANCommon.cpp +80 -0
  293. package/cpp/zxing-core/core/src/oned/ODUPCEANCommon.h +129 -0
  294. package/cpp/zxing-core/core/src/oned/ODUPCEWriter.cpp +56 -0
  295. package/cpp/zxing-core/core/src/oned/ODUPCEWriter.h +34 -0
  296. package/cpp/zxing-core/core/src/oned/ODWriterHelper.cpp +39 -0
  297. package/cpp/zxing-core/core/src/oned/ODWriterHelper.h +48 -0
  298. package/cpp/zxing-core/core/src/pdf417/MicroPDFReader.cpp +796 -0
  299. package/cpp/zxing-core/core/src/pdf417/MicroPDFReader.h +23 -0
  300. package/cpp/zxing-core/core/src/pdf417/PDF417.cpp +85 -0
  301. package/cpp/zxing-core/core/src/pdf417/PDF417.h +81 -0
  302. package/cpp/zxing-core/core/src/pdf417/PDFBarcodeMetadata.h +53 -0
  303. package/cpp/zxing-core/core/src/pdf417/PDFBarcodeValue.cpp +48 -0
  304. package/cpp/zxing-core/core/src/pdf417/PDFBarcodeValue.h +38 -0
  305. package/cpp/zxing-core/core/src/pdf417/PDFBoundingBox.cpp +116 -0
  306. package/cpp/zxing-core/core/src/pdf417/PDFBoundingBox.h +75 -0
  307. package/cpp/zxing-core/core/src/pdf417/PDFCodeword.h +71 -0
  308. package/cpp/zxing-core/core/src/pdf417/PDFCodewordDecoder.cpp +588 -0
  309. package/cpp/zxing-core/core/src/pdf417/PDFCodewordDecoder.h +41 -0
  310. package/cpp/zxing-core/core/src/pdf417/PDFCompaction.h +20 -0
  311. package/cpp/zxing-core/core/src/pdf417/PDFCustomData.h +32 -0
  312. package/cpp/zxing-core/core/src/pdf417/PDFDecoder.cpp +725 -0
  313. package/cpp/zxing-core/core/src/pdf417/PDFDecoder.h +20 -0
  314. package/cpp/zxing-core/core/src/pdf417/PDFDetectionResult.cpp +247 -0
  315. package/cpp/zxing-core/core/src/pdf417/PDFDetectionResult.h +74 -0
  316. package/cpp/zxing-core/core/src/pdf417/PDFDetectionResultColumn.cpp +321 -0
  317. package/cpp/zxing-core/core/src/pdf417/PDFDetectionResultColumn.h +83 -0
  318. package/cpp/zxing-core/core/src/pdf417/PDFDetector.cpp +371 -0
  319. package/cpp/zxing-core/core/src/pdf417/PDFDetector.h +45 -0
  320. package/cpp/zxing-core/core/src/pdf417/PDFEncoder.cpp +570 -0
  321. package/cpp/zxing-core/core/src/pdf417/PDFEncoder.h +182 -0
  322. package/cpp/zxing-core/core/src/pdf417/PDFHighLevelEncoder.cpp +570 -0
  323. package/cpp/zxing-core/core/src/pdf417/PDFHighLevelEncoder.h +32 -0
  324. package/cpp/zxing-core/core/src/pdf417/PDFReader.cpp +333 -0
  325. package/cpp/zxing-core/core/src/pdf417/PDFReader.h +28 -0
  326. package/cpp/zxing-core/core/src/pdf417/PDFScanningDecoder.cpp +559 -0
  327. package/cpp/zxing-core/core/src/pdf417/PDFScanningDecoder.h +41 -0
  328. package/cpp/zxing-core/core/src/pdf417/PDFWriter.cpp +170 -0
  329. package/cpp/zxing-core/core/src/pdf417/PDFWriter.h +74 -0
  330. package/cpp/zxing-core/core/src/pdf417/ZXBigInteger.cpp +623 -0
  331. package/cpp/zxing-core/core/src/pdf417/ZXBigInteger.h +81 -0
  332. package/cpp/zxing-core/core/src/pdf417/ZXNullable.h +105 -0
  333. package/cpp/zxing-core/core/src/qrcode/QRBitMatrixParser.cpp +294 -0
  334. package/cpp/zxing-core/core/src/qrcode/QRBitMatrixParser.h +41 -0
  335. package/cpp/zxing-core/core/src/qrcode/QRCodecMode.cpp +95 -0
  336. package/cpp/zxing-core/core/src/qrcode/QRCodecMode.h +59 -0
  337. package/cpp/zxing-core/core/src/qrcode/QRDataBlock.cpp +93 -0
  338. package/cpp/zxing-core/core/src/qrcode/QRDataBlock.h +52 -0
  339. package/cpp/zxing-core/core/src/qrcode/QRDataMask.h +50 -0
  340. package/cpp/zxing-core/core/src/qrcode/QRDecoder.cpp +359 -0
  341. package/cpp/zxing-core/core/src/qrcode/QRDecoder.h +19 -0
  342. package/cpp/zxing-core/core/src/qrcode/QRDetector.cpp +920 -0
  343. package/cpp/zxing-core/core/src/qrcode/QRDetector.h +45 -0
  344. package/cpp/zxing-core/core/src/qrcode/QRECB.h +52 -0
  345. package/cpp/zxing-core/core/src/qrcode/QREncodeResult.h +33 -0
  346. package/cpp/zxing-core/core/src/qrcode/QREncoder.cpp +568 -0
  347. package/cpp/zxing-core/core/src/qrcode/QREncoder.h +21 -0
  348. package/cpp/zxing-core/core/src/qrcode/QRErrorCorrectionLevel.cpp +51 -0
  349. package/cpp/zxing-core/core/src/qrcode/QRErrorCorrectionLevel.h +39 -0
  350. package/cpp/zxing-core/core/src/qrcode/QRFormatInformation.cpp +160 -0
  351. package/cpp/zxing-core/core/src/qrcode/QRFormatInformation.h +61 -0
  352. package/cpp/zxing-core/core/src/qrcode/QRMaskUtil.cpp +156 -0
  353. package/cpp/zxing-core/core/src/qrcode/QRMaskUtil.h +15 -0
  354. package/cpp/zxing-core/core/src/qrcode/QRMatrixUtil.cpp +318 -0
  355. package/cpp/zxing-core/core/src/qrcode/QRMatrixUtil.h +25 -0
  356. package/cpp/zxing-core/core/src/qrcode/QRReader.cpp +149 -0
  357. package/cpp/zxing-core/core/src/qrcode/QRReader.h +21 -0
  358. package/cpp/zxing-core/core/src/qrcode/QRVersion.cpp +754 -0
  359. package/cpp/zxing-core/core/src/qrcode/QRVersion.h +127 -0
  360. package/cpp/zxing-core/core/src/qrcode/QRWriter.cpp +51 -0
  361. package/cpp/zxing-core/core/src/qrcode/QRWriter.h +74 -0
  362. package/cpp/zxing-core/core/version.rc.in +34 -0
  363. package/cpp/zxing-core/core/zxing.pc.in +8 -0
  364. package/cpp/zxing-core/wrappers/ios/README.md +25 -0
  365. package/cpp/zxing-core/wrappers/ios/Sources/Wrapper/Version.h +29 -0
  366. package/cpp/zxing-core/zxing-cpp.podspec +45 -0
  367. package/lib/factory.d.ts +10 -0
  368. package/lib/factory.js +12 -0
  369. package/lib/index.d.ts +9 -0
  370. package/lib/index.js +9 -0
  371. package/lib/specs/Barcode.nitro.d.ts +63 -0
  372. package/lib/specs/Barcode.nitro.js +1 -0
  373. package/lib/specs/BarcodeFormat.d.ts +11 -0
  374. package/lib/specs/BarcodeFormat.js +1 -0
  375. package/lib/specs/BarcodeScanner.nitro.d.ts +89 -0
  376. package/lib/specs/BarcodeScanner.nitro.js +1 -0
  377. package/lib/specs/BarcodeScannerFactory.nitro.d.ts +26 -0
  378. package/lib/specs/BarcodeScannerFactory.nitro.js +1 -0
  379. package/lib/specs/BarcodeValueType.d.ts +9 -0
  380. package/lib/specs/BarcodeValueType.js +1 -0
  381. package/lib/specs/Point.d.ts +14 -0
  382. package/lib/specs/Point.js +1 -0
  383. package/lib/specs/Rect.d.ts +22 -0
  384. package/lib/specs/Rect.js +1 -0
  385. package/lib/useBarcodeScanner.d.ts +23 -0
  386. package/lib/useBarcodeScanner.js +25 -0
  387. package/nitro.json +20 -0
  388. package/nitrogen/generated/.gitattributes +1 -0
  389. package/nitrogen/generated/android/VisionCameraZxing+autolinking.cmake +83 -0
  390. package/nitrogen/generated/android/VisionCameraZxing+autolinking.gradle +27 -0
  391. package/nitrogen/generated/android/VisionCameraZxingOnLoad.cpp +49 -0
  392. package/nitrogen/generated/android/VisionCameraZxingOnLoad.hpp +34 -0
  393. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/zxing/VisionCameraZxingOnLoad.kt +35 -0
  394. package/nitrogen/generated/ios/VisionCameraZxing+autolinking.rb +62 -0
  395. package/nitrogen/generated/ios/VisionCameraZxing-Swift-Cxx-Bridge.cpp +17 -0
  396. package/nitrogen/generated/ios/VisionCameraZxing-Swift-Cxx-Bridge.hpp +27 -0
  397. package/nitrogen/generated/ios/VisionCameraZxing-Swift-Cxx-Umbrella.hpp +38 -0
  398. package/nitrogen/generated/ios/VisionCameraZxingAutolinking.mm +35 -0
  399. package/nitrogen/generated/ios/VisionCameraZxingAutolinking.swift +16 -0
  400. package/nitrogen/generated/shared/c++/BarcodeFormat.hpp +124 -0
  401. package/nitrogen/generated/shared/c++/BarcodeScannerOptions.hpp +85 -0
  402. package/nitrogen/generated/shared/c++/BarcodeValueType.hpp +120 -0
  403. package/nitrogen/generated/shared/c++/HybridBarcodeScannerSpec.cpp +23 -0
  404. package/nitrogen/generated/shared/c++/HybridBarcodeScannerSpec.hpp +74 -0
  405. package/nitrogen/generated/shared/c++/HybridBarcodeSpec.cpp +27 -0
  406. package/nitrogen/generated/shared/c++/HybridBarcodeSpec.hpp +82 -0
  407. package/nitrogen/generated/shared/c++/HybridZXingBarcodeScannerFactorySpec.cpp +21 -0
  408. package/nitrogen/generated/shared/c++/HybridZXingBarcodeScannerFactorySpec.hpp +67 -0
  409. package/nitrogen/generated/shared/c++/Point.hpp +87 -0
  410. package/nitrogen/generated/shared/c++/Rect.hpp +95 -0
  411. package/nitrogen/generated/shared/c++/TargetBarcodeFormat.hpp +124 -0
  412. package/package.json +108 -0
  413. package/react-native.config.js +16 -0
  414. package/src/factory.ts +26 -0
  415. package/src/index.ts +9 -0
  416. package/src/specs/Barcode.nitro.ts +70 -0
  417. package/src/specs/BarcodeFormat.ts +31 -0
  418. package/src/specs/BarcodeScanner.nitro.ts +91 -0
  419. package/src/specs/BarcodeScannerFactory.nitro.ts +27 -0
  420. package/src/specs/BarcodeValueType.ts +25 -0
  421. package/src/specs/Point.ts +14 -0
  422. package/src/specs/Rect.ts +22 -0
  423. package/src/useBarcodeScanner.ts +36 -0
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright 2016 Nu-book Inc.
3
+ * Copyright 2016 ZXing authors
4
+ * Copyright 2021 Axel Waggershauser
5
+ */
6
+ // SPDX-License-Identifier: Apache-2.0
7
+
8
+ #pragma once
9
+
10
+ #include "ConcentricFinder.h"
11
+ #include "DetectorResult.h"
12
+ #include "StdGenerator.h"
13
+
14
+ #include <vector>
15
+
16
+ namespace ZXing {
17
+
18
+ class DetectorResult;
19
+ class BitMatrix;
20
+
21
+ namespace QRCode {
22
+
23
+ struct FinderPatternSet
24
+ {
25
+ ConcentricPattern bl, tl, tr;
26
+ };
27
+
28
+ using FinderPatterns = std::vector<ConcentricPattern>;
29
+ using FinderPatternSets = std::vector<FinderPatternSet>;
30
+
31
+ FinderPatterns FindFinderPatterns(const BitMatrix& image, bool tryHarder);
32
+ FinderPatternSets GenerateFinderPatternSets(FinderPatterns& patterns);
33
+
34
+ using DetectorResults = std::generator<DetectorResult>;
35
+
36
+ DetectorResults SampleQR(const BitMatrix& image, const FinderPatternSet& fp);
37
+ DetectorResult SampleMQR(const BitMatrix& image, const ConcentricPattern& fp);
38
+ DetectorResult SampleRMQR(const BitMatrix& image, const ConcentricPattern& fp);
39
+
40
+ DetectorResult DetectPureQR(const BitMatrix& image);
41
+ DetectorResult DetectPureMQR(const BitMatrix& image);
42
+ DetectorResult DetectPureRMQR(const BitMatrix& image);
43
+
44
+ } // QRCode
45
+ } // ZXing
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright 2016 Nu-book Inc.
3
+ * Copyright 2016 ZXing authors
4
+ */
5
+ // SPDX-License-Identifier: Apache-2.0
6
+
7
+ #pragma once
8
+
9
+ #include <array>
10
+
11
+ namespace ZXing::QRCode {
12
+
13
+ /**
14
+ * <p>Encapsulates the parameters for one error-correction block in one symbol version.
15
+ * This includes the number of data codewords, and the number of times a block with these
16
+ * parameters is used consecutively in the QR code version's format.</p>
17
+ *
18
+ * @author Sean Owen
19
+ */
20
+ struct ECB
21
+ {
22
+ int count;
23
+ int dataCodewords;
24
+ };
25
+
26
+ /**
27
+ * <p>Encapsulates a set of error-correction blocks in one symbol version. Most versions will
28
+ * use blocks of differing sizes within one version, so, this encapsulates the parameters for
29
+ * each set of blocks. It also holds the number of error-correction codewords per block since it
30
+ * will be the same across all blocks within one version.</p>
31
+ *
32
+ * @author Sean Owen
33
+ */
34
+ struct ECBlocks
35
+ {
36
+ int codewordsPerBlock;
37
+ std::array<ECB, 2> blocks;
38
+
39
+ int numBlocks() const { return blocks[0].count + blocks[1].count; }
40
+
41
+ int totalCodewords() const { return codewordsPerBlock * numBlocks(); }
42
+
43
+ int totalDataCodewords() const
44
+ {
45
+ return blocks[0].count * (blocks[0].dataCodewords + codewordsPerBlock)
46
+ + blocks[1].count * (blocks[1].dataCodewords + codewordsPerBlock);
47
+ }
48
+
49
+ const std::array<ECB, 2>& blockArray() const { return blocks; }
50
+ };
51
+
52
+ } // namespace ZXing::QRCode
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright 2016 Huy Cuong Nguyen
3
+ * Copyright 2016 ZXing authors
4
+ */
5
+ // SPDX-License-Identifier: Apache-2.0
6
+
7
+ #pragma once
8
+
9
+ #include "BitMatrix.h"
10
+ #include "ByteArray.h"
11
+ #include "QRCodecMode.h"
12
+ #include "QRVersion.h"
13
+
14
+ namespace ZXing::QRCode {
15
+
16
+ /**
17
+ * @author satorux@google.com (Satoru Takabayashi) - creator
18
+ * @author dswitkin@google.com (Daniel Switkin) - ported from C++
19
+ *
20
+ * Original class name in Java was QRCode, as this name is taken already for the namespace,
21
+ * so it's renamed here EncodeResult.
22
+ */
23
+ class EncodeResult
24
+ {
25
+ public:
26
+ ErrorCorrectionLevel ecLevel = ErrorCorrectionLevel::Invalid;
27
+ CodecMode mode = CodecMode::TERMINATOR;
28
+ const Version* version = nullptr;
29
+ int maskPattern = -1;
30
+ BitMatrix matrix;
31
+ };
32
+
33
+ } // namespace ZXing::QRCode
@@ -0,0 +1,568 @@
1
+ /*
2
+ * Copyright 2016 Huy Cuong Nguyen
3
+ * Copyright 2016 ZXing authors
4
+ */
5
+ // SPDX-License-Identifier: Apache-2.0
6
+
7
+ #include "QREncoder.h"
8
+
9
+ #include "BitArray.h"
10
+ #include "ECI.h"
11
+ #include "QREncodeResult.h"
12
+ #include "QRErrorCorrectionLevel.h"
13
+ #include "QRMaskUtil.h"
14
+ #include "QRMatrixUtil.h"
15
+ #include "ReedSolomon.h"
16
+ #include "TextEncoder.h"
17
+ #include "ZXTestSupport.h"
18
+ #include "ZXAlgorithms.h"
19
+
20
+ #include <algorithm>
21
+ #include <array>
22
+ #include <limits>
23
+ #include <stdexcept>
24
+
25
+ namespace ZXing::QRCode {
26
+
27
+ static const CharacterSet DEFAULT_BYTE_MODE_ENCODING = CharacterSet::ISO8859_1;
28
+
29
+ // The original table is defined in the table 5 of JISX0510:2004 (p.19).
30
+ static const std::array<int, 16 * 6> ALPHANUMERIC_TABLE = {
31
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00-0x0f
32
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10-0x1f
33
+ 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // 0x20-0x2f
34
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // 0x30-0x3f
35
+ -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x40-0x4f
36
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // 0x50-0x5f
37
+ };
38
+
39
+ static bool IsOnlyDoubleByteKanji(const std::wstring& content)
40
+ {
41
+ std::string bytes = TextEncoder::FromUnicode(content, CharacterSet::Shift_JIS);
42
+ size_t length = bytes.length();
43
+ if (length % 2 != 0) {
44
+ return false;
45
+ }
46
+ for (size_t i = 0; i < length; i += 2) {
47
+ int byte1 = bytes[i] & 0xff;
48
+ if ((byte1 < 0x81 || byte1 > 0x9F) && (byte1 < 0xE0 || byte1 > 0xEB)) {
49
+ return false;
50
+ }
51
+ }
52
+ return true;
53
+ }
54
+
55
+ /**
56
+ * @return the code point of the table used in alphanumeric mode or
57
+ * -1 if there is no corresponding code in the table.
58
+ */
59
+ ZXING_EXPORT_TEST_ONLY
60
+ int GetAlphanumericCode(int code)
61
+ {
62
+ if (code < Size(ALPHANUMERIC_TABLE)) {
63
+ return ALPHANUMERIC_TABLE[code];
64
+ }
65
+ return -1;
66
+ }
67
+
68
+ /**
69
+ * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
70
+ * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
71
+ */
72
+ ZXING_EXPORT_TEST_ONLY
73
+ CodecMode ChooseMode(const std::wstring& content, CharacterSet encoding)
74
+ {
75
+ if (encoding == CharacterSet::Shift_JIS && IsOnlyDoubleByteKanji(content)) {
76
+ // Choose Kanji mode if all input are double-byte characters
77
+ return CodecMode::KANJI;
78
+ }
79
+ bool hasNumeric = false;
80
+ bool hasAlphanumeric = false;
81
+ for (wchar_t c : content) {
82
+ if (IsDigit(c)) {
83
+ hasNumeric = true;
84
+ }
85
+ else if (GetAlphanumericCode(c) != -1) {
86
+ hasAlphanumeric = true;
87
+ }
88
+ else {
89
+ return CodecMode::BYTE;
90
+ }
91
+ }
92
+ if (hasAlphanumeric) {
93
+ return CodecMode::ALPHANUMERIC;
94
+ }
95
+ if (hasNumeric) {
96
+ return CodecMode::NUMERIC;
97
+ }
98
+ return CodecMode::BYTE;
99
+ }
100
+
101
+ /*
102
+ * See ISO/IEC 18004:2015 Table 4
103
+ */
104
+ static void AppendECI(CharacterSet eci, BitArray& bits)
105
+ {
106
+ int eciValue = ToInt(ToECI(eci));
107
+ if (eciValue >= 0 && eciValue <= 999999) {
108
+ bits.appendBits(static_cast<int>(CodecMode::ECI), 4);
109
+ if (eciValue <= 127) {
110
+ bits.appendBits(eciValue, 8);
111
+ }
112
+ else if (eciValue <= 16383) {
113
+ bits.appendBits(0x8000 | eciValue, 16);
114
+ }
115
+ else {
116
+ bits.appendBits(0xC00000 | eciValue, 24);
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Append mode info. On success, store the result in "bits".
123
+ */
124
+ ZXING_EXPORT_TEST_ONLY
125
+ void AppendModeInfo(CodecMode mode, BitArray& bits)
126
+ {
127
+ bits.appendBits(static_cast<int>(mode), 4);
128
+ }
129
+
130
+
131
+ /**
132
+ * Append length info. On success, store the result in "bits".
133
+ */
134
+ ZXING_EXPORT_TEST_ONLY
135
+ void AppendLengthInfo(int numLetters, const Version& version, CodecMode mode, BitArray& bits)
136
+ {
137
+ int numBits = CharacterCountBits(mode, version);
138
+ if (numLetters >= (1 << numBits)) {
139
+ throw std::invalid_argument(std::to_string(numLetters) + " is bigger than " + std::to_string((1 << numBits) - 1));
140
+ }
141
+ bits.appendBits(numLetters, numBits);
142
+ }
143
+
144
+ ZXING_EXPORT_TEST_ONLY
145
+ void AppendNumericBytes(const std::wstring& content, BitArray& bits)
146
+ {
147
+ size_t length = content.length();
148
+ size_t i = 0;
149
+ while (i < length) {
150
+ int num1 = content[i] - '0';
151
+ if (i + 2 < length) {
152
+ // Encode three numeric letters in ten bits.
153
+ int num2 = content[i + 1] - '0';
154
+ int num3 = content[i + 2] - '0';
155
+ bits.appendBits(num1 * 100 + num2 * 10 + num3, 10);
156
+ i += 3;
157
+ }
158
+ else if (i + 1 < length) {
159
+ // Encode two numeric letters in seven bits.
160
+ int num2 = content[i + 1] - '0';
161
+ bits.appendBits(num1 * 10 + num2, 7);
162
+ i += 2;
163
+ }
164
+ else {
165
+ // Encode one numeric letter in four bits.
166
+ bits.appendBits(num1, 4);
167
+ i++;
168
+ }
169
+ }
170
+ }
171
+
172
+ ZXING_EXPORT_TEST_ONLY
173
+ void AppendAlphanumericBytes(const std::wstring& content, BitArray& bits)
174
+ {
175
+ size_t length = content.length();
176
+ size_t i = 0;
177
+ while (i < length) {
178
+ int code1 = GetAlphanumericCode(content[i]);
179
+ if (code1 == -1) {
180
+ throw std::invalid_argument("Unexpected contents");
181
+ }
182
+ if (i + 1 < length) {
183
+ int code2 = GetAlphanumericCode(content[i + 1]);
184
+ if (code2 == -1) {
185
+ throw std::invalid_argument("Unexpected contents");
186
+ }
187
+ // Encode two alphanumeric letters in 11 bits.
188
+ bits.appendBits(code1 * 45 + code2, 11);
189
+ i += 2;
190
+ }
191
+ else {
192
+ // Encode one alphanumeric letter in six bits.
193
+ bits.appendBits(code1, 6);
194
+ i++;
195
+ }
196
+ }
197
+ }
198
+
199
+ ZXING_EXPORT_TEST_ONLY
200
+ void Append8BitBytes(const std::wstring& content, CharacterSet encoding, BitArray& bits)
201
+ {
202
+ for (char b : TextEncoder::FromUnicode(content, encoding)) {
203
+ bits.appendBits(b, 8);
204
+ }
205
+ }
206
+
207
+ ZXING_EXPORT_TEST_ONLY
208
+ void AppendKanjiBytes(const std::wstring& content, BitArray& bits)
209
+ {
210
+ std::string bytes = TextEncoder::FromUnicode(content, CharacterSet::Shift_JIS);
211
+ int length = Size(bytes);
212
+ if (length % 2 != 0) {
213
+ throw std::invalid_argument("Kanji byte size not even");
214
+ }
215
+ --length;
216
+ for (int i = 0; i < length; i += 2) {
217
+ int byte1 = bytes[i] & 0xff;
218
+ int byte2 = bytes[i + 1] & 0xff;
219
+ int code = (byte1 << 8) | byte2;
220
+ int subtracted = -1;
221
+ if (code >= 0x8140 && code <= 0x9ffc) {
222
+ subtracted = code - 0x8140;
223
+ }
224
+ else if (code >= 0xe040 && code <= 0xebbf) {
225
+ subtracted = code - 0xc140;
226
+ }
227
+ if (subtracted == -1) {
228
+ throw std::invalid_argument("Invalid byte sequence");
229
+ }
230
+ int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
231
+ bits.appendBits(encoded, 13);
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
237
+ */
238
+ ZXING_EXPORT_TEST_ONLY
239
+ void AppendBytes(const std::wstring& content, CodecMode mode, CharacterSet encoding, BitArray& bits)
240
+ {
241
+ switch (mode) {
242
+ case CodecMode::NUMERIC: AppendNumericBytes(content, bits); break;
243
+ case CodecMode::ALPHANUMERIC: AppendAlphanumericBytes(content, bits); break;
244
+ case CodecMode::BYTE: Append8BitBytes(content, encoding, bits); break;
245
+ case CodecMode::KANJI: AppendKanjiBytes(content, bits); break;
246
+ default: throw std::invalid_argument("Invalid mode: " + std::to_string(static_cast<int>(mode)));
247
+ }
248
+ }
249
+
250
+ /**
251
+ * @return true if the number of input bits will fit in a code with the specified version and
252
+ * error correction level.
253
+ */
254
+ static bool WillFit(int numInputBits, const Version& version, ErrorCorrectionLevel ecLevel) {
255
+ // In the following comments, we use numbers of Version 7-H.
256
+ // numBytes = 196
257
+ int numBytes = version.totalCodewords();
258
+ // getNumECBytes = 130
259
+ auto& ecBlocks = version.ecBlocksForLevel(ecLevel);
260
+ int numEcBytes = ecBlocks.totalCodewords();
261
+ // getNumDataBytes = 196 - 130 = 66
262
+ int numDataBytes = numBytes - numEcBytes;
263
+ int totalInputBytes = (numInputBits + 7) / 8;
264
+ return numDataBytes >= totalInputBytes;
265
+ }
266
+
267
+ static const Version& ChooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel)
268
+ {
269
+ for (int versionNum = 1; versionNum <= 40; versionNum++) {
270
+ const Version* version = Version::Model2(versionNum);
271
+ if (WillFit(numInputBits, *version, ecLevel)) {
272
+ return *version;
273
+ }
274
+ }
275
+ throw std::invalid_argument("Data too big");
276
+ }
277
+
278
+ /**
279
+ * Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
280
+ */
281
+ ZXING_EXPORT_TEST_ONLY
282
+ void TerminateBits(int numDataBytes, BitArray& bits)
283
+ {
284
+ int capacity = numDataBytes * 8;
285
+ if (bits.size() > capacity) {
286
+ throw std::invalid_argument("data bits cannot fit in the QR Code" + std::to_string(bits.size()) + " > "
287
+ + std::to_string(capacity));
288
+ }
289
+ for (int i = 0; i < 4 && bits.size() < capacity; ++i) {
290
+ bits.appendBit(false);
291
+ }
292
+ // Append termination bits. See 8.4.8 of JISX0510:2004 (p.24) for details.
293
+ // If the last byte isn't 8-bit aligned, we'll add padding bits.
294
+ int numBitsInLastByte = bits.size() & 0x07;
295
+ if (numBitsInLastByte > 0) {
296
+ for (int i = numBitsInLastByte; i < 8; i++) {
297
+ bits.appendBit(false);
298
+ }
299
+ }
300
+ // If we have more space, we'll fill the space with padding patterns defined in 8.4.9 (p.24).
301
+ int numPaddingBytes = numDataBytes - bits.sizeInBytes();
302
+ for (int i = 0; i < numPaddingBytes; ++i) {
303
+ bits.appendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8);
304
+ }
305
+ if (bits.size() != capacity) {
306
+ throw std::invalid_argument("Bits size does not equal capacity");
307
+ }
308
+ }
309
+
310
+ struct BlockPair
311
+ {
312
+ ByteArray dataBytes;
313
+ ByteArray ecBytes;
314
+ };
315
+
316
+
317
+ /**
318
+ * Get number of data bytes and number of error correction bytes for block id "blockID". Store
319
+ * the result in "numDataBytesInBlock", and "numECBytesInBlock". See table 12 in 8.5.1 of
320
+ * JISX0510:2004 (p.30)
321
+ */
322
+ ZXING_EXPORT_TEST_ONLY
323
+ void GetNumDataBytesAndNumECBytesForBlockID(int numTotalBytes, int numDataBytes, int numRSBlocks, int blockID,
324
+ int& numDataBytesInBlock, int& numECBytesInBlock)
325
+ {
326
+ if (blockID >= numRSBlocks) {
327
+ throw std::invalid_argument("Block ID too large");
328
+ }
329
+ // numRsBlocksInGroup2 = 196 % 5 = 1
330
+ int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
331
+ // numRsBlocksInGroup1 = 5 - 1 = 4
332
+ int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
333
+ // numTotalBytesInGroup1 = 196 / 5 = 39
334
+ int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks;
335
+ // numTotalBytesInGroup2 = 39 + 1 = 40
336
+ int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1;
337
+ // numDataBytesInGroup1 = 66 / 5 = 13
338
+ int numDataBytesInGroup1 = numDataBytes / numRSBlocks;
339
+ // numDataBytesInGroup2 = 13 + 1 = 14
340
+ int numDataBytesInGroup2 = numDataBytesInGroup1 + 1;
341
+ // numEcBytesInGroup1 = 39 - 13 = 26
342
+ int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1;
343
+ // numEcBytesInGroup2 = 40 - 14 = 26
344
+ int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2;
345
+ // Sanity checks.
346
+ // 26 = 26
347
+ if (numEcBytesInGroup1 != numEcBytesInGroup2) {
348
+ throw std::invalid_argument("EC bytes mismatch");
349
+ }
350
+ // 5 = 4 + 1.
351
+ if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2) {
352
+ throw std::invalid_argument("RS blocks mismatch");
353
+ }
354
+ // 196 = (13 + 26) * 4 + (14 + 26) * 1
355
+ if (numTotalBytes
356
+ != ((numDataBytesInGroup1 + numEcBytesInGroup1) * numRsBlocksInGroup1)
357
+ + ((numDataBytesInGroup2 + numEcBytesInGroup2) * numRsBlocksInGroup2)) {
358
+ throw std::invalid_argument("Total bytes mismatch");
359
+ }
360
+
361
+ if (blockID < numRsBlocksInGroup1) {
362
+ numDataBytesInBlock = numDataBytesInGroup1;
363
+ numECBytesInBlock = numEcBytesInGroup1;
364
+ }
365
+ else {
366
+ numDataBytesInBlock = numDataBytesInGroup2;
367
+ numECBytesInBlock = numEcBytesInGroup2;
368
+ }
369
+ }
370
+
371
+ ZXING_EXPORT_TEST_ONLY
372
+ void GenerateECBytes(const ByteArray& dataBytes, int numEcBytes, ByteArray& ecBytes)
373
+ {
374
+ ecBytes.resize(numEcBytes);
375
+ ReedSolomonEncode(RSField::QRCode, dataBytes, ecBytes);
376
+ }
377
+
378
+
379
+ /**
380
+ * Interleave "bits" with corresponding error correction bytes. On success, store the result in
381
+ * "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
382
+ */
383
+ ZXING_EXPORT_TEST_ONLY
384
+ BitArray InterleaveWithECBytes(const BitArray& bits, int numTotalBytes, int numDataBytes, int numRSBlocks)
385
+ {
386
+ // "bits" must have "getNumDataBytes" bytes of data.
387
+ if (bits.sizeInBytes() != numDataBytes) {
388
+ throw std::invalid_argument("Number of bits and data bytes does not match");
389
+ }
390
+
391
+ // Step 1. Divide data bytes into blocks and generate error correction bytes for them. We'll
392
+ // store the divided data bytes blocks and error correction bytes blocks into "blocks".
393
+ int dataBytesOffset = 0;
394
+ int maxNumDataBytes = 0;
395
+ int maxNumEcBytes = 0;
396
+
397
+ // Since, we know the number of reedsolmon blocks, we can initialize the vector with the number.
398
+ std::vector<BlockPair> blocks(numRSBlocks);
399
+
400
+ for (int i = 0; i < numRSBlocks; ++i) {
401
+ int numDataBytesInBlock = 0;
402
+ int numEcBytesInBlock = 0;
403
+ GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, numRSBlocks, i, numDataBytesInBlock, numEcBytesInBlock);
404
+
405
+ blocks[i].dataBytes = bits.toBytes(8 * dataBytesOffset, numDataBytesInBlock);
406
+ GenerateECBytes(blocks[i].dataBytes, numEcBytesInBlock, blocks[i].ecBytes);
407
+
408
+ maxNumDataBytes = std::max(maxNumDataBytes, numDataBytesInBlock);
409
+ maxNumEcBytes = std::max(maxNumEcBytes, Size(blocks[i].ecBytes));
410
+ dataBytesOffset += numDataBytesInBlock;
411
+ }
412
+ if (numDataBytes != dataBytesOffset) {
413
+ throw std::invalid_argument("Data bytes does not match offset");
414
+ }
415
+
416
+ BitArray output;
417
+ // First, place data blocks.
418
+ for (int i = 0; i < maxNumDataBytes; ++i) {
419
+ for (auto& block : blocks) {
420
+ if (i < Size(block.dataBytes)) {
421
+ output.appendBits(block.dataBytes[i], 8);
422
+ }
423
+ }
424
+ }
425
+ // Then, place error correction blocks.
426
+ for (int i = 0; i < maxNumEcBytes; ++i) {
427
+ for (auto& block : blocks) {
428
+ if (i < Size(block.ecBytes)) {
429
+ output.appendBits(block.ecBytes[i], 8);
430
+ }
431
+ }
432
+ }
433
+ if (numTotalBytes != output.sizeInBytes()) { // Should be same.
434
+ throw std::invalid_argument("Interleaving error: " + std::to_string(numTotalBytes) + " and " + std::to_string(output.sizeInBytes())
435
+ + " differ.");
436
+ }
437
+ return output;
438
+ }
439
+
440
+
441
+ static int ChooseMaskPattern(const BitArray& bits, ErrorCorrectionLevel ecLevel, const Version& version, TritMatrix& matrix)
442
+ {
443
+ int minPenalty = std::numeric_limits<int>::max(); // Lower penalty is better.
444
+ int bestMaskPattern = -1;
445
+ // We try all mask patterns to choose the best one.
446
+ for (int maskPattern = 0; maskPattern < NUM_MASK_PATTERNS; maskPattern++) {
447
+ BuildMatrix(bits, ecLevel, version, maskPattern, matrix);
448
+ int penalty = MaskUtil::CalculateMaskPenalty(matrix);
449
+ if (penalty < minPenalty) {
450
+ minPenalty = penalty;
451
+ bestMaskPattern = maskPattern;
452
+ }
453
+ }
454
+ return bestMaskPattern;
455
+ }
456
+
457
+ static int CalculateBitsNeeded(CodecMode mode, const BitArray& headerBits, const BitArray& dataBits, const Version& version)
458
+ {
459
+ return headerBits.size() + CharacterCountBits(mode, version) + dataBits.size();
460
+ }
461
+
462
+ /**
463
+ * Decides the smallest version of QR code that will contain all of the provided data.
464
+ * @throws WriterException if the data cannot fit in any version
465
+ */
466
+ static const Version& RecommendVersion(ErrorCorrectionLevel ecLevel, CodecMode mode, const BitArray& headerBits, const BitArray& dataBits)
467
+ {
468
+ // Hard part: need to know version to know how many bits length takes. But need to know how many
469
+ // bits it takes to know version. First we take a guess at version by assuming version will be
470
+ // the minimum, 1:
471
+ int provisionalBitsNeeded = CalculateBitsNeeded(mode, headerBits, dataBits, *Version::Model2(1));
472
+ const Version& provisionalVersion = ChooseVersion(provisionalBitsNeeded, ecLevel);
473
+
474
+ // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
475
+ int bitsNeeded = CalculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
476
+ return ChooseVersion(bitsNeeded, ecLevel);
477
+ }
478
+
479
+ EncodeResult Encode(const std::wstring& content, ErrorCorrectionLevel ecLevel, CharacterSet charset, int versionNumber,
480
+ bool useGs1Format, int maskPattern)
481
+ {
482
+ if (charset == CharacterSet::Unknown) {
483
+ charset = DEFAULT_BYTE_MODE_ENCODING;
484
+ }
485
+
486
+ bool charsetIsDefault = (charset == DEFAULT_BYTE_MODE_ENCODING);
487
+
488
+ // Pick an encoding mode appropriate for the content. Note that this will not attempt to use
489
+ // multiple modes / segments even if that were more efficient. Twould be nice.
490
+ CodecMode mode = ChooseMode(content, charset);
491
+
492
+ // This will store the header information, like mode and
493
+ // length, as well as "header" segments like an ECI segment.
494
+ BitArray headerBits;
495
+
496
+ // Append ECI segment if applicable
497
+ if (mode == CodecMode::BYTE && !charsetIsDefault) {
498
+ AppendECI(charset, headerBits);
499
+ }
500
+
501
+ // Append the FNC1 mode header for GS1 formatted data if applicable
502
+ if (useGs1Format) {
503
+ // GS1 formatted codes are prefixed with a FNC1 in first position mode header
504
+ AppendModeInfo(CodecMode::FNC1_FIRST_POSITION, headerBits);
505
+ }
506
+
507
+ // (With ECI in place,) Write the mode marker
508
+ AppendModeInfo(mode, headerBits);
509
+
510
+ // Collect data within the main segment, separately, to count its size if needed. Don't add it to
511
+ // main payload yet.
512
+ BitArray dataBits;
513
+ AppendBytes(content, mode, charset, dataBits);
514
+
515
+ const Version* version;
516
+ if (versionNumber > 0) {
517
+ version = Version::Model2(versionNumber);
518
+ if (version != nullptr) {
519
+ int bitsNeeded = CalculateBitsNeeded(mode, headerBits, dataBits, *version);
520
+ if (!WillFit(bitsNeeded, *version, ecLevel)) {
521
+ throw std::invalid_argument("Data too big for requested version");
522
+ }
523
+ }
524
+ else {
525
+ version = &RecommendVersion(ecLevel, mode, headerBits, dataBits);
526
+ }
527
+ }
528
+ else {
529
+ version = &RecommendVersion(ecLevel, mode, headerBits, dataBits);
530
+ }
531
+
532
+ BitArray headerAndDataBits;
533
+ headerAndDataBits.appendBitArray(headerBits);
534
+ // Find "length" of main segment and write it
535
+ int numLetters = mode == CodecMode::BYTE ? dataBits.sizeInBytes() : Size(content);
536
+ AppendLengthInfo(numLetters, *version, mode, headerAndDataBits);
537
+ // Put data together into the overall payload
538
+ headerAndDataBits.appendBitArray(dataBits);
539
+
540
+ auto& ecBlocks = version->ecBlocksForLevel(ecLevel);
541
+ int numDataBytes = version->totalCodewords() - ecBlocks.totalCodewords();
542
+
543
+ // Terminate the bits properly.
544
+ TerminateBits(numDataBytes, headerAndDataBits);
545
+
546
+ // Interleave data bits with error correction code.
547
+ BitArray finalBits =
548
+ InterleaveWithECBytes(headerAndDataBits, version->totalCodewords(), numDataBytes, ecBlocks.numBlocks());
549
+
550
+ EncodeResult output;
551
+ output.ecLevel = ecLevel;
552
+ output.mode = mode;
553
+ output.version = version;
554
+
555
+ // Choose the mask pattern and set to "qrCode".
556
+ int dimension = version->dimension();
557
+ TritMatrix matrix(dimension, dimension);
558
+ output.maskPattern = maskPattern != -1 ? maskPattern : ChooseMaskPattern(finalBits, ecLevel, *version, matrix);
559
+
560
+ // Build the matrix and set it to "qrCode".
561
+ BuildMatrix(finalBits, ecLevel, *version, output.maskPattern, matrix);
562
+
563
+ output.matrix = ToBitMatrix(matrix);
564
+
565
+ return output;
566
+ }
567
+
568
+ } // namespace ZXing::QRCode