Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,131 @@
package com.bumptech.glide.load.resource.gif;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.gifdecoder.GifHeader;
import com.bumptech.glide.gifdecoder.GifHeaderParser;
import com.bumptech.glide.gifdecoder.StandardGifDecoder;
import com.bumptech.glide.load.DecodeFormat;
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.bitmap_recycle.ArrayPool;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.UnitTransformation;
import com.bumptech.glide.util.LogTime;
import com.bumptech.glide.util.Util;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Queue;
/* loaded from: classes.dex */
public class ByteBufferGifDecoder implements ResourceDecoder<ByteBuffer, GifDrawable> {
private static final GifDecoderFactory f = new GifDecoderFactory();
private static final GifHeaderParserPool g = new GifHeaderParserPool();
private final Context a;
private final List<ImageHeaderParser> b;
private final GifHeaderParserPool c;
private final GifDecoderFactory d;
private final GifBitmapProvider e;
static class GifDecoderFactory {
GifDecoderFactory() {
}
GifDecoder a(GifDecoder.BitmapProvider bitmapProvider, GifHeader gifHeader, ByteBuffer byteBuffer, int i) {
return new StandardGifDecoder(bitmapProvider, gifHeader, byteBuffer, i);
}
}
public ByteBufferGifDecoder(Context context, List<ImageHeaderParser> list, BitmapPool bitmapPool, ArrayPool arrayPool) {
this(context, list, bitmapPool, arrayPool, g, f);
}
ByteBufferGifDecoder(Context context, List<ImageHeaderParser> list, BitmapPool bitmapPool, ArrayPool arrayPool, GifHeaderParserPool gifHeaderParserPool, GifDecoderFactory gifDecoderFactory) {
this.a = context.getApplicationContext();
this.b = list;
this.d = gifDecoderFactory;
this.e = new GifBitmapProvider(bitmapPool, arrayPool);
this.c = gifHeaderParserPool;
}
static class GifHeaderParserPool {
private final Queue<GifHeaderParser> a = Util.a(0);
GifHeaderParserPool() {
}
synchronized GifHeaderParser a(ByteBuffer byteBuffer) {
GifHeaderParser poll;
poll = this.a.poll();
if (poll == null) {
poll = new GifHeaderParser();
}
poll.a(byteBuffer);
return poll;
}
synchronized void a(GifHeaderParser gifHeaderParser) {
gifHeaderParser.a();
this.a.offer(gifHeaderParser);
}
}
@Override // com.bumptech.glide.load.ResourceDecoder
public boolean a(ByteBuffer byteBuffer, Options options) throws IOException {
return !((Boolean) options.a(GifOptions.b)).booleanValue() && ImageHeaderParserUtils.a(this.b, byteBuffer) == ImageHeaderParser.ImageType.GIF;
}
@Override // com.bumptech.glide.load.ResourceDecoder
public GifDrawableResource a(ByteBuffer byteBuffer, int i, int i2, Options options) {
GifHeaderParser a = this.c.a(byteBuffer);
try {
return a(byteBuffer, i, i2, a, options);
} finally {
this.c.a(a);
}
}
private GifDrawableResource a(ByteBuffer byteBuffer, int i, int i2, GifHeaderParser gifHeaderParser, Options options) {
long a = LogTime.a();
try {
GifHeader b = gifHeaderParser.b();
if (b.b() > 0 && b.c() == 0) {
Bitmap.Config config = options.a(GifOptions.a) == DecodeFormat.PREFER_RGB_565 ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;
GifDecoder a2 = this.d.a(this.e, b, byteBuffer, a(b, i, i2));
a2.a(config);
a2.b();
Bitmap a3 = a2.a();
if (a3 == null) {
return null;
}
GifDrawableResource gifDrawableResource = new GifDrawableResource(new GifDrawable(this.a, a2, UnitTransformation.a(), i, i2, a3));
if (Log.isLoggable("BufferGifDecoder", 2)) {
Log.v("BufferGifDecoder", "Decoded GIF from stream in " + LogTime.a(a));
}
return gifDrawableResource;
}
if (Log.isLoggable("BufferGifDecoder", 2)) {
Log.v("BufferGifDecoder", "Decoded GIF from stream in " + LogTime.a(a));
}
return null;
} finally {
if (Log.isLoggable("BufferGifDecoder", 2)) {
Log.v("BufferGifDecoder", "Decoded GIF from stream in " + LogTime.a(a));
}
}
}
private static int a(GifHeader gifHeader, int i, int i2) {
int min = Math.min(gifHeader.a() / i2, gifHeader.d() / i);
int max = Math.max(1, min == 0 ? 0 : Integer.highestOneBit(min));
if (Log.isLoggable("BufferGifDecoder", 2) && max > 1) {
Log.v("BufferGifDecoder", "Downsampling GIF, sampleSize: " + max + ", target dimens: [" + i + "x" + i2 + "], actual dimens: [" + gifHeader.d() + "x" + gifHeader.a() + "]");
}
return max;
}
}

View File

@@ -0,0 +1,60 @@
package com.bumptech.glide.load.resource.gif;
import android.graphics.Bitmap;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
/* loaded from: classes.dex */
public final class GifBitmapProvider implements GifDecoder.BitmapProvider {
private final BitmapPool a;
private final ArrayPool b;
public GifBitmapProvider(BitmapPool bitmapPool, ArrayPool arrayPool) {
this.a = bitmapPool;
this.b = arrayPool;
}
@Override // com.bumptech.glide.gifdecoder.GifDecoder.BitmapProvider
public Bitmap a(int i, int i2, Bitmap.Config config) {
return this.a.b(i, i2, config);
}
@Override // com.bumptech.glide.gifdecoder.GifDecoder.BitmapProvider
public byte[] b(int i) {
ArrayPool arrayPool = this.b;
return arrayPool == null ? new byte[i] : (byte[]) arrayPool.b(i, byte[].class);
}
@Override // com.bumptech.glide.gifdecoder.GifDecoder.BitmapProvider
public void a(Bitmap bitmap) {
this.a.a(bitmap);
}
@Override // com.bumptech.glide.gifdecoder.GifDecoder.BitmapProvider
public void a(byte[] bArr) {
ArrayPool arrayPool = this.b;
if (arrayPool == null) {
return;
}
arrayPool.put(bArr);
}
@Override // com.bumptech.glide.gifdecoder.GifDecoder.BitmapProvider
public int[] a(int i) {
ArrayPool arrayPool = this.b;
if (arrayPool == null) {
return new int[i];
}
return (int[]) arrayPool.b(i, int[].class);
}
@Override // com.bumptech.glide.gifdecoder.GifDecoder.BitmapProvider
public void a(int[] iArr) {
ArrayPool arrayPool = this.b;
if (arrayPool == null) {
return;
}
arrayPool.put(iArr);
}
}

View File

@@ -0,0 +1,239 @@
package com.bumptech.glide.load.resource.gif;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import com.bumptech.glide.Glide;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.resource.gif.GifFrameLoader;
import com.bumptech.glide.util.Preconditions;
import java.nio.ByteBuffer;
/* loaded from: classes.dex */
public class GifDrawable extends Drawable implements GifFrameLoader.FrameCallback, Animatable {
private final GifState a;
private boolean b;
private boolean c;
private boolean d;
private boolean e;
private int f;
private int g;
private boolean h;
private Paint i;
private Rect j;
static final class GifState extends Drawable.ConstantState {
final GifFrameLoader a;
GifState(GifFrameLoader gifFrameLoader) {
this.a = gifFrameLoader;
}
@Override // android.graphics.drawable.Drawable.ConstantState
public int getChangingConfigurations() {
return 0;
}
@Override // android.graphics.drawable.Drawable.ConstantState
public Drawable newDrawable(Resources resources) {
return newDrawable();
}
@Override // android.graphics.drawable.Drawable.ConstantState
public Drawable newDrawable() {
return new GifDrawable(this);
}
}
public GifDrawable(Context context, GifDecoder gifDecoder, Transformation<Bitmap> transformation, int i, int i2, Bitmap bitmap) {
this(new GifState(new GifFrameLoader(Glide.b(context), gifDecoder, i, i2, transformation, bitmap)));
}
/* JADX WARN: Multi-variable type inference failed */
private Drawable.Callback h() {
Drawable.Callback callback = getCallback();
while (callback instanceof Drawable) {
callback = ((Drawable) callback).getCallback();
}
return callback;
}
private Rect i() {
if (this.j == null) {
this.j = new Rect();
}
return this.j;
}
private Paint j() {
if (this.i == null) {
this.i = new Paint(2);
}
return this.i;
}
private void k() {
this.f = 0;
}
private void l() {
Preconditions.a(!this.d, "You cannot start a recycled Drawable. Ensure thatyou clear any references to the Drawable when clearing the corresponding request.");
if (this.a.a.f() == 1) {
invalidateSelf();
} else {
if (this.b) {
return;
}
this.b = true;
this.a.a.a(this);
invalidateSelf();
}
}
private void m() {
this.b = false;
this.a.a.b(this);
}
public void a(Transformation<Bitmap> transformation, Bitmap bitmap) {
this.a.a.a(transformation, bitmap);
}
public ByteBuffer b() {
return this.a.a.b();
}
public Bitmap c() {
return this.a.a.e();
}
public int d() {
return this.a.a.f();
}
@Override // android.graphics.drawable.Drawable
public void draw(Canvas canvas) {
if (this.d) {
return;
}
if (this.h) {
Gravity.apply(119, getIntrinsicWidth(), getIntrinsicHeight(), getBounds(), i());
this.h = false;
}
canvas.drawBitmap(this.a.a.c(), (Rect) null, i(), j());
}
public int e() {
return this.a.a.d();
}
public int f() {
return this.a.a.h();
}
public void g() {
this.d = true;
this.a.a.a();
}
@Override // android.graphics.drawable.Drawable
public Drawable.ConstantState getConstantState() {
return this.a;
}
@Override // android.graphics.drawable.Drawable
public int getIntrinsicHeight() {
return this.a.a.g();
}
@Override // android.graphics.drawable.Drawable
public int getIntrinsicWidth() {
return this.a.a.i();
}
@Override // android.graphics.drawable.Drawable
public int getOpacity() {
return -2;
}
@Override // android.graphics.drawable.Animatable
public boolean isRunning() {
return this.b;
}
@Override // android.graphics.drawable.Drawable
protected void onBoundsChange(Rect rect) {
super.onBoundsChange(rect);
this.h = true;
}
@Override // android.graphics.drawable.Drawable
public void setAlpha(int i) {
j().setAlpha(i);
}
@Override // android.graphics.drawable.Drawable
public void setColorFilter(ColorFilter colorFilter) {
j().setColorFilter(colorFilter);
}
@Override // android.graphics.drawable.Drawable
public boolean setVisible(boolean z, boolean z2) {
Preconditions.a(!this.d, "Cannot change the visibility of a recycled resource. Ensure that you unset the Drawable from your View before changing the View's visibility.");
this.e = z;
if (!z) {
m();
} else if (this.c) {
l();
}
return super.setVisible(z, z2);
}
@Override // android.graphics.drawable.Animatable
public void start() {
this.c = true;
k();
if (this.e) {
l();
}
}
@Override // android.graphics.drawable.Animatable
public void stop() {
this.c = false;
m();
}
@Override // com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback
public void a() {
if (h() == null) {
stop();
invalidateSelf();
return;
}
invalidateSelf();
if (e() == d() - 1) {
this.f++;
}
int i = this.g;
if (i == -1 || this.f < i) {
return;
}
stop();
}
GifDrawable(GifState gifState) {
this.e = true;
this.g = -1;
Preconditions.a(gifState);
this.a = gifState;
}
}

View File

@@ -0,0 +1,31 @@
package com.bumptech.glide.load.resource.gif;
import android.util.Log;
import com.bumptech.glide.load.EncodeStrategy;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceEncoder;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.util.ByteBufferUtil;
import java.io.File;
import java.io.IOException;
/* loaded from: classes.dex */
public class GifDrawableEncoder implements ResourceEncoder<GifDrawable> {
@Override // com.bumptech.glide.load.ResourceEncoder
public EncodeStrategy a(Options options) {
return EncodeStrategy.SOURCE;
}
@Override // com.bumptech.glide.load.Encoder
public boolean a(Resource<GifDrawable> resource, File file, Options options) {
try {
ByteBufferUtil.a(resource.get().b(), file);
return true;
} catch (IOException e) {
if (Log.isLoggable("GifEncoder", 5)) {
Log.w("GifEncoder", "Failed to encode GIF drawable data", e);
}
return false;
}
}
}

View File

@@ -0,0 +1,32 @@
package com.bumptech.glide.load.resource.gif;
import com.bumptech.glide.load.engine.Initializable;
import com.bumptech.glide.load.resource.drawable.DrawableResource;
/* loaded from: classes.dex */
public class GifDrawableResource extends DrawableResource<GifDrawable> implements Initializable {
public GifDrawableResource(GifDrawable gifDrawable) {
super(gifDrawable);
}
@Override // com.bumptech.glide.load.engine.Resource
public void a() {
((GifDrawable) this.a).stop();
((GifDrawable) this.a).g();
}
@Override // com.bumptech.glide.load.engine.Resource
public Class<GifDrawable> b() {
return GifDrawable.class;
}
@Override // com.bumptech.glide.load.resource.drawable.DrawableResource, com.bumptech.glide.load.engine.Initializable
public void c() {
((GifDrawable) this.a).c().prepareToDraw();
}
@Override // com.bumptech.glide.load.engine.Resource
public int getSize() {
return ((GifDrawable) this.a).f();
}
}

View File

@@ -0,0 +1,50 @@
package com.bumptech.glide.load.resource.gif;
import android.content.Context;
import android.graphics.Bitmap;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.util.Preconditions;
import java.security.MessageDigest;
/* loaded from: classes.dex */
public class GifDrawableTransformation implements Transformation<GifDrawable> {
private final Transformation<Bitmap> b;
public GifDrawableTransformation(Transformation<Bitmap> transformation) {
Preconditions.a(transformation);
this.b = transformation;
}
@Override // com.bumptech.glide.load.Transformation
public Resource<GifDrawable> a(Context context, Resource<GifDrawable> resource, int i, int i2) {
GifDrawable gifDrawable = resource.get();
Resource<Bitmap> bitmapResource = new BitmapResource(gifDrawable.c(), Glide.b(context).d());
Resource<Bitmap> a = this.b.a(context, bitmapResource, i, i2);
if (!bitmapResource.equals(a)) {
bitmapResource.a();
}
gifDrawable.a(this.b, a.get());
return resource;
}
@Override // com.bumptech.glide.load.Key
public boolean equals(Object obj) {
if (obj instanceof GifDrawableTransformation) {
return this.b.equals(((GifDrawableTransformation) obj).b);
}
return false;
}
@Override // com.bumptech.glide.load.Key
public int hashCode() {
return this.b.hashCode();
}
@Override // com.bumptech.glide.load.Key
public void a(MessageDigest messageDigest) {
this.b.a(messageDigest);
}
}

View File

