From e9a41f56c0a8bc2fa256b24352598689425bdbe7 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 19 Apr 2019 20:25:31 -0700 Subject: Added ColorConversion.h/cpp --- Graphics/GraphicsTools/src/GraphicsUtilities.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'Graphics/GraphicsTools') diff --git a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp index 29837ec3..f1f85aa6 100644 --- a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp +++ b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp @@ -22,11 +22,13 @@ */ #include "pch.h" +#include +#include + #include "GraphicsUtilities.h" #include "DebugUtilities.h" #include "GraphicsAccessories.h" -#include -#include +#include "ColorConversion.h" #define PI_F 3.1415926f @@ -64,16 +66,6 @@ void GenerateCheckerBoardPatternInternal(Uint32 Width, Uint32 Height, TEXTURE_FO } } -static float LinearToSRGB(float x) -{ - // This is exactly the sRGB curve - //return x < 0.0031308 ? 12.92 * x : 1.055 * pow(std::abs(x), 1.0 / 2.4) - 0.055; - - // This is cheaper but nearly equivalent - return x < 0.0031308f ? 12.92f * x : 1.13005f * sqrtf(std::abs(x - 0.00228f)) - 0.13448f * x + 0.005719f; -} - - void GenerateCheckerBoardPattern(Uint32 Width, Uint32 Height, TEXTURE_FORMAT Fmt, Uint32 HorzCells, Uint32 VertCells, Uint8 *pData, Uint32 StrideInBytes) { const auto& FmtAttribs = GetTextureFormatAttribs(Fmt); @@ -94,7 +86,7 @@ void GenerateCheckerBoardPattern(Uint32 Width, Uint32 Height, TEXTURE_FORMAT Fmt GenerateCheckerBoardPatternInternal(Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes, [](Uint8 *pDstTexel, Uint32 NumComponents, float fVal) { - Uint8 uVal = static_cast( LinearToSRGB(fVal) * 255.f); + Uint8 uVal = static_cast( FastLinearToSRGB(fVal) * 255.f); for (Uint32 c = 0; c < NumComponents; ++c) pDstTexel[c] = uVal; }); -- cgit v1.2.3