Result.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. "use strict";
  2. /*
  3. * Copyright 2007 ZXing authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. var System_1 = require("./util/System");
  19. /**
  20. * <p>Encapsulates the result of decoding a barcode within an image.</p>
  21. *
  22. * @author Sean Owen
  23. */
  24. var Result = /** @class */ (function () {
  25. // public constructor(private text: string,
  26. // Uint8Array rawBytes,
  27. // ResultPoconst resultPoints: Int32Array,
  28. // BarcodeFormat format) {
  29. // this(text, rawBytes, resultPoints, format, System.currentTimeMillis())
  30. // }
  31. // public constructor(text: string,
  32. // Uint8Array rawBytes,
  33. // ResultPoconst resultPoints: Int32Array,
  34. // BarcodeFormat format,
  35. // long timestamp) {
  36. // this(text, rawBytes, rawBytes == null ? 0 : 8 * rawBytes.length,
  37. // resultPoints, format, timestamp)
  38. // }
  39. function Result(text, rawBytes, numBits, resultPoints, format, timestamp) {
  40. if (numBits === void 0) { numBits = rawBytes == null ? 0 : 8 * rawBytes.length; }
  41. if (timestamp === void 0) { timestamp = System_1.default.currentTimeMillis(); }
  42. this.text = text;
  43. this.rawBytes = rawBytes;
  44. this.numBits = numBits;
  45. this.resultPoints = resultPoints;
  46. this.format = format;
  47. this.timestamp = timestamp;
  48. this.text = text;
  49. this.rawBytes = rawBytes;
  50. if (undefined === numBits || null === numBits) {
  51. this.numBits = (rawBytes === null || rawBytes === undefined) ? 0 : 8 * rawBytes.length;
  52. }
  53. else {
  54. this.numBits = numBits;
  55. }
  56. this.resultPoints = resultPoints;
  57. this.format = format;
  58. this.resultMetadata = null;
  59. if (undefined === timestamp || null === timestamp) {
  60. this.timestamp = System_1.default.currentTimeMillis();
  61. }
  62. else {
  63. this.timestamp = timestamp;
  64. }
  65. }
  66. /**
  67. * @return raw text encoded by the barcode
  68. */
  69. Result.prototype.getText = function () {
  70. return this.text;
  71. };
  72. /**
  73. * @return raw bytes encoded by the barcode, if applicable, otherwise {@code null}
  74. */
  75. Result.prototype.getRawBytes = function () {
  76. return this.rawBytes;
  77. };
  78. /**
  79. * @return how many bits of {@link #getRawBytes()} are valid; typically 8 times its length
  80. * @since 3.3.0
  81. */
  82. Result.prototype.getNumBits = function () {
  83. return this.numBits;
  84. };
  85. /**
  86. * @return points related to the barcode in the image. These are typically points
  87. * identifying finder patterns or the corners of the barcode. The exact meaning is
  88. * specific to the type of barcode that was decoded.
  89. */
  90. Result.prototype.getResultPoints = function () {
  91. return this.resultPoints;
  92. };
  93. /**
  94. * @return {@link BarcodeFormat} representing the format of the barcode that was decoded
  95. */
  96. Result.prototype.getBarcodeFormat = function () {
  97. return this.format;
  98. };
  99. /**
  100. * @return {@link Map} mapping {@link ResultMetadataType} keys to values. May be
  101. * {@code null}. This contains optional metadata about what was detected about the barcode,
  102. * like orientation.
  103. */
  104. Result.prototype.getResultMetadata = function () {
  105. return this.resultMetadata;
  106. };
  107. Result.prototype.putMetadata = function (type, value) {
  108. if (this.resultMetadata === null) {
  109. this.resultMetadata = new Map();
  110. }
  111. this.resultMetadata.set(type, value);
  112. };
  113. Result.prototype.putAllMetadata = function (metadata) {
  114. if (metadata !== null) {
  115. if (this.resultMetadata === null) {
  116. this.resultMetadata = metadata;
  117. }
  118. else {
  119. this.resultMetadata = new Map(metadata);
  120. }
  121. }
  122. };
  123. Result.prototype.addResultPoints = function (newPoints) {
  124. var oldPoints = this.resultPoints;
  125. if (oldPoints === null) {
  126. this.resultPoints = newPoints;
  127. }
  128. else if (newPoints !== null && newPoints.length > 0) {
  129. var allPoints = new Array(oldPoints.length + newPoints.length);
  130. System_1.default.arraycopy(oldPoints, 0, allPoints, 0, oldPoints.length);
  131. System_1.default.arraycopy(newPoints, 0, allPoints, oldPoints.length, newPoints.length);
  132. this.resultPoints = allPoints;
  133. }
  134. };
  135. Result.prototype.getTimestamp = function () {
  136. return this.timestamp;
  137. };
  138. /*@Override*/
  139. Result.prototype.toString = function () {
  140. return this.text;
  141. };
  142. return Result;
  143. }());
  144. exports.default = Result;