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

Maciej Stachowiak mjs at apple.com
Tue Nov 3 11:10:40 PST 2015


Minimal strings should round trip ok, but will it still be accurate enough if the client attempts to do math with them? It's at least theoretically possible someone may try to multiply by the alpha value.

 - Maciej

> On Nov 2, 2015, at 12:28 AM, Gavin Barraclough <barraclough at apple.com> wrote:
> 
>> On Nov 1, 2015, at 7:40 PM, Darin Adler <darin at apple.com <mailto:darin at apple.com>> wrote:
>> 
>> 3) Can you help me come up with a super-efficient algorithm to do this serialization?
> 
> Table lookup? FP conversion code is hard, and this is a relatively small number of strings.
> 
> You could also flatten all the strings into one big string, and take out a pointer indirection (below).
> 
> Data would add 1.5k to binary size, which is probably competitive to instruction space for an optimized implementation.
> 
> cheers,
> G.
> 
> 
> const char* unsignedCharToFloatString(unsigned char x)
> {
>     return unsignedCharToFloatStrings[x];
> }
> 
> static const char* unsignedCharToFloatStrings[256] = {
>     "0",
>     "0.003",
>     "0.007",
>     "0.01",
>     "0.015",
>     "0.019",
>     "0.023",
>     "0.027",
>     "0.03",
>     "0.035",
>     "0.039",
>     "0.043",
>     "0.047",
>     "0.05",
>     "0.054",
>     "0.058",
>     "0.062",
>     "0.066",
>     "0.07",
>     "0.074",
>     "0.078",
>     "0.082",
>     "0.086",
>     "0.09",
>     "0.094",
>     "0.098",
>     "0.1",
>     "0.105",
>     "0.109",
>     "0.113",
>     "0.117",
>     "0.12",
>     "0.125",
>     "0.129",
>     "0.133",
>     "0.137",
>     "0.14",
>     "0.145",
>     "0.149",
>     "0.152",
>     "0.156",
>     "0.16",
>     "0.164",
>     "0.168",
>     "0.172",
>     "0.176",
>     "0.18",
>     "0.184",
>     "0.188",
>     "0.192",
>     "0.196",
>     "0.2",
>     "0.203",
>     "0.207",
>     "0.21",
>     "0.215",
>     "0.219",
>     "0.223",
>     "0.227",
>     "0.23",
>     "0.235",
>     "0.239",
>     "0.243",
>     "0.247",
>     "0.25",
>     "0.254",
>     "0.258",
>     "0.262",
>     "0.266",
>     "0.27",
>     "0.274",
>     "0.278",
>     "0.282",
>     "0.286",
>     "0.29",
>     "0.294",
>     "0.298",
>     "0.3",
>     "0.305",
>     "0.309",
>     "0.313",
>     "0.317",
>     "0.32",
>     "0.325",
>     "0.329",
>     "0.333",
>     "0.337",
>     "0.34",
>     "0.345",
>     "0.349",
>     "0.352",
>     "0.356",
>     "0.36",
>     "0.364",
>     "0.368",
>     "0.372",
>     "0.376",
>     "0.38",
>     "0.384",
>     "0.388",
>     "0.392",
>     "0.396",
>     "0.4",
>     "0.403",
>     "0.407",
>     "0.41",
>     "0.415",
>     "0.419",
>     "0.423",
>     "0.427",
>     "0.43",
>     "0.435",
>     "0.439",
>     "0.443",
>     "0.447",
>     "0.45",
>     "0.454",
>     "0.458",
>     "0.462",
>     "0.466",
>     "0.47",
>     "0.474",
>     "0.478",
>     "0.482",
>     "0.486",
>     "0.49",
>     "0.494",
>     "0.498",
>     "0.5",
>     "0.505",
>     "0.509",
>     "0.513",
>     "0.517",
>     "0.52",
>     "0.525",
>     "0.529",
>     "0.533",
>     "0.537",
>     "0.54",
>     "0.545",
>     "0.549",
>     "0.552",
>     "0.556",
>     "0.56",
>     "0.564",
>     "0.568",
>     "0.572",
>     "0.576",
>     "0.58",
>     "0.584",
>     "0.588",
>     "0.592",
>     "0.596",
>     "0.6",
>     "0.603",
>     "0.607",
>     "0.61",
>     "0.615",
>     "0.619",
>     "0.623",
>     "0.627",
>     "0.63",
>     "0.635",
>     "0.639",
>     "0.643",
>     "0.647",
>     "0.65",
>     "0.654",
>     "0.658",
>     "0.662",
>     "0.666",
>     "0.67",
>     "0.674",
>     "0.678",
>     "0.682",
>     "0.686",
>     "0.69",
>     "0.694",
>     "0.698",
>     "0.7",
>     "0.705",
>     "0.709",
>     "0.713",
>     "0.717",
>     "0.72",
>     "0.725",
>     "0.729",
>     "0.733",
>     "0.737",
>     "0.74",
>     "0.745",
>     "0.749",
>     "0.752",
>     "0.756",
>     "0.76",
>     "0.764",
>     "0.768",
>     "0.772",
>     "0.776",
>     "0.78",
>     "0.784",
>     "0.788",
>     "0.792",
>     "0.796",
>     "0.8",
>     "0.803",
>     "0.807",
>     "0.81",
>     "0.815",
>     "0.819",
>     "0.823",
>     "0.827",
>     "0.83",
>     "0.835",
>     "0.839",
>     "0.843",
>     "0.847",
>     "0.85",
>     "0.854",
>     "0.858",
>     "0.862",
>     "0.866",
>     "0.87",
>     "0.874",
>     "0.878",
>     "0.882",
>     "0.886",
>     "0.89",
>     "0.894",
>     "0.898",
>     "0.9",
>     "0.905",
>     "0.909",
>     "0.913",
>     "0.917",
>     "0.92",
>     "0.925",
>     "0.929",
>     "0.933",
>     "0.937",
>     "0.94",
>     "0.945",
>     "0.949",
>     "0.952",
>     "0.956",
>     "0.96",
>     "0.964",
>     "0.968",
>     "0.972",
>     "0.976",
>     "0.98",
>     "0.984",
>     "0.988",
>     "0.992",
>     "0.996",
>     "1",
> };
> 
> const char* unsignedCharToFloatStringSingleIndirection(unsigned char x)
> {
>     return &"\x30\x00\x00\x00\x00\x00\x30\x2E\x30\x30\x33\x00\x30\x2E\x30\x30\x37\x00\x30\x2E\x30\x31\x00\x00\x30\x2E\x30\x31\x35\x00\x30\x2E\x30\x31\x39\x00\x30\x2E\x30\x32\x33\x00\x30\x2E\x30\x32\x37\x00\x30\x2E\x30\x33\x00\x00\x30\x2E\x30\x33\x35\x00\x30\x2E\x30\x33\x39\x00\x30\x2E\x30\x34\x33\x00\x30\x2E\x30\x34\x37\x00\x30\x2E\x30\x35\x00\x00\x30\x2E\x30\x35\x34\x00\x30\x2E\x30\x35\x38\x00\x30\x2E\x30\x36\x32\x00\x30\x2E\x30\x36\x36\x00\x30\x2E\x30\x37\x00\x00\x30\x2E\x30\x37\x34\x00\x30\x2E\x30\x37\x38\x00\x30\x2E\x30\x38\x32\x00\x30\x2E\x30\x38\x36\x00\x30\x2E\x30\x39\x00\x00\x30\x2E\x30\x39\x34\x00\x30\x2E\x30\x39\x38\x00\x30\x2E\x31\x00\x00\x00\x30\x2E\x31\x30\x35\x00\x30\x2E\x31\x30\x39\x00\x30\x2E\x31\x31\x33\x00\x30\x2E\x31\x31\x37\x00\x30\x2E\x31\x32\x00\x00\x30\x2E\x31\x32\x35\x00\x30\x2E\x31\x32\x39\x00\x30\x2E\x31\x33\x33\x00\x30\x2E\x31\x33\x37\x00\x30\x2E\x31\x34\x00\x00\x30\x2E\x31\x34\x35\x00\x30\x2E\x31\x34\x39\x00\x30\x2E\x31\x35\x32\x00\x30\x2E\x31\x35\x36\x00\x30\x2E\x31\x36\x00\x00\x30\x2E\x31\x36\x34\x00\x30\x2E\x31\x36\x38\x00\x30\x2E\x31\x37\x32\x00\x30\x2E\x31\x37\x36\x00\x30\x2E\x31\x38\x00\x00\x30\x2E\x31\x38\x34\x00\x30\x2E\x31\x38\x38\x00\x30\x2E\x31\x39\x32\x00\x30\x2E\x31\x39\x36\x00\x30\x2E\x32\x00\x00\x00\x30\x2E\x32\x30\x33\x00\x30\x2E\x32\x30\x37\x00\x30\x2E\x32\x31\x00\x00\x30\x2E\x32\x31\x35\x00\x30\x2E\x32\x31\x39\x00\x30\x2E\x32\x32\x33\x00\x30\x2E\x32\x32\x37\x00\x30\x2E\x32\x33\x00\x00\x30\x2E\x32\x33\x35\x00\x30\x2E\x32\x33\x39\x00\x30\x2E\x32\x34\x33\x00\x30\x2E\x32\x34\x37\x00\x30\x2E\x32\x35\x00\x00\x30\x2E\x32\x35\x34\x00\x30\x2E\x32\x35\x38\x00\x30\x2E\x32\x36\x32\x00\x30\x2E\x32\x36\x36\x00\x30\x2E\x32\x37\x00\x00\x30\x2E\x32\x37\x34\x00\x30\x2E\x32\x37\x38\x00\x30\x2E\x32\x38\x32\x00\x30\x2E\x32\x38\x36\x00\x30\x2E\x32\x39\x00\x00\x30\x2E\x32\x39\x34\x00\x30\x2E\x32\x39\x38\x00\x30\x2E\x33\x00\x00\x00\x30\x2E\x33\x30\x35\x00\x30\x2E\x33\x30\x39\x00\x30\x2E\x33\x31\x33\x00\x30\x2E\x33\x31\x37\x00\x30\x2E\x33\x32\x00\x00\x30\x2E\x33\x32\x35\x00\x30\x2E\x33\x32\x39\x00\x30\x2E\x33\x33\x33\x00\x30\x2E\x33\x33\x37\x00\x30\x2E\x33\x34\x00\x00\x30\x2E\x33\x34\x35\x00\x30\x2E\x33\x34\x39\x00\x30\x2E\x33\x35\x32\x00\x30\x2E\x33\x35\x36\x00\x30\x2E\x33\x36\x00\x00\x30\x2E\x33\x36\x34\x00\x30\x2E\x33\x36\x38\x00\x30\x2E\x33\x37\x32\x00\x30\x2E\x33\x37\x36\x00\x30\x2E\x33\x38\x00\x00\x30\x2E\x33\x38\x34\x00\x30\x2E\x33\x38\x38\x00\x30\x2E\x33\x39\x32\x00\x30\x2E\x33\x39\x36\x00\x30\x2E\x34\x00\x00\x00\x30\x2E\x34\x30\x33\x00\x30\x2E\x34\x30\x37\x00\x30\x2E\x34\x31\x00\x00\x30\x2E\x34\x31\x35\x00\x30\x2E\x34\x31\x39\x00\x30\x2E\x34\x32\x33\x00\x30\x2E\x34\x32\x37\x00\x30\x2E\x34\x33\x00\x00\x30\x2E\x34\x33\x35\x00\x30\x2E\x34\x33\x39\x00\x30\x2E\x34\x34\x33\x00\x30\x2E\x34\x34\x37\x00\x30\x2E\x34\x35\x00\x00\x30\x2E\x34\x35\x34\x00\x30\x2E\x34\x35\x38\x00\x30\x2E\x34\x36\x32\x00\x30\x2E\x34\x36\x36\x00\x30\x2E\x34\x37\x00\x00\x30\x2E\x34\x37\x34\x00\x30\x2E\x34\x37\x38\x00\x30\x2E\x34\x38\x32\x00\x30\x2E\x34\x38\x36\x00\x30\x2E\x34\x39\x00\x00\x30\x2E\x34\x39\x34\x00\x30\x2E\x34\x39\x38\x00\x30\x2E\x35\x00\x00\x00\x30\x2E\x35\x30\x35\x00\x30\x2E\x35\x30\x39\x00\x30\x2E\x35\x31\x33\x00\x30\x2E\x35\x31\x37\x00\x30\x2E\x35\x32\x00\x00\x30\x2E\x35\x32\x35\x00\x30\x2E\x35\x32\x39\x00\x30\x2E\x35\x33\x33\x00\x30\x2E\x35\x33\x37\x00\x30\x2E\x35\x34\x00\x00\x30\x2E\x35\x34\x35\x00\x30\x2E\x35\x34\x39\x00\x30\x2E\x35\x35\x32\x00\x30\x2E\x35\x35\x36\x00\x30\x2E\x35\x36\x00\x00\x30\x2E\x35\x36\x34\x00\x30\x2E\x35\x36\x38\x00\x30\x2E\x35\x37\x32\x00\x30\x2E\x35\x37\x36\x00\x30\x2E\x35\x38\x00\x00\x30\x2E\x35\x38\x34\x00\x30\x2E\x35\x38\x38\x00\x30\x2E\x35\x39\x32\x00\x30\x2E\x35\x39\x36\x00\x30\x2E\x36\x00\x00\x00\x30\x2E\x36\x30\x33\x00\x30\x2E\x36\x30\x37\x00\x30\x2E\x36\x31\x00\x00\x30\x2E\x36\x31\x35\x00\x30\x2E\x36\x31\x39\x00\x30\x2E\x36\x32\x33\x00\x30\x2E\x36\x32\x37\x00\x30\x2E\x36\x33\x00\x00\x30\x2E\x36\x33\x35\x00\x30\x2E\x36\x33\x39\x00\x30\x2E\x36\x34\x33\x00\x30\x2E\x36\x34\x37\x00\x30\x2E\x36\x35\x00\x00\x30\x2E\x36\x35\x34\x00\x30\x2E\x36\x35\x38\x00\x30\x2E\x36\x36\x32\x00\x30\x2E\x36\x36\x36\x00\x30\x2E\x36\x37\x00\x00\x30\x2E\x36\x37\x34\x00\x30\x2E\x36\x37\x38\x00\x30\x2E\x36\x38\x32\x00\x30\x2E\x36\x38\x36\x00\x30\x2E\x36\x39\x00\x00\x30\x2E\x36\x39\x34\x00\x30\x2E\x36\x39\x38\x00\x30\x2E\x37\x00\x00\x00\x30\x2E\x37\x30\x35\x00\x30\x2E\x37\x30\x39\x00\x30\x2E\x37\x31\x33\x00\x30\x2E\x37\x31\x37\x00\x30\x2E\x37\x32\x00\x00\x30\x2E\x37\x32\x35\x00\x30\x2E\x37\x32\x39\x00\x30\x2E\x37\x33\x33\x00\x30\x2E\x37\x33\x37\x00\x30\x2E\x37\x34\x00\x00\x30\x2E\x37\x34\x35\x00\x30\x2E\x37\x34\x39\x00\x30\x2E\x37\x35\x32\x00\x30\x2E\x37\x35\x36\x00\x30\x2E\x37\x36\x00\x00\x30\x2E\x37\x36\x34\x00\x30\x2E\x37\x36\x38\x00\x30\x2E\x37\x37\x32\x00\x30\x2E\x37\x37\x36\x00\x30\x2E\x37\x38\x00\x00\x30\x2E\x37\x38\x34\x00\x30\x2E\x37\x38\x38\x00\x30\x2E\x37\x39\x32\x00\x30\x2E\x37\x39\x36\x00\x30\x2E\x38\x00\x00\x00\x30\x2E\x38\x30\x33\x00\x30\x2E\x38\x30\x37\x00\x30\x2E\x38\x31\x00\x00\x30\x2E\x38\x31\x35\x00\x30\x2E\x38\x31\x39\x00\x30\x2E\x38\x32\x33\x00\x30\x2E\x38\x32\x37\x00\x30\x2E\x38\x33\x00\x00\x30\x2E\x38\x33\x35\x00\x30\x2E\x38\x33\x39\x00\x30\x2E\x38\x34\x33\x00\x30\x2E\x38\x34\x37\x00\x30\x2E\x38\x35\x00\x00\x30\x2E\x38\x35\x34\x00\x30\x2E\x38\x35\x38\x00\x30\x2E\x38\x36\x32\x00\x30\x2E\x38\x36\x36\x00\x30\x2E\x38\x37\x00\x00\x30\x2E\x38\x37\x34\x00\x30\x2E\x38\x37\x38\x00\x30\x2E\x38\x38\x32\x00\x30\x2E\x38\x38\x36\x00\x30\x2E\x38\x39\x00\x00\x30\x2E\x38\x39\x34\x00\x30\x2E\x38\x39\x38\x00\x30\x2E\x39\x00\x00\x00\x30\x2E\x39\x30\x35\x00\x30\x2E\x39\x30\x39\x00\x30\x2E\x39\x31\x33\x00\x30\x2E\x39\x31\x37\x00\x30\x2E\x39\x32\x00\x00\x30\x2E\x39\x32\x35\x00\x30\x2E\x39\x32\x39\x00\x30\x2E\x39\x33\x33\x00\x30\x2E\x39\x33\x37\x00\x30\x2E\x39\x34\x00\x00\x30\x2E\x39\x34\x35\x00\x30\x2E\x39\x34\x39\x00\x30\x2E\x39\x35\x32\x00\x30\x2E\x39\x35\x36\x00\x30\x2E\x39\x36\x00\x00\x30\x2E\x39\x36\x34\x00\x30\x2E\x39\x36\x38\x00\x30\x2E\x39\x37\x32\x00\x30\x2E\x39\x37\x36\x00\x30\x2E\x39\x38\x00\x00\x30\x2E\x39\x38\x34\x00\x30\x2E\x39\x38\x38\x00\x30\x2E\x39\x39\x32\x00\x30\x2E\x39\x39\x36\x00\x31"[(ptrdiff_t)x * 6];
> }
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20151103/4f277978/attachment.html>


More information about the webkit-dev mailing list