mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-26 09:02:34 -06:00
203 lines
7.7 KiB
Java
203 lines
7.7 KiB
Java
package com.google.zxing.oned;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.DecodeHintType;
|
|
import com.google.zxing.FormatException;
|
|
import com.google.zxing.NotFoundException;
|
|
import com.google.zxing.Result;
|
|
import com.google.zxing.ResultPoint;
|
|
import com.google.zxing.common.BitArray;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public final class ITFReader extends OneDReader {
|
|
private static final float MAX_AVG_VARIANCE = 0.38f;
|
|
private static final float MAX_INDIVIDUAL_VARIANCE = 0.5f;
|
|
private static final int N = 1;
|
|
private static final int W = 3;
|
|
private static final int w = 2;
|
|
private int narrowLineWidth = -1;
|
|
private static final int[] DEFAULT_ALLOWED_LENGTHS = {6, 8, 10, 12, 14};
|
|
private static final int[] START_PATTERN = {1, 1, 1, 1};
|
|
private static final int[][] END_PATTERN_REVERSED = {new int[]{1, 1, 2}, new int[]{1, 1, 3}};
|
|
private static final int[][] PATTERNS = {new int[]{1, 1, 2, 2, 1}, new int[]{2, 1, 1, 1, 2}, new int[]{1, 2, 1, 1, 2}, new int[]{2, 2, 1, 1, 1}, new int[]{1, 1, 2, 1, 2}, new int[]{2, 1, 2, 1, 1}, new int[]{1, 2, 2, 1, 1}, new int[]{1, 1, 1, 2, 2}, new int[]{2, 1, 1, 2, 1}, new int[]{1, 2, 1, 2, 1}, new int[]{1, 1, 3, 3, 1}, new int[]{3, 1, 1, 1, 3}, new int[]{1, 3, 1, 1, 3}, new int[]{3, 3, 1, 1, 1}, new int[]{1, 1, 3, 1, 3}, new int[]{3, 1, 3, 1, 1}, new int[]{1, 3, 3, 1, 1}, new int[]{1, 1, 1, 3, 3}, new int[]{3, 1, 1, 3, 1}, new int[]{1, 3, 1, 3, 1}};
|
|
|
|
@Override // com.google.zxing.oned.OneDReader
|
|
public Result decodeRow(int i, BitArray bitArray, Map<DecodeHintType, ?> map) throws FormatException, NotFoundException {
|
|
boolean z;
|
|
int[] decodeStart = decodeStart(bitArray);
|
|
int[] decodeEnd = decodeEnd(bitArray);
|
|
StringBuilder sb = new StringBuilder(20);
|
|
decodeMiddle(bitArray, decodeStart[1], decodeEnd[0], sb);
|
|
String sb2 = sb.toString();
|
|
int[] iArr = map != null ? (int[]) map.get(DecodeHintType.ALLOWED_LENGTHS) : null;
|
|
if (iArr == null) {
|
|
iArr = DEFAULT_ALLOWED_LENGTHS;
|
|
}
|
|
int length = sb2.length();
|
|
int length2 = iArr.length;
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
while (true) {
|
|
if (i2 >= length2) {
|
|
z = false;
|
|
break;
|
|
}
|
|
int i4 = iArr[i2];
|
|
if (length == i4) {
|
|
z = true;
|
|
break;
|
|
}
|
|
if (i4 > i3) {
|
|
i3 = i4;
|
|
}
|
|
i2++;
|
|
}
|
|
if ((z || length <= i3) && !z) {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
float f = i;
|
|
return new Result(sb2, null, new ResultPoint[]{new ResultPoint(decodeStart[1], f), new ResultPoint(decodeEnd[0], f)}, BarcodeFormat.ITF);
|
|
}
|
|
|
|
private static void decodeMiddle(BitArray bitArray, int i, int i2, StringBuilder sb) throws NotFoundException {
|
|
int[] iArr = new int[10];
|
|
int[] iArr2 = new int[5];
|
|
int[] iArr3 = new int[5];
|
|
while (i < i2) {
|
|
recordPattern(bitArray, i, iArr);
|
|
for (int i3 = 0; i3 < 5; i3++) {
|
|
int i4 = i3 * 2;
|
|
iArr2[i3] = iArr[i4];
|
|
iArr3[i3] = iArr[i4 + 1];
|
|
}
|
|
sb.append((char) (decodeDigit(iArr2) + 48));
|
|
sb.append((char) (decodeDigit(iArr3) + 48));
|
|
for (int i5 = 0; i5 < 10; i5++) {
|
|
i += iArr[i5];
|
|
}
|
|
}
|
|
}
|
|
|
|
private int[] decodeStart(BitArray bitArray) throws NotFoundException {
|
|
int[] findGuardPattern = findGuardPattern(bitArray, skipWhiteSpace(bitArray), START_PATTERN);
|
|
int i = findGuardPattern[1];
|
|
int i2 = findGuardPattern[0];
|
|
this.narrowLineWidth = (i - i2) / 4;
|
|
validateQuietZone(bitArray, i2);
|
|
return findGuardPattern;
|
|
}
|
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:9:0x001b, code lost:
|
|
|
|
return;
|
|
*/
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private void validateQuietZone(com.google.zxing.common.BitArray r2, int r3) throws com.google.zxing.NotFoundException {
|
|
/*
|
|
r1 = this;
|
|
int r1 = r1.narrowLineWidth
|
|
int r1 = r1 * 10
|
|
int r1 = java.lang.Math.min(r1, r3)
|
|
int r3 = r3 + (-1)
|
|
La:
|
|
if (r1 <= 0) goto L19
|
|
if (r3 < 0) goto L19
|
|
boolean r0 = r2.get(r3)
|
|
if (r0 != 0) goto L19
|
|
int r1 = r1 + (-1)
|
|
int r3 = r3 + (-1)
|
|
goto La
|
|
L19:
|
|
if (r1 != 0) goto L1c
|
|
return
|
|
L1c:
|
|
com.google.zxing.NotFoundException r1 = com.google.zxing.NotFoundException.getNotFoundInstance()
|
|
throw r1
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.oned.ITFReader.validateQuietZone(com.google.zxing.common.BitArray, int):void");
|
|
}
|
|
|
|
private static int skipWhiteSpace(BitArray bitArray) throws NotFoundException {
|
|
int size = bitArray.getSize();
|
|
int nextSet = bitArray.getNextSet(0);
|
|
if (nextSet != size) {
|
|
return nextSet;
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
|
|
private int[] decodeEnd(BitArray bitArray) throws NotFoundException {
|
|
int[] findGuardPattern;
|
|
bitArray.reverse();
|
|
try {
|
|
int skipWhiteSpace = skipWhiteSpace(bitArray);
|
|
try {
|
|
findGuardPattern = findGuardPattern(bitArray, skipWhiteSpace, END_PATTERN_REVERSED[0]);
|
|
} catch (NotFoundException unused) {
|
|
findGuardPattern = findGuardPattern(bitArray, skipWhiteSpace, END_PATTERN_REVERSED[1]);
|
|
}
|
|
validateQuietZone(bitArray, findGuardPattern[0]);
|
|
int i = findGuardPattern[0];
|
|
findGuardPattern[0] = bitArray.getSize() - findGuardPattern[1];
|
|
findGuardPattern[1] = bitArray.getSize() - i;
|
|
return findGuardPattern;
|
|
} finally {
|
|
bitArray.reverse();
|
|
}
|
|
}
|
|
|
|
private static int[] findGuardPattern(BitArray bitArray, int i, int[] iArr) throws NotFoundException {
|
|
int length = iArr.length;
|
|
int[] iArr2 = new int[length];
|
|
int size = bitArray.getSize();
|
|
int i2 = i;
|
|
boolean z = false;
|
|
int i3 = 0;
|
|
while (i < size) {
|
|
if (bitArray.get(i) != z) {
|
|
iArr2[i3] = iArr2[i3] + 1;
|
|
} else {
|
|
if (i3 != length - 1) {
|
|
i3++;
|
|
} else {
|
|
if (patternMatchVariance(iArr2, iArr, 0.5f) < 0.38f) {
|
|
return new int[]{i2, i};
|
|
}
|
|
i2 += iArr2[0] + iArr2[1];
|
|
int i4 = i3 - 1;
|
|
System.arraycopy(iArr2, 2, iArr2, 0, i4);
|
|
iArr2[i4] = 0;
|
|
iArr2[i3] = 0;
|
|
i3--;
|
|
}
|
|
iArr2[i3] = 1;
|
|
z = !z;
|
|
}
|
|
i++;
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
|
|
private static int decodeDigit(int[] iArr) throws NotFoundException {
|
|
int length = PATTERNS.length;
|
|
float f = 0.38f;
|
|
int i = -1;
|
|
for (int i2 = 0; i2 < length; i2++) {
|
|
float patternMatchVariance = patternMatchVariance(iArr, PATTERNS[i2], 0.5f);
|
|
if (patternMatchVariance < f) {
|
|
i = i2;
|
|
f = patternMatchVariance;
|
|
} else if (patternMatchVariance == f) {
|
|
i = -1;
|
|
}
|
|
}
|
|
if (i >= 0) {
|
|
return i % 10;
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
}
|