package defpackage;

import android.graphics.Bitmap;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;

/* JADX INFO: renamed from: ˏᵴᵢᵶ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1911 {

    /* JADX INFO: renamed from: ˉᵲ, reason: contains not printable characters */
    public Boolean f7579;

    /* JADX INFO: renamed from: ˊᵙᵾᵲ, reason: contains not printable characters */
    public final int f7580;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public byte[] f7581;

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public final boolean f7582;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final ˊˊᵞᵽ f7584;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public Bitmap f7585;

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final int f7586;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public byte[] f7587;

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public int f7588;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public C0379 f7589;

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public final int f7590;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final int[] f7591;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public int[] f7592;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public byte[] f7593;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public int f7594;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public ByteBuffer f7595;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public byte[] f7596;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public short[] f7597;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final int[] f7578 = new int[256];

    /* JADX INFO: renamed from: ˏːˆ, reason: contains not printable characters */
    public Bitmap.Config f7583 = Bitmap.Config.ARGB_8888;

    public C1911(ˊˊᵞᵽ r4, C0379 c0379, ByteBuffer byteBuffer, int i) {
        this.f7584 = r4;
        this.f7589 = new C0379();
        synchronized (this) {
            try {
                if (i <= 0) {
                    throw new IllegalArgumentException("Sample size must be >=0, not: " + i);
                }
                int iHighestOneBit = Integer.highestOneBit(i);
                int i2 = 0;
                this.f7588 = 0;
                this.f7589 = c0379;
                this.f7594 = -1;
                ByteBuffer byteBufferAsReadOnlyBuffer = byteBuffer.asReadOnlyBuffer();
                this.f7595 = byteBufferAsReadOnlyBuffer;
                byteBufferAsReadOnlyBuffer.position(0);
                this.f7595.order(ByteOrder.LITTLE_ENDIAN);
                this.f7582 = false;
                ArrayList arrayList = c0379.f2201;
                int size = arrayList.size();
                while (true) {
                    if (i2 >= size) {
                        break;
                    }
                    Object obj = arrayList.get(i2);
                    i2++;
                    if (((C1585) obj).f6368 == 3) {
                        this.f7582 = true;
                        break;
                    }
                }
                this.f7586 = iHighestOneBit;
                int i3 = c0379.f2208;
                this.f7580 = i3 / iHighestOneBit;
                int i4 = c0379.f2204;
                this.f7590 = i4 / iHighestOneBit;
                int i5 = i3 * i4;
                C5540 c5540 = (C5540) this.f7584.ᵔᵖᵹᵫ;
                this.f7596 = c5540 == null ? new byte[i5] : (byte[]) c5540.m11166(i5, byte[].class);
                ˊˊᵞᵽ r42 = this.f7584;
                int i6 = this.f7580 * this.f7590;
                C5540 c55402 = (C5540) r42.ᵔᵖᵹᵫ;
                this.f7591 = c55402 == null ? new int[i6] : (int[]) c55402.m11166(i6, int[].class);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final synchronized Bitmap m5148() {
        try {
            if (this.f7589.f2200 <= 0 || this.f7594 < 0) {
                if (Log.isLoggable("ˏᵴᵢᵶ", 3)) {
                    int i = this.f7589.f2200;
                }
                this.f7588 = 1;
            }
            int i2 = this.f7588;
            if (i2 != 1 && i2 != 2) {
                this.f7588 = 0;
                if (this.f7587 == null) {
                    C5540 c5540 = (C5540) this.f7584.ᵔᵖᵹᵫ;
                    this.f7587 = c5540 == null ? new byte[255] : (byte[]) c5540.m11166(255, byte[].class);
                }
                C1585 c1585 = (C1585) this.f7589.f2201.get(this.f7594);
                int i3 = this.f7594 - 1;
                C1585 c15852 = i3 >= 0 ? (C1585) this.f7589.f2201.get(i3) : null;
                int[] iArr = c1585.f6369;
                if (iArr == null) {
                    iArr = this.f7589.f2203;
                }
                this.f7592 = iArr;
                if (iArr == null) {
                    Log.isLoggable("ˏᵴᵢᵶ", 3);
                    this.f7588 = 1;
                    return null;
                }
                if (c1585.f6372) {
                    System.arraycopy(iArr, 0, this.f7578, 0, iArr.length);
                    int[] iArr2 = this.f7578;
                    this.f7592 = iArr2;
                    iArr2[c1585.f6363] = 0;
                    if (c1585.f6368 == 2 && this.f7594 == 0) {
                        this.f7579 = Boolean.TRUE;
                    }
                }
                return m5151(c1585, c15852);
            }
            Log.isLoggable("ˏᵴᵢᵶ", 3);
            return null;
        } catch (Throwable th) {
            throw th;
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m5149(Bitmap.Config config) {
        Bitmap.Config config2;
        Bitmap.Config config3 = Bitmap.Config.ARGB_8888;
        if (config == config3 || config == (config2 = Bitmap.Config.RGB_565)) {
            this.f7583 = config;
            return;
        }
        throw new IllegalArgumentException("Unsupported format: " + config + ", must be one of " + config3 + " or " + config2);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final Bitmap m5150() {
        Boolean bool = this.f7579;
        Bitmap bitmapMo8270 = ((InterfaceC5397) this.f7584.ᵜᵪʾ).mo8270(this.f7580, this.f7590, (bool == null || bool.booleanValue()) ? Bitmap.Config.ARGB_8888 : this.f7583);
        bitmapMo8270.setHasAlpha(true);
        return bitmapMo8270;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:100:0x01e7 A[PHI: r7
      0x01e7: PHI (r7v18 int) = (r7v12 int), (r7v20 int), (r7v20 int) binds: [B:95:0x01d3, B:97:0x01de, B:98:0x01e0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:26:0x004b  */
    /* JADX WARN: Type inference failed for: r8v21 */
    /* JADX WARN: Type inference failed for: r8v22 */
    /* JADX WARN: Type inference failed for: r8v23 */
    /* JADX WARN: Type inference failed for: r8v29, types: [short] */
    /* JADX WARN: Type inference failed for: r8v31 */
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Bitmap m5151(C1585 c1585, C1585 c15852) {
        int[] iArr;
        int i;
        int i2;
        int i3;
        int i4;
        int i5;
        int[] iArr2;
        int i6;
        short[] sArr;
        byte[] bArr;
        short s;
        int i7;
        ˊˊᵞᵽ r3 = this.f7584;
        byte b = 0;
        int[] iArr3 = this.f7591;
        if (c15852 == null) {
            Bitmap bitmap = this.f7585;
            if (bitmap != null) {
                ((InterfaceC5397) r3.ᵜᵪʾ).mo7363(bitmap);
            }
            this.f7585 = null;
            Arrays.fill(iArr3, 0);
        }
        if (c15852 != null && c15852.f6368 == 3 && this.f7585 == null) {
            Arrays.fill(iArr3, 0);
        }
        int i8 = this.f7580;
        int i9 = this.f7586;
        if (c15852 != null && (i7 = c15852.f6368) > 0) {
            if (i7 == 2) {
                if (!c1585.f6372) {
                    C0379 c0379 = this.f7589;
                    int i10 = c0379.f2205;
                    if (c1585.f6369 != null && c0379.f2202 == c1585.f6363) {
                        i10 = 0;
                    }
                    int i11 = c15852.f6370 / i9;
                    int i12 = c15852.f6362 / i9;
                    int i13 = c15852.f6364 / i9;
                    int i14 = (i12 * i8) + (c15852.f6367 / i9);
                    int i15 = (i11 * i8) + i14;
                    while (i14 < i15) {
                        int i16 = i14 + i13;
                        for (int i17 = i14; i17 < i16; i17++) {
                            iArr3[i17] = i10;
                        }
                        i14 += i8;
                    }
                }
            } else if (i7 == 3) {
                Bitmap bitmap2 = this.f7585;
                if (bitmap2 != null) {
                    int i18 = this.f7590;
                    int i19 = this.f7580;
                    bitmap2.getPixels(iArr3, 0, i19, 0, 0, i19, i18);
                }
            }
        }
        this.f7595.position(c1585.f6366);
        int i20 = c1585.f6364 * c1585.f6370;
        byte[] bArr2 = this.f7596;
        if (bArr2 == null || bArr2.length < i20) {
            C5540 c5540 = (C5540) r3.ᵔᵖᵹᵫ;
            this.f7596 = c5540 == null ? new byte[i20] : (byte[]) c5540.m11166(i20, byte[].class);
        }
        byte[] bArr3 = this.f7596;
        if (this.f7597 == null) {
            this.f7597 = new short[4096];
        }
        short[] sArr2 = this.f7597;
        if (this.f7593 == null) {
            this.f7593 = new byte[4096];
        }
        byte[] bArr4 = this.f7593;
        if (this.f7581 == null) {
            this.f7581 = new byte[4097];
        }
        byte[] bArr5 = this.f7581;
        int i21 = this.f7595.get() & 255;
        int i22 = 1 << i21;
        int i23 = i22 + 1;
        int i24 = i22 + 2;
        int i25 = i21 + 1;
        int i26 = (1 << i25) - 1;
        for (int i27 = 0; i27 < i22; i27++) {
            sArr2[i27] = 0;
            bArr4[i27] = (byte) i27;
        }
        byte[] bArr6 = this.f7587;
        int i28 = 0;
        int i29 = 0;
        int i30 = 0;
        int i31 = 0;
        int i32 = 0;
        int i33 = 0;
        int i34 = 0;
        int i35 = 0;
        int i36 = i25;
        int i37 = i24;
        int i38 = i26;
        int i39 = -1;
        int i40 = -1;
        while (true) {
            if (i28 >= i20) {
                iArr = iArr3;
                break;
            }
            if (i29 == 0) {
                int i41 = this.f7595.get() & 255;
                if (i41 <= 0) {
                    i29 = i41;
                    iArr = iArr3;
                    sArr = sArr2;
                    bArr = bArr6;
                } else {
                    iArr = iArr3;
                    ByteBuffer byteBuffer = this.f7595;
                    sArr = sArr2;
                    bArr = bArr6;
                    i29 = i41;
                    byteBuffer.get(this.f7587, 0, Math.min(i41, byteBuffer.remaining()));
                }
                if (i29 <= 0) {
                    this.f7588 = 3;
                    b = 0;
                    break;
                }
                i30 = 0;
            } else {
                iArr = iArr3;
                sArr = sArr2;
                bArr = bArr6;
            }
            i32 += (bArr[i30] & 255) << i31;
            i30++;
            i29--;
            int i42 = i40;
            int i43 = i31 + 8;
            int i44 = i37;
            int i45 = i36;
            byte[] bArr7 = bArr4;
            int i46 = i34;
            while (true) {
                i31 = i43;
                if (i43 < i45) {
                    i34 = i46;
                    bArr4 = bArr7;
                    i36 = i45;
                    iArr3 = iArr;
                    bArr6 = bArr;
                    i39 = -1;
                    i40 = i42;
                    i37 = i44;
                    sArr2 = sArr;
                    break;
                }
                int i47 = i32 & i38;
                i32 >>= i45;
                i31 -= i45;
                if (i47 == i22) {
                    i45 = i25;
                    i44 = i24;
                    i38 = i26;
                    i42 = i39;
                    i43 = i31;
                } else {
                    if (i47 == i23) {
                        i37 = i44;
                        i36 = i45;
                        i34 = i46;
                        bArr4 = bArr7;
                        iArr3 = iArr;
                        sArr2 = sArr;
                        bArr6 = bArr;
                        i40 = i42;
                        break;
                    }
                    int i48 = i45;
                    if (i42 == i39) {
                        bArr3[i33] = bArr7[i47];
                        i33++;
                        i28++;
                        i42 = i47;
                        i46 = i42;
                        i43 = i31;
                        i45 = i48;
                    } else {
                        if (i47 >= i44) {
                            bArr5[i35] = (byte) i46;
                            i35++;
                            s = i42;
                        } else {
                            s = i47;
                        }
                        while (s >= i22) {
                            bArr5[i35] = bArr7[s];
                            i35++;
                            s = sArr[s];
                        }
                        i46 = bArr7[s] & 255;
                        byte b2 = (byte) i46;
                        bArr3[i33] = b2;
                        while (true) {
                            i33++;
                            i28++;
                            if (i35 <= 0) {
                                break;
                            }
                            i35--;
                            bArr3[i33] = bArr5[i35];
                        }
                        int i49 = i22;
                        if (i44 < 4096) {
                            sArr[i44] = (short) i42;
                            bArr7[i44] = b2;
                            i44++;
                            if ((i44 & i38) != 0 || i44 >= 4096) {
                                i45 = i48;
                            } else {
                                i45 = i48 + 1;
                                i38 += i44;
                            }
                            i42 = i47;
                            i43 = i31;
                            i22 = i49;
                        }
                    }
                    i39 = -1;
                }
            }
            b = 0;
        }
        Arrays.fill(bArr3, i33, i20, b);
        boolean z = c1585.f6365;
        int[] iArr4 = this.f7591;
        if (z || i9 != 1) {
            int i50 = c1585.f6370 / i9;
            int i51 = c1585.f6362 / i9;
            int i52 = c1585.f6364 / i9;
            int i53 = c1585.f6367 / i9;
            boolean z2 = this.f7594 == 0;
            byte[] bArr8 = this.f7596;
            int[] iArr5 = this.f7592;
            Boolean bool = this.f7579;
            int i54 = 8;
            int i55 = 0;
            int i56 = 0;
            int i57 = 1;
            while (i55 < i50) {
                int i58 = i51;
                if (c1585.f6365) {
                    if (i56 >= i50) {
                        i57++;
                        if (i57 == 2) {
                            i56 = 4;
                        } else if (i57 == 3) {
                            i54 = 4;
                            i56 = 2;
                        } else if (i57 == 4) {
                            i56 = 1;
                            i54 = 2;
                        }
                    }
                    i = i56 + i54;
                } else {
                    i = i56;
                    i56 = i55;
                }
                int i59 = i56 + i58;
                int i60 = i50;
                boolean z3 = i9 == 1;
                if (i59 < this.f7590) {
                    int i61 = i59 * i8;
                    int i62 = i61 + i53;
                    int i63 = i62 + i52;
                    int i64 = i61 + i8;
                    if (i64 < i63) {
                        i63 = i64;
                    }
                    i2 = i;
                    int i65 = i55 * i9 * c1585.f6364;
                    if (z3) {
                        int i66 = i62;
                        while (i66 < i63) {
                            int i67 = i66;
                            int i68 = iArr5[bArr8[i65] & 255];
                            if (i68 != 0) {
                                iArr4[i67] = i68;
                            } else if (z2 && bool == null) {
                                bool = Boolean.TRUE;
                            }
                            i65 += i9;
                            i66 = i67 + 1;
                        }
                    } else {
                        int i69 = ((i63 - i62) * i9) + i65;
                        Boolean bool2 = bool;
                        int i70 = i65;
                        int i71 = i62;
                        while (i71 < i63) {
                            int i72 = i63;
                            int i73 = c1585.f6364;
                            int i74 = i52;
                            int i75 = i70;
                            int i76 = 0;
                            int i77 = 0;
                            int i78 = 0;
                            int i79 = 0;
                            int i80 = 0;
                            while (true) {
                                if (i75 >= i70 + i9) {
                                    i5 = i53;
                                    break;
                                }
                                byte[] bArr9 = this.f7596;
                                i5 = i53;
                                if (i75 >= bArr9.length || i75 >= i69) {
                                    break;
                                }
                                int i81 = this.f7592[bArr9[i75] & 255];
                                if (i81 != 0) {
                                    i76 += (i81 >> 24) & 255;
                                    i77 += (i81 >> 16) & 255;
                                    i78 += (i81 >> 8) & 255;
                                    i79 += i81 & 255;
                                    i80++;
                                }
                                i75++;
                                i53 = i5;
                            }
                            int i82 = i70 + i73;
                            int i83 = i82;
                            while (i83 < i82 + i9) {
                                byte[] bArr10 = this.f7596;
                                int i84 = i82;
                                if (i83 >= bArr10.length || i83 >= i69) {
                                    break;
                                }
                                int i85 = this.f7592[bArr10[i83] & 255];
                                if (i85 != 0) {
                                    i76 += (i85 >> 24) & 255;
                                    i77 += (i85 >> 16) & 255;
                                    i78 += (i85 >> 8) & 255;
                                    i79 += i85 & 255;
                                    i80++;
                                }
                                i83++;
                                i82 = i84;
                            }
                            int i86 = i80 == 0 ? 0 : ((i76 / i80) << 24) | ((i77 / i80) << 16) | ((i78 / i80) << 8) | (i79 / i80);
                            if (i86 != 0) {
                                iArr4[i71] = i86;
                            } else if (z2 && bool2 == null) {
                                bool2 = Boolean.TRUE;
                            }
                            i70 += i9;
                            i71++;
                            i63 = i72;
                            i52 = i74;
                            i53 = i5;
                        }
                        i4 = i52;
                        i3 = i53;
                        bool = bool2;
                        i55++;
                        i51 = i58;
                        i50 = i60;
                        i56 = i2;
                        i52 = i4;
                        i53 = i3;
                    }
                } else {
                    i2 = i;
                }
                i4 = i52;
                i3 = i53;
                i55++;
                i51 = i58;
                i50 = i60;
                i56 = i2;
                i52 = i4;
                i53 = i3;
            }
            if (this.f7579 == null) {
                this.f7579 = Boolean.valueOf(bool == null ? false : bool.booleanValue());
            }
        } else {
            int i87 = c1585.f6370;
            int i88 = c1585.f6362;
            int i89 = c1585.f6364;
            int i90 = c1585.f6367;
            byte b3 = this.f7594 == 0 ? (byte) 1 : b;
            byte[] bArr11 = this.f7596;
            int[] iArr6 = this.f7592;
            byte b4 = -1;
            for (int i91 = b; i91 < i87; i91++) {
                int i92 = (i91 + i88) * i8;
                int i93 = i92 + i90;
                int i94 = i93 + i89;
                int i95 = i92 + i8;
                if (i95 < i94) {
                    i94 = i95;
                }
                int i96 = c1585.f6364 * i91;
                while (i93 < i94) {
                    int i97 = i87;
                    byte b5 = bArr11[i96];
                    int[] iArr7 = iArr4;
                    int i98 = b5 & 255;
                    if (i98 != b4) {
                        int i99 = iArr6[i98];
                        if (i99 != 0) {
                            iArr7[i93] = i99;
                        } else {
                            b4 = b5;
                        }
                    }
                    i96++;
                    i93++;
                    i87 = i97;
                    iArr4 = iArr7;
                }
            }
            Boolean bool3 = this.f7579;
            this.f7579 = Boolean.valueOf((bool3 != null && bool3.booleanValue()) || !(this.f7579 != null || b3 == 0 || b4 == -1));
        }
        if (this.f7582 && ((i6 = c1585.f6368) == 0 || i6 == 1)) {
            if (this.f7585 == null) {
                this.f7585 = m5150();
            }
            Bitmap bitmap3 = this.f7585;
            int i100 = this.f7590;
            int i101 = this.f7580;
            iArr2 = iArr;
            bitmap3.setPixels(iArr2, 0, i101, 0, 0, i101, i100);
        } else {
            iArr2 = iArr;
        }
        Bitmap bitmapM5150 = m5150();
        int i102 = this.f7590;
        int i103 = this.f7580;
        bitmapM5150.setPixels(iArr2, 0, i103, 0, 0, i103, i102);
        return bitmapM5150;
    }
}
