Initial commit
This commit is contained in:
28
sources/com/google/zxing/common/detector/MathUtils.java
Normal file
28
sources/com/google/zxing/common/detector/MathUtils.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.google.zxing.common.detector;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class MathUtils {
|
||||
public static float a(float f, float f2, float f3, float f4) {
|
||||
float f5 = f - f3;
|
||||
float f6 = f2 - f4;
|
||||
return (float) Math.sqrt((f5 * f5) + (f6 * f6));
|
||||
}
|
||||
|
||||
public static int a(float f) {
|
||||
return (int) (f + (f < 0.0f ? -0.5f : 0.5f));
|
||||
}
|
||||
|
||||
public static float a(int i, int i2, int i3, int i4) {
|
||||
int i5 = i - i3;
|
||||
int i6 = i2 - i4;
|
||||
return (float) Math.sqrt((i5 * i5) + (i6 * i6));
|
||||
}
|
||||
|
||||
public static int a(int[] iArr) {
|
||||
int i = 0;
|
||||
for (int i2 : iArr) {
|
||||
i += i2;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
@@ -0,0 +1,197 @@
|
||||
package com.google.zxing.common.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class WhiteRectangleDetector {
|
||||
private final BitMatrix a;
|
||||
private final int b;
|
||||
private final int c;
|
||||
private final int d;
|
||||
private final int e;
|
||||
private final int f;
|
||||
private final int g;
|
||||
|
||||
public WhiteRectangleDetector(BitMatrix bitMatrix) throws NotFoundException {
|
||||
this(bitMatrix, 10, bitMatrix.k() / 2, bitMatrix.i() / 2);
|
||||
}
|
||||
|
||||
public ResultPoint[] a() throws NotFoundException {
|
||||
boolean z;
|
||||
int i = this.d;
|
||||
int i2 = this.e;
|
||||
int i3 = this.g;
|
||||
int i4 = this.f;
|
||||
boolean z2 = false;
|
||||
int i5 = i;
|
||||
boolean z3 = false;
|
||||
boolean z4 = false;
|
||||
boolean z5 = false;
|
||||
boolean z6 = false;
|
||||
boolean z7 = false;
|
||||
for (boolean z8 = true; z8; z8 = z) {
|
||||
boolean z9 = true;
|
||||
z = false;
|
||||
while (true) {
|
||||
if ((z9 || !z3) && i2 < this.c) {
|
||||
z9 = a(i3, i4, i2, false);
|
||||
if (z9) {
|
||||
i2++;
|
||||
z3 = true;
|
||||
z = true;
|
||||
} else if (!z3) {
|
||||
i2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i2 < this.c) {
|
||||
boolean z10 = true;
|
||||
while (true) {
|
||||
if ((z10 || !z4) && i4 < this.b) {
|
||||
z10 = a(i5, i2, i4, true);
|
||||
if (z10) {
|
||||
i4++;
|
||||
z4 = true;
|
||||
z = true;
|
||||
} else if (!z4) {
|
||||
i4++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i4 < this.b) {
|
||||
boolean z11 = true;
|
||||
while (true) {
|
||||
if ((z11 || !z5) && i5 >= 0) {
|
||||
z11 = a(i3, i4, i5, false);
|
||||
if (z11) {
|
||||
i5--;
|
||||
z5 = true;
|
||||
z = true;
|
||||
} else if (!z5) {
|
||||
i5--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i5 >= 0) {
|
||||
boolean z12 = true;
|
||||
while (true) {
|
||||
if ((z12 || !z7) && i3 >= 0) {
|
||||
z12 = a(i5, i2, i3, true);
|
||||
if (z12) {
|
||||
i3--;
|
||||
z7 = true;
|
||||
z = true;
|
||||
} else if (!z7) {
|
||||
i3--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i3 >= 0) {
|
||||
if (z) {
|
||||
z6 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
z2 = true;
|
||||
break;
|
||||
}
|
||||
if (z2 || !z6) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
int i6 = i2 - i5;
|
||||
ResultPoint resultPoint = null;
|
||||
ResultPoint resultPoint2 = null;
|
||||
for (int i7 = 1; resultPoint2 == null && i7 < i6; i7++) {
|
||||
resultPoint2 = a(i5, i4 - i7, i5 + i7, i4);
|
||||
}
|
||||
if (resultPoint2 == null) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
ResultPoint resultPoint3 = null;
|
||||
for (int i8 = 1; resultPoint3 == null && i8 < i6; i8++) {
|
||||
resultPoint3 = a(i5, i3 + i8, i5 + i8, i3);
|
||||
}
|
||||
if (resultPoint3 == null) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
ResultPoint resultPoint4 = null;
|
||||
for (int i9 = 1; resultPoint4 == null && i9 < i6; i9++) {
|
||||
resultPoint4 = a(i2, i3 + i9, i2 - i9, i3);
|
||||
}
|
||||
if (resultPoint4 == null) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
for (int i10 = 1; resultPoint == null && i10 < i6; i10++) {
|
||||
resultPoint = a(i2, i4 - i10, i2 - i10, i4);
|
||||
}
|
||||
if (resultPoint != null) {
|
||||
return a(resultPoint, resultPoint2, resultPoint4, resultPoint3);
|
||||
}
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
public WhiteRectangleDetector(BitMatrix bitMatrix, int i, int i2, int i3) throws NotFoundException {
|
||||
this.a = bitMatrix;
|
||||
this.b = bitMatrix.i();
|
||||
this.c = bitMatrix.k();
|
||||
int i4 = i / 2;
|
||||
this.d = i2 - i4;
|
||||
this.e = i2 + i4;
|
||||
this.g = i3 - i4;
|
||||
this.f = i3 + i4;
|
||||
if (this.g < 0 || this.d < 0 || this.f >= this.b || this.e >= this.c) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private ResultPoint a(float f, float f2, float f3, float f4) {
|
||||
int a = MathUtils.a(MathUtils.a(f, f2, f3, f4));
|
||||
float f5 = a;
|
||||
float f6 = (f3 - f) / f5;
|
||||
float f7 = (f4 - f2) / f5;
|
||||
for (int i = 0; i < a; i++) {
|
||||
float f8 = i;
|
||||
int a2 = MathUtils.a((f8 * f6) + f);
|
||||
int a3 = MathUtils.a((f8 * f7) + f2);
|
||||
if (this.a.b(a2, a3)) {
|
||||
return new ResultPoint(a2, a3);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ResultPoint[] a(ResultPoint resultPoint, ResultPoint resultPoint2, ResultPoint resultPoint3, ResultPoint resultPoint4) {
|
||||
float a = resultPoint.a();
|
||||
float b = resultPoint.b();
|
||||
float a2 = resultPoint2.a();
|
||||
float b2 = resultPoint2.b();
|
||||
float a3 = resultPoint3.a();
|
||||
float b3 = resultPoint3.b();
|
||||
float a4 = resultPoint4.a();
|
||||
float b4 = resultPoint4.b();
|
||||
return a < ((float) this.c) / 2.0f ? new ResultPoint[]{new ResultPoint(a4 - 1.0f, b4 + 1.0f), new ResultPoint(a2 + 1.0f, b2 + 1.0f), new ResultPoint(a3 - 1.0f, b3 - 1.0f), new ResultPoint(a + 1.0f, b - 1.0f)} : new ResultPoint[]{new ResultPoint(a4 + 1.0f, b4 + 1.0f), new ResultPoint(a2 + 1.0f, b2 - 1.0f), new ResultPoint(a3 - 1.0f, b3 + 1.0f), new ResultPoint(a - 1.0f, b - 1.0f)};
|
||||
}
|
||||
|
||||
private boolean a(int i, int i2, int i3, boolean z) {
|
||||
if (z) {
|
||||
while (i <= i2) {
|
||||
if (this.a.b(i, i3)) {
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
while (i <= i2) {
|
||||
if (this.a.b(i3, i)) {
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user