245 lines
8.4 KiB
Java
245 lines
8.4 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 java.util.Arrays;
|
|
import java.util.Map;
|
|
import okhttp3.internal.http.StatusLine;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Code93Reader extends OneDReader {
|
|
private static final char[] c = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd*".toCharArray();
|
|
static final int[] d;
|
|
private static final int e;
|
|
private final StringBuilder a = new StringBuilder(20);
|
|
private final int[] b = new int[6];
|
|
|
|
static {
|
|
int[] iArr = {276, 328, 324, 322, 296, 292, 290, 336, 274, 266, 424, 420, 418, 404, 402, 394, 360, 356, 354, StatusLine.HTTP_PERM_REDIRECT, 282, 344, 332, 326, 300, 278, 436, 434, 428, 422, 406, 410, 364, 358, 310, 314, 302, 468, 466, 458, 366, 374, 430, 294, 474, 470, 306, 350};
|
|
d = iArr;
|
|
e = iArr[47];
|
|
}
|
|
|
|
private static String b(CharSequence charSequence) throws FormatException {
|
|
int i;
|
|
char c2;
|
|
int length = charSequence.length();
|
|
StringBuilder sb = new StringBuilder(length);
|
|
int i2 = 0;
|
|
while (i2 < length) {
|
|
char charAt = charSequence.charAt(i2);
|
|
if (charAt < 'a' || charAt > 'd') {
|
|
sb.append(charAt);
|
|
} else {
|
|
if (i2 >= length - 1) {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
i2++;
|
|
char charAt2 = charSequence.charAt(i2);
|
|
switch (charAt) {
|
|
case 'a':
|
|
if (charAt2 >= 'A' && charAt2 <= 'Z') {
|
|
i = charAt2 - '@';
|
|
c2 = (char) i;
|
|
sb.append(c2);
|
|
break;
|
|
} else {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
break;
|
|
case 'b':
|
|
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 <= 'S') {
|
|
i = charAt2 + '+';
|
|
} else if (charAt2 >= 'T' && charAt2 <= 'Z') {
|
|
c2 = 127;
|
|
sb.append(c2);
|
|
break;
|
|
} else {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
c2 = (char) i;
|
|
sb.append(c2);
|
|
break;
|
|
case 'c':
|
|
if (charAt2 >= 'A' && charAt2 <= 'O') {
|
|
i = charAt2 - ' ';
|
|
c2 = (char) i;
|
|
sb.append(c2);
|
|
} else {
|
|
if (charAt2 != 'Z') {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
c2 = ':';
|
|
sb.append(c2);
|
|
break;
|
|
}
|
|
case 'd':
|
|
if (charAt2 >= 'A' && charAt2 <= 'Z') {
|
|
i = charAt2 + ' ';
|
|
c2 = (char) i;
|
|
sb.append(c2);
|
|
break;
|
|
} else {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
default:
|
|
c2 = 0;
|
|
sb.append(c2);
|
|
break;
|
|
}
|
|
}
|
|
i2++;
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
@Override // com.google.zxing.oned.OneDReader
|
|
public Result a(int i, BitArray bitArray, Map<DecodeHintType, ?> map) throws NotFoundException, ChecksumException, FormatException {
|
|
int b = bitArray.b(a(bitArray)[1]);
|
|
int h = bitArray.h();
|
|
int[] iArr = this.b;
|
|
Arrays.fill(iArr, 0);
|
|
StringBuilder sb = this.a;
|
|
sb.setLength(0);
|
|
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.deleteCharAt(sb.length() - 1);
|
|
int i4 = 0;
|
|
for (int i5 : iArr) {
|
|
i4 += i5;
|
|
}
|
|
if (b2 == h || !bitArray.a(b2)) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
if (sb.length() < 2) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
a(sb);
|
|
sb.setLength(sb.length() - 2);
|
|
float f = i;
|
|
return new Result(b(sb), null, new ResultPoint[]{new ResultPoint((r14[1] + r14[0]) / 2.0f, f), new ResultPoint(b + (i4 / 2.0f), f)}, BarcodeFormat.CODE_93);
|
|
}
|
|
b = b2;
|
|
}
|
|
}
|
|
|
|
private int[] a(BitArray bitArray) throws NotFoundException {
|
|
int h = bitArray.h();
|
|
int b = bitArray.b(0);
|
|
Arrays.fill(this.b, 0);
|
|
int[] iArr = this.b;
|
|
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) == e) {
|
|
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 i = 0;
|
|
for (int i2 : iArr) {
|
|
i += i2;
|
|
}
|
|
int length = iArr.length;
|
|
int i3 = 0;
|
|
for (int i4 = 0; i4 < length; i4++) {
|
|
int round = Math.round((iArr[i4] * 9.0f) / i);
|
|
if (round <= 0 || round > 4) {
|
|
return -1;
|
|
}
|
|
if ((i4 & 1) == 0) {
|
|
int i5 = i3;
|
|
for (int i6 = 0; i6 < round; i6++) {
|
|
i5 = (i5 << 1) | 1;
|
|
}
|
|
i3 = i5;
|
|
} else {
|
|
i3 <<= round;
|
|
}
|
|
}
|
|
return i3;
|
|
}
|
|
|
|
private static char a(int i) throws NotFoundException {
|
|
int i2 = 0;
|
|
while (true) {
|
|
int[] iArr = d;
|
|
if (i2 < iArr.length) {
|
|
if (iArr[i2] == i) {
|
|
return c[i2];
|
|
}
|
|
i2++;
|
|
} else {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void a(CharSequence charSequence) throws ChecksumException {
|
|
int length = charSequence.length();
|
|
a(charSequence, length - 2, 20);
|
|
a(charSequence, length - 1, 15);
|
|
}
|
|
|
|
private static void a(CharSequence charSequence, int i, int i2) throws ChecksumException {
|
|
int i3 = 0;
|
|
int i4 = 1;
|
|
for (int i5 = i - 1; i5 >= 0; i5--) {
|
|
i3 += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd*".indexOf(charSequence.charAt(i5)) * i4;
|
|
i4++;
|
|
if (i4 > i2) {
|
|
i4 = 1;
|
|
}
|
|
}
|
|
if (charSequence.charAt(i) != c[i3 % 47]) {
|
|
throw ChecksumException.getChecksumInstance();
|
|
}
|
|
}
|
|
}
|