@zxing/browser
Version:
ZXing for JS's browser layer.
1,250 lines (1,222 loc) • 1.34 MB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ZXingBrowser = {}));
})(this, (function (exports) { 'use strict';
function fixProto(target, prototype) {
var setPrototypeOf = Object.setPrototypeOf;
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
}
function fixStack(target, fn) {
if (fn === void 0) {
fn = target.constructor;
}
var captureStackTrace = Error.captureStackTrace;
captureStackTrace && captureStackTrace(target, fn);
}
var __extends$19 = function () {
var _extendStatics = function extendStatics(d, b) {
_extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
}
};
return _extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
_extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}();
var CustomError = function (_super) {
__extends$19(CustomError, _super);
function CustomError(message, options) {
var _newTarget = this.constructor;
var _this = _super.call(this, message, options) || this;
Object.defineProperty(_this, 'name', {
value: _newTarget.name,
enumerable: false,
configurable: true
});
fixProto(_this, _newTarget.prototype);
fixStack(_this);
return _this;
}
return CustomError;
}(Error);
var __extends$18 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var Exception = /** @class */ (function (_super) {
__extends$18(Exception, _super);
/**
* Allows Exception to be constructed directly
* with some message and prototype definition.
*/
function Exception(message) {
if (message === void 0) { message = undefined; }
var _this = _super.call(this, message) || this;
_this.message = message;
return _this;
}
Exception.prototype.getKind = function () {
var ex = this.constructor;
return ex.kind;
};
/**
* It's typed as string so it can be extended and overriden.
*/
Exception.kind = 'Exception';
return Exception;
}(CustomError));
var __extends$17 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var ArgumentException = /** @class */ (function (_super) {
__extends$17(ArgumentException, _super);
function ArgumentException() {
return _super !== null && _super.apply(this, arguments) || this;
}
ArgumentException.kind = 'ArgumentException';
return ArgumentException;
}(Exception));
var __extends$16 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var IllegalArgumentException = /** @class */ (function (_super) {
__extends$16(IllegalArgumentException, _super);
function IllegalArgumentException() {
return _super !== null && _super.apply(this, arguments) || this;
}
IllegalArgumentException.kind = 'IllegalArgumentException';
return IllegalArgumentException;
}(Exception));
/*
* Copyright 2009 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var BinaryBitmap = /** @class */ (function () {
function BinaryBitmap(binarizer) {
this.binarizer = binarizer;
if (binarizer === null) {
throw new IllegalArgumentException('Binarizer must be non-null.');
}
}
/**
* @return The width of the bitmap.
*/
BinaryBitmap.prototype.getWidth = function () {
return this.binarizer.getWidth();
};
/**
* @return The height of the bitmap.
*/
BinaryBitmap.prototype.getHeight = function () {
return this.binarizer.getHeight();
};
/**
* Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
* cached data. Callers should assume this method is expensive and call it as seldom as possible.
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
*
* @param y The row to fetch, which must be in [0, bitmap height)
* @param row An optional preallocated array. If null or too small, it will be ignored.
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
* @return The array of bits for this row (true means black).
* @throws NotFoundException if row can't be binarized
*/
BinaryBitmap.prototype.getBlackRow = function (y /*int*/, row) {
return this.binarizer.getBlackRow(y, row);
};
/**
* Converts a 2D array of luminance data to 1 bit. As above, assume this method is expensive
* and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
* may not apply sharpening. Therefore, a row from this matrix may not be identical to one
* fetched using getBlackRow(), so don't mix and match between them.
*
* @return The 2D array of bits for the image (true means black).
* @throws NotFoundException if image can't be binarized to make a matrix
*/
BinaryBitmap.prototype.getBlackMatrix = function () {
// The matrix is created on demand the first time it is requested, then cached. There are two
// reasons for this:
// 1. This work will never be done if the caller only installs 1D Reader objects, or if a
// 1D Reader finds a barcode before the 2D Readers run.
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
if (this.matrix === null || this.matrix === undefined) {
this.matrix = this.binarizer.getBlackMatrix();
}
return this.matrix;
};
/**
* @return Whether this bitmap can be cropped.
*/
BinaryBitmap.prototype.isCropSupported = function () {
return this.binarizer.getLuminanceSource().isCropSupported();
};
/**
* Returns a new object with cropped image data. Implementations may keep a reference to the
* original data rather than a copy. Only callable if isCropSupported() is true.
*
* @param left The left coordinate, which must be in [0,getWidth())
* @param top The top coordinate, which must be in [0,getHeight())
* @param width The width of the rectangle to crop.
* @param height The height of the rectangle to crop.
* @return A cropped version of this object.
*/
BinaryBitmap.prototype.crop = function (left /*int*/, top /*int*/, width /*int*/, height /*int*/) {
var newSource = this.binarizer.getLuminanceSource().crop(left, top, width, height);
return new BinaryBitmap(this.binarizer.createBinarizer(newSource));
};
/**
* @return Whether this bitmap supports counter-clockwise rotation.
*/
BinaryBitmap.prototype.isRotateSupported = function () {
return this.binarizer.getLuminanceSource().isRotateSupported();
};
/**
* Returns a new object with rotated image data by 90 degrees counterclockwise.
* Only callable if {@link #isRotateSupported()} is true.
*
* @return A rotated version of this object.
*/
BinaryBitmap.prototype.rotateCounterClockwise = function () {
var newSource = this.binarizer.getLuminanceSource().rotateCounterClockwise();
return new BinaryBitmap(this.binarizer.createBinarizer(newSource));
};
/**
* Returns a new object with rotated image data by 45 degrees counterclockwise.
* Only callable if {@link #isRotateSupported()} is true.
*
* @return A rotated version of this object.
*/
BinaryBitmap.prototype.rotateCounterClockwise45 = function () {
var newSource = this.binarizer.getLuminanceSource().rotateCounterClockwise45();
return new BinaryBitmap(this.binarizer.createBinarizer(newSource));
};
/*@Override*/
BinaryBitmap.prototype.toString = function () {
try {
return this.getBlackMatrix().toString();
}
catch (e /*: NotFoundException*/) {
return '';
}
};
return BinaryBitmap;
}());
var __extends$15 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var ChecksumException = /** @class */ (function (_super) {
__extends$15(ChecksumException, _super);
function ChecksumException() {
return _super !== null && _super.apply(this, arguments) || this;
}
ChecksumException.getChecksumInstance = function () {
return new ChecksumException();
};
ChecksumException.kind = 'ChecksumException';
return ChecksumException;
}(Exception));
/*
* Copyright 2009 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This class hierarchy provides a set of methods to convert luminance data to 1 bit data.
* It allows the algorithm to vary polymorphically, for example allowing a very expensive
* thresholding technique for servers and a fast one for mobile. It also permits the implementation
* to vary, e.g. a JNI version for Android and a Java fallback version for other platforms.
*
* @author dswitkin@google.com (Daniel Switkin)
*/
var Binarizer = /** @class */ (function () {
function Binarizer(source) {
this.source = source;
}
Binarizer.prototype.getLuminanceSource = function () {
return this.source;
};
Binarizer.prototype.getWidth = function () {
return this.source.getWidth();
};
Binarizer.prototype.getHeight = function () {
return this.source.getHeight();
};
return Binarizer;
}());
var System = /** @class */ (function () {
function System() {
}
// public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
/**
* Makes a copy of a array.
*/
System.arraycopy = function (src, srcPos, dest, destPos, length) {
// TODO: better use split or set?
while (length--) {
dest[destPos++] = src[srcPos++];
}
};
/**
* Returns the current time in milliseconds.
*/
System.currentTimeMillis = function () {
return Date.now();
};
return System;
}());
var __extends$14 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var IndexOutOfBoundsException = /** @class */ (function (_super) {
__extends$14(IndexOutOfBoundsException, _super);
function IndexOutOfBoundsException() {
return _super !== null && _super.apply(this, arguments) || this;
}
IndexOutOfBoundsException.kind = 'IndexOutOfBoundsException';
return IndexOutOfBoundsException;
}(Exception));
var __extends$13 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var ArrayIndexOutOfBoundsException = /** @class */ (function (_super) {
__extends$13(ArrayIndexOutOfBoundsException, _super);
function ArrayIndexOutOfBoundsException(index, message) {
if (index === void 0) { index = undefined; }
if (message === void 0) { message = undefined; }
var _this = _super.call(this, message) || this;
_this.index = index;
_this.message = message;
return _this;
}
ArrayIndexOutOfBoundsException.kind = 'ArrayIndexOutOfBoundsException';
return ArrayIndexOutOfBoundsException;
}(IndexOutOfBoundsException));
var __values$G = (undefined && undefined.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var Arrays = /** @class */ (function () {
function Arrays() {
}
/**
* Assigns the specified int value to each element of the specified array
* of ints.
*
* @param a the array to be filled
* @param val the value to be stored in all elements of the array
*/
Arrays.fill = function (a, val) {
for (var i = 0, len = a.length; i < len; i++)
a[i] = val;
};
/**
* Assigns the specified int value to each element of the specified
* range of the specified array of ints. The range to be filled
* extends from index {@code fromIndex}, inclusive, to index
* {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
* @param fromIndex the index of the first element (inclusive) to be
* filled with the specified value
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
* @throws IllegalArgumentException if {@code fromIndex > toIndex}
* @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
* {@code toIndex > a.length}
*/
Arrays.fillWithin = function (a, fromIndex, toIndex, val) {
Arrays.rangeCheck(a.length, fromIndex, toIndex);
for (var i = fromIndex; i < toIndex; i++)
a[i] = val;
};
/**
* Checks that {@code fromIndex} and {@code toIndex} are in
* the range and throws an exception if they aren't.
*/
Arrays.rangeCheck = function (arrayLength, fromIndex, toIndex) {
if (fromIndex > toIndex) {
throw new IllegalArgumentException('fromIndex(' + fromIndex + ') > toIndex(' + toIndex + ')');
}
if (fromIndex < 0) {
throw new ArrayIndexOutOfBoundsException(fromIndex);
}
if (toIndex > arrayLength) {
throw new ArrayIndexOutOfBoundsException(toIndex);
}
};
Arrays.asList = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return args;
};
Arrays.create = function (rows, cols, value) {
var arr = Array.from({ length: rows });
return arr.map(function (x) { return Array.from({ length: cols }).fill(value); });
};
Arrays.createInt32Array = function (rows, cols, value) {
var arr = Array.from({ length: rows });
return arr.map(function (x) { return Int32Array.from({ length: cols }).fill(value); });
};
Arrays.equals = function (first, second) {
if (!first) {
return false;
}
if (!second) {
return false;
}
if (!first.length) {
return false;
}
if (!second.length) {
return false;
}
if (first.length !== second.length) {
return false;
}
for (var i = 0, length_1 = first.length; i < length_1; i++) {
if (first[i] !== second[i]) {
return false;
}
}
return true;
};
Arrays.hashCode = function (a) {
var e_1, _a;
if (a === null) {
return 0;
}
var result = 1;
try {
for (var a_1 = __values$G(a), a_1_1 = a_1.next(); !a_1_1.done; a_1_1 = a_1.next()) {
var element = a_1_1.value;
result = 31 * result + element;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (a_1_1 && !a_1_1.done && (_a = a_1.return)) _a.call(a_1);
}
finally { if (e_1) throw e_1.error; }
}
return result;
};
Arrays.fillUint8Array = function (a, value) {
for (var i = 0; i !== a.length; i++) {
a[i] = value;
}
};
Arrays.copyOf = function (original, newLength) {
return original.slice(0, newLength);
};
Arrays.copyOfUint8Array = function (original, newLength) {
if (original.length <= newLength) {
var newArray = new Uint8Array(newLength);
newArray.set(original);
return newArray;
}
return original.slice(0, newLength);
};
Arrays.copyOfRange = function (original, from, to) {
var newLength = to - from;
var copy = new Int32Array(newLength);
System.arraycopy(original, from, copy, 0, newLength);
return copy;
};
/*
* Returns the index of of the element in a sorted array or (-n-1) where n is the insertion point
* for the new element.
* Parameters:
* ar - A sorted array
* el - An element to search for
* comparator - A comparator function. The function takes two arguments: (a, b) and returns:
* a negative number if a is less than b;
* 0 if a is equal to b;
* a positive number of a is greater than b.
* The array may contain duplicate elements. If there are more than one equal elements in the array,
* the returned value can be the index of any one of the equal elements.
*
* http://jsfiddle.net/aryzhov/pkfst550/
*/
Arrays.binarySearch = function (ar, el, comparator) {
if (undefined === comparator) {
comparator = Arrays.numberComparator;
}
var m = 0;
var n = ar.length - 1;
while (m <= n) {
var k = (n + m) >> 1;
var cmp = comparator(el, ar[k]);
if (cmp > 0) {
m = k + 1;
}
else if (cmp < 0) {
n = k - 1;
}
else {
return k;
}
}
return -m - 1;
};
Arrays.numberComparator = function (a, b) {
return a - b;
};
return Arrays;
}());
/**
* Ponyfill for Java's Integer class.
*/
var Integer = /** @class */ (function () {
function Integer() {
}
Integer.numberOfTrailingZeros = function (i) {
var y;
if (i === 0)
return 32;
var n = 31;
y = i << 16;
if (y !== 0) {
n -= 16;
i = y;
}
y = i << 8;
if (y !== 0) {
n -= 8;
i = y;
}
y = i << 4;
if (y !== 0) {
n -= 4;
i = y;
}
y = i << 2;
if (y !== 0) {
n -= 2;
i = y;
}
return n - ((i << 1) >>> 31);
};
Integer.numberOfLeadingZeros = function (i) {
// HD, Figure 5-6
if (i === 0) {
return 32;
}
var n = 1;
if (i >>> 16 === 0) {
n += 16;
i <<= 16;
}
if (i >>> 24 === 0) {
n += 8;
i <<= 8;
}
if (i >>> 28 === 0) {
n += 4;
i <<= 4;
}
if (i >>> 30 === 0) {
n += 2;
i <<= 2;
}
n -= i >>> 31;
return n;
};
Integer.toHexString = function (i) {
return i.toString(16);
};
Integer.toBinaryString = function (intNumber) {
return String(parseInt(String(intNumber), 2));
};
// Returns the number of one-bits in the two's complement binary representation of the specified int value. This function is sometimes referred to as the population count.
// Returns:
// the number of one-bits in the two's complement binary representation of the specified int value.
Integer.bitCount = function (i) {
// HD, Figure 5-2
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;
};
Integer.truncDivision = function (dividend, divisor) {
return Math.trunc(dividend / divisor);
};
/**
* Converts A string to an integer.
* @param s A string to convert into a number.
* @param radix A value between 2 and 36 that specifies the base of the number in numString. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
*/
Integer.parseInt = function (num, radix) {
if (radix === void 0) { radix = undefined; }
return parseInt(num, radix);
};
Integer.MIN_VALUE_32_BITS = -2147483648;
Integer.MAX_VALUE = Number.MAX_SAFE_INTEGER;
return Integer;
}());
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>
*
* @author Sean Owen
*/
var BitArray /*implements Cloneable*/ = /** @class */ (function () {
// public constructor() {
// this.size = 0
// this.bits = new Int32Array(1)
// }
// public constructor(size?: number /*int*/) {
// if (undefined === size) {
// this.size = 0
// } else {
// this.size = size
// }
// this.bits = this.makeArray(size)
// }
// For testing only
function BitArray(size /*int*/, bits) {
if (undefined === size) {
this.size = 0;
this.bits = new Int32Array(1);
}
else {
this.size = size;
if (undefined === bits || null === bits) {
this.bits = BitArray.makeArray(size);
}
else {
this.bits = bits;
}
}
}
BitArray.prototype.getSize = function () {
return this.size;
};
BitArray.prototype.getSizeInBytes = function () {
return Math.floor((this.size + 7) / 8);
};
BitArray.prototype.ensureCapacity = function (size /*int*/) {
if (size > this.bits.length * 32) {
var newBits = BitArray.makeArray(size);
System.arraycopy(this.bits, 0, newBits, 0, this.bits.length);
this.bits = newBits;
}
};
/**
* @param i bit to get
* @return true iff bit i is set
*/
BitArray.prototype.get = function (i /*int*/) {
return (this.bits[Math.floor(i / 32)] & (1 << (i & 0x1F))) !== 0;
};
/**
* Sets bit i.
*
* @param i bit to set
*/
BitArray.prototype.set = function (i /*int*/) {
this.bits[Math.floor(i / 32)] |= 1 << (i & 0x1F);
};
/**
* Flips bit i.
*
* @param i bit to set
*/
BitArray.prototype.flip = function (i /*int*/) {
this.bits[Math.floor(i / 32)] ^= 1 << (i & 0x1F);
};
/**
* @param from first bit to check
* @return index of first bit that is set, starting from the given index, or size if none are set
* at or beyond this given index
* @see #getNextUnset(int)
*/
BitArray.prototype.getNextSet = function (from /*int*/) {
var size = this.size;
if (from >= size) {
return size;
}
var bits = this.bits;
var bitsOffset = Math.floor(from / 32);
var currentBits = bits[bitsOffset];
// mask off lesser bits first
currentBits &= ~((1 << (from & 0x1F)) - 1);
var length = bits.length;
while (currentBits === 0) {
if (++bitsOffset === length) {
return size;
}
currentBits = bits[bitsOffset];
}
var result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
};
/**
* @param from index to start looking for unset bit
* @return index of next unset bit, or {@code size} if none are unset until the end
* @see #getNextSet(int)
*/
BitArray.prototype.getNextUnset = function (from /*int*/) {
var size = this.size;
if (from >= size) {
return size;
}
var bits = this.bits;
var bitsOffset = Math.floor(from / 32);
var currentBits = ~bits[bitsOffset];
// mask off lesser bits first
currentBits &= ~((1 << (from & 0x1F)) - 1);
var length = bits.length;
while (currentBits === 0) {
if (++bitsOffset === length) {
return size;
}
currentBits = ~bits[bitsOffset];
}
var result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
};
/**
* Sets a block of 32 bits, starting at bit i.
*
* @param i first bit to set
* @param newBits the new value of the next 32 bits. Note again that the least-significant bit
* corresponds to bit i, the next-least-significant to i+1, and so on.
*/
BitArray.prototype.setBulk = function (i /*int*/, newBits /*int*/) {
this.bits[Math.floor(i / 32)] = newBits;
};
/**
* Sets a range of bits.
*
* @param start start of range, inclusive.
* @param end end of range, exclusive
*/
BitArray.prototype.setRange = function (start /*int*/, end /*int*/) {
if (end < start || start < 0 || end > this.size) {
throw new IllegalArgumentException();
}
if (end === start) {
return;
}
end--; // will be easier to treat this as the last actually set bit -- inclusive
var firstInt = Math.floor(start / 32);
var lastInt = Math.floor(end / 32);
var bits = this.bits;
for (var i = firstInt; i <= lastInt; i++) {
var firstBit = i > firstInt ? 0 : start & 0x1F;
var lastBit = i < lastInt ? 31 : end & 0x1F;
// Ones from firstBit to lastBit, inclusive
var mask = (2 << lastBit) - (1 << firstBit);
bits[i] |= mask;
}
};
/**
* Clears all bits (sets to false).
*/
BitArray.prototype.clear = function () {
var max = this.bits.length;
var bits = this.bits;
for (var i = 0; i < max; i++) {
bits[i] = 0;
}
};
/**
* Efficient method to check if a range of bits is set, or not set.
*
* @param start start of range, inclusive.
* @param end end of range, exclusive
* @param value if true, checks that bits in range are set, otherwise checks that they are not set
* @return true iff all bits are set or not set in range, according to value argument
* @throws IllegalArgumentException if end is less than start or the range is not contained in the array
*/
BitArray.prototype.isRange = function (start /*int*/, end /*int*/, value) {
if (end < start || start < 0 || end > this.size) {
throw new IllegalArgumentException();
}
if (end === start) {
return true; // empty range matches
}
end--; // will be easier to treat this as the last actually set bit -- inclusive
var firstInt = Math.floor(start / 32);
var lastInt = Math.floor(end / 32);
var bits = this.bits;
for (var i = firstInt; i <= lastInt; i++) {
var firstBit = i > firstInt ? 0 : start & 0x1F;
var lastBit = i < lastInt ? 31 : end & 0x1F;
// Ones from firstBit to lastBit, inclusive
var mask = (2 << lastBit) - (1 << firstBit) & 0xFFFFFFFF;
// TYPESCRIPTPORT: & 0xFFFFFFFF added to discard anything after 32 bits, as ES has 53 bits
// Return false if we're looking for 1s and the masked bits[i] isn't all 1s (is: that,
// equals the mask, or we're looking for 0s and the masked portion is not all 0s
if ((bits[i] & mask) !== (value ? mask : 0)) {
return false;
}
}
return true;
};
BitArray.prototype.appendBit = function (bit) {
this.ensureCapacity(this.size + 1);
if (bit) {
this.bits[Math.floor(this.size / 32)] |= 1 << (this.size & 0x1F);
}
this.size++;
};
/**
* Appends the least-significant bits, from value, in order from most-significant to
* least-significant. For example, appending 6 bits from 0x000001E will append the bits
* 0, 1, 1, 1, 1, 0 in that order.
*
* @param value {@code int} containing bits to append
* @param numBits bits from value to append
*/
BitArray.prototype.appendBits = function (value /*int*/, numBits /*int*/) {
if (numBits < 0 || numBits > 32) {
throw new IllegalArgumentException('Num bits must be between 0 and 32');
}
this.ensureCapacity(this.size + numBits);
// const appendBit = this.appendBit;
for (var numBitsLeft = numBits; numBitsLeft > 0; numBitsLeft--) {
this.appendBit(((value >> (numBitsLeft - 1)) & 0x01) === 1);
}
};
BitArray.prototype.appendBitArray = function (other) {
var otherSize = other.size;
this.ensureCapacity(this.size + otherSize);
// const appendBit = this.appendBit;
for (var i = 0; i < otherSize; i++) {
this.appendBit(other.get(i));
}
};
BitArray.prototype.xor = function (other) {
if (this.size !== other.size) {
throw new IllegalArgumentException('Sizes don\'t match');
}
var bits = this.bits;
for (var i = 0, length_1 = bits.length; i < length_1; i++) {
// The last int could be incomplete (i.e. not have 32 bits in
// it) but there is no problem since 0 XOR 0 == 0.
bits[i] ^= other.bits[i];
}
};
/**
*
* @param bitOffset first bit to start writing
* @param array array to write into. Bytes are written most-significant byte first. This is the opposite
* of the internal representation, which is exposed by {@link #getBitArray()}
* @param offset position in array to start writing
* @param numBytes how many bytes to write
*/
BitArray.prototype.toBytes = function (bitOffset /*int*/, array, offset /*int*/, numBytes /*int*/) {
for (var i = 0; i < numBytes; i++) {
var theByte = 0;
for (var j = 0; j < 8; j++) {
if (this.get(bitOffset)) {
theByte |= 1 << (7 - j);
}
bitOffset++;
}
array[offset + i] = /*(byte)*/ theByte;
}
};
/**
* @return underlying array of ints. The first element holds the first 32 bits, and the least
* significant bit is bit 0.
*/
BitArray.prototype.getBitArray = function () {
return this.bits;
};
/**
* Reverses all bits in the array.
*/
BitArray.prototype.reverse = function () {
var newBits = new Int32Array(this.bits.length);
// reverse all int's first
var len = Math.floor((this.size - 1) / 32);
var oldBitsLen = len + 1;
var bits = this.bits;
for (var i = 0; i < oldBitsLen; i++) {
var x = bits[i];
x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
x = ((x >> 4) & 0x0f0f0f0f) | ((x & 0x0f0f0f0f) << 4);
x = ((x >> 8) & 0x00ff00ff) | ((x & 0x00ff00ff) << 8);
x = ((x >> 16) & 0x0000ffff) | ((x & 0x0000ffff) << 16);
newBits[len - i] = /*(int)*/ x;
}
// now correct the int's if the bit size isn't a multiple of 32
if (this.size !== oldBitsLen * 32) {
var leftOffset = oldBitsLen * 32 - this.size;
var currentInt = newBits[0] >>> leftOffset;
for (var i = 1; i < oldBitsLen; i++) {
var nextInt = newBits[i];
currentInt |= nextInt << (32 - leftOffset);
newBits[i - 1] = currentInt;
currentInt = nextInt >>> leftOffset;
}
newBits[oldBitsLen - 1] = currentInt;
}
this.bits = newBits;
};
BitArray.makeArray = function (size /*int*/) {
return new Int32Array(Math.floor((size + 31) / 32));
};
/*@Override*/
BitArray.prototype.equals = function (o) {
if (!(o instanceof BitArray)) {
return false;
}
var other = o;
return this.size === other.size && Arrays.equals(this.bits, other.bits);
};
/*@Override*/
BitArray.prototype.hashCode = function () {
return 31 * this.size + Arrays.hashCode(this.bits);
};
/*@Override*/
BitArray.prototype.toString = function () {
var result = '';
for (var i = 0, size = this.size; i < size; i++) {
if ((i & 0x07) === 0) {
result += ' ';
}
result += this.get(i) ? 'X' : '.';
}
return result;
};
/*@Override*/
BitArray.prototype.clone = function () {
return new BitArray(this.size, this.bits.slice());
};
/**
* converts to boolean array.
*/
BitArray.prototype.toArray = function () {
var result = [];
for (var i = 0, size = this.size; i < size; i++) {
result.push(this.get(i));
}
return result;
};
return BitArray;
}());
/*
* Copyright 2009 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*namespace com.google.zxing {*/
/**
* Encapsulates a type of hint that a caller may pass to a barcode reader to help it
* more quickly or accurately decode it. It is up to implementations to decide what,
* if anything, to do with the information that is supplied.
*
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
* @see Reader#decode(BinaryBitmap,java.util.Map)
*/
var DecodeHintType;
(function (DecodeHintType) {
/**
* Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
*/
DecodeHintType[DecodeHintType["OTHER"] = 0] = "OTHER"; /*(Object.class)*/
/**
* Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["PURE_BARCODE"] = 1] = "PURE_BARCODE"; /*(Void.class)*/
/**
* Image is known to be of one of a few possible formats.
* Maps to a {@link List} of {@link BarcodeFormat}s.
*/
DecodeHintType[DecodeHintType["POSSIBLE_FORMATS"] = 2] = "POSSIBLE_FORMATS"; /*(List.class)*/
/**
* Spend more time to try to find a barcode; optimize for accuracy, not speed.
* Doesn't matter what it maps to; use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["TRY_HARDER"] = 3] = "TRY_HARDER"; /*(Void.class)*/
/**
* Specifies what character encoding to use when decoding, where applicable (type String)
*/
DecodeHintType[DecodeHintType["CHARACTER_SET"] = 4] = "CHARACTER_SET"; /*(String.class)*/
/**
* Allowed lengths of encoded data -- reject anything else. Maps to an {@code Int32Array}.
*/
DecodeHintType[DecodeHintType["ALLOWED_LENGTHS"] = 5] = "ALLOWED_LENGTHS"; /*(Int32Array.class)*/
/**
* Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["ASSUME_CODE_39_CHECK_DIGIT"] = 6] = "ASSUME_CODE_39_CHECK_DIGIT"; /*(Void.class)*/
/**
* Enable extended mode for Code 39 codes. Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["ENABLE_CODE_39_EXTENDED_MODE"] = 7] = "ENABLE_CODE_39_EXTENDED_MODE"; /*(Void.class)*/
/**
* Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed.
* For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["ASSUME_GS1"] = 8] = "ASSUME_GS1"; /*(Void.class)*/
/**
* If true, return the start and end digits in a Codabar barcode instead of stripping them. They
* are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them
* to not be. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["RETURN_CODABAR_START_END"] = 9] = "RETURN_CODABAR_START_END"; /*(Void.class)*/
/**
* The caller needs to be notified via callback when a possible {@link ResultPoint}
* is found. Maps to a {@link ResultPointCallback}.
*/
DecodeHintType[DecodeHintType["NEED_RESULT_POINT_CALLBACK"] = 10] = "NEED_RESULT_POINT_CALLBACK"; /*(ResultPointCallback.class)*/
/**
* Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
* Maps to an {@code Int32Array} of the allowed extension lengths, for example [2], [5], or [2, 5].
* If it is optional to have an extension, do not set this hint. If this is set,
* and a UPC or EAN barcode is found but an extension is not, then no result will be returned
* at all.
*/
DecodeHintType[DecodeHintType["ALLOWED_EAN_EXTENSIONS"] = 11] = "ALLOWED_EAN_EXTENSIONS"; /*(Int32Array.class)*/
// End of enumeration values.
/**
* Data type the hint is expecting.
* Among the possible values the {@link Void} stands out as being used for
* hints that do not expect a value to be supplied (flag hints). Such hints
* will possibly have their value ignored, or replaced by a
* {@link Boolean#TRUE}. Hint suppliers should probably use
* {@link Boolean#TRUE} as directed by the actual hint documentation.
*/
// private valueType: Class<?>
// DecodeHintType(valueType: Class<?>) {
// this.valueType = valueType
// }
// public getValueType(): Class<?> {
// return valueType
// }
})(DecodeHintType || (DecodeHintType = {}));
var DecodeHintType$1 = DecodeHintType;
var __extends$12 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* Custom Error class of type Exception.
*/
var FormatException = /** @class */ (function (_super) {
__extends$12(FormatException, _super);
function FormatException() {
return _super !== null && _super.apply(this, arguments) || this;
}
FormatException.getFormatInstance = function () {
return new FormatException();
};
FormatException.kind = 'FormatException';
return FormatException;
}(Exception));
/*
* Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __values$F = (undefined && undefined.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
/*import java.util.HashMap;*/
/*import java.util.Map;*/
var CharacterSetValueIdentifiers;
(function (CharacterSetValueIdentifiers) {
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Cp437"] = 0] = "Cp437";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_1"] = 1] = "ISO8859_1";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_2"] = 2] = "ISO8859_2";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_3"] = 3] = "ISO8859_3";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_4"] = 4] = "ISO8859_4";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_5"] = 5] = "ISO8859_5";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_6"] = 6] = "ISO8859_6";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_7"] = 7] = "ISO8859_7";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_8"] = 8] = "ISO8859_8";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_9"] = 9] = "ISO8859_9";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_10"] = 10] = "ISO8859_10";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_11"] = 11] = "ISO8859_11";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_13"] = 12] = "ISO8859_13";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_14"] = 13] = "ISO8859_14";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_15"] = 14] = "ISO8859_15";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_16"] = 15] = "ISO8859_16";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["SJIS"] = 16] = "SJIS";
CharacterSetValueId