package p1; 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 p1.a; /* loaded from: classes.dex */ public class e implements a { /* renamed from: u, reason: collision with root package name */ private static final String f12937u = "e"; /* renamed from: a, reason: collision with root package name */ private int[] f12938a; /* renamed from: b, reason: collision with root package name */ private final int[] f12939b; /* renamed from: c, reason: collision with root package name */ private final a.InterfaceC0209a f12940c; /* renamed from: d, reason: collision with root package name */ private ByteBuffer f12941d; /* renamed from: e, reason: collision with root package name */ private byte[] f12942e; /* renamed from: f, reason: collision with root package name */ private short[] f12943f; /* renamed from: g, reason: collision with root package name */ private byte[] f12944g; /* renamed from: h, reason: collision with root package name */ private byte[] f12945h; /* renamed from: i, reason: collision with root package name */ private byte[] f12946i; /* renamed from: j, reason: collision with root package name */ private int[] f12947j; /* renamed from: k, reason: collision with root package name */ private int f12948k; /* renamed from: l, reason: collision with root package name */ private c f12949l; /* renamed from: m, reason: collision with root package name */ private Bitmap f12950m; /* renamed from: n, reason: collision with root package name */ private boolean f12951n; /* renamed from: o, reason: collision with root package name */ private int f12952o; /* renamed from: p, reason: collision with root package name */ private int f12953p; /* renamed from: q, reason: collision with root package name */ private int f12954q; /* renamed from: r, reason: collision with root package name */ private int f12955r; /* renamed from: s, reason: collision with root package name */ private Boolean f12956s; /* renamed from: t, reason: collision with root package name */ private Bitmap.Config f12957t; public e(a.InterfaceC0209a interfaceC0209a, c cVar, ByteBuffer byteBuffer, int i10) { this(interfaceC0209a); q(cVar, byteBuffer, i10); } private int i(int i10, int i11, int i12) { int i13 = 0; int i14 = 0; int i15 = 0; int i16 = 0; int i17 = 0; for (int i18 = i10; i18 < this.f12953p + i10; i18++) { byte[] bArr = this.f12946i; if (i18 >= bArr.length || i18 >= i11) { break; } int i19 = this.f12938a[bArr[i18] & 255]; if (i19 != 0) { i13 += (i19 >> 24) & 255; i14 += (i19 >> 16) & 255; i15 += (i19 >> 8) & 255; i16 += i19 & 255; i17++; } } int i20 = i10 + i12; for (int i21 = i20; i21 < this.f12953p + i20; i21++) { byte[] bArr2 = this.f12946i; if (i21 >= bArr2.length || i21 >= i11) { break; } int i22 = this.f12938a[bArr2[i21] & 255]; if (i22 != 0) { i13 += (i22 >> 24) & 255; i14 += (i22 >> 16) & 255; i15 += (i22 >> 8) & 255; i16 += i22 & 255; i17++; } } if (i17 == 0) { return 0; } return ((i13 / i17) << 24) | ((i14 / i17) << 16) | ((i15 / i17) << 8) | (i16 / i17); } private void j(b bVar) { int i10; int i11; int i12; int i13; int i14; int[] iArr = this.f12947j; int i15 = bVar.f12912d; int i16 = this.f12953p; int i17 = i15 / i16; int i18 = bVar.f12910b / i16; int i19 = bVar.f12911c / i16; int i20 = bVar.f12909a / i16; boolean z10 = this.f12948k == 0; int i21 = this.f12955r; int i22 = this.f12954q; byte[] bArr = this.f12946i; int[] iArr2 = this.f12938a; Boolean bool = this.f12956s; int i23 = 8; int i24 = 0; int i25 = 0; int i26 = 1; while (i25 < i17) { Boolean bool2 = bool; if (bVar.f12913e) { if (i24 >= i17) { int i27 = i26 + 1; i10 = i17; if (i27 == 2) { i26 = i27; i24 = 4; } else if (i27 == 3) { i26 = i27; i24 = 2; i23 = 4; } else if (i27 != 4) { i26 = i27; } else { i26 = i27; i24 = 1; i23 = 2; } } else { i10 = i17; } i11 = i24 + i23; } else { i10 = i17; i11 = i24; i24 = i25; } int i28 = i24 + i18; boolean z11 = i16 == 1; if (i28 < i22) { int i29 = i28 * i21; int i30 = i29 + i20; int i31 = i30 + i19; int i32 = i29 + i21; if (i32 < i31) { i31 = i32; } i12 = i11; int i33 = i25 * i16 * bVar.f12911c; if (z11) { int i34 = i30; while (i34 < i31) { int i35 = i18; int i36 = iArr2[bArr[i33] & 255]; if (i36 != 0) { iArr[i34] = i36; } else if (z10 && bool2 == null) { bool2 = Boolean.TRUE; } i33 += i16; i34++; i18 = i35; } } else { i14 = i18; int i37 = ((i31 - i30) * i16) + i33; int i38 = i30; while (true) { i13 = i19; if (i38 < i31) { int i39 = i(i33, i37, bVar.f12911c); if (i39 != 0) { iArr[i38] = i39; } else if (z10 && bool2 == null) { bool2 = Boolean.TRUE; } i33 += i16; i38++; i19 = i13; } } bool = bool2; i25++; i18 = i14; i17 = i10; i19 = i13; i24 = i12; } } else { i12 = i11; } i14 = i18; i13 = i19; bool = bool2; i25++; i18 = i14; i17 = i10; i19 = i13; i24 = i12; } Boolean bool3 = bool; if (this.f12956s == null) { this.f12956s = Boolean.valueOf(bool3 == null ? false : bool3.booleanValue()); } } private void k(b bVar) { b bVar2 = bVar; int[] iArr = this.f12947j; int i10 = bVar2.f12912d; int i11 = bVar2.f12910b; int i12 = bVar2.f12911c; int i13 = bVar2.f12909a; boolean z10 = this.f12948k == 0; int i14 = this.f12955r; byte[] bArr = this.f12946i; int[] iArr2 = this.f12938a; int i15 = 0; byte b10 = -1; while (i15 < i10) { int i16 = (i15 + i11) * i14; int i17 = i16 + i13; int i18 = i17 + i12; int i19 = i16 + i14; if (i19 < i18) { i18 = i19; } int i20 = bVar2.f12911c * i15; int i21 = i17; while (i21 < i18) { byte b11 = bArr[i20]; int i22 = i10; int i23 = b11 & 255; if (i23 != b10) { int i24 = iArr2[i23]; if (i24 != 0) { iArr[i21] = i24; } else { b10 = b11; } } i20++; i21++; i10 = i22; } i15++; bVar2 = bVar; } Boolean bool = this.f12956s; this.f12956s = Boolean.valueOf((bool != null && bool.booleanValue()) || (this.f12956s == null && z10 && b10 != -1)); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r7v10 */ /* JADX WARN: Type inference failed for: r7v11 */ /* JADX WARN: Type inference failed for: r7v12 */ /* JADX WARN: Type inference failed for: r7v15, types: [short] */ /* JADX WARN: Type inference failed for: r7v17 */ private void l(b bVar) { int i10; int i11; short s10; e eVar = this; if (bVar != null) { eVar.f12941d.position(bVar.f12918j); } if (bVar == null) { c cVar = eVar.f12949l; i10 = cVar.f12925f; i11 = cVar.f12926g; } else { i10 = bVar.f12911c; i11 = bVar.f12912d; } int i12 = i10 * i11; byte[] bArr = eVar.f12946i; if (bArr == null || bArr.length < i12) { eVar.f12946i = eVar.f12940c.e(i12); } byte[] bArr2 = eVar.f12946i; if (eVar.f12943f == null) { eVar.f12943f = new short[4096]; } short[] sArr = eVar.f12943f; if (eVar.f12944g == null) { eVar.f12944g = new byte[4096]; } byte[] bArr3 = eVar.f12944g; if (eVar.f12945h == null) { eVar.f12945h = new byte[4097]; } byte[] bArr4 = eVar.f12945h; int p10 = p(); int i13 = 1 << p10; int i14 = i13 + 1; int i15 = i13 + 2; int i16 = p10 + 1; int i17 = (1 << i16) - 1; int i18 = 0; for (int i19 = 0; i19 < i13; i19++) { sArr[i19] = 0; bArr3[i19] = (byte) i19; } byte[] bArr5 = eVar.f12942e; int i20 = i16; int i21 = i15; int i22 = i17; int i23 = 0; int i24 = 0; int i25 = 0; int i26 = 0; int i27 = 0; int i28 = -1; int i29 = 0; int i30 = 0; while (true) { if (i18 >= i12) { break; } if (i23 == 0) { i23 = o(); if (i23 <= 0) { eVar.f12952o = 3; break; } i24 = 0; } i26 += (bArr5[i24] & 255) << i25; i24++; i23--; int i31 = i25 + 8; int i32 = i21; int i33 = i20; int i34 = i28; int i35 = i16; int i36 = i29; while (true) { if (i31 < i33) { i28 = i34; i21 = i32; i25 = i31; eVar = this; i29 = i36; i16 = i35; i20 = i33; break; } int i37 = i15; int i38 = i26 & i22; i26 >>= i33; i31 -= i33; if (i38 == i13) { i22 = i17; i33 = i35; i32 = i37; i15 = i32; i34 = -1; } else { if (i38 == i14) { i25 = i31; i29 = i36; i21 = i32; i16 = i35; i15 = i37; i28 = i34; i20 = i33; eVar = this; break; } if (i34 == -1) { bArr2[i27] = bArr3[i38]; i27++; i18++; i34 = i38; i36 = i34; i15 = i37; i31 = i31; } else { if (i38 >= i32) { bArr4[i30] = (byte) i36; i30++; s10 = i34; } else { s10 = i38; } while (s10 >= i13) { bArr4[i30] = bArr3[s10]; i30++; s10 = sArr[s10]; } i36 = bArr3[s10] & 255; byte b10 = (byte) i36; bArr2[i27] = b10; while (true) { i27++; i18++; if (i30 <= 0) { break; } i30--; bArr2[i27] = bArr4[i30]; } byte[] bArr6 = bArr4; if (i32 < 4096) { sArr[i32] = (short) i34; bArr3[i32] = b10; i32++; if ((i32 & i22) == 0 && i32 < 4096) { i33++; i22 += i32; } } i34 = i38; i15 = i37; i31 = i31; bArr4 = bArr6; } } } } Arrays.fill(bArr2, i27, i12, (byte) 0); } private Bitmap n() { Boolean bool = this.f12956s; Bitmap a10 = this.f12940c.a(this.f12955r, this.f12954q, (bool == null || bool.booleanValue()) ? Bitmap.Config.ARGB_8888 : this.f12957t); a10.setHasAlpha(true); return a10; } private int o() { int p10 = p(); if (p10 <= 0) { return p10; } ByteBuffer byteBuffer = this.f12941d; byteBuffer.get(this.f12942e, 0, Math.min(p10, byteBuffer.remaining())); return p10; } private int p() { return this.f12941d.get() & 255; } private Bitmap r(b bVar, b bVar2) { int i10; int i11; Bitmap bitmap; int[] iArr = this.f12947j; int i12 = 0; if (bVar2 == null) { Bitmap bitmap2 = this.f12950m; if (bitmap2 != null) { this.f12940c.c(bitmap2); } this.f12950m = null; Arrays.fill(iArr, 0); } if (bVar2 != null && bVar2.f12915g == 3 && this.f12950m == null) { Arrays.fill(iArr, 0); } if (bVar2 != null && (i11 = bVar2.f12915g) > 0) { if (i11 == 2) { if (!bVar.f12914f) { c cVar = this.f12949l; int i13 = cVar.f12931l; if (bVar.f12919k == null || cVar.f12929j != bVar.f12916h) { i12 = i13; } } int i14 = bVar2.f12912d; int i15 = this.f12953p; int i16 = i14 / i15; int i17 = bVar2.f12910b / i15; int i18 = bVar2.f12911c / i15; int i19 = bVar2.f12909a / i15; int i20 = this.f12955r; int i21 = (i17 * i20) + i19; int i22 = (i16 * i20) + i21; while (i21 < i22) { int i23 = i21 + i18; for (int i24 = i21; i24 < i23; i24++) { iArr[i24] = i12; } i21 += this.f12955r; } } else if (i11 == 3 && (bitmap = this.f12950m) != null) { int i25 = this.f12955r; bitmap.getPixels(iArr, 0, i25, 0, 0, i25, this.f12954q); } } l(bVar); if (bVar.f12913e || this.f12953p != 1) { j(bVar); } else { k(bVar); } if (this.f12951n && ((i10 = bVar.f12915g) == 0 || i10 == 1)) { if (this.f12950m == null) { this.f12950m = n(); } Bitmap bitmap3 = this.f12950m; int i26 = this.f12955r; bitmap3.setPixels(iArr, 0, i26, 0, 0, i26, this.f12954q); } Bitmap n10 = n(); int i27 = this.f12955r; n10.setPixels(iArr, 0, i27, 0, 0, i27, this.f12954q); return n10; } @Override // p1.a public synchronized Bitmap a() { if (this.f12949l.f12922c <= 0 || this.f12948k < 0) { String str = f12937u; if (Log.isLoggable(str, 3)) { Log.d(str, "Unable to decode frame, frameCount=" + this.f12949l.f12922c + ", framePointer=" + this.f12948k); } this.f12952o = 1; } int i10 = this.f12952o; if (i10 != 1 && i10 != 2) { this.f12952o = 0; if (this.f12942e == null) { this.f12942e = this.f12940c.e(255); } b bVar = (b) this.f12949l.f12924e.get(this.f12948k); int i11 = this.f12948k - 1; b bVar2 = i11 >= 0 ? (b) this.f12949l.f12924e.get(i11) : null; int[] iArr = bVar.f12919k; if (iArr == null) { iArr = this.f12949l.f12920a; } this.f12938a = iArr; if (iArr == null) { String str2 = f12937u; if (Log.isLoggable(str2, 3)) { Log.d(str2, "No valid color table found for frame #" + this.f12948k); } this.f12952o = 1; return null; } if (bVar.f12914f) { System.arraycopy(iArr, 0, this.f12939b, 0, iArr.length); int[] iArr2 = this.f12939b; this.f12938a = iArr2; iArr2[bVar.f12916h] = 0; if (bVar.f12915g == 2 && this.f12948k == 0) { this.f12956s = Boolean.TRUE; } } return r(bVar, bVar2); } String str3 = f12937u; if (Log.isLoggable(str3, 3)) { Log.d(str3, "Unable to decode frame, status=" + this.f12952o); } return null; } @Override // p1.a public void b() { this.f12948k = (this.f12948k + 1) % this.f12949l.f12922c; } @Override // p1.a public int c() { return this.f12949l.f12922c; } @Override // p1.a public void clear() { this.f12949l = null; byte[] bArr = this.f12946i; if (bArr != null) { this.f12940c.d(bArr); } int[] iArr = this.f12947j; if (iArr != null) { this.f12940c.f(iArr); } Bitmap bitmap = this.f12950m; if (bitmap != null) { this.f12940c.c(bitmap); } this.f12950m = null; this.f12941d = null; this.f12956s = null; byte[] bArr2 = this.f12942e; if (bArr2 != null) { this.f12940c.d(bArr2); } } @Override // p1.a public int d() { int i10; if (this.f12949l.f12922c <= 0 || (i10 = this.f12948k) < 0) { return 0; } return m(i10); } @Override // p1.a public void e(Bitmap.Config config) { if (config == Bitmap.Config.ARGB_8888 || config == Bitmap.Config.RGB_565) { this.f12957t = config; return; } throw new IllegalArgumentException("Unsupported format: " + config + ", must be one of " + Bitmap.Config.ARGB_8888 + " or " + Bitmap.Config.RGB_565); } @Override // p1.a public void f() { this.f12948k = -1; } @Override // p1.a public int g() { return this.f12948k; } @Override // p1.a public ByteBuffer getData() { return this.f12941d; } @Override // p1.a public int h() { return this.f12941d.limit() + this.f12946i.length + (this.f12947j.length * 4); } public int m(int i10) { if (i10 >= 0) { c cVar = this.f12949l; if (i10 < cVar.f12922c) { return ((b) cVar.f12924e.get(i10)).f12917i; } } return -1; } public synchronized void q(c cVar, ByteBuffer byteBuffer, int i10) { if (i10 <= 0) { throw new IllegalArgumentException("Sample size must be >=0, not: " + i10); } int highestOneBit = Integer.highestOneBit(i10); this.f12952o = 0; this.f12949l = cVar; this.f12948k = -1; ByteBuffer asReadOnlyBuffer = byteBuffer.asReadOnlyBuffer(); this.f12941d = asReadOnlyBuffer; asReadOnlyBuffer.position(0); this.f12941d.order(ByteOrder.LITTLE_ENDIAN); this.f12951n = false; Iterator it = cVar.f12924e.iterator(); while (true) { if (!it.hasNext()) { break; } else if (((b) it.next()).f12915g == 3) { this.f12951n = true; break; } } this.f12953p = highestOneBit; int i11 = cVar.f12925f; this.f12955r = i11 / highestOneBit; int i12 = cVar.f12926g; this.f12954q = i12 / highestOneBit; this.f12946i = this.f12940c.e(i11 * i12); this.f12947j = this.f12940c.b(this.f12955r * this.f12954q); } public e(a.InterfaceC0209a interfaceC0209a) { this.f12939b = new int[256]; this.f12957t = Bitmap.Config.ARGB_8888; this.f12940c = interfaceC0209a; this.f12949l = new c(); } }