Skip to content

Commit 321c3e5

Browse files
committed
[css-images] Define the color-hint functionality that Rik presented.
--HG-- extra : rebase_source : a34f16f9cb06b70a0cddb329628042f451a675b6
1 parent 9344b0d commit 321c3e5

File tree

2 files changed

+382
-212
lines changed

2 files changed

+382
-212
lines changed

css-images/Overview.bs

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,20 +1677,33 @@ Gradient Color-Stops</h3>
16771677

16781678
<pre class=prod>
16791679
<dfn>&lt;color-stop-list></dfn> =
1680-
<<cap-linear-color-stop>> , [ <<linear-color-stop>># , ]? <<cap-linear-color-stop>>
1681-
<dfn>&lt;cap-linear-color-stop></dfn> = <<color>> &amp;&amp; <<color-stop-length>>?
1682-
<dfn>&lt;linear-color-stop></dfn> = <<color>> || <<color-stop-length>>
1680+
[ <<linear-color-stop>> , <<linear-color-hint>>? ]# , <<linear-color-stop>>
1681+
<dfn>&lt;linear-color-stop></dfn> = <<color>> && <<color-stop-length>>
1682+
<dfn>&lt;linear-color-hint></dfn> = <<length>> | <<percentage>>
16831683
<dfn>&lt;color-stop-length></dfn> = [ <<length>> | <<percentage>> ]{1,2}
16841684
16851685
<dfn>&lt;angular-color-stop-list></dfn> =
1686-
<<cap-angular-color-stop>> , [ <<angular-color-stop>># , ]? <<cap-angular-color-stop>>H
1687-
<dfn>&lt;cap-angular-color-stop></dfn> = <<color>> &amp;&amp; <<color-stop-angle>>?
1688-
<dfn>&lt;angular-color-stop></dfn> = <<color>> || <<color-stop-angle>>
1686+
[ <<angular-color-stop>> , <<angular-color-hint>>? ]# , <<angular-color-stop>>
1687+
<dfn>&lt;angular-color-stop></dfn> = <<color>> && <<color-stop-angle>>?
1688+
<dfn>&lt;angular-color-hint></dfn> = <<angle>> | <<percentage>>
16891689
<dfn>&lt;color-stop-angle></dfn> = [ <<angle>> | <<percentage>> ]{1,2}
16901690
16911691
<dfn>&lt;color-stop></dfn> = <<color-stop-length>> | <<color-stop-angle>>
16921692
</pre>
16931693

1694+
<pre class='railroad'>
1695+
Plus:
1696+
Sequence:
1697+
N: <color-stop>
1698+
T: ,
1699+
Choice: 1
1700+
N: <color-hint>
1701+
Skip:
1702+
T: ,
1703+
N: <color-stop>
1704+
</pre>
1705+
1706+
16941707
<p class='issue'>
16951708
This is past the complexity point where it can be easily understood with just prose.
16961709
Add a diagram illustrating the possibilities,
@@ -1700,9 +1713,18 @@ Gradient Color-Stops</h3>
17001713
The colors in gradients are specified using <a>color stops</a>.
17011714
A <dfn export>color stop</dfn> is a combination of a color and one or two positions.
17021715
(Depending on the type of gradient, that position can be a length, angle, or percentage.)
1703-
While every color stop conceptually has both of these,
1704-
either of them can be omitted when writing a stylesheet.
1705-
(The missing parts are automatically filled in by the user agent.)
1716+
While every color stop conceptually has at least one position,
1717+
the position can be omitted in the syntax.
1718+
(It gets automatically filled in by the user agent; see below for details.)
1719+
1720+
Some <a>color stops</a> don't have a color,
1721+
only a position.
1722+
A <a>color stop</a> like this is a <dfn>color interpolation hint</dfn>,
1723+
which specifies how the colors of the two <a>color stops</a> on either side
1724+
should be interpolated in the space between them
1725+
(by default, they interpolate linearly).
1726+
There can only be at most one <a>color interpolation hint</a> between any two given normal <a>color stops</a>;
1727+
using more than that makes the function invalid.
17061728

17071729
Color stops are organized into a <dfn export>color stop list</dfn>,
17081730
which is a list of one or more <a>color stops</a>.
@@ -1732,7 +1754,7 @@ Gradient Color-Stops</h3>
17321754
to specifying two <a>color stops</a> with the same color,
17331755
one for each position.
17341756
However, if the color is omitted,
1735-
it's treated slightly differently by step 4 in the clean-up algorithm below.
1757+
it's treated as a single <a>color stop</a> by step 4 in the clean-up algorithm below.
17361758
<span class='note'>Specifying two locations makes it easier to create solid-color "stripes" in a gradient,
17371759
without having to repeat the color twice.</span>
17381760

@@ -1793,8 +1815,48 @@ Gradient Color-Stops</h3>
17931815
At each <a>color stop</a> position,
17941816
the line is the color of the <a>color stop</a>.
17951817
Between two <a>color stops</a>,
1796-
the line's color is linearly interpolated between the colors of the two <a>color stops</a>,
1818+
the line's color is interpolated between the colors of the two <a>color stops</a>,
17971819
with the interpolation taking place in premultiplied RGBA space.
1820+
1821+
By default,
1822+
this interpolation is linear--
1823+
at 25%, 50%, or 75% of the distance between two <a>color stops</a>,
1824+
the color is a 25%, 50%, or 75% blend of the colors of the two stops.
1825+
1826+
However, if a <a>color interpolation hint</a> was provided between two <a>color stops</a>,
1827+
the interpolation is non-linear,
1828+
and controlled by the hint:
1829+
1830+
<ol>
1831+
<li>
1832+
Determine the location of the hint as a percentage of the distance between the two <a>color stops</a>,
1833+
denoted as a number between 0 and 1,
1834+
where 0 indicates the hint is placed right on the first <a>color stop</a>,
1835+
and 1 indicates the hint is placed right on the second <a>color stop</a>.
1836+
Let this percentage be <var>H</var>.
1837+
1838+
<li>
1839+
For any given point between the two color stops,
1840+
determine the point's location as a percetnage of the distance between the two <a>color stops</a>,
1841+
in the same way as the previous step.
1842+
Let this percentage be <var>P</var>.
1843+
1844+
<li>
1845+
Let <var>C</var>, the color weighting at that point,
1846+
be equal to <code>P<sup>log<sub>.5</sub>(H)</sup></code>.
1847+
1848+
<li>
1849+
The color at that point is then a linear blend between the colors of the two <a>color stops</a>,
1850+
blending <code>(1 - C)</code> of the first stop and <var>C</var> of the second stop.
1851+
</ol>
1852+
1853+
Note: If the hint is placed halfway between the two stops,
1854+
this is thus the ordinary linear interpolation.
1855+
If the hint is placed anywhere else,
1856+
it dictates the position of the "halfway point",
1857+
where the color is an equal blend between the two <a>color stops</a>,
1858+
and produces smooth, even blends between the <a>color stops</a> and the "halfway point".
1859+
17981860
Before the first <a>color stop</a>,
17991861
the line is the color of the first <a>color stop</a>.
18001862
After the last <a>color stop</a>, the line is the color of the last <a>color stop</a>.

0 commit comments

Comments
 (0)