-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat alpha channel differently when compositing animations
Currently our implementation of InterpolationType::Composite is too general and could result in errors when applied to color. Let's use an example to demonstrate how it works. Suppose we have to keyframes to animation keyframe[0]: (10, 0, 0, 1), composite: add keyframe[1]: (30, 0, 0, 1), composite: replace and the underlying color of the animation target is (50, 0, 0, 1). We want to calculate the interpolation result at 1.2, and we will use alpha channel because that's easier to demonstrate. The first step is computing the interpolated result at 1.2 for the two keyframes, and our implementation gives correct result where the alpha is 1 * (-0.2) + 1 *1.2 = 1. In other words, the result is (34, 0, 0, 1). Next step is to composite the interpolated result onto the underlying value. The alpha channel is 1 * (-0.2) + 1 = 0.8. We can see that the alpha channel is wrong, and because of that, the other channel would be wrong because they operate on pre-multiplied numbers. This CL treats alpha channel differently for color. When the underlying and the other one has the same alpha channel, we keep that value and do not apply the formula. Here is the spec indicates that alpha channel needs to be always clamped to range [0, 1]: https://www.w3.org/TR/css-color-3/#alphavaluedt Bug: 981326 Change-Id: I34429d0a463bdc83099d58ad23874086d861dc9f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715786 Commit-Queue: Xida Chen <xidachen@chromium.org> Reviewed-by: Stephen McGruer <smcgruer@chromium.org> Cr-Commit-Position: refs/heads/master@{#686064}
- Loading branch information
Showing
4 changed files
with
80 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
third_party/blink/web_tests/animations/composition/color-composition.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<meta charset="UTF-8"> | ||
<style> | ||
.target { | ||
width: 40px; | ||
height: 40px; | ||
background-color: black; | ||
} | ||
.expected { | ||
background-color: green; | ||
} | ||
</style> | ||
<body> | ||
<script src="../interpolation/resources/interpolation-test.js"></script> | ||
<script> | ||
assertComposition({ | ||
property: 'color', | ||
underlying: 'rgb(50, 50, 50)', | ||
addFrom: 'rgb(10, 10, 10)', | ||
replaceTo: 'rgb(30, 30, 30)', | ||
}, [ | ||
{at: 0, is: 'rgb(60, 60, 60)'}, | ||
{at: 0.2, is: 'rgb(54, 54, 54)'}, | ||
{at: 1, is: 'rgb(30, 30, 30)'}, | ||
{at: 1.2, is: 'rgb(24, 24, 24)'}, | ||
{at: 1.5, is: 'rgb(15, 15, 15)'}, | ||
]); | ||
|
||
assertComposition({ | ||
property: 'color', | ||
underlying: 'rgb(60, 60, 60)', | ||
addFrom: 'rgb(0, 0, 0)', | ||
replaceTo: 'rgb(50, 50, 50)', | ||
}, [ | ||
{at: 0, is: 'rgb(60, 60, 60)'}, | ||
{at: 0.5, is: 'rgb(55, 55, 55)'}, | ||
{at: 1, is: 'rgb(50, 50, 50)'}, | ||
{at: 1.2, is: 'rgb(48, 48, 48)'}, | ||
{at: 1.5, is: 'rgb(45, 45, 45)'}, | ||
]); | ||
</script> | ||
</body> |
89 changes: 0 additions & 89 deletions
89
.../web_tests/animations/custom-properties/custom-color-list-type-interpolation-expected.txt
This file was deleted.
Oops, something went wrong.