package p138.p145.p146.p151.p160.p165;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import com.bumptech.glide.load.ImageHeaderParser;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import p138.p139.p143.p144.C2803;
import p138.p145.p146.p148.C2833;
import p138.p145.p146.p148.C2834;
import p138.p145.p146.p148.C2835;
import p138.p145.p146.p151.C2848;
import p138.p145.p146.p151.EnumC2841;
import p138.p145.p146.p151.InterfaceC2850;
import p138.p145.p146.p151.p154.InterfaceC2932;
import p138.p145.p146.p151.p154.p155.InterfaceC2940;
import p138.p145.p146.p151.p154.p155.InterfaceC2942;
import p138.p145.p146.p151.p160.C3078;
import p138.p145.p146.p174.C3236;
import p138.p145.p146.p174.C3240;

/* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ތ.ބ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C3138 implements InterfaceC2850<ByteBuffer, C3142> {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final C3139 f9368 = new C3139();

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final C3140 f9369 = new C3140();

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Context f9370;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final List<ImageHeaderParser> f9371;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final C3140 f9372;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C3139 f9373;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final C3141 f9374;

    /* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ތ.ބ.֏$֏, reason: contains not printable characters */
    public static class C3139 {
    }

    /* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ތ.ބ.֏$ؠ, reason: contains not printable characters */
    public static class C3140 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final Queue<C2834> f9375 = C3240.m5334(0);

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public synchronized C2834 m5210(ByteBuffer byteBuffer) {
            C2834 c2834Poll;
            c2834Poll = this.f9375.poll();
            if (c2834Poll == null) {
                c2834Poll = new C2834();
            }
            c2834Poll.f8764 = null;
            Arrays.fill(c2834Poll.f8763, (byte) 0);
            c2834Poll.f8765 = new C2833();
            c2834Poll.f8766 = 0;
            ByteBuffer byteBufferAsReadOnlyBuffer = byteBuffer.asReadOnlyBuffer();
            c2834Poll.f8764 = byteBufferAsReadOnlyBuffer;
            byteBufferAsReadOnlyBuffer.position(0);
            c2834Poll.f8764.order(ByteOrder.LITTLE_ENDIAN);
            return c2834Poll;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public synchronized void m5211(C2834 c2834) {
            c2834.f8764 = null;
            c2834.f8765 = null;
            this.f9375.offer(c2834);
        }
    }

    public C3138(Context context, List<ImageHeaderParser> list, InterfaceC2942 interfaceC2942, InterfaceC2940 interfaceC2940) {
        C3140 c3140 = f9369;
        C3139 c3139 = f9368;
        this.f9370 = context.getApplicationContext();
        this.f9371 = list;
        this.f9373 = c3139;
        this.f9374 = new C3141(interfaceC2942, interfaceC2940);
        this.f9372 = c3140;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static int m5208(C2833 c2833, int i, int i2) {
        int iMin = Math.min(c2833.f8756 / i2, c2833.f8755 / i);
        int iMax = Math.max(1, iMin == 0 ? 0 : Integer.highestOneBit(iMin));
        if (Log.isLoggable("BufferGifDecoder", 2) && iMax > 1) {
            StringBuilder sbM4890 = C2803.m4890("Downsampling GIF, sampleSize: ", iMax, ", target dimens: [", i, "x");
            sbM4890.append(i2);
            sbM4890.append("], actual dimens: [");
            sbM4890.append(c2833.f8755);
            sbM4890.append("x");
            sbM4890.append(c2833.f8756);
            sbM4890.append("]");
            Log.v("BufferGifDecoder", sbM4890.toString());
        }
        return iMax;
    }

    @Override // p138.p145.p146.p151.InterfaceC2850
    /* JADX INFO: renamed from: ֏ */
    public InterfaceC2932<C3142> mo4981(ByteBuffer byteBuffer, int i, int i2, C2848 c2848) {
        ByteBuffer byteBuffer2 = byteBuffer;
        C2834 c2834M5210 = this.f9372.m5210(byteBuffer2);
        try {
            return m5209(byteBuffer2, i, i2, c2834M5210, c2848);
        } finally {
            this.f9372.m5211(c2834M5210);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C3145 m5209(ByteBuffer byteBuffer, int i, int i2, C2834 c2834, C2848 c2848) {
        long jM5320 = C3236.m5320();
        try {
            C2833 c2833M4961 = c2834.m4961();
            if (c2833M4961.f8752 > 0 && c2833M4961.f8751 == 0) {
                Bitmap.Config config = c2848.m4979(C3152.f9413) == EnumC2841.PREFER_RGB_565 ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;
                int iM5208 = m5208(c2833M4961, i, i2);
                C3139 c3139 = this.f9373;
                C3141 c3141 = this.f9374;
                if (c3139 == null) {
                    throw null;
                }
                C2835 c2835 = new C2835(c3141, c2833M4961, byteBuffer, iM5208);
                c2835.mo4951(config);
                c2835.mo4953();
                Bitmap bitmapMo4952 = c2835.mo4952();
                if (bitmapMo4952 == null) {
                    return null;
                }
                C3145 c3145 = new C3145(new C3142(this.f9370, c2835, (C3078) C3078.f9277, i, i2, bitmapMo4952));
                if (Log.isLoggable("BufferGifDecoder", 2)) {
                    StringBuilder sbM4889 = C2803.m4889("Decoded GIF from stream in ");
                    sbM4889.append(C3236.m5319(jM5320));
                    Log.v("BufferGifDecoder", sbM4889.toString());
                }
                return c3145;
            }
            if (Log.isLoggable("BufferGifDecoder", 2)) {
                StringBuilder sbM48892 = C2803.m4889("Decoded GIF from stream in ");
                sbM48892.append(C3236.m5319(jM5320));
                Log.v("BufferGifDecoder", sbM48892.toString());
            }
            return null;
        } finally {
            if (Log.isLoggable("BufferGifDecoder", 2)) {
                StringBuilder sbM48893 = C2803.m4889("Decoded GIF from stream in ");
                sbM48893.append(C3236.m5319(jM5320));
                Log.v("BufferGifDecoder", sbM48893.toString());
            }
        }
    }

    @Override // p138.p145.p146.p151.InterfaceC2850
    /* JADX INFO: renamed from: ֏ */
    public boolean mo4982(ByteBuffer byteBuffer, C2848 c2848) {
        ImageHeaderParser.ImageType imageType;
        ByteBuffer byteBuffer2 = byteBuffer;
        if (((Boolean) c2848.m4979(C3152.f9414)).booleanValue()) {
            return false;
        }
        List<ImageHeaderParser> list = this.f9371;
        if (byteBuffer2 == null) {
            imageType = ImageHeaderParser.ImageType.UNKNOWN;
        } else {
            int size = list.size();
            int i = 0;
            while (true) {
                if (i >= size) {
                    imageType = ImageHeaderParser.ImageType.UNKNOWN;
                    break;
                }
                ImageHeaderParser.ImageType imageTypeMo1038 = list.get(i).mo1038(byteBuffer2);
                if (imageTypeMo1038 != ImageHeaderParser.ImageType.UNKNOWN) {
                    imageType = imageTypeMo1038;
                    break;
                }
                i++;
            }
        }
        return imageType == ImageHeaderParser.ImageType.GIF;
    }
}
