From d4741eece17480b4744ee423003a25b5c20f38a0 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Mon, 15 Nov 2021 13:09:02 +0100 Subject: [PATCH] Fix H clamping for very small negative values. In case of very small negative h (e.g. -1e-40), with the current implementation, you will go through the first condition and end up with h = 6.f, and will miss the second condition. --- modules/imgproc/src/color_hsv.simd.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/imgproc/src/color_hsv.simd.hpp b/modules/imgproc/src/color_hsv.simd.hpp index 7501f4b113..b1eb50d7a4 100644 --- a/modules/imgproc/src/color_hsv.simd.hpp +++ b/modules/imgproc/src/color_hsv.simd.hpp @@ -955,12 +955,11 @@ struct HLS2RGB_f float p1 = 2*l - p2; h *= hscale; - if( h < 0 ) - do h += 6; while( h < 0 ); - else if( h >= 6 ) - do h -= 6; while( h >= 6 ); + // We need both loops to clamp (e.g. for h == -1e-40). + while( h < 0 ) h += 6; + while( h >= 6 ) h -= 6; - assert( 0 <= h && h < 6 ); + CV_DbgAssert( 0 <= h && h < 6 ); sector = cvFloor(h); h -= sector; -- GitLab