From 3eb32cf75051f79060e576ab413ec35e9d05f633 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Thu, 25 Jul 2024 19:08:11 +0800 Subject: [PATCH] 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: --- .../cogl/conform/test-offscreen-texture-formats.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/tests/cogl/conform/test-offscreen-texture-formats.c b/src/tests/cogl/conform/test-offscreen-texture-formats.c index 23eee3538..ba2d804c1 100644 --- a/src/tests/cogl/conform/test-offscreen-texture-formats.c +++ b/src/tests/cogl/conform/test-offscreen-texture-formats.c @@ -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