From 8cf29ebc25e983e13eb8261204615849a674b56d Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Mon, 14 Feb 2022 11:10:58 -0600 Subject: [PATCH 1/3] Added support for several UNORM_SRGB formats Signed-off-by: Chris Galvan --- .../ReflectedPropertyCtrl.cpp | 12 ----- .../ReflectedPropertyItem.cpp | 3 -- .../ReflectedVarWrapper.cpp | 44 ------------------ .../ReflectedVarWrapper.h | 15 ------ Code/Editor/Util/ColorUtils.cpp | 46 ------------------- Code/Editor/Util/EditorUtils.cpp | 13 +++--- Code/Editor/editor_core_files.cmake | 1 - Code/Framework/AzCore/AzCore/Math/Color.h | 6 +++ Code/Framework/AzCore/AzCore/Math/Color.inl | 21 ++++++--- .../Code/Source/Converters/Gamma.cpp | 16 ++----- .../RPI/Code/Source/RPI.Public/RPIUtils.cpp | 17 +++++++ .../Editor/Animation/Util/UiEditorUtils.cpp | 14 +++--- 12 files changed, 56 insertions(+), 152 deletions(-) delete mode 100644 Code/Editor/Util/ColorUtils.cpp diff --git a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp index c5bf6a4d81..dd32b96b2c 100644 --- a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp +++ b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.cpp @@ -360,18 +360,6 @@ void ReflectedPropertyControl::CreateItems(XmlNodeRef node, CVarBlockPtr& outBlo textureVar->Set(textureName); } } - else if (!azstricmp(type, "color")) - { - CSmartVariable colorVar; - AddVariable(group, colorVar, child->getTag(), humanReadableName.toUtf8().data(), strDescription.toUtf8().data(), func, pUserData, IVariable::DT_COLOR); - ColorB color; - if (child->getAttr("value", color)) - { - ColorF colorLinear = ColorGammaToLinear(QColor(color.r, color.g, color.b)); - Vec3 colorVec3(colorLinear.r, colorLinear.g, colorLinear.b); - colorVar->Set(colorVec3); - } - } } } diff --git a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp index 0fcbac3204..b56a3e411d 100644 --- a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp +++ b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp @@ -243,9 +243,6 @@ void ReflectedPropertyItem::SetVariable(IVariable *var) case ePropertySelection: m_reflectedVarAdapter = new ReflectedVarEnumAdapter; break; - case ePropertyColor: - m_reflectedVarAdapter = new ReflectedVarColorAdapter; - break; case ePropertyUser: m_reflectedVarAdapter = new ReflectedVarUserAdapter; break; diff --git a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp index 8eefbbc8eb..1e8d42acc0 100644 --- a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp +++ b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.cpp @@ -312,50 +312,6 @@ void ReflectedVarVector4Adapter::SyncIVarToReflectedVar(IVariable *pVariable) pVariable->Set(Vec4(m_reflectedVar->m_value.GetX(), m_reflectedVar->m_value.GetY(), m_reflectedVar->m_value.GetZ(), m_reflectedVar->m_value.GetW())); } - -void ReflectedVarColorAdapter::SetVariable(IVariable *pVariable) -{ - m_reflectedVar.reset(new CReflectedVarColor(pVariable->GetHumanName().toUtf8().data())); - m_reflectedVar->m_description = pVariable->GetDescription().toUtf8().data(); -} - -void ReflectedVarColorAdapter::SyncReflectedVarToIVar(IVariable *pVariable) -{ - if (pVariable->GetType() == IVariable::VECTOR) - { - Vec3 v(0, 0, 0); - pVariable->Get(v); - const QColor col = ColorLinearToGamma(ColorF(v.x, v.y, v.z)); - m_reflectedVar->m_color.Set(static_cast(col.redF()), static_cast(col.greenF()), static_cast(col.blueF())); - } - else - { - int col(0); - pVariable->Get(col); - const QColor qcolor = ColorToQColor((uint32)col); - m_reflectedVar->m_color.Set(static_cast(qcolor.redF()), static_cast(qcolor.greenF()), static_cast(qcolor.blueF())); - } -} - -void ReflectedVarColorAdapter::SyncIVarToReflectedVar(IVariable *pVariable) -{ - if (pVariable->GetType() == IVariable::VECTOR) - { - ColorF colLin = ColorGammaToLinear(QColor::fromRgbF(m_reflectedVar->m_color.GetX(), m_reflectedVar->m_color.GetY(), m_reflectedVar->m_color.GetZ())); - pVariable->Set(Vec3(colLin.r, colLin.g, colLin.b)); - } - else - { - int ir = static_cast(m_reflectedVar->m_color.GetX() * 255.0f); - int ig = static_cast(m_reflectedVar->m_color.GetY() * 255.0f); - int ib = static_cast(m_reflectedVar->m_color.GetZ() * 255.0f); - - pVariable->Set(static_cast(RGB(ir, ig, ib))); - } -} - - - void ReflectedVarResourceAdapter::SetVariable(IVariable *pVariable) { m_reflectedVar.reset(new CReflectedVarResource(pVariable->GetHumanName().toUtf8().data())); diff --git a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.h b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.h index 807413226c..4efbab0bab 100644 --- a/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.h +++ b/Code/Editor/Controls/ReflectedPropertyControl/ReflectedVarWrapper.h @@ -186,21 +186,6 @@ AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING }; - -class EDITOR_CORE_API ReflectedVarColorAdapter - : public ReflectedVarAdapter -{ -public: - void SetVariable(IVariable* pVariable) override; - void SyncReflectedVarToIVar(IVariable* pVariable) override; - void SyncIVarToReflectedVar(IVariable* pVariable) override; - CReflectedVar* GetReflectedVar() override { return m_reflectedVar.data(); } -private: -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - QScopedPointer m_reflectedVar; -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -}; - class EDITOR_CORE_API ReflectedVarResourceAdapter : public ReflectedVarAdapter { diff --git a/Code/Editor/Util/ColorUtils.cpp b/Code/Editor/Util/ColorUtils.cpp deleted file mode 100644 index eaaea8a2ef..0000000000 --- a/Code/Editor/Util/ColorUtils.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -// Qt -#include -#include - -////////////////////////////////////////////////////////////////////////// -QColor ColorLinearToGamma(ColorF col) -{ - float r = clamp_tpl(col.r, 0.0f, 1.0f); - float g = clamp_tpl(col.g, 0.0f, 1.0f); - float b = clamp_tpl(col.b, 0.0f, 1.0f); - float a = clamp_tpl(col.a, 0.0f, 1.0f); - - r = (float)(r <= 0.0031308 ? (12.92 * r) : (1.055 * pow((double)r, 1.0 / 2.4) - 0.055)); - g = (float)(g <= 0.0031308 ? (12.92 * g) : (1.055 * pow((double)g, 1.0 / 2.4) - 0.055)); - b = (float)(b <= 0.0031308 ? (12.92 * b) : (1.055 * pow((double)b, 1.0 / 2.4) - 0.055)); - - return QColor(int(r * 255.0f), int(g * 255.0f), int(b * 255.0f), int(a * 255.0f)); -} - -////////////////////////////////////////////////////////////////////////// -ColorF ColorGammaToLinear(const QColor& col) -{ - float r = (float)col.red() / 255.0f; - float g = (float)col.green() / 255.0f; - float b = (float)col.blue() / 255.0f; - float a = (float)col.alpha() / 255.0f; - - return ColorF((float)(r <= 0.04045 ? (r / 12.92) : pow(((double)r + 0.055) / 1.055, 2.4)), - (float)(g <= 0.04045 ? (g / 12.92) : pow(((double)g + 0.055) / 1.055, 2.4)), - (float)(b <= 0.04045 ? (b / 12.92) : pow(((double)b + 0.055) / 1.055, 2.4)), a); -} - -QColor ColorToQColor(uint32 color) -{ - return QColor::fromRgbF((float)GetRValue(color) / 255.0f, - (float)GetGValue(color) / 255.0f, - (float)GetBValue(color) / 255.0f); -} diff --git a/Code/Editor/Util/EditorUtils.cpp b/Code/Editor/Util/EditorUtils.cpp index 47264a51ab..440941e469 100644 --- a/Code/Editor/Util/EditorUtils.cpp +++ b/Code/Editor/Util/EditorUtils.cpp @@ -6,6 +6,7 @@ * */ +#include #include "EditorDefs.h" @@ -184,9 +185,9 @@ QColor ColorLinearToGamma(ColorF col) float b = clamp_tpl(col.b, 0.0f, 1.0f); float a = clamp_tpl(col.a, 0.0f, 1.0f); - r = (float)(r <= 0.0031308 ? (12.92 * r) : (1.055 * pow((double)r, 1.0 / 2.4) - 0.055)); - g = (float)(g <= 0.0031308 ? (12.92 * g) : (1.055 * pow((double)g, 1.0 / 2.4) - 0.055)); - b = (float)(b <= 0.0031308 ? (12.92 * b) : (1.055 * pow((double)b, 1.0 / 2.4) - 0.055)); + r = AZ::Color::ConvertSrgbLinearToGamma(r); + g = AZ::Color::ConvertSrgbLinearToGamma(g); + b = AZ::Color::ConvertSrgbLinearToGamma(b); return QColor(int(r * 255.0f), int(g * 255.0f), int(b * 255.0f), int(a * 255.0f)); } @@ -199,9 +200,9 @@ ColorF ColorGammaToLinear(const QColor& col) float b = (float)col.blue() / 255.0f; float a = (float)col.alpha() / 255.0f; - return ColorF((float)(r <= 0.04045 ? (r / 12.92) : pow(((double)r + 0.055) / 1.055, 2.4)), - (float)(g <= 0.04045 ? (g / 12.92) : pow(((double)g + 0.055) / 1.055, 2.4)), - (float)(b <= 0.04045 ? (b / 12.92) : pow(((double)b + 0.055) / 1.055, 2.4)), a); + return ColorF(AZ::Color::ConvertSrgbGammaToLinear(r), + AZ::Color::ConvertSrgbGammaToLinear(g), + AZ::Color::ConvertSrgbGammaToLinear(b), a); } QColor ColorToQColor(uint32 color) diff --git a/Code/Editor/editor_core_files.cmake b/Code/Editor/editor_core_files.cmake index 447d763a63..15ad0f13a1 100644 --- a/Code/Editor/editor_core_files.cmake +++ b/Code/Editor/editor_core_files.cmake @@ -48,7 +48,6 @@ set(FILES Util/Image.cpp Util/ImageHistogram.h Util/Image.h - Util/ColorUtils.cpp Undo/Undo.cpp Undo/IUndoManagerListener.h Undo/IUndoObject.h diff --git a/Code/Framework/AzCore/AzCore/Math/Color.h b/Code/Framework/AzCore/AzCore/Math/Color.h index 4f506e219d..c0c798fbb9 100644 --- a/Code/Framework/AzCore/AzCore/Math/Color.h +++ b/Code/Framework/AzCore/AzCore/Math/Color.h @@ -134,6 +134,12 @@ namespace AZ //! Color from u32 => 0xAABBGGRR, RGB convert from Gamma corrected to Linear values. void FromU32GammaToLinear(u32 c); + //! Convert SRGB gamma space to linear space + static float ConvertSrgbGammaToLinear(float x); + + //! Convert SRGB linear space to gamma space + static float ConvertSrgbLinearToGamma(float x); + //! Convert color from linear to gamma corrected space. Color LinearToGamma() const; diff --git a/Code/Framework/AzCore/AzCore/Math/Color.inl b/Code/Framework/AzCore/AzCore/Math/Color.inl index c07d0f2d88..f3b691e163 100644 --- a/Code/Framework/AzCore/AzCore/Math/Color.inl +++ b/Code/Framework/AzCore/AzCore/Math/Color.inl @@ -370,6 +370,15 @@ namespace AZ *this = GammaToLinear(); } + AZ_MATH_INLINE float Color::ConvertSrgbGammaToLinear(float x) + { + return x <= 0.04045 ? (x / 12.92f) : static_cast(pow((static_cast(x) + 0.055) / 1.055, 2.4)); + } + + AZ_MATH_INLINE float Color::ConvertSrgbLinearToGamma(float x) + { + return x <= 0.0031308 ? 12.92f * x : static_cast(1.055 * pow(static_cast(x), 1.0 / 2.4) - 0.055); + } AZ_MATH_INLINE Color Color::LinearToGamma() const { @@ -377,9 +386,9 @@ namespace AZ float g = GetG(); float b = GetB(); - r = (r <= 0.0031308 ? 12.92f * r : static_cast(1.055 * pow(static_cast(r), 1.0 / 2.4) - 0.055)); - g = (g <= 0.0031308 ? 12.92f * g : static_cast(1.055 * pow(static_cast(g), 1.0 / 2.4) - 0.055)); - b = (b <= 0.0031308 ? 12.92f * b : static_cast(1.055 * pow(static_cast(b), 1.0 / 2.4) - 0.055)); + r = ConvertSrgbLinearToGamma(r); + g = ConvertSrgbLinearToGamma(g); + b = ConvertSrgbLinearToGamma(b); return Color(r,g,b,GetA()); } @@ -391,9 +400,9 @@ namespace AZ float g = GetG(); float b = GetB(); - return Color(r <= 0.04045 ? (r / 12.92f) : static_cast(pow((static_cast(r) + 0.055) / 1.055, 2.4)), - g <= 0.04045 ? (g / 12.92f) : static_cast(pow((static_cast(g) + 0.055) / 1.055, 2.4)), - b <= 0.04045 ? (b / 12.92f) : static_cast(pow((static_cast(b) + 0.055) / 1.055, 2.4)), GetA()); + return Color(ConvertSrgbGammaToLinear(r), + ConvertSrgbGammaToLinear(g), + ConvertSrgbGammaToLinear(b), GetA()); } diff --git a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Converters/Gamma.cpp b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Converters/Gamma.cpp index e00af4ab88..0e44a22af3 100644 --- a/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Converters/Gamma.cpp +++ b/Gems/Atom/Asset/ImageProcessingAtom/Code/Source/Converters/Gamma.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -118,19 +119,8 @@ namespace ImageProcessingAtom float m_fMaxDiff = 0.0f; }; - - static float GammaToLinear(float x) - { - return (x <= 0.04045f) ? x / 12.92f : powf((x + 0.055f) / 1.055f, 2.4f); - } - - static float LinearToGamma(float x) - { - return (x <= 0.0031308f) ? x * 12.92f : 1.055f * powf(x, 1.0f / 2.4f) - 0.055f; - } - - static FunctionLookupTable<1024> s_lutGammaToLinear(GammaToLinear, 0.04045f, 0.00001f); - static FunctionLookupTable<1024> s_lutLinearToGamma(LinearToGamma, 0.05f, 0.00001f); + static FunctionLookupTable<1024> s_lutGammaToLinear(AZ::Color::ConvertSrgbGammaToLinear, 0.04045f, 0.00001f); + static FunctionLookupTable<1024> s_lutLinearToGamma(AZ::Color::ConvertSrgbLinearToGamma, 0.05f, 0.00001f); /////////////////////////////////////////////////////////////////////////////////// diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp index a92d0e5ee8..5683a3effa 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp @@ -14,6 +14,7 @@ #include #include +#include #include namespace AZ @@ -113,12 +114,22 @@ namespace AZ case AZ::RHI::Format::A8_UNORM: case AZ::RHI::Format::R8G8_UNORM: case AZ::RHI::Format::R8G8B8A8_UNORM: + case AZ::RHI::Format::A8B8G8R8_UNORM: { return mem[index] / static_cast(std::numeric_limits::max()); } + case AZ::RHI::Format::R8_UNORM_SRGB: + case AZ::RHI::Format::R8G8_UNORM_SRGB: + case AZ::RHI::Format::R8G8B8A8_UNORM_SRGB: + case AZ::RHI::Format::A8B8G8R8_UNORM_SRGB: + { + float srgbValue = mem[index] / static_cast(std::numeric_limits::max()); + return AZ::Color::ConvertSrgbGammaToLinear(srgbValue); + } case AZ::RHI::Format::R8_SNORM: case AZ::RHI::Format::R8G8_SNORM: case AZ::RHI::Format::R8G8B8A8_SNORM: + case AZ::RHI::Format::A8B8G8R8_SNORM: { // Scale the value from AZ::s8 min/max to -1 to 1 // We need to treat -128 and -127 the same, so that we get a symmetric @@ -452,9 +463,15 @@ namespace AZ case AZ::RHI::Format::A8_UNORM: case AZ::RHI::Format::R8G8_UNORM: case AZ::RHI::Format::R8G8B8A8_UNORM: + case AZ::RHI::Format::A8B8G8R8_UNORM: + case AZ::RHI::Format::R8_UNORM_SRGB: + case AZ::RHI::Format::R8G8_UNORM_SRGB: + case AZ::RHI::Format::R8G8B8A8_UNORM_SRGB: + case AZ::RHI::Format::A8B8G8R8_UNORM_SRGB: case AZ::RHI::Format::R8_SNORM: case AZ::RHI::Format::R8G8_SNORM: case AZ::RHI::Format::R8G8B8A8_SNORM: + case AZ::RHI::Format::A8B8G8R8_SNORM: case AZ::RHI::Format::D16_UNORM: case AZ::RHI::Format::R16_UNORM: case AZ::RHI::Format::R16G16_UNORM: diff --git a/Gems/LyShine/Code/Editor/Animation/Util/UiEditorUtils.cpp b/Gems/LyShine/Code/Editor/Animation/Util/UiEditorUtils.cpp index 85270df355..fb43e00780 100644 --- a/Gems/LyShine/Code/Editor/Animation/Util/UiEditorUtils.cpp +++ b/Gems/LyShine/Code/Editor/Animation/Util/UiEditorUtils.cpp @@ -9,6 +9,8 @@ //#include "CustomizeKeyboardPage.h" +#include + #include #include @@ -99,9 +101,9 @@ QColor ColorLinearToGamma(ColorF col) float g = clamp_tpl(col.g, 0.0f, 1.0f); float b = clamp_tpl(col.b, 0.0f, 1.0f); - r = (float)(r <= 0.0031308 ? (12.92 * r) : (1.055 * pow((double)r, 1.0 / 2.4) - 0.055)); - g = (float)(g <= 0.0031308 ? (12.92 * g) : (1.055 * pow((double)g, 1.0 / 2.4) - 0.055)); - b = (float)(b <= 0.0031308 ? (12.92 * b) : (1.055 * pow((double)b, 1.0 / 2.4) - 0.055)); + r = AZ::Color::ConvertSrgbLinearToGamma(r); + g = AZ::Color::ConvertSrgbLinearToGamma(g); + b = AZ::Color::ConvertSrgbLinearToGamma(b); return QColor(int(r * 255.0f), int(g * 255.0f), int(b * 255.0f)); } @@ -113,7 +115,7 @@ ColorF ColorGammaToLinear(const QColor& col) float g = (float)col.green() / 255.0f; float b = (float)col.blue() / 255.0f; - return ColorF((float)(r <= 0.04045 ? (r / 12.92) : pow(((double)r + 0.055) / 1.055, 2.4)), - (float)(g <= 0.04045 ? (g / 12.92) : pow(((double)g + 0.055) / 1.055, 2.4)), - (float)(b <= 0.04045 ? (b / 12.92) : pow(((double)b + 0.055) / 1.055, 2.4))); + return ColorF(AZ::Color::ConvertSrgbGammaToLinear(r), + AZ::Color::ConvertSrgbGammaToLinear(g), + AZ::Color::ConvertSrgbGammaToLinear(b)); } From 12d5a304b5e0f593ac2390bdc3113ac1add23cbf Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Tue, 15 Feb 2022 16:47:58 -0600 Subject: [PATCH 2/3] Improved performance of UNORM_SRGB pixel retrieval by switching to a pre-computed lookup table Signed-off-by: Chris Galvan --- .../RPI/Code/Source/RPI.Public/RPIUtils.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp index 5683a3effa..b2d1663857 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp @@ -15,6 +15,7 @@ #include #include +#include #include namespace AZ @@ -106,6 +107,30 @@ namespace AZ return ((value - origMin) / (origMax - origMin)) * (scaledMax - scaledMin) + scaledMin; } + // Pre-compute a lookup table for converting SRGB gamma to linear + // by specifying the AZ::u8 so we don't have to do the computation + // when retrieving pixels + using ConversionLookupTable = AZStd::array; + ConversionLookupTable CreateSrgbGammaToLinearLookupTable() + { + ConversionLookupTable lookupTable; + + for (size_t i = 0; i < lookupTable.array_size; ++i) + { + float srgbValue = i / static_cast(std::numeric_limits::max()); + lookupTable[i] = AZ::Color::ConvertSrgbGammaToLinear(srgbValue); + } + + return lookupTable; + } + + static ConversionLookupTable s_SrgbGammaToLinearLookupTable = CreateSrgbGammaToLinearLookupTable(); + + float ConvertSrgbGammaToLinearUint(AZ::u8 x) + { + return s_SrgbGammaToLinearLookupTable[x]; + } + float RetrieveFloatValue(const AZ::u8* mem, size_t index, AZ::RHI::Format format) { switch (format) @@ -123,8 +148,9 @@ namespace AZ case AZ::RHI::Format::R8G8B8A8_UNORM_SRGB: case AZ::RHI::Format::A8B8G8R8_UNORM_SRGB: { - float srgbValue = mem[index] / static_cast(std::numeric_limits::max()); - return AZ::Color::ConvertSrgbGammaToLinear(srgbValue); + // Use a variant of ConvertSrgbGammaToLinear that takes an AZ::u8 + // and a lookup table instead of a float for better performance + return ConvertSrgbGammaToLinearUint(mem[index]); } case AZ::RHI::Format::R8_SNORM: case AZ::RHI::Format::R8G8_SNORM: From 9a32d433f47871a30d00e26deef3620f722dc9a8 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Tue, 15 Feb 2022 17:29:53 -0600 Subject: [PATCH 3/3] Changed to use the lookup table directly than have a helper method Signed-off-by: Chris Galvan --- Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp index b2d1663857..b1ae2d5698 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp @@ -126,11 +126,6 @@ namespace AZ static ConversionLookupTable s_SrgbGammaToLinearLookupTable = CreateSrgbGammaToLinearLookupTable(); - float ConvertSrgbGammaToLinearUint(AZ::u8 x) - { - return s_SrgbGammaToLinearLookupTable[x]; - } - float RetrieveFloatValue(const AZ::u8* mem, size_t index, AZ::RHI::Format format) { switch (format) @@ -148,9 +143,9 @@ namespace AZ case AZ::RHI::Format::R8G8B8A8_UNORM_SRGB: case AZ::RHI::Format::A8B8G8R8_UNORM_SRGB: { - // Use a variant of ConvertSrgbGammaToLinear that takes an AZ::u8 - // and a lookup table instead of a float for better performance - return ConvertSrgbGammaToLinearUint(mem[index]); + // Use a lookup table that takes an AZ::u8 instead of a float + // for better performance + return s_SrgbGammaToLinearLookupTable[mem[index]]; } case AZ::RHI::Format::R8_SNORM: case AZ::RHI::Format::R8G8_SNORM: