jimu-decompiled/sources/com/bumptech/glide/load/resource/bitmap/DrawableToBitmapConverter.java
2025-05-13 19:24:51 +02:00

73 lines
2.8 KiB
Java

package com.bumptech.glide.load.resource.bitmap;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter;
import java.util.concurrent.locks.Lock;
/* loaded from: classes.dex */
final class DrawableToBitmapConverter {
private static final BitmapPool a = new BitmapPoolAdapter() { // from class: com.bumptech.glide.load.resource.bitmap.DrawableToBitmapConverter.1
@Override // com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter, com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
public void a(Bitmap bitmap) {
}
};
static Resource<Bitmap> a(BitmapPool bitmapPool, Drawable drawable, int i, int i2) {
Bitmap bitmap;
Drawable current = drawable.getCurrent();
boolean z = false;
if (current instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) current).getBitmap();
} else if (current instanceof Animatable) {
bitmap = null;
} else {
bitmap = b(bitmapPool, current, i, i2);
z = true;
}
if (!z) {
bitmapPool = a;
}
return BitmapResource.a(bitmap, bitmapPool);
}
private static Bitmap b(BitmapPool bitmapPool, Drawable drawable, int i, int i2) {
if (i == Integer.MIN_VALUE && drawable.getIntrinsicWidth() <= 0) {
if (Log.isLoggable("DrawableToBitmap", 5)) {
Log.w("DrawableToBitmap", "Unable to draw " + drawable + " to Bitmap with Target.SIZE_ORIGINAL because the Drawable has no intrinsic width");
}
return null;
}
if (i2 == Integer.MIN_VALUE && drawable.getIntrinsicHeight() <= 0) {
if (Log.isLoggable("DrawableToBitmap", 5)) {
Log.w("DrawableToBitmap", "Unable to draw " + drawable + " to Bitmap with Target.SIZE_ORIGINAL because the Drawable has no intrinsic height");
}
return null;
}
if (drawable.getIntrinsicWidth() > 0) {
i = drawable.getIntrinsicWidth();
}
if (drawable.getIntrinsicHeight() > 0) {
i2 = drawable.getIntrinsicHeight();
}
Lock a2 = TransformationUtils.a();
a2.lock();
Bitmap a3 = bitmapPool.a(i, i2, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(a3);
drawable.setBounds(0, 0, i, i2);
drawable.draw(canvas);
canvas.setBitmap(null);
return a3;
} finally {
a2.unlock();
}
}
}