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.ReaderException; import com.google.zxing.Result; import com.google.zxing.ResultMetadataType; import com.google.zxing.ResultPoint; import com.google.zxing.ResultPointCallback; import com.google.zxing.common.BitArray; import java.util.Arrays; import java.util.Map; /* loaded from: classes.dex */ public abstract class UPCEANReader extends OneDReader { static final int[] d = {1, 1, 1}; static final int[] e = {1, 1, 1, 1, 1}; static final int[] f = {1, 1, 1, 1, 1, 1}; static final int[][] g = {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}}; static final int[][] h = new int[20][]; private final StringBuilder a = new StringBuilder(20); private final UPCEANExtensionSupport b = new UPCEANExtensionSupport(); private final EANManufacturerOrgSupport c = new EANManufacturerOrgSupport(); static { System.arraycopy(g, 0, h, 0, 10); for (int i = 10; i < 20; i++) { int[] iArr = g[i - 10]; int[] iArr2 = new int[iArr.length]; for (int i2 = 0; i2 < iArr.length; i2++) { iArr2[i2] = iArr[(iArr.length - i2) - 1]; } h[i] = iArr2; } } protected UPCEANReader() { } static int[] a(BitArray bitArray) throws NotFoundException { int[] iArr = new int[d.length]; int[] iArr2 = null; boolean z = false; int i = 0; while (!z) { Arrays.fill(iArr, 0, d.length, 0); iArr2 = a(bitArray, i, false, d, iArr); int i2 = iArr2[0]; int i3 = iArr2[1]; int i4 = i2 - (i3 - i2); if (i4 >= 0) { z = bitArray.a(i4, i2, false); } i = i3; } return iArr2; } static int b(CharSequence charSequence) throws FormatException { int length = charSequence.length(); int i = 0; for (int i2 = length - 1; i2 >= 0; i2 -= 2) { int charAt = charSequence.charAt(i2) - '0'; if (charAt < 0 || charAt > 9) { throw FormatException.getFormatInstance(); } i += charAt; } int i3 = i * 3; for (int i4 = length - 2; i4 >= 0; i4 -= 2) { int charAt2 = charSequence.charAt(i4) - '0'; if (charAt2 < 0 || charAt2 > 9) { throw FormatException.getFormatInstance(); } i3 += charAt2; } return (1000 - i3) % 10; } protected abstract int a(BitArray bitArray, int[] iArr, StringBuilder sb) throws NotFoundException; abstract BarcodeFormat a(); @Override // com.google.zxing.oned.OneDReader public Result a(int i, BitArray bitArray, Map map) throws NotFoundException, ChecksumException, FormatException { return a(i, bitArray, a(bitArray), map); } public Result a(int i, BitArray bitArray, int[] iArr, Map map) throws NotFoundException, ChecksumException, FormatException { int i2; String a; ResultPointCallback resultPointCallback = map == null ? null : (ResultPointCallback) map.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); boolean z = true; if (resultPointCallback != null) { resultPointCallback.a(new ResultPoint((iArr[0] + iArr[1]) / 2.0f, i)); } StringBuilder sb = this.a; sb.setLength(0); int a2 = a(bitArray, iArr, sb); if (resultPointCallback != null) { resultPointCallback.a(new ResultPoint(a2, i)); } int[] a3 = a(bitArray, a2); if (resultPointCallback != null) { resultPointCallback.a(new ResultPoint((a3[0] + a3[1]) / 2.0f, i)); } int i3 = a3[1]; int i4 = (i3 - a3[0]) + i3; if (i4 < bitArray.h() && bitArray.a(i3, i4, false)) { String sb2 = sb.toString(); if (sb2.length() >= 8) { if (a(sb2)) { BarcodeFormat a4 = a(); float f2 = i; Result result = new Result(sb2, null, new ResultPoint[]{new ResultPoint((iArr[1] + iArr[0]) / 2.0f, f2), new ResultPoint((a3[1] + a3[0]) / 2.0f, f2)}, a4); try { Result a5 = this.b.a(i, bitArray, a3[1]); result.a(ResultMetadataType.UPC_EAN_EXTENSION, a5.e()); result.a(a5.c()); result.a(a5.d()); i2 = a5.e().length(); } catch (ReaderException unused) { i2 = 0; } int[] iArr2 = map != null ? (int[]) map.get(DecodeHintType.ALLOWED_EAN_EXTENSIONS) : null; if (iArr2 != null) { int length = iArr2.length; int i5 = 0; while (true) { if (i5 >= length) { z = false; break; } if (i2 == iArr2[i5]) { break; } i5++; } if (!z) { throw NotFoundException.getNotFoundInstance(); } } if ((a4 == BarcodeFormat.EAN_13 || a4 == BarcodeFormat.UPC_A) && (a = this.c.a(sb2)) != null) { result.a(ResultMetadataType.POSSIBLE_COUNTRY, a); } return result; } throw ChecksumException.getChecksumInstance(); } throw FormatException.getFormatInstance(); } throw NotFoundException.getNotFoundInstance(); } boolean a(String str) throws FormatException { return a((CharSequence) str); } static boolean a(CharSequence charSequence) throws FormatException { int length = charSequence.length(); if (length == 0) { return false; } int i = length - 1; return b(charSequence.subSequence(0, i)) == Character.digit(charSequence.charAt(i), 10); } int[] a(BitArray bitArray, int i) throws NotFoundException { return a(bitArray, i, false, d); } static int[] a(BitArray bitArray, int i, boolean z, int[] iArr) throws NotFoundException { return a(bitArray, i, z, iArr, new int[iArr.length]); } private static int[] a(BitArray bitArray, int i, boolean z, int[] iArr, int[] iArr2) throws NotFoundException { int h2 = bitArray.h(); int c = z ? bitArray.c(i) : bitArray.b(i); int length = iArr.length; int i2 = c; int i3 = 0; while (c < h2) { if (bitArray.a(c) != z) { iArr2[i3] = iArr2[i3] + 1; } else { if (i3 != length - 1) { i3++; } else { if (OneDReader.a(iArr2, iArr, 0.7f) < 0.48f) { return new int[]{i2, c}; } 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; } c++; } throw NotFoundException.getNotFoundInstance(); } static int a(BitArray bitArray, int[] iArr, int i, int[][] iArr2) throws NotFoundException { OneDReader.a(bitArray, i, iArr); int length = iArr2.length; float f2 = 0.48f; int i2 = -1; for (int i3 = 0; i3 < length; i3++) { float a = OneDReader.a(iArr, iArr2[i3], 0.7f); if (a < f2) { i2 = i3; f2 = a; } } if (i2 >= 0) { return i2; } throw NotFoundException.getNotFoundInstance(); } }