@qr-platform/qr-code.js 0.8.17

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 (208) hide show
  1. package/.github/workflows/publish.yml +18 -0
  2. package/CHANGELOG.md +233 -0
  3. package/LICENSE.md +77 -0
  4. package/README.md +188 -0
  5. package/docs/advanced-examples.md +523 -0
  6. package/docs/api-reference-guide.md +254 -0
  7. package/docs/documentation.md +1592 -0
  8. package/docs/examples.md +322 -0
  9. package/docs/license-management.md +501 -0
  10. package/docs/typescript-types-definitions.md +372 -0
  11. package/docs/usage-guide.md +622 -0
  12. package/lib/core/qr-code-js.d.ts +48 -0
  13. package/lib/core/qr-constant.d.ts +9 -0
  14. package/lib/core/qr-options-validation.d.ts +13 -0
  15. package/lib/core/qr-svg.d.ts +76 -0
  16. package/lib/core/qr-templates.d.ts +6 -0
  17. package/lib/figures/corner-dot.d.ts +24 -0
  18. package/lib/figures/corner-square.d.ts +24 -0
  19. package/lib/figures/dot.d.ts +31 -0
  20. package/lib/index.d.ts +52 -0
  21. package/lib/lib/image/GIFImage.d.ts +19 -0
  22. package/lib/lib/io/Base64.d.ts +10 -0
  23. package/lib/lib/io/Base64DecodeInputStream.d.ts +15 -0
  24. package/lib/lib/io/Base64EncodeOutputStream.d.ts +17 -0
  25. package/lib/lib/io/ByteArrayInputStream.d.ts +12 -0
  26. package/lib/lib/io/ByteArrayOutputStream.d.ts +12 -0
  27. package/lib/lib/io/InputStream.d.ts +10 -0
  28. package/lib/lib/io/OutputStream.d.ts +12 -0
  29. package/lib/lib/qr-code.d.ts +5 -0
  30. package/lib/lib/qrcode/BitBuffer.d.ts +11 -0
  31. package/lib/lib/qrcode/ErrorCorrectLevel.d.ts +23 -0
  32. package/lib/lib/qrcode/MaskPattern.d.ts +39 -0
  33. package/lib/lib/qrcode/Mode.d.ts +23 -0
  34. package/lib/lib/qrcode/Polynomial.d.ts +15 -0
  35. package/lib/lib/qrcode/QR8BitByte.d.ts +13 -0
  36. package/lib/lib/qrcode/QRAlphaNum.d.ts +13 -0
  37. package/lib/lib/qrcode/QRCode.d.ts +22 -0
  38. package/lib/lib/qrcode/QRCodeMinimal.d.ts +58 -0
  39. package/lib/lib/qrcode/QRData.d.ts +17 -0
  40. package/lib/lib/qrcode/QRKanji.d.ts +13 -0
  41. package/lib/lib/qrcode/QRMath.d.ts +13 -0
  42. package/lib/lib/qrcode/QRNumber.d.ts +14 -0
  43. package/lib/lib/qrcode/QRUtil.d.ts +25 -0
  44. package/lib/lib/qrcode/RSBlock.d.ts +16 -0
  45. package/lib/lib/text/createStringToBytes.d.ts +9 -0
  46. package/lib/lib/text/stringToBytes_SJIS.d.ts +8 -0
  47. package/lib/lib/text/stringToBytes_UTF8.d.ts +7 -0
  48. package/lib/lib/zbar-wasm/index.d.ts +1 -0
  49. package/lib/lib/zxing-js/src/browser/BrowserCodeReader.d.ts +410 -0
  50. package/lib/lib/zxing-js/src/browser/BrowserQRCodeReader.d.ts +29 -0
  51. package/lib/lib/zxing-js/src/browser/BrowserQRCodeSvgWriter.d.ts +46 -0
  52. package/lib/lib/zxing-js/src/browser/BrowserSvgCodeWriter.d.ts +49 -0
  53. package/lib/lib/zxing-js/src/browser/DecodeContinuouslyCallback.d.ts +6 -0
  54. package/lib/lib/zxing-js/src/browser/HTMLCanvasElementLuminanceSource.d.ts +27 -0
  55. package/lib/lib/zxing-js/src/browser/HTMLVisualMediaElement.d.ts +4 -0
  56. package/lib/lib/zxing-js/src/browser/VideoInputDevice.d.ts +22 -0
  57. package/lib/lib/zxing-js/src/browser.d.ts +3 -0
  58. package/lib/lib/zxing-js/src/core/ArgumentException.d.ts +7 -0
  59. package/lib/lib/zxing-js/src/core/ArithmeticException.d.ts +7 -0
  60. package/lib/lib/zxing-js/src/core/ArrayIndexOutOfBoundsException.d.ts +10 -0
  61. package/lib/lib/zxing-js/src/core/BarcodeFormat.d.ts +42 -0
  62. package/lib/lib/zxing-js/src/core/Binarizer.d.ts +53 -0
  63. package/lib/lib/zxing-js/src/core/BinaryBitmap.d.ts +78 -0
  64. package/lib/lib/zxing-js/src/core/ChecksumException.d.ts +8 -0
  65. package/lib/lib/zxing-js/src/core/DecodeHintType.d.ts +91 -0
  66. package/lib/lib/zxing-js/src/core/Dimension.d.ts +13 -0
  67. package/lib/lib/zxing-js/src/core/EncodeHintType.d.ts +99 -0
  68. package/lib/lib/zxing-js/src/core/Exception.d.ts +17 -0
  69. package/lib/lib/zxing-js/src/core/FormatException.d.ts +8 -0
  70. package/lib/lib/zxing-js/src/core/HighContrastLuminanceSource.d.ts +27 -0
  71. package/lib/lib/zxing-js/src/core/IllegalArgumentException.d.ts +7 -0
  72. package/lib/lib/zxing-js/src/core/IllegalStateException.d.ts +7 -0
  73. package/lib/lib/zxing-js/src/core/IndexOutOfBoundsException.d.ts +7 -0
  74. package/lib/lib/zxing-js/src/core/InvertedLuminanceSource.d.ts +22 -0
  75. package/lib/lib/zxing-js/src/core/LuminanceSource.d.ts +84 -0
  76. package/lib/lib/zxing-js/src/core/NodeLuminanceSource.d.ts +36 -0
  77. package/lib/lib/zxing-js/src/core/NotFoundException.d.ts +8 -0
  78. package/lib/lib/zxing-js/src/core/NullPointerException.d.ts +7 -0
  79. package/lib/lib/zxing-js/src/core/OutOfMemoryError.d.ts +6 -0
  80. package/lib/lib/zxing-js/src/core/PlanarYUVLuminanceSource.d.ts +35 -0
  81. package/lib/lib/zxing-js/src/core/RGBLuminanceSource.d.ts +21 -0
  82. package/lib/lib/zxing-js/src/core/Reader.d.ts +49 -0
  83. package/lib/lib/zxing-js/src/core/ReaderException.d.ts +7 -0
  84. package/lib/lib/zxing-js/src/core/ReedSolomonException.d.ts +7 -0
  85. package/lib/lib/zxing-js/src/core/Result.d.ts +52 -0
  86. package/lib/lib/zxing-js/src/core/ResultMetadataType.d.ts +68 -0
  87. package/lib/lib/zxing-js/src/core/ResultPoint.d.ts +34 -0
  88. package/lib/lib/zxing-js/src/core/ResultPointCallback.d.ts +11 -0
  89. package/lib/lib/zxing-js/src/core/UniversalLuminanceSource.d.ts +46 -0
  90. package/lib/lib/zxing-js/src/core/UnsupportedOperationException.d.ts +7 -0
  91. package/lib/lib/zxing-js/src/core/Writer.d.ts +30 -0
  92. package/lib/lib/zxing-js/src/core/WriterException.d.ts +7 -0
  93. package/lib/lib/zxing-js/src/core/common/BitArray.d.ts +111 -0
  94. package/lib/lib/zxing-js/src/core/common/BitMatrix.d.ts +98 -0
  95. package/lib/lib/zxing-js/src/core/common/BitSource.d.ts +38 -0
  96. package/lib/lib/zxing-js/src/core/common/CharacterSetECI.d.ts +89 -0
  97. package/lib/lib/zxing-js/src/core/common/DecoderResult.d.ts +64 -0
  98. package/lib/lib/zxing-js/src/core/common/DefaultGridSampler.d.ts +10 -0
  99. package/lib/lib/zxing-js/src/core/common/DetectorResult.d.ts +16 -0
  100. package/lib/lib/zxing-js/src/core/common/ECIEncoderSet.d.ts +37 -0
  101. package/lib/lib/zxing-js/src/core/common/ECIInput.d.ts +79 -0
  102. package/lib/lib/zxing-js/src/core/common/GlobalHistogramBinarizer.d.ts +29 -0
  103. package/lib/lib/zxing-js/src/core/common/GridSampler.d.ts +36 -0
  104. package/lib/lib/zxing-js/src/core/common/GridSamplerInstance.d.ts +18 -0
  105. package/lib/lib/zxing-js/src/core/common/HybridBinarizer.d.ts +54 -0
  106. package/lib/lib/zxing-js/src/core/common/MinimalECIInput.d.ts +123 -0
  107. package/lib/lib/zxing-js/src/core/common/PerspectiveTransform.d.ts +26 -0
  108. package/lib/lib/zxing-js/src/core/common/StringUtils.d.ts +48 -0
  109. package/lib/lib/zxing-js/src/core/common/detector/CornerDetector.d.ts +35 -0
  110. package/lib/lib/zxing-js/src/core/common/detector/MathUtils.d.ts +36 -0
  111. package/lib/lib/zxing-js/src/core/common/detector/WhiteRectangleDetector.d.ts +71 -0
  112. package/lib/lib/zxing-js/src/core/common/reedsolomon/AbstractGenericGF.d.ts +34 -0
  113. package/lib/lib/zxing-js/src/core/common/reedsolomon/AbstractGenericGFPoly.d.ts +36 -0
  114. package/lib/lib/zxing-js/src/core/common/reedsolomon/GenericGF.d.ts +58 -0
  115. package/lib/lib/zxing-js/src/core/common/reedsolomon/GenericGFPoly.d.ts +47 -0
  116. package/lib/lib/zxing-js/src/core/common/reedsolomon/ReedSolomonDecoder.d.ts +40 -0
  117. package/lib/lib/zxing-js/src/core/common/reedsolomon/ReedSolomonEncoder.d.ts +41 -0
  118. package/lib/lib/zxing-js/src/core/qrcode/QRCodeReader.d.ts +35 -0
  119. package/lib/lib/zxing-js/src/core/qrcode/QRCodeWriter.d.ts +13 -0
  120. package/lib/lib/zxing-js/src/core/qrcode/decoder/BitMatrixParser.d.ts +58 -0
  121. package/lib/lib/zxing-js/src/core/qrcode/decoder/DataBlock.d.ts +28 -0
  122. package/lib/lib/zxing-js/src/core/qrcode/decoder/DataMask.d.ts +36 -0
  123. package/lib/lib/zxing-js/src/core/qrcode/decoder/DecodedBitStreamParser.d.ts +30 -0
  124. package/lib/lib/zxing-js/src/core/qrcode/decoder/Decoder.d.ts +44 -0
  125. package/lib/lib/zxing-js/src/core/qrcode/decoder/ECB.d.ts +12 -0
  126. package/lib/lib/zxing-js/src/core/qrcode/decoder/ECBlocks.d.ts +16 -0
  127. package/lib/lib/zxing-js/src/core/qrcode/decoder/ErrorCorrectionLevel.d.ts +38 -0
  128. package/lib/lib/zxing-js/src/core/qrcode/decoder/FormatInformation.d.ts +33 -0
  129. package/lib/lib/zxing-js/src/core/qrcode/decoder/Mode.d.ts +56 -0
  130. package/lib/lib/zxing-js/src/core/qrcode/decoder/QRCodeDecoderMetaData.d.ts +21 -0
  131. package/lib/lib/zxing-js/src/core/qrcode/decoder/Version.d.ts +44 -0
  132. package/lib/lib/zxing-js/src/core/qrcode/detector/AlignmentPattern.d.ts +21 -0
  133. package/lib/lib/zxing-js/src/core/qrcode/detector/AlignmentPatternFinder.d.ts +82 -0
  134. package/lib/lib/zxing-js/src/core/qrcode/detector/Detector.d.ts +87 -0
  135. package/lib/lib/zxing-js/src/core/qrcode/detector/FinderPattern.d.ts +26 -0
  136. package/lib/lib/zxing-js/src/core/qrcode/detector/FinderPatternFinder.d.ts +114 -0
  137. package/lib/lib/zxing-js/src/core/qrcode/detector/FinderPatternInfo.d.ts +16 -0
  138. package/lib/lib/zxing-js/src/core/qrcode/encoder/BlockPair.d.ts +7 -0
  139. package/lib/lib/zxing-js/src/core/qrcode/encoder/ByteMatrix.d.ts +24 -0
  140. package/lib/lib/zxing-js/src/core/qrcode/encoder/Encoder.d.ts +85 -0
  141. package/lib/lib/zxing-js/src/core/qrcode/encoder/MaskUtil.d.ts +47 -0
  142. package/lib/lib/zxing-js/src/core/qrcode/encoder/MatrixUtil.d.ts +37 -0
  143. package/lib/lib/zxing-js/src/core/qrcode/encoder/QRCode.d.ts +29 -0
  144. package/lib/lib/zxing-js/src/core/util/Arrays.d.ts +45 -0
  145. package/lib/lib/zxing-js/src/core/util/ByteArrayOutputStream.d.ts +174 -0
  146. package/lib/lib/zxing-js/src/core/util/Charset.d.ts +7 -0
  147. package/lib/lib/zxing-js/src/core/util/Collections.d.ts +11 -0
  148. package/lib/lib/zxing-js/src/core/util/Float.d.ts +14 -0
  149. package/lib/lib/zxing-js/src/core/util/Formatter.d.ts +28 -0
  150. package/lib/lib/zxing-js/src/core/util/Integer.d.ts +19 -0
  151. package/lib/lib/zxing-js/src/core/util/Long.d.ts +12 -0
  152. package/lib/lib/zxing-js/src/core/util/OutputStream.d.ts +106 -0
  153. package/lib/lib/zxing-js/src/core/util/StandardCharsets.d.ts +7 -0
  154. package/lib/lib/zxing-js/src/core/util/StringBuilder.d.ts +21 -0
  155. package/lib/lib/zxing-js/src/core/util/StringEncoding.d.ts +51 -0
  156. package/lib/lib/zxing-js/src/core/util/System.d.ts +10 -0
  157. package/lib/lib/zxing-js/src/customTypings.d.ts +16 -0
  158. package/lib/lib/zxing-js/src/index.d.ts +5 -0
  159. package/lib/lib/zxing-js/src/node.d.ts +1 -0
  160. package/lib/license/LicenseManager.d.ts +69 -0
  161. package/lib/license/LicenseManagerNode.d.ts +64 -0
  162. package/lib/node.d.ts +37 -0
  163. package/lib/options-demo.d.ts +239 -0
  164. package/lib/plugins/QRBorderHelpers.d.ts +32 -0
  165. package/lib/plugins/QRBorderPlugin.d.ts +35 -0
  166. package/lib/plugins/QRValidatorZbar.d.ts +38 -0
  167. package/lib/plugins/QRValidatorZbarNode.d.ts +60 -0
  168. package/lib/plugins/QRValidatorZbarNodeSharp.d.ts +83 -0
  169. package/lib/qr-code-js-node.js +1 -0
  170. package/lib/qr-code-js.js +1 -0
  171. package/lib/templates/borders-inner-outter.d.ts +129 -0
  172. package/lib/templates/borders-inner-scale-offset.d.ts +497 -0
  173. package/lib/templates/borders-inner.d.ts +129 -0
  174. package/lib/templates/borders-no-license.d.ts +129 -0
  175. package/lib/templates/borders-outter.d.ts +129 -0
  176. package/lib/templates/borders-text-auto-curved.d.ts +129 -0
  177. package/lib/templates/borders-text-full-curved.d.ts +133 -0
  178. package/lib/templates/borders.d.ts +129 -0
  179. package/lib/templates/scales.d.ts +130 -0
  180. package/lib/templates/scan-validators/index.d.ts +1 -0
  181. package/lib/templates/scan-validators/tests/cases/basic-inverted.d.ts +9 -0
  182. package/lib/templates/scan-validators/tests/cases/basic-no-license.d.ts +3 -0
  183. package/lib/templates/scan-validators/tests/cases/basic.d.ts +3 -0
  184. package/lib/templates/scan-validators/tests/cases/colors-inverted.d.ts +2 -0
  185. package/lib/templates/scan-validators/tests/cases/colors.d.ts +58 -0
  186. package/lib/templates/scan-validators/tests/cases/out-of-borders-inverted.d.ts +9 -0
  187. package/lib/templates/scan-validators/tests/cases/out-of-borders.d.ts +9 -0
  188. package/lib/templates/scan-validators/tests/cases/position-inverted.d.ts +9 -0
  189. package/lib/templates/scan-validators/tests/cases/position.d.ts +3 -0
  190. package/lib/templates/scan-validators/tests/index.d.ts +27 -0
  191. package/lib/tools/browser-image-tools.d.ts +7 -0
  192. package/lib/tools/browser-utils.d.ts +18 -0
  193. package/lib/types/helper.d.ts +23 -0
  194. package/lib/utils/canvas-options.d.ts +7 -0
  195. package/lib/utils/color.d.ts +4 -0
  196. package/lib/utils/gradient.d.ts +26 -0
  197. package/lib/utils/image.d.ts +16 -0
  198. package/lib/utils/merge.d.ts +5 -0
  199. package/lib/utils/options.d.ts +220 -0
  200. package/lib/utils/qrcode.d.ts +8 -0
  201. package/lib/utils/scan-validator-node.d.ts +15 -0
  202. package/lib/utils/scan-validators/abstract-scan-validator.d.ts +43 -0
  203. package/lib/utils/scan-validators/zbar-scan-validator.d.ts +8 -0
  204. package/lib/utils/scan-validators/zxing-canvas-scan-validator.d.ts +10 -0
  205. package/lib/utils/scan-validators/zxing-scan-validator.d.ts +8 -0
  206. package/lib/utils/svg.d.ts +2 -0
  207. package/lib/utils/token-validator.d.ts +19 -0
  208. package/package.json +80 -0
