package ඓ.ῲ.K.㳳;

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

/* renamed from: ඓ.ῲ.K.㳳.㸾  reason: contains not printable characters */
/* compiled from: GifHeaderParser */
public class C1217 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public C1212 f4826;

    /* renamed from: ῲ  reason: contains not printable characters */
    public ByteBuffer f4827;

    /* renamed from: K  reason: contains not printable characters */
    public final byte[] f4828 = new byte[256];

    /* renamed from: 㸾  reason: contains not printable characters */
    public int f4829 = 0;

    /* renamed from: ʬ  reason: contains not printable characters */
    public final int m3279() {
        try {
            return this.f4827.get() & 255;
        } catch (Exception unused) {
            this.f4826.f4786 = 1;
            return 0;
        }
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public final int m3280() {
        return this.f4827.getShort();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public C1212 m3281() {
        if (this.f4827 == null) {
            throw new IllegalStateException("You must call setData() before parseHeader()");
        } else if (m3282()) {
            return this.f4826;
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 6; i++) {
                sb.append((char) m3279());
            }
            if (!sb.toString().startsWith("GIF")) {
                this.f4826.f4786 = 1;
            } else {
                this.f4826.f4791 = m3280();
                this.f4826.f4787 = m3280();
                int r0 = m3279();
                this.f4826.f4793 = (r0 & 128) != 0;
                this.f4826.f4785 = (int) Math.pow(2.0d, (double) ((r0 & 7) + 1));
                this.f4826.f4790 = m3279();
                this.f4826.f4784 = m3279();
                if (this.f4826.f4793 && !m3282()) {
                    C1212 r02 = this.f4826;
                    r02.f4788 = m3283(r02.f4785);
                    C1212 r03 = this.f4826;
                    r03.f4789 = r03.f4788[r03.f4790];
                }
            }
            if (!m3282()) {
                boolean z = false;
                while (!z && !m3282() && this.f4826.f4782 <= Integer.MAX_VALUE) {
                    int r5 = m3279();
                    if (r5 == 33) {
                        int r52 = m3279();
                        if (r52 == 1) {
                            m3284();
                        } else if (r52 == 249) {
                            this.f4826.f4792 = new C1214();
                            m3279();
                            int r53 = m3279();
                            C1214 r6 = this.f4826.f4792;
                            r6.f4820 = (r53 & 28) >> 2;
                            if (r6.f4820 == 0) {
                                r6.f4820 = 1;
                            }
                            this.f4826.f4792.f4823 = (r53 & 1) != 0;
                            int r54 = m3280();
                            if (r54 < 2) {
                                r54 = 10;
                            }
                            C1214 r7 = this.f4826.f4792;
                            r7.f4818 = r54 * 10;
                            r7.f4825 = m3279();
                            m3279();
                        } else if (r52 == 254) {
                            m3284();
                        } else if (r52 != 255) {
                            m3284();
                        } else {
                            m3285();
                            StringBuilder sb2 = new StringBuilder();
                            for (int i2 = 0; i2 < 11; i2++) {
                                sb2.append((char) this.f4828[i2]);
                            }
                            if (sb2.toString().equals("NETSCAPE2.0")) {
                                do {
                                    m3285();
                                    byte[] bArr = this.f4828;
                                    if (bArr[0] == 1) {
                                        this.f4826.f4794 = ((bArr[2] & 255) << 8) | (bArr[1] & 255);
                                    }
                                    if (this.f4829 <= 0) {
                                        break;
                                    }
                                } while (!m3282());
                            } else {
                                m3284();
                            }
                        }
                    } else if (r5 == 44) {
                        C1212 r55 = this.f4826;
                        if (r55.f4792 == null) {
                            r55.f4792 = new C1214();
                        }
                        this.f4826.f4792.f4821 = m3280();
                        this.f4826.f4792.f4819 = m3280();
                        this.f4826.f4792.f4815 = m3280();
                        this.f4826.f4792.f4824 = m3280();
                        int r56 = m3279();
                        boolean z2 = (r56 & 128) != 0;
                        int pow = (int) Math.pow(2.0d, (double) ((r56 & 7) + 1));
                        this.f4826.f4792.f4816 = (r56 & 64) != 0;
                        if (z2) {
                            this.f4826.f4792.f4817 = m3283(pow);
                        } else {
                            this.f4826.f4792.f4817 = null;
                        }
                        this.f4826.f4792.f4822 = this.f4827.position();
                        m3279();
                        m3284();
                        if (!m3282()) {
                            C1212 r57 = this.f4826;
                            r57.f4782++;
                            r57.f4783.add(r57.f4792);
                        }
                    } else if (r5 != 59) {
                        this.f4826.f4786 = 1;
                    } else {
                        z = true;
                    }
                }
                C1212 r04 = this.f4826;
                if (r04.f4782 < 0) {
                    r04.f4786 = 1;
                }
            }
            return this.f4826;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final int[] m3283(int i) {
        byte[] bArr = new byte[(i * 3)];
        int[] iArr = null;
        try {
            this.f4827.get(bArr);
            iArr = new int[256];
            int i2 = 0;
            int i3 = 0;
            while (i2 < i) {
                int i4 = i3 + 1;
                int i5 = i4 + 1;
                int i6 = i5 + 1;
                int i7 = i2 + 1;
                iArr[i2] = ((bArr[i3] & 255) << 16) | -16777216 | ((bArr[i4] & 255) << 8) | (bArr[i5] & 255);
                i3 = i6;
                i2 = i7;
            }
        } catch (BufferUnderflowException e) {
            if (Log.isLoggable("GifHeaderParser", 3)) {
                Log.d("GifHeaderParser", "Format Error Reading Color Table", e);
            }
            this.f4826.f4786 = 1;
        }
        return iArr;
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public final void m3284() {
        int r0;
        do {
            r0 = m3279();
            this.f4827.position(Math.min(this.f4827.position() + r0, this.f4827.limit()));
        } while (r0 > 0);
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public final void m3285() {
        this.f4829 = m3279();
        if (this.f4829 > 0) {
            int i = 0;
            int i2 = 0;
            while (i < this.f4829) {
                try {
                    i2 = this.f4829 - i;
                    this.f4827.get(this.f4828, i, i2);
                    i += i2;
                } catch (Exception e) {
                    if (Log.isLoggable("GifHeaderParser", 3)) {
                        Log.d("GifHeaderParser", "Error Reading Block n: " + i + " count: " + i2 + " blockSize: " + this.f4829, e);
                    }
                    this.f4826.f4786 = 1;
                    return;
                }
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final boolean m3282() {
        return this.f4826.f4786 != 0;
    }
}
