Skip to content

Commit

Permalink
[css-color-4] Added steps for serializing a uint8_t alpha, from cssom-1
Browse files Browse the repository at this point in the history
  • Loading branch information
svgeesus committed Jan 30, 2024
1 parent 94cfc4c commit a28b013
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions css-color-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5943,9 +5943,49 @@ Serializing alpha values</h3>
an implicit value of 1 (fully opaque) is the default.

If the alpha is any other value than 1,
it is explicitly included in the serialization,
as a <<number>>, not a <<percentage>>.
The value is expressed in base ten,
it is explicitly included in the serialization as described below.

If the value is internally represented as an integer
between 0 and 255 inclusive (i.e. 8-bit unsigned integer),
follow these steps:

<ol>
<li>Let <var>alpha</var> be the given integer.
<li>If there exists an integer between 0 and 100 inclusive that,
when multiplied with 2.55 and rounded to the closest integer
(rounding up if two values are equally close), equals <var>alpha</var>,
let <var>rounded</var> be that integer divided by 100.
<li>Otherwise, let <var>rounded</var> be <var>alpha</var>
divided by 0.255 and rounded to the closest integer
(rounding up if two values are equally close),
divided by 1000.
<li>Return the result of serializing <var>rounded</var>
as a <<number>>.
</ol>

Otherwise, return the result of serializing the given value
(as a <<number>>, not a <<percentage>>).

<div class="example" id="ex-alpha-255">
<p>
For example,
if the alpha is stored as the 8-bit unsigned integer 237,
the integer 93 satisfies the criterion
because Math.round(93 * 2.55) is 237,
and so the alpha is serialized as "0.93".
</p>
<p>
However,
if the alpha is stored as the 8-bit unsigned integer 236,
there is no such integer
(92 maps to 235 while 94 maps to 240),
and so since 236 ÷ 0.255 = 925.490196078
the alpha is serialized as "0.92549"
(no more than 6 figures, trailing zeroes omitted).
</p>
</div>

The <<number>> value is expressed in base ten,
with the "." character as decimal separator.
The leading zero must not be omitted.
Trailing zeroes must be omitted.
Expand Down

0 comments on commit a28b013

Please sign in to comment.