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
qcolortrclut.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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#include "qcolortrclut_p.h"
7#include <qmath.h>
8
10std::shared_ptr<QColorTrcLut> QColorTrcLut::create()
11{
12 struct Access : QColorTrcLut {};
13 return std::make_shared<Access>();
14}
15
16std::shared_ptr<QColorTrcLut> QColorTrcLut::fromGamma(qreal gamma, Direction dir)
17{
18 auto cp = create();
19 cp->setFromGamma(gamma, dir);
20 return cp;
21}
22
24{
25 auto cp = create();
26 cp->setFromTransferFunction(fun, dir);
27 return cp;
28}
29
31{
32 auto cp = create();
33 cp->setFromTransferTable(table, dir);
34 return cp;
35}
36
38{
39 if (dir & ToLinear) {
40 if (!m_toLinear)
41 m_toLinear.reset(new ushort[Resolution + 1]);
42 for (int i = 0; i <= Resolution; ++i)
43 m_toLinear[i] = ushort(qRound(qPow(i / qreal(Resolution), gamma) * (255 * 256)));
44 }
45
46 if (dir & FromLinear) {
47 if (!m_fromLinear)
48 m_fromLinear.reset(new ushort[Resolution + 1]);
49 for (int i = 0; i <= Resolution; ++i)
50 m_fromLinear[i] = ushort(qRound(qPow(i / qreal(Resolution), qreal(1) / gamma) * (255 * 256)));
51 }
52}
53
55{
56 if (dir & ToLinear) {
57 if (!m_toLinear)
58 m_toLinear.reset(new ushort[Resolution + 1]);
59 for (int i = 0; i <= Resolution; ++i)
60 m_toLinear[i] = ushort(qRound(fun.apply(i / qreal(Resolution)) * (255 * 256)));
61 }
62
63 if (dir & FromLinear) {
64 if (!m_fromLinear)
65 m_fromLinear.reset(new ushort[Resolution + 1]);
66 QColorTransferFunction inv = fun.inverted();
67 for (int i = 0; i <= Resolution; ++i)
68 m_fromLinear[i] = ushort(qRound(inv.apply(i / qreal(Resolution)) * (255 * 256)));
69 }
70}
71
73{
74 if (dir & ToLinear) {
75 if (!m_toLinear)
76 m_toLinear.reset(new ushort[Resolution + 1]);
77 for (int i = 0; i <= Resolution; ++i)
78 m_toLinear[i] = ushort(qBound(0, qRound(table.apply(i / qreal(Resolution)) * (255 * 256)), 65280));
79 }
80
81 if (dir & FromLinear) {
82 if (!m_fromLinear)
83 m_fromLinear.reset(new ushort[Resolution + 1]);
84 float minInverse = 0.0f;
85 for (int i = 0; i <= Resolution; ++i) {
86 minInverse = table.applyInverse(i / qreal(Resolution), minInverse);
87 m_fromLinear[i] = ushort(qBound(0, qRound(minInverse * (255 * 256)), 65280));
88 }
89 }
90}
91
std::unique_ptr< ushort[]> m_fromLinear
static constexpr qsizetype Resolution
void setFromTransferTable(const QColorTransferTable &transTable, Direction dir=BiLinear)
static std::shared_ptr< QColorTrcLut > fromTransferTable(const QColorTransferTable &transTable, Direction dir=BiLinear)
void setFromTransferFunction(const QColorTransferFunction &transFn, Direction dir=BiLinear)
std::unique_ptr< ushort[]> m_toLinear
static std::shared_ptr< QColorTrcLut > fromGamma(qreal gamma, Direction dir=BiLinear)
void setFromGamma(qreal gamma, Direction dir=BiLinear)
static std::shared_ptr< QColorTrcLut > fromTransferFunction(const QColorTransferFunction &transFn, Direction dir=BiLinear)
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
auto qPow(T1 x, T2 y)
Definition qmath.h:180
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLenum GLenum GLsizei void * table
unsigned short ushort
Definition qtypes.h:33
double qreal
Definition qtypes.h:187
QString dir
[11]
QJSValue fun
[0]