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: classes.dex */ public final class ITFReader extends OneDReader { private static final int[] b = {6, 8, 10, 12, 14}; private static final int[] c = {1, 1, 1, 1}; private static final int[][] d = {new int[]{1, 1, 2}, new int[]{1, 1, 3}}; private static final int[][] e = {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}}; private int a = -1; private int[] b(BitArray bitArray) throws NotFoundException { int[] c2 = c(bitArray, c(bitArray), c); this.a = (c2[1] - c2[0]) / 4; a(bitArray, c2[0]); return c2; } private static int c(BitArray bitArray) throws NotFoundException { int h = bitArray.h(); int b2 = bitArray.b(0); if (b2 != h) { return b2; } throw NotFoundException.getNotFoundInstance(); } @Override // com.google.zxing.oned.OneDReader public Result a(int i, BitArray bitArray, Map map) throws FormatException, NotFoundException { boolean z; int[] b2 = b(bitArray); int[] a = a(bitArray); StringBuilder sb = new StringBuilder(20); a(bitArray, b2[1], a[0], sb); String sb2 = sb.toString(); int[] iArr = map != null ? (int[]) map.get(DecodeHintType.ALLOWED_LENGTHS) : null; if (iArr == null) { iArr = b; } 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 = true; } if (!z) { throw FormatException.getFormatInstance(); } float f = i; return new Result(sb2, null, new ResultPoint[]{new ResultPoint(b2[1], f), new ResultPoint(a[0], f)}, BarcodeFormat.ITF); } private static int[] c(BitArray bitArray, int i, int[] iArr) throws NotFoundException { int length = iArr.length; int[] iArr2 = new int[length]; int h = bitArray.h(); int i2 = i; boolean z = false; int i3 = 0; while (i < h) { if (bitArray.a(i) != z) { iArr2[i3] = iArr2[i3] + 1; } else { if (i3 != length - 1) { i3++; } else { if (OneDReader.a(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 void a(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) { OneDReader.a(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) (a(iArr2) + 48)); sb.append((char) (a(iArr3) + 48)); for (int i5 = 0; i5 < 10; i5++) { i += iArr[i5]; } } } /* JADX WARN: Code restructure failed: missing block: B:12:0x001b, code lost: return; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private void a(com.google.zxing.common.BitArray r3, int r4) throws com.google.zxing.NotFoundException { /* r2 = this; int r0 = r2.a int r0 = r0 * 10 if (r0 >= r4) goto L7 goto L8 L7: r0 = r4 L8: int r4 = r4 + (-1) La: if (r0 <= 0) goto L19 if (r4 < 0) goto L19 boolean r1 = r3.a(r4) if (r1 != 0) goto L19 int r0 = r0 + (-1) int r4 = r4 + (-1) goto La L19: if (r0 != 0) goto L1c return L1c: com.google.zxing.NotFoundException r3 = com.google.zxing.NotFoundException.getNotFoundInstance() throw r3 */ throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.oned.ITFReader.a(com.google.zxing.common.BitArray, int):void"); } private int[] a(BitArray bitArray) throws NotFoundException { int[] c2; bitArray.j(); try { int c3 = c(bitArray); try { c2 = c(bitArray, c3, d[0]); } catch (NotFoundException unused) { c2 = c(bitArray, c3, d[1]); } a(bitArray, c2[0]); int i = c2[0]; c2[0] = bitArray.h() - c2[1]; c2[1] = bitArray.h() - i; return c2; } finally { bitArray.j(); } } private static int a(int[] iArr) throws NotFoundException { int length = e.length; int i = -1; float f = 0.38f; for (int i2 = 0; i2 < length; i2++) { float a = OneDReader.a(iArr, e[i2], 0.5f); if (a < f) { i = i2; f = a; } else if (a == f) { i = -1; } } if (i >= 0) { return i % 10; } throw NotFoundException.getNotFoundInstance(); } }