package defpackage;

import android.graphics.Bitmap;
import android.os.SystemClock;
import android.util.Log;
import j$.util.Objects;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/* JADX INFO: renamed from: ᵺᵤᐧᵖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C5147 implements InterfaceC1220 {

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C5540 f19359;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public static final C1305 f19358 = C1305.m3832(90, "com.bumptech.glide.load.resource.bitmap.BitmapEncoder.CompressionQuality");

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public static final C1305 f19357 = new C1305("com.bumptech.glide.load.resource.bitmap.BitmapEncoder.CompressionFormat", null, C1305.f5473);

    public C5147(C5540 c5540) {
        this.f19359 = c5540;
    }

    @Override // defpackage.InterfaceC1220
    /* JADX INFO: renamed from: ˉᵲ */
    public final int mo2759(C2220 c2220) {
        return 2;
    }

    @Override // defpackage.InterfaceC4562
    /* JADX INFO: renamed from: ᵪᵹᵥᵻ */
    public final boolean mo2774(Object obj, File file, C2220 c2220) throws Throwable {
        boolean z;
        Bitmap bitmap = (Bitmap) ((InterfaceC1364) obj).get();
        C1305 c1305 = f19357;
        Bitmap.CompressFormat compressFormat = (Bitmap.CompressFormat) c2220.m5809(c1305);
        if (compressFormat == null) {
            compressFormat = bitmap.hasAlpha() ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG;
        }
        bitmap.getWidth();
        bitmap.getHeight();
        int i = AbstractC0925.f4045;
        SystemClock.elapsedRealtimeNanos();
        int iIntValue = ((Integer) c2220.m5809(f19358)).intValue();
        OutputStream c1476 = null;
        try {
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                C5540 c5540 = this.f19359;
                if (c5540 != null) {
                    try {
                        c1476 = new C1476(fileOutputStream, c5540);
                    } catch (IOException unused) {
                        c1476 = fileOutputStream;
                        Log.isLoggable("BitmapEncoder", 3);
                        if (c1476 != null) {
                            try {
                                c1476.close();
                            } catch (IOException unused2) {
                            }
                        }
                        z = false;
                    } catch (Throwable th) {
                        th = th;
                        c1476 = fileOutputStream;
                        if (c1476 != null) {
                            try {
                                c1476.close();
                            } catch (IOException unused3) {
                            }
                        }
                        throw th;
                    }
                } else {
                    c1476 = fileOutputStream;
                }
                bitmap.compress(compressFormat, iIntValue, c1476);
                c1476.close();
                try {
                    c1476.close();
                } catch (IOException unused4) {
                }
                z = true;
            } catch (IOException unused5) {
            }
            if (Log.isLoggable("BitmapEncoder", 2)) {
                Objects.toString(compressFormat);
                ᵱˉˈ.ˊᵨᵧ(bitmap);
                SystemClock.elapsedRealtimeNanos();
                Objects.toString(c2220.m5809(c1305));
                bitmap.hasAlpha();
            }
            return z;
        } catch (Throwable th2) {
            th = th2;
        }
    }
}
