package zb;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.NotFoundException;
import com.google.zxing.ResultMetadataType;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public final class g extends j {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final int[] f37141b = {6, 8, 10, 12, 14};

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final int[] f37142c = {1, 1, 1, 1};

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final int[][] f37143d = {new int[]{1, 1, 2}, new int[]{1, 1, 3}};

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final int[][] f37144e = {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}};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f37145a = -1;

    public static int h(int[] iArr) throws NotFoundException {
        float f10 = 0.38f;
        int i10 = 0;
        int i11 = -1;
        while (i10 < 20) {
            float fE = j.e(iArr, f37144e[i10], i10 <= 9 ? 0.5f : 0.75f);
            if (fE < f10) {
                i11 = i10;
                f10 = fE;
            } else if (fE == f10) {
                i11 = -1;
            }
            i10++;
        }
        if (i11 >= 0) {
            return i11 % 10;
        }
        throw NotFoundException.a();
    }

    public static int[] i(int i10, tb.a aVar, int[] iArr) throws NotFoundException {
        int length = iArr.length;
        int[] iArr2 = new int[length];
        int i11 = aVar.f33004b;
        int i12 = i10;
        boolean z10 = false;
        int i13 = 0;
        while (i10 < i11) {
            if (aVar.d(i10) != z10) {
                iArr2[i13] = iArr2[i13] + 1;
            } else {
                if (i13 != length - 1) {
                    i13++;
                } else {
                    if (j.e(iArr2, iArr, 0.5f) < 0.38f) {
                        return new int[]{i12, i10};
                    }
                    i12 += iArr2[0] + iArr2[1];
                    int i14 = i13 - 1;
                    System.arraycopy(iArr2, 2, iArr2, 0, i14);
                    iArr2[i14] = 0;
                    iArr2[i13] = 0;
                    i13--;
                }
                iArr2[i13] = 1;
                z10 = !z10;
            }
            i10++;
        }
        throw NotFoundException.a();
    }

    @Override // zb.j
    public final ob.f c(int i10, tb.a aVar, Map map) throws NotFoundException, FormatException {
        int[] iArrI;
        boolean z10;
        int i11 = aVar.f33004b;
        int iE = aVar.e(0);
        if (iE == i11) {
            throw NotFoundException.a();
        }
        int[] iArrI2 = i(iE, aVar, f37142c);
        int i12 = iArrI2[1];
        int i13 = iArrI2[0];
        this.f37145a = (i12 - i13) / 4;
        j(i13, aVar);
        int[][] iArr = f37143d;
        aVar.i();
        try {
            int i14 = aVar.f33004b;
            int iE2 = aVar.e(0);
            if (iE2 == i14) {
                throw NotFoundException.a();
            }
            try {
                iArrI = i(iE2, aVar, iArr[0]);
            } catch (NotFoundException unused) {
                iArrI = i(iE2, aVar, iArr[1]);
            }
            j(iArrI[0], aVar);
            int i15 = iArrI[0];
            int i16 = aVar.f33004b;
            iArrI[0] = i16 - iArrI[1];
            iArrI[1] = i16 - i15;
            aVar.i();
            StringBuilder sb = new StringBuilder(20);
            int i17 = iArrI2[1];
            int i18 = iArrI[0];
            int[] iArr2 = new int[10];
            int[] iArr3 = new int[5];
            int[] iArr4 = new int[5];
            while (i17 < i18) {
                j.f(i17, aVar, iArr2);
                for (int i19 = 0; i19 < 5; i19++) {
                    int i20 = i19 * 2;
                    iArr3[i19] = iArr2[i20];
                    iArr4[i19] = iArr2[i20 + 1];
                }
                sb.append((char) (h(iArr3) + 48));
                sb.append((char) (h(iArr4) + 48));
                for (int i21 = 0; i21 < 10; i21++) {
                    i17 += iArr2[i21];
                }
            }
            String string = sb.toString();
            int[] iArr5 = map != null ? (int[]) map.get(DecodeHintType.f24320e) : null;
            if (iArr5 == null) {
                iArr5 = f37141b;
            }
            int length = string.length();
            int length2 = iArr5.length;
            int i22 = 0;
            int i23 = 0;
            while (true) {
                if (i22 >= length2) {
                    z10 = false;
                    break;
                }
                int i24 = iArr5[i22];
                if (length == i24) {
                    z10 = true;
                    break;
                }
                if (i24 > i23) {
                    i23 = i24;
                }
                i22++;
            }
            if ((z10 || length <= i23) && !z10) {
                throw FormatException.a();
            }
            float f10 = i10;
            ob.f fVar = new ob.f(string, null, new ob.g[]{new ob.g(iArrI2[1], f10), new ob.g(iArrI[0], f10)}, BarcodeFormat.f24310i);
            fVar.b(ResultMetadataType.f24344m, "]I0");
            return fVar;
        } catch (Throwable th) {
            aVar.i();
            throw th;
        }
    }

    public final void j(int i10, tb.a aVar) throws NotFoundException {
        int iMin = Math.min(this.f37145a * 10, i10);
        for (int i11 = i10 - 1; iMin > 0 && i11 >= 0 && !aVar.d(i11); i11--) {
            iMin--;
        }
        if (iMin != 0) {
            throw NotFoundException.a();
        }
    }
}
