fix: guard zero-dimension bitmap and recycle on early return in BlurTransformation
Made-with: Cursor
This commit is contained in:
@@ -29,11 +29,15 @@ class BlurTransformation(
|
|||||||
private suspend fun Bitmap.stackBlur(scale: Float, radius: Int): Bitmap? =
|
private suspend fun Bitmap.stackBlur(scale: Float, radius: Int): Bitmap? =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
var sentBitmap = this@stackBlur
|
var sentBitmap = this@stackBlur
|
||||||
val width = (sentBitmap.width * scale).roundToInt()
|
val width = (sentBitmap.width * scale).roundToInt().coerceAtLeast(1)
|
||||||
val height = (sentBitmap.height * scale).roundToInt()
|
val height = (sentBitmap.height * scale).roundToInt().coerceAtLeast(1)
|
||||||
sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false)
|
sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false)
|
||||||
val bitmap = sentBitmap.copy(sentBitmap.config ?: Bitmap.Config.ARGB_8888, true)
|
val bitmap = sentBitmap.copy(sentBitmap.config ?: Bitmap.Config.ARGB_8888, true)
|
||||||
if (radius < 1) return@withContext null
|
if (radius < 1) {
|
||||||
|
sentBitmap.recycle()
|
||||||
|
bitmap.recycle()
|
||||||
|
return@withContext null
|
||||||
|
}
|
||||||
val w = bitmap.width
|
val w = bitmap.width
|
||||||
val h = bitmap.height
|
val h = bitmap.height
|
||||||
val pix = IntArray(w * h)
|
val pix = IntArray(w * h)
|
||||||
|
|||||||
Reference in New Issue
Block a user