package zb;

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

/* JADX INFO: loaded from: classes.dex */
public abstract class j implements ob.e {
    public static float e(int[] iArr, int[] iArr2, float f10) {
        int length = iArr.length;
        int i10 = 0;
        int i11 = 0;
        for (int i12 = 0; i12 < length; i12++) {
            i10 += iArr[i12];
            i11 += iArr2[i12];
        }
        if (i10 < i11) {
            return Float.POSITIVE_INFINITY;
        }
        float f11 = i10;
        float f12 = f11 / i11;
        float f13 = f10 * f12;
        float f14 = 0.0f;
        for (int i13 = 0; i13 < length; i13++) {
            float f15 = iArr2[i13] * f12;
            float f16 = iArr[i13];
            float f17 = f16 > f15 ? f16 - f15 : f15 - f16;
            if (f17 > f13) {
                return Float.POSITIVE_INFINITY;
            }
            f14 += f17;
        }
        return f14 / f11;
    }

    public static void f(int i10, tb.a aVar, int[] iArr) throws NotFoundException {
        int length = iArr.length;
        int i11 = 0;
        Arrays.fill(iArr, 0, length, 0);
        int i12 = aVar.f33004b;
        if (i10 >= i12) {
            throw NotFoundException.a();
        }
        boolean z10 = !aVar.d(i10);
        while (i10 < i12) {
            if (aVar.d(i10) != z10) {
                iArr[i11] = iArr[i11] + 1;
            } else {
                i11++;
                if (i11 == length) {
                    break;
                }
                iArr[i11] = 1;
                z10 = !z10;
            }
            i10++;
        }
        if (i11 != length) {
            if (i11 != length - 1 || i10 != i12) {
                throw NotFoundException.a();
            }
        }
    }

    public static void g(int i10, tb.a aVar, int[] iArr) throws NotFoundException {
        int length = iArr.length;
        boolean zD = aVar.d(i10);
        while (i10 > 0 && length >= 0) {
            i10--;
            if (aVar.d(i10) != zD) {
                length--;
                zD = !zD;
            }
        }
        if (length >= 0) {
            throw NotFoundException.a();
        }
        f(i10 + 1, aVar, iArr);
    }

    @Override // ob.e
    public ob.f a(xyz.stream.utils.f fVar, Map map) throws NotFoundException {
        try {
            return d(fVar, map);
        } catch (NotFoundException e10) {
            if (map == null || !map.containsKey(DecodeHintType.f24318c) || !((ob.b) ((o0.i) fVar.f36132b).f31277a).c()) {
                throw e10;
            }
            xyz.stream.utils.f fVar2 = new xyz.stream.utils.f(((o0.i) fVar.f36132b).g(((ob.b) ((o0.i) fVar.f36132b).f31277a).d()));
            ob.f fVarD = d(fVar2, map);
            Map map2 = fVarD.f31471e;
            ResultMetadataType resultMetadataType = ResultMetadataType.f24332a;
            int iIntValue = 270;
            if (map2 != null && map2.containsKey(resultMetadataType)) {
                iIntValue = (((Integer) map2.get(resultMetadataType)).intValue() + 270) % 360;
            }
            fVarD.b(resultMetadataType, Integer.valueOf(iIntValue));
            ob.g[] gVarArr = fVarD.f31469c;
            if (gVarArr != null) {
                int i10 = ((ob.b) ((o0.i) fVar2.f36132b).f31277a).f31460b;
                for (int i11 = 0; i11 < gVarArr.length; i11++) {
                    ob.g gVar = gVarArr[i11];
                    gVarArr[i11] = new ob.g((i10 - gVar.f31473b) - 1.0f, gVar.f31472a);
                }
            }
            return fVarD;
        }
    }

    @Override // ob.e
    public ob.f b(xyz.stream.utils.f fVar) {
        return a(fVar, null);
    }

    public abstract ob.f c(int i10, tb.a aVar, Map map);

    /* JADX WARN: Removed duplicated region for block: B:34:0x007e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final ob.f d(xyz.stream.utils.f fVar, Map map) throws NotFoundException {
        j jVar;
        Map map2;
        int i10;
        ob.g gVar;
        xyz.stream.utils.f fVar2 = fVar;
        Map map3 = map;
        Object obj = fVar2.f36132b;
        int i11 = ((ob.b) ((o0.i) obj).f31277a).f31459a;
        int i12 = ((ob.b) ((o0.i) obj).f31277a).f31460b;
        tb.a aVar = new tb.a(i11);
        int i13 = 1;
        int i14 = 0;
        boolean z10 = map3 != null && map3.containsKey(DecodeHintType.f24318c);
        int iMax = Math.max(1, i12 >> (z10 ? 8 : 5));
        int i15 = z10 ? i12 : 15;
        int i16 = i12 / 2;
        int i17 = 0;
        while (i17 < i15) {
            int i18 = i17 + 1;
            int i19 = i18 / 2;
            if ((i17 & 1) != 0) {
                i19 = -i19;
            }
            int i20 = (i19 * iMax) + i16;
            if (i20 < 0 || i20 >= i12) {
                break;
            }
            try {
                aVar = ((o0.i) fVar2.f36132b).j(i20, aVar);
                int i21 = i14;
                while (i21 < 2) {
                    if (i21 == i13) {
                        aVar.i();
                        if (map3 != null) {
                            DecodeHintType decodeHintType = DecodeHintType.f24324i;
                            if (map3.containsKey(decodeHintType)) {
                                EnumMap enumMap = new EnumMap(DecodeHintType.class);
                                enumMap.putAll(map3);
                                enumMap.remove(decodeHintType);
                                jVar = this;
                                map3 = enumMap;
                            } else {
                                jVar = this;
                            }
                        }
                    }
                    try {
                        ob.f fVarC = jVar.c(i20, aVar, map3);
                        if (i21 == i13) {
                            try {
                                fVarC.b(ResultMetadataType.f24332a, 180);
                                ob.g[] gVarArr = fVarC.f31469c;
                                if (gVarArr != null) {
                                    float f10 = i11;
                                    map2 = map3;
                                    try {
                                        ob.g gVar2 = gVarArr[i14];
                                        gVarArr[0] = new ob.g((f10 - gVar2.f31472a) - 1.0f, gVar2.f31473b);
                                        try {
                                            ob.g gVar3 = gVarArr[1];
                                            gVar = new ob.g((f10 - gVar3.f31472a) - 1.0f, gVar3.f31473b);
                                            i10 = 1;
                                        } catch (ReaderException unused) {
                                            i10 = 1;
                                        }
                                        try {
                                            gVarArr[1] = gVar;
                                        } catch (ReaderException unused2) {
                                            continue;
                                            i21++;
                                            i13 = i10;
                                            map3 = map2;
                                            i14 = 0;
                                        }
                                    } catch (ReaderException unused3) {
                                        i10 = 1;
                                        i21++;
                                        i13 = i10;
                                        map3 = map2;
                                        i14 = 0;
                                    }
                                }
                            } catch (ReaderException unused4) {
                                map2 = map3;
                            }
                        }
                        return fVarC;
                    } catch (ReaderException unused5) {
                        map2 = map3;
                        i10 = i13;
                    }
                }
            } catch (NotFoundException unused6) {
            }
            i13 = i13;
            i17 = i18;
            i14 = 0;
            fVar2 = fVar;
        }
        throw NotFoundException.a();
    }

    @Override // ob.e
    public void reset() {
    }
}
