package rh;

import android.graphics.ColorSpace;
import android.graphics.ImageDecoder;
import android.util.Log;
import android.util.Size;
import jh.g;
import jh.h;
import jh.i;
import sh.l;
import sh.m;
import sh.r;

/* loaded from: classes4.dex */
public final class a implements ImageDecoder.OnHeaderDecodedListener {

    /* renamed from: a, reason: collision with root package name */
    private final r f34786a = r.b();

    /* renamed from: b, reason: collision with root package name */
    private final int f34787b;

    /* renamed from: c, reason: collision with root package name */
    private final int f34788c;

    /* renamed from: d, reason: collision with root package name */
    private final jh.b f34789d;

    /* renamed from: e, reason: collision with root package name */
    private final l f34790e;

    /* renamed from: f, reason: collision with root package name */
    private final boolean f34791f;

    /* renamed from: g, reason: collision with root package name */
    private final i f34792g;

    /* renamed from: rh.a$a, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    class C0821a implements ImageDecoder.OnPartialImageListener {
        C0821a() {
        }

        @Override // android.graphics.ImageDecoder.OnPartialImageListener
        public boolean onPartialImage(ImageDecoder.DecodeException decodeException) {
            return false;
        }
    }

    public a(int i10, int i11, h hVar) {
        this.f34787b = i10;
        this.f34788c = i11;
        this.f34789d = (jh.b) hVar.c(m.f35733f);
        this.f34790e = (l) hVar.c(l.f35731h);
        g gVar = m.f35737j;
        this.f34791f = hVar.c(gVar) != null && ((Boolean) hVar.c(gVar)).booleanValue();
        this.f34792g = (i) hVar.c(m.f35734g);
    }

    @Override // android.graphics.ImageDecoder.OnHeaderDecodedListener
    public void onHeaderDecoded(ImageDecoder imageDecoder, ImageDecoder.ImageInfo imageInfo, ImageDecoder.Source source) {
        boolean z10 = false;
        if (this.f34786a.e(this.f34787b, this.f34788c, this.f34791f, false)) {
            imageDecoder.setAllocator(3);
        } else {
            imageDecoder.setAllocator(1);
        }
        if (this.f34789d == jh.b.PREFER_RGB_565) {
            imageDecoder.setMemorySizePolicy(0);
        }
        imageDecoder.setOnPartialImageListener(new C0821a());
        Size size = imageInfo.getSize();
        int i10 = this.f34787b;
        if (i10 == Integer.MIN_VALUE) {
            i10 = size.getWidth();
        }
        int i11 = this.f34788c;
        if (i11 == Integer.MIN_VALUE) {
            i11 = size.getHeight();
        }
        float b10 = this.f34790e.b(size.getWidth(), size.getHeight(), i10, i11);
        int round = Math.round(size.getWidth() * b10);
        int round2 = Math.round(size.getHeight() * b10);
        if (Log.isLoggable("ImageDecoder", 2)) {
            Log.v("ImageDecoder", "Resizing from [" + size.getWidth() + "x" + size.getHeight() + "] to [" + round + "x" + round2 + "] scaleFactor: " + b10);
        }
        imageDecoder.setTargetSize(round, round2);
        i iVar = this.f34792g;
        if (iVar != null) {
            if (iVar == i.DISPLAY_P3 && imageInfo.getColorSpace() != null && imageInfo.getColorSpace().isWideGamut()) {
                z10 = true;
            }
            imageDecoder.setTargetColorSpace(ColorSpace.get(z10 ? ColorSpace.Named.DISPLAY_P3 : ColorSpace.Named.SRGB));
        }
    }
}
