Merge pull request #7625 from aws-lumberyard-dev/cgalvan/AddSupportForUNORM_SRGB
Added support for several UNORM_SRGB formatsmonroegm-disable-blank-issue-2
commit
c2d6ba0c69
@ -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);
|
||||
}
|
||||
Loading…
Reference in New Issue