package p138.p145.p146.p148;

import android.util.Log;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import p138.p139.p143.p144.C2803;

/* JADX INFO: renamed from: ދ.ؠ.֏.ފ.ށ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C2834 {

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public ByteBuffer f8764;

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final byte[] f8763 = new byte[256];

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m4959() {
        return this.f8765.f8751 != 0;
    }

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

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public C2833 m4961() {
        if (this.f8764 == null) {
            throw new IllegalStateException("You must call setData() before parseHeader()");
        }
        if (m4959()) {
            return this.f8765;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            sb.append((char) m4962());
        }
        if (sb.toString().startsWith("GIF")) {
            this.f8765.f8755 = m4964();
            this.f8765.f8756 = m4964();
            this.f8765.f8757 = (m4962() & 128) != 0;
            this.f8765.f8758 = (int) Math.pow(2.0d, (r0 & 7) + 1);
            this.f8765.f8759 = m4962();
            this.f8765.f8760 = m4962();
            if (this.f8765.f8757 && !m4959()) {
                C2833 c2833 = this.f8765;
                c2833.f8750 = m4960(c2833.f8758);
                C2833 c28332 = this.f8765;
                c28332.f8761 = c28332.f8750[c28332.f8759];
            }
        } else {
            this.f8765.f8751 = 1;
        }
        if (!m4959()) {
            boolean z = false;
            while (!z && !m4959() && this.f8765.f8752 <= Integer.MAX_VALUE) {
                int iM4962 = m4962();
                if (iM4962 == 33) {
                    int iM49622 = m4962();
                    if (iM49622 == 1) {
                        m4965();
                    } else if (iM49622 == 249) {
                        this.f8765.f8753 = new C2832();
                        m4962();
                        int iM49623 = m4962();
                        C2832 c2832 = this.f8765.f8753;
                        int i2 = (iM49623 & 28) >> 2;
                        c2832.f8745 = i2;
                        if (i2 == 0) {
                            c2832.f8745 = 1;
                        }
                        this.f8765.f8753.f8744 = (iM49623 & 1) != 0;
                        int iM4964 = m4964();
                        if (iM4964 < 2) {
                            iM4964 = 10;
                        }
                        C2832 c28322 = this.f8765.f8753;
                        c28322.f8747 = iM4964 * 10;
                        c28322.f8746 = m4962();
                        m4962();
                    } else if (iM49622 == 254) {
                        m4965();
                    } else if (iM49622 != 255) {
                        m4965();
                    } else {
                        m4963();
                        StringBuilder sb2 = new StringBuilder();
                        for (int i3 = 0; i3 < 11; i3++) {
                            sb2.append((char) this.f8763[i3]);
                        }
                        if (sb2.toString().equals("NETSCAPE2.0")) {
                            do {
                                m4963();
                                byte[] bArr = this.f8763;
                                if (bArr[0] == 1) {
                                    this.f8765.f8762 = ((bArr[2] & 255) << 8) | (bArr[1] & 255);
                                }
                                if (this.f8766 > 0) {
                                }
                            } while (!m4959());
                        } else {
                            m4965();
                        }
                    }
                } else if (iM4962 == 44) {
                    C2833 c28333 = this.f8765;
                    if (c28333.f8753 == null) {
                        c28333.f8753 = new C2832();
                    }
                    this.f8765.f8753.f8739 = m4964();
                    this.f8765.f8753.f8740 = m4964();
                    this.f8765.f8753.f8741 = m4964();
                    this.f8765.f8753.f8742 = m4964();
                    int iM49624 = m4962();
                    boolean z2 = (iM49624 & 128) != 0;
                    int iPow = (int) Math.pow(2.0d, (iM49624 & 7) + 1);
                    this.f8765.f8753.f8743 = (iM49624 & 64) != 0;
                    if (z2) {
                        this.f8765.f8753.f8749 = m4960(iPow);
                    } else {
                        this.f8765.f8753.f8749 = null;
                    }
                    this.f8765.f8753.f8748 = this.f8764.position();
                    m4962();
                    m4965();
                    if (!m4959()) {
                        C2833 c28334 = this.f8765;
                        c28334.f8752++;
                        c28334.f8754.add(c28334.f8753);
                    }
                } else if (iM4962 != 59) {
                    this.f8765.f8751 = 1;
                } else {
                    z = true;
                }
            }
            C2833 c28335 = this.f8765;
            if (c28335.f8752 < 0) {
                c28335.f8751 = 1;
            }
        }
        return this.f8765;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final int m4962() {
        try {
            return this.f8764.get() & 255;
        } catch (Exception unused) {
            this.f8765.f8751 = 1;
            return 0;
        }
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final void m4963() {
        int iM4962 = m4962();
        this.f8766 = iM4962;
        if (iM4962 > 0) {
            int i = 0;
            int i2 = 0;
            while (i < this.f8766) {
                try {
                    i2 = this.f8766 - i;
                    this.f8764.get(this.f8763, i, i2);
                    i += i2;
                } catch (Exception e) {
                    if (Log.isLoggable("GifHeaderParser", 3)) {
                        StringBuilder sbM4890 = C2803.m4890("Error Reading Block n: ", i, " count: ", i2, " blockSize: ");
                        sbM4890.append(this.f8766);
                        Log.d("GifHeaderParser", sbM4890.toString(), e);
                    }
                    this.f8765.f8751 = 1;
                    return;
                }
            }
        }
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final int m4964() {
        return this.f8764.getShort();
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final void m4965() {
        int iM4962;
        do {
            iM4962 = m4962();
            this.f8764.position(Math.min(this.f8764.position() + iM4962, this.f8764.limit()));
        } while (iM4962 > 0);
    }
}
