package l5;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.SystemClock;
import android.util.Log;
import androidx.annotation.Nullable;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.ImageHeaderParser$ImageType;
import com.bumptech.glide.load.engine.e0;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import xyz.stream.api.a0;

/* JADX INFO: loaded from: classes.dex */
public final class a implements a5.m {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final androidx.window.core.h f30117f = new androidx.window.core.h(15);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final a0 f30118g = new a0(14);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f30119a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final List f30120b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final a0 f30121c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final androidx.window.core.h f30122d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final b f30123e;

    public a(Context context, ArrayList arrayList, c5.e eVar, c5.b bVar) {
        androidx.window.core.h hVar = f30117f;
        this.f30119a = context.getApplicationContext();
        this.f30120b = arrayList;
        this.f30122d = hVar;
        this.f30123e = new b(eVar, bVar);
        this.f30121c = f30118g;
    }

    @Override // a5.m
    public final boolean a(Object obj, a5.l lVar) {
        return !((Boolean) lVar.get(l.f30160b)).booleanValue() && a5.g.getType(this.f30120b, (ByteBuffer) obj) == ImageHeaderParser$ImageType.GIF;
    }

    @Override // a5.m
    public final e0 decode(Object obj, int i10, int i11, a5.l lVar) {
        y4.d dVar;
        ByteBuffer byteBuffer = (ByteBuffer) obj;
        a0 a0Var = this.f30121c;
        synchronized (a0Var) {
            try {
                y4.d dVar2 = (y4.d) ((Queue) a0Var.f35758b).poll();
                if (dVar2 == null) {
                    dVar2 = new y4.d();
                }
                dVar = dVar2;
                dVar.e(byteBuffer);
            } catch (Throwable th) {
                throw th;
            }
        }
        try {
            return decode(byteBuffer, i10, i11, dVar, lVar);
        } finally {
            this.f30121c.j(dVar);
        }
    }

    @Nullable
    private e decode(ByteBuffer byteBuffer, int i10, int i11, y4.d dVar, a5.l lVar) {
        Bitmap.Config config;
        int i12 = t5.i.f32966a;
        SystemClock.elapsedRealtimeNanos();
        try {
            y4.c cVarB = dVar.b();
            if (cVarB.f36815c > 0 && cVarB.f36814b == 0) {
                if (lVar.get(l.f30159a) == DecodeFormat.f5596b) {
                    config = Bitmap.Config.RGB_565;
                } else {
                    config = Bitmap.Config.ARGB_8888;
                }
                int iMin = Math.min(cVarB.f36819g / i11, cVarB.f36818f / i10);
                int iMax = Math.max(1, iMin == 0 ? 0 : Integer.highestOneBit(iMin));
                androidx.window.core.h hVar = this.f30122d;
                b bVar = this.f30123e;
                hVar.getClass();
                y4.e eVar = new y4.e(bVar, cVarB, byteBuffer, iMax);
                eVar.d(config);
                eVar.f36839l = (eVar.f36839l + 1) % eVar.f36840m.f36815c;
                Bitmap nextFrame = eVar.getNextFrame();
                if (nextFrame == null) {
                    if (Log.isLoggable("BufferGifDecoder", 2)) {
                        SystemClock.elapsedRealtimeNanos();
                    }
                    return null;
                }
                e eVar2 = new e(new d(new c(new k(com.bumptech.glide.c.a(this.f30119a), eVar, i10, i11, i5.c.f26575b, nextFrame))));
                if (Log.isLoggable("BufferGifDecoder", 2)) {
                    SystemClock.elapsedRealtimeNanos();
                }
                return eVar2;
            }
            return null;
        } finally {
            if (Log.isLoggable("BufferGifDecoder", 2)) {
                SystemClock.elapsedRealtimeNanos();
            }
        }
    }
}
