package ඓ.ῲ.K.ᕣ.ᕣ.ʬ;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ColorSpace;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.ImageHeaderParser;
import com.bumptech.glide.load.PreferredColorSpace;
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
import com.facebook.internal.NativeProtocol;
import com.google.android.material.bottomappbar.BottomAppBarTopEdgeTreatment;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import ඓ.ῲ.K.ᓣ.C0845;
import ඓ.ῲ.K.ᓣ.C0847;
import ඓ.ῲ.K.ᕣ.C0850;
import ඓ.ῲ.K.ᕣ.C1121;
import ඓ.ῲ.K.ᕣ.ᕣ.ʬ.AbstractC0870;
import ඓ.ῲ.K.ᕣ.ᨨ.AbstractC1027;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0967;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0976;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.C0964;
import ඓ.K.K.K.C1293;
import ῲ.ᨨ.㳳.C1841;

/* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ʬ.ᕣ  reason: contains not printable characters */
/* compiled from: Downsampler */
public final class C0873 {

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static final AbstractC0874 f4117 = new C0875();

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static final C0850<Boolean> f4118 = C0850.m2469("com.bumptech.glide.load.resource.bitmap.Downsampler.AllowHardwareDecode", false);

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final C0850<PreferredColorSpace> f4119 = C0850.m2469("com.bumptech.glide.load.resource.bitmap.Downsampler.PreferredColorSpace", PreferredColorSpace.SRGB);

    /* renamed from: 㑃  reason: contains not printable characters */
    public static final Set<ImageHeaderParser.ImageType> f4120 = Collections.unmodifiableSet(EnumSet.of(ImageHeaderParser.ImageType.JPEG, ImageHeaderParser.ImageType.PNG_A, ImageHeaderParser.ImageType.PNG));

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final Set<String> f4121 = Collections.unmodifiableSet(new HashSet(Arrays.asList("image/vnd.wap.wbmp", "image/x-ico")));

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final C0850<DecodeFormat> f4122 = C0850.m2469("com.bumptech.glide.load.resource.bitmap.Downsampler.DecodeFormat", DecodeFormat.DEFAULT);

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final C0850<Boolean> f4123 = C0850.m2469("com.bumptech.glide.load.resource.bitmap.Downsampler.FixBitmapSize", false);

    /* renamed from: 䁗  reason: contains not printable characters */
    public static final Queue<BitmapFactory.Options> f4124 = C0845.m2458(0);

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC0967 f4125;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C0857 f4126 = C0857.m2481();

    /* renamed from: ῲ  reason: contains not printable characters */
    public final DisplayMetrics f4127;

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC0976 f4128;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final List<ImageHeaderParser> f4129;

    /* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ʬ.ᕣ$ῲ  reason: contains not printable characters */
    /* compiled from: Downsampler */
    public interface AbstractC0874 {
        /* renamed from: K  reason: contains not printable characters */
        void m2537();

        /* renamed from: K  reason: contains not printable characters */
        void m2538(AbstractC0976 v, Bitmap bitmap) throws IOException;
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᕣ.ʬ.ᕣ$K  reason: contains not printable characters */
    /* compiled from: Downsampler */
    public class C0875 implements AbstractC0874 {
        @Override // ඓ.ῲ.K.ᕣ.ᕣ.ʬ.C0873.AbstractC0874
        /* renamed from: K  reason: contains not printable characters */
        public void m2539() {
        }

        @Override // ඓ.ῲ.K.ᕣ.ᕣ.ʬ.C0873.AbstractC0874
        /* renamed from: K  reason: contains not printable characters */
        public void m2540(AbstractC0976 r1, Bitmap bitmap) {
        }
    }

    static {
        C0850<DownsampleStrategy> r0 = DownsampleStrategy.f2248;
    }

