diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-11-29 18:56:53 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-11-29 18:56:53 +0000 |
| commit | 80e44f29d72cdbcacc991b95ed40dc4e57b3b945 (patch) | |
| tree | 726417b01a1eac70b38c7db3da5b671b6bad5208 | |
| parent | Minor update to SRGBAverage helper function (diff) | |
| download | DiligentCore-80e44f29d72cdbcacc991b95ed40dc4e57b3b945.tar.gz DiligentCore-80e44f29d72cdbcacc991b95ed40dc4e57b3b945.zip | |
Another minor update to SRGBAverage
| -rw-r--r-- | Graphics/GraphicsTools/src/GraphicsUtilities.cpp | 3 | ||||
| -rw-r--r-- | Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsUtilitiesTest.cpp | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp index 93e188fd..664749b2 100644 --- a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp +++ b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp @@ -149,7 +149,8 @@ ChannelType SRGBAverage(ChannelType c0, ChannelType c1, ChannelType c2, ChannelT float fLinearAverage = (FastSRGBToLinear(fc0) + FastSRGBToLinear(fc1) + FastSRGBToLinear(fc2) + FastSRGBToLinear(fc3)) * 0.25f; float fSRGBAverage = FastLinearToSRGB(fLinearAverage) * MaxVal; - // Clamping by MaxVal is essential because fast SRGB math is imprecise + // Clamping on both ends is essential because fast SRGB math is imprecise + fSRGBAverage = std::max(fSRGBAverage, 0.f); fSRGBAverage = std::min(fSRGBAverage, MaxVal); return static_cast<ChannelType>(fSRGBAverage); diff --git a/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsUtilitiesTest.cpp b/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsUtilitiesTest.cpp index 50b4cb47..1aabca1c 100644 --- a/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsUtilitiesTest.cpp +++ b/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsUtilitiesTest.cpp @@ -488,7 +488,8 @@ TEST(GraphicsTools_CalculateMipLevel, sRGB) FastSRGBToLinear(FineData[((x * 2 + 0) + (y * 2 + 1) * FineWidth) * NumChannels + c] / 255.f) + FastSRGBToLinear(FineData[((x * 2 + 1) + (y * 2 + 1) * FineWidth) * NumChannels + c] / 255.f)) * 0.25f; - float fSRGB = FastLinearToSRGB(fLinearAverage); + fLinearAverage = std::min(std::max(fLinearAverage, 0.f), 255.f); + float fSRGB = FastLinearToSRGB(fLinearAverage); RefCoarseData[(x + y * CoarseWidth) * NumChannels + c] = static_cast<Uint8>(fSRGB * 255.f); } |
