UNPKG

@tjieco/library

Version:

TypeScript port of ZXing multi-format 1D/2D barcode image processing library, with Code128 and ITF support.

1,318 lines (1,288 loc) 539 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("text-encoding")); else if(typeof define === 'function' && define.amd) define("Library", ["text-encoding"], factory); else if(typeof exports === 'object') exports["Library"] = factory(require("text-encoding")); else root["Library"] = factory(root["text-encoding"]); })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_37__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 50); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Exception = /** @class */ (function () { function Exception(type, message) { this.type = type; this.message = message; } Exception.prototype.getType = function () { return this.type; }; Exception.prototype.getMessage = function () { return this.message; }; Exception.isOfType = function (ex, type) { return ex.type === type; }; Exception.IllegalArgumentException = 'IllegalArgumentException'; Exception.NotFoundException = 'NotFoundException'; Exception.ArithmeticException = 'ArithmeticException'; Exception.FormatException = 'FormatException'; Exception.ChecksumException = 'ChecksumException'; Exception.WriterException = 'WriterException'; Exception.IllegalStateException = 'IllegalStateException'; Exception.UnsupportedOperationException = 'UnsupportedOperationException'; Exception.ReedSolomonException = 'ReedSolomonException'; Exception.ArgumentException = 'ArgumentException'; Exception.ReaderException = 'ReaderException'; return Exception; }()); exports.default = Exception; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var System = /** @class */ (function () { function System() { } // public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) System.arraycopy = function (src, srcPos, dest, destPos, length) { // TODO: better use split or set? var i = srcPos; var j = destPos; var c = length; while (c--) { dest[j++] = src[i++]; } }; System.currentTimeMillis = function () { return Date.now(); }; return System; }()); exports.default = System; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); /*namespace com.google.zxing {*/ var MathUtils_1 = __webpack_require__(13); var Float_1 = __webpack_require__(53); /** * <p>Encapsulates a point of interest in an image containing a barcode. Typically, this * would be the location of a finder pattern or the corner of the barcode, for example.</p> * * @author Sean Owen */ var ResultPoint = /** @class */ (function () { function ResultPoint(x /*float*/, y /*float*/) { this.x = x; this.y = y; } ResultPoint.prototype.getX = function () { return this.x; }; ResultPoint.prototype.getY = function () { return this.y; }; /*@Override*/ ResultPoint.prototype.equals = function (other) { if (other instanceof ResultPoint) { var otherPoint = other; return this.x === otherPoint.x && this.y === otherPoint.y; } return false; }; /*@Override*/ ResultPoint.prototype.hashCode = function () { return 31 * Float_1.default.floatToIntBits(this.x) + Float_1.default.floatToIntBits(this.y); }; /*@Override*/ ResultPoint.prototype.toString = function () { return '(' + this.x + ',' + this.y + ')'; }; /** * Orders an array of three ResultPoints in an order [A,B,C] such that AB is less than AC * and BC is less than AC, and the angle between BC and BA is less than 180 degrees. * * @param patterns array of three {@code ResultPoint} to order */ ResultPoint.orderBestPatterns = function (patterns) { // Find distances between pattern centers var zeroOneDistance = this.distance(patterns[0], patterns[1]); var oneTwoDistance = this.distance(patterns[1], patterns[2]); var zeroTwoDistance = this.distance(patterns[0], patterns[2]); var pointA; var pointB; var pointC; // Assume one closest to other two is B; A and C will just be guesses at first if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) { pointB = patterns[0]; pointA = patterns[1]; pointC = patterns[2]; } else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) { pointB = patterns[1]; pointA = patterns[0]; pointC = patterns[2]; } else { pointB = patterns[2]; pointA = patterns[0]; pointC = patterns[1]; } // Use cross product to figure out whether A and C are correct or flipped. // This asks whether BC x BA has a positive z component, which is the arrangement // we want for A, B, C. If it's negative, then we've got it flipped around and // should swap A and C. if (this.crossProductZ(pointA, pointB, pointC) < 0.0) { var temp = pointA; pointA = pointC; pointC = temp; } patterns[0] = pointA; patterns[1] = pointB; patterns[2] = pointC; }; /** * @param pattern1 first pattern * @param pattern2 second pattern * @return distance between two points */ ResultPoint.distance = function (pattern1, pattern2) { return MathUtils_1.default.distance(pattern1.x, pattern1.y, pattern2.x, pattern2.y); }; /** * Returns the z component of the cross product between vectors BC and BA. */ ResultPoint.crossProductZ = function (pointA, pointB, pointC) { var bX = pointB.x; var bY = pointB.y; return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX)); }; return ResultPoint; }()); exports.default = ResultPoint; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); /*namespace com.google.zxing.common {*/ /*import java.util.Arrays;*/ var Exception_1 = __webpack_require__(0); var BitArray_1 = __webpack_require__(4); var System_1 = __webpack_require__(1); var Arrays_1 = __webpack_require__(17); var StringBuilder_1 = __webpack_require__(5); /** * <p>Represents a 2D matrix of bits. In function arguments below, and throughout the common * module, x is the column position, and y is the row position. The ordering is always x, y. * The origin is at the top-left.</p> * * <p>Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins * with a new int. This is done intentionally so that we can copy out a row into a BitArray very * efficiently.</p> * * <p>The ordering of bits is row-major. Within each int, the least significant bits are used first, * meaning they represent lower x values. This is compatible with BitArray's implementation.</p> * * @author Sean Owen * @author dswitkin@google.com (Daniel Switkin) */ var BitMatrix /*implements Cloneable*/ = /** @class */ (function () { /** * Creates an empty square {@link BitMatrix}. * * @param dimension height and width */ // public constructor(dimension: number /*int*/) { // this(dimension, dimension) // } /** * Creates an empty {@link BitMatrix}. * * @param width bit matrix width * @param height bit matrix height */ // public constructor(width: number /*int*/, height: number /*int*/) { // if (width < 1 || height < 1) { // throw new Exception(Exception.IllegalArgumentException, "Both dimensions must be greater than 0") // } // this.width = width // this.height = height // this.rowSize = (width + 31) / 32 // bits = new int[rowSize * height]; // } function BitMatrix(width /*int*/, height /*int*/, rowSize /*int*/, bits) { this.width = width; this.height = height; this.rowSize = rowSize; this.bits = bits; if (undefined === height || null === height) { height = width; } this.height = height; if (width < 1 || height < 1) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'Both dimensions must be greater than 0'); } if (undefined === rowSize || null === rowSize) { rowSize = Math.floor((width + 31) / 32); } this.rowSize = rowSize; if (undefined === bits || null === bits) { this.bits = new Int32Array(this.rowSize * this.height); } } /** * Interprets a 2D array of booleans as a {@link BitMatrix}, where "true" means an "on" bit. * * @param image bits of the image, as a row-major 2D array. Elements are arrays representing rows * @return {@link BitMatrix} representation of image */ BitMatrix.parseFromBooleanArray = function (image) { var height = image.length; var width = image[0].length; var bits = new BitMatrix(width, height); for (var i = 0; i < height; i++) { var imageI = image[i]; for (var j = 0; j < width; j++) { if (imageI[j]) { bits.set(j, i); } } } return bits; }; BitMatrix.parseFromString = function (stringRepresentation, setString, unsetString) { if (stringRepresentation === null) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'stringRepresentation cannot be null'); } var bits = new Array(stringRepresentation.length); var bitsPos = 0; var rowStartPos = 0; var rowLength = -1; var nRows = 0; var pos = 0; while (pos < stringRepresentation.length) { if (stringRepresentation.charAt(pos) === '\n' || stringRepresentation.charAt(pos) === '\r') { if (bitsPos > rowStartPos) { if (rowLength === -1) { rowLength = bitsPos - rowStartPos; } else if (bitsPos - rowStartPos !== rowLength) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'row lengths do not match'); } rowStartPos = bitsPos; nRows++; } pos++; } else if (stringRepresentation.substring(pos, pos + setString.length) === setString) { pos += setString.length; bits[bitsPos] = true; bitsPos++; } else if (stringRepresentation.substring(pos, pos + unsetString.length) === unsetString) { pos += unsetString.length; bits[bitsPos] = false; bitsPos++; } else { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'illegal character encountered: ' + stringRepresentation.substring(pos)); } } // no EOL at end? if (bitsPos > rowStartPos) { if (rowLength === -1) { rowLength = bitsPos - rowStartPos; } else if (bitsPos - rowStartPos !== rowLength) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'row lengths do not match'); } nRows++; } var matrix = new BitMatrix(rowLength, nRows); for (var i = 0; i < bitsPos; i++) { if (bits[i]) { matrix.set(Math.floor(i % rowLength), Math.floor(i / rowLength)); } } return matrix; }; /** * <p>Gets the requested bit, where true means black.</p> * * @param x The horizontal component (i.e. which column) * @param y The vertical component (i.e. which row) * @return value of given bit in matrix */ BitMatrix.prototype.get = function (x /*int*/, y /*int*/) { var offset = y * this.rowSize + Math.floor(x / 32); return ((this.bits[offset] >>> (x & 0x1f)) & 1) !== 0; }; /** * <p>Sets the given bit to true.</p> * * @param x The horizontal component (i.e. which column) * @param y The vertical component (i.e. which row) */ BitMatrix.prototype.set = function (x /*int*/, y /*int*/) { var offset = y * this.rowSize + Math.floor(x / 32); this.bits[offset] |= (1 << (x & 0x1f)) & 0xFFFFFFFF; }; BitMatrix.prototype.unset = function (x /*int*/, y /*int*/) { var offset = y * this.rowSize + Math.floor(x / 32); this.bits[offset] &= ~((1 << (x & 0x1f)) & 0xFFFFFFFF); }; /** * <p>Flips the given bit.</p> * * @param x The horizontal component (i.e. which column) * @param y The vertical component (i.e. which row) */ BitMatrix.prototype.flip = function (x /*int*/, y /*int*/) { var offset = y * this.rowSize + Math.floor(x / 32); this.bits[offset] ^= ((1 << (x & 0x1f)) & 0xFFFFFFFF); }; /** * Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding * mask bit is set. * * @param mask XOR mask */ BitMatrix.prototype.xor = function (mask) { if (this.width !== mask.getWidth() || this.height !== mask.getHeight() || this.rowSize !== mask.getRowSize()) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'input matrix dimensions do not match'); } var rowArray = new BitArray_1.default(Math.floor(this.width / 32) + 1); var rowSize = this.rowSize; var bits = this.bits; for (var y = 0, height = this.height; y < height; y++) { var offset = y * rowSize; var row = mask.getRow(y, rowArray).getBitArray(); for (var x = 0; x < rowSize; x++) { bits[offset + x] ^= row[x]; } } }; /** * Clears all bits (sets to false). */ BitMatrix.prototype.clear = function () { var bits = this.bits; var max = bits.length; for (var i = 0; i < max; i++) { bits[i] = 0; } }; /** * <p>Sets a square region of the bit matrix to true.</p> * * @param left The horizontal position to begin at (inclusive) * @param top The vertical position to begin at (inclusive) * @param width The width of the region * @param height The height of the region */ BitMatrix.prototype.setRegion = function (left /*int*/, top /*int*/, width /*int*/, height /*int*/) { if (top < 0 || left < 0) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'Left and top must be nonnegative'); } if (height < 1 || width < 1) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'Height and width must be at least 1'); } var right = left + width; var bottom = top + height; if (bottom > this.height || right > this.width) { throw new Exception_1.default(Exception_1.default.IllegalArgumentException, 'The region must fit inside the matrix'); } var rowSize = this.rowSize; var bits = this.bits; for (var y = top; y < bottom; y++) { var offset = y * rowSize; for (var x = left; x < right; x++) { bits[offset + Math.floor(x / 32)] |= ((1 << (x & 0x1f)) & 0xFFFFFFFF); } } }; /** * A fast method to retrieve one row of data from the matrix as a BitArray. * * @param y The row to retrieve * @param row An optional caller-allocated BitArray, will be allocated if null or too small * @return The resulting BitArray - this reference should always be used even when passing * your own row */ BitMatrix.prototype.getRow = function (y /*int*/, row) { if (row === null || row === undefined || row.getSize() < this.width) { row = new BitArray_1.default(this.width); } else { row.clear(); } var rowSize = this.rowSize; var bits = this.bits; var offset = y * rowSize; for (var x = 0; x < rowSize; x++) { row.setBulk(x * 32, bits[offset + x]); } return row; }; /** * @param y row to set * @param row {@link BitArray} to copy from */ BitMatrix.prototype.setRow = function (y /*int*/, row) { System_1.default.arraycopy(row.getBitArray(), 0, this.bits, y * this.rowSize, this.rowSize); }; /** * Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees */ BitMatrix.prototype.rotate180 = function () { var width = this.getWidth(); var height = this.getHeight(); var topRow = new BitArray_1.default(width); var bottomRow = new BitArray_1.default(width); for (var i = 0, length_1 = Math.floor((height + 1) / 2); i < length_1; i++) { topRow = this.getRow(i, topRow); bottomRow = this.getRow(height - 1 - i, bottomRow); topRow.reverse(); bottomRow.reverse(); this.setRow(i, bottomRow); this.setRow(height - 1 - i, topRow); } }; /** * This is useful in detecting the enclosing rectangle of a 'pure' barcode. * * @return {@code left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white */ BitMatrix.prototype.getEnclosingRectangle = function () { var width = this.width; var height = this.height; var rowSize = this.rowSize; var bits = this.bits; var left = width; var top = height; var right = -1; var bottom = -1; for (var y = 0; y < height; y++) { for (var x32 = 0; x32 < rowSize; x32++) { var theBits = bits[y * rowSize + x32]; if (theBits !== 0) { if (y < top) { top = y; } if (y > bottom) { bottom = y; } if (x32 * 32 < left) { var bit = 0; while (((theBits << (31 - bit)) & 0xFFFFFFFF) === 0) { bit++; } if ((x32 * 32 + bit) < left) { left = x32 * 32 + bit; } } if (x32 * 32 + 31 > right) { var bit = 31; while ((theBits >>> bit) === 0) { bit--; } if ((x32 * 32 + bit) > right) { right = x32 * 32 + bit; } } } } } if (right < left || bottom < top) { return null; } return Int32Array.from([left, top, right - left + 1, bottom - top + 1]); }; /** * This is useful in detecting a corner of a 'pure' barcode. * * @return {@code x,y} coordinate of top-left-most 1 bit, or null if it is all white */ BitMatrix.prototype.getTopLeftOnBit = function () { var rowSize = this.rowSize; var bits = this.bits; var bitsOffset = 0; while (bitsOffset < bits.length && bits[bitsOffset] === 0) { bitsOffset++; } if (bitsOffset === bits.length) { return null; } var y = bitsOffset / rowSize; var x = (bitsOffset % rowSize) * 32; var theBits = bits[bitsOffset]; var bit = 0; while (((theBits << (31 - bit)) & 0xFFFFFFFF) === 0) { bit++; } x += bit; return Int32Array.from([x, y]); }; BitMatrix.prototype.getBottomRightOnBit = function () { var rowSize = this.rowSize; var bits = this.bits; var bitsOffset = bits.length - 1; while (bitsOffset >= 0 && bits[bitsOffset] === 0) { bitsOffset--; } if (bitsOffset < 0) { return null; } var y = Math.floor(bitsOffset / rowSize); var x = Math.floor(bitsOffset % rowSize) * 32; var theBits = bits[bitsOffset]; var bit = 31; while ((theBits >>> bit) === 0) { bit--; } x += bit; return Int32Array.from([x, y]); }; /** * @return The width of the matrix */ BitMatrix.prototype.getWidth = function () { return this.width; }; /** * @return The height of the matrix */ BitMatrix.prototype.getHeight = function () { return this.height; }; /** * @return The row size of the matrix */ BitMatrix.prototype.getRowSize = function () { return this.rowSize; }; /*@Override*/ BitMatrix.prototype.equals = function (o) { if (!(o instanceof BitMatrix)) { return false; } var other = o; return this.width === other.width && this.height === other.height && this.rowSize === other.rowSize && Arrays_1.default.equals(this.bits, other.bits); }; /*@Override*/ BitMatrix.prototype.hashCode = function () { var hash = this.width; hash = 31 * hash + this.width; hash = 31 * hash + this.height; hash = 31 * hash + this.rowSize; hash = 31 * hash + Arrays_1.default.hashCode(this.bits); return hash; }; /** * @return string representation using "X" for set and " " for unset bits */ /*@Override*/ // public toString(): string { // return toString(": "X, " ") // } /** * @param setString representation of a set bit * @param unsetString representation of an unset bit * @return string representation of entire matrix utilizing given strings */ // public toString(setString: string = "X ", unsetString: string = " "): string { // return this.buildToString(setString, unsetString, "\n") // } /** * @param setString representation of a set bit * @param unsetString representation of an unset bit * @param lineSeparator newline character in string representation * @return string representation of entire matrix utilizing given strings and line separator * @deprecated call {@link #toString(String,String)} only, which uses \n line separator always */ // @Deprecated BitMatrix.prototype.toString = function (setString, unsetString, lineSeparator) { if (setString === void 0) { setString = 'x'; } if (unsetString === void 0) { unsetString = ' '; } if (lineSeparator === void 0) { lineSeparator = '\n'; } return this.buildToString(setString, unsetString, lineSeparator); }; BitMatrix.prototype.buildToString = function (setString, unsetString, lineSeparator) { var result = new StringBuilder_1.default(); result.append(lineSeparator); for (var y = 0, height = this.height; y < height; y++) { for (var x = 0, width = this.width; x < width; x++) { result.append(this.get(x, y) ? setString : unsetString); } result.append(lineSeparator); } return result.toString(); }; /*@Override*/ BitMatrix.prototype.clone = function () { return new BitMatrix(this.width, this.height, this.rowSize, this.bits.slice()); }; return BitMatrix; }()); exports.default = BitMatrix; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); /*namespace com.google.zxing.common {*/ /*import java.util.Arrays;*/ var System_1 = __webpack_require__(1); var Integer_1 = __webpack_require__(10); var Arrays_1 = __webpack_require__(17); var Exception_1 = __webpack_require__(0); /** * <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_1.default.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_1.default.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_1.default.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 Exception_1.default(Exception_1.default.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 Exception_1.default(Exception_1.default.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 Exception_1.default(Exception_1.default.IllegalArgumentException, 'Num bits must be between 0 and 32'); } this.ensureCapacity(this.size + numBits); var 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); var 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 Exception_1.default(Exception_1.default.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_1.default.equals(this.bits, other.bits); }; /*@Override*/ BitArray.prototype.hashCode = function () { return 31 * this.size + Arrays_1.default.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()); }; return BitArray; }()); exports.default = BitArray; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var StringBuilder = /** @class */ (function () { function StringBuilder(value) { if (value === void 0) { value = ''; } this.value = value; } StringBuilder.prototype.append = function (s) { if (typeof s === 'string') { this.value += s.toString(); } else { this.value += String.fromCharCode(s); } return this; }; StringBuilder.prototype.length = function () { return this.value.length; }; StringBuilder.prototype.charAt = function (n) { return this.value.charAt(n); }; StringBuilder.prototype.deleteCharAt = function (n) { this.value = this.value.substr(0, n) + this.value.substring(n + 1); }; StringBuilder.prototype.setCharAt = function (n, c) { this.value = this.value.substr(0, n) + c + this.value.substr(n + 1); }; StringBuilder.prototype.toString = function () { return this.value; }; return StringBuilder; }()); exports.default = StringBuilder; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* * 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 __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var LuminanceSource_1 = __webpack_require__(7); /*namespace com.google.zxing {*/ /** * A wrapper implementation of {@link LuminanceSource} which inverts the luminances it returns -- black becomes * white and vice versa, and each value becomes (255-value). * * @author Sean Owen */ var InvertedLuminanceSource = /** @class */ (function (_super) { __extends(InvertedLuminanceSource, _super); function InvertedLuminanceSource(delegate) { var _this = _super.call(this, delegate.getWidth(), delegate.getHeight()) || this; _this.delegate = delegate; return _this; } /*@Override*/ InvertedLuminanceSource.prototype.getRow = function (y /*int*/, row) { var sourceRow = this.delegate.getRow(y, row); var width = this.getWidth(); for (var i = 0; i < width; i++) { sourceRow[i] = /*(byte)*/ (255 - (sourceRow[i] & 0xFF)); } return sourceRow; }; /*@Override*/ InvertedLuminanceSource.prototype.getMatrix = function () { var matrix = this.delegate.getMatrix(); var length = this.getWidth() * this.getHeight(); var invertedMatrix = new Uint8ClampedArray(length); for (var i = 0; i < length; i++) { invertedMatrix[i] = /*(byte)*/ (255 - (matrix[i] & 0xFF)); } return invertedMatrix; }; /*@Override*/ InvertedLuminanceSource.prototype.isCropSupported = function () { return this.delegate.isCropSupported(); }; /*@Override*/ InvertedLuminanceSource.prototype.crop = function (left /*int*/, top /*int*/, width /*int*/, height /*int*/) { return new InvertedLuminanceSource(this.delegate.crop(left, top, width, height)); }; /*@Override*/ InvertedLuminanceSource.prototype.isRotateSupported = function () { return this.delegate.isRotateSupported(); }; /** * @return original delegate {@link LuminanceSource} since invert undoes itself */ /*@Override*/ InvertedLuminanceSource.prototype.invert = function () { return this.delegate; }; /*@Override*/ InvertedLuminanceSource.prototype.rotateCounterClockwise = function () { return new InvertedLuminanceSource(this.delegate.rotateCounterClockwise()); }; /*@Override*/ InvertedLuminanceSource.prototype.rotateCounterClockwise45 = function () { return new InvertedLuminanceSource(this.delegate.rotateCounterClockwise45()); }; return InvertedLuminanceSource; }(LuminanceSource_1.default)); exports.default = InvertedLuminanceSource; /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); var Exception_1 = __webpack_require__(0); var StringBuilder_1 = __webpack_require__(5); /*namespace com.google.zxing {*/ /** * The purpose of this class hierarchy is to abstract different bitmap implementations across * platforms into a standard interface for requesting greyscale luminance values. The interface * only provides immutable methods; therefore crop and rotation create copies. This is to ensure * that one Reader does not modify the original luminance source and leave it in an unknown state * for other Readers in the chain. * * @author dswitkin@google.com (Daniel Switkin) */ var LuminanceSource = /** @class */ (function () { function LuminanceSource(width /*int*/, height /*int*/) { this.width = width; this.height = height; } /** * @return The width of the bitmap. */ LuminanceSource.prototype.getWidth = function () { return this.width; }; /** * @return The height of the bitmap. */ LuminanceSource.prototype.getHeight = function () { return this.height; }; /** * @return Whether this subclass supports cropping. */ LuminanceSource.prototype.isCropSupported = function () { return false; }; /** * 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