fix: guard zero-dimension bitmap and recycle on early return in BlurTransformation

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-18 11:36:35 -04:00
parent 2e615850bc
commit 14aeeecd9c

View File

@@ -29,11 +29,15 @@ class BlurTransformation(
private suspend fun Bitmap.stackBlur(scale: Float, radius: Int): Bitmap? =
withContext(Dispatchers.IO) {
var sentBitmap = this@stackBlur
val width = (sentBitmap.width * scale).roundToInt()
val height = (sentBitmap.height * scale).roundToInt()
val width = (sentBitmap.width * scale).roundToInt().coerceAtLeast(1)
val height = (sentBitmap.height * scale).roundToInt().coerceAtLeast(1)
sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false)
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 h = bitmap.height
val pix = IntArray(w * h)