@@ -0,0 +1,293 @@
package com.bumptech.glide.load.resource.gif;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.bumptech.glide.signature.ObjectKey;
import com.bumptech.glide.util.Preconditions;
import com.bumptech.glide.util.Util;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes.dex */
class GifFrameLoader {
private final GifDecoder a;
private final Handler b;
private final List<FrameCallback> c;
final RequestManager d;
private final BitmapPool e;
private boolean f;
private boolean g;
private boolean h;
private RequestBuilder<Bitmap> i;
private DelayTarget j;
private boolean k;
private DelayTarget l;
private Bitmap m;
private DelayTarget n;
private OnEveryFrameListener o;
static class DelayTarget extends SimpleTarget<Bitmap> {
private final Handler d;
final int e;
private final long f;
private Bitmap g;
DelayTarget(Handler handler, int i, long j) {
this.d = handler;
this.e = i;
this.f = j;
}
@Override // com.bumptech.glide.request.target.Target
public /* bridge */ /* synthetic */ void a(Object obj, Transition transition) {
a((Bitmap) obj, (Transition<? super Bitmap>) transition);
}
Bitmap d() {
return this.g;
}
public void a(Bitmap bitmap, Transition<? super Bitmap> transition) {
this.g = bitmap;
this.d.sendMessageAtTime(this.d.obtainMessage(1, this), this.f);
}
}
public interface FrameCallback {
void a();
}
private class FrameLoaderCallback implements Handler.Callback {
FrameLoaderCallback() {
}
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
int i = message.what;
if (i == 1) {
GifFrameLoader.this.a((DelayTarget) message.obj);
return true;
}
if (i != 2) {
return false;
}
GifFrameLoader.this.d.a((Target<?>) message.obj);
return false;
}
}
interface OnEveryFrameListener {
void a();
}
GifFrameLoader(Glide glide, GifDecoder gifDecoder, int i, int i2, Transformation<Bitmap> transformation, Bitmap bitmap) {
this(glide.d(), Glide.e(glide.f()), gifDecoder, null, a(Glide.e(glide.f()), i, i2), transformation, bitmap);
}
private static Key j() {
return new ObjectKey(Double.valueOf(Math.random()));
}
private int k() {
return Util.a(c().getWidth(), c().getHeight(), c().getConfig());
}
private void l() {
if (!this.f || this.g) {
return;
}
if (this.h) {
Preconditions.a(this.n == null, "Pending target must be null when starting from the first frame");
this.a.f();
this.h = false;
}
DelayTarget delayTarget = this.n;
if (delayTarget != null) {
this.n = null;
a(delayTarget);
return;
}
this.g = true;
long uptimeMillis = SystemClock.uptimeMillis() + this.a.d();
this.a.b();
this.l = new DelayTarget(this.b, this.a.g(), uptimeMillis);
RequestBuilder<Bitmap> requestBuilder = this.i;
requestBuilder.a(RequestOptions.b(j()));
requestBuilder.a(this.a);
requestBuilder.a((RequestBuilder<Bitmap>) this.l);
}
private void m() {
Bitmap bitmap = this.m;
if (bitmap != null) {
this.e.a(bitmap);
this.m = null;
}
}
private void n() {
if (this.f) {
return;
}
this.f = true;
this.k = false;
l();
}
private void o() {
this.f = false;
}
void a(Transformation<Bitmap> transformation, Bitmap bitmap) {
Preconditions.a(transformation);
Preconditions.a(bitmap);
this.m = bitmap;
RequestBuilder<Bitmap> requestBuilder = this.i;
requestBuilder.a(new RequestOptions().a(transformation));
this.i = requestBuilder;
}
void b(FrameCallback frameCallback) {
this.c.remove(frameCallback);
if (this.c.isEmpty()) {
o();
}
}
Bitmap c() {
DelayTarget delayTarget = this.j;
return delayTarget != null ? delayTarget.d() : this.m;
}
int d() {
DelayTarget delayTarget = this.j;
if (delayTarget != null) {
return delayTarget.e;
}
return -1;
}
Bitmap e() {
return this.m;
}
int f() {
return this.a.c();
}
int g() {
return c().getHeight();
}
int h() {
return this.a.h() + k();
}
int i() {
return c().getWidth();
}
void a(FrameCallback frameCallback) {
if (!this.k) {
if (!this.c.contains(frameCallback)) {
boolean isEmpty = this.c.isEmpty();
this.c.add(frameCallback);
if (isEmpty) {
n();
return;
}
return;
}
throw new IllegalStateException("Cannot subscribe twice in a row");
}
throw new IllegalStateException("Cannot subscribe to a cleared frame loader");
}
ByteBuffer b() {
return this.a.e().asReadOnlyBuffer();
}
GifFrameLoader(BitmapPool bitmapPool, RequestManager requestManager, GifDecoder gifDecoder, Handler handler, RequestBuilder<Bitmap> requestBuilder, Transformation<Bitmap> transformation, Bitmap bitmap) {
this.c = new ArrayList();
this.d = requestManager;
handler = handler == null ? new Handler(Looper.getMainLooper(), new FrameLoaderCallback()) : handler;
this.e = bitmapPool;
this.b = handler;
this.i = requestBuilder;
this.a = gifDecoder;
a(transformation, bitmap);
}
void a() {
this.c.clear();
m();
o();
DelayTarget delayTarget = this.j;
if (delayTarget != null) {
this.d.a((Target<?>) delayTarget);
this.j = null;
}
DelayTarget delayTarget2 = this.l;
if (delayTarget2 != null) {
this.d.a((Target<?>) delayTarget2);
this.l = null;
}
DelayTarget delayTarget3 = this.n;
if (delayTarget3 != null) {
this.d.a((Target<?>) delayTarget3);
this.n = null;
}
this.a.clear();
this.k = true;
}
void a(DelayTarget delayTarget) {
OnEveryFrameListener onEveryFrameListener = this.o;
if (onEveryFrameListener != null) {
onEveryFrameListener.a();
}
this.g = false;
if (this.k) {
this.b.obtainMessage(2, delayTarget).sendToTarget();
return;
}
if (!this.f) {
this.n = delayTarget;
return;
}
if (delayTarget.d() != null) {
m();
DelayTarget delayTarget2 = this.j;
this.j = delayTarget;
for (int size = this.c.size() - 1; size >= 0; size--) {
this.c.get(size).a();
}
if (delayTarget2 != null) {
this.b.obtainMessage(2, delayTarget2).sendToTarget();
}
}
l();
}
private static RequestBuilder<Bitmap> a(RequestManager requestManager, int i, int i2) {
RequestBuilder<Bitmap> d = requestManager.d();
d.a(RequestOptions.b(DiskCacheStrategy.b).b(true).a(true).a(i, i2));
return d;
}
}