@@ -0,0 +1,38 @@
1
+ export declare enum ErrorCorrectionLevelValues {
2
+ L = 0,
3
+ M = 1,
4
+ Q = 2,
5
+ H = 3
6
+ }
7
+ /**
8
+ * <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels
9
+ * defined by the QR code standard.</p>
10
+ *
11
+ * @author Sean Owen
12
+ */
13
+ export default class ErrorCorrectionLevel {
14
+ private value;
15
+ private stringValue;
16
+ private bits;
17
+ private static FOR_BITS;
18
+ private static FOR_VALUE;
19
+ /** L = ~7% correction */
20
+ static L: ErrorCorrectionLevel;
21
+ /** M = ~15% correction */
22
+ static M: ErrorCorrectionLevel;
23
+ /** Q = ~25% correction */
24
+ static Q: ErrorCorrectionLevel;
25
+ /** H = ~30% correction */
26
+ static H: ErrorCorrectionLevel;
27
+ private constructor();
28
+ getValue(): ErrorCorrectionLevelValues;
29
+ getBits(): number;
30
+ static fromString(s: string): ErrorCorrectionLevel;
31
+ toString(): string;
32
+ equals(o: any): boolean;
33
+ /**
34
+ * @param bits int containing the two bits encoding a QR Code's error correction level
35
+ * @return ErrorCorrectionLevel representing the encoded error correction level
36
+ */
37
+ static forBits(bits: number): ErrorCorrectionLevel;
38
+ }
@@ -0,0 +1,33 @@
1
+ import ErrorCorrectionLevel from './ErrorCorrectionLevel';
2
+ /**
3
+ * <p>Encapsulates a QR Code's format information, including the data mask used and
4
+ * error correction level.</p>
5
+ *
6
+ * @author Sean Owen
7
+ * @see DataMask
8
+ * @see ErrorCorrectionLevel
9
+ */
10
+ export default class FormatInformation {
11
+ private static FORMAT_INFO_MASK_QR;
12
+ /**
13
+ * See ISO 18004:2006, Annex C, Table C.1
14
+ */
15
+ private static FORMAT_INFO_DECODE_LOOKUP;
16
+ private errorCorrectionLevel;
17
+ private dataMask;
18
+ private constructor();
19
+ static numBitsDiffering(a: number, b: number): number;
20
+ /**
21
+ * @param maskedFormatInfo1 format info indicator, with mask still applied
22
+ * @param maskedFormatInfo2 second copy of same info; both are checked at the same time
23
+ * to establish best match
24
+ * @return information about the format it specifies, or {@code null}
25
+ * if doesn't seem to match any known pattern
26
+ */
27
+ static decodeFormatInformation(maskedFormatInfo1: number, maskedFormatInfo2: number): FormatInformation | null;
28
+ private static doDecodeFormatInformation;
29
+ getErrorCorrectionLevel(): ErrorCorrectionLevel;
30
+ getDataMask(): number;
31
+ hashCode(): number;
32
+ equals(o: Object): boolean;
33
+ }
@@ -0,0 +1,56 @@
1
+ import Version from './Version';
2
+ export declare enum ModeValues {
3
+ TERMINATOR = 0,// Not really a mode...
4
+ NUMERIC = 1,
5
+ ALPHANUMERIC = 2,
6
+ STRUCTURED_APPEND = 3,// Not supported
7
+ BYTE = 4,
8
+ ECI = 5,// character counts don't apply
9
+ KANJI = 6,
10
+ FNC1_FIRST_POSITION = 7,
11
+ FNC1_SECOND_POSITION = 8,
12
+ /** See GBT 18284-2000; "Hanzi" is a transliteration of this mode name. */
13
+ HANZI = 9
14
+ }
15
+ /**
16
+ * <p>See ISO 18004:2006, 6.4.1, Tables 2 and 3. This enum encapsulates the various modes in which
17
+ * data can be encoded to bits in the QR code standard.</p>
18
+ *
19
+ * @author Sean Owen
20
+ */
21
+ export default class Mode {
22
+ private value;
23
+ private stringValue;
24
+ private characterCountBitsForVersions;
25
+ private bits;
26
+ private static FOR_BITS;
27
+ private static FOR_VALUE;
28
+ static TERMINATOR: Mode;
29
+ static NUMERIC: Mode;
30
+ static ALPHANUMERIC: Mode;
31
+ static STRUCTURED_APPEND: Mode;
32
+ static BYTE: Mode;
33
+ static ECI: Mode;
34
+ static KANJI: Mode;
35
+ static FNC1_FIRST_POSITION: Mode;
36
+ static FNC1_SECOND_POSITION: Mode;
37
+ /** See GBT 18284-2000; "Hanzi" is a transliteration of this mode name. */
38
+ static HANZI: Mode;
39
+ private constructor();
40
+ /**
41
+ * @param bits four bits encoding a QR Code data mode
42
+ * @return Mode encoded by these bits
43
+ * @throws IllegalArgumentException if bits do not correspond to a known mode
44
+ */
45
+ static forBits(bits: number): Mode;
46
+ /**
47
+ * @param version version in question
48
+ * @return number of bits used, in this QR Code symbol {@link Version}, to encode the
49
+ * count of characters that will follow encoded in this Mode
50
+ */
51
+ getCharacterCountBits(version: Version): number;
52
+ getValue(): ModeValues;
53
+ getBits(): number;
54
+ equals(o: any): boolean;
55
+ toString(): string;
56
+ }
@@ -0,0 +1,21 @@
1
+ import ResultPoint from '../../ResultPoint';
2
+ /**
3
+ * Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the
4
+ * decoding caller. Callers are expected to process this.
5
+ *
6
+ * @see com.google.zxing.common.DecoderResult#getOther()
7
+ */
8
+ export default class QRCodeDecoderMetaData {
9
+ private mirrored;
10
+ constructor(mirrored: boolean);
11
+ /**
12
+ * @return true if the QR Code was mirrored.
13
+ */
14
+ isMirrored(): boolean;
15
+ /**
16
+ * Apply the result points' order correction due to mirroring.
17
+ *
18
+ * @param points Array of points to apply mirror correction to.
19
+ */
20
+ applyMirroredCorrection(points: Array<ResultPoint>): void;
21
+ }
@@ -0,0 +1,44 @@
1
+ import BitMatrix from '../../common/BitMatrix';
2
+ import ECBlocks from './ECBlocks';
3
+ import ErrorCorrectionLevel from './ErrorCorrectionLevel';
4
+ /**
5
+ * See ISO 18004:2006 Annex D
6
+ *
7
+ * @author Sean Owen
8
+ */
9
+ export default class Version {
10
+ private versionNumber;
11
+ private alignmentPatternCenters;
12
+ /**
13
+ * See ISO 18004:2006 Annex D.
14
+ * Element i represents the raw version bits that specify version i + 7
15
+ */
16
+ private static VERSION_DECODE_INFO;
17
+ /**
18
+ * See ISO 18004:2006 6.5.1 Table 9
19
+ */
20
+ private static VERSIONS;
21
+ private ecBlocks;
22
+ private totalCodewords;
23
+ private constructor();
24
+ getVersionNumber(): number;
25
+ getAlignmentPatternCenters(): Int32Array;
26
+ getTotalCodewords(): number;
27
+ getDimensionForVersion(): number;
28
+ getECBlocksForLevel(ecLevel: ErrorCorrectionLevel): ECBlocks;
29
+ /**
30
+ * <p>Deduces version information purely from QR Code dimensions.</p>
31
+ *
32
+ * @param dimension dimension in modules
33
+ * @return Version for a QR Code of that dimension
34
+ * @throws FormatException if dimension is not 1 mod 4
35
+ */
36
+ static getProvisionalVersionForDimension(dimension: number): Version;
37
+ static getVersionForNumber(versionNumber: number): Version;
38
+ static decodeVersionInformation(versionBits: number): Version | null;
39
+ /**
40
+ * See ISO 18004:2006 Annex E
41
+ */
42
+ buildFunctionPattern(): BitMatrix;
43
+ toString(): string;
44
+ }
@@ -0,0 +1,21 @@
1
+ import ResultPoint from '../../ResultPoint';
2
+ /**
3
+ * <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
4
+ * all but the simplest QR Codes.</p>
5
+ *
6
+ * @author Sean Owen
7
+ */
8
+ export default class AlignmentPattern extends ResultPoint {
9
+ private estimatedModuleSize;
10
+ constructor(posX: number, posY: number, estimatedModuleSize: number);
11
+ /**
12
+ * <p>Determines if this alignment pattern "about equals" an alignment pattern at the stated
13
+ * position and size -- meaning, it is at nearly the same center with nearly the same size.</p>
14
+ */
15
+ aboutEquals(moduleSize: number, i: number, j: number): boolean;
16
+ /**
17
+ * Combines this object's current estimate of a finder pattern position and module size
18
+ * with a new estimate. It returns a new {@code FinderPattern} containing an average of the two.
19
+ */
20
+ combineEstimate(i: number, j: number, newModuleSize: number): AlignmentPattern;
21
+ }
@@ -0,0 +1,82 @@
1
+ import BitMatrix from '../../common/BitMatrix';
2
+ import ResultPointCallback from '../../ResultPointCallback';
3
+ import AlignmentPattern from './AlignmentPattern';
4
+ /**
5
+ * <p>This class attempts to find alignment patterns in a QR Code. Alignment patterns look like finder
6
+ * patterns but are smaller and appear at regular intervals throughout the image.</p>
7
+ *
8
+ * <p>At the moment this only looks for the bottom-right alignment pattern.</p>
9
+ *
10
+ * <p>This is mostly a simplified copy of {@link FinderPatternFinder}. It is copied,
11
+ * pasted and stripped down here for maximum performance but does unfortunately duplicate
12
+ * some code.</p>
13
+ *
14
+ * <p>This class is thread-safe but not reentrant. Each thread must allocate its own object.</p>
15
+ *
16
+ * @author Sean Owen
17
+ */
18
+ export default class AlignmentPatternFinder {
19
+ private image;
20
+ private startX;
21
+ private startY;
22
+ private width;
23
+ private height;
24
+ private moduleSize;
25
+ private resultPointCallback;
26
+ private possibleCenters;
27
+ private crossCheckStateCount;
28
+ /**
29
+ * <p>Creates a finder that will look in a portion of the whole image.</p>
30
+ *
31
+ * @param image image to search
32
+ * @param startX left column from which to start searching
33
+ * @param startY top row from which to start searching
34
+ * @param width width of region to search
35
+ * @param height height of region to search
36
+ * @param moduleSize estimated module size so far
37
+ */
38
+ constructor(image: BitMatrix, startX: number, startY: number, width: number, height: number, moduleSize: number, resultPointCallback: ResultPointCallback);
39
+ /**
40
+ * <p>This method attempts to find the bottom-right alignment pattern in the image. It is a bit messy since
41
+ * it's pretty performance-critical and so is written to be fast foremost.</p>
42
+ *
43
+ * @return {@link AlignmentPattern} if found
44
+ * @throws NotFoundException if not found
45
+ */
46
+ find(): AlignmentPattern;
47
+ /**
48
+ * Given a count of black/white/black pixels just seen and an end position,
49
+ * figures the location of the center of this black/white/black run.
50
+ */
51
+ private static centerFromEnd;
52
+ /**
53
+ * @param stateCount count of black/white/black pixels just read
54
+ * @return true iff the proportions of the counts is close enough to the 1/1/1 ratios
55
+ * used by alignment patterns to be considered a match
56
+ */
57
+ private foundPatternCross;
58
+ /**
59
+ * <p>After a horizontal scan finds a potential alignment pattern, this method
60
+ * "cross-checks" by scanning down vertically through the center of the possible
61
+ * alignment pattern to see if the same proportion is detected.</p>
62
+ *
63
+ * @param startI row where an alignment pattern was detected
64
+ * @param centerJ center of the section that appears to cross an alignment pattern
65
+ * @param maxCount maximum reasonable number of modules that should be
66
+ * observed in any reading state, based on the results of the horizontal scan
67
+ * @return vertical center of alignment pattern, or {@link Float#NaN} if not found
68
+ */
69
+ private crossCheckVertical;
70
+ /**
71
+ * <p>This is called when a horizontal scan finds a possible alignment pattern. It will
72
+ * cross check with a vertical scan, and if successful, will see if this pattern had been
73
+ * found on a previous horizontal scan. If so, we consider it confirmed and conclude we have
74
+ * found the alignment pattern.</p>
75
+ *
76
+ * @param stateCount reading state module counts from horizontal scan
77
+ * @param i row where alignment pattern may be found
78
+ * @param j end of possible alignment pattern in row
79
+ * @return {@link AlignmentPattern} if we have found the same pattern twice, or null if not
80
+ */
81
+ private handlePossibleCenter;
82
+ }
@@ -0,0 +1,87 @@
1
+ import BitMatrix from '../../common/BitMatrix';
2
+ import DetectorResult from '../../common/DetectorResult';
3
+ import DecodeHintType from '../../DecodeHintType';
4
+ import ResultPoint from '../../ResultPoint';
5
+ import ResultPointCallback from '../../ResultPointCallback';
6
+ import AlignmentPattern from './AlignmentPattern';
7
+ import FinderPatternInfo from './FinderPatternInfo';
8
+ /**
9
+ * <p>Encapsulates logic that can detect a QR Code in an image, even if the QR Code
10
+ * is rotated or skewed, or partially obscured.</p>
11
+ *
12
+ * @author Sean Owen
13
+ */
14
+ export default class Detector {
15
+ private image;
16
+ private resultPointCallback?;
17
+ constructor(image: BitMatrix);
18
+ protected getImage(): BitMatrix;
19
+ protected getResultPointCallback(): ResultPointCallback | undefined;
20
+ /**
21
+ * <p>Detects a QR Code in an image.</p>
22
+ *
23
+ * @return {@link DetectorResult} encapsulating results of detecting a QR Code
24
+ * @throws NotFoundException if QR Code cannot be found
25
+ * @throws FormatException if a QR Code cannot be decoded
26
+ */
27
+ /**
28
+ * <p>Detects a QR Code in an image.</p>
29
+ *
30
+ * @param hints optional hints to detector
31
+ * @return {@link DetectorResult} encapsulating results of detecting a QR Code
32
+ * @throws NotFoundException if QR Code cannot be found
33
+ * @throws FormatException if a QR Code cannot be decoded
34
+ */
35
+ detect(hints: Map<DecodeHintType, any>): DetectorResult;
36
+ protected processFinderPatternInfo(info: FinderPatternInfo): DetectorResult;
37
+ private static createTransform;
38
+ private static sampleGrid;
39
+ /**
40
+ * <p>Computes the dimension (number of modules on a size) of the QR Code based on the position
41
+ * of the finder patterns and estimated module size.</p>
42
+ */
43
+ private static computeDimension;
44
+ /**
45
+ * <p>Computes an average estimated module size based on estimated derived from the positions
46
+ * of the three finder patterns.</p>
47
+ *
48
+ * @param topLeft detected top-left finder pattern center
49
+ * @param topRight detected top-right finder pattern center
50
+ * @param bottomLeft detected bottom-left finder pattern center
51
+ * @return estimated module size
52
+ */
53
+ protected calculateModuleSize(topLeft: ResultPoint, topRight: ResultPoint, bottomLeft: ResultPoint): number;
54
+ /**
55
+ * <p>Estimates module size based on two finder patterns -- it uses
56
+ * {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
57
+ * width of each, measuring along the axis between their centers.</p>
58
+ */
59
+ private calculateModuleSizeOneWay;
60
+ /**
61
+ * See {@link #sizeOfBlackWhiteBlackRun(int, int, int, int)}; computes the total width of
62
+ * a finder pattern by looking for a black-white-black run from the center in the direction
63
+ * of another point (another finder pattern center), and in the opposite direction too.
64
+ */
65
+ private sizeOfBlackWhiteBlackRunBothWays;
66
+ /**
67
+ * <p>This method traces a line from a point in the image, in the direction towards another point.
68
+ * It begins in a black region, and keeps going until it finds white, then black, then white again.
69
+ * It reports the distance from the start to this point.</p>
70
+ *
71
+ * <p>This is used when figuring out how wide a finder pattern is, when the finder pattern
72
+ * may be skewed or rotated.</p>
73
+ */
74
+ private sizeOfBlackWhiteBlackRun;
75
+ /**
76
+ * <p>Attempts to locate an alignment pattern in a limited region of the image, which is
77
+ * guessed to contain it. This method uses {@link AlignmentPattern}.</p>
78
+ *
79
+ * @param overallEstModuleSize estimated module size so far
80
+ * @param estAlignmentX x coordinate of center of area probably containing alignment pattern
81
+ * @param estAlignmentY y coordinate of above
82
+ * @param allowanceFactor number of pixels in all directions to search from the center
83
+ * @return {@link AlignmentPattern} if found, or null otherwise
84
+ * @throws NotFoundException if an unexpected error occurs during detection
85
+ */
86
+ protected findAlignmentInRegion(overallEstModuleSize: number, estAlignmentX: number, estAlignmentY: number, allowanceFactor: number): AlignmentPattern;
87
+ }
@@ -0,0 +1,26 @@
1
+ import ResultPoint from '../../ResultPoint';
2
+ /**
3
+ * <p>Encapsulates a finder pattern, which are the three square patterns found in
4
+ * the corners of QR Codes. It also encapsulates a count of similar finder patterns,
5
+ * as a convenience to the finder's bookkeeping.</p>
6
+ *
7
+ * @author Sean Owen
8
+ */
9
+ export default class FinderPattern extends ResultPoint {
10
+ private estimatedModuleSize;
11
+ private count?;
12
+ constructor(posX: number, posY: number, estimatedModuleSize: number, count?: number | undefined);
13
+ getEstimatedModuleSize(): number;
14
+ getCount(): number | undefined;
15
+ /**
16
+ * <p>Determines if this finder pattern "about equals" a finder pattern at the stated
17
+ * position and size -- meaning, it is at nearly the same center with nearly the same size.</p>
18
+ */
19
+ aboutEquals(moduleSize: number, i: number, j: number): boolean;
20
+ /**
21
+ * Combines this object's current estimate of a finder pattern position and module size
22
+ * with a new estimate. It returns a new {@code FinderPattern} containing a weighted average
23
+ * based on count.
24
+ */
25
+ combineEstimate(i: number, j: number, newModuleSize: number): FinderPattern;
26
+ }
@@ -0,0 +1,114 @@
1
+ import BitMatrix from '../../common/BitMatrix';
2
+ import DecodeHintType from '../../DecodeHintType';
3
+ import ResultPointCallback from '../../ResultPointCallback';
4
+ import FinderPattern from './FinderPattern';
5
+ import FinderPatternInfo from './FinderPatternInfo';
6
+ /**
7
+ * <p>This class attempts to find finder patterns in a QR Code. Finder patterns are the square
8
+ * markers at three corners of a QR Code.</p>
9
+ *
10
+ * <p>This class is thread-safe but not reentrant. Each thread must allocate its own object.
11
+ *
12
+ * @author Sean Owen
13
+ */
14
+ export default class FinderPatternFinder {
15
+ private image;
16
+ private resultPointCallback;
17
+ private static CENTER_QUORUM;
18
+ protected static MIN_SKIP: number;
19
+ protected static MAX_MODULES: number;
20
+ private possibleCenters;
21
+ private hasSkipped?;
22
+ private crossCheckStateCount;
23
+ /**
24
+ * <p>Creates a finder that will search the image for three finder patterns.</p>
25
+ *
26
+ * @param image image to search
27
+ */
28
+ constructor(image: BitMatrix, resultPointCallback: ResultPointCallback);
29
+ protected getImage(): BitMatrix;
30
+ protected getPossibleCenters(): FinderPattern[];
31
+ find(hints: Map<DecodeHintType, any>): FinderPatternInfo;
32
+ /**
33
+ * Given a count of black/white/black/white/black pixels just seen and an end position,
34
+ * figures the location of the center of this run.
35
+ */
36
+ private static centerFromEnd;
37
+ /**
38
+ * @param stateCount count of black/white/black/white/black pixels just read
39
+ * @return true iff the proportions of the counts is close enough to the 1/1/3/1/1 ratios
40
+ * used by finder patterns to be considered a match
41
+ */
42
+ protected static foundPatternCross(stateCount: Int32Array): boolean;
43
+ private getCrossCheckStateCount;
44
+ /**
45
+ * After a vertical and horizontal scan finds a potential finder pattern, this method
46
+ * "cross-cross-cross-checks" by scanning down diagonally through the center of the possible
47
+ * finder pattern to see if the same proportion is detected.
48
+ *
49
+ * @param startI row where a finder pattern was detected
50
+ * @param centerJ center of the section that appears to cross a finder pattern
51
+ * @param maxCount maximum reasonable number of modules that should be
52
+ * observed in any reading state, based on the results of the horizontal scan
53
+ * @param originalStateCountTotal The original state count total.
54
+ * @return true if proportions are withing expected limits
55
+ */
56
+ private crossCheckDiagonal;
57
+ /**
58
+ * <p>After a horizontal scan finds a potential finder pattern, this method
59
+ * "cross-checks" by scanning down vertically through the center of the possible
60
+ * finder pattern to see if the same proportion is detected.</p>
61
+ *
62
+ * @param startI row where a finder pattern was detected
63
+ * @param centerJ center of the section that appears to cross a finder pattern
64
+ * @param maxCount maximum reasonable number of modules that should be
65
+ * observed in any reading state, based on the results of the horizontal scan
66
+ * @return vertical center of finder pattern, or {@link Float#NaN} if not found
67
+ */
68
+ private crossCheckVertical;
69
+ /**
70
+ * <p>Like {@link #crossCheckVertical(int, int, int, int)}, and in fact is basically identical,
71
+ * except it reads horizontally instead of vertically. This is used to cross-cross
72
+ * check a vertical cross check and locate the real center of the alignment pattern.</p>
73
+ */
74
+ private crossCheckHorizontal;
75
+ /**
76
+ * <p>This is called when a horizontal scan finds a possible alignment pattern. It will
77
+ * cross check with a vertical scan, and if successful, will, ah, cross-cross-check
78
+ * with another horizontal scan. This is needed primarily to locate the real horizontal
79
+ * center of the pattern in cases of extreme skew.
80
+ * And then we cross-cross-cross check with another diagonal scan.</p>
81
+ *
82
+ * <p>If that succeeds the finder pattern location is added to a list that tracks
83
+ * the number of times each location has been nearly-matched as a finder pattern.
84
+ * Each additional find is more evidence that the location is in fact a finder
85
+ * pattern center
86
+ *
87
+ * @param stateCount reading state module counts from horizontal scan
88
+ * @param i row where finder pattern may be found
89
+ * @param j end of possible finder pattern in row
90
+ * @param pureBarcode true if in "pure barcode" mode
91
+ * @return true if a finder pattern candidate was found this time
92
+ */
93
+ protected handlePossibleCenter(stateCount: Int32Array, i: number, j: number, pureBarcode: boolean): boolean;
94
+ /**
95
+ * @return number of rows we could safely skip during scanning, based on the first
96
+ * two finder patterns that have been located. In some cases their position will
97
+ * allow us to infer that the third pattern must lie below a certain point farther
98
+ * down in the image.
99
+ */
100
+ private findRowSkip;
101
+ /**
102
+ * @return true iff we have found at least 3 finder patterns that have been detected
103
+ * at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the
104
+ * candidates is "pretty similar"
105
+ */
106
+ private haveMultiplyConfirmedCenters;
107
+ /**
108
+ * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are
109
+ * those that have been detected at least {@link #CENTER_QUORUM} times, and whose module
110
+ * size differs from the average among those patterns the least
111
+ * @throws NotFoundException if 3 such finder patterns do not exist
112
+ */
113
+ private selectBestPatterns;
114
+ }
@@ -0,0 +1,16 @@
1
+ import FinderPattern from './FinderPattern';
2
+ /**
3
+ * <p>Encapsulates information about finder patterns in an image, including the location of
4
+ * the three finder patterns, and their estimated module size.</p>
5
+ *
6
+ * @author Sean Owen
7
+ */
8
+ export default class FinderPatternInfo {
9
+ private bottomLeft;
10
+ private topLeft;
11
+ private topRight;
12
+ constructor(patternCenters: FinderPattern[]);
13
+ getBottomLeft(): FinderPattern;
14
+ getTopLeft(): FinderPattern;
15
+ getTopRight(): FinderPattern;
16
+ }
@@ -0,0 +1,7 @@
1
+ export default class BlockPair {
2
+ private dataBytes;
3
+ private errorCorrectionBytes;
4
+ constructor(dataBytes: Uint8Array, errorCorrectionBytes: Uint8Array);
5
+ getDataBytes(): Uint8Array;
6
+ getErrorCorrectionBytes(): Uint8Array;
7
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
3
+ * -1, 0, and 1, I'm going to use less memory and go with bytes.
4
+ *
5
+ * @author dswitkin@google.com (Daniel Switkin)
6
+ */
7
+ export default class ByteMatrix {
8
+ private width;
9
+ private height;
10
+ private bytes;
11
+ constructor(width: number, height: number);
12
+ getHeight(): number;
13
+ getWidth(): number;
14
+ get(x: number, y: number): number;
15
+ /**
16
+ * @return an internal representation as bytes, in row-major order. array[y][x] represents point (x,y)
17
+ */
18
+ getArray(): Array<Uint8Array>;
19
+ setNumber(x: number, y: number, value: number): void;
20
+ setBoolean(x: number, y: number, value: boolean): void;
21
+ clear(value: number): void;
22
+ equals(o: any): boolean;
23
+ toString(): string;
24
+ }
@@ -0,0 +1,85 @@
1
+ import ErrorCorrectionLevel from '../decoder/ErrorCorrectionLevel';
2
+ import Mode from '../decoder/Mode';
3
+ import Version from '../decoder/Version';
4
+ import QRCode from './QRCode';
5
+ /**
6
+ * @author satorux@google.com (Satoru Takabayashi) - creator
7
+ * @author dswitkin@google.com (Daniel Switkin) - ported from C++
8
+ */
9
+ export default class Encoder {
10
+ private static ALPHANUMERIC_TABLE;
11
+ static DEFAULT_BYTE_MODE_ENCODING: string;
12
+ private constructor();
13
+ private static calculateMaskPenalty;
14
+ /**
15
+ * @param content text to encode
16
+ * @param ecLevel error correction level to use
17
+ * @return {@link QRCode} representing the encoded QR code
18
+ * @throws WriterException if encoding can't succeed, because of for example invalid content
19
+ * or configuration
20
+ */
21
+ static encode(content: string, ecLevel: ErrorCorrectionLevel, hints?: Map<EncodeHintType, any>): QRCode;
22
+ /**
23
+ * Decides the smallest version of QR code that will contain all of the provided data.
24
+ *
25
+ * @throws WriterException if the data cannot fit in any version
26
+ */
27
+ private static recommendVersion;
28
+ private static calculateBitsNeeded;
29
+ /**
30
+ * @return the code point of the table used in alphanumeric mode or
31
+ * -1 if there is no corresponding code in the table.
32
+ */
33
+ static getAlphanumericCode(code: number): number;
34
+ /**
35
+ * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
36
+ * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
37
+ */
38
+ static chooseMode(content: string, encoding?: string): Mode;
39
+ private static isOnlyDoubleByteKanji;
40
+ private static chooseMaskPattern;
41
+ private static chooseVersion;
42
+ /**
43
+ * @return true if the number of input bits will fit in a code with the specified version and
44
+ * error correction level.
45
+ */
46
+ private static willFit;
47
+ /**
48
+ * Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
49
+ */
50
+ static terminateBits(numDataBytes: number, bits: BitArray): void;
51
+ /**
52
+ * Get number of data bytes and number of error correction bytes for block id "blockID". Store
53
+ * the result in "numDataBytesInBlock", and "numECBytesInBlock". See table 12 in 8.5.1 of
54
+ * JISX0510:2004 (p.30)
55
+ */
56
+ static getNumDataBytesAndNumECBytesForBlockID(numTotalBytes: number, numDataBytes: number, numRSBlocks: number, blockID: number, numDataBytesInBlock: Int32Array, numECBytesInBlock: Int32Array): void;
57
+ /**
58
+ * Interleave "bits" with corresponding error correction bytes. On success, store the result in
59
+ * "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
60
+ */
61
+ static interleaveWithECBytes(bits: BitArray, numTotalBytes: number, numDataBytes: number, numRSBlocks: number): BitArray;
62
+ static generateECBytes(dataBytes: Uint8Array, numEcBytesInBlock: number): Uint8Array;
63
+ /**
64
+ * Append mode info. On success, store the result in "bits".
65
+ */
66
+ static appendModeInfo(mode: Mode, bits: BitArray): void;
67
+ /**
68
+ * Append length info. On success, store the result in "bits".
69
+ */
70
+ static appendLengthInfo(numLetters: number, version: Version, mode: Mode, bits: BitArray): void;
71
+ /**
72
+ * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
73
+ */
74
+ static appendBytes(content: string, mode: Mode, bits: BitArray, encoding: string): void;
75
+ private static getDigit;
76
+ private static isDigit;
77
+ static appendNumericBytes(content: string, bits: BitArray): void;
78
+ static appendAlphanumericBytes(content: string, bits: BitArray): void;
79
+ static append8BitBytes(content: string, bits: BitArray, encoding: string): void;
80
+ /**
81
+ * @throws WriterException
82
+ */
83
+ static appendKanjiBytes(content: string, bits: BitArray): void;
84
+ private static appendECI;
85
+ }