mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 01:22:33 -06:00
261 lines
9.6 KiB
Java
261 lines
9.6 KiB
Java
|
package com.google.zxing.oned;
|
||
|
|
||
|
import com.google.common.base.Ascii;
|
||
|
import com.google.zxing.BarcodeFormat;
|
||
|
import com.google.zxing.ChecksumException;
|
||
|
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.Arrays;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/* loaded from: classes3.dex */
|
||
|
public final class Code39Reader extends OneDReader {
|
||
|
static final String ALPHABET_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
|
||
|
static final int ASTERISK_ENCODING = 148;
|
||
|
static final int[] CHARACTER_ENCODINGS = {52, 289, 97, 352, 49, 304, 112, 37, 292, 100, 265, 73, 328, 25, 280, 88, 13, 268, 76, 28, 259, 67, 322, 19, 274, 82, 7, 262, 70, 22, 385, 193, 448, 145, 400, 208, 133, 388, 196, 168, 162, 138, 42};
|
||
|
private final int[] counters;
|
||
|
private final StringBuilder decodeRowResult;
|
||
|
private final boolean extendedMode;
|
||
|
private final boolean usingCheckDigit;
|
||
|
|
||
|
public Code39Reader() {
|
||
|
this(false);
|
||
|
}
|
||
|
|
||
|
public Code39Reader(boolean z) {
|
||
|
this(z, false);
|
||
|
}
|
||
|
|
||
|
public Code39Reader(boolean z, boolean z2) {
|
||
|
this.usingCheckDigit = z;
|
||
|
this.extendedMode = z2;
|
||
|
this.decodeRowResult = new StringBuilder(20);
|
||
|
this.counters = new int[9];
|
||
|
}
|
||
|
|
||
|
@Override // com.google.zxing.oned.OneDReader
|
||
|
public Result decodeRow(int i, BitArray bitArray, Map<DecodeHintType, ?> map) throws NotFoundException, ChecksumException, FormatException {
|
||
|
String sb;
|
||
|
int[] iArr = this.counters;
|
||
|
Arrays.fill(iArr, 0);
|
||
|
StringBuilder sb2 = this.decodeRowResult;
|
||
|
sb2.setLength(0);
|
||
|
int nextSet = bitArray.getNextSet(findAsteriskPattern(bitArray, iArr)[1]);
|
||
|
int size = bitArray.getSize();
|
||
|
while (true) {
|
||
|
recordPattern(bitArray, nextSet, iArr);
|
||
|
int narrowWidePattern = toNarrowWidePattern(iArr);
|
||
|
if (narrowWidePattern < 0) {
|
||
|
throw NotFoundException.getNotFoundInstance();
|
||
|
}
|
||
|
char patternToChar = patternToChar(narrowWidePattern);
|
||
|
sb2.append(patternToChar);
|
||
|
int i2 = nextSet;
|
||
|
for (int i3 : iArr) {
|
||
|
i2 += i3;
|
||
|
}
|
||
|
int nextSet2 = bitArray.getNextSet(i2);
|
||
|
if (patternToChar == '*') {
|
||
|
sb2.setLength(sb2.length() - 1);
|
||
|
int i4 = 0;
|
||
|
for (int i5 : iArr) {
|
||
|
i4 += i5;
|
||
|
}
|
||
|
int i6 = (nextSet2 - nextSet) - i4;
|
||
|
if (nextSet2 != size && (i6 << 1) < i4) {
|
||
|
throw NotFoundException.getNotFoundInstance();
|
||
|
}
|
||
|
if (this.usingCheckDigit) {
|
||
|
int length = sb2.length() - 1;
|
||
|
int i7 = 0;
|
||
|
for (int i8 = 0; i8 < length; i8++) {
|
||
|
i7 += ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(i8));
|
||
|
}
|
||
|
if (sb2.charAt(length) != ALPHABET_STRING.charAt(i7 % 43)) {
|
||
|
throw ChecksumException.getChecksumInstance();
|
||
|
}
|
||
|
sb2.setLength(length);
|
||
|
}
|
||
|
if (sb2.length() == 0) {
|
||
|
throw NotFoundException.getNotFoundInstance();
|
||
|
}
|
||
|
if (this.extendedMode) {
|
||
|
sb = decodeExtended(sb2);
|
||
|
} else {
|
||
|
sb = sb2.toString();
|
||
|
}
|
||
|
float f = i;
|
||
|
return new Result(sb, null, new ResultPoint[]{new ResultPoint((r2[1] + r2[0]) / 2.0f, f), new ResultPoint(nextSet + (i4 / 2.0f), f)}, BarcodeFormat.CODE_39);
|
||
|
}
|
||
|
nextSet = nextSet2;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static int[] findAsteriskPattern(BitArray bitArray, int[] iArr) throws NotFoundException {
|
||
|
int size = bitArray.getSize();
|
||
|
int nextSet = bitArray.getNextSet(0);
|
||
|
int length = iArr.length;
|
||
|
boolean z = false;
|
||
|
int i = 0;
|
||
|
int i2 = nextSet;
|
||
|
while (nextSet < size) {
|
||
|
if (bitArray.get(nextSet) != z) {
|
||
|
iArr[i] = iArr[i] + 1;
|
||
|
} else {
|
||
|
if (i != length - 1) {
|
||
|
i++;
|
||
|
} else {
|
||
|
if (toNarrowWidePattern(iArr) == ASTERISK_ENCODING && bitArray.isRange(Math.max(0, i2 - ((nextSet - i2) / 2)), i2, false)) {
|
||
|
return new int[]{i2, nextSet};
|
||
|
}
|
||
|
i2 += iArr[0] + iArr[1];
|
||
|
int i3 = i - 1;
|
||
|
System.arraycopy(iArr, 2, iArr, 0, i3);
|
||
|
iArr[i3] = 0;
|
||
|
iArr[i] = 0;
|
||
|
i--;
|
||
|
}
|
||
|
iArr[i] = 1;
|
||
|
z = !z;
|
||
|
}
|
||
|
nextSet++;
|
||
|
}
|
||
|
throw NotFoundException.getNotFoundInstance();
|
||
|
}
|
||
|
|
||
|
private static int toNarrowWidePattern(int[] iArr) {
|
||
|
int length = iArr.length;
|
||
|
int i = 0;
|
||
|
while (true) {
|
||
|
int i2 = Integer.MAX_VALUE;
|
||
|
for (int i3 : iArr) {
|
||
|
if (i3 < i2 && i3 > i) {
|
||
|
i2 = i3;
|
||
|
}
|
||
|
}
|
||
|
int i4 = 0;
|
||
|
int i5 = 0;
|
||
|
int i6 = 0;
|
||
|
for (int i7 = 0; i7 < length; i7++) {
|
||
|
int i8 = iArr[i7];
|
||
|
if (i8 > i2) {
|
||
|
i5 |= 1 << ((length - 1) - i7);
|
||
|
i4++;
|
||
|
i6 += i8;
|
||
|
}
|
||
|
}
|
||
|
if (i4 == 3) {
|
||
|
for (int i9 = 0; i9 < length && i4 > 0; i9++) {
|
||
|
int i10 = iArr[i9];
|
||
|
if (i10 > i2) {
|
||
|
i4--;
|
||
|
if ((i10 << 1) >= i6) {
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return i5;
|
||
|
}
|
||
|
if (i4 <= 3) {
|
||
|
return -1;
|
||
|
}
|
||
|
i = i2;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static char patternToChar(int i) throws NotFoundException {
|
||
|
int i2 = 0;
|
||
|
while (true) {
|
||
|
int[] iArr = CHARACTER_ENCODINGS;
|
||
|
if (i2 >= iArr.length) {
|
||
|
if (i == ASTERISK_ENCODING) {
|
||
|
return '*';
|
||
|
}
|
||
|
throw NotFoundException.getNotFoundInstance();
|
||
|
}
|
||
|
if (iArr[i2] == i) {
|
||
|
return ALPHABET_STRING.charAt(i2);
|
||
|
}
|
||
|
i2++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static String decodeExtended(CharSequence charSequence) throws FormatException {
|
||
|
int i;
|
||
|
char c;
|
||
|
int length = charSequence.length();
|
||
|
StringBuilder sb = new StringBuilder(length);
|
||
|
int i2 = 0;
|
||
|
while (i2 < length) {
|
||
|
char charAt = charSequence.charAt(i2);
|
||
|
if (charAt == '+' || charAt == '$' || charAt == '%' || charAt == '/') {
|
||
|
i2++;
|
||
|
char charAt2 = charSequence.charAt(i2);
|
||
|
if (charAt != '$') {
|
||
|
if (charAt != '%') {
|
||
|
if (charAt != '+') {
|
||
|
if (charAt == '/') {
|
||
|
if (charAt2 >= 'A' && charAt2 <= 'O') {
|
||
|
i = charAt2 - ' ';
|
||
|
} else {
|
||
|
if (charAt2 != 'Z') {
|
||
|
throw FormatException.getFormatInstance();
|
||
|
}
|
||
|
c = ':';
|
||
|
sb.append(c);
|
||
|
}
|
||
|
}
|
||
|
c = 0;
|
||
|
sb.append(c);
|
||
|
} else {
|
||
|
if (charAt2 < 'A' || charAt2 > 'Z') {
|
||
|
throw FormatException.getFormatInstance();
|
||
|
}
|
||
|
i = charAt2 + ' ';
|
||
|
}
|
||
|
} else if (charAt2 >= 'A' && charAt2 <= 'E') {
|
||
|
i = charAt2 - '&';
|
||
|
} else if (charAt2 >= 'F' && charAt2 <= 'J') {
|
||
|
i = charAt2 - 11;
|
||
|
} else if (charAt2 >= 'K' && charAt2 <= 'O') {
|
||
|
i = charAt2 + 16;
|
||
|
} else if (charAt2 < 'P' || charAt2 > 'T') {
|
||
|
if (charAt2 != 'U') {
|
||
|
if (charAt2 == 'V') {
|
||
|
c = '@';
|
||
|
} else if (charAt2 == 'W') {
|
||
|
c = '`';
|
||
|
} else {
|
||
|
if (charAt2 != 'X' && charAt2 != 'Y' && charAt2 != 'Z') {
|
||
|
throw FormatException.getFormatInstance();
|
||
|
}
|
||
|
c = Ascii.MAX;
|
||
|
}
|
||
|
sb.append(c);
|
||
|
}
|
||
|
c = 0;
|
||
|
sb.append(c);
|
||
|
} else {
|
||
|
i = charAt2 + '+';
|
||
|
}
|
||
|
} else {
|
||
|
if (charAt2 < 'A' || charAt2 > 'Z') {
|
||
|
throw FormatException.getFormatInstance();
|
||
|
}
|
||
|
i = charAt2 - '@';
|
||
|
}
|
||
|
c = (char) i;
|
||
|
sb.append(c);
|
||
|
} else {
|
||
|
sb.append(charAt);
|
||
|
}
|
||
|
i2++;
|
||
|
}
|
||
|
return sb.toString();
|
||
|
}
|
||
|
}
|