Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcolorclut_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCOLORCLUT_H
5#define QCOLORCLUT_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qlist.h>
19#include <QtGui/private/qcolormatrix_p.h>
20
22
23// A 3/4-dimensional lookup table compatible with ICC lut8, lut16, mAB, and mBA formats.
25{
26 inline static QColorVector interpolate(const QColorVector &a, const QColorVector &b, float t)
27 {
28 return a + (b - a) * t; // faster than std::lerp by assuming no super large or non-number floats
29 }
30 inline static void interpolateIn(QColorVector &a, const QColorVector &b, float t)
31 {
32 a += (b - a) * t;
33 }
34public:
35 uint32_t gridPointsX = 0;
36 uint32_t gridPointsY = 0;
37 uint32_t gridPointsZ = 0;
38 uint32_t gridPointsW = 1;
39 QList<QColorVector> table;
40
41 bool isEmpty() const { return table.isEmpty(); }
42
44 {
46 QColorVector frac;
47 const float x = std::clamp(v.x, 0.0f, 1.0f) * (gridPointsX - 1);
48 const float y = std::clamp(v.y, 0.0f, 1.0f) * (gridPointsY - 1);
49 const float z = std::clamp(v.z, 0.0f, 1.0f) * (gridPointsZ - 1);
50 const float w = std::clamp(v.w, 0.0f, 1.0f) * (gridPointsW - 1);
51 const uint32_t lox = static_cast<uint32_t>(std::floor(x));
52 const uint32_t hix = std::min(lox + 1, gridPointsX - 1);
53 const uint32_t loy = static_cast<uint32_t>(std::floor(y));
54 const uint32_t hiy = std::min(loy + 1, gridPointsY - 1);
55 const uint32_t loz = static_cast<uint32_t>(std::floor(z));
56 const uint32_t hiz = std::min(loz + 1, gridPointsZ - 1);
57 const uint32_t low = static_cast<uint32_t>(std::floor(w));
58 const uint32_t hiw = std::min(low + 1, gridPointsW - 1);
59 frac.x = x - static_cast<float>(lox);
60 frac.y = y - static_cast<float>(loy);
61 frac.z = z - static_cast<float>(loz);
62 frac.w = w - static_cast<float>(low);
63 if (gridPointsW > 1) {
67 + z * gridPointsW
68 + w;
69 };
70 QColorVector tmp[8];
71 // interpolate over w
72 tmp[0] = interpolate(table[index(lox, loy, loz, low)],
73 table[index(lox, loy, loz, hiw)], frac.w);
74 tmp[1] = interpolate(table[index(lox, loy, hiz, low)],
75 table[index(lox, loy, hiz, hiw)], frac.w);
76 tmp[2] = interpolate(table[index(lox, hiy, loz, low)],
77 table[index(lox, hiy, loz, hiw)], frac.w);
78 tmp[3] = interpolate(table[index(lox, hiy, hiz, low)],
79 table[index(lox, hiy, hiz, hiw)], frac.w);
80 tmp[4] = interpolate(table[index(hix, loy, loz, low)],
81 table[index(hix, loy, loz, hiw)], frac.w);
82 tmp[5] = interpolate(table[index(hix, loy, hiz, low)],
83 table[index(hix, loy, hiz, hiw)], frac.w);
84 tmp[6] = interpolate(table[index(hix, hiy, loz, low)],
85 table[index(hix, hiy, loz, hiw)], frac.w);
86 tmp[7] = interpolate(table[index(hix, hiy, hiz, low)],
87 table[index(hix, hiy, hiz, hiw)], frac.w);
88 // interpolate over z
89 for (int i = 0; i < 4; ++i)
90 interpolateIn(tmp[i * 2], tmp[i * 2 + 1], frac.z);
91 // interpolate over y
92 for (int i = 0; i < 2; ++i)
93 interpolateIn(tmp[i * 4], tmp[i * 4 + 2], frac.y);
94 // interpolate over x
95 interpolateIn(tmp[0], tmp[4], frac.x);
96 return tmp[0];
97 }
98 auto index = [&](qsizetype x, qsizetype y, qsizetype z) -> qsizetype {
99 return x * gridPointsZ * gridPointsY
100 + y * gridPointsZ
101 + z;
102 };
103 QColorVector tmp[8] = {
104 table[index(lox, loy, loz)],
105 table[index(lox, loy, hiz)],
106 table[index(lox, hiy, loz)],
107 table[index(lox, hiy, hiz)],
108 table[index(hix, loy, loz)],
109 table[index(hix, loy, hiz)],
110 table[index(hix, hiy, loz)],
111 table[index(hix, hiy, hiz)]
112 };
113 // interpolate over z
114 for (int i = 0; i < 4; ++i)
115 interpolateIn(tmp[i * 2], tmp[i * 2 + 1], frac.z);
116 // interpolate over y
117 for (int i = 0; i < 2; ++i)
118 interpolateIn(tmp[i * 4], tmp[i * 4 + 2], frac.y);
119 // interpolate over x
120 interpolateIn(tmp[0], tmp[4], frac.x);
121 return tmp[0];
122 }
123};
124
126
127#endif // QCOLORCLUT_H
QColorVector apply(const QColorVector &v) const
QList< QColorVector > table
uint32_t gridPointsY
uint32_t gridPointsW
bool isEmpty() const
uint32_t gridPointsX
uint32_t gridPointsZ
Combined button and popup list for selecting options.
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLint y
GLdouble GLdouble t
Definition qopenglext.h:243
GLenum GLenum GLsizei void * table
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qsizetype
Definition qtypes.h:165