package zb;

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final char[] f37121d = "0123456789-$:/.+ABCD".toCharArray();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final int[] f37122e = {3, 6, 9, 96, 18, 66, 33, 36, 48, 72, 12, 24, 69, 81, 84, 21, 26, 41, 11, 14};

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final char[] f37123f = {'A', 'B', 'C', 'D'};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final StringBuilder f37124a = new StringBuilder(20);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int[] f37125b = new int[80];

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f37126c = 0;

    public static boolean h(char[] cArr, char c6) {
        if (cArr != null) {
            for (char c10 : cArr) {
                if (c10 == c6) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override // zb.j
    public final ob.f c(int i10, tb.a aVar, Map map) throws NotFoundException {
        int i11;
        int[] iArr;
        Arrays.fill(this.f37125b, 0);
        this.f37126c = 0;
        int iF = aVar.f(0);
        int i12 = aVar.f33004b;
        if (iF >= i12) {
            throw NotFoundException.a();
        }
        int i13 = 0;
        boolean z10 = true;
        while (iF < i12) {
            if (aVar.d(iF) != z10) {
                i13++;
            } else {
                int[] iArr2 = this.f37125b;
                int i14 = this.f37126c;
                iArr2[i14] = i13;
                int i15 = i14 + 1;
                this.f37126c = i15;
                if (i15 >= iArr2.length) {
                    int[] iArr3 = new int[i15 * 2];
                    System.arraycopy(iArr2, 0, iArr3, 0, i15);
                    this.f37125b = iArr3;
                }
                z10 = !z10;
                i13 = 1;
            }
            iF++;
        }
        int[] iArr4 = this.f37125b;
        int i16 = this.f37126c;
        iArr4[i16] = i13;
        int i17 = i16 + 1;
        this.f37126c = i17;
        if (i17 >= iArr4.length) {
            int[] iArr5 = new int[i17 * 2];
            System.arraycopy(iArr4, 0, iArr5, 0, i17);
            this.f37125b = iArr5;
        }
        int i18 = 1;
        while (i18 < this.f37126c) {
            int i19 = i(i18);
            if (i19 != -1) {
                char[] cArr = f37121d;
                char c6 = cArr[i19];
                char[] cArr2 = f37123f;
                if (h(cArr2, c6)) {
                    int i20 = 0;
                    for (int i21 = i18; i21 < i18 + 7; i21++) {
                        i20 += this.f37125b[i21];
                    }
                    if (i18 == 1 || this.f37125b[i18 - 1] >= i20 / 2) {
                        StringBuilder sb = this.f37124a;
                        sb.setLength(0);
                        int i22 = i18;
                        while (true) {
                            int i23 = i(i22);
                            if (i23 == -1) {
                                throw NotFoundException.a();
                            }
                            sb.append((char) i23);
                            i11 = i22 + 8;
                            if ((sb.length() > 1 && h(cArr2, cArr[i23])) || i11 >= this.f37126c) {
                                break;
                            }
                            i22 = i11;
                        }
                        int i24 = i22 + 7;
                        int i25 = this.f37125b[i24];
                        int i26 = 0;
                        for (int i27 = -8; i27 < -1; i27++) {
                            i26 += this.f37125b[i11 + i27];
                        }
                        if (i11 < this.f37126c && i25 < i26 / 2) {
                            throw NotFoundException.a();
                        }
                        int[] iArr6 = {0, 0, 0, 0};
                        int[] iArr7 = {0, 0, 0, 0};
                        int length = sb.length() - 1;
                        int i28 = i18;
                        int i29 = 0;
                        while (true) {
                            iArr = f37122e;
                            if (i29 > length) {
                                break;
                            }
                            int i30 = iArr[sb.charAt(i29)];
                            for (int i31 = 6; i31 >= 0; i31--) {
                                int i32 = ((i30 & 1) * 2) + (i31 & 1);
                                iArr6[i32] = iArr6[i32] + this.f37125b[i28 + i31];
                                iArr7[i32] = iArr7[i32] + 1;
                                i30 >>= 1;
                            }
                            i28 += 8;
                            i29++;
                        }
                        float[] fArr = new float[4];
                        float[] fArr2 = new float[4];
                        int i33 = 0;
                        for (int i34 = 2; i33 < i34; i34 = 2) {
                            fArr2[i33] = 0.0f;
                            int i35 = i33 + 2;
                            float f10 = iArr6[i35];
                            float f11 = iArr7[i35];
                            float f12 = ((f10 / f11) + (iArr6[i33] / iArr7[i33])) / 2.0f;
                            fArr2[i35] = f12;
                            fArr[i33] = f12;
                            fArr[i35] = ((f10 * 2.0f) + 1.5f) / f11;
                            i33++;
                        }
                        int i36 = i18;
                        for (int i37 = 0; i37 <= length; i37++) {
                            int i38 = iArr[sb.charAt(i37)];
                            for (int i39 = 6; i39 >= 0; i39--) {
                                int i40 = ((i38 & 1) * 2) + (i39 & 1);
                                float f13 = this.f37125b[i36 + i39];
                                if (f13 < fArr2[i40] || f13 > fArr[i40]) {
                                    throw NotFoundException.a();
                                }
                                i38 >>= 1;
                            }
                            i36 += 8;
                        }
                        for (int i41 = 0; i41 < sb.length(); i41++) {
                            sb.setCharAt(i41, cArr[sb.charAt(i41)]);
                        }
                        if (!h(cArr2, sb.charAt(0))) {
                            throw NotFoundException.a();
                        }
                        if (!h(cArr2, sb.charAt(sb.length() - 1))) {
                            throw NotFoundException.a();
                        }
                        if (sb.length() <= 3) {
                            throw NotFoundException.a();
                        }
                        if (map == null || !map.containsKey(DecodeHintType.f24323h)) {
                            sb.deleteCharAt(sb.length() - 1);
                            sb.deleteCharAt(0);
                        }
                        int i42 = 0;
                        for (int i43 = 0; i43 < i18; i43++) {
                            i42 += this.f37125b[i43];
                        }
                        float f14 = i42;
                        while (i18 < i24) {
                            i42 += this.f37125b[i18];
                            i18++;
                        }
                        float f15 = i10;
                        ob.f fVar = new ob.f(sb.toString(), null, new ob.g[]{new ob.g(f14, f15), new ob.g(i42, f15)}, BarcodeFormat.f24303b);
                        fVar.b(ResultMetadataType.f24344m, "]F0");
                        return fVar;
                    }
                }
            }
            i18 += 2;
        }
        throw NotFoundException.a();
    }

    public final int i(int i10) {
        int i11 = i10 + 7;
        if (i11 >= this.f37126c) {
            return -1;
        }
        int[] iArr = this.f37125b;
        int i12 = Integer.MAX_VALUE;
        int i13 = 0;
        int i14 = Integer.MAX_VALUE;
        int i15 = 0;
        for (int i16 = i10; i16 < i11; i16 += 2) {
            int i17 = iArr[i16];
            if (i17 < i14) {
                i14 = i17;
            }
            if (i17 > i15) {
                i15 = i17;
            }
        }
        int i18 = (i14 + i15) / 2;
        int i19 = 0;
        for (int i20 = i10 + 1; i20 < i11; i20 += 2) {
            int i21 = iArr[i20];
            if (i21 < i12) {
                i12 = i21;
            }
            if (i21 > i19) {
                i19 = i21;
            }
        }
        int i22 = (i12 + i19) / 2;
        int i23 = 128;
        int i24 = 0;
        for (int i25 = 0; i25 < 7; i25++) {
            i23 >>= 1;
            if (iArr[i10 + i25] > ((i25 & 1) == 0 ? i18 : i22)) {
                i24 |= i23;
            }
        }
        while (true) {
            int[] iArr2 = f37122e;
            if (i13 >= iArr2.length) {
                return -1;
            }
            if (iArr2[i13] == i24) {
                return i13;
            }
            i13++;
        }
    }
}
