@@ -1333,8 +1333,23 @@ Repeating Gradients: the ''repeating-linear-gradient()'', ''repeating-radial-gra
1333
1333
<h3 id='color-stop-syntax'>
1334
1334
Gradient Color-Stops</h3>
1335
1335
1336
- All gradients are specified by a list of color stops,
1337
- giving the color and position of each stop on the [=gradient line=] ,
1336
+ The colors in gradients are specified using <a>color stops</a> .
1337
+ A <dfn export>color stop</dfn> is a combination of a color and one or two positions.
1338
+ (Depending on the type of gradient, that position can be a length, angle, or percentage.)
1339
+ While every color stop conceptually has at least one position,
1340
+ the position can be omitted in the syntax.
1341
+ (It gets automatically filled in by the user agent; see below for details.)
1342
+ The unit identifier may be omitted if the position is zero.
1343
+
1344
+ Between two <a>color stops</a> there can be a <dfn local-lt="color hint">color interpolation hint</dfn> ,
1345
+ which specifies how the colors of the two <a>color stops</a> on either side
1346
+ should be interpolated in the space between them
1347
+ (by default, they interpolate linearly).
1348
+ There can only be at most one <a>color interpolation hint</a> between any two given <a>color stops</a> ;
1349
+ using more than that makes the function invalid.
1350
+
1351
+ Color stops are organized into a <dfn export>color stop list</dfn> ,
1352
+ which is a list of one or more <a>color stops</a> ,
1338
1353
according to the following grammar:
1339
1354
1340
1355
<pre class=prod>
@@ -1375,33 +1390,6 @@ Gradient Color-Stops</h3>
1375
1390
</pre>
1376
1391
</div>
1377
1392
1378
- <p class='issue'>
1379
- This is past the complexity point where it can be easily understood with just prose.
1380
- Add a diagram illustrating the possibilities,
1381
- preferably for all three kinds of gradients
1382
- (to show off the three shapes of gradient lines).
1383
-
1384
- The colors in gradients are specified using <a>color stops</a> .
1385
- A <dfn export>color stop</dfn> is a combination of a color and one or two positions.
1386
- (Depending on the type of gradient, that position can be a length, angle, or percentage.)
1387
- While every color stop conceptually has at least one position,
1388
- the position can be omitted in the syntax.
1389
- (It gets automatically filled in by the user agent; see below for details.)
1390
- The unit identifier may be omitted if the position is zero.
1391
-
1392
- Between two <a>color stops</a> there can be a <dfn local-lt="color hint">color interpolation hint</dfn> ,
1393
- which specifies how the colors of the two <a>color stops</a> on either side
1394
- should be interpolated in the space between them
1395
- (by default, they interpolate linearly).
1396
- There can only be at most one <a>color interpolation hint</a> between any two given <a>color stops</a> ;
1397
- using more than that makes the function invalid.
1398
-
1399
- Color stops are organized into a <dfn export>color stop list</dfn> ,
1400
- which is a list of one or more <a>color stops</a> .
1401
- The first and last <a>color stops</a> in the list
1402
- must have a color
1403
- (though their position can be omitted).
1404
-
1405
1393
<a>Color stops</a> and <a>color hints</a> are placed on a <a>gradient line</a> ,
1406
1394
which defines the colors at every point of a gradient.
1407
1395
The gradient function defines the shape and length of the <a>gradient line</a> ,
@@ -1432,6 +1420,121 @@ Gradient Color-Stops</h3>
1432
1420
If multiple stops in a row lack a position,
1433
1421
they space themselves out equally.
1434
1422
1423
+ <h4 id=coloring-gradient-line>
1424
+ Coloring the Gradient Line</h4>
1425
+
1426
+ At each <a>color stop</a> position,
1427
+ the [=gradient line=] is the color of the <a>color stop</a> .
1428
+ Before the first <a>color stop</a> ,
1429
+ the [=gradient line=] is the color of the first <a>color stop</a> .
1430
+ After the last <a>color stop</a> , the [=gradient line=] is the color of the last <a>color stop</a> .
1431
+ Between two <a>color stops</a> ,
1432
+ the [=gradient line’s=] color is interpolated between the colors of the two <a>color stops</a> ,
1433
+ with the interpolation taking place in premultiplied RGBA space.
1434
+
1435
+ By default,
1436
+ this interpolation is linear--
1437
+ at 25%, 50%, or 75% of the distance between two <a>color stops</a> ,
1438
+ the color is a 25%, 50%, or 75% blend of the colors of the two stops.
1439
+
1440
+ However, if a <a>color hint</a> was provided between two <a>color stops</a> ,
1441
+ the interpolation is non-linear,
1442
+ and controlled by the hint:
1443
+
1444
+ <div algorithm="interpolate with a color hint">
1445
+ <ol>
1446
+ <li>
1447
+ Determine the location of the <a>color hint</a> as a percentage of the distance between the two <a>color stops</a> ,
1448
+ denoted as a number between 0 and 1,
1449
+ where 0 indicates the hint is placed right on the first <a>color stop</a> ,
1450
+ and 1 indicates the hint is placed right on the second <a>color stop</a> .
1451
+ Let this percentage be <var> H</var> .
1452
+
1453
+ <li>
1454
+ For any given point between the two color stops,
1455
+ determine the point's location as a percentage of the distance between the two <a>color stops</a> ,
1456
+ in the same way as the previous step.
1457
+ Let this percentage be <var> P</var> .
1458
+
1459
+ <li>
1460
+ Let <var> C</var> , the color weighting at that point,
1461
+ be equal to <code> P<sup> log<sub> H</sub> (.5)</sup></code> .
1462
+
1463
+ <li>
1464
+ The color at that point is then a linear blend between the colors of the two <a>color stops</a> ,
1465
+ blending <code> (1 - C)</code> of the first stop and <var> C</var> of the second stop.
1466
+ </ol>
1467
+ </div>
1468
+
1469
+ Note: The color hint specifies where the "halfway color"--
1470
+ the 50% blend between the colors of the two surrounding color stops--
1471
+ should be placed.
1472
+ When the hint is exactly halfway between the two surrounding color stops,
1473
+ the above interpolation algorithm
1474
+ happens to produce the ordinary linear interpolation.
1475
+ If the hint is placed anywhere else,
1476
+ it produces a smooth "exponential curve"
1477
+ between the surrounding color stops,
1478
+ with the "halfway color" occuring exactly where the hint specifies.
1479
+
1480
+ Issue: Add a visual example of a color hint being used.
1481
+
1482
+ If multiple <a>color stops</a> have the same position,
1483
+ they produce an infinitesimal transition from the one specified first in the list
1484
+ to the one specified last.
1485
+ In effect, the color suddenly changes at that position rather than smoothly transitioning.
1486
+
1487
+ <div class=example>
1488
+ The following example illustrates the difference between
1489
+ a gradient transitioning in pre-multiplied sRGBA
1490
+ and one transitioning (incorrectly) in non-premultiplied.
1491
+ In both of these example,
1492
+ the gradient is drawn over a white background.
1493
+ Both gradients could be written with the following value:
1494
+
1495
+ <pre> linear-gradient(90deg, red, transparent, blue)</pre>
1496
+
1497
+ In premultiplied space,
1498
+ transitions to or from "transparent" always look nice:
1499
+
1500
+ <object data="images/gradient2.svg" width="200"height="100"> (Image requires SVG)</object>
1501
+
1502
+ On the other hand,
1503
+ if a gradient were to incorrectly transition in non-premultiplied space,
1504
+ the colors near "transparent" would noticeably darken to a grayish color,
1505
+ because "transparent" is actually a shorthand for ''rgba(0,0,0,0)'' , or transparent black:
1506
+
1507
+ <object data="images/gradient3.svg" width="200"height="100"> (Image requires SVG)</object>
1508
+ </div>
1509
+
1510
+ <div class=note>
1511
+
1512
+ The definition and implications of "premultiplied" color spaces are given elsewhere in the technical literature,
1513
+ but a quick primer is given here to illuminate the process.
1514
+
1515
+ Given a color expressed as an rgba() 4-tuple,
1516
+ one can convert this to a premultiplied representation
1517
+ by multiplying the red, green, and blue components by the alpha component.
1518
+ For example, a partially-transparent blue may be given as <code class=lang-css><nobr> rgba(0, 0, 255, .5)</nobr></code> ,
1519
+ which would then be expressed as <code><nobr> [0, 0, 127.5, .5] </nobr></code> in its premultiplied representation.
1520
+
1521
+ Interpolating colors using the premultiplied representations
1522
+ rather than the plain rgba representations
1523
+ tends to produce more attractive transitions,
1524
+ particularly when transitioning from a fully opaque color to fully transparent.
1525
+
1526
+ Note that transitions where either the transparency or the color are held constant
1527
+ (for example, transitioning between <code class=lang-css><nobr> rgba(255, 0, 0, 100%)</nobr></code> (opaque red)
1528
+ and <code class=lang-css><nobr> rgba(0,0,255,100%)</nobr></code> (opaque blue),
1529
+ or <code class=lang-css><nobr> rgba(255,0,0,100%)</nobr></code> (opaque red)
1530
+ and <code class=lang-css><nobr> rgba(255,0,0,0%)</nobr></code> (transparent red))
1531
+ have identical results whether the color interpolation is done in premultiplied or non-premultiplied color-space.
1532
+ Differences only arise when <em> both</em> the color and transparency differ between the two endpoints.
1533
+ </div>
1534
+
1535
+ <h4 id=color-stop-fixup>
1536
+ Color Stop "Fixup"</h4>
1537
+
1435
1538
The following steps must be applied <em> in order</em> to process the <<color-stop-list>> .
1436
1539
After applying these rules,
1437
1540
all <a>color stops</a> and <a>color hints</a> will have a definite position and color (if appropriate)
@@ -1464,63 +1567,9 @@ Gradient Color-Stops</h3>
1464
1567
at the cost of changing behavior from level 3 for some edge cases that triggered fixup.
1465
1568
Make sure this is handled well in the serialization rules.
1466
1569
1467
- At each <a>color stop</a> position,
1468
- the line is the color of the <a>color stop</a> .
1469
- Between two <a>color stops</a> ,
1470
- the line's color is interpolated between the colors of the two <a>color stops</a> ,
1471
- with the interpolation taking place in premultiplied RGBA space.
1472
-
1473
- By default,
1474
- this interpolation is linear--
1475
- at 25%, 50%, or 75% of the distance between two <a>color stops</a> ,
1476
- the color is a 25%, 50%, or 75% blend of the colors of the two stops.
1477
-
1478
- However, if a <a>color hint</a> was provided between two <a>color stops</a> ,
1479
- the interpolation is non-linear,
1480
- and controlled by the hint:
1481
-
1482
- <ol>
1483
- <li>
1484
- Determine the location of the <a>color hint</a> as a percentage of the distance between the two <a>color stops</a> ,
1485
- denoted as a number between 0 and 1,
1486
- where 0 indicates the hint is placed right on the first <a>color stop</a> ,
1487
- and 1 indicates the hint is placed right on the second <a>color stop</a> .
1488
- Let this percentage be <var> H</var> .
1489
-
1490
- <li>
1491
- For any given point between the two color stops,
1492
- determine the point's location as a percentage of the distance between the two <a>color stops</a> ,
1493
- in the same way as the previous step.
1494
- Let this percentage be <var> P</var> .
1495
-
1496
- <li>
1497
- Let <var> C</var> , the color weighting at that point,
1498
- be equal to <code> P<sup> log<sub> H</sub> (.5)</sup></code> .
1499
-
1500
- <li>
1501
- The color at that point is then a linear blend between the colors of the two <a>color stops</a> ,
1502
- blending <code> (1 - C)</code> of the first stop and <var> C</var> of the second stop.
1503
- </ol>
1504
-
1505
- Note: If the hint is placed halfway between the two stops,
1506
- this is thus the ordinary linear interpolation.
1507
- If the hint is placed anywhere else,
1508
- it dictates the position of the "halfway point",
1509
- where the color is an equal blend between the two <a>color stops</a> ,
1510
- and produces smooth, even blends between the <a>color stops</a> and the "halfway point".
1511
-
1512
- Before the first <a>color stop</a> ,
1513
- the line is the color of the first <a>color stop</a> .
1514
- After the last <a>color stop</a> , the line is the color of the last <a>color stop</a> .
1515
-
1516
- If multiple <a>color stops</a> have the same position,
1517
- they produce an infinitesimal transition from the one specified first in the rule
1518
- to the one specified last.
1519
- In effect, the color suddenly changes at that position rather than smoothly transitioning.
1520
-
1521
1570
<div class=example>
1522
- Below are several pairs of gradients.
1523
- The latter of each pair is a manually "fixed-up" version of the former,
1571
+ In the following pairs of gradients,
1572
+ the latter of each pair is a manually "fixed-up" version of the former,
1524
1573
obtained by applying the above rules.
1525
1574
For each pair, both gradients will render identically.
1526
1575
<span class='note'> The numbers in each arrow specify which fixup steps are invoked in the transformation.</span>
@@ -1560,29 +1609,6 @@ Gradient Color-Stops</h3>
1560
1609
</pre>
1561
1610
</div>
1562
1611
1563
- <div class=example>
1564
- The following example illustrates the difference between
1565
- a gradient transitioning in pre-multiplied sRGBA
1566
- and one transitioning (incorrectly) in non-premultiplied.
1567
- In both of these example,
1568
- the gradient is drawn over a white background.
1569
- Both gradients could be written with the following value:
1570
-
1571
- <pre> linear-gradient(90deg, red, transparent, blue)</pre>
1572
-
1573
- In premultiplied space,
1574
- transitions to or from "transparent" always look nice:
1575
-
1576
- <object data="images/gradient2.svg" width="200"height="100"> (Image requires SVG)</object>
1577
-
1578
- On the other hand,
1579
- if a gradient were to incorrectly transition in non-premultiplied space,
1580
- the colors near "transparent" would noticeably darken to a grayish color,
1581
- because "transparent" is actually a shorthand for ''rgba(0,0,0,0)'' , or transparent black:
1582
-
1583
- <object data="images/gradient3.svg" width="200"height="100"> (Image requires SVG)</object>
1584
- </div>
1585
-
1586
1612
Note: It is recommended that authors not mix different types of units,
1587
1613
such as px, em, or %,
1588
1614
in a single rule,
@@ -1593,23 +1619,8 @@ Gradient Color-Stops</h3>
1593
1619
the blue <a>color stop's</a> position would be equivalent to "75px",
1594
1620
which precedes the yellow <a>color stop</a> ,
1595
1621
and would be corrected to a position of 100px.
1596
-
1597
- Note: The definition and implications of "premultiplied" color spaces are given elsewhere in the technical literature,
1598
- but a quick primer is given here to illuminate the process.
1599
- Given a color expressed as an rgba() 4-tuple,
1600
- one can convert this to a premultiplied representation
1601
- by multiplying the red, green, and blue components by the alpha component.
1602
- For example, a partially-transparent blue may be given as rgba(0,0,255,.5),
1603
- which would then be expressed as [0, 0, 127.5, .5] in its premultiplied representation.
1604
- Interpolating colors using the premultiplied representations
1605
- rather than the plain rgba representations
1606
- tends to produce more attractive transitions,
1607
- particularly when transitioning from a fully opaque color to fully transparent.
1608
- Note that transitions where either the transparency or the color are held constant
1609
- (for example, transitioning between rgba(255,0,0,100%) and rgba(0,0,255,100%),
1610
- or rgba(255,0,0,100%) and rgba(255,0,0,0%))
1611
- have identical results whether the color interpolation is done in premultiplied or non-premultiplied color-space.
1612
- Differences only arise when both the color and transparency differ between the two endpoints.
1622
+ This would produce an abrupt transition from yellow to blue,
1623
+ rather than the likely-intended smooth transition between the two colors.
1613
1624
1614
1625
1615
1626
1D Image Values: the ''stripes()'' notation {#stripes}
0 commit comments