View File

@@ -0,0 +1,28 @@
package com.bumptech.glide.load.resource.gif;
import android.graphics.Bitmap;
import com.bumptech.glide.gifdecoder.GifDecoder;
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.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
/* loaded from: classes.dex */
public final class GifFrameResourceDecoder implements ResourceDecoder<GifDecoder, Bitmap> {
private final BitmapPool a;
public GifFrameResourceDecoder(BitmapPool bitmapPool) {
this.a = bitmapPool;
}
@Override // com.bumptech.glide.load.ResourceDecoder
public boolean a(GifDecoder gifDecoder, Options options) {
return true;
}
@Override // com.bumptech.glide.load.ResourceDecoder
public Resource<Bitmap> a(GifDecoder gifDecoder, int i, int i2, Options options) {
return BitmapResource.a(gifDecoder.a(), this.a);
}
}

View File

@@ -0,0 +1,10 @@
package com.bumptech.glide.load.resource.gif;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.Option;
/* loaded from: classes.dex */
public final class GifOptions {
public static final Option<DecodeFormat> a = Option.a("com.bumptech.glide.load.resource.gif.GifOptions.DecodeFormat", DecodeFormat.DEFAULT);
public static final Option<Boolean> b = Option.a("com.bumptech.glide.load.resource.gif.GifOptions.DisableAnimation", false);
}

View File

@@ -0,0 +1,63 @@
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;
}
}
}