package c.i.e.q; import c.i.e.d; import c.i.e.j; import c.i.e.k; import c.i.e.l; import c.i.e.n.a; import com.google.zxing.ChecksumException; import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.ReaderException; import com.google.zxing.Result; import java.util.Arrays; import java.util.Map; /* compiled from: UPCEANReader */ public abstract class p extends k { public static final int[] a = {1, 1, 1}; public static final int[] b = {1, 1, 1, 1, 1}; /* renamed from: c reason: collision with root package name */ public static final int[][] f1467c; public static final int[][] d; public final StringBuilder e = new StringBuilder(20); public final o f = new o(); public final g g = new g(); static { int[][] iArr = {new int[]{3, 2, 1, 1}, new int[]{2, 2, 2, 1}, new int[]{2, 1, 2, 2}, new int[]{1, 4, 1, 1}, new int[]{1, 1, 3, 2}, new int[]{1, 2, 3, 1}, new int[]{1, 1, 1, 4}, new int[]{1, 3, 1, 2}, new int[]{1, 2, 1, 3}, new int[]{3, 1, 1, 2}}; f1467c = iArr; int[][] iArr2 = new int[20][]; d = iArr2; System.arraycopy(iArr, 0, iArr2, 0, 10); for (int i = 10; i < 20; i++) { int[] iArr3 = f1467c[i - 10]; int[] iArr4 = new int[iArr3.length]; for (int i2 = 0; i2 < iArr3.length; i2++) { iArr4[i2] = iArr3[(iArr3.length - i2) - 1]; } d[i] = iArr4; } } public static int h(a aVar, int[] iArr, int i, int[][] iArr2) throws NotFoundException { k.e(aVar, i, iArr); int length = iArr2.length; float f = 0.48f; int i2 = -1; for (int i3 = 0; i3 < length; i3++) { float d2 = k.d(iArr, iArr2[i3], 0.7f); if (d2 < f) { i2 = i3; f = d2; } } if (i2 >= 0) { return i2; } throw NotFoundException.k; } public static int[] l(a aVar, int i, boolean z2, int[] iArr, int[] iArr2) throws NotFoundException { int i2 = aVar.j; int g = z2 ? aVar.g(i) : aVar.f(i); int length = iArr.length; boolean z3 = z2; int i3 = 0; int i4 = g; while (g < i2) { if (aVar.b(g) != z3) { iArr2[i3] = iArr2[i3] + 1; } else { if (i3 != length - 1) { i3++; } else if (k.d(iArr2, iArr, 0.7f) < 0.48f) { return new int[]{i4, g}; } else { i4 += iArr2[0] + iArr2[1]; int i5 = i3 - 1; System.arraycopy(iArr2, 2, iArr2, 0, i5); iArr2[i5] = 0; iArr2[i3] = 0; i3 = i5; } iArr2[i3] = 1; z3 = !z3; } g++; } throw NotFoundException.k; } public static int[] m(a aVar) throws NotFoundException { int[] iArr = new int[a.length]; int[] iArr2 = null; boolean z2 = false; int i = 0; while (!z2) { int[] iArr3 = a; Arrays.fill(iArr, 0, iArr3.length, 0); iArr2 = l(aVar, i, false, iArr3, iArr); int i2 = iArr2[0]; int i3 = iArr2[1]; int i4 = i2 - (i3 - i2); if (i4 >= 0) { z2 = aVar.h(i4, i2, false); } i = i3; } return iArr2; } @Override // c.i.e.q.k public Result b(int i, a aVar, Map map) throws NotFoundException, ChecksumException, FormatException { return k(i, aVar, m(aVar), map); } public boolean g(String str) throws FormatException { int length = str.length(); if (length == 0) { return false; } int i = length - 1; int digit = Character.digit(str.charAt(i), 10); CharSequence subSequence = str.subSequence(0, i); int length2 = subSequence.length(); int i2 = 0; for (int i3 = length2 - 1; i3 >= 0; i3 -= 2) { int charAt = subSequence.charAt(i3) - '0'; if (charAt < 0 || charAt > 9) { throw FormatException.a(); } i2 += charAt; } int i4 = i2 * 3; while (true) { length2 -= 2; if (length2 < 0) { return (1000 - i4) % 10 == digit; } int charAt2 = subSequence.charAt(length2) - '0'; if (charAt2 < 0 || charAt2 > 9) { break; } i4 += charAt2; } throw FormatException.a(); } public int[] i(a aVar, int i) throws NotFoundException { int[] iArr = a; return l(aVar, i, false, iArr, new int[iArr.length]); } public abstract int j(a aVar, int[] iArr, StringBuilder sb) throws NotFoundException; public Result k(int i, a aVar, int[] iArr, Map map) throws NotFoundException, ChecksumException, FormatException { int i2; boolean z2; String str = null; l lVar = map == null ? null : (l) map.get(d.NEED_RESULT_POINT_CALLBACK); if (lVar != null) { lVar.a(new k(((float) (iArr[0] + iArr[1])) / 2.0f, (float) i)); } StringBuilder sb = this.e; sb.setLength(0); int j = j(aVar, iArr, sb); if (lVar != null) { lVar.a(new k((float) j, (float) i)); } int[] i3 = i(aVar, j); if (lVar != null) { lVar.a(new k(((float) (i3[0] + i3[1])) / 2.0f, (float) i)); } int i4 = i3[1]; int i5 = (i4 - i3[0]) + i4; if (i5 >= aVar.j || !aVar.h(i4, i5, false)) { throw NotFoundException.k; } String sb2 = sb.toString(); if (sb2.length() < 8) { throw FormatException.a(); } else if (g(sb2)) { c.i.e.a n = n(); float f = (float) i; Result result = new Result(sb2, null, new k[]{new k(((float) (iArr[1] + iArr[0])) / 2.0f, f), new k(((float) (i3[1] + i3[0])) / 2.0f, f)}, n); try { Result a2 = this.f.a(i, aVar, i3[1]); result.b(j.UPC_EAN_EXTENSION, a2.a); result.a(a2.e); k[] kVarArr = a2.f2477c; k[] kVarArr2 = result.f2477c; if (kVarArr2 == null) { result.f2477c = kVarArr; } else if (kVarArr != null && kVarArr.length > 0) { k[] kVarArr3 = new k[(kVarArr2.length + kVarArr.length)]; System.arraycopy(kVarArr2, 0, kVarArr3, 0, kVarArr2.length); System.arraycopy(kVarArr, 0, kVarArr3, kVarArr2.length, kVarArr.length); result.f2477c = kVarArr3; } i2 = a2.a.length(); } catch (ReaderException unused) { i2 = 0; } int[] iArr2 = map == null ? null : (int[]) map.get(d.ALLOWED_EAN_EXTENSIONS); if (iArr2 != null) { int length = iArr2.length; int i6 = 0; while (true) { if (i6 >= length) { z2 = false; break; } else if (i2 == iArr2[i6]) { z2 = true; break; } else { i6++; } } if (!z2) { throw NotFoundException.k; } } if (n == c.i.e.a.EAN_13 || n == c.i.e.a.UPC_A) { g gVar = this.g; gVar.b(); int parseInt = Integer.parseInt(sb2.substring(0, 3)); int size = gVar.a.size(); int i7 = 0; while (true) { if (i7 < size) { int[] iArr3 = gVar.a.get(i7); int i8 = iArr3[0]; if (parseInt < i8) { break; } if (iArr3.length != 1) { i8 = iArr3[1]; } if (parseInt <= i8) { str = gVar.b.get(i7); break; } i7++; } else { break; } } if (str != null) { result.b(j.POSSIBLE_COUNTRY, str); } } return result; } else { throw ChecksumException.a(); } } public abstract c.i.e.a n(); }