package yl;

import com.google.zxing.qrcode.decoder.e;
import com.google.zxing.qrcode.decoder.i;
import fl.g;
import java.util.List;
import java.util.Map;
import yk.c;
import yk.m;
import yk.o;
import yk.q;
import yk.r;
import yk.s;

/* loaded from: classes3.dex */
public class a implements o {

    /* renamed from: b, reason: collision with root package name */
    private static final s[] f52840b = new s[0];

    /* renamed from: a, reason: collision with root package name */
    private final e f52841a = new e();

    private static fl.b c(fl.b bVar) {
        int[] l10 = bVar.l();
        int[] h10 = bVar.h();
        if (l10 == null || h10 == null) {
            throw m.a();
        }
        float d10 = d(l10, bVar);
        int i10 = l10[1];
        int i11 = h10[1];
        int i12 = l10[0];
        int i13 = h10[0];
        if (i12 >= i13 || i10 >= i11) {
            throw m.a();
        }
        int i14 = i11 - i10;
        if (i14 != i13 - i12 && (i13 = i12 + i14) >= bVar.n()) {
            throw m.a();
        }
        int round = Math.round(((i13 - i12) + 1) / d10);
        int round2 = Math.round((i14 + 1) / d10);
        if (round <= 0 || round2 <= 0) {
            throw m.a();
        }
        if (round2 != round) {
            throw m.a();
        }
        int i15 = (int) (d10 / 2.0f);
        int i16 = i10 + i15;
        int i17 = i12 + i15;
        int i18 = (((int) ((round - 1) * d10)) + i17) - i13;
        if (i18 > 0) {
            if (i18 > i15) {
                throw m.a();
            }
            i17 -= i18;
        }
        int i19 = (((int) ((round2 - 1) * d10)) + i16) - i11;
        if (i19 > 0) {
            if (i19 > i15) {
                throw m.a();
            }
            i16 -= i19;
        }
        fl.b bVar2 = new fl.b(round, round2);
        for (int i20 = 0; i20 < round2; i20++) {
            int i21 = ((int) (i20 * d10)) + i16;
            for (int i22 = 0; i22 < round; i22++) {
                if (bVar.f(((int) (i22 * d10)) + i17, i21)) {
                    bVar2.p(i22, i20);
                }
            }
        }
        return bVar2;
    }

    private static float d(int[] iArr, fl.b bVar) {
        int j10 = bVar.j();
        int n10 = bVar.n();
        int i10 = iArr[0];
        boolean z10 = true;
        int i11 = iArr[1];
        int i12 = 0;
        while (i10 < n10 && i11 < j10) {
            if (z10 != bVar.f(i10, i11)) {
                i12++;
                if (i12 == 5) {
                    break;
                }
                z10 = !z10;
            }
            i10++;
            i11++;
        }
        if (i10 == n10 || i11 == j10) {
            throw m.a();
        }
        return (i10 - iArr[0]) / 7.0f;
    }

    @Override // yk.o
    public final q a(c cVar, Map map) {
        fl.e c10;
        s[] b10;
        if (map == null || !map.containsKey(yk.e.PURE_BARCODE)) {
            g e10 = new zl.c(cVar.a()).e(map);
            c10 = this.f52841a.c(e10.a(), map);
            b10 = e10.b();
        } else {
            c10 = this.f52841a.c(c(cVar.a()), map);
            b10 = f52840b;
        }
        if (c10.d() instanceof i) {
            ((i) c10.d()).a(b10);
        }
        q qVar = new q(c10.h(), c10.e(), b10, yk.a.QR_CODE);
        List a10 = c10.a();
        if (a10 != null) {
            qVar.h(r.BYTE_SEGMENTS, a10);
        }
        String b11 = c10.b();
        if (b11 != null) {
            qVar.h(r.ERROR_CORRECTION_LEVEL, b11);
        }
        if (c10.i()) {
            qVar.h(r.STRUCTURED_APPEND_SEQUENCE, Integer.valueOf(c10.g()));
            qVar.h(r.STRUCTURED_APPEND_PARITY, Integer.valueOf(c10.f()));
        }
        return qVar;
    }

    @Override // yk.o
    public q b(c cVar) {
        return a(cVar, null);
    }

    @Override // yk.o
    public void reset() {
    }
}
