mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 07:01:30 +00:00
[idd] postprocess: centralize color transform state
This commit is contained in:
@@ -22,6 +22,55 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool NearlyEqual(float a, float b, float tolerance)
|
||||
{
|
||||
const float delta = a - b;
|
||||
return delta >= -tolerance && delta <= tolerance;
|
||||
}
|
||||
|
||||
bool Identity(const D12ColorTransform& transform)
|
||||
{
|
||||
static const float matrixTolerance = 1.0f / 1048576.0f;
|
||||
static const float lutTolerance = 1.0f / 65535.0f;
|
||||
|
||||
if (transform.matrixEnabled)
|
||||
{
|
||||
for (unsigned row = 0; row < 3; ++row)
|
||||
for (unsigned column = 0; column < 4; ++column)
|
||||
{
|
||||
const float expected = row == column ? 1.0f : 0.0f;
|
||||
const float effective =
|
||||
transform.matrix[row][column] * transform.scalar;
|
||||
if (!NearlyEqual(effective, expected, matrixTolerance))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (transform.lutEnabled)
|
||||
for (unsigned i = 0; i < 4096; ++i)
|
||||
{
|
||||
const float expected = static_cast<float>(i) / 4095.0f;
|
||||
if (!NearlyEqual(transform.lut[i][0], expected, lutTolerance) ||
|
||||
!NearlyEqual(transform.lut[i][1], expected, lutTolerance) ||
|
||||
!NearlyEqual(transform.lut[i][2], expected, lutTolerance))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<const D12ColorTransform> D12::Transform(
|
||||
const std::shared_ptr<const D12ColorTransform>& transform)
|
||||
{
|
||||
if (!transform || (!transform->matrixEnabled && !transform->lutEnabled) ||
|
||||
Identity(*transform))
|
||||
return nullptr;
|
||||
return transform;
|
||||
}
|
||||
|
||||
FrameType D12::Type(DXGI_FORMAT format)
|
||||
{
|
||||
switch (format)
|
||||
|
||||
Reference in New Issue
Block a user