Skip to content

Commit a28b013

Browse files
committed
[css-color-4] Added steps for serializing a uint8_t alpha, from cssom-1 #9798
1 parent 94cfc4c commit a28b013

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

css-color-4/Overview.bs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,9 +5943,49 @@ Serializing alpha values</h3>
59435943
an implicit value of 1 (fully opaque) is the default.
59445944

59455945
If the alpha is any other value than 1,
5946-
it is explicitly included in the serialization,
5947-
as a <<number>>, not a <<percentage>>.
5948-
The value is expressed in base ten,
5946+
it is explicitly included in the serialization as described below.
5947+
5948+
If the value is internally represented as an integer
5949+
between 0 and 255 inclusive (i.e. 8-bit unsigned integer),
5950+
follow these steps:
5951+
5952+
<ol>
5953+
<li>Let <var>alpha</var> be the given integer.
5954+
<li>If there exists an integer between 0 and 100 inclusive that,
5955+
when multiplied with 2.55 and rounded to the closest integer
5956+
(rounding up if two values are equally close), equals <var>alpha</var>,
5957+
let <var>rounded</var> be that integer divided by 100.
5958+
<li>Otherwise, let <var>rounded</var> be <var>alpha</var>
5959+
divided by 0.255 and rounded to the closest integer
5960+
(rounding up if two values are equally close),
5961+
divided by 1000.
5962+
<li>Return the result of serializing <var>rounded</var>
5963+
as a <<number>>.
5964+
</ol>
5965+
5966+
Otherwise, return the result of serializing the given value
5967+
(as a <<number>>, not a <<percentage>>).
5968+
5969+
<div class="example" id="ex-alpha-255">
5970+
<p>
5971+
For example,
5972+
if the alpha is stored as the 8-bit unsigned integer 237,
5973+
the integer 93 satisfies the criterion
5974+
because Math.round(93 * 2.55) is 237,
5975+
and so the alpha is serialized as "0.93".
5976+
</p>
5977+
<p>
5978+
However,
5979+
if the alpha is stored as the 8-bit unsigned integer 236,
5980+
there is no such integer
5981+
(92 maps to 235 while 94 maps to 240),
5982+
and so since 236 ÷ 0.255 = 925.490196078
5983+
the alpha is serialized as "0.92549"
5984+
(no more than 6 figures, trailing zeroes omitted).
5985+
</p>
5986+
</div>
5987+
5988+
The <<number>> value is expressed in base ten,
59495989
with the "." character as decimal separator.
59505990
The leading zero must not be omitted.
59515991
Trailing zeroes must be omitted.

0 commit comments

Comments
 (0)