discord-jadx/app/src/main/java/b/f/k/a.java

110 lines
3.4 KiB
Java

package b.f.k;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ColorSpace;
import android.os.Build;
import androidx.core.util.Pools;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Objects;
/* compiled from: BitmapUtil */
public final class a {
public static final Pools.SynchronizedPool<ByteBuffer> a = new Pools.SynchronizedPool<>(12);
/* compiled from: BitmapUtil */
/* renamed from: b.f.k.a$a reason: collision with other inner class name */
public static /* synthetic */ class C0067a {
public static final /* synthetic */ int[] a;
static {
int[] iArr = new int[Bitmap.Config.values().length];
a = iArr;
try {
iArr[Bitmap.Config.ARGB_8888.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[Bitmap.Config.ALPHA_8.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
a[Bitmap.Config.ARGB_4444.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
a[Bitmap.Config.RGB_565.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
a[Bitmap.Config.RGBA_F16.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
try {
a[Bitmap.Config.HARDWARE.ordinal()] = 6;
} catch (NoSuchFieldError unused6) {
}
}
}
public static b a(InputStream inputStream) {
Objects.requireNonNull(inputStream);
Pools.SynchronizedPool<ByteBuffer> synchronizedPool = a;
ByteBuffer acquire = synchronizedPool.acquire();
if (acquire == null) {
acquire = ByteBuffer.allocate(16384);
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
options.inTempStorage = acquire.array();
ColorSpace colorSpace = null;
BitmapFactory.decodeStream(inputStream, null, options);
if (Build.VERSION.SDK_INT >= 26) {
colorSpace = options.outColorSpace;
}
b bVar = new b(options.outWidth, options.outHeight, colorSpace);
synchronizedPool.release(acquire);
return bVar;
} catch (Throwable th) {
a.release(acquire);
throw th;
}
}
public static int b(Bitmap.Config config) {
switch (C0067a.a[config.ordinal()]) {
case 1:
return 4;
case 2:
return 1;
case 3:
case 4:
return 2;
case 5:
return 8;
case 6:
return 4;
default:
throw new UnsupportedOperationException("The provided Bitmap.Config is not supported");
}
}
public static int c(int i, int i2, Bitmap.Config config) {
return b(config) * i * i2;
}
@SuppressLint({"NewApi"})
public static int d(Bitmap bitmap) {
if (bitmap == null) {
return 0;
}
try {
return bitmap.getAllocationByteCount();
} catch (NullPointerException unused) {
return bitmap.getByteCount();
}
}
}