From d79e4c182e040d079629a950bd65f70d930fa997 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 12 Jul 2023 18:03:08 +0200 Subject: [PATCH] cogl/tests: Fix float->int, int->float conversions To obtain a float between 0 and 1 we have to devide the integer by the highest possible value instead of the number of values. Fixes off by one errors in the tests on some hardware/driver combinations. Part-of: --- .../conform/test-offscreen-texture-formats.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tests/cogl/conform/test-offscreen-texture-formats.c b/src/tests/cogl/conform/test-offscreen-texture-formats.c index 4e13feaf4..093eea01e 100644 --- a/src/tests/cogl/conform/test-offscreen-texture-formats.c +++ b/src/tests/cogl/conform/test-offscreen-texture-formats.c @@ -36,8 +36,8 @@ rgb10_to_rgb8 (int rgb10) { float r; - r = rgb10 / (float) (1 << 10); - return (int) (r * (float) (1 << 8)); + r = rgb10 / (float) ((1 << 10) - 1); + return (int) (r * (float) ((1 << 8) - 1)); } static int @@ -45,8 +45,8 @@ rgb8_to_rgb10 (int rgb8) { float r; - r = rgb8 / (float) (1 << 8); - return (int) (r * (float) (1 << 10)); + r = rgb8 / (float) ((1 << 8) - 1); + return (int) (r * (float) ((1 << 10) - 1)); } static void @@ -73,10 +73,10 @@ test_offscreen_texture_formats_store_rgb10 (void) /* The extra fraction is there to avoid rounding inconsistencies in OpenGL * implementations. */ - red = (rgb10_red / (float) (1 << 10)) + 0.00001; - green = (rgb10_green / (float) (1 << 10)) + 0.00001; - blue = (rgb10_blue / (float) (1 << 10)) + 0.00001; - alpha = (rgb10_alpha / (float) (1 << 2)) + 0.00001; + red = (rgb10_red / (float) ((1 << 10) - 1)) + 0.00001; + green = (rgb10_green / (float) ((1 << 10) - 1)) + 0.00001; + blue = (rgb10_blue / (float) ((1 << 10) - 1)) + 0.00001; + alpha = (rgb10_alpha / (float) ((1 << 2) - 1)) + 0.00001; /* Make sure that that the color value can't be represented using rgb8. */ g_assert_cmpint (rgb8_to_rgb10 (rgb10_to_rgb8 (rgb10_red)), !=, rgb10_red); @@ -304,10 +304,10 @@ test_offscreen_texture_formats_paint_rgb10 (void) /* The extra fraction is there to avoid rounding inconsistencies in OpenGL * implementations. */ - red = (rgb10_red / (float) (1 << 10)) + 0.00001; - green = (rgb10_green / (float) (1 << 10)) + 0.00001; - blue = (rgb10_blue / (float) (1 << 10)) + 0.00001; - alpha = (rgb10_alpha / (float) (1 << 2)) + 0.00001; + red = (rgb10_red / (float) ((1 << 10 ) - 1)) + 0.00001; + green = (rgb10_green / (float) ((1 << 10) - 1)) + 0.00001; + blue = (rgb10_blue / (float) ((1 << 10) - 1)) + 0.00001; + alpha = (rgb10_alpha / (float) ((1 << 2) - 1)) + 0.00001; /* Make sure that that the color value can't be represented using rgb8. */ g_assert_cmpint (rgb8_to_rgb10 (rgb10_to_rgb8 (rgb10_red)), !=, rgb10_red);