Skip to content

Commit

Permalink
map +inf of hdr intent half fp values to max instead of zero
Browse files Browse the repository at this point in the history
Test: ./ultrahdr_app
  • Loading branch information
ram-mohan authored and DichenZhang1 committed Nov 15, 2024
1 parent 1766f18 commit 6143f22
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/include/ultrahdr/gainmapmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,18 @@ static inline Color clampPixelFloatLinear(Color e) {
return {{{clampPixelFloatLinear(e.r), clampPixelFloatLinear(e.g), clampPixelFloatLinear(e.b)}}};
}

static float mapNonFiniteFloats(float val) {
if (std::isinf(val)) {
return val > 0 ? kMaxPixelFloatHdrLinear : 0.0f;
}
// nan
return 0.0f;
}

static inline Color sanitizePixel(Color e) {
float r = std::isfinite(e.r) ? clampPixelFloatLinear(e.r) : 0.0f;
float g = std::isfinite(e.g) ? clampPixelFloatLinear(e.g) : 0.0f;
float b = std::isfinite(e.b) ? clampPixelFloatLinear(e.b) : 0.0f;
float r = std::isfinite(e.r) ? clampPixelFloatLinear(e.r) : mapNonFiniteFloats(e.r);
float g = std::isfinite(e.g) ? clampPixelFloatLinear(e.g) : mapNonFiniteFloats(e.g);
float b = std::isfinite(e.b) ? clampPixelFloatLinear(e.b) : mapNonFiniteFloats(e.b);
return {{{r, g, b}}};
}

Expand Down

0 comments on commit 6143f22

Please sign in to comment.