package com.bumptech.glide.gifdecoder; import android.graphics.Bitmap; import android.util.Log; import com.bumptech.glide.gifdecoder.GifDecoder; import com.ijm.dataencryption.de.DataDecryptTool; import com.ubt.jimu.base.util.FileUtil; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import java.util.Iterator; /* loaded from: classes.dex */ public class StandardGifDecoder implements GifDecoder { private static final String u = "StandardGifDecoder"; private int[] a; private final int[] b; private final GifDecoder.BitmapProvider c; private ByteBuffer d; private byte[] e; private short[] f; private byte[] g; private byte[] h; private byte[] i; private int[] j; private int k; private GifHeader l; private Bitmap m; private boolean n; private int o; private int p; private int q; private int r; private Boolean s; private Bitmap.Config t; public StandardGifDecoder(GifDecoder.BitmapProvider bitmapProvider, GifHeader gifHeader, ByteBuffer byteBuffer, int i) { this(bitmapProvider); a(gifHeader, byteBuffer, i); } private Bitmap i() { Boolean bool = this.s; Bitmap a = this.c.a(this.r, this.q, (bool == null || bool.booleanValue()) ? Bitmap.Config.ARGB_8888 : this.t); a.setHasAlpha(true); return a; } private int j() { int k = k(); if (k <= 0) { return k; } ByteBuffer byteBuffer = this.d; byteBuffer.get(this.e, 0, Math.min(k, byteBuffer.remaining())); return k; } private int k() { return this.d.get() & 255; } public int a(int i) { if (i >= 0) { GifHeader gifHeader = this.l; if (i < gifHeader.c) { return gifHeader.e.get(i).i; } } return -1; } @Override // com.bumptech.glide.gifdecoder.GifDecoder public void b() { this.k = (this.k + 1) % this.l.c; } @Override // com.bumptech.glide.gifdecoder.GifDecoder public int c() { return this.l.c; } @Override // com.bumptech.glide.gifdecoder.GifDecoder public void clear() { this.l = null; byte[] bArr = this.i; if (bArr != null) { this.c.a(bArr); } int[] iArr = this.j; if (iArr != null) { this.c.a(iArr); } Bitmap bitmap = this.m; if (bitmap != null) { this.c.a(bitmap); } this.m = null; this.d = null; this.s = null; byte[] bArr2 = this.e; if (bArr2 != null) { this.c.a(bArr2); } } @Override // com.bumptech.glide.gifdecoder.GifDecoder public int d() { int i; if (this.l.c <= 0 || (i = this.k) < 0) { return 0; } return a(i); } @Override // com.bumptech.glide.gifdecoder.GifDecoder public ByteBuffer e() { return this.d; } @Override // com.bumptech.glide.gifdecoder.GifDecoder public void f() { this.k = -1; } @Override // com.bumptech.glide.gifdecoder.GifDecoder public int g() { return this.k; } @Override // com.bumptech.glide.gifdecoder.GifDecoder public int h() { return this.d.limit() + this.i.length + (this.j.length * 4); } private void b(GifFrame gifFrame) { GifFrame gifFrame2 = gifFrame; int[] iArr = this.j; int i = gifFrame2.d; int i2 = gifFrame2.b; int i3 = gifFrame2.c; int i4 = gifFrame2.a; boolean z = this.k == 0; int i5 = this.r; byte[] bArr = this.i; int[] iArr2 = this.a; int i6 = 0; byte b = -1; while (i6 < i) { int i7 = (i6 + i2) * i5; int i8 = i7 + i4; int i9 = i8 + i3; int i10 = i7 + i5; if (i10 < i9) { i9 = i10; } int i11 = gifFrame2.c * i6; for (int i12 = i8; i12 < i9; i12++) { byte b2 = bArr[i11]; int i13 = b2 & 255; if (i13 != b) { int i14 = iArr2[i13]; if (i14 != 0) { iArr[i12] = i14; } else { b = b2; } } i11++; } i6++; gifFrame2 = gifFrame; } this.s = Boolean.valueOf(this.s == null && z && b != -1); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v10 */ /* JADX WARN: Type inference failed for: r4v11 */ /* JADX WARN: Type inference failed for: r4v12 */ /* JADX WARN: Type inference failed for: r4v17, types: [short] */ /* JADX WARN: Type inference failed for: r4v20 */ private void c(GifFrame gifFrame) { int i; int i2; short s; StandardGifDecoder standardGifDecoder = this; if (gifFrame != null) { standardGifDecoder.d.position(gifFrame.j); } if (gifFrame == null) { GifHeader gifHeader = standardGifDecoder.l; i = gifHeader.f; i2 = gifHeader.g; } else { i = gifFrame.c; i2 = gifFrame.d; } int i3 = i * i2; byte[] bArr = standardGifDecoder.i; if (bArr == null || bArr.length < i3) { standardGifDecoder.i = standardGifDecoder.c.b(i3); } byte[] bArr2 = standardGifDecoder.i; if (standardGifDecoder.f == null) { standardGifDecoder.f = new short[FileUtil.ZIP_BUFFER_SIZE]; } short[] sArr = standardGifDecoder.f; if (standardGifDecoder.g == null) { standardGifDecoder.g = new byte[FileUtil.ZIP_BUFFER_SIZE]; } byte[] bArr3 = standardGifDecoder.g; if (standardGifDecoder.h == null) { standardGifDecoder.h = new byte[4097]; } byte[] bArr4 = standardGifDecoder.h; int k = k(); int i4 = 1 << k; int i5 = i4 + 1; int i6 = i4 + 2; int i7 = k + 1; int i8 = (1 << i7) - 1; int i9 = 0; for (int i10 = 0; i10 < i4; i10++) { sArr[i10] = 0; bArr3[i10] = (byte) i10; } byte[] bArr5 = standardGifDecoder.e; int i11 = i7; int i12 = i6; int i13 = i8; int i14 = 0; int i15 = 0; int i16 = 0; int i17 = 0; int i18 = 0; int i19 = -1; int i20 = 0; int i21 = 0; while (true) { if (i9 >= i3) { break; } if (i14 == 0) { i14 = j(); if (i14 <= 0) { standardGifDecoder.o = 3; break; } i17 = 0; } i16 += (bArr5[i17] & 255) << i15; i17++; i14--; int i22 = i15 + 8; int i23 = i19; int i24 = i20; int i25 = i12; int i26 = i18; int i27 = i9; int i28 = i11; while (true) { if (i22 < i28) { i11 = i28; i20 = i24; i9 = i27; i18 = i26; i15 = i22; i12 = i25; i19 = i23; standardGifDecoder = this; break; } int i29 = i16 & i13; i16 >>= i28; i22 -= i28; if (i29 == i4) { i28 = i7; i25 = i6; i13 = i8; i23 = -1; } else { if (i29 == i5) { i15 = i22; i11 = i28; i9 = i27; i18 = i26; i12 = i25; i20 = i24; i19 = i23; break; } if (i23 == -1) { bArr2[i26] = bArr3[i29]; i26++; i27++; standardGifDecoder = this; i23 = i29; i24 = i23; } else { int i30 = i25; if (i29 >= i30) { bArr4[i21] = (byte) i24; i21++; s = i23; } else { s = i29; } while (s >= i4) { bArr4[i21] = bArr3[s]; i21++; s = sArr[s]; } int i31 = bArr3[s] & 255; int i32 = i7; byte b = (byte) i31; bArr2[i26] = b; while (true) { i26++; i27++; if (i21 <= 0) { break; } i21--; bArr2[i26] = bArr4[i21]; } if (i30 < 4096) { sArr[i30] = (short) i23; bArr3[i30] = b; i30++; if ((i30 & i13) == 0 && i30 < 4096) { i28++; i13 += i30; } } i23 = i29; i22 = i22; i7 = i32; i24 = i31; i25 = i30; standardGifDecoder = this; } } } } Arrays.fill(bArr2, i18, i3, (byte) 0); } public StandardGifDecoder(GifDecoder.BitmapProvider bitmapProvider) { this.b = new int[DataDecryptTool.DECRYPT_ALL_FILE]; this.t = Bitmap.Config.ARGB_8888; this.c = bitmapProvider; this.l = new GifHeader(); } @Override // com.bumptech.glide.gifdecoder.GifDecoder public synchronized Bitmap a() { if (this.l.c <= 0 || this.k < 0) { if (Log.isLoggable(u, 3)) { Log.d(u, "Unable to decode frame, frameCount=" + this.l.c + ", framePointer=" + this.k); } this.o = 1; } if (this.o != 1 && this.o != 2) { this.o = 0; if (this.e == null) { this.e = this.c.b(255); } GifFrame gifFrame = this.l.e.get(this.k); int i = this.k - 1; GifFrame gifFrame2 = i >= 0 ? this.l.e.get(i) : null; this.a = gifFrame.k != null ? gifFrame.k : this.l.a; if (this.a == null) { if (Log.isLoggable(u, 3)) { Log.d(u, "No valid color table found for frame #" + this.k); } this.o = 1; return null; } if (gifFrame.f) { System.arraycopy(this.a, 0, this.b, 0, this.a.length); this.a = this.b; this.a[gifFrame.h] = 0; } return a(gifFrame, gifFrame2); } if (Log.isLoggable(u, 3)) { Log.d(u, "Unable to decode frame, status=" + this.o); } return null; } public synchronized void a(GifHeader gifHeader, ByteBuffer byteBuffer, int i) { if (i > 0) { int highestOneBit = Integer.highestOneBit(i); this.o = 0; this.l = gifHeader; this.k = -1; this.d = byteBuffer.asReadOnlyBuffer(); this.d.position(0); this.d.order(ByteOrder.LITTLE_ENDIAN); this.n = false; Iterator it = gifHeader.e.iterator(); while (true) { if (!it.hasNext()) { break; } else if (it.next().g == 3) { this.n = true; break; } } this.p = highestOneBit; this.r = gifHeader.f / highestOneBit; this.q = gifHeader.g / highestOneBit; this.i = this.c.b(gifHeader.f * gifHeader.g); this.j = this.c.a(this.r * this.q); } else { throw new IllegalArgumentException("Sample size must be >=0, not: " + i); } } @Override // com.bumptech.glide.gifdecoder.GifDecoder public void a(Bitmap.Config config) { if (config != Bitmap.Config.ARGB_8888 && config != Bitmap.Config.RGB_565) { throw new IllegalArgumentException("Unsupported format: " + config + ", must be one of " + Bitmap.Config.ARGB_8888 + " or " + Bitmap.Config.RGB_565); } this.t = config; } private Bitmap a(GifFrame gifFrame, GifFrame gifFrame2) { int i; int i2; Bitmap bitmap; int[] iArr = this.j; int i3 = 0; if (gifFrame2 == null) { Bitmap bitmap2 = this.m; if (bitmap2 != null) { this.c.a(bitmap2); } this.m = null; Arrays.fill(iArr, 0); } if (gifFrame2 != null && gifFrame2.g == 3 && this.m == null) { Arrays.fill(iArr, 0); } if (gifFrame2 != null && (i2 = gifFrame2.g) > 0) { if (i2 == 2) { if (!gifFrame.f) { GifHeader gifHeader = this.l; int i4 = gifHeader.l; if (gifFrame.k == null || gifHeader.j != gifFrame.h) { i3 = i4; } } else if (this.k == 0) { this.s = true; } int i5 = gifFrame2.d; int i6 = this.p; int i7 = i5 / i6; int i8 = gifFrame2.b / i6; int i9 = gifFrame2.c / i6; int i10 = gifFrame2.a / i6; int i11 = this.r; int i12 = (i8 * i11) + i10; int i13 = (i7 * i11) + i12; while (i12 < i13) { int i14 = i12 + i9; for (int i15 = i12; i15 < i14; i15++) { iArr[i15] = i3; } i12 += this.r; } } else if (i2 == 3 && (bitmap = this.m) != null) { int i16 = this.r; bitmap.getPixels(iArr, 0, i16, 0, 0, i16, this.q); } } c(gifFrame); if (!gifFrame.e && this.p == 1) { b(gifFrame); } else { a(gifFrame); } if (this.n && ((i = gifFrame.g) == 0 || i == 1)) { if (this.m == null) { this.m = i(); } Bitmap bitmap3 = this.m; int i17 = this.r; bitmap3.setPixels(iArr, 0, i17, 0, 0, i17, this.q); } Bitmap i18 = i(); int i19 = this.r; i18.setPixels(iArr, 0, i19, 0, 0, i19, this.q); return i18; } private void a(GifFrame gifFrame) { int i; int i2; int i3; int i4; int i5; int[] iArr = this.j; int i6 = gifFrame.d; int i7 = this.p; int i8 = i6 / i7; int i9 = gifFrame.b / i7; int i10 = gifFrame.c / i7; int i11 = gifFrame.a / i7; Boolean bool = true; boolean z = this.k == 0; int i12 = this.p; int i13 = this.r; int i14 = this.q; byte[] bArr = this.i; int[] iArr2 = this.a; Boolean bool2 = this.s; int i15 = 0; int i16 = 0; int i17 = 1; int i18 = 8; while (i15 < i8) { Boolean bool3 = bool; if (gifFrame.e) { if (i16 >= i8) { i = i8; i5 = i17 + 1; if (i5 == 2) { i16 = 4; } else if (i5 == 3) { i16 = 2; i18 = 4; } else if (i5 == 4) { i16 = 1; i18 = 2; } } else { i = i8; i5 = i17; } i2 = i16 + i18; i17 = i5; } else { i = i8; i2 = i16; i16 = i15; } int i19 = i16 + i9; boolean z2 = i12 == 1; if (i19 < i14) { int i20 = i19 * i13; int i21 = i20 + i11; int i22 = i21 + i10; int i23 = i20 + i13; if (i23 < i22) { i22 = i23; } i3 = i9; int i24 = i15 * i12 * gifFrame.c; if (z2) { int i25 = i21; while (i25 < i22) { int i26 = i10; int i27 = iArr2[bArr[i24] & 255]; if (i27 != 0) { iArr[i25] = i27; } else if (z && bool2 == null) { bool2 = bool3; } i24 += i12; i25++; i10 = i26; } } else { i4 = i10; int i28 = ((i22 - i21) * i12) + i24; int i29 = i21; while (i29 < i22) { int i30 = i22; int a = a(i24, i28, gifFrame.c); if (a != 0) { iArr[i29] = a; } else if (z && bool2 == null) { bool2 = bool3; } i24 += i12; i29++; i22 = i30; } i15++; i16 = i2; i10 = i4; bool = bool3; i8 = i; i9 = i3; } } else { i3 = i9; } i4 = i10; i15++; i16 = i2; i10 = i4; bool = bool3; i8 = i; i9 = i3; } if (this.s == null) { this.s = Boolean.valueOf(bool2 == null ? false : bool2.booleanValue()); } } private int a(int i, int i2, int i3) { int i4 = 0; int i5 = 0; int i6 = 0; int i7 = 0; int i8 = 0; for (int i9 = i; i9 < this.p + i; i9++) { byte[] bArr = this.i; if (i9 >= bArr.length || i9 >= i2) { break; } int i10 = this.a[bArr[i9] & 255]; if (i10 != 0) { i4 += (i10 >> 24) & 255; i5 += (i10 >> 16) & 255; i6 += (i10 >> 8) & 255; i7 += i10 & 255; i8++; } } int i11 = i + i3; for (int i12 = i11; i12 < this.p + i11; i12++) { byte[] bArr2 = this.i; if (i12 >= bArr2.length || i12 >= i2) { break; } int i13 = this.a[bArr2[i12] & 255]; if (i13 != 0) { i4 += (i13 >> 24) & 255; i5 += (i13 >> 16) & 255; i6 += (i13 >> 8) & 255; i7 += i13 & 255; i8++; } } if (i8 == 0) { return 0; } return ((i4 / i8) << 24) | ((i5 / i8) << 16) | ((i6 / i8) << 8) | (i7 / i8); } }