Result.js 5.1 KB

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