package ඓ.ῲ.K.㳳;

import android.graphics.Bitmap;
import android.util.Log;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.progressindicator.BaseProgressIndicator;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Iterator;
import ඓ.ῲ.K.ᕣ.ᕣ.ⁱ.C0905;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0967;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.C0964;
import ඓ.ῲ.K.㳳.AbstractC1215;

/* renamed from: ඓ.ῲ.K.㳳.ඓ  reason: contains not printable characters */
/* compiled from: StandardGifDecoder */
public class C1213 implements AbstractC1215 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC1215.AbstractC1216 f4795;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public boolean f4796;

    /* renamed from: ؿ  reason: contains not printable characters */
    public int f4797;

    /* renamed from: ݜ  reason: contains not printable characters */
    public Boolean f4798;

    /* renamed from: ඓ  reason: contains not printable characters */
    public byte[] f4799;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public int f4800;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public int f4801;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public byte[] f4802;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final int[] f4803 = new int[256];

    /* renamed from: ⁱ  reason: contains not printable characters */
    public byte[] f4804;

    /* renamed from: K  reason: contains not printable characters */
    public int[] f4805;

    /* renamed from: 㑃  reason: contains not printable characters */
    public C1212 f4806;

    /* renamed from: 㗗  reason: contains not printable characters */
    public int f4807;

    /* renamed from: 㗽  reason: contains not printable characters */
    public int f4808;

    /* renamed from: 㳳  reason: contains not printable characters */
    public int[] f4809;

    /* renamed from: 㴹  reason: contains not printable characters */
    public short[] f4810;

    /* renamed from: 㸾  reason: contains not printable characters */
    public ByteBuffer f4811;

    /* renamed from: 㿎  reason: contains not printable characters */
    public byte[] f4812;

    /* renamed from: 䀟  reason: contains not printable characters */
    public Bitmap.Config f4813 = Bitmap.Config.ARGB_8888;

    /* renamed from: 䁗  reason: contains not printable characters */
    public Bitmap f4814;

    public C1213(AbstractC1215.AbstractC1216 k, C1212 r3, ByteBuffer byteBuffer, int i) {
        this.f4795 = k;
        this.f4806 = new C1212();
        m3278(r3, byteBuffer, i);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public synchronized Bitmap m3274() {
        if (this.f4806.f4782 <= 0 || this.f4801 < 0) {
            if (Log.isLoggable("ඓ", 3)) {
                Log.d("ඓ", "Unable to decode frame, frameCount=" + this.f4806.f4782 + ", framePointer=" + this.f4801);
            }
            this.f4807 = 1;
        }
        if (this.f4807 != 1) {
            if (this.f4807 != 2) {
                this.f4807 = 0;
                if (this.f4799 == null) {
                    this.f4799 = ((C0905) this.f4795).m2593(BaseProgressIndicator.MAX_ALPHA);
                }
                C1214 r5 = this.f4806.f4783.get(this.f4801);
                int i = this.f4801 - 1;
                C1214 r6 = i >= 0 ? this.f4806.f4783.get(i) : null;
                this.f4805 = r5.f4817 != null ? r5.f4817 : this.f4806.f4788;
                if (this.f4805 == null) {
                    if (Log.isLoggable("ඓ", 3)) {
                        Log.d("ඓ", "No valid color table found for frame #" + this.f4801);
                    }
                    this.f4807 = 1;
                    return null;
                }
                if (r5.f4823) {
                    System.arraycopy(this.f4805, 0, this.f4803, 0, this.f4805.length);
                    this.f4805 = this.f4803;
                    this.f4805[r5.f4825] = 0;
                    if (r5.f4820 == 2 && this.f4801 == 0) {
                        this.f4798 = true;
                    }
                }
                return m3276(r5, r6);
            }
        }
        if (Log.isLoggable("ඓ", 3)) {
            Log.d("ඓ", "Unable to decode frame, status=" + this.f4807);
        }
        return null;
    }

    /* renamed from: K  reason: contains not printable characters */
    public synchronized void m3278(C1212 r3, ByteBuffer byteBuffer, int i) {
        int[] iArr;
        if (i > 0) {
            int highestOneBit = Integer.highestOneBit(i);
            this.f4807 = 0;
            this.f4806 = r3;
            this.f4801 = -1;
            this.f4811 = byteBuffer.asReadOnlyBuffer();
            this.f4811.position(0);
            this.f4811.order(ByteOrder.LITTLE_ENDIAN);
            this.f4796 = false;
            Iterator<C1214> it2 = r3.f4783.iterator();
            while (true) {
                if (it2.hasNext()) {
                    if (it2.next().f4820 == 3) {
                        this.f4796 = true;
                        break;
                    }
                } else {
                    break;
                }
            }
            this.f4797 = highestOneBit;
            int i2 = r3.f4791;
            this.f4808 = i2 / highestOneBit;
            int i3 = r3.f4787;
            this.f4800 = i3 / highestOneBit;
            this.f4802 = ((C0905) this.f4795).m2593(i2 * i3);
            AbstractC1215.AbstractC1216 k = this.f4795;
            int i4 = this.f4808 * this.f4800;
            AbstractC0967 r32 = ((C0905) k).f4169;
            if (r32 == null) {
                iArr = new int[i4];
            } else {
                iArr = (int[]) ((C0964) r32).m2735(i4, int[].class);
            }
            this.f4809 = iArr;
        } else {
            throw new IllegalArgumentException("Sample size must be >=0, not: " + i);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m3277(Bitmap.Config config) {
        if (config == Bitmap.Config.ARGB_8888 || config == Bitmap.Config.RGB_565) {
            this.f4813 = config;
            return;
        }
        throw new IllegalArgumentException("Unsupported format: " + config + ", must be one of " + Bitmap.Config.ARGB_8888 + " or " + Bitmap.Config.RGB_565);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:23:0x0045, code lost:
        if (r3.f4790 == r37.f4825) goto L_0x0047;
     */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x0060  */
    /* renamed from: K  reason: contains not printable characters */
    public final Bitmap m3276(C1214 r37, C1214 r38) {
        int i;
        int i2;
        int[] iArr;
        int i3;
        boolean z;
        int i4;
        int i5;
        int i6;
        int i7;
        int i8;
        int i9;
        int i10;
        int i11;
        int i12;
        int i13;
        int i14;
        int i15;
        int i16;
        byte[] bArr;
        short s;
        int i17;
        Bitmap bitmap;
        int i18;
        int i19;
        int i20;
        int[] iArr2 = this.f4809;
        if (r38 == null) {
            Bitmap bitmap2 = this.f4814;
            if (bitmap2 != null) {
                ((C0905) this.f4795).f4170.m2772(bitmap2);
            }
            this.f4814 = null;
            Arrays.fill(iArr2, 0);
        }
        if (r38 != null && r38.f4820 == 3 && this.f4814 == null) {
            Arrays.fill(iArr2, 0);
        }
        if (r38 != null && (i17 = r38.f4820) > 0) {
            if (i17 == 2) {
                if (!r37.f4823) {
                    C1212 r3 = this.f4806;
                    i18 = r3.f4789;
                    if (r37.f4817 != null) {
                    }
                    int i21 = r38.f4824;
                    int i22 = this.f4797;
                    int i23 = i21 / i22;
                    int i24 = r38.f4819 / i22;
                    int i25 = r38.f4815 / i22;
                    int i26 = r38.f4821 / i22;
                    int i27 = this.f4808;
                    i19 = (i24 * i27) + i26;
                    i20 = (i23 * i27) + i19;
                    while (i19 < i20) {
                        int i28 = i19 + i25;
                        for (int i29 = i19; i29 < i28; i29++) {
                            iArr2[i29] = i18;
                        }
                        i19 += this.f4808;
                    }
                }
                i18 = 0;
                int i212 = r38.f4824;
                int i222 = this.f4797;
                int i232 = i212 / i222;
                int i242 = r38.f4819 / i222;
                int i252 = r38.f4815 / i222;
                int i262 = r38.f4821 / i222;
                int i272 = this.f4808;
                i19 = (i242 * i272) + i262;
                i20 = (i232 * i272) + i19;
                while (i19 < i20) {
                }
            } else if (i17 == 3 && (bitmap = this.f4814) != null) {
                int i30 = this.f4808;
                bitmap.getPixels(iArr2, 0, i30, 0, 0, i30, this.f4800);
            }
        }
        if (r37 != null) {
            this.f4811.position(r37.f4822);
        }
        if (r37 == null) {
            C1212 r2 = this.f4806;
            i = r2.f4791;
            i2 = r2.f4787;
        } else {
            i = r37.f4815;
            i2 = r37.f4824;
        }
        int i31 = i * i2;
        byte[] bArr2 = this.f4802;
        if (bArr2 == null || bArr2.length < i31) {
            this.f4802 = ((C0905) this.f4795).m2593(i31);
        }
        byte[] bArr3 = this.f4802;
        if (this.f4810 == null) {
            this.f4810 = new short[RecyclerView.AbstractC0269.FLAG_APPEARED_IN_PRE_LAYOUT];
        }
        short[] sArr = this.f4810;
        if (this.f4804 == null) {
            this.f4804 = new byte[RecyclerView.AbstractC0269.FLAG_APPEARED_IN_PRE_LAYOUT];
        }
        byte[] bArr4 = this.f4804;
        if (this.f4812 == null) {
            this.f4812 = new byte[4097];
        }
        byte[] bArr5 = this.f4812;
        int i32 = this.f4811.get() & 255;
        int i33 = 1 << i32;
        int i34 = i33 + 1;
        int i35 = i33 + 2;
        int i36 = i32 + 1;
        int i37 = (1 << i36) - 1;
        for (int i38 = 0; i38 < i33; i38++) {
            sArr[i38] = 0;
            bArr4[i38] = (byte) i38;
        }
        byte[] bArr6 = this.f4799;
        C1213 r9 = this;
        int i39 = i36;
        int i40 = i35;
        int i41 = i37;
        int i42 = 0;
        int i43 = 0;
        int i44 = 0;
        int i45 = 0;
        int i46 = 0;
        short s2 = -1;
        int i47 = 0;
        int i48 = 0;
        int i49 = 0;
        while (true) {
            if (i42 >= i31) {
                iArr = iArr2;
                break;
            }
            if (i43 == 0) {
                int i50 = this.f4811.get() & 255;
                if (i50 <= 0) {
                    i16 = i36;
                    iArr = iArr2;
                    i15 = i42;
                } else {
                    ByteBuffer byteBuffer = r9.f4811;
                    i16 = i36;
                    i15 = i42;
                    iArr = iArr2;
                    byteBuffer.get(r9.f4799, 0, Math.min(i50, byteBuffer.remaining()));
                }
                if (i50 <= 0) {
                    r9.f4807 = 3;
                    break;
                }
                i43 = i50;
                i46 = 0;
            } else {
                i16 = i36;
                iArr = iArr2;
                i15 = i42;
            }
            i45 += (bArr6[i46] & 255) << i44;
            i46++;
            i43--;
            C1213 r18 = r9;
            int i51 = i44 + 8;
            short s3 = s2;
            int i52 = i47;
            int i53 = i40;
            int i54 = i39;
            while (true) {
                if (i51 < i54) {
                    bArr = bArr6;
                    i44 = i51;
                    r9 = this;
                    break;
                }
                int i55 = i45 & i41;
                i45 >>= i54;
                i51 -= i54;
                if (i55 == i33) {
                    i53 = i35;
                    i41 = i37;
                    i54 = i16;
                    s3 = -1;
                } else {
                    bArr = bArr6;
                    if (i55 == i34) {
                        i44 = i51;
                        r9 = r18;
                        break;
                    }
                    if (s3 == -1) {
                        bArr3[i48] = bArr4[i55];
                        i48++;
                        i15++;
                        i52 = i55;
                    } else {
                        if (i55 >= i53) {
                            bArr5[i49] = (byte) i52;
                            i49++;
                            s = s3;
                        } else {
                            s = i55;
                        }
                        while (s >= i33) {
                            bArr5[i49] = bArr4[s];
                            i49++;
                            s = sArr[s];
                        }
                        int i56 = bArr4[s] & 255;
                        byte b = (byte) i56;
                        bArr3[i48] = b;
                        while (true) {
                            i48++;
                            i15++;
                            if (i49 <= 0) {
                                break;
                            }
                            i49--;
                            bArr3[i48] = bArr5[i49];
                        }
                        if (i53 < 4096) {
                            sArr[i53] = (short) s3;
                            bArr4[i53] = b;
                            i53++;
                            if ((i53 & i41) == 0 && i53 < 4096) {
                                i54++;
                                i41 += i53;
                            }
                        }
                        i52 = i56;
                    }
                    r18 = this;
                    s3 = i55;
                    bArr6 = bArr;
                }
            }
            i39 = i54;
            i47 = i52;
            i40 = i53;
            bArr6 = bArr;
            i36 = i16;
            iArr2 = iArr;
            s2 = s3;
            i42 = i15;
        }
        Arrays.fill(bArr3, i48, i31, (byte) 0);
        if (r37.f4816 || this.f4797 != 1) {
            int[] iArr3 = this.f4809;
            int i57 = r37.f4824;
            int i58 = this.f4797;
            int i59 = i57 / i58;
            int i60 = r37.f4819 / i58;
            int i61 = r37.f4815 / i58;
            int i62 = r37.f4821 / i58;
            boolean z2 = this.f4801 == 0;
            int i63 = this.f4797;
            int i64 = this.f4808;
            int i65 = this.f4800;
            byte[] bArr7 = this.f4802;
            int[] iArr4 = this.f4805;
            Boolean bool = this.f4798;
            int i66 = 0;
            int i67 = 0;
            int i68 = 1;
            int i69 = 8;
            while (i67 < i59) {
                Boolean bool2 = bool;
                if (r37.f4816) {
                    if (i66 >= i59) {
                        i14 = i68 + 1;
                        i4 = i59;
                        if (i14 == 2) {
                            i66 = 4;
                        } else if (i14 == 3) {
                            i66 = 2;
                            i69 = 4;
                        } else if (i14 == 4) {
                            i66 = 1;
                            i69 = 2;
                        }
                    } else {
                        i4 = i59;
                        i14 = i68;
                    }
                    i5 = i66 + i69;
                    i68 = i14;
                } else {
                    i4 = i59;
                    i5 = i66;
                    i66 = i67;
                }
                int i70 = i66 + i60;
                boolean z3 = i63 == 1;
                if (i70 < i65) {
                    int i71 = i70 * i64;
                    int i72 = i71 + i62;
                    i11 = i5;
                    int i73 = i72 + i61;
                    int i74 = i71 + i64;
                    if (i74 < i73) {
                        i73 = i74;
                    }
                    i10 = i60;
                    int i75 = i67 * i63 * r37.f4815;
                    if (z3) {
                        int i76 = i75;
                        Boolean bool3 = bool2;
                        int i77 = i72;
                        while (i77 < i73) {
                            int i78 = iArr4[bArr7[i76] & 255];
                            if (i78 != 0) {
                                iArr3[i77] = i78;
                            } else if (z2 && bool3 == null) {
                                bool3 = true;
                            }
                            i76 += i63;
                            i77++;
                            i61 = i61;
                        }
                        i9 = i61;
                        i8 = i62;
                        bool2 = bool3;
                    } else {
                        i9 = i61;
                        int i79 = ((i73 - i72) * i63) + i75;
                        int i80 = i75;
                        Boolean bool4 = bool2;
                        int i81 = i72;
                        while (i81 < i73) {
                            int i82 = r37.f4815;
                            int i83 = i80;
                            int i84 = 0;
                            int i85 = 0;
                            int i86 = 0;
                            int i87 = 0;
                            int i88 = 0;
                            while (true) {
                                if (i83 >= this.f4797 + i80) {
                                    i12 = i65;
                                    break;
                                }
                                byte[] bArr8 = this.f4802;
                                i12 = i65;
                                if (i83 >= bArr8.length || i83 >= i79) {
                                    break;
                                }
                                int i89 = this.f4805[bArr8[i83] & 255];
                                if (i89 != 0) {
                                    i84 += (i89 >> 24) & BaseProgressIndicator.MAX_ALPHA;
                                    i85 += (i89 >> 16) & BaseProgressIndicator.MAX_ALPHA;
                                    i86 += (i89 >> 8) & BaseProgressIndicator.MAX_ALPHA;
                                    i87 += i89 & BaseProgressIndicator.MAX_ALPHA;
                                    i88++;
                                }
                                i83++;
                                i65 = i12;
                            }
                            int i90 = i82 + i80;
                            for (int i91 = i90; i91 < this.f4797 + i90; i91++) {
                                byte[] bArr9 = this.f4802;
                                if (i91 >= bArr9.length || i91 >= i79) {
                                    break;
                                }
                                int i92 = this.f4805[bArr9[i91] & 255];
                                if (i92 != 0) {
                                    i84 += (i92 >> 24) & BaseProgressIndicator.MAX_ALPHA;
                                    i85 += (i92 >> 16) & BaseProgressIndicator.MAX_ALPHA;
                                    i86 += (i92 >> 8) & BaseProgressIndicator.MAX_ALPHA;
                                    i87 += i92 & BaseProgressIndicator.MAX_ALPHA;
                                    i88++;
                                }
                            }
                            if (i88 == 0) {
                                i13 = 0;
                            } else {
                                i13 = ((i84 / i88) << 24) | ((i85 / i88) << 16) | ((i86 / i88) << 8) | (i87 / i88);
                            }
                            if (i13 != 0) {
                                iArr3[i81] = i13;
                            } else if (z2 && bool4 == null) {
                                bool4 = true;
                            }
                            i80 += i63;
                            i81++;
                            i73 = i73;
                            i62 = i62;
                            i64 = i64;
                            i65 = i12;
                        }
                        i8 = i62;
                        i7 = i64;
                        i6 = i65;
                        bool = bool4;
                        i67++;
                        i59 = i4;
                        i66 = i11;
                        i60 = i10;
                        i61 = i9;
                        i62 = i8;
                        i64 = i7;
                        i65 = i6;
                    }
                } else {
                    i11 = i5;
                    i10 = i60;
                    i9 = i61;
                    i8 = i62;
                }
                i7 = i64;
                i6 = i65;
                bool = bool2;
                i67++;
                i59 = i4;
                i66 = i11;
                i60 = i10;
                i61 = i9;
                i62 = i8;
                i64 = i7;
                i65 = i6;
            }
            if (this.f4798 == null) {
                if (bool == null) {
                    z = false;
                } else {
                    z = bool.booleanValue();
                }
                this.f4798 = Boolean.valueOf(z);
            }
        } else {
            int[] iArr5 = this.f4809;
            int i93 = r37.f4824;
            int i94 = r37.f4819;
            int i95 = r37.f4815;
            int i96 = r37.f4821;
            boolean z4 = this.f4801 == 0;
            int i97 = this.f4808;
            byte[] bArr10 = this.f4802;
            int[] iArr6 = this.f4805;
            byte b2 = -1;
            for (int i98 = 0; i98 < i93; i98++) {
                int i99 = (i98 + i94) * i97;
                int i100 = i99 + i96;
                int i101 = i100 + i95;
                int i102 = i99 + i97;
                if (i102 >= i101) {
                    i102 = i101;
                }
                int i103 = r37.f4815 * i98;
                while (i100 < i102) {
                    byte b3 = bArr10[i103];
                    int i104 = b3 & 255;
                    if (i104 != b2) {
                        int i105 = iArr6[i104];
                        if (i105 != 0) {
                            iArr5[i100] = i105;
                        } else {
                            b2 = b3;
                        }
                    }
                    i103++;
                    i100++;
                    i93 = i93;
                    i94 = i94;
                }
            }
            Boolean bool5 = this.f4798;
            this.f4798 = Boolean.valueOf((bool5 != null && bool5.booleanValue()) || (this.f4798 == null && z4 && b2 != -1));
        }
        if (this.f4796 && ((i3 = r37.f4820) == 0 || i3 == 1)) {
            if (this.f4814 == null) {
                this.f4814 = m3275();
            }
            Bitmap bitmap3 = this.f4814;
            int i106 = this.f4808;
            bitmap3.setPixels(iArr, 0, i106, 0, 0, i106, this.f4800);
        }
        Bitmap r92 = m3275();
        int i107 = this.f4808;
        r92.setPixels(iArr, 0, i107, 0, 0, i107, this.f4800);
        return r92;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final Bitmap m3275() {
        Boolean bool = this.f4798;
        Bitmap.Config config = (bool == null || bool.booleanValue()) ? Bitmap.Config.ARGB_8888 : this.f4813;
        Bitmap r0 = ((C0905) this.f4795).f4170.m2768(this.f4808, this.f4800, config);
        r0.setHasAlpha(true);
        return r0;
    }
}