    public C0873(List<ImageHeaderParser> list, DisplayMetrics displayMetrics, AbstractC0976 r4, AbstractC0967 r5) {
        this.f4129 = list;
        C1841.m4783(displayMetrics, "Argument must not be null");
        this.f4127 = displayMetrics;
        C1841.m4783(r4, "Argument must not be null");
        this.f4128 = r4;
        C1841.m4783(r5, "Argument must not be null");
        this.f4125 = r5;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static int m2521(double d) {
        return (int) (d + 0.5d);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static int[] m2523(AbstractC0870 r1, BitmapFactory.Options options, AbstractC0874 r3, AbstractC0976 r4) throws IOException {
        options.inJustDecodeBounds = true;
        m2525(r1, options, r3, r4);
        options.inJustDecodeBounds = false;
        return new int[]{options.outWidth, options.outHeight};
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m2529(int i) {
        return i == 90 || i == 270;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public static synchronized BitmapFactory.Options m2530() {
        BitmapFactory.Options poll;
        synchronized (C0873.class) {
            synchronized (f4124) {
                poll = f4124.poll();
            }
            if (poll == null) {
                poll = new BitmapFactory.Options();
                m2522(poll);
            }
        }
        return poll;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public boolean m2531() {
        int i = Build.VERSION.SDK_INT;
        return true;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public boolean m2532() {
        return true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1027<Bitmap> m2534(InputStream inputStream, int i, int i2, C1121 r10, AbstractC0874 r11) throws IOException {
        return m2535(new AbstractC0870.C0872(inputStream, this.f4129, this.f4125), i, i2, r10, r11);
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m2536() {
        return true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC1027<Bitmap> m2535(AbstractC0870 r16, int i, int i2, C1121 r19, AbstractC0874 r20) throws IOException {
        byte[] bArr = (byte[]) ((C0964) this.f4125).m2735(NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST, byte[].class);
        BitmapFactory.Options r14 = m2530();
        r14.inTempStorage = bArr;
        DecodeFormat decodeFormat = (DecodeFormat) r19.m3002(f4122);
        PreferredColorSpace preferredColorSpace = (PreferredColorSpace) r19.m3002(f4119);
        try {
            return C0859.m2488(m2533(r16, r14, (DownsampleStrategy) r19.m3002(DownsampleStrategy.f2248), decodeFormat, preferredColorSpace, r19.m3002(f4118) != null && ((Boolean) r19.m3002(f4118)).booleanValue(), i, i2, ((Boolean) r19.m3002(f4123)).booleanValue(), r20), this.f4128);
        } finally {
            m2528(r14);
            ((C0964) this.f4125).m2743(bArr);
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static void m2522(BitmapFactory.Options options) {
        options.inTempStorage = null;
        options.inDither = false;
        options.inScaled = false;
        options.inSampleSize = 1;
        options.inPreferredConfig = null;
        options.inJustDecodeBounds = false;
        options.inDensity = 0;
        options.inTargetDensity = 0;
        if (Build.VERSION.SDK_INT >= 26) {
            options.inPreferredColorSpace = null;
            options.outColorSpace = null;
            options.outConfig = null;
        }
        options.outWidth = 0;
        options.outHeight = 0;
        options.outMimeType = null;
        options.inBitmap = null;
        options.inMutable = true;
    }

    /* JADX WARNING: Removed duplicated region for block: B:103:0x02dd  */
    /* JADX WARNING: Removed duplicated region for block: B:105:0x02e6  */
    /* JADX WARNING: Removed duplicated region for block: B:106:0x02e8  */
    /* JADX WARNING: Removed duplicated region for block: B:125:0x0336 A[ADDED_TO_REGION] */
    /* JADX WARNING: Removed duplicated region for block: B:130:0x0341  */
    /* JADX WARNING: Removed duplicated region for block: B:136:0x034c  */
    /* JADX WARNING: Removed duplicated region for block: B:137:0x0354  */
    /* JADX WARNING: Removed duplicated region for block: B:140:0x037e  */
    /* JADX WARNING: Removed duplicated region for block: B:146:0x03d4  */
    /* JADX WARNING: Removed duplicated region for block: B:149:0x03de  */
    /* JADX WARNING: Removed duplicated region for block: B:151:0x03e1  */
    /* JADX WARNING: Removed duplicated region for block: B:155:0x03ef  */
    /* JADX WARNING: Removed duplicated region for block: B:167:0x0410  */
    /* JADX WARNING: Removed duplicated region for block: B:171:0x042e  */
    /* JADX WARNING: Removed duplicated region for block: B:173:0x04b2  */
    /* JADX WARNING: Removed duplicated region for block: B:192:0x054d A[ORIG_RETURN, RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x01c3  */
    /* JADX WARNING: Removed duplicated region for block: B:88:0x01c7  */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x01d5  */
    /* JADX WARNING: Removed duplicated region for block: B:92:0x0247  */
    /* renamed from: K  reason: contains not printable characters */
    public final Bitmap m2533(AbstractC0870 r31, BitmapFactory.Options options, DownsampleStrategy downsampleStrategy, DecodeFormat decodeFormat, PreferredColorSpace preferredColorSpace, boolean z, int i, int i2, boolean z2, AbstractC0874 r40) throws IOException {
        int i3;
        int i4;
        long j;
        boolean z3;
        int i5;
        int i6;
        String str;
        int i7;
        String str2;
        boolean r0;
        String str3;
        int i8;
        int i9;
        Bitmap r02;
        boolean z4;
        Bitmap bitmap;
        ColorSpace colorSpace;
        Bitmap.Config config;
        int i10;
        boolean z5;
        String str4;
        int i11;
        String str5;
        String str6;
        int i12;
        int i13;
        int i14;
        int i15;
        int i16;
        int i17;
        int i18;
        int i19;
        double d;
        int i20;
        int i21;
        long r8 = C0847.m2463();
        int[] r10 = m2523(r31, options, r40, this.f4128);
        int i22 = r10[0];
        int i23 = r10[1];
        String str7 = options.outMimeType;
        boolean z6 = (i22 == -1 || i23 == -1) ? false : z;
        int r14 = r31.m2509();
        switch (r14) {
            case 3:
            case 4:
                i3 = 180;
                break;
            case 5:
            case 6:
                i3 = 90;
                break;
            case 7:
            case 8:
                i3 = BottomAppBarTopEdgeTreatment.ANGLE_UP;
                break;
            default:
                i3 = 0;
                break;
        }
        switch (r14) {
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                j = r8;
                i4 = r14;
                z3 = true;
                break;
            default:
                j = r8;
                i4 = r14;
                z3 = false;
                break;
        }
        int i24 = i == Integer.MIN_VALUE ? m2529(i3) ? i23 : i22 : i;
        int i25 = i2 == Integer.MIN_VALUE ? m2529(i3) ? i22 : i23 : i2;
        ImageHeaderParser.ImageType r6 = r31.m2512();
        AbstractC0976 r5 = this.f4128;
        String str8 = ", target density: ";
        String str9 = "x";
        if (i22 <= 0) {
            str2 = "Downsampler";
            i7 = i24;
            i5 = i23;
            str4 = "]";
            i6 = i25;
            str = ", density: ";
            i11 = 3;
        } else if (i23 <= 0) {
            i11 = 3;
            str2 = "Downsampler";
            i7 = i24;
            i5 = i23;
            str4 = "]";
            i6 = i25;
            str = ", density: ";
        } else {
            if (m2529(i3)) {
                str6 = "]";
                str5 = ", density: ";
                i13 = i23;
                i12 = i22;
            } else {
                str6 = "]";
                str5 = ", density: ";
                i12 = i23;
                i13 = i22;
            }
            float r4 = downsampleStrategy.m1317(i13, i12, i24, i25);
            if (r4 > 0.0f) {
                DownsampleStrategy.SampleSizeRounding r15 = downsampleStrategy.m1318(i13, i12, i24, i25);
                if (r15 != null) {
                    float f = (float) i13;
                    float f2 = (float) i12;
                    int r03 = i13 / m2521((double) (r4 * f));
                    int r82 = i12 / m2521((double) (r4 * f2));
                    if (r15 == DownsampleStrategy.SampleSizeRounding.MEMORY) {
                        i14 = Math.max(r03, r82);
                    } else {
                        i14 = Math.min(r03, r82);
                    }
                    if (Build.VERSION.SDK_INT > 23 || !f4121.contains(options.outMimeType)) {
                        i15 = Math.max(1, Integer.highestOneBit(i14));
                        if (r15 == DownsampleStrategy.SampleSizeRounding.MEMORY && ((float) i15) < 1.0f / r4) {
                            i15 <<= 1;
                        }
                    } else {
                        i15 = 1;
                    }
                    options.inSampleSize = i15;
                    if (r6 == ImageHeaderParser.ImageType.JPEG) {
                        float min = (float) Math.min(i15, 8);
                        i20 = (int) Math.ceil((double) (f / min));
                        i21 = (int) Math.ceil((double) (f2 / min));
                        int i26 = i15 / 8;
                        if (i26 > 0) {
                            i20 /= i26;
                            i21 /= i26;
                        }
                    } else {
                        if (r6 == ImageHeaderParser.ImageType.PNG || r6 == ImageHeaderParser.ImageType.PNG_A) {
                            float f3 = (float) i15;
                            i20 = (int) Math.floor((double) (f / f3));
                            d = Math.floor((double) (f2 / f3));
                        } else if (r6 != ImageHeaderParser.ImageType.WEBP && r6 != ImageHeaderParser.ImageType.WEBP_A) {
                            if (i13 % i15 == 0 && i12 % i15 == 0) {
                                i17 = i13 / i15;
                                i16 = i12 / i15;
                            } else {
                                int[] r1 = m2523(r31, options, r40, r5);
                                i17 = r1[0];
                                i16 = r1[1];
                            }
                            i7 = i24;
                            i6 = i25;
                            double r83 = (double) downsampleStrategy.m1317(i17, i16, i7, i6);
                            int i27 = Build.VERSION.SDK_INT;
                            int r12 = m2524(r83);
                            int r62 = m2521(((double) r12) * r83);
                            options.inTargetDensity = m2521((r83 / ((double) (((float) r62) / ((float) r12)))) * ((double) r62));
                            options.inDensity = m2524(r83);
                            i18 = options.inTargetDensity;
                            if (!(i18 <= 0 && (i19 = options.inDensity) > 0 && i18 != i19)) {
                                options.inScaled = true;
                            } else {
                                options.inTargetDensity = 0;
                                options.inDensity = 0;
                            }
                            str2 = "Downsampler";
                            if (!Log.isLoggable(str2, 2)) {
                                StringBuilder sb = new StringBuilder();
                                sb.append("Calculate scaling, source: [");
                                sb.append(i22);
                                str9 = str9;
                                sb.append(str9);
                                i5 = i23;
                                sb.append(i5);
                                sb.append("], degreesToRotate: ");
                                sb.append(i3);
                                sb.append(", target: [");
                                sb.append(i7);
                                sb.append(str9);
                                sb.append(i6);
                                sb.append("], power of two scaled: [");
                                sb.append(i17);
                                sb.append(str9);
                                sb.append(i16);
                                sb.append("], exact scale factor: ");
                                sb.append(r4);
                                sb.append(", power of 2 sample size: ");
                                sb.append(i15);
                                sb.append(", adjusted scale factor: ");
                                sb.append(r83);
                                str8 = str8;
                                sb.append(str8);
                                sb.append(options.inTargetDensity);
                                str = str5;
                                sb.append(str);
                                sb.append(options.inDensity);
                                Log.v(str2, sb.toString());
                            } else {
                                str = str5;
                                str8 = str8;
                                i5 = i23;
                                str9 = str9;
                            }
                            r0 = this.f4126.m2483(i7, i6, z6, z3);
                            if (r0) {
                                options.inPreferredConfig = Bitmap.Config.HARDWARE;
                                options.inMutable = false;
                            }
                            if (r0) {
                                str3 = str8;
                            } else {
                                str3 = str8;
                                if (decodeFormat != DecodeFormat.PREFER_ARGB_8888) {
                                    int i28 = Build.VERSION.SDK_INT;
                                    try {
                                        z5 = r31.m2512().hasAlpha();
                                    } catch (IOException e) {
                                        if (Log.isLoggable(str2, 3)) {
                                            Log.d(str2, "Cannot determine whether the image has alpha or not from header, format " + decodeFormat, e);
                                        }
                                        z5 = false;
                                    }
                                    options.inPreferredConfig = z5 ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
                                    if (options.inPreferredConfig == Bitmap.Config.RGB_565) {
                                        options.inDither = true;
                                    }
                                } else {
                                    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                                }
                            }
                            int i29 = Build.VERSION.SDK_INT;
                            int i30 = options.inSampleSize;
                            int i31 = Build.VERSION.SDK_INT;
                            if (i22 >= 0 || i5 < 0 || !z2) {
                                int i32 = options.inTargetDensity;
                                float f4 = i32 <= 0 && (i10 = options.inDensity) > 0 && i32 != i10 ? ((float) options.inTargetDensity) / ((float) options.inDensity) : 1.0f;
                                int i33 = options.inSampleSize;
                                float f5 = (float) i33;
                                i7 = Math.round(((float) ((int) Math.ceil((double) (((float) i22) / f5)))) * f4);
                                i8 = Math.round(((float) ((int) Math.ceil((double) (((float) i5) / f5)))) * f4);
                                if (Log.isLoggable(str2, 2)) {
                                    Log.v(str2, "Calculated target [" + i7 + str9 + i8 + "] for source [" + i22 + str9 + i5 + "], sampleSize: " + i33 + ", targetDensity: " + options.inTargetDensity + str + options.inDensity + ", density multiplier: " + f4);
                                }
                            } else {
                                i8 = i6;
                            }
                            if (i7 > 0 && i8 > 0) {
                                AbstractC0976 r42 = this.f4128;
                                if (Build.VERSION.SDK_INT < 26) {
                                    config = null;
                                } else if (options.inPreferredConfig != Bitmap.Config.HARDWARE) {
                                    config = options.outConfig;
                                }
                                if (config == null) {
                                    config = options.inPreferredConfig;
                                }
                                options.inBitmap = r42.m2768(i7, i8, config);
                            }
                            i9 = Build.VERSION.SDK_INT;
                            if (i9 >= 28) {
                                options.inPreferredColorSpace = ColorSpace.get(preferredColorSpace == PreferredColorSpace.DISPLAY_P3 && (colorSpace = options.outColorSpace) != null && colorSpace.isWideGamut() ? ColorSpace.Named.DISPLAY_P3 : ColorSpace.Named.SRGB);
                            } else if (i9 >= 26) {
                                options.inPreferredColorSpace = ColorSpace.get(ColorSpace.Named.SRGB);
                            }
                            r02 = m2525(r31, options, r40, this.f4128);
                            r40.m2538(this.f4128, r02);
                            if (Log.isLoggable(str2, 2)) {
                                StringBuilder r43 = C1293.m3416("Decoded ");
                                r43.append(m2527(r02));
                                r43.append(" from [");
                                r43.append(i22);
                                r43.append(str9);
                                r43.append(i5);
                                r43.append("] ");
                                r43.append(str7);
                                r43.append(" with inBitmap ");
                                r43.append(m2527(options.inBitmap));
                                r43.append(" for [");
                                r43.append(i);
                                r43.append(str9);
                                r43.append(i2);
                                r43.append("], sample size: ");
                                r43.append(options.inSampleSize);
                                r43.append(str);
                                r43.append(options.inDensity);
                                r43.append(str3);
                                r43.append(options.inTargetDensity);
                                r43.append(", thread: ");
                                r43.append(Thread.currentThread().getName());
                                r43.append(", duration: ");
                                r43.append(C0847.m2462(j));
                                Log.v(str2, r43.toString());
                            }
                            if (r02 == null) {
                                return null;
                            }
                            r02.setDensity(this.f4127.densityDpi);
                            AbstractC0976 r2 = this.f4128;
                            switch (i4) {
                                case 2:
                                case 3:
                                case 4:
                                case 5:
                                case 6:
                                case 7:
                                case 8:
                                    z4 = true;
                                    break;
                                default:
                                    z4 = false;
                                    break;
                            }
                            if (!z4) {
                                bitmap = r02;
                            } else {
                                Matrix matrix = new Matrix();
                                switch (i4) {
                                    case 2:
                                        matrix.setScale(-1.0f, 1.0f);
                                        break;
                                    case 3:
                                        matrix.setRotate(180.0f);
                                        break;
                                    case 4:
                                        matrix.setRotate(180.0f);
                                        matrix.postScale(-1.0f, 1.0f);
                                        break;
                                    case 5:
                                        matrix.setRotate(90.0f);
                                        matrix.postScale(-1.0f, 1.0f);
                                        break;
                                    case 6:
                                        matrix.setRotate(90.0f);
                                        break;
                                    case 7:
                                        matrix.setRotate(-90.0f);
                                        matrix.postScale(-1.0f, 1.0f);
                                        break;
                                    case 8:
                                        matrix.setRotate(-90.0f);
                                        break;
                                }
                                RectF rectF = new RectF(0.0f, 0.0f, (float) r02.getWidth(), (float) r02.getHeight());
                                matrix.mapRect(rectF);
                                bitmap = r2.m2769(Math.round(rectF.width()), Math.round(rectF.height()), C0868.m2506(r02));
                                matrix.postTranslate(-rectF.left, -rectF.top);
                                bitmap.setHasAlpha(r02.hasAlpha());
                                C0868.m2508(r02, bitmap, matrix);
                            }
                            if (r02.equals(bitmap)) {
                                return bitmap;
                            }
                            this.f4128.m2772(r02);
                            return bitmap;
                        } else if (Build.VERSION.SDK_INT >= 24) {
                            float f6 = (float) i15;
                            i20 = Math.round(f / f6);
                            i21 = Math.round(f2 / f6);
                        } else {
                            float f7 = (float) i15;
                            i20 = (int) Math.floor((double) (f / f7));
                            d = Math.floor((double) (f2 / f7));
                        }
                        i21 = (int) d;
                    }
                    i16 = i21;
                    i17 = i20;
                    i7 = i24;
                    i6 = i25;
                    double r832 = (double) downsampleStrategy.m1317(i17, i16, i7, i6);
                    int i272 = Build.VERSION.SDK_INT;
                    int r122 = m2524(r832);
                    int r622 = m2521(((double) r122) * r832);
                    options.inTargetDensity = m2521((r832 / ((double) (((float) r622) / ((float) r122)))) * ((double) r622));
                    options.inDensity = m2524(r832);
                    i18 = options.inTargetDensity;
                    if (!(i18 <= 0 && (i19 = options.inDensity) > 0 && i18 != i19)) {
                    }
                    str2 = "Downsampler";
                    if (!Log.isLoggable(str2, 2)) {
                    }
                    r0 = this.f4126.m2483(i7, i6, z6, z3);
                    if (r0) {
                    }
                    if (r0) {
                    }
                    int i292 = Build.VERSION.SDK_INT;
                    int i302 = options.inSampleSize;
                    int i312 = Build.VERSION.SDK_INT;
                    if (i22 >= 0) {
                    }
                    int i322 = options.inTargetDensity;
                    if (i322 <= 0 && (i10 = options.inDensity) > 0 && i322 != i10) {
                    }
                    int i332 = options.inSampleSize;
                    float f52 = (float) i332;
                    i7 = Math.round(((float) ((int) Math.ceil((double) (((float) i22) / f52)))) * f4);
                    i8 = Math.round(((float) ((int) Math.ceil((double) (((float) i5) / f52)))) * f4);
                    if (Log.isLoggable(str2, 2)) {
                    }
                    AbstractC0976 r422 = this.f4128;
                    if (Build.VERSION.SDK_INT < 26) {
                    }
                    if (config == null) {
                    }
                    options.inBitmap = r422.m2768(i7, i8, config);
                    i9 = Build.VERSION.SDK_INT;
                    if (i9 >= 28) {
                    }
                    r02 = m2525(r31, options, r40, this.f4128);
                    r40.m2538(this.f4128, r02);
                    if (Log.isLoggable(str2, 2)) {
                    }
                    if (r02 == null) {
                    }
                } else {
                    throw new IllegalArgumentException("Cannot round with null rounding");
                }
            } else {
                throw new IllegalArgumentException("Cannot scale with factor: " + r4 + " from: " + downsampleStrategy + ", source: [" + i22 + str9 + i23 + "], target: [" + i24 + str9 + i25 + str6);
            }
        }
        if (Log.isLoggable(str2, i11)) {
            Log.d(str2, "Unable to determine dimensions for: " + r6 + " with target [" + i7 + str9 + i6 + str4);
        }
        r0 = this.f4126.m2483(i7, i6, z6, z3);
        if (r0) {
        }
        if (r0) {
        }
        int i2922 = Build.VERSION.SDK_INT;
        int i3022 = options.inSampleSize;
        int i3122 = Build.VERSION.SDK_INT;
        if (i22 >= 0) {
        }
        int i3222 = options.inTargetDensity;
        if (i3222 <= 0 && (i10 = options.inDensity) > 0 && i3222 != i10) {
        }
        int i3322 = options.inSampleSize;
        float f522 = (float) i3322;
        i7 = Math.round(((float) ((int) Math.ceil((double) (((float) i22) / f522)))) * f4);
        i8 = Math.round(((float) ((int) Math.ceil((double) (((float) i5) / f522)))) * f4);
        if (Log.isLoggable(str2, 2)) {
        }
        AbstractC0976 r4222 = this.f4128;
        if (Build.VERSION.SDK_INT < 26) {
        }
        if (config == null) {
        }
        options.inBitmap = r4222.m2768(i7, i8, config);
        i9 = Build.VERSION.SDK_INT;
        if (i9 >= 28) {
        }
        r02 = m2525(r31, options, r40, this.f4128);
        r40.m2538(this.f4128, r02);
        if (Log.isLoggable(str2, 2)) {
        }
        if (r02 == null) {
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m2524(double d) {
        if (d > 1.0d) {
            d = 1.0d / d;
        }
        return (int) Math.round(d * 2.147483647E9d);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static Bitmap m2525(AbstractC0870 r5, BitmapFactory.Options options, AbstractC0874 r7, AbstractC0976 r8) throws IOException {
        if (!options.inJustDecodeBounds) {
            r7.m2537();
            r5.m2510();
        }
        int i = options.outWidth;
        int i2 = options.outHeight;
        String str = options.outMimeType;
        C0868.f4110.lock();
        try {
            return r5.m2511(options);
        } catch (IllegalArgumentException e) {
            IOException r1 = m2526(e, i, i2, str, options);
            if (Log.isLoggable("Downsampler", 3)) {
                Log.d("Downsampler", "Failed to decode with inBitmap, trying again without Bitmap re-use", r1);
            }
            Bitmap bitmap = options.inBitmap;
            if (bitmap != null) {
                try {
                    r8.m2772(bitmap);
                    options.inBitmap = null;
                    return m2525(r5, options, r7, r8);
                } catch (IOException unused) {
                    throw r1;
                }
            } else {
                throw r1;
            }
        } finally {
            C0868.f4110.unlock();
        }
    }

    @TargetApi(19)
    /* renamed from: K  reason: contains not printable characters */
    public static String m2527(Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        }
        int i = Build.VERSION.SDK_INT;
        StringBuilder r0 = C1293.m3416(" (");
        r0.append(bitmap.getAllocationByteCount());
        r0.append(")");
        String sb = r0.toString();
        StringBuilder r1 = C1293.m3416("[");
        r1.append(bitmap.getWidth());
        r1.append("x");
        r1.append(bitmap.getHeight());
        r1.append("] ");
        r1.append(bitmap.getConfig());
        r1.append(sb);
        return r1.toString();
    }

    /* renamed from: K  reason: contains not printable characters */
    public static IOException m2526(IllegalArgumentException illegalArgumentException, int i, int i2, String str, BitmapFactory.Options options) {
        return new IOException("Exception decoding bitmap, outWidth: " + i + ", outHeight: " + i2 + ", outMimeType: " + str + ", inBitmap: " + m2527(options.inBitmap), illegalArgumentException);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m2528(BitmapFactory.Options options) {
        m2522(options);
        synchronized (f4124) {
            f4124.offer(options);
        }
    }
}
