mirror of
https://github.com/opencv/opencv.git
synced 2025-07-21 19:47:02 +08:00
Use NaN-safe clip function.
This is to prevent more NaN to int conversions like in #21111.
This commit is contained in:
parent
2329cbc1a2
commit
3da17c42a4
@ -2979,9 +2979,9 @@ struct RGB2Luvfloat
|
|||||||
for( ; i < n; i++, src += scn, dst += 3 )
|
for( ; i < n; i++, src += scn, dst += 3 )
|
||||||
{
|
{
|
||||||
float R = src[0], G = src[1], B = src[2];
|
float R = src[0], G = src[1], B = src[2];
|
||||||
R = std::min(std::max(R, 0.f), 1.f);
|
R = clip(R);
|
||||||
G = std::min(std::max(G, 0.f), 1.f);
|
G = clip(G);
|
||||||
B = std::min(std::max(B, 0.f), 1.f);
|
B = clip(B);
|
||||||
if( gammaTab )
|
if( gammaTab )
|
||||||
{
|
{
|
||||||
R = splineInterpolate(R*gscale, gammaTab, GAMMA_TAB_SIZE);
|
R = splineInterpolate(R*gscale, gammaTab, GAMMA_TAB_SIZE);
|
||||||
@ -3205,9 +3205,9 @@ struct Luv2RGBfloat
|
|||||||
float G = X*C3 + Y*C4 + Z*C5;
|
float G = X*C3 + Y*C4 + Z*C5;
|
||||||
float B = X*C6 + Y*C7 + Z*C8;
|
float B = X*C6 + Y*C7 + Z*C8;
|
||||||
|
|
||||||
R = std::min(std::max(R, 0.f), 1.f);
|
R = clip(R);
|
||||||
G = std::min(std::max(G, 0.f), 1.f);
|
G = clip(G);
|
||||||
B = std::min(std::max(B, 0.f), 1.f);
|
B = clip(B);
|
||||||
|
|
||||||
if( gammaTab )
|
if( gammaTab )
|
||||||
{
|
{
|
||||||
|
@ -3203,6 +3203,8 @@ TEST(ImgProc_RGB2Lab, NaN_21111)
|
|||||||
src(0, 1) = src(0, 28) = src(0, 82) = src(0, 109) = cv::Vec3f(0, kNaN, 0);
|
src(0, 1) = src(0, 28) = src(0, 82) = src(0, 109) = cv::Vec3f(0, kNaN, 0);
|
||||||
src(0, 2) = src(0, 29) = src(0, 83) = src(0, 110) = cv::Vec3f(kNaN, 0, 0);
|
src(0, 2) = src(0, 29) = src(0, 83) = src(0, 110) = cv::Vec3f(kNaN, 0, 0);
|
||||||
EXPECT_NO_THROW(cvtColor(src, dst, COLOR_RGB2Lab));
|
EXPECT_NO_THROW(cvtColor(src, dst, COLOR_RGB2Lab));
|
||||||
|
EXPECT_NO_THROW(cvtColor(src, dst, COLOR_RGB2Luv));
|
||||||
|
EXPECT_NO_THROW(cvtColor(src, dst, COLOR_Luv2RGB));
|
||||||
|
|
||||||
#if 0 // no NaN propagation guarantee
|
#if 0 // no NaN propagation guarantee
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
|
Loading…
Reference in New Issue
Block a user