package defpackage;

import android.util.Log;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;

/* renamed from: ᵙᵺ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2624 {

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public C1130 f10144;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public ByteBuffer f10146;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final byte[] f10145 = new byte[256];

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public int f10147 = 0;

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final int[] m6592(int i) {
        byte[] bArr = new byte[i * 3];
        int[] iArr = null;
        try {
            this.f10146.get(bArr);
            iArr = new int[256];
            int i2 = 0;
            int i3 = 0;
            while (i2 < i) {
                int i4 = bArr[i3] & 255;
                int i5 = i3 + 2;
                int i6 = bArr[i3 + 1] & 255;
                i3 += 3;
                int i7 = i2 + 1;
                iArr[i2] = (i6 << 8) | (i4 << 16) | (-16777216) | (bArr[i5] & 255);
                i2 = i7;
            }
            return iArr;
        } catch (BufferUnderflowException unused) {
            Log.isLoggable("GifHeaderParser", 3);
            this.f10144.f4852 = 1;
            return iArr;
        }
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final void m6593() {
        int iM6594;
        do {
            iM6594 = m6594();
            this.f10146.position(Math.min(this.f10146.position() + iM6594, this.f10146.limit()));
        } while (iM6594 > 0);
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final int m6594() {
        try {
            return this.f10146.get() & 255;
        } catch (Exception unused) {
            this.f10144.f4852 = 1;
            return 0;
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final boolean m6595() {
        return this.f10144.f4852 != 0;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C1130 m6596() {
        byte[] bArr;
        if (this.f10146 == null) {
            ᵹˉᵞ.ᵳٴᵶ("You must call setData() before parseHeader()");
            return null;
        }
        if (m6595()) {
            return this.f10144;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            sb.append((char) m6594());
        }
        boolean zStartsWith = sb.toString().startsWith("GIF");
        C1130 c1130 = this.f10144;
        if (zStartsWith) {
            c1130.f4848 = this.f10146.getShort();
            this.f10144.f4847 = this.f10146.getShort();
            int iM6594 = m6594();
            C1130 c11302 = this.f10144;
            c11302.f4855 = (iM6594 & 128) != 0;
            c11302.f4850 = (int) Math.pow(2.0d, (iM6594 & 7) + 1);
            this.f10144.f4853 = m6594();
            C1130 c11303 = this.f10144;
            m6594();
            c11303.getClass();
            if (this.f10144.f4855 && !m6595()) {
                C1130 c11304 = this.f10144;
                c11304.f4851 = m6592(c11304.f4850);
                C1130 c11305 = this.f10144;
                c11305.f4854 = c11305.f4851[c11305.f4853];
            }
        } else {
            c1130.f4852 = 1;
        }
        if (!m6595()) {
            boolean z = false;
            while (!z && !m6595() && this.f10144.f4849 <= Integer.MAX_VALUE) {
                int iM65942 = m6594();
                if (iM65942 == 33) {
                    int iM65943 = m6594();
                    if (iM65943 == 1) {
                        m6593();
                    } else if (iM65943 == 249) {
                        this.f10144.f4856 = new C5332();
                        m6594();
                        int iM65944 = m6594();
                        C5332 c5332 = this.f10144.f4856;
                        int i2 = (iM65944 & 28) >> 2;
                        c5332.f19963 = i2;
                        if (i2 == 0) {
                            c5332.f19963 = 1;
                        }
                        c5332.f19964 = (iM65944 & 1) != 0;
                        short s = this.f10146.getShort();
                        if (s < 2) {
                            s = 10;
                        }
                        C5332 c53322 = this.f10144.f4856;
                        c53322.f19966 = s * 10;
                        c53322.f19971 = m6594();
                        m6594();
                    } else if (iM65943 == 254) {
                        m6593();
                    } else if (iM65943 != 255) {
                        m6593();
                    } else {
                        m6597();
                        StringBuilder sb2 = new StringBuilder();
                        int i3 = 0;
                        while (true) {
                            bArr = this.f10145;
                            if (i3 >= 11) {
                                break;
                            }
                            sb2.append((char) bArr[i3]);
                            i3++;
                        }
                        if (sb2.toString().equals("NETSCAPE2.0")) {
                            do {
                                m6597();
                                if (bArr[0] == 1) {
                                    byte b = bArr[1];
                                    byte b2 = bArr[2];
                                    this.f10144.getClass();
                                }
                                if (this.f10147 > 0) {
                                }
                            } while (!m6595());
                        } else {
                            m6593();
                        }
                    }
                } else if (iM65942 == 44) {
                    C1130 c11306 = this.f10144;
                    if (c11306.f4856 == null) {
                        c11306.f4856 = new C5332();
                    }
                    c11306.f4856.f19967 = this.f10146.getShort();
                    this.f10144.f4856.f19968 = this.f10146.getShort();
                    this.f10144.f4856.f19965 = this.f10146.getShort();
                    this.f10144.f4856.f19972 = this.f10146.getShort();
                    int iM65945 = m6594();
                    boolean z2 = (iM65945 & 128) != 0;
                    int iPow = (int) Math.pow(2.0d, (iM65945 & 7) + 1);
                    C5332 c53323 = this.f10144.f4856;
                    c53323.f19962 = (iM65945 & 64) != 0;
                    if (z2) {
                        c53323.f19970 = m6592(iPow);
                    } else {
                        c53323.f19970 = null;
                    }
                    this.f10144.f4856.f19969 = this.f10146.position();
                    m6594();
                    m6593();
                    if (!m6595()) {
                        C1130 c11307 = this.f10144;
                        c11307.f4849++;
                        c11307.f4846.add(c11307.f4856);
                    }
                } else if (iM65942 != 59) {
                    this.f10144.f4852 = 1;
                } else {
                    z = true;
                }
            }
            C1130 c11308 = this.f10144;
            if (c11308.f4849 < 0) {
                c11308.f4852 = 1;
            }
        }
        return this.f10144;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m6597() {
        int iM6594 = m6594();
        this.f10147 = iM6594;
        if (iM6594 <= 0) {
            return;
        }
        int i = 0;
        while (true) {
            try {
                int i2 = this.f10147;
                if (i >= i2) {
                    return;
                }
                int i3 = i2 - i;
                this.f10146.get(this.f10145, i, i3);
                i += i3;
            } catch (Exception unused) {
                Log.isLoggable("GifHeaderParser", 3);
                this.f10144.f4852 = 1;
                return;
            }
        }
    }
}
