[webkit-dev] Proposal for serializing alpha channel values; request for algorithm help

L. David Baron dbaron at dbaron.org
Thu Nov 5 23:24:00 PST 2015


On Monday 2015-11-02 08:37 -0800, Simon Fraser wrote:
> > On Nov 1, 2015, at 7:40 PM, Darin Adler <darin at apple.com> wrote:
> > 
> > Hi folks.
> > 
> > Our engine supports alpha values from 0-255. But when we serialize them, we turn them into floating point values. When we do that, we include way too many digits of precision. For example, the alpha value 127 becomes 0.498039.
> > 
> > I like the idea of writing the minimum number of digits that are needed to round trip. So 127 would become 0.498 or even maybe 0.49 and 128 would become 0.5.
> > 
> > Three questions:
> > 
> > 1) Does the CSS specification allow or encourage this?
> 
> As long as the values round-trip, I think it’s OK.
> 
> > 2) Do you like this idea?
> 
> I would like to know what other browsers do.

For what it's worth, Gecko does have code to produce a
minimal-length alpha value.  nsStyleUtil::ColorComponentToFloat just
tries rounding to 2 decimal places, sees if the resulting float
round-trips back to the same 0-255 alpha value, and if it doesn't,
rounds to 3 places.

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                          https://www.mozilla.org/   𝄂
             Before I built a wall I'd ask to know
             What I was walling in or walling out,
             And to whom I was like to give offense.
               - Robert Frost, Mending Wall (1914)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20151106/a7f21cfd/attachment.sig>


More information about the webkit-dev mailing list