Initial commit
This commit is contained in:
249
sources/com/google/zxing/datamatrix/detector/Detector.java
Normal file
249
sources/com/google/zxing/datamatrix/detector/Detector.java
Normal file
@@ -0,0 +1,249 @@
|
||||
package com.google.zxing.datamatrix.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DetectorResult;
|
||||
import com.google.zxing.common.GridSampler;
|
||||
import com.google.zxing.common.detector.MathUtils;
|
||||
import com.google.zxing.common.detector.WhiteRectangleDetector;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class Detector {
|
||||
private final BitMatrix a;
|
||||
private final WhiteRectangleDetector b;
|
||||
|
||||
private static final class ResultPointsAndTransitions {
|
||||
private final ResultPoint a;
|
||||
private final ResultPoint b;
|
||||
private final int c;
|
||||
|
||||
ResultPoint a() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
ResultPoint b() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
int c() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.a + "/" + this.b + '/' + this.c;
|
||||
}
|
||||
|
||||
private ResultPointsAndTransitions(ResultPoint resultPoint, ResultPoint resultPoint2, int i) {
|
||||
this.a = resultPoint;
|
||||
this.b = resultPoint2;
|
||||
this.c = i;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ResultPointsAndTransitionsComparator implements Serializable, Comparator<ResultPointsAndTransitions> {
|
||||
private ResultPointsAndTransitionsComparator() {
|
||||
}
|
||||
|
||||
@Override // java.util.Comparator
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public int compare(ResultPointsAndTransitions resultPointsAndTransitions, ResultPointsAndTransitions resultPointsAndTransitions2) {
|
||||
return resultPointsAndTransitions.c() - resultPointsAndTransitions2.c();
|
||||
}
|
||||
}
|
||||
|
||||
public Detector(BitMatrix bitMatrix) throws NotFoundException {
|
||||
this.a = bitMatrix;
|
||||
this.b = new WhiteRectangleDetector(bitMatrix);
|
||||
}
|
||||
|
||||
private ResultPointsAndTransitions b(ResultPoint resultPoint, ResultPoint resultPoint2) {
|
||||
int a = (int) resultPoint.a();
|
||||
int b = (int) resultPoint.b();
|
||||
int a2 = (int) resultPoint2.a();
|
||||
int b2 = (int) resultPoint2.b();
|
||||
int i = 0;
|
||||
boolean z = Math.abs(b2 - b) > Math.abs(a2 - a);
|
||||
if (z) {
|
||||
b = a;
|
||||
a = b;
|
||||
b2 = a2;
|
||||
a2 = b2;
|
||||
}
|
||||
int abs = Math.abs(a2 - a);
|
||||
int abs2 = Math.abs(b2 - b);
|
||||
int i2 = (-abs) / 2;
|
||||
int i3 = b < b2 ? 1 : -1;
|
||||
int i4 = a >= a2 ? -1 : 1;
|
||||
boolean b3 = this.a.b(z ? b : a, z ? a : b);
|
||||
while (a != a2) {
|
||||
boolean b4 = this.a.b(z ? b : a, z ? a : b);
|
||||
if (b4 != b3) {
|
||||
i++;
|
||||
b3 = b4;
|
||||
}
|
||||
i2 += abs2;
|
||||
if (i2 > 0) {
|
||||
if (b == b2) {
|
||||
break;
|
||||
}
|
||||
b += i3;
|
||||
i2 -= abs;
|
||||
}
|
||||
a += i4;
|
||||
}
|
||||
return new ResultPointsAndTransitions(resultPoint, resultPoint2, i);
|
||||
}
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
/* JADX WARN: Type inference failed for: r14v3, types: [com.google.zxing.ResultPoint] */
|
||||
/* JADX WARN: Type inference failed for: r16v3, types: [com.google.zxing.ResultPoint] */
|
||||
/* JADX WARN: Type inference failed for: r22v0, types: [com.google.zxing.ResultPoint] */
|
||||
/* JADX WARN: Type inference failed for: r23v0, types: [com.google.zxing.datamatrix.detector.Detector] */
|
||||
/* JADX WARN: Type inference failed for: r3v3, types: [com.google.zxing.ResultPoint[]] */
|
||||
/* JADX WARN: Type inference failed for: r4v6, types: [com.google.zxing.ResultPoint[]] */
|
||||
/* JADX WARN: Type inference failed for: r6v2, types: [com.google.zxing.ResultPoint] */
|
||||
public DetectorResult a() throws NotFoundException {
|
||||
ResultPoint resultPoint;
|
||||
ResultPoint a;
|
||||
BitMatrix a2;
|
||||
ResultPoint[] a3 = this.b.a();
|
||||
ResultPoint resultPoint2 = a3[0];
|
||||
ResultPoint resultPoint3 = a3[1];
|
||||
ResultPoint resultPoint4 = a3[2];
|
||||
ResultPoint resultPoint5 = a3[3];
|
||||
ArrayList arrayList = new ArrayList(4);
|
||||
arrayList.add(b(resultPoint2, resultPoint3));
|
||||
arrayList.add(b(resultPoint2, resultPoint4));
|
||||
arrayList.add(b(resultPoint3, resultPoint5));
|
||||
arrayList.add(b(resultPoint4, resultPoint5));
|
||||
AnonymousClass1 anonymousClass1 = null;
|
||||
Collections.sort(arrayList, new ResultPointsAndTransitionsComparator());
|
||||
ResultPointsAndTransitions resultPointsAndTransitions = (ResultPointsAndTransitions) arrayList.get(0);
|
||||
ResultPointsAndTransitions resultPointsAndTransitions2 = (ResultPointsAndTransitions) arrayList.get(1);
|
||||
HashMap hashMap = new HashMap();
|
||||
a(hashMap, resultPointsAndTransitions.a());
|
||||
a(hashMap, resultPointsAndTransitions.b());
|
||||
a(hashMap, resultPointsAndTransitions2.a());
|
||||
a(hashMap, resultPointsAndTransitions2.b());
|
||||
Object obj = null;
|
||||
Object obj2 = null;
|
||||
for (Map.Entry entry : hashMap.entrySet()) {
|
||||
?? r16 = (ResultPoint) entry.getKey();
|
||||
if (((Integer) entry.getValue()).intValue() == 2) {
|
||||
obj = r16;
|
||||
} else if (anonymousClass1 == null) {
|
||||
anonymousClass1 = r16;
|
||||
} else {
|
||||
obj2 = r16;
|
||||
}
|
||||
}
|
||||
if (anonymousClass1 == null || obj == null || obj2 == null) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
?? r4 = {anonymousClass1, obj, obj2};
|
||||
ResultPoint.a(r4);
|
||||
?? r14 = r4[0];
|
||||
?? r22 = r4[1];
|
||||
?? r6 = r4[2];
|
||||
ResultPoint resultPoint6 = !hashMap.containsKey(resultPoint2) ? resultPoint2 : !hashMap.containsKey(resultPoint3) ? resultPoint3 : !hashMap.containsKey(resultPoint4) ? resultPoint4 : resultPoint5;
|
||||
int c = b(r6, resultPoint6).c();
|
||||
int c2 = b(r14, resultPoint6).c();
|
||||
if ((c & 1) == 1) {
|
||||
c++;
|
||||
}
|
||||
int i = c + 2;
|
||||
if ((c2 & 1) == 1) {
|
||||
c2++;
|
||||
}
|
||||
int i2 = c2 + 2;
|
||||
if (i * 4 >= i2 * 7 || i2 * 4 >= i * 7) {
|
||||
resultPoint = r6;
|
||||
a = a(r22, r14, r6, resultPoint6, i, i2);
|
||||
if (a == null) {
|
||||
a = resultPoint6;
|
||||
}
|
||||
int c3 = b(resultPoint, a).c();
|
||||
int c4 = b(r14, a).c();
|
||||
if ((c3 & 1) == 1) {
|
||||
c3++;
|
||||
}
|
||||
int i3 = c3;
|
||||
if ((c4 & 1) == 1) {
|
||||
c4++;
|
||||
}
|
||||
a2 = a(this.a, resultPoint, r22, r14, a, i3, c4);
|
||||
} else {
|
||||
a = a(r22, r14, r6, resultPoint6, Math.min(i2, i));
|
||||
if (a == null) {
|
||||
a = resultPoint6;
|
||||
}
|
||||
int max = Math.max(b(r6, a).c(), b(r14, a).c()) + 1;
|
||||
if ((max & 1) == 1) {
|
||||
max++;
|
||||
}
|
||||
int i4 = max;
|
||||
a2 = a(this.a, r6, r22, r14, a, i4, i4);
|
||||
resultPoint = r6;
|
||||
}
|
||||
return new DetectorResult(a2, new ResultPoint[]{resultPoint, r22, r14, a});
|
||||
}
|
||||
|
||||
private ResultPoint a(ResultPoint resultPoint, ResultPoint resultPoint2, ResultPoint resultPoint3, ResultPoint resultPoint4, int i, int i2) {
|
||||
float a = a(resultPoint, resultPoint2) / i;
|
||||
float a2 = a(resultPoint3, resultPoint4);
|
||||
ResultPoint resultPoint5 = new ResultPoint(resultPoint4.a() + (((resultPoint4.a() - resultPoint3.a()) / a2) * a), resultPoint4.b() + (a * ((resultPoint4.b() - resultPoint3.b()) / a2)));
|
||||
float a3 = a(resultPoint, resultPoint3) / i2;
|
||||
float a4 = a(resultPoint2, resultPoint4);
|
||||
ResultPoint resultPoint6 = new ResultPoint(resultPoint4.a() + (((resultPoint4.a() - resultPoint2.a()) / a4) * a3), resultPoint4.b() + (a3 * ((resultPoint4.b() - resultPoint2.b()) / a4)));
|
||||
if (a(resultPoint5)) {
|
||||
return (a(resultPoint6) && Math.abs(i - b(resultPoint3, resultPoint5).c()) + Math.abs(i2 - b(resultPoint2, resultPoint5).c()) > Math.abs(i - b(resultPoint3, resultPoint6).c()) + Math.abs(i2 - b(resultPoint2, resultPoint6).c())) ? resultPoint6 : resultPoint5;
|
||||
}
|
||||
if (a(resultPoint6)) {
|
||||
return resultPoint6;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ResultPoint a(ResultPoint resultPoint, ResultPoint resultPoint2, ResultPoint resultPoint3, ResultPoint resultPoint4, int i) {
|
||||
float f = i;
|
||||
float a = a(resultPoint, resultPoint2) / f;
|
||||
float a2 = a(resultPoint3, resultPoint4);
|
||||
ResultPoint resultPoint5 = new ResultPoint(resultPoint4.a() + (((resultPoint4.a() - resultPoint3.a()) / a2) * a), resultPoint4.b() + (a * ((resultPoint4.b() - resultPoint3.b()) / a2)));
|
||||
float a3 = a(resultPoint, resultPoint3) / f;
|
||||
float a4 = a(resultPoint2, resultPoint4);
|
||||
ResultPoint resultPoint6 = new ResultPoint(resultPoint4.a() + (((resultPoint4.a() - resultPoint2.a()) / a4) * a3), resultPoint4.b() + (a3 * ((resultPoint4.b() - resultPoint2.b()) / a4)));
|
||||
if (a(resultPoint5)) {
|
||||
return (a(resultPoint6) && Math.abs(b(resultPoint3, resultPoint5).c() - b(resultPoint2, resultPoint5).c()) > Math.abs(b(resultPoint3, resultPoint6).c() - b(resultPoint2, resultPoint6).c())) ? resultPoint6 : resultPoint5;
|
||||
}
|
||||
if (a(resultPoint6)) {
|
||||
return resultPoint6;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean a(ResultPoint resultPoint) {
|
||||
return resultPoint.a() >= 0.0f && resultPoint.a() < ((float) this.a.k()) && resultPoint.b() > 0.0f && resultPoint.b() < ((float) this.a.i());
|
||||
}
|
||||
|
||||
private static int a(ResultPoint resultPoint, ResultPoint resultPoint2) {
|
||||
return MathUtils.a(ResultPoint.a(resultPoint, resultPoint2));
|
||||
}
|
||||
|
||||
private static void a(Map<ResultPoint, Integer> map, ResultPoint resultPoint) {
|
||||
Integer num = map.get(resultPoint);
|
||||
map.put(resultPoint, Integer.valueOf(num != null ? 1 + num.intValue() : 1));
|
||||
}
|
||||
|
||||
private static BitMatrix a(BitMatrix bitMatrix, ResultPoint resultPoint, ResultPoint resultPoint2, ResultPoint resultPoint3, ResultPoint resultPoint4, int i, int i2) throws NotFoundException {
|
||||
float f = i - 0.5f;
|
||||
float f2 = i2 - 0.5f;
|
||||
return GridSampler.a().a(bitMatrix, i, i2, 0.5f, 0.5f, f, 0.5f, f, f2, 0.5f, f2, resultPoint.a(), resultPoint.b(), resultPoint4.a(), resultPoint4.b(), resultPoint3.a(), resultPoint3.b(), resultPoint2.a(), resultPoint2.b());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user