Commit cd3f24d5 authored by Benjamin Otte's avatar Benjamin Otte

cssvalue: Change color transitions to run premultiplied

Previously, the unpremultiplied values from the GdkRGBA were taken. Now
we premultiply the color values as specified by the CSS specs.
This is only relevant when transitioning with translucent colors.

An example is the halfway transition between transparent (0, 0, 0, 0)
and white (1, 1, 1, 1). Previously, all 4 values where transitioned
separately and the result was semi-transparent gray (0.5, 0.5, 0.5,
0.5).
By depending on the alpha value, the result is now semi-transparent
white (1, 1, 1, 0.5) which is what one would naively expect.

New reftest: color-transition
parent 142abce4
......@@ -74,9 +74,15 @@ gtk_css_value_rgba_transition (GtkCssValue *start,
}
else
{
result.red = transition (start->rgba.red, end->rgba.red, progress);
result.green = transition (start->rgba.green, end->rgba.green, progress);
result.blue = transition (start->rgba.blue, end->rgba.blue, progress);
result.red = transition (start->rgba.red * start->rgba.alpha,
end->rgba.red * end->rgba.alpha,
progress) / result.alpha;
result.green = transition (start->rgba.green * start->rgba.alpha,
end->rgba.green * end->rgba.alpha,
progress) / result.alpha;
result.blue = transition (start->rgba.blue * start->rgba.alpha,
end->rgba.blue * end->rgba.alpha,
progress) / result.alpha;
}
return _gtk_css_rgba_value_new_from_rgba (&result);
......
......@@ -185,6 +185,9 @@ testdata = \
cellrenderer-pixbuf-stock-rtl.css \
cellrenderer-pixbuf-stock-rtl.ui \
cellrenderer-pixbuf-stock-rtl.ref.ui \
color-transition.css \
color-transition.ref.ui \
color-transition.ui \
css-currentcolor-alpha.css \
css-currentcolor-alpha.ui \
css-currentcolor-alpha.ref.ui \
......
@import "reset-to-defaults.css";
@keyframes foo {
100% { background-color: blue; }
}
GtkWindow {
background-color: #7F0080;
}
GtkBox {
background-color: red;
}
GtkBox GtkBox {
background-color: transparent;
animation: foo 100s steps(2);
}
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
</object>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
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