diff options
author | Neil Roberts <[email protected]> | 2015-01-14 15:14:05 +0000 |
---|---|---|
committer | Neil Roberts <[email protected]> | 2015-01-16 13:53:15 +0000 |
commit | a4ab08bf451593dc45ebef80da66563b0ba5bbe5 (patch) | |
tree | ec81c550ae8b1b0c9a0b5fa06060bd690affdf01 /src/mesa/swrast_setup | |
parent | 6367ca8b41ce99de21a27953713413d678e5d30d (diff) |
format_utils: Use a more precise conversion when decreasing bits
When converting to a format that has fewer bits the previous code was just
shifting off the bits. This doesn't provide very accurate results. For example
when converting from 8 bits to 5 bits it is equivalent to doing this:
x * 32 / 256
This works as if it's taking a value from a range where 256 represents 1.0 and
scaling it down to a range where 32 represents 1.0. However this is not
correct because it is actually 255 and 31 that represent 1.0.
We can do better with a formula like this:
(x * 31 + 127) / 255
The +127 is to make it round correctly.
The new code has a special case to use uint64_t when the result of the
multiplication would overflow an unsigned int. This function is inline and
only ever called with constant values so hopefully the if statements will be
folded.
The main incentive to do this is to make the CPU conversion path pick the same
values as the hardware would if it did the conversion. This fixes failures
with the ‘texsubimage pbo’ test when using the patches from here:
http://lists.freedesktop.org/archives/mesa-dev/2015-January/074312.html
v2: Use 64-bit arithmetic when src_bits+dst_bits > 32
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/mesa/swrast_setup')
0 files changed, 0 insertions, 0 deletions