package defpackage;

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

/* JADX INFO: renamed from: ːʾᵞʔ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1950 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public ByteBuffer f7753;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public C0379 f7754;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final byte[] f7755 = new byte[256];

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public int f7756 = 0;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C0379 m5212() {
        byte[] bArr;
        if (this.f7753 == null) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("You must call setData() before parseHeader()");
            return null;
        }
        if (m5215()) {
            return this.f7754;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            sb.append((char) m5213());
        }
        boolean zStartsWith = sb.toString().startsWith("GIF");
        C0379 c0379 = this.f7754;
        if (zStartsWith) {
            c0379.f2208 = this.f7753.getShort();
            this.f7754.f2204 = this.f7753.getShort();
            int iM5213 = m5213();
            C0379 c03792 = this.f7754;
            c03792.f2199 = (iM5213 & 128) != 0;
            c03792.f2207 = (int) Math.pow(2.0d, (iM5213 & 7) + 1);
            this.f7754.f2202 = m5213();
            C0379 c03793 = this.f7754;
            m5213();
            c03793.getClass();
            if (this.f7754.f2199 && !m5215()) {
                C0379 c03794 = this.f7754;
                c03794.f2203 = m5214(c03794.f2207);
                C0379 c03795 = this.f7754;
                c03795.f2205 = c03795.f2203[c03795.f2202];
            }
        } else {
            c0379.f2198 = 1;
        }
        if (!m5215()) {
            boolean z = false;
            while (!z && !m5215() && this.f7754.f2200 <= Integer.MAX_VALUE) {
                int iM52132 = m5213();
                if (iM52132 == 33) {
                    int iM52133 = m5213();
                    if (iM52133 == 1) {
                        m5217();
                    } else if (iM52133 == 249) {
                        this.f7754.f2206 = new C1585();
                        m5213();
                        int iM52134 = m5213();
                        C1585 c1585 = this.f7754.f2206;
                        int i2 = (iM52134 & 28) >> 2;
                        c1585.f6368 = i2;
                        if (i2 == 0) {
                            c1585.f6368 = 1;
                        }
                        c1585.f6372 = (iM52134 & 1) != 0;
                        short s = this.f7753.getShort();
                        if (s < 2) {
                            s = 10;
                        }
                        C1585 c15852 = this.f7754.f2206;
                        c15852.f6371 = s * 10;
                        c15852.f6363 = m5213();
                        m5213();
                    } else if (iM52133 == 254) {
                        m5217();
                    } else if (iM52133 != 255) {
                        m5217();
                    } else {
                        m5216();
                        StringBuilder sb2 = new StringBuilder();
                        int i3 = 0;
                        while (true) {
                            bArr = this.f7755;
                            if (i3 >= 11) {
                                break;
                            }
                            sb2.append((char) bArr[i3]);
                            i3++;
                        }
                        if (sb2.toString().equals("NETSCAPE2.0")) {
                            do {
                                m5216();
                                if (bArr[0] == 1) {
                                    byte b = bArr[1];
                                    byte b2 = bArr[2];
                                    this.f7754.getClass();
                                }
                                if (this.f7756 > 0) {
                                }
                            } while (!m5215());
                        } else {
                            m5217();
                        }
                    }
                } else if (iM52132 == 44) {
                    C0379 c03796 = this.f7754;
                    if (c03796.f2206 == null) {
                        c03796.f2206 = new C1585();
                    }
                    c03796.f2206.f6367 = this.f7753.getShort();
                    this.f7754.f2206.f6362 = this.f7753.getShort();
                    this.f7754.f2206.f6364 = this.f7753.getShort();
                    this.f7754.f2206.f6370 = this.f7753.getShort();
                    int iM52135 = m5213();
                    boolean z2 = (iM52135 & 128) != 0;
                    int iPow = (int) Math.pow(2.0d, (iM52135 & 7) + 1);
                    C1585 c15853 = this.f7754.f2206;
                    c15853.f6365 = (iM52135 & 64) != 0;
                    if (z2) {
                        c15853.f6369 = m5214(iPow);
                    } else {
                        c15853.f6369 = null;
                    }
                    this.f7754.f2206.f6366 = this.f7753.position();
                    m5213();
                    m5217();
                    if (!m5215()) {
                        C0379 c03797 = this.f7754;
                        c03797.f2200++;
                        c03797.f2201.add(c03797.f2206);
                    }
                } else if (iM52132 != 59) {
                    this.f7754.f2198 = 1;
                } else {
                    z = true;
                }
            }
            C0379 c03798 = this.f7754;
            if (c03798.f2200 < 0) {
                c03798.f2198 = 1;
            }
        }
        return this.f7754;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final int m5213() {
        try {
            return this.f7753.get() & 255;
        } catch (Exception unused) {
            this.f7754.f2198 = 1;
            return 0;
        }
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final int[] m5214(int i) {
        byte[] bArr = new byte[i * 3];
        int[] iArr = null;
        try {
            this.f7753.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.f7754.f2198 = 1;
            return iArr;
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final boolean m5215() {
        return this.f7754.f2198 != 0;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m5216() {
        int iM5213 = m5213();
        this.f7756 = iM5213;
        if (iM5213 <= 0) {
            return;
        }
        int i = 0;
        while (true) {
            try {
                int i2 = this.f7756;
                if (i >= i2) {
                    return;
                }
                int i3 = i2 - i;
                this.f7753.get(this.f7755, i, i3);
                i += i3;
            } catch (Exception unused) {
                Log.isLoggable("GifHeaderParser", 3);
                this.f7754.f2198 = 1;
                return;
            }
        }
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m5217() {
        int iM5213;
        do {
            iM5213 = m5213();
            this.f7753.position(Math.min(this.f7753.position() + iM5213, this.f7753.limit()));
        } while (iM5213 > 0);
    }
}
