angular2-qrscanner
Version:
QrScanner will scan for a QRCode from your Web-cam and return its string representation by drawing the captured image onto a 2D Canvas and use [@LazarSoft/jsqrcode](https://github.com/LazarSoft/jsqrcode) to check for a valid QRCode every *Xms*
1,004 lines (975 loc) • 121 kB
JavaScript
import { Component, EventEmitter, Input, Output, ViewChild, Renderer2, NgModule } from '@angular/core';
import { Subject } from 'rxjs';
import { CommonModule } from '@angular/common';
var AlignmentPattern = /** @class */ (function () {
function AlignmentPattern(posX, posY, estimatedModuleSize) {
this.count = 1;
this.incrementCount = function () {
this.count++;
};
this.aboutEquals = function (moduleSize, i, j) {
if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) {
var moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);
return moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;
}
return false;
};
this.x = posX;
this.y = posY;
this.estimatedModuleSize = estimatedModuleSize;
}
Object.defineProperty(AlignmentPattern.prototype, "EstimatedModuleSize", {
get: function () {
return this.estimatedModuleSize;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AlignmentPattern.prototype, "Count", {
get: function () {
return this.count;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AlignmentPattern.prototype, "X", {
get: function () {
return Math.floor(this.x);
},
enumerable: true,
configurable: true
});
Object.defineProperty(AlignmentPattern.prototype, "Y", {
get: function () {
return Math.floor(this.y);
},
enumerable: true,
configurable: true
});
return AlignmentPattern;
}());
var AlignmentPatternFinder = /** @class */ (function () {
function AlignmentPatternFinder(image, startX, startY, width, height, moduleSize, imageWidth, imageHeight, resultPointCallback) {
this.possibleCenters = new Array();
this.crossCheckStateCount = new Array(0, 0, 0);
this.centerFromEnd = function (stateCount, end) {
return (end - stateCount[2]) - stateCount[1] / 2.0;
};
this.foundPatternCross = function (stateCount) {
var moduleSize = this.moduleSize;
var maxVariance = moduleSize / 2.0;
for (var i = 0; i < 3; i++) {
if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) {
return false;
}
}
return true;
};
this.crossCheckVertical = function (startI, centerJ, maxCount, originalStateCountTotal) {
var image = this.image;
var maxI = this.imageHeight;
var stateCount = this.crossCheckStateCount;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
var i = startI;
while (i >= 0 && image[centerJ + i * this.imageWidth] && stateCount[1] <= maxCount) {
stateCount[1]++;
i--;
}
if (i < 0 || stateCount[1] > maxCount) {
return NaN;
}
while (i >= 0 && !image[centerJ + i * this.imageWidth] && stateCount[0] <= maxCount) {
stateCount[0]++;
i--;
}
if (stateCount[0] > maxCount) {
return NaN;
}
i = startI + 1;
while (i < maxI && image[centerJ + i * this.imageWidth] && stateCount[1] <= maxCount) {
stateCount[1]++;
i++;
}
if (i == maxI || stateCount[1] > maxCount) {
return NaN;
}
while (i < maxI && !image[centerJ + i * this.imageWidth] && stateCount[2] <= maxCount) {
stateCount[2]++;
i++;
}
if (stateCount[2] > maxCount) {
return NaN;
}
var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
return NaN;
}
return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, i) : NaN;
};
this.handlePossibleCenter = function (stateCount, i, j) {
var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
var centerJ = this.centerFromEnd(stateCount, j);
var centerI = this.crossCheckVertical(i, Math.floor(centerJ), 2 * stateCount[1], stateCountTotal);
if (!isNaN(centerI)) {
var estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0;
var max = this.possibleCenters.length;
for (var index = 0; index < max; index++) {
var center = this.possibleCenters[index];
if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) {
return new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
}
}
var point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
this.possibleCenters.push(point);
if (this.resultPointCallback != null) {
this.resultPointCallback.foundPossibleResultPoint(point);
}
}
return null;
};
this.find = function () {
var startX = this.startX;
var height = this.height;
var maxJ = startX + this.width;
var middleI = this.startY + (height >> 1);
var stateCount = new Array(0, 0, 0);
for (var iGen = 0; iGen < height; iGen++) {
var i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1));
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
var j = startX;
while (j < maxJ && !this.image[j + this.imageWidth * i]) {
j++;
}
var currentState = 0;
while (j < maxJ) {
if (this.image[j + i * this.imageWidth]) {
if (currentState == 1) {
stateCount[currentState]++;
}
else {
if (currentState == 2) {
if (this.foundPatternCross(stateCount)) {
var confirmed = this.handlePossibleCenter(stateCount, i, j);
if (confirmed != null) {
return confirmed;
}
}
stateCount[0] = stateCount[2];
stateCount[1] = 1;
stateCount[2] = 0;
currentState = 1;
}
else {
stateCount[++currentState]++;
}
}
}
else {
if (currentState == 1) {
currentState++;
}
stateCount[currentState]++;
}
j++;
}
if (this.foundPatternCross(stateCount)) {
var confirmed = this.handlePossibleCenter(stateCount, i, maxJ);
if (confirmed != null) {
return confirmed;
}
}
}
if (!(this.possibleCenters.length == 0)) {
return this.possibleCenters[0];
}
throw "Couldn't find enough alignment patterns";
};
this.image = image;
this.startX = startX;
this.startY = startY;
this.width = width;
this.height = height;
this.moduleSize = moduleSize;
this.resultPointCallback = resultPointCallback;
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
}
return AlignmentPatternFinder;
}());
var PerspectiveTransform = /** @class */ (function () {
function PerspectiveTransform(a11, a21, a31, a12, a22, a32, a13, a23, a33) {
this.transformPoints1 = function (points) {
var max = points.length;
var a11 = this.a11;
var a12 = this.a12;
var a13 = this.a13;
var a21 = this.a21;
var a22 = this.a22;
var a23 = this.a23;
var a31 = this.a31;
var a32 = this.a32;
var a33 = this.a33;
for (var i = 0; i < max; i += 2) {
var x = points[i];
var y = points[i + 1];
var denominator = a13 * x + a23 * y + a33;
points[i] = (a11 * x + a21 * y + a31) / denominator;
points[i + 1] = (a12 * x + a22 * y + a32) / denominator;
}
};
this.transformPoints2 = function (xValues, yValues) {
var n = xValues.length;
for (var i = 0; i < n; i++) {
var x = xValues[i];
var y = yValues[i];
var denominator = this.a13 * x + this.a23 * y + this.a33;
xValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator;
yValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator;
}
};
this.buildAdjoint = function () {
return new PerspectiveTransform(this.a22 * this.a33 - this.a23 * this.a32, this.a23 * this.a31 - this.a21 * this.a33, this.a21 * this.a32 - this.a22 * this.a31, this.a13 * this.a32 - this.a12 * this.a33, this.a11 * this.a33 - this.a13 * this.a31, this.a12 * this.a31 - this.a11 * this.a32, this.a12 * this.a23 - this.a13 * this.a22, this.a13 * this.a21 - this.a11 * this.a23, this.a11 * this.a22 - this.a12 * this.a21);
};
this.times = function (other) {
return new PerspectiveTransform(this.a11 * other.a11 + this.a21 * other.a12 + this.a31 * other.a13, this.a11 * other.a21 + this.a21 * other.a22 + this.a31 * other.a23, this.a11 * other.a31 + this.a21 * other.a32 + this.a31 * other.a33, this.a12 * other.a11 + this.a22 * other.a12 + this.a32 * other.a13, this.a12 * other.a21 + this.a22 * other.a22 + this.a32 * other.a23, this.a12 * other.a31 + this.a22 * other.a32 + this.a32 * other.a33, this.a13 * other.a11 + this.a23 * other.a12 + this.a33 * other.a13, this.a13 * other.a21 + this.a23 * other.a22 + this.a33 * other.a23, this.a13 * other.a31 + this.a23 * other.a32 + this.a33 * other.a33);
};
this.a11 = a11;
this.a12 = a12;
this.a13 = a13;
this.a21 = a21;
this.a22 = a22;
this.a23 = a23;
this.a31 = a31;
this.a32 = a32;
this.a33 = a33;
}
PerspectiveTransform.quadrilateralToQuadrilateral = function (x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p) {
var qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3);
var sToQ = this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p);
return sToQ.times(qToS);
};
PerspectiveTransform.squareToQuadrilateral = function (x0, y0, x1, y1, x2, y2, x3, y3) {
var dy2 = y3 - y2;
var dy3 = y0 - y1 + y2 - y3;
if (dy2 == 0.0 && dy3 == 0.0) {
return new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0);
}
else {
var dx1 = x1 - x2;
var dx2 = x3 - x2;
var dx3 = x0 - x1 + x2 - x3;
var dy1 = y1 - y2;
var denominator = dx1 * dy2 - dx2 * dy1;
var a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
var a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
return new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0);
}
};
PerspectiveTransform.quadrilateralToSquare = function (x0, y0, x1, y1, x2, y2, x3, y3) {
var t = this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3);
return t.buildAdjoint();
};
return PerspectiveTransform;
}());
var BitMatrix = /** @class */ (function () {
function BitMatrix(width, height) {
if (!height)
height = width;
if (width < 1 || height < 1) {
throw "Both dimensions must be greater than 0";
}
this.width = width;
this.height = height;
this.rowSize = width >> 5;
if ((width & 0x1f) != 0) {
this.rowSize++;
}
this.bits = new Array(this.rowSize * height);
for (var i = 0; i < this.bits.length; i++)
this.bits[i] = 0;
}
Object.defineProperty(BitMatrix.prototype, "Width", {
get: function () {
return this.width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BitMatrix.prototype, "Height", {
get: function () {
return this.height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BitMatrix.prototype, "Dimension", {
get: function () {
if (this.width != this.height) {
throw "Can't call getDimension() on a non-square matrix";
}
return this.width;
},
enumerable: true,
configurable: true
});
BitMatrix.prototype.URShift = function (number, bits) {
if (number >= 0)
return number >> bits;
else
return (number >> bits) + (2 << ~bits);
};
BitMatrix.prototype.get_Renamed = function (x, y) {
var offset = y * this.rowSize + (x >> 5);
return ((this.URShift(this.bits[offset], (x & 0x1f))) & 1) != 0;
};
BitMatrix.prototype.set_Renamed = function (x, y) {
var offset = y * this.rowSize + (x >> 5);
this.bits[offset] |= 1 << (x & 0x1f);
};
BitMatrix.prototype.flip = function (x, y) {
var offset = y * this.rowSize + (x >> 5);
this.bits[offset] ^= 1 << (x & 0x1f);
};
BitMatrix.prototype.clear = function () {
var max = this.bits.length;
for (var i = 0; i < max; i++) {
this.bits[i] = 0;
}
};
BitMatrix.prototype.setRegion = function (left, top, width, height) {
if (top < 0 || left < 0) {
throw "Left and top must be nonnegative";
}
if (height < 1 || width < 1) {
throw "Height and width must be at least 1";
}
var right = left + width;
var bottom = top + height;
if (bottom > this.height || right > this.width) {
throw "The region must fit inside the matrix";
}
for (var y = top; y < bottom; y++) {
var offset = y * this.rowSize;
for (var x = left; x < right; x++) {
this.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
}
}
};
return BitMatrix;
}());
var GridSampler = /** @class */ (function () {
function GridSampler(width, height) {
this.width = width;
this.height = height;
}
GridSampler.prototype.checkAndNudgePoints = function (image, points) {
var width = this.width;
var height = this.height;
var nudged = true;
for (var offset = 0; offset < points.length && nudged; offset += 2) {
var x = Math.floor(points[offset]);
var y = Math.floor(points[offset + 1]);
if (x < -1 || x > width || y < -1 || y > height) {
throw "Error.checkAndNudgePoints ";
}
nudged = false;
if (x == -1) {
points[offset] = 0.0;
nudged = true;
}
else if (x == width) {
points[offset] = width - 1;
nudged = true;
}
if (y == -1) {
points[offset + 1] = 0.0;
nudged = true;
}
else if (y == height) {
points[offset + 1] = height - 1;
nudged = true;
}
}
nudged = true;
for (var offset = points.length - 2; offset >= 0 && nudged; offset -= 2) {
var x = Math.floor(points[offset]);
var y = Math.floor(points[offset + 1]);
if (x < -1 || x > width || y < -1 || y > height) {
throw "Error.checkAndNudgePoints ";
}
nudged = false;
if (x == -1) {
points[offset] = 0.0;
nudged = true;
}
else if (x == width) {
points[offset] = width - 1;
nudged = true;
}
if (y == -1) {
points[offset + 1] = 0.0;
nudged = true;
}
else if (y == height) {
points[offset + 1] = height - 1;
nudged = true;
}
}
};
GridSampler.prototype.sampleGrid3 = function (image, rawImage, dimension, transform) {
var bits = new BitMatrix(dimension, dimension);
var points = new Array(dimension << 1);
for (var y = 0; y < dimension; y++) {
var max = points.length;
var iValue = y + 0.5;
for (var x = 0; x < max; x += 2) {
points[x] = (x >> 1) + 0.5;
points[x + 1] = iValue;
}
transform.transformPoints1(points);
this.checkAndNudgePoints(image, points);
try {
for (var x = 0; x < max; x += 2) {
var xpoint = (Math.floor(points[x]) * 4) + (Math.floor(points[x + 1]) * this.width * 4);
var bit = image[Math.floor(points[x]) + this.width * Math.floor(points[x + 1])];
rawImage.data[xpoint] = bit ? 255 : 0;
rawImage.data[xpoint + 1] = bit ? 255 : 0;
rawImage.data[xpoint + 2] = 0;
rawImage.data[xpoint + 3] = 255;
if (bit)
bits.set_Renamed(x >> 1, y);
}
}
catch (aioobe) {
throw "Error.checkAndNudgePoints";
}
}
return bits;
};
GridSampler.prototype.sampleGridx = function (image, dimension, p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY) {
var transform = PerspectiveTransform.quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY);
return this.sampleGrid3(image, {}, dimension, transform);
};
return GridSampler;
}());
var ErrorCorrectionLevel = /** @class */ (function () {
function ErrorCorrectionLevel(ordinal, bits, name) {
this.ordinal_Renamed_Field = ordinal;
this.bits = bits;
this.name = name;
}
ErrorCorrectionLevel.forBits = function (bits) {
if (bits < 0 || bits >= this.FOR_BITS.length) {
throw "ArgumentException";
}
return this.FOR_BITS[bits];
};
Object.defineProperty(ErrorCorrectionLevel.prototype, "Bits", {
get: function () {
return this.bits;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ErrorCorrectionLevel.prototype, "Name", {
get: function () {
return this.name;
},
enumerable: true,
configurable: true
});
ErrorCorrectionLevel.prototype.ordinal = function () {
return this.ordinal_Renamed_Field;
};
return ErrorCorrectionLevel;
}());
ErrorCorrectionLevel.L = new ErrorCorrectionLevel(0, 0x01, "L");
ErrorCorrectionLevel.M = new ErrorCorrectionLevel(1, 0x00, "M");
ErrorCorrectionLevel.Q = new ErrorCorrectionLevel(2, 0x03, "Q");
ErrorCorrectionLevel.H = new ErrorCorrectionLevel(3, 0x02, "H");
ErrorCorrectionLevel.FOR_BITS = new Array(ErrorCorrectionLevel.M, ErrorCorrectionLevel.L, ErrorCorrectionLevel.H, ErrorCorrectionLevel.Q);
var FormatInformation = /** @class */ (function () {
function FormatInformation(formatInfo) {
this.Equals = function (o) {
var other = o;
return this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask;
};
this.errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03);
this.dataMask = (formatInfo & 0x07);
}
Object.defineProperty(FormatInformation.prototype, "ErrorCorrectionLevel", {
get: function () {
return this.errorCorrectionLevel;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FormatInformation.prototype, "DataMask", {
get: function () {
return this.dataMask;
},
enumerable: true,
configurable: true
});
FormatInformation.prototype.GetHashCode = function () {
return (this.errorCorrectionLevel.ordinal() << 3) | this.dataMask;
};
FormatInformation.URShift = function (number, bits) {
if (number >= 0)
return number >> bits;
else
return (number >> bits) + (2 << ~bits);
};
FormatInformation.numBitsDiffering = function (a, b) {
a ^= b;
return FormatInformation.BITS_SET_IN_HALF_BYTE[a & 0x0F]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 4) & 0x0F)]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 8) & 0x0F)]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 12) & 0x0F)]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 16) & 0x0F)]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 20) & 0x0F)]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 24) & 0x0F)]
+ FormatInformation.BITS_SET_IN_HALF_BYTE[(this.URShift(a, 28) & 0x0F)];
};
FormatInformation.decodeFormatInformation = function (maskedFormatInfo) {
var formatInfo = this.doDecodeFormatInformation(maskedFormatInfo);
if (formatInfo != null) {
return formatInfo;
}
return this.doDecodeFormatInformation(maskedFormatInfo ^ FormatInformation.FORMAT_INFO_MASK_QR);
};
FormatInformation.doDecodeFormatInformation = function (maskedFormatInfo) {
var bestDifference = 0xffffffff;
var bestFormatInfo = 0;
for (var i = 0; i < FormatInformation.FORMAT_INFO_DECODE_LOOKUP.length; i++) {
var decodeInfo = FormatInformation.FORMAT_INFO_DECODE_LOOKUP[i];
var targetInfo = decodeInfo[0];
if (targetInfo == maskedFormatInfo) {
return new FormatInformation(decodeInfo[1]);
}
var bitsDifference = FormatInformation.numBitsDiffering(maskedFormatInfo, targetInfo);
if (bitsDifference < bestDifference) {
bestFormatInfo = decodeInfo[1];
bestDifference = bitsDifference;
}
}
if (bestDifference <= 3) {
return new FormatInformation(bestFormatInfo);
}
return null;
};
FormatInformation.forBits = function (bits) {
{
if (bits < 0 || bits >= FormatInformation.FOR_BITS.length) {
throw "ArgumentException";
}
return FormatInformation.FOR_BITS[bits];
}
};
return FormatInformation;
}());
FormatInformation.FORMAT_INFO_MASK_QR = 0x5412;
FormatInformation.FORMAT_INFO_DECODE_LOOKUP = new Array(new Array(0x5412, 0x00), new Array(0x5125, 0x01), new Array(0x5E7C, 0x02), new Array(0x5B4B, 0x03), new Array(0x45F9, 0x04), new Array(0x40CE, 0x05), new Array(0x4F97, 0x06), new Array(0x4AA0, 0x07), new Array(0x77C4, 0x08), new Array(0x72F3, 0x09), new Array(0x7DAA, 0x0A), new Array(0x789D, 0x0B), new Array(0x662F, 0x0C), new Array(0x6318, 0x0D), new Array(0x6C41, 0x0E), new Array(0x6976, 0x0F), new Array(0x1689, 0x10), new Array(0x13BE, 0x11), new Array(0x1CE7, 0x12), new Array(0x19D0, 0x13), new Array(0x0762, 0x14), new Array(0x0255, 0x15), new Array(0x0D0C, 0x16), new Array(0x083B, 0x17), new Array(0x355F, 0x18), new Array(0x3068, 0x19), new Array(0x3F31, 0x1A), new Array(0x3A06, 0x1B), new Array(0x24B4, 0x1C), new Array(0x2183, 0x1D), new Array(0x2EDA, 0x1E), new Array(0x2BED, 0x1F));
FormatInformation.BITS_SET_IN_HALF_BYTE = new Array(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);
FormatInformation.L = new ErrorCorrectionLevel(0, 0x01, "L");
FormatInformation.M = new ErrorCorrectionLevel(1, 0x00, "M");
FormatInformation.Q = new ErrorCorrectionLevel(2, 0x03, "Q");
FormatInformation.H = new ErrorCorrectionLevel(3, 0x02, "H");
FormatInformation.FOR_BITS = new Array(FormatInformation.M, FormatInformation.L, FormatInformation.H, FormatInformation.Q);
var ECB = /** @class */ (function () {
function ECB(count, dataCodewords) {
this.count = count;
this.dataCodewords = dataCodewords;
}
Object.defineProperty(ECB.prototype, "Count", {
get: function () {
return this.count;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ECB.prototype, "DataCodewords", {
get: function () {
return this.dataCodewords;
},
enumerable: true,
configurable: true
});
return ECB;
}());
var ECBlocks = /** @class */ (function () {
function ECBlocks(ecCodewordsPerBlock, ecBlocks1, ecBlocks2) {
this.getECBlocks = function () {
return this.ecBlocks;
};
this.ecCodewordsPerBlock = ecCodewordsPerBlock;
if (ecBlocks2)
this.ecBlocks = new Array(ecBlocks1, ecBlocks2);
else
this.ecBlocks = new Array(ecBlocks1);
}
Object.defineProperty(ECBlocks.prototype, "ECCodewordsPerBlock", {
get: function () {
return this.ecCodewordsPerBlock;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ECBlocks.prototype, "TotalECCodewords", {
get: function () {
return this.ecCodewordsPerBlock * this.NumBlocks;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ECBlocks.prototype, "NumBlocks", {
get: function () {
var total = 0;
for (var i = 0; i < this.ecBlocks.length; i++) {
total += this.ecBlocks[i].length;
}
return total;
},
enumerable: true,
configurable: true
});
return ECBlocks;
}());
var Version = /** @class */ (function () {
function Version(versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4) {
this.buildFunctionPattern = function () {
var dimension = this.DimensionForVersion;
var bitMatrix = new BitMatrix(dimension);
bitMatrix.setRegion(0, 0, 9, 9);
bitMatrix.setRegion(dimension - 8, 0, 8, 9);
bitMatrix.setRegion(0, dimension - 8, 9, 8);
var max = this.alignmentPatternCenters.length;
for (var x = 0; x < max; x++) {
var i = this.alignmentPatternCenters[x] - 2;
for (var y = 0; y < max; y++) {
if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
continue;
}
bitMatrix.setRegion(this.alignmentPatternCenters[y] - 2, i, 5, 5);
}
}
bitMatrix.setRegion(6, 9, 1, dimension - 17);
bitMatrix.setRegion(9, 6, dimension - 17, 1);
if (this.versionNumber > 6) {
bitMatrix.setRegion(dimension - 11, 0, 3, 6);
bitMatrix.setRegion(0, dimension - 11, 6, 3);
}
return bitMatrix;
};
this.getECBlocksForLevel = function (ecLevel) {
return this.ecBlocks[ecLevel.ordinal()];
};
this.versionNumber = versionNumber;
this.alignmentPatternCenters = alignmentPatternCenters;
this.ecBlocks = new Array(ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4);
var total = 0;
var ecCodewords = ecBlocks1.ECCodewordsPerBlock;
var ecbArray = ecBlocks1.getECBlocks();
for (var i = 0; i < ecbArray.length; i++) {
var ecBlock = ecbArray[i];
total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords);
}
this.totalCodewords = total;
}
Object.defineProperty(Version.prototype, "VersionNumber", {
get: function () {
return this.versionNumber;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Version.prototype, "AlignmentPatternCenters", {
get: function () {
return this.alignmentPatternCenters;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Version.prototype, "TotalCodewords", {
get: function () {
return this.totalCodewords;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Version.prototype, "DimensionForVersion", {
get: function () {
return 17 + 4 * this.versionNumber;
},
enumerable: true,
configurable: true
});
Version.getVersionForNumber = function (versionNumber) {
if (versionNumber < 1 || versionNumber > 40) {
throw "ArgumentException";
}
return Version.VERSIONS[versionNumber - 1];
};
Version.getProvisionalVersionForDimension = function (dimension) {
if (dimension % 4 != 1) {
throw "Error getProvisionalVersionForDimension";
}
try {
return Version.getVersionForNumber((dimension - 17) >> 2);
}
catch (iae) {
throw "Error getVersionForNumber";
}
};
Version.decodeVersionInformation = function (versionBits) {
var bestDifference = 0xffffffff;
var bestVersion = 0;
for (var i = 0; i < Version.VERSION_DECODE_INFO.length; i++) {
var targetVersion = Version.VERSION_DECODE_INFO[i];
if (targetVersion == versionBits) {
return this.getVersionForNumber(i + 7);
}
var bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);
if (bitsDifference < bestDifference) {
bestVersion = i + 7;
bestDifference = bitsDifference;
}
}
if (bestDifference <= 3) {
return this.getVersionForNumber(bestVersion);
}
return null;
};
Version.buildVersions = function () {
return new Array(new Version(1, new Array(), new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))), new Version(2, new Array(6, 18), new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))), new Version(3, new Array(6, 22), new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))), new Version(4, new Array(6, 26), new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))), new Version(5, new Array(6, 30), new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(18, new ECB(2, 15), new ECB(2, 16)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))), new Version(6, new Array(6, 34), new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)), new ECBlocks(24, new ECB(4, 19)), new ECBlocks(28, new ECB(4, 15))), new Version(7, new Array(6, 22, 38), new ECBlocks(20, new ECB(2, 78)), new ECBlocks(18, new ECB(4, 31)), new ECBlocks(18, new ECB(2, 14), new ECB(4, 15)), new ECBlocks(26, new ECB(4, 13), new ECB(1, 14))), new Version(8, new Array(6, 24, 42), new ECBlocks(24, new ECB(2, 97)), new ECBlocks(22, new ECB(2, 38), new ECB(2, 39)), new ECBlocks(22, new ECB(4, 18), new ECB(2, 19)), new ECBlocks(26, new ECB(4, 14), new ECB(2, 15))), new Version(9, new Array(6, 26, 46), new ECBlocks(30, new ECB(2, 116)), new ECBlocks(22, new ECB(3, 36), new ECB(2, 37)), new ECBlocks(20, new ECB(4, 16), new ECB(4, 17)), new ECBlocks(24, new ECB(4, 12), new ECB(4, 13))), new Version(10, new Array(6, 28, 50), new ECBlocks(18, new ECB(2, 68), new ECB(2, 69)), new ECBlocks(26, new ECB(4, 43), new ECB(1, 44)), new ECBlocks(24, new ECB(6, 19), new ECB(2, 20)), new ECBlocks(28, new ECB(6, 15), new ECB(2, 16))), new Version(11, new Array(6, 30, 54), new ECBlocks(20, new ECB(4, 81)), new ECBlocks(30, new ECB(1, 50), new ECB(4, 51)), new ECBlocks(28, new ECB(4, 22), new ECB(4, 23)), new ECBlocks(24, new ECB(3, 12), new ECB(8, 13))), new Version(12, new Array(6, 32, 58), new ECBlocks(24, new ECB(2, 92), new ECB(2, 93)), new ECBlocks(22, new ECB(6, 36), new ECB(2, 37)), new ECBlocks(26, new ECB(4, 20), new ECB(6, 21)), new ECBlocks(28, new ECB(7, 14), new ECB(4, 15))), new Version(13, new Array(6, 34, 62), new ECBlocks(26, new ECB(4, 107)), new ECBlocks(22, new ECB(8, 37), new ECB(1, 38)), new ECBlocks(24, new ECB(8, 20), new ECB(4, 21)), new ECBlocks(22, new ECB(12, 11), new ECB(4, 12))), new Version(14, new Array(6, 26, 46, 66), new ECBlocks(30, new ECB(3, 115), new ECB(1, 116)), new ECBlocks(24, new ECB(4, 40), new ECB(5, 41)), new ECBlocks(20, new ECB(11, 16), new ECB(5, 17)), new ECBlocks(24, new ECB(11, 12), new ECB(5, 13))), new Version(15, new Array(6, 26, 48, 70), new ECBlocks(22, new ECB(5, 87), new ECB(1, 88)), new ECBlocks(24, new ECB(5, 41), new ECB(5, 42)), new ECBlocks(30, new ECB(5, 24), new ECB(7, 25)), new ECBlocks(24, new ECB(11, 12), new ECB(7, 13))), new Version(16, new Array(6, 26, 50, 74), new ECBlocks(24, new ECB(5, 98), new ECB(1, 99)), new ECBlocks(28, new ECB(7, 45), new ECB(3, 46)), new ECBlocks(24, new ECB(15, 19), new ECB(2, 20)), new ECBlocks(30, new ECB(3, 15), new ECB(13, 16))), new Version(17, new Array(6, 30, 54, 78), new ECBlocks(28, new ECB(1, 107), new ECB(5, 108)), new ECBlocks(28, new ECB(10, 46), new ECB(1, 47)), new ECBlocks(28, new ECB(1, 22), new ECB(15, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(17, 15))), new Version(18, new Array(6, 30, 56, 82), new ECBlocks(30, new ECB(5, 120), new ECB(1, 121)), new ECBlocks(26, new ECB(9, 43), new ECB(4, 44)), new ECBlocks(28, new ECB(17, 22), new ECB(1, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(19, 15))), new Version(19, new Array(6, 30, 58, 86), new ECBlocks(28, new ECB(3, 113), new ECB(4, 114)), new ECBlocks(26, new ECB(3, 44), new ECB(11, 45)), new ECBlocks(26, new ECB(17, 21), new ECB(4, 22)), new ECBlocks(26, new ECB(9, 13), new ECB(16, 14))), new Version(20, new Array(6, 34, 62, 90), new ECBlocks(28, new ECB(3, 107), new ECB(5, 108)), new ECBlocks(26, new ECB(3, 41), new ECB(13, 42)), new ECBlocks(30, new ECB(15, 24), new ECB(5, 25)), new ECBlocks(28, new ECB(15, 15), new ECB(10, 16))), new Version(21, new Array(6, 28, 50, 72, 94), new ECBlocks(28, new ECB(4, 116), new ECB(4, 117)), new ECBlocks(26, new ECB(17, 42)), new ECBlocks(28, new ECB(17, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(19, 16), new ECB(6, 17))), new Version(22, new Array(6, 26, 50, 74, 98), new ECBlocks(28, new ECB(2, 111), new ECB(7, 112)), new ECBlocks(28, new ECB(17, 46)), new ECBlocks(30, new ECB(7, 24), new ECB(16, 25)), new ECBlocks(24, new ECB(34, 13))), new Version(23, new Array(6, 30, 54, 74, 102), new ECBlocks(30, new ECB(4, 121), new ECB(5, 122)), new ECBlocks(28, new ECB(4, 47), new ECB(14, 48)), new ECBlocks(30, new ECB(11, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(16, 15), new ECB(14, 16))), new Version(24, new Array(6, 28, 54, 80, 106), new ECBlocks(30, new ECB(6, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(6, 45), new ECB(14, 46)), new ECBlocks(30, new ECB(11, 24), new ECB(16, 25)), new ECBlocks(30, new ECB(30, 16), new ECB(2, 17))), new Version(25, new Array(6, 32, 58, 84, 110), new ECBlocks(26, new ECB(8, 106), new ECB(4, 107)), new ECBlocks(28, new ECB(8, 47), new ECB(13, 48)), new ECBlocks(30, new ECB(7, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(13, 16))), new Version(26, new Array(6, 30, 58, 86, 114), new ECBlocks(28, new ECB(10, 114), new ECB(2, 115)), new ECBlocks(28, new ECB(19, 46), new ECB(4, 47)), new ECBlocks(28, new ECB(28, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(33, 16), new ECB(4, 17))), new Version(27, new Array(6, 34, 62, 90, 118), new ECBlocks(30, new ECB(8, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(22, 45), new ECB(3, 46)), new ECBlocks(30, new ECB(8, 23), new ECB(26, 24)), new ECBlocks(30, new ECB(12, 15), new ECB(28, 16))), new Version(28, new Array(6, 26, 50, 74, 98, 122), new ECBlocks(30, new ECB(3, 117), new ECB(10, 118)), new ECBlocks(28, new ECB(3, 45), new ECB(23, 46)), new ECBlocks(30, new ECB(4, 24), new ECB(31, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(31, 16))), new Version(29, new Array(6, 30, 54, 78, 102, 126), new ECBlocks(30, new ECB(7, 116), new ECB(7, 117)), new ECBlocks(28, new ECB(21, 45), new ECB(7, 46)), new ECBlocks(30, new ECB(1, 23), new ECB(37, 24)), new ECBlocks(30, new ECB(19, 15), new ECB(26, 16))), new Version(30, new Array(6, 26, 52, 78, 104, 130), new ECBlocks(30, new ECB(5, 115), new ECB(10, 116)), new ECBlocks(28, new ECB(19, 47), new ECB(10, 48)), new ECBlocks(30, new ECB(15, 24), new ECB(25, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(25, 16))), new Version(31, new Array(6, 30, 56, 82, 108, 134), new ECBlocks(30, new ECB(13, 115), new ECB(3, 116)), new ECBlocks(28, new ECB(2, 46), new ECB(29, 47)), new ECBlocks(30, new ECB(42, 24), new ECB(1, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(28, 16))), new Version(32, new Array(6, 34, 60, 86, 112, 138), new ECBlocks(30, new ECB(17, 115)), new ECBlocks(28, new ECB(10, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(10, 24), new ECB(35, 25)), new ECBlocks(30, new ECB(19, 15), new ECB(35, 16))), new Version(33, new Array(6, 30, 58, 86, 114, 142), new ECBlocks(30, new ECB(17, 115), new ECB(1, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(21, 47)), new ECBlocks(30, new ECB(29, 24), new ECB(19, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(46, 16))), new Version(34, new Array(6, 34, 62, 90, 118, 146), new ECBlocks(30, new ECB(13, 115), new ECB(6, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(44, 24), new ECB(7, 25)), new ECBlocks(30, new ECB(59, 16), new ECB(1, 17))), new Version(35, new Array(6, 30, 54, 78, 102, 126, 150), new ECBlocks(30, new ECB(12, 121), new ECB(7, 122)), new ECBlocks(28, new ECB(12, 47), new ECB(26, 48)), new ECBlocks(30, new ECB(39, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(41, 16))), new Version(36, new Array(6, 24, 50, 76, 102, 128, 154), new ECBlocks(30, new ECB(6, 121), new ECB(14, 122)), new ECBlocks(28, new ECB(6, 47), new ECB(34, 48)), new ECBlocks(30, new ECB(46, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(2, 15), new ECB(64, 16))), new Version(37, new Array(6, 28, 54, 80, 106, 132, 158), new ECBlocks(30, new ECB(17, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(29, 46), new ECB(14, 47)), new ECBlocks(30, new ECB(49, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(24, 15), new ECB(46, 16))), new Version(38, new Array(6, 32, 58, 84, 110, 136, 162), new ECBlocks(30, new ECB(4, 122), new ECB(18, 123)), new ECBlocks(28, new ECB(13, 46), new ECB(32, 47)), new ECBlocks(30, new ECB(48, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(42, 15), new ECB(32, 16))), new Version(39, new Array(6, 26, 54, 82, 110, 138, 166), new ECBlocks(30, new ECB(20, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(40, 47), new ECB(7, 48)), new ECBlocks(30, new ECB(43, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(10, 15), new ECB(67, 16))), new Version(40, new Array(6, 30, 58, 86, 114, 142, 170), new ECBlocks(30, new ECB(19, 118), new ECB(6, 119)), new ECBlocks(28, new ECB(18, 47), new ECB(31, 48)), new ECBlocks(30, new ECB(34, 24), new ECB(34, 25)), new ECBlocks(30, new ECB(20, 15), new ECB(61, 16))));
};
return Version;
}());
Version.VERSION_DECODE_INFO = new Array(0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69);
Version.VERSIONS = Version.buildVersions();
if (!Array.prototype.remove) {
Array.prototype.remove = function (from) {
var rest = this.slice((from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
}
var FinderPattern = /** @class */ (function () {
function FinderPattern(posX, posY, estimatedModuleSize) {
this.incrementCount = function () {
this.count++;
};
this.aboutEquals = function (moduleSize, i, j) {
if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize) {
var moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);
return moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;
}
return false;
};
this.x = posX;
this.y = posY;
this.count = 1;
this.estimatedModuleSize = estimatedModuleSize;
}
Object.defineProperty(FinderPattern.prototype, "EstimatedModuleSize", {
get: function () {
return this.estimatedModuleSize;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FinderPattern.prototype, "Count", {
get: function () {
return this.count;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FinderPattern.prototype, "X", {
get: function () {
return this.x;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FinderPattern.prototype, "Y", {
get: function () {
return this.y;
},
enumerable: true,
configurable: true
});
return FinderPattern;
}());
FinderPattern.MIN_SKIP = 3;
FinderPattern.MAX_MODULES = 57;
FinderPattern.INTEGER_MATH_SHIFT = 8;
FinderPattern.CENTER_QUORUM = 2;
var FinderPatternInfo = /** @class */ (function () {
function FinderPatternInfo(patternCenters) {
this.bottomLeft = patternCenters[0];
this.topLeft = patternCenters[1];
this.topRight = patternCenters[2];
}
Object.defineProperty(FinderPatternInfo.prototype, "BottomLeft", {
get: function () {
return this.bottomLeft;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FinderPatternInfo.prototype, "TopLeft", {
get: function () {
return this.topLeft;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FinderPatternInfo.prototype, "TopRight", {
get: function () {
return this.topRight;
},
enumerable: true,
configurable: true
});
return FinderPatternInfo;
}());
var FinderPatternFinder = /** @class */ (function () {
function FinderPatternFinder(width, height) {
this.possibleCenters = new Array();
this.hasSkipped = false;
this.crossCheckStateCount = new Array(0, 0, 0, 0, 0);
this.orderBestPatterns = function (patterns) {
function distance(pattern1, pattern2) {
var xDiff = pattern1.X - pattern2.X;
var yDiff = pattern1.Y - pattern2.Y;
return Math.sqrt((xDiff * xDiff + yDiff * yDiff));
}
function crossProductZ(pointA, pointB, pointC) {
var bX = pointB.x;
var bY = pointB.y;
return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));
}
var zeroOneDistance = distance(patterns[0], patterns[1]);
var oneTwoDistance = distance(patterns[1], patterns[2]);
var zeroTwoDistance = distance(patterns[0], patterns[2]);
var pointA, pointB, pointC;
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];
}
if (crossProductZ(pointA, pointB, pointC) < 0.0) {
var temp = pointA;
pointA = pointC;
pointC = temp;
}
patterns[0] = pointA;
patterns[1] = pointB;
patterns[2] = pointC;
};
this.foundPatternCross = function (stateCount) {
var totalModuleSize = 0;
for (var i = 0; i < 5; i++) {
var count = stateCount[i];
if (count == 0) {
return false;
}
totalModuleSize += count;
}
if (totalModuleSize < 7) {
return false;
}
var moduleSize = Math.floor((totalModuleSize << FinderPattern.INTEGER_MATH_SHIFT) / 7);
var maxVariance = Math.floor(moduleSize / 2);
return Math.abs(moduleSize - (stateCount[0]
<< FinderPattern.INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[1]
<< FinderPattern.INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(3 * moduleSize - (stateCount[2]
<< FinderPattern.INTEGER_MATH_SHIFT)) < 3 * maxVariance && Math.abs(moduleSize - (stateCount[3]
<< FinderPattern.INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[4]
<< FinderPattern.INTEGER_MATH_SHIFT)) < maxVariance;
};
this.centerFromEnd = function (stateCount, end) {
return (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0;
};
this.crossCheckVertical = function (startI, centerJ, maxCount, originalStateCountTotal) {
var image = this.image;
var maxI = this.height;
var stateCount = this.CrossCheckStateCount;
var i = startI;
while (i >= 0 && image[centerJ + i * this.width]) {
stateCount[2]++;
i--;
}
if (i < 0) {
return NaN;
}
while (i >= 0 && !image[centerJ + i * this.width] && stateCount[1] <= maxCount) {
stateCount[1]++;
i--;
}
if (i < 0 || stateCount[1] > maxCount) {
return NaN;
}
while (i >= 0 && image[centerJ + i * this.width] && stateCount[0] <= maxCount) {
stateCount[0]++;
i--;
}
if (stateCount[0] > maxCount) {
return NaN;
}
i = startI + 1;
while (i < maxI && image[centerJ + i * this.width]) {
stateCount[2]++;
i++;
}
if (i == maxI) {
return NaN;
}
while (i < maxI && !image[centerJ + i * this.width] && stateCount[3] < maxCount) {
stateCount[3]++;
i++;
}
if (i == maxI || stateCount[3] >= maxCount) {
return NaN;
}
while (i < maxI && image[centerJ + i * this.width] && stateCount[4] < maxCount) {
stateCount[4]++;
i++;
}
if (stateCount[4] >= maxCount) {
return NaN;
}
var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
return NaN;
}
return this.foundPatternCross(stateCount) ? this.centerFromEnd(stateCount, i) : NaN;
};
this.crossCheckHorizontal = function (startJ, centerI, maxCount, originalStateCountTotal) {
var image = this.image;
var maxJ = this.width;
var stateCount = this.CrossCheckStateCount;
var j = startJ;
while (j >= 0 && image[j + centerI * this.width]) {
stateCount[2]++;
j--;
}
if (j < 0) {
return NaN;
}
while (j >= 0 && !image[j + centerI * this.width] && stateCount[1] <= maxCount) {