Skip to content

Commit 03d245d

Browse files
committed
[Math] Fix Nan from powf() domain error.
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]>
1 parent 4dd0273 commit 03d245d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/OpenColorIO/ops/gamma/GammaOpCPU.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ void GammaMoncurveOpCPUFwd::apply(const void * inImg, void * outImg, long numPix
538538

539539
for(long idx=0; idx<numPixels; ++idx)
540540
{
541-
const float pixel[4] = { in[0], in[1], in[2], in[3] };
541+
const float pixel[4] = { std::max(0.0f, in[0]),
542+
std::max(0.0f, in[1]),
543+
std::max(0.0f, in[2]),
544+
std::max(0.0f, in[3]) };
542545

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

628631
for(long idx=0; idx<numPixels; ++idx)
629632
{
630-
const float pixel[4] = { in[0], in[1], in[2], in[3] };
633+
const float pixel[4] = { std::max(0.0f, in[0]),
634+
std::max(0.0f, in[1]),
635+
std::max(0.0f, in[2]),
636+
std::max(0.0f, in[3]) };
631637

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

0 commit comments

Comments
 (0)