Initial commit
This commit is contained in:
357
sources/com/google/zxing/aztec/detector/Detector.java
Normal file
357
sources/com/google/zxing/aztec/detector/Detector.java
Normal file
@@ -0,0 +1,357 @@
|
||||
package com.google.zxing.aztec.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.GridSampler;
|
||||
import com.google.zxing.common.detector.MathUtils;
|
||||
import com.google.zxing.common.detector.WhiteRectangleDetector;
|
||||
import com.google.zxing.common.reedsolomon.GenericGF;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class Detector {
|
||||
private static final int[] g = {3808, 476, 2107, 1799};
|
||||
private final BitMatrix a;
|
||||
private boolean b;
|
||||
private int c;
|
||||
private int d;
|
||||
private int e;
|
||||
private int f;
|
||||
|
||||
static final class Point {
|
||||
private final int a;
|
||||
private final int b;
|
||||
|
||||
Point(int i, int i2) {
|
||||
this.a = i;
|
||||
this.b = i2;
|
||||
}
|
||||
|
||||
int a() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
int b() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
ResultPoint c() {
|
||||
return new ResultPoint(a(), b());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "<" + this.a + ' ' + this.b + '>';
|
||||
}
|
||||
}
|
||||
|
||||
public Detector(BitMatrix bitMatrix) {
|
||||
this.a = bitMatrix;
|
||||
}
|
||||
|
||||
private Point b() {
|
||||
ResultPoint c;
|
||||
ResultPoint resultPoint;
|
||||
ResultPoint resultPoint2;
|
||||
ResultPoint resultPoint3;
|
||||
ResultPoint c2;
|
||||
ResultPoint c3;
|
||||
ResultPoint c4;
|
||||
ResultPoint c5;
|
||||
try {
|
||||
ResultPoint[] a = new WhiteRectangleDetector(this.a).a();
|
||||
resultPoint2 = a[0];
|
||||
resultPoint3 = a[1];
|
||||
resultPoint = a[2];
|
||||
c = a[3];
|
||||
} catch (NotFoundException unused) {
|
||||
int k = this.a.k() / 2;
|
||||
int i = this.a.i() / 2;
|
||||
int i2 = k + 7;
|
||||
int i3 = i - 7;
|
||||
ResultPoint c6 = a(new Point(i2, i3), false, 1, -1).c();
|
||||
int i4 = i + 7;
|
||||
ResultPoint c7 = a(new Point(i2, i4), false, 1, 1).c();
|
||||
int i5 = k - 7;
|
||||
ResultPoint c8 = a(new Point(i5, i4), false, -1, 1).c();
|
||||
c = a(new Point(i5, i3), false, -1, -1).c();
|
||||
resultPoint = c8;
|
||||
resultPoint2 = c6;
|
||||
resultPoint3 = c7;
|
||||
}
|
||||
int a2 = MathUtils.a((((resultPoint2.a() + c.a()) + resultPoint3.a()) + resultPoint.a()) / 4.0f);
|
||||
int a3 = MathUtils.a((((resultPoint2.b() + c.b()) + resultPoint3.b()) + resultPoint.b()) / 4.0f);
|
||||
try {
|
||||
ResultPoint[] a4 = new WhiteRectangleDetector(this.a, 15, a2, a3).a();
|
||||
c2 = a4[0];
|
||||
c3 = a4[1];
|
||||
c4 = a4[2];
|
||||
c5 = a4[3];
|
||||
} catch (NotFoundException unused2) {
|
||||
int i6 = a2 + 7;
|
||||
int i7 = a3 - 7;
|
||||
c2 = a(new Point(i6, i7), false, 1, -1).c();
|
||||
int i8 = a3 + 7;
|
||||
c3 = a(new Point(i6, i8), false, 1, 1).c();
|
||||
int i9 = a2 - 7;
|
||||
c4 = a(new Point(i9, i8), false, -1, 1).c();
|
||||
c5 = a(new Point(i9, i7), false, -1, -1).c();
|
||||
}
|
||||
return new Point(MathUtils.a((((c2.a() + c5.a()) + c3.a()) + c4.a()) / 4.0f), MathUtils.a((((c2.b() + c5.b()) + c3.b()) + c4.b()) / 4.0f));
|
||||
}
|
||||
|
||||
public AztecDetectorResult a(boolean z) throws NotFoundException {
|
||||
ResultPoint[] a = a(b());
|
||||
if (z) {
|
||||
ResultPoint resultPoint = a[0];
|
||||
a[0] = a[2];
|
||||
a[2] = resultPoint;
|
||||
}
|
||||
a(a);
|
||||
BitMatrix bitMatrix = this.a;
|
||||
int i = this.f;
|
||||
return new AztecDetectorResult(a(bitMatrix, a[i % 4], a[(i + 1) % 4], a[(i + 2) % 4], a[(i + 3) % 4]), b(a), this.b, this.d, this.c);
|
||||
}
|
||||
|
||||
private void a(ResultPoint[] resultPointArr) throws NotFoundException {
|
||||
long j;
|
||||
long j2;
|
||||
if (a(resultPointArr[0]) && a(resultPointArr[1]) && a(resultPointArr[2]) && a(resultPointArr[3])) {
|
||||
int i = this.e * 2;
|
||||
int[] iArr = {a(resultPointArr[0], resultPointArr[1], i), a(resultPointArr[1], resultPointArr[2], i), a(resultPointArr[2], resultPointArr[3], i), a(resultPointArr[3], resultPointArr[0], i)};
|
||||
this.f = a(iArr, i);
|
||||
long j3 = 0;
|
||||
for (int i2 = 0; i2 < 4; i2++) {
|
||||
int i3 = iArr[(this.f + i2) % 4];
|
||||
if (this.b) {
|
||||
j = j3 << 7;
|
||||
j2 = (i3 >> 1) & 127;
|
||||
} else {
|
||||
j = j3 << 10;
|
||||
j2 = ((i3 >> 2) & 992) + ((i3 >> 1) & 31);
|
||||
}
|
||||
j3 = j + j2;
|
||||
}
|
||||
int a = a(j3, this.b);
|
||||
if (this.b) {
|
||||
this.c = (a >> 6) + 1;
|
||||
this.d = (a & 63) + 1;
|
||||
return;
|
||||
} else {
|
||||
this.c = (a >> 11) + 1;
|
||||
this.d = (a & 2047) + 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
private ResultPoint[] b(ResultPoint[] resultPointArr) {
|
||||
return a(resultPointArr, this.e * 2, a());
|
||||
}
|
||||
|
||||
private int b(Point point, Point point2) {
|
||||
float a = a(point, point2);
|
||||
float a2 = (point2.a() - point.a()) / a;
|
||||
float b = (point2.b() - point.b()) / a;
|
||||
float a3 = point.a();
|
||||
float b2 = point.b();
|
||||
boolean b3 = this.a.b(point.a(), point.b());
|
||||
int ceil = (int) Math.ceil(a);
|
||||
float f = a3;
|
||||
float f2 = b2;
|
||||
int i = 0;
|
||||
for (int i2 = 0; i2 < ceil; i2++) {
|
||||
f += a2;
|
||||
f2 += b;
|
||||
if (this.a.b(MathUtils.a(f), MathUtils.a(f2)) != b3) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
float f3 = i / a;
|
||||
if (f3 <= 0.1f || f3 >= 0.9f) {
|
||||
return (f3 <= 0.1f) == b3 ? 1 : -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int a(int[] iArr, int i) throws NotFoundException {
|
||||
int i2 = 0;
|
||||
for (int i3 : iArr) {
|
||||
i2 = (i2 << 3) + ((i3 >> (i - 2)) << 1) + (i3 & 1);
|
||||
}
|
||||
int i4 = ((i2 & 1) << 11) + (i2 >> 1);
|
||||
for (int i5 = 0; i5 < 4; i5++) {
|
||||
if (Integer.bitCount(g[i5] ^ i4) <= 2) {
|
||||
return i5;
|
||||
}
|
||||
}
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
private static int a(long j, boolean z) throws NotFoundException {
|
||||
int i;
|
||||
int i2;
|
||||
if (z) {
|
||||
i = 7;
|
||||
i2 = 2;
|
||||
} else {
|
||||
i = 10;
|
||||
i2 = 4;
|
||||
}
|
||||
int i3 = i - i2;
|
||||
int[] iArr = new int[i];
|
||||
for (int i4 = i - 1; i4 >= 0; i4--) {
|
||||
iArr[i4] = ((int) j) & 15;
|
||||
j >>= 4;
|
||||
}
|
||||
try {
|
||||
new ReedSolomonDecoder(GenericGF.k).a(iArr, i3);
|
||||
int i5 = 0;
|
||||
for (int i6 = 0; i6 < i2; i6++) {
|
||||
i5 = (i5 << 4) + iArr[i6];
|
||||
}
|
||||
return i5;
|
||||
} catch (ReedSolomonException unused) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private ResultPoint[] a(Point point) throws NotFoundException {
|
||||
this.e = 1;
|
||||
Point point2 = point;
|
||||
Point point3 = point2;
|
||||
Point point4 = point3;
|
||||
Point point5 = point4;
|
||||
boolean z = true;
|
||||
while (this.e < 9) {
|
||||
Point a = a(point2, z, 1, -1);
|
||||
Point a2 = a(point3, z, 1, 1);
|
||||
Point a3 = a(point4, z, -1, 1);
|
||||
Point a4 = a(point5, z, -1, -1);
|
||||
if (this.e > 2) {
|
||||
double a5 = (a(a4, a) * this.e) / (a(point5, point2) * (this.e + 2));
|
||||
if (a5 < 0.75d || a5 > 1.25d || !a(a, a2, a3, a4)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
z = !z;
|
||||
this.e++;
|
||||
point5 = a4;
|
||||
point2 = a;
|
||||
point3 = a2;
|
||||
point4 = a3;
|
||||
}
|
||||
int i = this.e;
|
||||
if (i != 5 && i != 7) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
this.b = this.e == 5;
|
||||
ResultPoint[] resultPointArr = {new ResultPoint(point2.a() + 0.5f, point2.b() - 0.5f), new ResultPoint(point3.a() + 0.5f, point3.b() + 0.5f), new ResultPoint(point4.a() - 0.5f, point4.b() + 0.5f), new ResultPoint(point5.a() - 0.5f, point5.b() - 0.5f)};
|
||||
int i2 = this.e;
|
||||
return a(resultPointArr, (i2 * 2) - 3, i2 * 2);
|
||||
}
|
||||
|
||||
private BitMatrix a(BitMatrix bitMatrix, ResultPoint resultPoint, ResultPoint resultPoint2, ResultPoint resultPoint3, ResultPoint resultPoint4) throws NotFoundException {
|
||||
GridSampler a = GridSampler.a();
|
||||
int a2 = a();
|
||||
float f = a2 / 2.0f;
|
||||
int i = this.e;
|
||||
float f2 = f - i;
|
||||
float f3 = f + i;
|
||||
return a.a(bitMatrix, a2, a2, f2, f2, f3, f2, f3, f3, f2, f3, resultPoint.a(), resultPoint.b(), resultPoint2.a(), resultPoint2.b(), resultPoint3.a(), resultPoint3.b(), resultPoint4.a(), resultPoint4.b());
|
||||
}
|
||||
|
||||
private int a(ResultPoint resultPoint, ResultPoint resultPoint2, int i) {
|
||||
float a = a(resultPoint, resultPoint2);
|
||||
float f = a / i;
|
||||
float a2 = resultPoint.a();
|
||||
float b = resultPoint.b();
|
||||
float a3 = ((resultPoint2.a() - resultPoint.a()) * f) / a;
|
||||
float b2 = (f * (resultPoint2.b() - resultPoint.b())) / a;
|
||||
int i2 = 0;
|
||||
for (int i3 = 0; i3 < i; i3++) {
|
||||
float f2 = i3;
|
||||
if (this.a.b(MathUtils.a((f2 * a3) + a2), MathUtils.a((f2 * b2) + b))) {
|
||||
i2 |= 1 << ((i - i3) - 1);
|
||||
}
|
||||
}
|
||||
return i2;
|
||||
}
|
||||
|
||||
private boolean a(Point point, Point point2, Point point3, Point point4) {
|
||||
Point point5 = new Point(point.a() - 3, point.b() + 3);
|
||||
Point point6 = new Point(point2.a() - 3, point2.b() - 3);
|
||||
Point point7 = new Point(point3.a() + 3, point3.b() - 3);
|
||||
Point point8 = new Point(point4.a() + 3, point4.b() + 3);
|
||||
int b = b(point8, point5);
|
||||
return b != 0 && b(point5, point6) == b && b(point6, point7) == b && b(point7, point8) == b;
|
||||
}
|
||||
|
||||
private Point a(Point point, boolean z, int i, int i2) {
|
||||
int a = point.a() + i;
|
||||
int b = point.b();
|
||||
while (true) {
|
||||
b += i2;
|
||||
if (!a(a, b) || this.a.b(a, b) != z) {
|
||||
break;
|
||||
}
|
||||
a += i;
|
||||
}
|
||||
int i3 = a - i;
|
||||
int i4 = b - i2;
|
||||
while (a(i3, i4) && this.a.b(i3, i4) == z) {
|
||||
i3 += i;
|
||||
}
|
||||
int i5 = i3 - i;
|
||||
while (a(i5, i4) && this.a.b(i5, i4) == z) {
|
||||
i4 += i2;
|
||||
}
|
||||
return new Point(i5, i4 - i2);
|
||||
}
|
||||
|
||||
private static ResultPoint[] a(ResultPoint[] resultPointArr, int i, int i2) {
|
||||
float f = i2 / (i * 2.0f);
|
||||
float a = resultPointArr[0].a() - resultPointArr[2].a();
|
||||
float b = resultPointArr[0].b() - resultPointArr[2].b();
|
||||
float a2 = (resultPointArr[0].a() + resultPointArr[2].a()) / 2.0f;
|
||||
float b2 = (resultPointArr[0].b() + resultPointArr[2].b()) / 2.0f;
|
||||
float f2 = a * f;
|
||||
float f3 = b * f;
|
||||
ResultPoint resultPoint = new ResultPoint(a2 + f2, b2 + f3);
|
||||
ResultPoint resultPoint2 = new ResultPoint(a2 - f2, b2 - f3);
|
||||
float a3 = resultPointArr[1].a() - resultPointArr[3].a();
|
||||
float b3 = resultPointArr[1].b() - resultPointArr[3].b();
|
||||
float a4 = (resultPointArr[1].a() + resultPointArr[3].a()) / 2.0f;
|
||||
float b4 = (resultPointArr[1].b() + resultPointArr[3].b()) / 2.0f;
|
||||
float f4 = a3 * f;
|
||||
float f5 = f * b3;
|
||||
return new ResultPoint[]{resultPoint, new ResultPoint(a4 + f4, b4 + f5), resultPoint2, new ResultPoint(a4 - f4, b4 - f5)};
|
||||
}
|
||||
|
||||
private boolean a(int i, int i2) {
|
||||
return i >= 0 && i < this.a.k() && i2 > 0 && i2 < this.a.i();
|
||||
}
|
||||
|
||||
private boolean a(ResultPoint resultPoint) {
|
||||
return a(MathUtils.a(resultPoint.a()), MathUtils.a(resultPoint.b()));
|
||||
}
|
||||
|
||||
private static float a(Point point, Point point2) {
|
||||
return MathUtils.a(point.a(), point.b(), point2.a(), point2.b());
|
||||
}
|
||||
|
||||
private static float a(ResultPoint resultPoint, ResultPoint resultPoint2) {
|
||||
return MathUtils.a(resultPoint.a(), resultPoint.b(), resultPoint2.a(), resultPoint2.b());
|
||||
}
|
||||
|
||||
private int a() {
|
||||
if (this.b) {
|
||||
return (this.c * 4) + 11;
|
||||
}
|
||||
int i = this.c;
|
||||
return i <= 4 ? (i * 4) + 15 : (i * 4) + ((((i - 4) / 8) + 1) * 2) + 15;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user