35void QColorTrcLut::setFromGamma(
float gamma, Direction dir)
37 constexpr float iRes = 1.f /
float(Resolution);
40 m_toLinear.reset(
new ushort[Resolution + 1]);
41 for (
int i = 0; i <= Resolution; ++i) {
42 const int val = qRound(qPow(i * iRes, gamma) * (255 * 256));
43 m_toLinear[i] = qBound(0, val, 65280);
47 if (dir & FromLinear) {
48 const float iGamma = 1.f / gamma;
50 m_fromLinear.reset(
new ushort[Resolution + 1]);
51 for (
int i = 0; i <= Resolution; ++i)
52 m_fromLinear[i] = ushort(qRound(qBound(0.f, qPow(i * iRes, iGamma), 1.f) * (255 * 256)));
56void QColorTrcLut::setFromTransferFunction(
const QColorTransferFunction &fun, Direction dir)
58 constexpr float iRes = 1.f /
float(Resolution);
61 m_toLinear.reset(
new ushort[Resolution + 1]);
62 for (
int i = 0; i <= Resolution; ++i) {
63 const int val = qRound(fun.apply(i * iRes)* (255 * 256));
64 if (val > 65280 && i < m_unclampedToLinear)
65 m_unclampedToLinear = i;
66 m_toLinear[i] = qBound(0, val, 65280);
70 if (dir & FromLinear) {
72 m_fromLinear.reset(
new ushort[Resolution + 1]);
73 QColorTransferFunction inv = fun.inverted();
74 for (
int i = 0; i <= Resolution; ++i)
75 m_fromLinear[i] = ushort(qRound(qBound(0.f, inv.apply(i * iRes), 1.f) * (255 * 256)));
79void QColorTrcLut::setFromTransferGenericFunction(
const QColorTransferGenericFunction &fun, Direction dir)
81 constexpr float iRes = 1.f /
float(Resolution);
84 m_toLinear.reset(
new ushort[Resolution + 1]);
85 for (
int i = 0; i <= Resolution; ++i) {
86 const int val = qRound(fun.apply(i * iRes) * (255 * 256));
87 if (val > 65280 && i < m_unclampedToLinear)
88 m_unclampedToLinear = i;
89 m_toLinear[i] = qBound(0, val, 65280);
93 if (dir & FromLinear) {
95 m_fromLinear.reset(
new ushort[Resolution + 1]);
96 for (
int i = 0; i <= Resolution; ++i)
97 m_fromLinear[i] = ushort(qRound(qBound(0.f, fun.applyInverse(i * iRes), 1.f) * (255 * 256)));
101void QColorTrcLut::setFromTransferTable(
const QColorTransferTable &table, Direction dir)
103 constexpr float iRes = 1.f /
float(Resolution);
104 if (dir & ToLinear) {
106 m_toLinear.reset(
new ushort[Resolution + 1]);
107 for (
int i = 0; i <= Resolution; ++i)
108 m_toLinear[i] = ushort(qRound(table.apply(i * iRes) * (255 * 256)));
111 if (dir & FromLinear) {
113 m_fromLinear.reset(
new ushort[Resolution + 1]);
114 float minInverse = 0.0f;
115 for (
int i = 0; i <= Resolution; ++i) {
116 minInverse = table.applyInverse(i * iRes, minInverse);
117 m_fromLinear[i] = ushort(qRound(minInverse * (255 * 256)));
122void QColorTrcLut::setFromTrc(
const QColorTrc &trc, Direction dir)
124 switch (trc.m_type) {
125 case QColorTrc::Type::ParameterizedFunction:
126 return setFromTransferFunction(trc.fun(), dir);
127 case QColorTrc::Type::Table:
128 return setFromTransferTable(trc.table(), dir);
129 case QColorTrc::Type::GenericFunction:
130 return setFromTransferGenericFunction(trc.hdr(), dir);
131 case QColorTrc::Type::Uninitialized: