package p138.p145.p146.p148;

import android.graphics.Bitmap;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Iterator;
import p138.p145.p146.p148.InterfaceC2830;
import p138.p145.p146.p151.p154.p155.InterfaceC2940;
import p138.p145.p146.p151.p160.p165.C3141;

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int[] f8767;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final InterfaceC2830.InterfaceC2831 f8769;

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

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public byte[] f8771;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public short[] f8772;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public byte[] f8773;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public byte[] f8774;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public byte[] f8775;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public int[] f8776;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public int f8777;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public Bitmap f8779;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public boolean f8780;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public int f8781;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public int f8782;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public int f8783;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public int f8784;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public Boolean f8785;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final int[] f8768 = new int[256];

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public Bitmap.Config f8786 = Bitmap.Config.ARGB_8888;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public C2833 f8778 = new C2833();

    public C2835(InterfaceC2830.InterfaceC2831 interfaceC2831, C2833 c2833, ByteBuffer byteBuffer, int i) {
        this.f8769 = interfaceC2831;
        m4967(c2833, byteBuffer, i);
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    public void clear() {
        InterfaceC2940 interfaceC2940;
        InterfaceC2940 interfaceC29402;
        InterfaceC2940 interfaceC29403;
        this.f8778 = null;
        byte[] bArr = this.f8775;
        if (bArr != null && (interfaceC29403 = ((C3141) this.f8769).f9377) != null) {
            interfaceC29403.mo5080(bArr);
        }
        int[] iArr = this.f8776;
        if (iArr != null && (interfaceC29402 = ((C3141) this.f8769).f9377) != null) {
            interfaceC29402.mo5080(iArr);
        }
        Bitmap bitmap = this.f8779;
        if (bitmap != null) {
            ((C3141) this.f8769).f9376.mo5088(bitmap);
        }
        this.f8779 = null;
        this.f8770 = null;
        this.f8785 = null;
        byte[] bArr2 = this.f8771;
        if (bArr2 == null || (interfaceC2940 = ((C3141) this.f8769).f9377) == null) {
            return;
        }
        interfaceC2940.mo5080(bArr2);
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ֏ */
    public int mo4950() {
        return this.f8777;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0047  */
    /* JADX WARN: Type inference failed for: r5v28 */
    /* JADX WARN: Type inference failed for: r5v29 */
    /* JADX WARN: Type inference failed for: r5v30 */
    /* JADX WARN: Type inference failed for: r5v35, types: [short] */
    /* JADX WARN: Type inference failed for: r5v37 */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Bitmap m4966(C2832 c2832, C2832 c28322) {
        int i;
        int i2;
        int[] iArr;
        int i3;
        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;
        int i17;
        short s;
        int i18;
        Bitmap bitmap;
        int[] iArr2 = this.f8776;
        if (c28322 == null) {
            Bitmap bitmap2 = this.f8779;
            if (bitmap2 != null) {
                ((C3141) this.f8769).f9376.mo5088(bitmap2);
            }
            this.f8779 = null;
            Arrays.fill(iArr2, 0);
        }
        if (c28322 != null && c28322.f8745 == 3 && this.f8779 == null) {
            Arrays.fill(iArr2, 0);
        }
        if (c28322 != null && (i18 = c28322.f8745) > 0) {
            if (i18 == 2) {
                if (!c2832.f8744) {
                    C2833 c2833 = this.f8778;
                    int i19 = c2833.f8761;
                    if (c2832.f8749 != null && c2833.f8759 == c2832.f8746) {
                        i19 = 0;
                    }
                    int i20 = c28322.f8742;
                    int i21 = this.f8782;
                    int i22 = i20 / i21;
                    int i23 = c28322.f8740 / i21;
                    int i24 = c28322.f8741 / i21;
                    int i25 = c28322.f8739 / i21;
                    int i26 = this.f8784;
                    int i27 = (i23 * i26) + i25;
                    int i28 = (i22 * i26) + i27;
                    while (i27 < i28) {
                        int i29 = i27 + i24;
                        for (int i30 = i27; i30 < i29; i30++) {
                            iArr2[i30] = i19;
                        }
                        i27 += this.f8784;
                    }
                }
            } else if (i18 == 3 && (bitmap = this.f8779) != null) {
                int i31 = this.f8784;
                bitmap.getPixels(iArr2, 0, i31, 0, 0, i31, this.f8783);
            }
        }
        if (c2832 != null) {
            this.f8770.position(c2832.f8748);
        }
        if (c2832 == null) {
            C2833 c28332 = this.f8778;
            i = c28332.f8755;
            i2 = c28332.f8756;
        } else {
            i = c2832.f8741;
            i2 = c2832.f8742;
        }
        int i32 = i * i2;
        byte[] bArr = this.f8775;
        if (bArr == null || bArr.length < i32) {
            this.f8775 = ((C3141) this.f8769).m5212(i32);
        }
        byte[] bArr2 = this.f8775;
        if (this.f8772 == null) {
            this.f8772 = new short[4096];
        }
        short[] sArr = this.f8772;
        if (this.f8773 == null) {
            this.f8773 = new byte[4096];
        }
        byte[] bArr3 = this.f8773;
        if (this.f8774 == null) {
            this.f8774 = new byte[4097];
        }
        byte[] bArr4 = this.f8774;
        int i33 = this.f8770.get() & 255;
        int i34 = 1 << i33;
        int i35 = i34 + 1;
        int i36 = i34 + 2;
        int i37 = i33 + 1;
        int i38 = (1 << i37) - 1;
        for (int i39 = 0; i39 < i34; i39++) {
            sArr[i39] = 0;
            bArr3[i39] = (byte) i39;
        }
        byte[] bArr5 = this.f8771;
        C2835 c2835 = this;
        int i40 = i37;
        int i41 = i36;
        int i42 = i38;
        int i43 = 0;
        int i44 = -1;
        int i45 = 0;
        int i46 = 0;
        int i47 = 0;
        int i48 = 0;
        int i49 = 0;
        int i50 = 0;
        int i51 = 0;
        while (true) {
            if (i43 >= i32) {
                iArr = iArr2;
                break;
            }
            if (i45 == 0) {
                int i52 = c2835.f8770.get() & 255;
                if (i52 <= 0) {
                    i13 = i37;
                    i14 = i43;
                    iArr = iArr2;
                    i15 = i44;
                } else {
                    i13 = i37;
                    ByteBuffer byteBuffer = c2835.f8770;
                    i14 = i43;
                    i15 = i44;
                    iArr = iArr2;
                    byteBuffer.get(c2835.f8771, 0, Math.min(i52, byteBuffer.remaining()));
                }
                if (i52 <= 0) {
                    c2835.f8781 = 3;
                    break;
                }
                i45 = i52;
                i46 = 0;
            } else {
                i13 = i37;
                i14 = i43;
                iArr = iArr2;
                i15 = i44;
            }
            i48 += (bArr5[i46] & 255) << i47;
            i46++;
            i45--;
            int i53 = i47 + 8;
            int i54 = i41;
            int i55 = i40;
            i43 = i14;
            i44 = i15;
            byte[] bArr6 = bArr5;
            int i56 = i49;
            while (true) {
                if (i53 < i55) {
                    i16 = i56;
                    c2835 = this;
                    break;
                }
                C2835 c28352 = c2835;
                int i57 = i48 & i42;
                i48 >>= i55;
                i53 -= i55;
                if (i57 == i34) {
                    i17 = i53;
                    i54 = i36;
                    i42 = i38;
                    c2835 = c28352;
                    i55 = i13;
                    i44 = -1;
                } else {
                    if (i57 == i35) {
                        c2835 = c28352;
                        i16 = i56;
                        break;
                    }
                    i17 = i53;
                    if (i44 == -1) {
                        bArr2[i50] = bArr3[i57];
                        i50++;
                        i43++;
                        i56 = i57;
                        i44 = i56;
                        c2835 = this;
                    } else {
                        if (i57 >= i54) {
                            bArr4[i51] = (byte) i56;
                            i51++;
                            s = i44;
                        } else {
                            s = i57;
                        }
                        while (s >= i34) {
                            bArr4[i51] = bArr3[s];
                            i51++;
                            s = sArr[s];
                        }
                        int i58 = bArr3[s] & 255;
                        byte b = (byte) i58;
                        bArr2[i50] = b;
                        while (true) {
                            i50++;
                            i43++;
                            if (i51 <= 0) {
                                break;
                            }
                            i51--;
                            bArr2[i50] = bArr4[i51];
                        }
                        if (i54 < 4096) {
                            sArr[i54] = (short) i44;
                            bArr3[i54] = b;
                            i54++;
                            if ((i54 & i42) == 0 && i54 < 4096) {
                                i55++;
                                i42 += i54;
                            }
                        }
                        i44 = i57;
                        i56 = i58;
                        i53 = i17;
                        c2835 = this;
                    }
                }
                i53 = i17;
            }
            i40 = i55;
            bArr5 = bArr6;
            i49 = i16;
            i37 = i13;
            i47 = i53;
            i41 = i54;
            iArr2 = iArr;
        }
        Arrays.fill(bArr2, i50, i32, (byte) 0);
        if (c2832.f8743 || this.f8782 != 1) {
            int[] iArr3 = this.f8776;
            int i59 = c2832.f8742;
            int i60 = this.f8782;
            int i61 = i59 / i60;
            int i62 = c2832.f8740 / i60;
            int i63 = c2832.f8741 / i60;
            int i64 = c2832.f8739 / i60;
            boolean z = this.f8777 == 0;
            int i65 = this.f8782;
            int i66 = this.f8784;
            int i67 = this.f8783;
            byte[] bArr7 = this.f8775;
            int[] iArr4 = this.f8767;
            Boolean bool = this.f8785;
            int i68 = 0;
            int i69 = 0;
            int i70 = 1;
            int i71 = 8;
            while (i69 < i61) {
                Boolean bool2 = bool;
                if (c2832.f8743) {
                    if (i68 >= i61) {
                        int i72 = i70 + 1;
                        i3 = i61;
                        if (i72 == 2) {
                            i70 = i72;
                            i68 = 4;
                        } else if (i72 != 3) {
                            i70 = i72;
                            if (i72 == 4) {
                                i68 = 1;
                                i71 = 2;
                            }
                        } else {
                            i70 = i72;
                            i68 = 2;
                            i71 = 4;
                        }
                    } else {
                        i3 = i61;
                    }
                    i4 = i68 + i71;
                } else {
                    i3 = i61;
                    i4 = i68;
                    i68 = i69;
                }
                int i73 = i68 + i62;
                boolean z2 = i65 == 1;
                if (i73 < i67) {
                    int i74 = i73 * i66;
                    int i75 = i74 + i64;
                    i5 = i4;
                    int i76 = i75 + i63;
                    int i77 = i74 + i66;
                    if (i77 < i76) {
                        i76 = i77;
                    }
                    i6 = i62;
                    int i78 = i69 * i65 * c2832.f8741;
                    if (z2) {
                        bool = bool2;
                        int i79 = i75;
                        while (true) {
                            i7 = i63;
                            if (i79 >= i76) {
                                break;
                            }
                            int i80 = iArr4[bArr7[i78] & 255];
                            if (i80 != 0) {
                                iArr3[i79] = i80;
                            } else if (z && bool == null) {
                                bool = true;
                            }
                            i78 += i65;
                            i79++;
                            i63 = i7;
                        }
                    } else {
                        i7 = i63;
                        int i81 = ((i76 - i75) * i65) + i78;
                        bool = bool2;
                        int i82 = i75;
                        while (i82 < i76) {
                            int i83 = i76;
                            int i84 = c2832.f8741;
                            int i85 = i64;
                            int i86 = i66;
                            int i87 = i78;
                            int i88 = 0;
                            int i89 = 0;
                            int i90 = 0;
                            int i91 = 0;
                            int i92 = 0;
                            while (true) {
                                if (i87 >= this.f8782 + i78) {
                                    i11 = i67;
                                    break;
                                }
                                byte[] bArr8 = this.f8775;
                                i11 = i67;
                                if (i87 >= bArr8.length || i87 >= i81) {
                                    break;
                                }
                                int i93 = this.f8767[bArr8[i87] & 255];
                                if (i93 != 0) {
                                    i88 += (i93 >> 24) & 255;
                                    i89 += (i93 >> 16) & 255;
                                    i90 += (i93 >> 8) & 255;
                                    i91 += i93 & 255;
                                    i92++;
                                }
                                i87++;
                                i67 = i11;
                            }
                            int i94 = i84 + i78;
                            for (int i95 = i94; i95 < this.f8782 + i94; i95++) {
                                byte[] bArr9 = this.f8775;
                                if (i95 >= bArr9.length || i95 >= i81) {
                                    break;
                                }
                                int i96 = this.f8767[bArr9[i95] & 255];
                                if (i96 != 0) {
                                    i88 += (i96 >> 24) & 255;
                                    i89 += (i96 >> 16) & 255;
                                    i90 += (i96 >> 8) & 255;
                                    i91 += i96 & 255;
                                    i92++;
                                }
                            }
                            int i97 = i92 == 0 ? 0 : ((i88 / i92) << 24) | ((i89 / i92) << 16) | ((i90 / i92) << 8) | (i91 / i92);
                            if (i97 != 0) {
                                iArr3[i82] = i97;
                            } else if (z && bool == null) {
                                bool = true;
                            }
                            i78 += i65;
                            i82++;
                            i76 = i83;
                            i64 = i85;
                            i66 = i86;
                            i67 = i11;
                        }
                    }
                    i8 = i64;
                    i9 = i66;
                    i10 = i67;
                } else {
                    i5 = i4;
                    i6 = i62;
                    i7 = i63;
                    i8 = i64;
                    i9 = i66;
                    i10 = i67;
                    bool = bool2;
                }
                i69++;
                i61 = i3;
                i68 = i5;
                i62 = i6;
                i63 = i7;
                i64 = i8;
                i66 = i9;
                i67 = i10;
            }
            Boolean bool3 = bool;
            if (this.f8785 == null) {
                this.f8785 = Boolean.valueOf(bool3 == null ? false : bool3.booleanValue());
            }
        } else {
            int[] iArr5 = this.f8776;
            int i98 = c2832.f8742;
            int i99 = c2832.f8740;
            int i100 = c2832.f8741;
            int i101 = c2832.f8739;
            boolean z3 = this.f8777 == 0;
            int i102 = this.f8784;
            byte[] bArr10 = this.f8775;
            int[] iArr6 = this.f8767;
            byte b2 = -1;
            for (int i103 = 0; i103 < i98; i103++) {
                int i104 = (i103 + i99) * i102;
                int i105 = i104 + i101;
                int i106 = i105 + i100;
                int i107 = i104 + i102;
                if (i107 < i106) {
                    i106 = i107;
                }
                int i108 = c2832.f8741 * i103;
                while (i105 < i106) {
                    int i109 = i98;
                    byte b3 = bArr10[i108];
                    int i110 = i99;
                    int i111 = b3 & 255;
                    if (i111 != b2) {
                        int i112 = iArr6[i111];
                        if (i112 != 0) {
                            iArr5[i105] = i112;
                        } else {
                            b2 = b3;
                        }
                    }
                    i108++;
                    i105++;
                    i98 = i109;
                    i99 = i110;
                }
            }
            Boolean bool4 = this.f8785;
            this.f8785 = Boolean.valueOf((bool4 != null && bool4.booleanValue()) || (this.f8785 == null && z3 && b2 != -1));
        }
        if (this.f8780 && ((i12 = c2832.f8745) == 0 || i12 == 1)) {
            if (this.f8779 == null) {
                this.f8779 = m4968();
            }
            Bitmap bitmap3 = this.f8779;
            int i113 = this.f8784;
            bitmap3.setPixels(iArr, 0, i113, 0, 0, i113, this.f8783);
        }
        Bitmap bitmapM4968 = m4968();
        int i114 = this.f8784;
        bitmapM4968.setPixels(iArr, 0, i114, 0, 0, i114, this.f8783);
        return bitmapM4968;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ֏ */
    public void mo4951(Bitmap.Config config) {
        if (config == Bitmap.Config.ARGB_8888 || config == Bitmap.Config.RGB_565) {
            this.f8786 = config;
            return;
        }
        throw new IllegalArgumentException("Unsupported format: " + config + ", must be one of " + Bitmap.Config.ARGB_8888 + " or " + Bitmap.Config.RGB_565);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public synchronized void m4967(C2833 c2833, ByteBuffer byteBuffer, int i) {
        if (i <= 0) {
            throw new IllegalArgumentException("Sample size must be >=0, not: " + i);
        }
        int iHighestOneBit = Integer.highestOneBit(i);
        this.f8781 = 0;
        this.f8778 = c2833;
        this.f8777 = -1;
        ByteBuffer byteBufferAsReadOnlyBuffer = byteBuffer.asReadOnlyBuffer();
        this.f8770 = byteBufferAsReadOnlyBuffer;
        byteBufferAsReadOnlyBuffer.position(0);
        this.f8770.order(ByteOrder.LITTLE_ENDIAN);
        this.f8780 = false;
        Iterator<C2832> it = c2833.f8754.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            } else if (it.next().f8745 == 3) {
                this.f8780 = true;
                break;
            }
        }
        this.f8782 = iHighestOneBit;
        this.f8784 = c2833.f8755 / iHighestOneBit;
        this.f8783 = c2833.f8756 / iHighestOneBit;
        this.f8775 = ((C3141) this.f8769).m5212(c2833.f8755 * c2833.f8756);
        InterfaceC2830.InterfaceC2831 interfaceC2831 = this.f8769;
        int i2 = this.f8784 * this.f8783;
        InterfaceC2940 interfaceC2940 = ((C3141) interfaceC2831).f9377;
        this.f8776 = interfaceC2940 == null ? new int[i2] : (int[]) interfaceC2940.mo5081(i2, int[].class);
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ؠ */
    public synchronized Bitmap mo4952() {
        if (this.f8778.f8752 <= 0 || this.f8777 < 0) {
            if (Log.isLoggable("ނ", 3)) {
                Log.d("ނ", "Unable to decode frame, frameCount=" + this.f8778.f8752 + ", framePointer=" + this.f8777);
            }
            this.f8781 = 1;
        }
        if (this.f8781 != 1 && this.f8781 != 2) {
            this.f8781 = 0;
            if (this.f8771 == null) {
                this.f8771 = ((C3141) this.f8769).m5212(255);
            }
            C2832 c2832 = this.f8778.f8754.get(this.f8777);
            int i = this.f8777 - 1;
            C2832 c28322 = i >= 0 ? this.f8778.f8754.get(i) : null;
            int[] iArr = c2832.f8749 != null ? c2832.f8749 : this.f8778.f8750;
            this.f8767 = iArr;
            if (iArr == null) {
                if (Log.isLoggable("ނ", 3)) {
                    Log.d("ނ", "No valid color table found for frame #" + this.f8777);
                }
                this.f8781 = 1;
                return null;
            }
            if (c2832.f8744) {
                System.arraycopy(iArr, 0, this.f8768, 0, iArr.length);
                int[] iArr2 = this.f8768;
                this.f8767 = iArr2;
                iArr2[c2832.f8746] = 0;
                if (c2832.f8745 == 2 && this.f8777 == 0) {
                    this.f8785 = true;
                }
            }
            return m4966(c2832, c28322);
        }
        if (Log.isLoggable("ނ", 3)) {
            Log.d("ނ", "Unable to decode frame, status=" + this.f8781);
        }
        return null;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ހ */
    public void mo4953() {
        this.f8777 = (this.f8777 + 1) % this.f8778.f8752;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ށ */
    public int mo4954() {
        return this.f8778.f8752;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ނ */
    public int mo4955() {
        int i;
        C2833 c2833 = this.f8778;
        int i2 = c2833.f8752;
        if (i2 <= 0 || (i = this.f8777) < 0) {
            return 0;
        }
        if (i < 0 || i >= i2) {
            return -1;
        }
        return c2833.f8754.get(i).f8747;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ރ */
    public int mo4956() {
        return (this.f8776.length * 4) + this.f8770.limit() + this.f8775.length;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ބ */
    public ByteBuffer mo4957() {
        return this.f8770;
    }

    @Override // p138.p145.p146.p148.InterfaceC2830
    /* JADX INFO: renamed from: ޅ */
    public void mo4958() {
        this.f8777 = -1;
    }

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final Bitmap m4968() {
        Boolean bool = this.f8785;
        Bitmap.Config config = (bool == null || bool.booleanValue()) ? Bitmap.Config.ARGB_8888 : this.f8786;
        Bitmap bitmapMo5089 = ((C3141) this.f8769).f9376.mo5089(this.f8784, this.f8783, config);
        bitmapMo5089.setHasAlpha(true);
        return bitmapMo5089;
    }
}
