2010-01-30 Simon Fraser <simon.fraser@apple.com>

        Reviewed by Adele Peterson.

        Do color animations on premultiplied colors
        https://bugs.webkit.org/show_bug.cgi?id=34383

        Convert colors to premultiplied alpha before interpolating them,
        then convert the result back to non-premultiplied. This gives better
        results when animating from transparent colors.

        Test: transitions/color-transition-premultiplied.html

        * page/animation/AnimationBase.cpp:
        (WebCore::blendFunc):

git-svn-id: svn://svn.chromium.org/blink/trunk@54106 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6f045fff
2010-01-30 Simon Fraser <simon.fraser@apple.com>
Reviewed by Adele Peterson.
Do color animations on premultiplied colors
https://bugs.webkit.org/show_bug.cgi?id=34383
Testcase for animating from transparent colors.
* transitions/color-transition-premultiplied-expected.txt: Added.
* transitions/color-transition-premultiplied.html: Added.
== Rolled over to ChangeLog-2010-01-29 == == Rolled over to ChangeLog-2010-01-29 ==
PASS - "background-color" property for "one" element at 0.5s saw something close to: 0,127,0
PASS - "background-color" property for "two" element at 0.5s saw something close to: 0,0,255
<!DOCTYPE html>
<html>
<head>
<style type="text/css" media="screen">
.box {
width: 100px;
height: 100px;
margin: 10px;
border: 1px solid black;
-webkit-transition: background-color 1s linear;
-moz-transition: background-color 1s linear;
}
#one {
background-color: transparent;
}
#one.changed {
background-color: green;
}
#two {
background-color: rgba(0, 255, 0, 0);
}
#two.changed {
background-color: rgba(0, 0, 255, 1);
}
</style>
<script src="transition-test-helpers.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
const expectedValues = [
// [time, element-id, property, expected-value, tolerance]
[0.5, 'one', 'background-color', [0, 127, 0], 2],
[0.5, 'two', 'background-color', [0, 0, 255], 2]
];
function setupTest()
{
document.getElementById('one').className = 'box changed';
document.getElementById('two').className = 'box changed';
}
runTransitionTest(expectedValues, setupTest, true);
</script>
</head>
<body>
<div class="box" id="one">
</div>
<div class="box" id="two">
</div>
<div id="result">
</div>
</body>
</html>
\ No newline at end of file
2010-01-30 Simon Fraser <simon.fraser@apple.com>
Reviewed by Adele Peterson.
Do color animations on premultiplied colors
https://bugs.webkit.org/show_bug.cgi?id=34383
Convert colors to premultiplied alpha before interpolating them,
then convert the result back to non-premultiplied. This gives better
results when animating from transparent colors.
Test: transitions/color-transition-premultiplied.html
* page/animation/AnimationBase.cpp:
(WebCore::blendFunc):
2010-01-30 Gustavo Noronha Silva <gns@gnome.org> 2010-01-30 Gustavo Noronha Silva <gns@gnome.org>
Build fixes needed for make distcheck. Build fixes needed for make distcheck.
......
...@@ -92,10 +92,17 @@ static inline Color blendFunc(const AnimationBase* anim, const Color& from, cons ...@@ -92,10 +92,17 @@ static inline Color blendFunc(const AnimationBase* anim, const Color& from, cons
if (progress == 1 && !to.isValid()) if (progress == 1 && !to.isValid())
return Color(); return Color();
return Color(blendFunc(anim, from.red(), to.red(), progress), // Contrary to the name, RGBA32 actually stores ARGB, so we can initialize Color directly from premultipliedARGBFromColor().
blendFunc(anim, from.green(), to.green(), progress), // Also, premultipliedARGBFromColor() bails on zero alpha, so special-case that.
blendFunc(anim, from.blue(), to.blue(), progress), Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : 0;
blendFunc(anim, from.alpha(), to.alpha(), progress)); Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : 0;
Color premultBlended(blendFunc(anim, premultFrom.red(), premultTo.red(), progress),
blendFunc(anim, premultFrom.green(), premultTo.green(), progress),
blendFunc(anim, premultFrom.blue(), premultTo.blue(), progress),
blendFunc(anim, premultFrom.alpha(), premultTo.alpha(), progress));
return Color(colorFromPremultipliedARGB(premultBlended.rgb()));
} }
static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress) static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment