package defpackage;

import android.graphics.Bitmap;
import android.graphics.Rect;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.zip.Inflater;

/* JADX INFO: renamed from: ᵜᵚ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2867 implements InterfaceC3971 {

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public static final C5508 f10963;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final C2841 f10965;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public Inflater f10967;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C4545 f10964 = new C4545();

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final C4545 f10966 = new C4545();

    static {
        C2822 c2822 = AbstractC4509.f17159;
        f10963 = new C5508(-9223372036854775807L, -9223372036854775807L, C2598.f10048);
    }

    public C2867(List list) {
        int i;
        C2841 c2841 = new C2841();
        this.f10965 = c2841;
        String strTrim = new String((byte[]) list.get(0), StandardCharsets.UTF_8).trim();
        String str = AbstractC0956.f4222;
        for (String str2 : strTrim.split("\\r?\\n", -1)) {
            if (str2.startsWith("palette: ")) {
                String[] strArrSplit = str2.substring(9).split(",", -1);
                c2841.f10885 = new int[strArrSplit.length];
                for (int i2 = 0; i2 < strArrSplit.length; i2++) {
                    int[] iArr = c2841.f10885;
                    try {
                        i = Integer.parseInt(strArrSplit[i2].trim(), 16);
                    } catch (RuntimeException e) {
                        ˋˀᵧ.ᵠˏˏ("Parsing color failed", e);
                        i = 0;
                    }
                    iArr[i2] = i;
                }
            } else if (str2.startsWith("size: ")) {
                String[] strArrSplit2 = str2.substring(6).trim().split("x", -1);
                if (strArrSplit2.length != 2) {
                    ˋˀᵧ.ʿٴˇ("Ignoring malformed IDX size line: '" + str2 + "'");
                } else {
                    try {
                        c2841.f10881 = Integer.parseInt(strArrSplit2[0]);
                        c2841.f10876 = Integer.parseInt(strArrSplit2[1]);
                        c2841.f10883 = true;
                    } catch (RuntimeException e2) {
                        ˋˀᵧ.ᵠˏˏ("Parsing IDX failed", e2);
                    }
                }
            }
        }
    }

    @Override // defpackage.InterfaceC3971
    public final /* synthetic */ void reset() {
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to find 'out' block for switch in B:44:0x00c8. Please report as an issue. */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:101:0x0288  */
    /* JADX WARN: Removed duplicated region for block: B:104:0x028e  */
    /* JADX WARN: Removed duplicated region for block: B:106:0x0294  */
    /* JADX WARN: Removed duplicated region for block: B:92:0x0274  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x027b  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$ArrayArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // defpackage.InterfaceC3971
    /* JADX INFO: renamed from: ˊᵫᵗ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void mo1086(byte[] bArr, int i, int i2, C1589 c1589, InterfaceC3498 interfaceC3498) {
        C5508 c5508;
        char c;
        long j;
        char c2;
        C4847 c4847;
        long j2;
        long j3;
        Rect rect;
        C4545 c4545 = this.f10964;
        c4545.m9600(i + i2, bArr);
        c4545.m9624(i);
        if (this.f10967 == null) {
            this.f10967 = new Inflater();
        }
        Inflater inflater = this.f10967;
        String str = AbstractC0956.f4222;
        if (c4545.m9623() > 0 && c4545.m9622() == 120) {
            C4545 c45452 = this.f10966;
            if (AbstractC0956.m3239(c4545, c45452, inflater)) {
                c4545.m9600(c45452.f17283, c45452.f17284);
            }
        }
        C2841 c2841 = this.f10965;
        long j4 = -9223372036854775807L;
        c2841.f10875 = -9223372036854775807L;
        c2841.f10877 = -9223372036854775807L;
        char c3 = 0;
        c2841.f10878 = false;
        c2841.f10884 = null;
        c2841.f10879 = -1;
        c2841.f10882 = -1;
        int iM9623 = c4545.m9623();
        if (iM9623 < 2 || c4545.m9598() != iM9623) {
            c5508 = f10963;
        } else {
            if (c2841.f10885 == null) {
                ˋˀᵧ.ʿٴˇ("Skipping SPU (no palette)");
            } else if (c2841.f10883) {
                int i3 = c4545.f17282 - 2;
                c4545.m9624(c4545.m9598() + i3);
                while (true) {
                    if (c4545.m9623() < 4) {
                        j = j4;
                        c2 = c3;
                        c = c2;
                    } else {
                        int i4 = c4545.f17282;
                        int iM9598 = c4545.m9598() * 10000;
                        int iM95982 = c4545.m9598() + i3;
                        c = (iM95982 == i4 || iM95982 >= c4545.f17283) ? c3 : (char) 1;
                        int i5 = c != 0 ? iM95982 : c4545.f17283;
                        j = j4;
                        char c4 = 1;
                        while (c4545.f17282 < i5 && c4 != 0) {
                            long j5 = iM9598;
                            int[] iArr = c2841.f10880;
                            int iM9626 = c4545.m9626();
                            char c5 = c3;
                            if (iM9626 != 255) {
                                switch (iM9626) {
                                    case 0:
                                        c4 = 1;
                                        break;
                                    case 1:
                                        c2841.f10875 = j5;
                                        c4 = 1;
                                        break;
                                    case 2:
                                        c2841.f10877 = j5;
                                        c4 = 1;
                                        break;
                                    case 3:
                                        if (c4545.m9623() >= 2) {
                                            int iM96262 = c4545.m9626();
                                            int iM96263 = c4545.m9626();
                                            iArr[3] = C2841.m6821(c2841.f10885, iM96262 >> 4);
                                            iArr[2] = C2841.m6821(c2841.f10885, iM96262 & 15);
                                            iArr[1] = C2841.m6821(c2841.f10885, iM96263 >> 4);
                                            iArr[c5] = C2841.m6821(c2841.f10885, iM96263 & 15);
                                            c2841.f10878 = true;
                                            c4 = 1;
                                        } else {
                                            ˋˀᵧ.ʿٴˇ("Incomplete color command");
                                            c4 = c5;
                                        }
                                        break;
                                    case 4:
                                        if (c4545.m9623() < 2) {
                                            ˋˀᵧ.ʿٴˇ("Incomplete alpha command");
                                        } else if (c2841.f10878) {
                                            int iM96264 = c4545.m9626();
                                            int iM96265 = c4545.m9626();
                                            iArr[3] = C2841.m6820(iArr[3], iM96264 >> 4);
                                            iArr[2] = C2841.m6820(iArr[2], iM96264 & 15);
                                            iArr[1] = C2841.m6820(iArr[1], iM96265 >> 4);
                                            iArr[c5] = C2841.m6820(iArr[c5], iM96265 & 15);
                                            c4 = 1;
                                        } else {
                                            ˋˀᵧ.ʿٴˇ("Ignoring alpha command before color command");
                                        }
                                        c4 = c5;
                                        break;
                                    case 5:
                                        if (c4545.m9623() >= 6) {
                                            int iM96266 = c4545.m9626();
                                            int iM96267 = c4545.m9626();
                                            int i6 = (iM96266 << 4) | (iM96267 >> 4);
                                            int iM96268 = ((iM96267 & 15) << 8) | c4545.m9626();
                                            int iM96269 = c4545.m9626();
                                            int iM962610 = c4545.m9626();
                                            c2841.f10884 = new Rect(i6, (iM96269 << 4) | (iM962610 >> 4), iM96268 + 1, (((iM962610 & 15) << 8) | c4545.m9626()) + 1);
                                            c4 = 1;
                                        } else {
                                            ˋˀᵧ.ʿٴˇ("Incomplete area command");
                                            c4 = c5;
                                        }
                                        break;
                                    case C5224.STRING_SET_FIELD_NUMBER /* 6 */:
                                        if (c4545.m9623() >= 4) {
                                            c2841.f10879 = c4545.m9598();
                                            c2841.f10882 = c4545.m9598();
                                            c4 = 1;
                                        } else {
                                            ˋˀᵧ.ʿٴˇ("Incomplete offsets command");
                                            c4 = c5;
                                        }
                                        break;
                                    default:
                                        AbstractC3653.m8224(iM9626, "Unrecognized command: ");
                                        c4 = c5;
                                        break;
                                }
                            } else {
                                c4 = c5;
                            }
                            c3 = c5;
                        }
                        c2 = c3;
                        if (c != 0) {
                            c4545.m9624(iM95982);
                        }
                    }
                    if (c == 0) {
                        if (c2841.f10885 != null || !c2841.f10883 || !c2841.f10878 || (rect = c2841.f10884) == null || c2841.f10879 == -1 || c2841.f10882 == -1 || rect.width() < 2 || c2841.f10884.height() < 2) {
                            c4847 = null;
                        } else {
                            Rect rect2 = c2841.f10884;
                            int[] iArr2 = new int[rect2.height() * rect2.width()];
                            C3180 c3180 = new C3180(1);
                            c4545.m9624(c2841.f10879);
                            c3180.m7294(c4545);
                            c2841.m6822(c3180, true, rect2, iArr2);
                            c4545.m9624(c2841.f10882);
                            c3180.m7294(c4545);
                            c2841.m6822(c3180, c2, rect2, iArr2);
                            c4847 = new C4847(null, null, null, Bitmap.createBitmap(iArr2, rect2.width(), rect2.height(), Bitmap.Config.ARGB_8888), rect2.top / c2841.f10876, 0, 0, rect2.left / c2841.f10881, 0, Integer.MIN_VALUE, -3.4028235E38f, rect2.width() / c2841.f10881, rect2.height() / c2841.f10876, false, -16777216, Integer.MIN_VALUE, 0.0f, 0);
                        }
                        j2 = c2841.f10877;
                        if (j2 == j) {
                            long j6 = c2841.f10875;
                            if (j6 != j && j2 > j6) {
                                j2 -= j6;
                            }
                            j3 = j2;
                        } else {
                            j3 = j;
                        }
                        c5508 = new C5508(c2841.f10875, j3, c4847 == null ? AbstractC4509.m9553(c4847) : C2598.f10048);
                    } else {
                        j4 = j;
                        c3 = c2;
                    }
                }
            } else {
                ˋˀᵧ.ʿٴˇ("Skipping SPU (no plane)");
            }
            j = -9223372036854775807L;
            c2 = 0;
            if (c2841.f10885 != null) {
                c4847 = null;
                j2 = c2841.f10877;
                if (j2 == j) {
                }
                c5508 = new C5508(c2841.f10875, j3, c4847 == null ? AbstractC4509.m9553(c4847) : C2598.f10048);
            }
        }
        interfaceC3498.accept(c5508);
    }

    @Override // defpackage.InterfaceC3971
    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public final int mo1087() {
        return 2;
    }

    @Override // defpackage.InterfaceC3971
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public final /* synthetic */ InterfaceC4153 mo1088(byte[] bArr, int i, int i2) {
        return AbstractC2704.m6518(this, bArr, i2);
    }
}
