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
qcolortrc_p.h
Go to the documentation of this file.
1// Copyright (C) 2018 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 QCOLORTRC_P_H
5#define QCOLORTRC_P_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 <QtGui/private/qtguiglobal_p.h>
21
23
24// Defines a TRC (Tone Reproduction Curve)
25class Q_GUI_EXPORT QColorTrc
26{
27public:
28 QColorTrc() noexcept : m_type(Type::Uninitialized) { }
29 QColorTrc(const QColorTransferFunction &fun) : m_type(Type::Function), m_fun(fun) { }
30 QColorTrc(const QColorTransferTable &table) : m_type(Type::Table), m_table(table) { }
31 QColorTrc(QColorTransferFunction &&fun) noexcept : m_type(Type::Function), m_fun(std::move(fun)) { }
32 QColorTrc(QColorTransferTable &&table) noexcept : m_type(Type::Table), m_table(std::move(table)) { }
33
34 enum class Type {
37 Table
38 };
39
40 bool isIdentity() const
41 {
42 return (m_type == Type::Function && m_fun.isIdentity())
43 || (m_type == Type::Table && m_table.isIdentity());
44 }
45 bool isValid() const
46 {
47 return m_type != Type::Uninitialized;
48 }
49 float apply(float x) const
50 {
51 if (m_type == Type::Table)
52 return m_table.apply(x);
53 if (m_type == Type::Function)
54 return m_fun.apply(x);
55 return x;
56 }
57 float applyExtended(float x) const
58 {
59 if (x >= 0.0f && x <= 1.0f)
60 return apply(x);
61 if (m_type == Type::Function)
62 return std::copysign(m_fun.apply(std::abs(x)), x);
63 if (m_type == Type::Table)
64 return x < 0.0f ? 0.0f : 1.0f;
65 return x;
66 }
67 float applyInverse(float x) const
68 {
69 if (m_type == Type::Table)
70 return m_table.applyInverse(x);
71 if (m_type == Type::Function)
72 return m_fun.inverted().apply(x);
73 return x;
74 }
75 float applyInverseExtended(float x) const
76 {
77 if (x >= 0.0f && x <= 1.0f)
78 return applyInverse(x);
79 if (m_type == Type::Function)
80 return std::copysign(applyInverse(std::abs(x)), x);
81 if (m_type == Type::Table)
82 return x < 0.0f ? 0.0f : 1.0f;
83 return x;
84 }
85
86 friend inline bool operator!=(const QColorTrc &o1, const QColorTrc &o2);
87 friend inline bool operator==(const QColorTrc &o1, const QColorTrc &o2);
88
92};
93
94inline bool operator!=(const QColorTrc &o1, const QColorTrc &o2)
95{
96 if (o1.m_type != o2.m_type)
97 return true;
98 if (o1.m_type == QColorTrc::Type::Function)
99 return o1.m_fun != o2.m_fun;
100 if (o1.m_type == QColorTrc::Type::Table)
101 return o1.m_table != o2.m_table;
102 return false;
103}
104inline bool operator==(const QColorTrc &o1, const QColorTrc &o2)
105{
106 return !(o1 != o2);
107}
108
110
111#endif // QCOLORTRC
QColorTrc(const QColorTransferFunction &fun)
Definition qcolortrc_p.h:29
QColorTrc(const QColorTransferTable &table)
Definition qcolortrc_p.h:30
QColorTransferFunction m_fun
Definition qcolortrc_p.h:90
bool isValid() const
Definition qcolortrc_p.h:45
float applyInverseExtended(float x) const
Definition qcolortrc_p.h:75
Type m_type
Definition qcolortrc_p.h:89
QColorTrc() noexcept
Definition qcolortrc_p.h:28
QColorTrc(QColorTransferTable &&table) noexcept
Definition qcolortrc_p.h:32
bool isIdentity() const
Definition qcolortrc_p.h:40
QColorTrc(QColorTransferFunction &&fun) noexcept
Definition qcolortrc_p.h:31
float applyExtended(float x) const
Definition qcolortrc_p.h:57
float apply(float x) const
Definition qcolortrc_p.h:49
float applyInverse(float x) const
Definition qcolortrc_p.h:67
QColorTransferTable m_table
Definition qcolortrc_p.h:91
Combined button and popup list for selecting options.
bool operator!=(const QColorTrc &o1, const QColorTrc &o2)
Definition qcolortrc_p.h:94
bool operator==(const QColorTrc &o1, const QColorTrc &o2)
constexpr bool operator!=(const timespec &t1, const timespec &t2)
constexpr int Uninitialized
GLint GLint GLint GLint GLint x
[0]
GLenum GLenum GLsizei void * table
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
QJSValue fun
[0]
Definition moc.h:23