34void QColorTrcLut::setFromGamma(
float gamma, Direction dir)
36 constexpr float iRes = 1.f /
float(Resolution);
39 m_toLinear.reset(
new ushort[Resolution + 1]);
40 for (
int i = 0; i <= Resolution; ++i) {
41 const int val = qRound(qPow(i * iRes, gamma) * (255 * 256));
42 m_toLinear[i] = qBound(0, val, 65280);
46 if (dir & FromLinear) {
47 const float iGamma = 1.f / gamma;
49 m_fromLinear.reset(
new ushort[Resolution + 1]);
50 for (
int i = 0; i <= Resolution; ++i)
51 m_fromLinear[i] = ushort(qRound(qBound(0.f, qPow(i * iRes, iGamma), 1.f) * (255 * 256)));
55void QColorTrcLut::setFromTransferFunction(
const QColorTransferFunction &fun, Direction dir)
57 constexpr float iRes = 1.f /
float(Resolution);
60 m_toLinear.reset(
new ushort[Resolution + 1]);
61 for (
int i = 0; i <= Resolution; ++i) {
62 const int val = qRound(fun.apply(i * iRes)* (255 * 256));
63 if (val > 65280 && i < m_unclampedToLinear)
64 m_unclampedToLinear = i;
65 m_toLinear[i] = qBound(0, val, 65280);
69 if (dir & FromLinear) {
71 m_fromLinear.reset(
new ushort[Resolution + 1]);
72 QColorTransferFunction inv = fun.inverted();
73 for (
int i = 0; i <= Resolution; ++i)
74 m_fromLinear[i] = ushort(qRound(qBound(0.f, inv.apply(i * iRes), 1.f) * (255 * 256)));
78void QColorTrcLut::setFromTransferGenericFunction(
const QColorTransferGenericFunction &fun, Direction dir)
80 constexpr float iRes = 1.f /
float(Resolution);
83 m_toLinear.reset(
new ushort[Resolution + 1]);
84 for (
int i = 0; i <= Resolution; ++i) {
85 const int val = qRound(fun.apply(i * iRes) * (255 * 256));
86 if (val > 65280 && i < m_unclampedToLinear)
87 m_unclampedToLinear = i;
88 m_toLinear[i] = qBound(0, val, 65280);
92 if (dir & FromLinear) {
94 m_fromLinear.reset(
new ushort[Resolution + 1]);
95 for (
int i = 0; i <= Resolution; ++i)
96 m_fromLinear[i] = ushort(qRound(qBound(0.f, fun.applyInverse(i * iRes), 1.f) * (255 * 256)));
100void QColorTrcLut::setFromTransferTable(
const QColorTransferTable &table, Direction dir)
102 constexpr float iRes = 1.f /
float(Resolution);
103 if (dir & ToLinear) {
105 m_toLinear.reset(
new ushort[Resolution + 1]);
106 for (
int i = 0; i <= Resolution; ++i)
107 m_toLinear[i] = ushort(qRound(table.apply(i * iRes) * (255 * 256)));
110 if (dir & FromLinear) {
112 m_fromLinear.reset(
new ushort[Resolution + 1]);
113 float minInverse = 0.0f;
114 for (
int i = 0; i <= Resolution; ++i) {
115 minInverse = table.applyInverse(i * iRes, minInverse);
116 m_fromLinear[i] = ushort(qRound(minInverse * (255 * 256)));
121void QColorTrcLut::setFromTrc(
const QColorTrc &trc, Direction dir)
123 switch (trc.m_type) {
124 case QColorTrc::Type::ParameterizedFunction:
125 return setFromTransferFunction(trc.fun(), dir);
126 case QColorTrc::Type::Table:
127 return setFromTransferTable(trc.table(), dir);
128 case QColorTrc::Type::GenericFunction:
129 return setFromTransferGenericFunction(trc.hdr(), dir);
130 case QColorTrc::Type::Uninitialized: