package p138.p176.p177.p190.p226.p229;

import android.graphics.Bitmap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.zip.Inflater;
import p138.p176.p177.p190.p226.AbstractC3947;
import p138.p176.p177.p190.p226.C3946;
import p138.p176.p177.p190.p226.InterfaceC3949;
import p138.p176.p177.p190.p239.C4140;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໟ.ދ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3980 extends AbstractC3947 {

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public final C4140 f12551;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public final C4140 f12552;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public final C3981 f12553;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public Inflater f12554;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໟ.ދ.֏$֏, reason: contains not printable characters */
    public static final class C3981 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C4140 f12555 = new C4140();

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final int[] f12556 = new int[256];

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public boolean f12557;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public int f12558;

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public int f12559;

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public int f12560;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public int f12561;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public int f12562;

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public int f12563;

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void m6416() {
            this.f12558 = 0;
            this.f12559 = 0;
            this.f12560 = 0;
            this.f12561 = 0;
            this.f12562 = 0;
            this.f12563 = 0;
            this.f12555.m6689(0);
            this.f12557 = false;
        }
    }

    public C3980() {
        super("PgsDecoder");
        this.f12551 = new C4140();
        this.f12552 = new C4140();
        this.f12553 = new C3981();
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:21:0x006f  */
    @Override // p138.p176.p177.p190.p226.AbstractC3947
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public InterfaceC3949 mo6372(byte[] bArr, int i, boolean z) {
        C4140 c4140;
        C4140 c41402;
        int i2;
        int iM6702;
        C3946 c3946;
        int i3;
        int i4;
        int iM6704;
        C3980 c3980 = this;
        C4140 c41403 = c3980.f12551;
        c41403.f13227 = bArr;
        c41403.f13229 = i;
        int i5 = 0;
        c41403.f13228 = 0;
        if (c41403.m6679() > 0 && c41403.m6686() == 120) {
            if (c3980.f12554 == null) {
                c3980.f12554 = new Inflater();
            }
            if (C4150.m6770(c41403, c3980.f12552, c3980.f12554)) {
                C4140 c41404 = c3980.f12552;
                c41403.m6684(c41404.f13227, c41404.f13229);
            }
        }
        c3980.f12553.m6416();
        ArrayList arrayList = new ArrayList();
        while (c3980.f12551.m6679() >= 3) {
            C4140 c41405 = c3980.f12551;
            C3981 c3981 = c3980.f12553;
            int i6 = c41405.f13229;
            int iM67022 = c41405.m6702();
            int iM6707 = c41405.m6707();
            int i7 = c41405.f13228 + iM6707;
            C3946 c39462 = null;
            if (i7 > i6) {
                c41405.m6693(i6);
            } else {
                if (iM67022 != 128) {
                    switch (iM67022) {
                        case 20:
                            if (c3981 == null) {
                                throw null;
                            }
                            if (iM6707 % 5 != 2) {
                                c4140 = c41405;
                                c3946 = null;
                            } else {
                                c41405.m6695(2);
                                Arrays.fill(c3981.f12556, i5);
                                int i8 = iM6707 / 5;
                                int i9 = 0;
                                while (i9 < i8) {
                                    int iM67023 = c41405.m6702();
                                    int iM67024 = c41405.m6702();
                                    double d = iM67024;
                                    double dM6702 = c41405.m6702() - 128;
                                    arrayList = arrayList;
                                    double dM67022 = c41405.m6702() - 128;
                                    c3981.f12556[iM67023] = (C4150.m6743((int) ((1.402d * dM6702) + d), 0, 255) << 16) | (c41405.m6702() << 24) | (C4150.m6743((int) ((d - (0.34414d * dM67022)) - (dM6702 * 0.71414d)), 0, 255) << 8) | C4150.m6743((int) ((dM67022 * 1.772d) + d), 0, 255);
                                    i9++;
                                    c41405 = c41405;
                                }
                                c4140 = c41405;
                                c3981.f12557 = true;
                                c3946 = null;
                            }
                            c39462 = c3946;
                            break;
                            break;
                        case 21:
                            if (c3981 == null) {
                                throw null;
                            }
                            if (iM6707 >= 4) {
                                c41405.m6695(3);
                                int i10 = iM6707 - 4;
                                if (!((c41405.m6702() & 128) != 0)) {
                                    C4140 c41406 = c3981.f12555;
                                    i3 = c41406.f13228;
                                    i4 = c41406.f13229;
                                    if (i3 < i4 && i10 > 0) {
                                        int iMin = Math.min(i10, i4 - i3);
                                        c41405.m6685(c3981.f12555.f13227, i3, iMin);
                                        c3981.f12555.m6693(i3 + iMin);
                                    }
                                } else if (i10 >= 7 && (iM6704 = c41405.m6704()) >= 4) {
                                    c3981.f12562 = c41405.m6707();
                                    c3981.f12563 = c41405.m6707();
                                    c3981.f12555.m6689(iM6704 - 4);
                                    i10 -= 7;
                                    C4140 c414062 = c3981.f12555;
                                    i3 = c414062.f13228;
                                    i4 = c414062.f13229;
                                    if (i3 < i4) {
                                        int iMin2 = Math.min(i10, i4 - i3);
                                        c41405.m6685(c3981.f12555.f13227, i3, iMin2);
                                        c3981.f12555.m6693(i3 + iMin2);
                                    }
                                }
                            }
                            c4140 = c41405;
                            c3946 = null;
                            c39462 = c3946;
                            break;
                            break;
                        case 22:
                            if (c3981 == null) {
                                throw null;
                            }
                            if (iM6707 >= 19) {
                                c3981.f12558 = c41405.m6707();
                                c3981.f12559 = c41405.m6707();
                                c41405.m6695(11);
                                c3981.f12560 = c41405.m6707();
                                c3981.f12561 = c41405.m6707();
                            }
                            c4140 = c41405;
                            c3946 = null;
                            c39462 = c3946;
                            break;
                            break;
                    }
                } else {
                    c4140 = c41405;
                    if (c3981.f12558 == 0 || c3981.f12559 == 0 || c3981.f12562 == 0 || c3981.f12563 == 0 || (i2 = (c41402 = c3981.f12555).f13229) == 0 || c41402.f13228 != i2 || !c3981.f12557) {
                        c39462 = null;
                    } else {
                        c41402.m6693(0);
                        int i11 = c3981.f12562 * c3981.f12563;
                        int[] iArr = new int[i11];
                        int i12 = 0;
                        while (i12 < i11) {
                            int iM67025 = c3981.f12555.m6702();
                            if (iM67025 != 0) {
                                iM6702 = i12 + 1;
                                iArr[i12] = c3981.f12556[iM67025];
                            } else {
                                int iM67026 = c3981.f12555.m6702();
                                if (iM67026 != 0) {
                                    iM6702 = ((iM67026 & 64) == 0 ? iM67026 & 63 : ((iM67026 & 63) << 8) | c3981.f12555.m6702()) + i12;
                                    Arrays.fill(iArr, i12, iM6702, (iM67026 & 128) == 0 ? 0 : c3981.f12556[c3981.f12555.m6702()]);
                                }
                            }
                            i12 = iM6702;
                        }
                        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(iArr, c3981.f12562, c3981.f12563, Bitmap.Config.ARGB_8888);
                        float f = c3981.f12560;
                        float f2 = c3981.f12558;
                        float f3 = f / f2;
                        float f4 = c3981.f12561;
                        float f5 = c3981.f12559;
                        c39462 = new C3946(bitmapCreateBitmap, f3, 0, f4 / f5, 0, c3981.f12562 / f2, c3981.f12563 / f5);
                    }
                    c3981.m6416();
                }
                c4140.m6693(i7);
            }
            ArrayList arrayList2 = arrayList;
            if (c39462 != null) {
                arrayList2.add(c39462);
            }
            i5 = 0;
            arrayList = arrayList2;
            c3980 = this;
        }
        return new C3982(Collections.unmodifiableList(arrayList));
    }
}
