253 lines
8.8 KiB
Java
253 lines
8.8 KiB
Java
package com.google.zxing.oned;
|
|
|
|
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 com.ubt.jimu.diy.DiyRobotFile;
|
|
import java.util.Arrays;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Code39Reader extends OneDReader {
|
|
static final int[] e = {52, 289, 97, 352, 49, 304, 112, 37, 292, 100, 265, 73, 328, 25, 280, 88, 13, 268, 76, 28, DiyRobotFile.TYPE_LOGO, 67, 322, 19, 274, 82, 7, 262, 70, 22, 385, 193, 448, 145, 400, 208, 133, 388, 196, 168, 162, 138, 42};
|
|
private final boolean a;
|
|
private final boolean b;
|
|
private final StringBuilder c;
|
|
private final int[] d;
|
|
|
|
public Code39Reader() {
|
|
this(false);
|
|
}
|
|
|
|
@Override // com.google.zxing.oned.OneDReader
|
|
public Result a(int i, BitArray bitArray, Map<DecodeHintType, ?> map) throws NotFoundException, ChecksumException, FormatException {
|
|
int[] iArr = this.d;
|
|
Arrays.fill(iArr, 0);
|
|
StringBuilder sb = this.c;
|
|
sb.setLength(0);
|
|
int b = bitArray.b(a(bitArray, iArr)[1]);
|
|
int h = bitArray.h();
|
|
while (true) {
|
|
OneDReader.a(bitArray, b, iArr);
|
|
int a = a(iArr);
|
|
if (a < 0) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
char a2 = a(a);
|
|
sb.append(a2);
|
|
int i2 = b;
|
|
for (int i3 : iArr) {
|
|
i2 += i3;
|
|
}
|
|
int b2 = bitArray.b(i2);
|
|
if (a2 == '*') {
|
|
sb.setLength(sb.length() - 1);
|
|
int i4 = 0;
|
|
for (int i5 : iArr) {
|
|
i4 += i5;
|
|
}
|
|
int i6 = (b2 - b) - i4;
|
|
if (b2 != h && (i6 << 1) < i4) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
if (this.a) {
|
|
int length = sb.length() - 1;
|
|
int i7 = 0;
|
|
for (int i8 = 0; i8 < length; i8++) {
|
|
i7 += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".indexOf(this.c.charAt(i8));
|
|
}
|
|
if (sb.charAt(length) != "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".charAt(i7 % 43)) {
|
|
throw ChecksumException.getChecksumInstance();
|
|
}
|
|
sb.setLength(length);
|
|
}
|
|
if (sb.length() == 0) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
float f = i;
|
|
return new Result(this.b ? a(sb) : sb.toString(), null, new ResultPoint[]{new ResultPoint((r2[1] + r2[0]) / 2.0f, f), new ResultPoint(b + (i4 / 2.0f), f)}, BarcodeFormat.CODE_39);
|
|
}
|
|
b = b2;
|
|
}
|
|
}
|
|
|
|
public Code39Reader(boolean z) {
|
|
this(z, false);
|
|
}
|
|
|
|
public Code39Reader(boolean z, boolean z2) {
|
|
this.a = z;
|
|
this.b = z2;
|
|
this.c = new StringBuilder(20);
|
|
this.d = new int[9];
|
|
}
|
|
|
|
private static int[] a(BitArray bitArray, int[] iArr) throws NotFoundException {
|
|
int h = bitArray.h();
|
|
int b = bitArray.b(0);
|
|
int length = iArr.length;
|
|
int i = b;
|
|
boolean z = false;
|
|
int i2 = 0;
|
|
while (b < h) {
|
|
if (bitArray.a(b) != z) {
|
|
iArr[i2] = iArr[i2] + 1;
|
|
} else {
|
|
if (i2 != length - 1) {
|
|
i2++;
|
|
} else {
|
|
if (a(iArr) == 148 && bitArray.a(Math.max(0, i - ((b - i) / 2)), i, false)) {
|
|
return new int[]{i, b};
|
|
}
|
|
i += iArr[0] + iArr[1];
|
|
int i3 = i2 - 1;
|
|
System.arraycopy(iArr, 2, iArr, 0, i3);
|
|
iArr[i3] = 0;
|
|
iArr[i2] = 0;
|
|
i2--;
|
|
}
|
|
iArr[i2] = 1;
|
|
z = !z;
|
|
}
|
|
b++;
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
|
|
private static int a(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 a(int i) throws NotFoundException {
|
|
int i2 = 0;
|
|
while (true) {
|
|
int[] iArr = e;
|
|
if (i2 >= iArr.length) {
|
|
if (i == 148) {
|
|
return '*';
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
if (iArr[i2] == i) {
|
|
return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".charAt(i2);
|
|
}
|
|
i2++;
|
|
}
|
|
}
|
|
|
|
private static String a(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 != '/') {
|
|
sb.append(charAt);
|
|
} else {
|
|
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 = 127;
|
|
}
|
|
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);
|
|
}
|
|
i2++;
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|