Skip to content

Commit

Permalink
Cleanup various PQ transform code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Aug 28, 2024
1 parent 114ecd7 commit 7385c08
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 248 deletions.
49 changes: 27 additions & 22 deletions include/utility/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,54 @@ constexpr DirectX::XMMATRIX c_fromXYZto709 = // Transposed

constexpr DirectX::XMMATRIX c_fromXYZtoLMS = // Transposed
{
{ 0.3592, -0.1922, 0.0070, 0.0 },
{ 0.6976, 1.1004, 0.0749, 0.0 },
{ -0.0358, 0.0755, 0.8434, 0.0 },
{ 0.0, 0.0, 0.0, 1.0 }
{ 0.3592f, -0.1922f, 0.0070f, 0.0f },
{ 0.6976f, 1.1004f, 0.0749f, 0.0f },
{ -0.0358f, 0.0755f, 0.8434f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};

constexpr DirectX::XMMATRIX c_fromLMStoXYZ = // Transposed
{
{ 2.070180056695613509600, 0.364988250032657479740, -0.049595542238932107896, 0.0 },
{ -1.326456876103021025500, 0.680467362852235141020, -0.049421161186757487412, 0.0 },
{ 0.206616006847855170810, -0.045421753075853231409, 1.187995941732803439400, 0.0 },
{ 0.0, 0.0, 0.0, 1.0 }
{ 2.070180056695613509600f, 0.364988250032657479740f, -0.049595542238932107896f, 0.0f },
{ -1.326456876103021025500f, 0.680467362852235141020f, -0.049421161186757487412f, 0.0f },
{ 0.206616006847855170810f, -0.045421753075853231409f, 1.187995941732803439400f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};

constexpr DirectX::XMMATRIX c_scRGBtoBt2100 = // Transposed
{
{ 2939026994.L / 585553224375.L, 76515593.L / 138420033750.L, 12225392.L / 93230009375.L, 0.0 },
{ 9255011753.L / 3513319346250.L, 6109575001.L / 830520202500.L, 1772384008.L / 2517210253125.L, 0.0 },
{ 173911579.L / 501902763750.L, 75493061.L / 830520202500.L, 18035212433.L / 2517210253125.L, 0.0 },
{ 0.0, 0.0, 0.0, 1.0 }
{ 2939026994.0f / 585553224375.0f, 76515593.0f / 138420033750.0f, 12225392.0f / 93230009375.0f, 0.0f },
{ 9255011753.0f / 3513319346250.0f, 6109575001.0f / 830520202500.0f, 1772384008.0f / 2517210253125.0f, 0.0f },
{ 173911579.0f / 501902763750.0f, 75493061.0f / 830520202500.0f, 18035212433.0f / 2517210253125.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};

constexpr DirectX::XMMATRIX c_Bt2100toscRGB = // Transposed
{
{ 348196442125.L / 1677558947.L, -579752563250.L / 37238079773.L, -12183628000.L / 5369968309.L, 0.0f },
{ -123225331250.L / 1677558947.L, 5273377093000.L / 37238079773.L, -472592308000.L / 37589778163.L, 0.0f },
{ -15276242500.L / 1677558947.L, -38864558125.L / 37238079773.L, 5256599974375.L / 37589778163.L, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
{ 348196442125.0f / 1677558947.0f, -579752563250.0f / 37238079773.0f, -12183628000.0f / 5369968309.0f, 0.0f },
{ -123225331250.0f / 1677558947.0f, 5273377093000.0f / 37238079773.0f, -472592308000.0f / 37589778163.0f, 0.0f },
{ -15276242500.0f / 1677558947.0f, -38864558125.0f / 37238079773.0f, 5256599974375.0f / 37589778163.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};

struct ParamsPQ
{
DirectX::XMVECTOR N, M;
DirectX::XMVECTOR N, M;
DirectX::XMVECTOR C1, C2, C3;
DirectX::XMVECTOR MaxPQ;
DirectX::XMVECTOR RcpN, RcpM;
};

static const ParamsPQ PQ =
{
DirectX::XMVectorReplicate (2610.0 / 4096.0 / 4.0), // N
DirectX::XMVectorReplicate (2523.0 / 4096.0 * 128.0), // M
DirectX::XMVectorReplicate (3424.0 / 4096.0), // C1
DirectX::XMVectorReplicate (2413.0 / 4096.0 * 32.0), // C2
DirectX::XMVectorReplicate (2392.0 / 4096.0 * 32.0), // C3
DirectX::XMVectorReplicate (2610.0 / 4096.0 / 4.0), // N
DirectX::XMVectorReplicate (2523.0 / 4096.0 * 128.0), // M
DirectX::XMVectorReplicate (3424.0 / 4096.0), // C1
DirectX::XMVectorReplicate (2413.0 / 4096.0 * 32.0), // C2
DirectX::XMVectorReplicate (2392.0 / 4096.0 * 32.0), // C3
DirectX::XMVectorReplicate (125.0f), // MaxPQ
DirectX::XMVectorReciprocal (DirectX::XMVectorReplicate (2610.0 / 4096.0 / 4.0)),
DirectX::XMVectorReciprocal (DirectX::XMVectorReplicate (2523.0 / 4096.0 * 128.0)),
};

#pragma warning( pop )
Expand Down
2 changes: 1 addition & 1 deletion src/tabs/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ LoadLibraryTexture (image_s& image)
XMVECTOR v = *pixels++;

v =
XMVector3Transform (v, c_from709toXYZ);
XMVectorMax (g_XMZero, XMVector3Transform (v, c_from709toXYZ));

luminance_freq [
std::clamp ( (int)
Expand Down
Loading

0 comments on commit 7385c08

Please sign in to comment.