package ᕣ.K.K;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import com.facebook.internal.WebDialog;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import top.zibin.luban.Checker;

/* renamed from: ᕣ.K.K.ῲ  reason: contains not printable characters */
/* compiled from: Engine */
public class C1462 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public int f5461;

    /* renamed from: ඓ  reason: contains not printable characters */
    public boolean f5462;

    /* renamed from: ῲ  reason: contains not printable characters */
    public File f5463;

    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1459 f5464;

    /* renamed from: 㸾  reason: contains not printable characters */
    public int f5465;

    public C1462(AbstractC1459 r1, File file, boolean z) throws IOException {
        this.f5463 = file;
        this.f5464 = r1;
        this.f5462 = z;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inSampleSize = 1;
        BitmapFactory.decodeStream(r1.m3669(), null, options);
        this.f5461 = options.outWidth;
        this.f5465 = options.outHeight;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:20:0x004f, code lost:
        if (r1 == 0) goto L_0x006e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0061, code lost:
        if (r1 == 0) goto L_0x006e;
     */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x008e  */
    /* JADX WARNING: Removed duplicated region for block: B:34:0x00b6  */
    /* JADX WARNING: Removed duplicated region for block: B:35:0x00b9  */
    /* renamed from: K  reason: contains not printable characters */
    public File m3672() throws IOException {
        int i;
        BitmapFactory.Options options = new BitmapFactory.Options();
        int i2 = this.f5461;
        int i3 = 1;
        if (i2 % 2 == 1) {
            i2++;
        }
        this.f5461 = i2;
        int i4 = this.f5465;
        if (i4 % 2 == 1) {
            i4++;
        }
        this.f5465 = i4;
        int max = Math.max(this.f5461, this.f5465);
        float min = ((float) Math.min(this.f5461, this.f5465)) / ((float) max);
        if (min > 1.0f || ((double) min) <= 0.5625d) {
            double d = (double) min;
            if (d > 0.5625d || d <= 0.5d) {
                i3 = (int) Math.ceil(((double) max) / (1280.0d / d));
                options.inSampleSize = i3;
                Bitmap decodeStream = BitmapFactory.decodeStream(this.f5464.m3669(), null, options);
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                if (Checker.SINGLE.isJPG(this.f5464.m3669())) {
                    int orientation = Checker.SINGLE.getOrientation(this.f5464.m3669());
                    Matrix matrix = new Matrix();
                    matrix.postRotate((float) orientation);
                    decodeStream = Bitmap.createBitmap(decodeStream, 0, 0, decodeStream.getWidth(), decodeStream.getHeight(), matrix, true);
                }
                decodeStream.compress(this.f5462 ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG, 60, byteArrayOutputStream);
                decodeStream.recycle();
                FileOutputStream fileOutputStream = new FileOutputStream(this.f5463);
                fileOutputStream.write(byteArrayOutputStream.toByteArray());
                fileOutputStream.flush();
                fileOutputStream.close();
                byteArrayOutputStream.close();
                return this.f5463;
            }
            i = max / WebDialog.MAX_PADDING_SCREEN_HEIGHT;
        } else {
            if (max >= 1664) {
                if (max < 4990) {
                    i3 = 2;
                } else if (max <= 4990 || max >= 10240) {
                    i = max / WebDialog.MAX_PADDING_SCREEN_HEIGHT;
                } else {
                    i3 = 4;
                }
            }
            options.inSampleSize = i3;
            Bitmap decodeStream2 = BitmapFactory.decodeStream(this.f5464.m3669(), null, options);
            ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
            if (Checker.SINGLE.isJPG(this.f5464.m3669())) {
            }
            decodeStream2.compress(this.f5462 ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG, 60, byteArrayOutputStream2);
            decodeStream2.recycle();
            FileOutputStream fileOutputStream2 = new FileOutputStream(this.f5463);
            fileOutputStream2.write(byteArrayOutputStream2.toByteArray());
            fileOutputStream2.flush();
            fileOutputStream2.close();
            byteArrayOutputStream2.close();
            return this.f5463;
        }
        i3 = i;
        options.inSampleSize = i3;
        Bitmap decodeStream22 = BitmapFactory.decodeStream(this.f5464.m3669(), null, options);
        ByteArrayOutputStream byteArrayOutputStream22 = new ByteArrayOutputStream();
        if (Checker.SINGLE.isJPG(this.f5464.m3669())) {
        }
        decodeStream22.compress(this.f5462 ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG, 60, byteArrayOutputStream22);
        decodeStream22.recycle();
        FileOutputStream fileOutputStream22 = new FileOutputStream(this.f5463);
        fileOutputStream22.write(byteArrayOutputStream22.toByteArray());
        fileOutputStream22.flush();
        fileOutputStream22.close();
        byteArrayOutputStream22.close();
        return this.f5463;
    }
}
