package coil.transform;

import A4.d;
import L4.a;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.graphics.Shader;
import coil.decode.DecodeUtils;
import coil.size.Dimension;
import coil.size.Scale;
import coil.size.Size;
import coil.size.Sizes;
import coil.util.Bitmaps;
import kotlin.jvm.internal.h;
import w4.k;

/* JADX INFO: loaded from: classes.dex */
public final class RoundedCornersTransformation implements Transformation {
    private final float bottomLeft;
    private final float bottomRight;
    private final String cacheKey;
    private final float topLeft;
    private final float topRight;

    public RoundedCornersTransformation() {
        this(0.0f, 0.0f, 0.0f, 0.0f, 15, null);
    }

    private final k calculateOutputSize(Bitmap bitmap, Size size) {
        if (Sizes.isOriginal(size)) {
            return new k(Integer.valueOf(bitmap.getWidth()), Integer.valueOf(bitmap.getHeight()));
        }
        Dimension dimensionComponent1 = size.component1();
        Dimension dimensionComponent2 = size.component2();
        if ((dimensionComponent1 instanceof Dimension.Pixels) && (dimensionComponent2 instanceof Dimension.Pixels)) {
            return new k(Integer.valueOf(((Dimension.Pixels) dimensionComponent1).px), Integer.valueOf(((Dimension.Pixels) dimensionComponent2).px));
        }
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Dimension width2 = size.getWidth();
        int i6 = width2 instanceof Dimension.Pixels ? ((Dimension.Pixels) width2).px : Integer.MIN_VALUE;
        Dimension height2 = size.getHeight();
        double dComputeSizeMultiplier = DecodeUtils.computeSizeMultiplier(width, height, i6, height2 instanceof Dimension.Pixels ? ((Dimension.Pixels) height2).px : Integer.MIN_VALUE, Scale.FILL);
        return new k(Integer.valueOf(a.c0(((double) bitmap.getWidth()) * dComputeSizeMultiplier)), Integer.valueOf(a.c0(dComputeSizeMultiplier * ((double) bitmap.getHeight()))));
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof RoundedCornersTransformation)) {
            return false;
        }
        RoundedCornersTransformation roundedCornersTransformation = (RoundedCornersTransformation) obj;
        return this.topLeft == roundedCornersTransformation.topLeft && this.topRight == roundedCornersTransformation.topRight && this.bottomLeft == roundedCornersTransformation.bottomLeft && this.bottomRight == roundedCornersTransformation.bottomRight;
    }

    @Override // coil.transform.Transformation
    public String getCacheKey() {
        return this.cacheKey;
    }

    public int hashCode() {
        return Float.hashCode(this.bottomRight) + com.google.android.recaptcha.internal.a.b(this.bottomLeft, com.google.android.recaptcha.internal.a.b(this.topRight, Float.hashCode(this.topLeft) * 31, 31), 31);
    }

    @Override // coil.transform.Transformation
    public Object transform(Bitmap bitmap, Size size, d dVar) {
        Paint paint = new Paint(3);
        k kVarCalculateOutputSize = calculateOutputSize(bitmap, size);
        int iIntValue = ((Number) kVarCalculateOutputSize.f25469a).intValue();
        int iIntValue2 = ((Number) kVarCalculateOutputSize.f25470b).intValue();
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(iIntValue, iIntValue2, Bitmaps.getSafeConfig(bitmap));
        Canvas canvas = new Canvas(bitmapCreateBitmap);
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        Matrix matrix = new Matrix();
        float fComputeSizeMultiplier = (float) DecodeUtils.computeSizeMultiplier(bitmap.getWidth(), bitmap.getHeight(), iIntValue, iIntValue2, Scale.FILL);
        float f6 = 2;
        matrix.setTranslate((iIntValue - (bitmap.getWidth() * fComputeSizeMultiplier)) / f6, (iIntValue2 - (bitmap.getHeight() * fComputeSizeMultiplier)) / f6);
        matrix.preScale(fComputeSizeMultiplier, fComputeSizeMultiplier);
        Shader.TileMode tileMode = Shader.TileMode.CLAMP;
        BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode);
        bitmapShader.setLocalMatrix(matrix);
        paint.setShader(bitmapShader);
        float f7 = this.topLeft;
        float f8 = this.topRight;
        float f9 = this.bottomRight;
        float f10 = this.bottomLeft;
        float[] fArr = {f7, f7, f8, f8, f9, f9, f10, f10};
        RectF rectF = new RectF(0.0f, 0.0f, canvas.getWidth(), canvas.getHeight());
        Path path = new Path();
        path.addRoundRect(rectF, fArr, Path.Direction.CW);
        canvas.drawPath(path, paint);
        return bitmapCreateBitmap;
    }

    public RoundedCornersTransformation(float f6, float f7, float f8, float f9) {
        this.topLeft = f6;
        this.topRight = f7;
        this.bottomLeft = f8;
        this.bottomRight = f9;
        if (f6 < 0.0f || f7 < 0.0f || f8 < 0.0f || f9 < 0.0f) {
            throw new IllegalArgumentException("All radii must be >= 0.");
        }
        this.cacheKey = RoundedCornersTransformation.class.getName() + '-' + f6 + ',' + f7 + ',' + f8 + ',' + f9;
    }

    public /* synthetic */ RoundedCornersTransformation(float f6, float f7, float f8, float f9, int i6, h hVar) {
        this((i6 & 1) != 0 ? 0.0f : f6, (i6 & 2) != 0 ? 0.0f : f7, (i6 & 4) != 0 ? 0.0f : f8, (i6 & 8) != 0 ? 0.0f : f9);
    }

    public RoundedCornersTransformation(float f6) {
        this(f6, f6, f6, f6);
    }
}
