Merge pull request #7625 from aws-lumberyard-dev/cgalvan/AddSupportForUNORM_SRGB

Added support for several UNORM_SRGB formats
This commit is contained in:
Chris Galvan
2022-02-16 09:18:34 -06:00
committed by GitHub
12 changed files with 77 additions and 152 deletions
-46
View File
@@ -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 <QColor>
#include <CryCommon/Cry_Color.h>
//////////////////////////////////////////////////////////////////////////
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);
}
+7 -6
View File
@@ -6,6 +6,7 @@
*
*/
#include <AzCore/Math/Color.h>
#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)