Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix defaults for blurRadius and noiseFactor #361

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ private val noiseTextureCache = lruCache<Int, Bitmap>(3)

context(CompositionLocalConsumerModifierNode)
private fun getNoiseTexture(noiseFactor: Float): Bitmap {
val cacheKey = (noiseFactor * 255).roundToInt()
val cached = noiseTextureCache[cacheKey]
val noiseAlphaInt = (noiseFactor * 255).roundToInt().coerceIn(0, 255)
val cached = noiseTextureCache[noiseAlphaInt]
if (cached != null && !cached.isRecycled) {
return cached
}

// We draw the noise with the given opacity
val resources = currentValueOf(LocalContext).resources
return BitmapFactory.decodeResource(resources, R.drawable.haze_noise)
.withAlpha(noiseFactor)
.also { noiseTextureCache.put(cacheKey, it) }
.withAlpha(noiseAlphaInt)
.also { noiseTextureCache.put(noiseAlphaInt, it) }
}

context(CompositionLocalConsumerModifierNode)
Expand Down Expand Up @@ -155,9 +155,9 @@ private fun AndroidRenderEffect.withTint(
* There might be a better way to do this via a [BlendMode], but none of the results looked as
* good.
*/
private fun Bitmap.withAlpha(alpha: Float): Bitmap {
private fun Bitmap.withAlpha(alpha: Int): Bitmap {
val paint = android.graphics.Paint().apply {
this.alpha = (alpha * 255).roundToInt().coerceIn(0, 255)
this.alpha = alpha
}

return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class HazeChildNode(
else -> Offset.Zero
}

override var blurRadius: Dp = HazeDefaults.blurRadius
override var blurRadius: Dp = Dp.Unspecified
set(value) {
if (value != field) {
log(TAG) { "blurRadius changed. Current: $field. New: $value" }
Expand All @@ -144,7 +144,7 @@ class HazeChildNode(
}
}

override var noiseFactor: Float = HazeDefaults.noiseFactor
override var noiseFactor: Float = -1f
set(value) {
if (value != field) {
log(TAG) { "noiseFactor changed. Current: $field. New: $value" }
Expand Down
Loading