Skip to content

Commit

Permalink
Opacity filter on Android (#44454)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44454

tsia

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D56847475

fbshipit-source-id: bbd51e8c744914f1d2caf392996d20ab03b3fb6f
  • Loading branch information
joevilches authored and facebook-github-bot committed May 8, 2024
1 parent b0e746e commit 00f3867
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ internal object FilterHelper {
"grayscale" -> createGrayscaleEffect(amount, chainedEffects)
"sepia" -> createSepiaEffect(amount, chainedEffects)
"saturate" -> createSaturateEffect(amount, chainedEffects)
"hue-rotate" -> createHueRotateEffect(amount, chainedEffects)
"hueRotate" -> createHueRotateEffect(amount, chainedEffects)
"invert" -> createInvertEffect(amount, chainedEffects)
"blur" -> createBlurEffect(amount, chainedEffects)
"opacity" -> createOpacityEffect(amount, chainedEffects)
else -> throw IllegalArgumentException("Invalid filter name: $filterName")
}
}
Expand All @@ -63,6 +64,7 @@ internal object FilterHelper {
"saturate" -> createSaturateColorMatrix(amount)
"hueRotate" -> createHueRotateColorMatrix(amount)
"invert" -> createInvertColorMatrix(amount)
"opacity" -> createOpacityColorMatrix(amount)
else -> throw IllegalArgumentException("Invalid color matrix filter: $filterName")
}

Expand Down Expand Up @@ -117,6 +119,20 @@ internal object FilterHelper {
return matrix
}

// https://www.w3.org/TR/filter-effects-1/#opacityEquivalent
public fun createOpacityEffect(
amount: Float,
chainedEffects: RenderEffect? = null
): RenderEffect {
return createColorMatrixEffect(createOpacityColorMatrix(amount), chainedEffects)
}

public fun createOpacityColorMatrix(amount: Float): ColorMatrix {
val matrix = ColorMatrix()
matrix.setScale(1f, 1f, 1f, amount)
return matrix
}

// https://www.w3.org/TR/filter-effects-1/#contrastEquivalent
public fun createContrastEffect(
amount: Float,
Expand Down

0 comments on commit 00f3867

Please sign in to comment.