jimu-decompiled/sources/com/bumptech/glide/load/resource/gif/StreamGifDecoder.java
2025-05-13 19:24:51 +02:00

64 lines
2.4 KiB
Java

package com.bumptech.glide.load.resource.gif;
import android.util.Log;
import com.bumptech.glide.load.ImageHeaderParser;
import com.bumptech.glide.load.ImageHeaderParserUtils;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.List;
/* loaded from: classes.dex */
public class StreamGifDecoder implements ResourceDecoder<InputStream, GifDrawable> {
private final List<ImageHeaderParser> a;
private final ResourceDecoder<ByteBuffer, GifDrawable> b;
private final ArrayPool c;
public StreamGifDecoder(List<ImageHeaderParser> list, ResourceDecoder<ByteBuffer, GifDrawable> resourceDecoder, ArrayPool arrayPool) {
this.a = list;
this.b = resourceDecoder;
this.c = arrayPool;
}
@Override // com.bumptech.glide.load.ResourceDecoder
public boolean a(InputStream inputStream, Options options) throws IOException {
return !((Boolean) options.a(GifOptions.b)).booleanValue() && ImageHeaderParserUtils.b(this.a, inputStream, this.c) == ImageHeaderParser.ImageType.GIF;
}
@Override // com.bumptech.glide.load.ResourceDecoder
public Resource<GifDrawable> a(InputStream inputStream, int i, int i2, Options options) throws IOException {
byte[] a = a(inputStream);
if (a == null) {
return null;
}
return this.b.a(ByteBuffer.wrap(a), i, i2, options);
}
private static byte[] a(InputStream inputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(16384);
try {
byte[] bArr = new byte[16384];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
byteArrayOutputStream.write(bArr, 0, read);
} else {
byteArrayOutputStream.flush();
return byteArrayOutputStream.toByteArray();
}
}
} catch (IOException e) {
if (!Log.isLoggable("StreamGifDecoder", 5)) {
return null;
}
Log.w("StreamGifDecoder", "Error reading data from stream", e);
return null;
}
}
}