Skip to content

Commit

Permalink
[Math] Fix Nan from powf() domain error.
Browse files Browse the repository at this point in the history
This change prevents calling powf(x,y) with negative x.

The SIMD versions using ssePower() already seem to be resistent to
negative pixel values, but the scalar version was not.

This would cause a SIGFPE on apps that have floating point exceptions
enabled.

FIXES: #2066

Signed-off-by: Bram Stolk <[email protected]>
  • Loading branch information
stolk committed Sep 30, 2024
1 parent 4dd0273 commit 03d245d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/OpenColorIO/ops/gamma/GammaOpCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ void GammaMoncurveOpCPUFwd::apply(const void * inImg, void * outImg, long numPix

for(long idx=0; idx<numPixels; ++idx)
{
const float pixel[4] = { in[0], in[1], in[2], in[3] };
const float pixel[4] = { std::max(0.0f, in[0]),
std::max(0.0f, in[1]),
std::max(0.0f, in[2]),
std::max(0.0f, in[3]) };

const float data[4] = { std::pow(pixel[0] * red[0] + red[1], red[2]),
std::pow(pixel[1] * grn[0] + grn[1], grn[2]),
Expand Down Expand Up @@ -627,7 +630,10 @@ void GammaMoncurveOpCPURev::apply(const void * inImg, void * outImg, long numPix

for(long idx=0; idx<numPixels; ++idx)
{
const float pixel[4] = { in[0], in[1], in[2], in[3] };
const float pixel[4] = { std::max(0.0f, in[0]),
std::max(0.0f, in[1]),
std::max(0.0f, in[2]),
std::max(0.0f, in[3]) };

const float data[4] = { std::pow(pixel[0], red[0]) * red[1] - red[2],
std::pow(pixel[1], grn[0]) * grn[1] - grn[2],
Expand Down

0 comments on commit 03d245d

Please sign in to comment.