package o6; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Build; import android.os.ParcelFileDescriptor; import android.util.DisplayMetrics; import android.util.Log; import e6.f; 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 o6.l; import o6.r; /* loaded from: classes2.dex */ public final class m { /* renamed from: f, reason: collision with root package name */ public static final e6.i f12751f = e6.i.f("com.imgmodule.load.resource.bitmap.Downsampler.DecodeFormat", e6.b.f9336c); /* renamed from: g, reason: collision with root package name */ public static final e6.i f12752g = e6.i.f("com.imgmodule.load.resource.bitmap.Downsampler.PreferredColorSpace", e6.k.SRGB); /* renamed from: h, reason: collision with root package name */ public static final e6.i f12753h = l.f12746h; /* renamed from: i, reason: collision with root package name */ public static final e6.i f12754i; /* renamed from: j, reason: collision with root package name */ public static final e6.i f12755j; /* renamed from: k, reason: collision with root package name */ private static final Set f12756k; /* renamed from: l, reason: collision with root package name */ private static final a f12757l; /* renamed from: m, reason: collision with root package name */ private static final Set f12758m; /* renamed from: n, reason: collision with root package name */ private static final Queue f12759n; /* renamed from: a, reason: collision with root package name */ private final i6.b f12760a; /* renamed from: b, reason: collision with root package name */ private final DisplayMetrics f12761b; /* renamed from: c, reason: collision with root package name */ private final i6.a f12762c; /* renamed from: d, reason: collision with root package name */ private final List f12763d; /* renamed from: e, reason: collision with root package name */ private final q f12764e = q.h(); public interface a { void a(); void b(i6.b bVar, Bitmap bitmap); } class b implements a { b() { } @Override // o6.m.a public void a() { } @Override // o6.m.a public void b(i6.b bVar, Bitmap bitmap) { } } static { Boolean bool = Boolean.FALSE; f12754i = e6.i.f("com.imgmodule.load.resource.bitmap.Downsampler.FixBitmapSize", bool); f12755j = e6.i.f("com.imgmodule.load.resource.bitmap.Downsampler.AllowHardwareDecode", bool); f12756k = Collections.unmodifiableSet(new HashSet(Arrays.asList("image/vnd.wap.wbmp", "image/x-ico"))); f12757l = new b(); f12758m = Collections.unmodifiableSet(EnumSet.of(f.a.JPEG, f.a.PNG_A, f.a.PNG)); f12759n = b7.k.h(0); } public m(List list, DisplayMetrics displayMetrics, i6.b bVar, i6.a aVar) { this.f12763d = list; this.f12761b = (DisplayMetrics) b7.j.d(displayMetrics); this.f12760a = (i6.b) b7.j.d(bVar); this.f12762c = (i6.a) b7.j.d(aVar); } private static int a(double d10) { return r((d10 / (r1 / r0)) * r(o(d10) * d10)); } /* JADX WARN: Code restructure failed: missing block: B:27:0x014d, code lost: r0 = r30.outColorSpace; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private android.graphics.Bitmap b(o6.r r29, android.graphics.BitmapFactory.Options r30, o6.l r31, e6.b r32, e6.k r33, boolean r34, int r35, int r36, boolean r37, o6.m.a r38) { /* Method dump skipped, instructions count: 446 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: o6.m.b(o6.r, android.graphics.BitmapFactory$Options, o6.l, e6.b, e6.k, boolean, int, int, boolean, o6.m$a):android.graphics.Bitmap"); } private static Bitmap c(r rVar, BitmapFactory.Options options, a aVar, i6.b bVar) { Bitmap c10; if (!options.inJustDecodeBounds) { aVar.a(); rVar.c(); } int i10 = options.outWidth; int i11 = options.outHeight; String str = options.outMimeType; y.h().lock(); try { try { c10 = rVar.b(options); } catch (IllegalArgumentException e10) { IOException f10 = f(e10, i10, i11, str, options); if (Log.isLoggable("Downsampler", 3)) { Log.d("Downsampler", "Failed to decode with inBitmap, trying again without Bitmap re-use", f10); } Bitmap bitmap = options.inBitmap; if (bitmap == null) { throw f10; } try { bVar.c(bitmap); options.inBitmap = null; c10 = c(rVar, options, aVar, bVar); } catch (IOException unused) { throw f10; } } return c10; } finally { y.h().unlock(); } } private static synchronized BitmapFactory.Options d() { BitmapFactory.Options options; synchronized (m.class) { Queue queue = f12759n; synchronized (queue) { options = (BitmapFactory.Options) queue.poll(); } if (options == null) { options = new BitmapFactory.Options(); t(options); } } return options; } private h6.h e(r rVar, int i10, int i11, e6.j jVar, a aVar) { byte[] bArr = (byte[]) this.f12762c.e(65536, byte[].class); BitmapFactory.Options d10 = d(); d10.inTempStorage = bArr; e6.b bVar = (e6.b) jVar.d(f12751f); e6.k kVar = (e6.k) jVar.d(f12752g); l lVar = (l) jVar.d(l.f12746h); boolean booleanValue = ((Boolean) jVar.d(f12754i)).booleanValue(); e6.i iVar = f12755j; try { return e.e(b(rVar, d10, lVar, bVar, kVar, jVar.d(iVar) != null && ((Boolean) jVar.d(iVar)).booleanValue(), i10, i11, booleanValue, aVar), this.f12760a); } finally { s(d10); this.f12762c.d(bArr); } } private static IOException f(IllegalArgumentException illegalArgumentException, int i10, int i11, String str, BitmapFactory.Options options) { return new IOException("Exception decoding bitmap, outWidth: " + i10 + ", outHeight: " + i11 + ", outMimeType: " + str + ", inBitmap: " + h(options), illegalArgumentException); } private static String g(Bitmap bitmap) { if (bitmap == null) { return null; } return "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig() + (" (" + bitmap.getAllocationByteCount() + ")"); } private static String h(BitmapFactory.Options options) { return g(options.inBitmap); } private static void i(int i10, int i11, String str, BitmapFactory.Options options, Bitmap bitmap, int i12, int i13, long j10) { Log.v("Downsampler", "Decoded " + g(bitmap) + " from [" + i10 + "x" + i11 + "] " + str + " with inBitmap " + h(options) + " for [" + i12 + "x" + i13 + "], sample size: " + options.inSampleSize + ", density: " + options.inDensity + ", target density: " + options.inTargetDensity + ", thread: " + Thread.currentThread().getName() + ", duration: " + b7.f.a(j10)); } private static void j(BitmapFactory.Options options, i6.b bVar, 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 = bVar.e(i10, i11, config); } private static void k(f.a aVar, r rVar, a aVar2, i6.b bVar, l lVar, int i10, int i11, int i12, int i13, int i14, BitmapFactory.Options options) { int i15; int i16; int i17; int floor; int floor2; if (i11 <= 0 || i12 <= 0) { if (Log.isLoggable("Downsampler", 3)) { Log.d("Downsampler", "Unable to determine dimensions for: " + aVar + " with target [" + i13 + "x" + i14 + "]"); return; } return; } if (m(i10)) { i16 = i11; i15 = i12; } else { i15 = i11; i16 = i12; } float b10 = lVar.b(i15, i16, i13, i14); if (b10 <= 0.0f) { throw new IllegalArgumentException("Cannot scale with factor: " + b10 + " from: " + lVar + ", source: [" + i11 + "x" + i12 + "], target: [" + i13 + "x" + i14 + "]"); } l.a a10 = lVar.a(i15, i16, i13, i14); if (a10 == null) { throw new IllegalArgumentException("Cannot round with null rounding"); } float f10 = i15; float f11 = i16; int r10 = i15 / r(b10 * f10); int r11 = i16 / r(b10 * f11); l.a aVar3 = l.a.MEMORY; int max = a10 == aVar3 ? Math.max(r10, r11) : Math.min(r10, r11); int i18 = Build.VERSION.SDK_INT; if (i18 > 23 || !f12756k.contains(options.outMimeType)) { int max2 = Math.max(1, Integer.highestOneBit(max)); if (a10 == aVar3 && max2 < 1.0f / b10) { max2 <<= 1; } i17 = max2; } else { i17 = 1; } options.inSampleSize = i17; if (aVar == f.a.JPEG) { float min = Math.min(i17, 8); floor = (int) Math.ceil(f10 / min); floor2 = (int) Math.ceil(f11 / min); int i19 = i17 / 8; if (i19 > 0) { floor /= i19; floor2 /= i19; } } else { if (aVar != f.a.PNG && aVar != f.a.PNG_A) { if (aVar == f.a.WEBP || aVar == f.a.WEBP_A) { if (i18 >= 24) { float f12 = i17; floor = Math.round(f10 / f12); floor2 = Math.round(f11 / f12); } } else if (i15 % i17 == 0 && i16 % i17 == 0) { floor = i15 / i17; floor2 = i16 / i17; } else { int[] q10 = q(rVar, options, aVar2, bVar); floor = q10[0]; floor2 = q10[1]; } } float f13 = i17; floor = (int) Math.floor(f10 / f13); floor2 = (int) Math.floor(f11 / f13); } double b11 = lVar.b(floor, floor2, i13, i14); options.inTargetDensity = a(b11); options.inDensity = o(b11); if (p(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" + floor2 + "], exact scale factor: " + b10 + ", power of 2 sample size: " + i17 + ", adjusted scale factor: " + b11 + ", target density: " + options.inTargetDensity + ", density: " + options.inDensity); } } private void l(r rVar, e6.b bVar, boolean z10, boolean z11, BitmapFactory.Options options, int i10, int i11) { boolean z12; if (this.f12764e.b(i10, i11, options, z10, z11)) { return; } if (bVar == e6.b.PREFER_ARGB_8888) { options.inPreferredConfig = Bitmap.Config.ARGB_8888; return; } try { z12 = rVar.d().a(); } 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 boolean m(int i10) { return i10 == 90 || i10 == 270; } private boolean n(f.a aVar) { return true; } private static int o(double d10) { if (d10 > 1.0d) { d10 = 1.0d / d10; } return (int) Math.round(d10 * 2.147483647E9d); } private static boolean p(BitmapFactory.Options options) { int i10; int i11 = options.inTargetDensity; return i11 > 0 && (i10 = options.inDensity) > 0 && i11 != i10; } private static int[] q(r rVar, BitmapFactory.Options options, a aVar, i6.b bVar) { options.inJustDecodeBounds = true; c(rVar, options, aVar, bVar); options.inJustDecodeBounds = false; return new int[]{options.outWidth, options.outHeight}; } private static int r(double d10) { return (int) (d10 + 0.5d); } private static void s(BitmapFactory.Options options) { t(options); Queue queue = f12759n; synchronized (queue) { queue.offer(options); } } private static void t(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; } public h6.h u(ParcelFileDescriptor parcelFileDescriptor, int i10, int i11, e6.j jVar) { return e(new r.c(parcelFileDescriptor, this.f12763d, this.f12762c), i10, i11, jVar, f12757l); } public h6.h v(InputStream inputStream, int i10, int i11, e6.j jVar, a aVar) { return e(new r.b(inputStream, this.f12763d, this.f12762c), i10, i11, jVar, aVar); } public h6.h w(ByteBuffer byteBuffer, int i10, int i11, e6.j jVar) { return e(new r.a(byteBuffer, this.f12763d, this.f12762c), i10, i11, jVar, f12757l); } public boolean x(ParcelFileDescriptor parcelFileDescriptor) { return f6.m.c(); } public boolean y(InputStream inputStream) { return true; } public boolean z(ByteBuffer byteBuffer) { return true; } }