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