package com.google.zxing.pdf417.decoder; import com.google.zxing.ChecksumException; import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.detector.MathUtils; import com.google.zxing.pdf417.PDF417Common; import com.google.zxing.pdf417.decoder.ec.ErrorCorrection; import java.lang.reflect.Array; import java.util.ArrayList; /* loaded from: classes.dex */ public final class PDF417ScanningDecoder { private static final ErrorCorrection a = new ErrorCorrection(); public static DecoderResult a(BitMatrix bitMatrix, ResultPoint resultPoint, ResultPoint resultPoint2, ResultPoint resultPoint3, ResultPoint resultPoint4, int i, int i2) throws NotFoundException, FormatException, ChecksumException { DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn; int i3; int i4; int i5; DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn2 = null; DetectionResult detectionResult = null; DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn3 = null; BoundingBox boundingBox = new BoundingBox(bitMatrix, resultPoint, resultPoint2, resultPoint3, resultPoint4); int i6 = 0; while (i6 < 2) { if (resultPoint != null) { detectionResultRowIndicatorColumn2 = a(bitMatrix, boundingBox, resultPoint, true, i, i2); } detectionResultRowIndicatorColumn = detectionResultRowIndicatorColumn2; if (resultPoint3 != null) { detectionResultRowIndicatorColumn3 = a(bitMatrix, boundingBox, resultPoint3, false, i, i2); } detectionResult = b(detectionResultRowIndicatorColumn, detectionResultRowIndicatorColumn3); if (detectionResult == null) { throw NotFoundException.getNotFoundInstance(); } if (i6 != 0 || detectionResult.d() == null || (detectionResult.d().f() >= boundingBox.f() && detectionResult.d().d() <= boundingBox.d())) { detectionResult.a(boundingBox); break; } boundingBox = detectionResult.d(); i6++; detectionResultRowIndicatorColumn2 = detectionResultRowIndicatorColumn; } detectionResultRowIndicatorColumn = detectionResultRowIndicatorColumn2; int a2 = detectionResult.a() + 1; detectionResult.a(0, detectionResultRowIndicatorColumn); detectionResult.a(a2, detectionResultRowIndicatorColumn3); boolean z = detectionResultRowIndicatorColumn != null; int i7 = i; int i8 = i2; for (int i9 = 1; i9 <= a2; i9++) { int i10 = z ? i9 : a2 - i9; if (detectionResult.a(i10) == null) { DetectionResultColumn detectionResultRowIndicatorColumn4 = (i10 == 0 || i10 == a2) ? new DetectionResultRowIndicatorColumn(boundingBox, i10 == 0) : new DetectionResultColumn(boundingBox); detectionResult.a(i10, detectionResultRowIndicatorColumn4); int i11 = -1; int i12 = i8; int i13 = -1; int i14 = i7; int f = boundingBox.f(); while (f <= boundingBox.d()) { int a3 = a(detectionResult, i10, f, z); if (a3 >= 0 && a3 <= boundingBox.c()) { i5 = a3; } else if (i13 != i11) { i5 = i13; } else { i3 = i13; i4 = i12; i12 = i4; i13 = i3; f++; i11 = -1; } i3 = i13; int i15 = i12; Codeword a4 = a(bitMatrix, boundingBox.e(), boundingBox.c(), z, i5, f, i14, i15); if (a4 != null) { detectionResultRowIndicatorColumn4.a(f, a4); i14 = Math.min(i14, a4.f()); i12 = Math.max(i15, a4.f()); i13 = i5; f++; i11 = -1; } else { i4 = i15; i12 = i4; i13 = i3; f++; i11 = -1; } } i7 = i14; i8 = i12; } } return b(detectionResult); } private static boolean a(int i, int i2, int i3) { return i2 + (-2) <= i && i <= i3 + 2; } private static DetectionResult b(DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn, DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn2) throws NotFoundException { BarcodeMetadata a2; if ((detectionResultRowIndicatorColumn == null && detectionResultRowIndicatorColumn2 == null) || (a2 = a(detectionResultRowIndicatorColumn, detectionResultRowIndicatorColumn2)) == null) { return null; } return new DetectionResult(a2, BoundingBox.a(a(detectionResultRowIndicatorColumn), a(detectionResultRowIndicatorColumn2))); } private static int c(int i) { return 2 << i; } private static int b(int[] iArr) { int i = -1; for (int i2 : iArr) { i = Math.max(i, i2); } return i; } private static DecoderResult b(DetectionResult detectionResult) throws FormatException, ChecksumException, NotFoundException { BarcodeValue[][] a2 = a(detectionResult); a(detectionResult, a2); ArrayList arrayList = new ArrayList(); int[] iArr = new int[detectionResult.c() * detectionResult.a()]; ArrayList arrayList2 = new ArrayList(); ArrayList arrayList3 = new ArrayList(); for (int i = 0; i < detectionResult.c(); i++) { int i2 = 0; while (i2 < detectionResult.a()) { int i3 = i2 + 1; int[] a3 = a2[i][i3].a(); int a4 = (detectionResult.a() * i) + i2; if (a3.length == 0) { arrayList.add(Integer.valueOf(a4)); } else if (a3.length == 1) { iArr[a4] = a3[0]; } else { arrayList3.add(Integer.valueOf(a4)); arrayList2.add(a3); } i2 = i3; } } int[][] iArr2 = new int[arrayList2.size()][]; for (int i4 = 0; i4 < iArr2.length; i4++) { iArr2[i4] = (int[]) arrayList2.get(i4); } return a(detectionResult.b(), iArr, PDF417Common.a(arrayList), PDF417Common.a(arrayList3), iArr2); } private static BoundingBox a(DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn) throws NotFoundException { int[] d; if (detectionResultRowIndicatorColumn == null || (d = detectionResultRowIndicatorColumn.d()) == null) { return null; } int b = b(d); int i = 0; int i2 = 0; for (int i3 : d) { i2 += b - i3; if (i3 > 0) { break; } } Codeword[] b2 = detectionResultRowIndicatorColumn.b(); for (int i4 = 0; i2 > 0 && b2[i4] == null; i4++) { i2--; } for (int length = d.length - 1; length >= 0; length--) { i += b - d[length]; if (d[length] > 0) { break; } } for (int length2 = b2.length - 1; i > 0 && b2[length2] == null; length2--) { i--; } return detectionResultRowIndicatorColumn.a().a(i2, i, detectionResultRowIndicatorColumn.e()); } /* JADX WARN: Removed duplicated region for block: B:17:0x0027 A[EDGE_INSN: B:17:0x0027->B:18:0x0027 BREAK A[LOOP:0: B:5:0x000c->B:13:0x000c], SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:8:0x0015 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private static int[] b(com.google.zxing.common.BitMatrix r7, int r8, int r9, boolean r10, int r11, int r12) { /* r0 = 8 int[] r1 = new int[r0] r2 = 1 if (r10 == 0) goto L9 r3 = 1 goto La L9: r3 = -1 La: r4 = 0 r5 = r10 Lc: if (r10 == 0) goto L11 if (r11 >= r9) goto L27 goto L13 L11: if (r11 < r8) goto L27 L13: if (r4 >= r0) goto L27 boolean r6 = r7.b(r11, r12) if (r6 != r5) goto L22 r6 = r1[r4] int r6 = r6 + r2 r1[r4] = r6 int r11 = r11 + r3 goto Lc L22: int r4 = r4 + 1 r5 = r5 ^ 1 goto Lc L27: if (r4 == r0) goto L34 if (r10 == 0) goto L2c r8 = r9 L2c: if (r11 != r8) goto L32 r7 = 7 if (r4 != r7) goto L32 goto L34 L32: r7 = 0 return r7 L34: return r1 */ throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.pdf417.decoder.PDF417ScanningDecoder.b(com.google.zxing.common.BitMatrix, int, int, boolean, int, int):int[]"); } private static int b(int i) { return a(a(i)); } private static BarcodeMetadata a(DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn, DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn2) { BarcodeMetadata c; BarcodeMetadata c2; if (detectionResultRowIndicatorColumn == null || (c = detectionResultRowIndicatorColumn.c()) == null) { if (detectionResultRowIndicatorColumn2 == null) { return null; } return detectionResultRowIndicatorColumn2.c(); } if (detectionResultRowIndicatorColumn2 == null || (c2 = detectionResultRowIndicatorColumn2.c()) == null || c.a() == c2.a() || c.b() == c2.b() || c.c() == c2.c()) { return c; } return null; } private static DetectionResultRowIndicatorColumn a(BitMatrix bitMatrix, BoundingBox boundingBox, ResultPoint resultPoint, boolean z, int i, int i2) { DetectionResultRowIndicatorColumn detectionResultRowIndicatorColumn = new DetectionResultRowIndicatorColumn(boundingBox, z); int i3 = 0; while (i3 < 2) { int i4 = i3 == 0 ? 1 : -1; int a2 = (int) resultPoint.a(); for (int b = (int) resultPoint.b(); b <= boundingBox.d() && b >= boundingBox.f(); b += i4) { Codeword a3 = a(bitMatrix, 0, bitMatrix.k(), z, a2, b, i, i2); if (a3 != null) { detectionResultRowIndicatorColumn.a(b, a3); if (z) { a2 = a3.d(); } else { a2 = a3.b(); } } } i3++; } return detectionResultRowIndicatorColumn; } private static void a(DetectionResult detectionResult, BarcodeValue[][] barcodeValueArr) throws NotFoundException { BarcodeValue barcodeValue = barcodeValueArr[0][1]; int[] a2 = barcodeValue.a(); int a3 = (detectionResult.a() * detectionResult.c()) - c(detectionResult.b()); if (a2.length != 0) { if (a2[0] != a3) { barcodeValue.a(a3); } } else { if (a3 > 0 && a3 <= 928) { barcodeValue.a(a3); return; } throw NotFoundException.getNotFoundInstance(); } } private static DecoderResult a(int i, int[] iArr, int[] iArr2, int[] iArr3, int[][] iArr4) throws FormatException, ChecksumException { int[] iArr5 = new int[iArr3.length]; int i2 = 100; while (true) { int i3 = i2 - 1; if (i2 > 0) { for (int i4 = 0; i4 < iArr5.length; i4++) { iArr[iArr3[i4]] = iArr4[i4][iArr5[i4]]; } try { return a(iArr, i, iArr2); } catch (ChecksumException unused) { if (iArr5.length == 0) { throw ChecksumException.getChecksumInstance(); } int i5 = 0; while (true) { if (i5 >= iArr5.length) { break; } if (iArr5[i5] < iArr4[i5].length - 1) { iArr5[i5] = iArr5[i5] + 1; break; } iArr5[i5] = 0; if (i5 == iArr5.length - 1) { throw ChecksumException.getChecksumInstance(); } i5++; } i2 = i3; } } else { throw ChecksumException.getChecksumInstance(); } } } private static BarcodeValue[][] a(DetectionResult detectionResult) { int c; BarcodeValue[][] barcodeValueArr = (BarcodeValue[][]) Array.newInstance((Class) BarcodeValue.class, detectionResult.c(), detectionResult.a() + 2); for (int i = 0; i < barcodeValueArr.length; i++) { for (int i2 = 0; i2 < barcodeValueArr[i].length; i2++) { barcodeValueArr[i][i2] = new BarcodeValue(); } } int i3 = 0; for (DetectionResultColumn detectionResultColumn : detectionResult.e()) { if (detectionResultColumn != null) { for (Codeword codeword : detectionResultColumn.b()) { if (codeword != null && (c = codeword.c()) >= 0 && c < barcodeValueArr.length) { barcodeValueArr[c][i3].a(codeword.e()); } } } i3++; } return barcodeValueArr; } private static boolean a(DetectionResult detectionResult, int i) { return i >= 0 && i <= detectionResult.a() + 1; } private static int a(DetectionResult detectionResult, int i, int i2, boolean z) { int i3 = z ? 1 : -1; int i4 = i - i3; Codeword a2 = a(detectionResult, i4) ? detectionResult.a(i4).a(i2) : null; if (a2 != null) { return z ? a2.b() : a2.d(); } Codeword b = detectionResult.a(i).b(i2); if (b != null) { return z ? b.d() : b.b(); } if (a(detectionResult, i4)) { b = detectionResult.a(i4).b(i2); } if (b != null) { return z ? b.b() : b.d(); } int i5 = 0; while (true) { i -= i3; if (a(detectionResult, i)) { for (Codeword codeword : detectionResult.a(i).b()) { if (codeword != null) { return (z ? codeword.b() : codeword.d()) + (i3 * i5 * (codeword.b() - codeword.d())); } } i5++; } else { BoundingBox d = detectionResult.d(); return z ? d.e() : d.c(); } } } private static Codeword a(BitMatrix bitMatrix, int i, int i2, boolean z, int i3, int i4, int i5, int i6) { int i7; int d; int a2; int a3 = a(bitMatrix, i, i2, z, i3, i4); int[] b = b(bitMatrix, i, i2, z, a3, i4); if (b == null) { return null; } int a4 = MathUtils.a(b); if (z) { a3 += a4; i7 = a3; } else { for (int i8 = 0; i8 < b.length / 2; i8++) { int i9 = b[i8]; b[i8] = b[(b.length - 1) - i8]; b[(b.length - 1) - i8] = i9; } i7 = a3 - a4; } if (a(a4, i5, i6) && (a2 = PDF417Common.a((d = PDF417CodewordDecoder.d(b)))) != -1) { return new Codeword(i7, a3, b(d), a2); } return null; } /* JADX WARN: Code restructure failed: missing block: B:16:0x0023, code lost: continue; */ /* JADX WARN: Code restructure failed: missing block: B:17:0x0023, code lost: r0 = -r0; r2 = !r2; r1 = r1 + 1; */ /* JADX WARN: Code restructure failed: missing block: B:18:0x0023, code lost: continue; */ /* JADX WARN: Code restructure failed: missing block: B:20:0x0023, code lost: continue; */ /* JADX WARN: Removed duplicated region for block: B:10:0x0018 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private static int a(com.google.zxing.common.BitMatrix r5, int r6, int r7, boolean r8, int r9, int r10) { /* if (r8 == 0) goto L4 r0 = -1 goto L5 L4: r0 = 1 L5: r1 = 0 r2 = r8 r8 = r9 L8: r3 = 2 if (r1 >= r3) goto L29 Lb: if (r2 == 0) goto L10 if (r8 < r6) goto L23 goto L12 L10: if (r8 >= r7) goto L23 L12: boolean r4 = r5.b(r8, r10) if (r2 != r4) goto L23 int r4 = r9 - r8 int r4 = java.lang.Math.abs(r4) if (r4 <= r3) goto L21 return r9 L21: int r8 = r8 + r0 goto Lb L23: int r0 = -r0 r2 = r2 ^ 1 int r1 = r1 + 1 goto L8 L29: return r8 */ throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.pdf417.decoder.PDF417ScanningDecoder.a(com.google.zxing.common.BitMatrix, int, int, boolean, int, int):int"); } private static DecoderResult a(int[] iArr, int i, int[] iArr2) throws FormatException, ChecksumException { if (iArr.length != 0) { int i2 = 1 << (i + 1); int a2 = a(iArr, iArr2, i2); a(iArr, i2); DecoderResult a3 = DecodedBitStreamParser.a(iArr, String.valueOf(i)); a3.b(Integer.valueOf(a2)); a3.a(Integer.valueOf(iArr2.length)); return a3; } throw FormatException.getFormatInstance(); } private static int a(int[] iArr, int[] iArr2, int i) throws ChecksumException { if ((iArr2 == null || iArr2.length <= (i / 2) + 3) && i >= 0 && i <= 512) { return a.a(iArr, i, iArr2); } throw ChecksumException.getChecksumInstance(); } private static void a(int[] iArr, int i) throws FormatException { if (iArr.length >= 4) { int i2 = iArr[0]; if (i2 > iArr.length) { throw FormatException.getFormatInstance(); } if (i2 == 0) { if (i < iArr.length) { iArr[0] = iArr.length - i; return; } throw FormatException.getFormatInstance(); } return; } throw FormatException.getFormatInstance(); } private static int[] a(int i) { int[] iArr = new int[8]; int i2 = 0; int i3 = 7; while (true) { int i4 = i & 1; if (i4 != i2) { i3--; if (i3 < 0) { return iArr; } i2 = i4; } iArr[i3] = iArr[i3] + 1; i >>= 1; } } private static int a(int[] iArr) { return ((((iArr[0] - iArr[2]) + iArr[4]) - iArr[6]) + 9) % 9; } }