Skip to content

Commit

Permalink
Use deferred for launching iterative blur
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Jan 2, 2025
1 parent b977011 commit 1bf8c2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private class CloudyModifierNode(
val blurredBitmap = iterativeBlur(
androidBitmap = targetBitmap,
radius = radius
)?.apply {
).await()?.apply {
drawImage(this.asImageBitmap())
} ?: throw RuntimeException("Couldn't capture a bitmap from the composable tree")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package com.skydoves.cloudy.internals.render

import android.graphics.Bitmap
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async

// This string is used for error messages.
private const val externalName = "RenderScript Toolkit"
Expand Down Expand Up @@ -316,10 +318,10 @@ internal fun vectorSize(bitmap: Bitmap): Int {
}
}

internal suspend fun iterativeBlur(
internal fun CoroutineScope.iterativeBlur(
androidBitmap: Bitmap,
radius: Int
): Bitmap? = coroutineScope {
): Deferred<Bitmap?> = async {
val iterate = (radius + 1) / 25
var bitmap: Bitmap? = RenderScriptToolkit.blur(
inputBitmap = androidBitmap,
Expand Down

0 comments on commit 1bf8c2d

Please sign in to comment.