package zb;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.ChecksumException;
import com.google.zxing.NotFoundException;
import com.google.zxing.ResultMetadataType;
import java.util.Arrays;
import java.util.Map;
import tv.danmaku.ijk.media.player.IjkEventListener;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final int[] f37128d = {52, 289, 97, 352, 49, 304, 112, 37, 292, 100, 265, 73, 328, 25, 280, 88, 13, 268, 76, 28, 259, 67, 322, 19, 274, 82, 7, 262, 70, 22, 385, 193, 448, 145, IjkEventListener.VIDEO_SIZE_CHANGED, 208, 133, 388, 196, 168, 162, 138, 42};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f37129a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int[] f37131c = new int[9];

    public c(boolean z10) {
        this.f37129a = z10;
    }

    public static int h(int[] iArr) {
        int length = iArr.length;
        int i10 = 0;
        while (true) {
            int i11 = Integer.MAX_VALUE;
            for (int i12 : iArr) {
                if (i12 < i11 && i12 > i10) {
                    i11 = i12;
                }
            }
            int i13 = 0;
            int i14 = 0;
            int i15 = 0;
            for (int i16 = 0; i16 < length; i16++) {
                int i17 = iArr[i16];
                if (i17 > i11) {
                    i14 |= 1 << ((length - 1) - i16);
                    i13++;
                    i15 += i17;
                }
            }
            if (i13 == 3) {
                for (int i18 = 0; i18 < length && i13 > 0; i18++) {
                    int i19 = iArr[i18];
                    if (i19 > i11) {
                        i13--;
                        if (i19 * 2 >= i15) {
                            return -1;
                        }
                    }
                }
                return i14;
            }
            if (i13 <= 3) {
                return -1;
            }
            i10 = i11;
        }
    }

    @Override // zb.j
    public final ob.f c(int i10, tb.a aVar, Map map) throws NotFoundException, ChecksumException {
        char cCharAt;
        int[] iArr = this.f37131c;
        int i11 = 0;
        Arrays.fill(iArr, 0);
        StringBuilder sb = this.f37130b;
        sb.setLength(0);
        int i12 = aVar.f33004b;
        int iE = aVar.e(0);
        int length = iArr.length;
        boolean z10 = false;
        int i13 = 0;
        int i14 = iE;
        while (iE < i12) {
            if (aVar.d(iE) != z10) {
                iArr[i13] = iArr[i13] + 1;
            } else {
                if (i13 == length - 1) {
                    int i15 = 148;
                    if (h(iArr) == 148 && aVar.h(Math.max(0, i14 - ((iE - i14) / 2)), i14)) {
                        int iE2 = aVar.e(new int[]{i14, iE}[1]);
                        int i16 = aVar.f33004b;
                        while (true) {
                            j.f(iE2, aVar, iArr);
                            int iH = h(iArr);
                            if (iH < 0) {
                                throw NotFoundException.a();
                            }
                            int i17 = i11;
                            while (true) {
                                if (i17 < 43) {
                                    if (f37128d[i17] == iH) {
                                        cCharAt = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".charAt(i17);
                                        break;
                                    }
                                    i17++;
                                } else {
                                    if (iH != i15) {
                                        throw NotFoundException.a();
                                    }
                                    cCharAt = '*';
                                }
                            }
                            sb.append(cCharAt);
                            int i18 = iE2;
                            for (int i19 : iArr) {
                                i18 += i19;
                            }
                            int iE3 = aVar.e(i18);
                            if (cCharAt == '*') {
                                sb.setLength(sb.length() - 1);
                                int i20 = 0;
                                for (int i21 : iArr) {
                                    i20 += i21;
                                }
                                int i22 = (iE3 - iE2) - i20;
                                if (iE3 != i16 && i22 * 2 < i20) {
                                    throw NotFoundException.a();
                                }
                                if (this.f37129a) {
                                    int length2 = sb.length() - 1;
                                    int iIndexOf = 0;
                                    for (int i23 = 0; i23 < length2; i23++) {
                                        iIndexOf += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".indexOf(sb.charAt(i23));
                                    }
                                    if (sb.charAt(length2) != "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".charAt(iIndexOf % 43)) {
                                        throw ChecksumException.a();
                                    }
                                    sb.setLength(length2);
                                }
                                if (sb.length() == 0) {
                                    throw NotFoundException.a();
                                }
                                float f10 = i10;
                                ob.f fVar = new ob.f(sb.toString(), null, new ob.g[]{new ob.g((r5[1] + r5[0]) / 2.0f, f10), new ob.g((i20 / 2.0f) + iE2, f10)}, BarcodeFormat.f24304c);
                                fVar.b(ResultMetadataType.f24344m, "]A0");
                                return fVar;
                            }
                            iE2 = iE3;
                            i11 = 0;
                            i15 = 148;
                        }
                    } else {
                        i14 += iArr[0] + iArr[1];
                        int i24 = i13 - 1;
                        System.arraycopy(iArr, 2, iArr, 0, i24);
                        iArr[i24] = 0;
                        iArr[i13] = 0;
                        i13--;
                    }
                } else {
                    i13++;
                }
                iArr[i13] = 1;
                z10 = !z10;
            }
            iE++;
        }
        throw NotFoundException.a();
    }
}
