cogl/tests: Avoid floats when converting between int formats
All we need is an intermediate int format with twice as many bits and to put division at the end to avoid any loss of precision. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3903>
This commit is contained in:
parent
7df6b5c4ed
commit
3eb32cf750
1 changed files with 2 additions and 8 deletions
|
@ -35,19 +35,13 @@ get_bits (uint32_t in,
|
|||
static int
|
||||
rgb16_to_rgb8 (int rgb16)
|
||||
{
|
||||
float r;
|
||||
|
||||
r = rgb16 / (float) ((1 << 16) - 1);
|
||||
return (int) (r * (float) ((1 << 8) - 1));
|
||||
return (int) ((int32_t) rgb16 * 0xff / 0xffff);
|
||||
}
|
||||
|
||||
static int
|
||||
rgb8_to_rgb16 (int rgb8)
|
||||
{
|
||||
float r;
|
||||
|
||||
r = rgb8 / (float) ((1 << 8) - 1);
|
||||
return (int) (r * (float) ((1 << 16) - 1));
|
||||
return (int) ((int32_t) rgb8 * 0xffff / 0xff);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Add table
Reference in a new issue