package z1; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.ColorSpace; import android.os.Build; import android.os.ParcelFileDescriptor; import android.util.DisplayMetrics; import android.util.Log; import com.bumptech.glide.load.ImageHeaderParser; import com.bumptech.glide.load.data.ParcelFileDescriptorRewinder; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; 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 z1.n; import z1.z; /* loaded from: classes.dex */ public final class t { /* renamed from: f, reason: collision with root package name */ public static final q1.g f15774f = q1.g.f("com.bumptech.glide.load.resource.bitmap.Downsampler.DecodeFormat", q1.b.f13352c); /* renamed from: g, reason: collision with root package name */ public static final q1.g f15775g = q1.g.f("com.bumptech.glide.load.resource.bitmap.Downsampler.PreferredColorSpace", q1.i.SRGB); /* renamed from: h, reason: collision with root package name */ public static final q1.g f15776h = n.f15769h; /* renamed from: i, reason: collision with root package name */ public static final q1.g f15777i; /* renamed from: j, reason: collision with root package name */ public static final q1.g f15778j; /* renamed from: k, reason: collision with root package name */ private static final Set f15779k; /* renamed from: l, reason: collision with root package name */ private static final b f15780l; /* renamed from: m, reason: collision with root package name */ private static final Set f15781m; /* renamed from: n, reason: collision with root package name */ private static final Queue f15782n; /* renamed from: a, reason: collision with root package name */ private final t1.d f15783a; /* renamed from: b, reason: collision with root package name */ private final DisplayMetrics f15784b; /* renamed from: c, reason: collision with root package name */ private final t1.b f15785c; /* renamed from: d, reason: collision with root package name */ private final List f15786d; /* renamed from: e, reason: collision with root package name */ private final y f15787e = y.b(); class a implements b { a() { } @Override // z1.t.b public void a() { } @Override // z1.t.b public void b(t1.d dVar, Bitmap bitmap) { } } public interface b { void a(); void b(t1.d dVar, Bitmap bitmap); } static { Boolean bool = Boolean.FALSE; f15777i = q1.g.f("com.bumptech.glide.load.resource.bitmap.Downsampler.FixBitmapSize", bool); f15778j = q1.g.f("com.bumptech.glide.load.resource.bitmap.Downsampler.AllowHardwareDecode", bool); f15779k = Collections.unmodifiableSet(new HashSet(Arrays.asList("image/vnd.wap.wbmp", "image/x-ico"))); f15780l = new a(); f15781m = Collections.unmodifiableSet(EnumSet.of(ImageHeaderParser.ImageType.JPEG, ImageHeaderParser.ImageType.PNG_A, ImageHeaderParser.ImageType.PNG)); f15782n = m2.k.e(0); } public t(List list, DisplayMetrics displayMetrics, t1.d dVar, t1.b bVar) { this.f15786d = list; this.f15784b = (DisplayMetrics) m2.j.d(displayMetrics); this.f15783a = (t1.d) m2.j.d(dVar); this.f15785c = (t1.b) m2.j.d(bVar); } private static int a(double d10) { return x((d10 / (r1 / r0)) * x(l(d10) * d10)); } private void b(z zVar, q1.b bVar, boolean z10, boolean z11, BitmapFactory.Options options, int i10, int i11) { boolean z12; if (this.f15787e.i(i10, i11, options, z10, z11)) { return; } if (bVar == q1.b.PREFER_ARGB_8888) { options.inPreferredConfig = Bitmap.Config.ARGB_8888; return; } try { z12 = zVar.d().hasAlpha(); } catch (IOException e10) { if (Log.isLoggable("Downsampler", 3)) { Log.d("Downsampler", "Cannot determine whether the image has alpha or not from header, format " + bVar, e10); } z12 = false; } Bitmap.Config config = z12 ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; options.inPreferredConfig = config; if (config == Bitmap.Config.RGB_565) { options.inDither = true; } } private static void c(ImageHeaderParser.ImageType imageType, z zVar, b bVar, t1.d dVar, n nVar, int i10, int i11, int i12, int i13, int i14, BitmapFactory.Options options) { int i15; int i16; int i17; int floor; double floor2; int i18; if (i11 <= 0 || i12 <= 0) { if (Log.isLoggable("Downsampler", 3)) { Log.d("Downsampler", "Unable to determine dimensions for: " + imageType + " with target [" + i13 + "x" + i14 + "]"); return; } return; } if (r(i10)) { i16 = i11; i15 = i12; } else { i15 = i11; i16 = i12; } float b10 = nVar.b(i15, i16, i13, i14); if (b10 <= 0.0f) { throw new IllegalArgumentException("Cannot scale with factor: " + b10 + " from: " + nVar + ", source: [" + i11 + "x" + i12 + "], target: [" + i13 + "x" + i14 + "]"); } n.g a10 = nVar.a(i15, i16, i13, i14); if (a10 == null) { throw new IllegalArgumentException("Cannot round with null rounding"); } float f10 = i15; float f11 = i16; int x10 = i15 / x(b10 * f10); int x11 = i16 / x(b10 * f11); n.g gVar = n.g.MEMORY; int max = a10 == gVar ? Math.max(x10, x11) : Math.min(x10, x11); int i19 = Build.VERSION.SDK_INT; if (i19 > 23 || !f15779k.contains(options.outMimeType)) { int max2 = Math.max(1, Integer.highestOneBit(max)); if (a10 == gVar && max2 < 1.0f / b10) { max2 <<= 1; } i17 = max2; } else { i17 = 1; } options.inSampleSize = i17; if (imageType == ImageHeaderParser.ImageType.JPEG) { float min = Math.min(i17, 8); floor = (int) Math.ceil(f10 / min); i18 = (int) Math.ceil(f11 / min); int i20 = i17 / 8; if (i20 > 0) { floor /= i20; i18 /= i20; } } else { if (imageType == ImageHeaderParser.ImageType.PNG || imageType == ImageHeaderParser.ImageType.PNG_A) { float f12 = i17; floor = (int) Math.floor(f10 / f12); floor2 = Math.floor(f11 / f12); } else if (imageType == ImageHeaderParser.ImageType.WEBP || imageType == ImageHeaderParser.ImageType.WEBP_A) { if (i19 >= 24) { float f13 = i17; floor = Math.round(f10 / f13); i18 = Math.round(f11 / f13); } else { float f14 = i17; floor = (int) Math.floor(f10 / f14); floor2 = Math.floor(f11 / f14); } } else if (i15 % i17 == 0 && i16 % i17 == 0) { floor = i15 / i17; i18 = i16 / i17; } else { int[] m10 = m(zVar, options, bVar, dVar); floor = m10[0]; i18 = m10[1]; } i18 = (int) floor2; } double b11 = nVar.b(floor, i18, i13, i14); options.inTargetDensity = a(b11); options.inDensity = l(b11); if (s(options)) { options.inScaled = true; } else { options.inTargetDensity = 0; options.inDensity = 0; } if (Log.isLoggable("Downsampler", 2)) { Log.v("Downsampler", "Calculate scaling, source: [" + i11 + "x" + i12 + "], degreesToRotate: " + i10 + ", target: [" + i13 + "x" + i14 + "], power of two scaled: [" + floor + "x" + i18 + "], exact scale factor: " + b10 + ", power of 2 sample size: " + i17 + ", adjusted scale factor: " + b11 + ", target density: " + options.inTargetDensity + ", density: " + options.inDensity); } } private s1.v g(z zVar, int i10, int i11, q1.h hVar, b bVar) { byte[] bArr = (byte[]) this.f15785c.e(65536, byte[].class); BitmapFactory.Options k10 = k(); k10.inTempStorage = bArr; q1.b bVar2 = (q1.b) hVar.c(f15774f); q1.i iVar = (q1.i) hVar.c(f15775g); n nVar = (n) hVar.c(n.f15769h); boolean booleanValue = ((Boolean) hVar.c(f15777i)).booleanValue(); q1.g gVar = f15778j; try { return f.e(h(zVar, k10, nVar, bVar2, iVar, hVar.c(gVar) != null && ((Boolean) hVar.c(gVar)).booleanValue(), i10, i11, booleanValue, bVar), this.f15783a); } finally { v(k10); this.f15785c.d(bArr); } } private Bitmap h(z zVar, BitmapFactory.Options options, n nVar, q1.b bVar, q1.i iVar, boolean z10, int i10, int i11, boolean z11, b bVar2) { int i12; int i13; String str; ColorSpace.Named named; ColorSpace colorSpace; int i14; ColorSpace colorSpace2; ColorSpace colorSpace3; ColorSpace colorSpace4; boolean isWideGamut; int round; int round2; long b10 = m2.f.b(); int[] m10 = m(zVar, options, bVar2, this.f15783a); boolean z12 = false; int i15 = m10[0]; int i16 = m10[1]; String str2 = options.outMimeType; boolean z13 = (i15 == -1 || i16 == -1) ? false : z10; int a10 = zVar.a(); int g10 = g0.g(a10); boolean j10 = g0.j(a10); if (i10 == Integer.MIN_VALUE) { i12 = i11; i13 = r(g10) ? i16 : i15; } else { i12 = i11; i13 = i10; } int i17 = i12 == Integer.MIN_VALUE ? r(g10) ? i15 : i16 : i12; ImageHeaderParser.ImageType d10 = zVar.d(); c(d10, zVar, bVar2, this.f15783a, nVar, g10, i15, i16, i13, i17, options); b(zVar, bVar, z13, j10, options, i13, i17); int i18 = Build.VERSION.SDK_INT; int i19 = options.inSampleSize; if (z(d10)) { if (i15 < 0 || i16 < 0 || !z11) { float f10 = s(options) ? options.inTargetDensity / options.inDensity : 1.0f; int i20 = options.inSampleSize; float f11 = i20; int ceil = (int) Math.ceil(i15 / f11); int ceil2 = (int) Math.ceil(i16 / f11); round = Math.round(ceil * f10); round2 = Math.round(ceil2 * f10); str = "Downsampler"; if (Log.isLoggable(str, 2)) { Log.v(str, "Calculated target [" + round + "x" + round2 + "] for source [" + i15 + "x" + i16 + "], sampleSize: " + i20 + ", targetDensity: " + options.inTargetDensity + ", density: " + options.inDensity + ", density multiplier: " + f10); } } else { str = "Downsampler"; round = i13; round2 = i17; } if (round > 0 && round2 > 0) { y(options, this.f15783a, round, round2); } } else { str = "Downsampler"; } if (i18 >= 28) { if (iVar == q1.i.DISPLAY_P3) { colorSpace3 = options.outColorSpace; if (colorSpace3 != null) { colorSpace4 = options.outColorSpace; isWideGamut = colorSpace4.isWideGamut(); if (isWideGamut) { z12 = true; } } } colorSpace2 = ColorSpace.get(z12 ? ColorSpace.Named.DISPLAY_P3 : ColorSpace.Named.SRGB); options.inPreferredColorSpace = colorSpace2; } else if (i18 >= 26) { named = ColorSpace.Named.SRGB; colorSpace = ColorSpace.get(named); options.inPreferredColorSpace = colorSpace; } Bitmap i21 = i(zVar, options, bVar2, this.f15783a); bVar2.b(this.f15783a, i21); if (Log.isLoggable(str, 2)) { i14 = a10; t(i15, i16, str2, options, i21, i10, i11, b10); } else { i14 = a10; } if (i21 == null) { return null; } i21.setDensity(this.f15784b.densityDpi); Bitmap k10 = g0.k(this.f15783a, i21, i14); if (i21.equals(k10)) { return k10; } this.f15783a.c(i21); return k10; } /* JADX WARN: Code restructure failed: missing block: B:26:?, code lost: throw r1; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private static android.graphics.Bitmap i(z1.z r5, android.graphics.BitmapFactory.Options r6, z1.t.b r7, t1.d r8) { /* java.lang.String r0 = "Downsampler" boolean r1 = r6.inJustDecodeBounds if (r1 != 0) goto Lc r7.a() r5.c() Lc: int r1 = r6.outWidth int r2 = r6.outHeight java.lang.String r3 = r6.outMimeType java.util.concurrent.locks.Lock r4 = z1.g0.f() r4.lock() android.graphics.Bitmap r5 = r5.b(r6) // Catch: java.lang.Throwable -> L25 java.lang.IllegalArgumentException -> L27 java.util.concurrent.locks.Lock r6 = z1.g0.f() r6.unlock() return r5 L25: r5 = move-exception goto L50 L27: r4 = move-exception java.io.IOException r1 = u(r4, r1, r2, r3, r6) // Catch: java.lang.Throwable -> L25 r2 = 3 boolean r2 = android.util.Log.isLoggable(r0, r2) // Catch: java.lang.Throwable -> L25 if (r2 == 0) goto L38 java.lang.String r2 = "Failed to decode with inBitmap, trying again without Bitmap re-use" android.util.Log.d(r0, r2, r1) // Catch: java.lang.Throwable -> L25 L38: android.graphics.Bitmap r0 = r6.inBitmap // Catch: java.lang.Throwable -> L25 if (r0 == 0) goto L4f r8.c(r0) // Catch: java.lang.Throwable -> L25 java.io.IOException -> L4e r0 = 0 r6.inBitmap = r0 // Catch: java.lang.Throwable -> L25 java.io.IOException -> L4e android.graphics.Bitmap r5 = i(r5, r6, r7, r8) // Catch: java.lang.Throwable -> L25 java.io.IOException -> L4e java.util.concurrent.locks.Lock r6 = z1.g0.f() r6.unlock() return r5 L4e: throw r1 // Catch: java.lang.Throwable -> L25 L4f: throw r1 // Catch: java.lang.Throwable -> L25 L50: java.util.concurrent.locks.Lock r6 = z1.g0.f() r6.unlock() throw r5 */ throw new UnsupportedOperationException("Method not decompiled: z1.t.i(z1.z, android.graphics.BitmapFactory$Options, z1.t$b, t1.d):android.graphics.Bitmap"); } private static String j(Bitmap bitmap) { if (bitmap == null) { return null; } return "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig() + (" (" + bitmap.getAllocationByteCount() + ")"); } private static synchronized BitmapFactory.Options k() { BitmapFactory.Options options; synchronized (t.class) { Queue queue = f15782n; synchronized (queue) { options = (BitmapFactory.Options) queue.poll(); } if (options == null) { options = new BitmapFactory.Options(); w(options); } } return options; } private static int l(double d10) { if (d10 > 1.0d) { d10 = 1.0d / d10; } return (int) Math.round(d10 * 2.147483647E9d); } private static int[] m(z zVar, BitmapFactory.Options options, b bVar, t1.d dVar) { options.inJustDecodeBounds = true; i(zVar, options, bVar, dVar); options.inJustDecodeBounds = false; return new int[]{options.outWidth, options.outHeight}; } private static String n(BitmapFactory.Options options) { return j(options.inBitmap); } private static boolean r(int i10) { return i10 == 90 || i10 == 270; } private static boolean s(BitmapFactory.Options options) { int i10; int i11 = options.inTargetDensity; return i11 > 0 && (i10 = options.inDensity) > 0 && i11 != i10; } private static void t(int i10, int i11, String str, BitmapFactory.Options options, Bitmap bitmap, int i12, int i13, long j10) { Log.v("Downsampler", "Decoded " + j(bitmap) + " from [" + i10 + "x" + i11 + "] " + str + " with inBitmap " + n(options) + " for [" + i12 + "x" + i13 + "], sample size: " + options.inSampleSize + ", density: " + options.inDensity + ", target density: " + options.inTargetDensity + ", thread: " + Thread.currentThread().getName() + ", duration: " + m2.f.a(j10)); } private static IOException u(IllegalArgumentException illegalArgumentException, int i10, int i11, String str, BitmapFactory.Options options) { return new IOException("Exception decoding bitmap, outWidth: " + i10 + ", outHeight: " + i11 + ", outMimeType: " + str + ", inBitmap: " + n(options), illegalArgumentException); } private static void v(BitmapFactory.Options options) { w(options); Queue queue = f15782n; synchronized (queue) { queue.offer(options); } } private static void w(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; } private static int x(double d10) { return (int) (d10 + 0.5d); } private static void y(BitmapFactory.Options options, t1.d dVar, int i10, int i11) { Bitmap.Config config; Bitmap.Config config2; if (Build.VERSION.SDK_INT >= 26) { Bitmap.Config config3 = options.inPreferredConfig; config2 = Bitmap.Config.HARDWARE; if (config3 == config2) { return; } else { config = options.outConfig; } } else { config = null; } if (config == null) { config = options.inPreferredConfig; } options.inBitmap = dVar.e(i10, i11, config); } private boolean z(ImageHeaderParser.ImageType imageType) { return true; } public s1.v d(ParcelFileDescriptor parcelFileDescriptor, int i10, int i11, q1.h hVar) { return g(new z.b(parcelFileDescriptor, this.f15786d, this.f15785c), i10, i11, hVar, f15780l); } public s1.v e(InputStream inputStream, int i10, int i11, q1.h hVar) { return f(inputStream, i10, i11, hVar, f15780l); } public s1.v f(InputStream inputStream, int i10, int i11, q1.h hVar, b bVar) { return g(new z.a(inputStream, this.f15786d, this.f15785c), i10, i11, hVar, bVar); } public boolean o(ParcelFileDescriptor parcelFileDescriptor) { return ParcelFileDescriptorRewinder.c(); } public boolean p(InputStream inputStream) { return true; } public boolean q(ByteBuffer byteBuffer) { return true; } }