Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLevelsCurve Class Reference

This class holds the parameters for a levels adjustment. It is modeled after KisCubicCurve and has similar interface and functionality. More...

#include <KisLevelsCurve.h>

Public Member Functions

const QVector< qreal > & floatTransfer (int size=256) const
 Returns a vector of size.
 
void fromString (const QString &text, bool *ok=nullptr)
 Parses the parameters from a given text.
 
qreal inputBlackPoint () const
 Get the input black point.
 
qreal inputGamma () const
 Get the gamma value.
 
qreal inputWhitePoint () const
 Get the input white point.
 
bool isIdentity () const
 Check whether the level info maps all values to themselves.
 
 KisLevelsCurve ()
 
 KisLevelsCurve (const KisLevelsCurve &rhs)=default
 
 KisLevelsCurve (const QString &text)
 
 KisLevelsCurve (qreal inputBlackPoint, qreal inputWhitePoint, qreal inputGamma, qreal outputBlackPoint, qreal outputWhitePoint)
 
const QString & name () const
 Get the name associated with this levels info object.
 
KisLevelsCurveoperator= (const KisLevelsCurve &rhs)=default
 
bool operator== (const KisLevelsCurve &rhs) const
 
qreal outputBlackPoint () const
 Get the output black point.
 
qreal outputWhitePoint () const
 Get the output white point.
 
void resetAll ()
 Resets the input and output levels (and gamma)
 
void resetInputLevels ()
 Resets the input levels only (and gamma)
 
void resetOutputLevels ()
 Resets the output levels only.
 
void setInputBlackPoint (qreal newInputBlackPoint)
 Set the input black point.
 
void setInputGamma (qreal newInputGamma)
 Set the gamma value.
 
void setInputWhitePoint (qreal newInputWhitePoint)
 Set the input white point.
 
void setName (const QString &newName)
 Set the name associated with this levels info object. This allows us to carry around a display name for the level info internally. It could potentially be useful anywhere level info are used in the UI.
 
void setOutputBlackPoint (qreal newOutputBlackPoint)
 Set the output black point.
 
void setOutputWhitePoint (qreal newOutputWhitePoint)
 Set the output white point.
 
QString toString () const
 Get a text representation of the parameters. The format is: "input_black_point;input_white_point;input_gamma;output_black_point;output_white_point". For example: "0;1;0.6;0;1", "0.2;0.8;1.2;0.25;0.75".
 
const QVector< quint16 > & uint16Transfer (int size=256) const
 Returns a vector of size.
 
qreal value (qreal x) const
 Evaluates the function formed by the levels parameters for a given x. The input and output values are normalized.
 

Static Public Member Functions

static constexpr qreal defaultInputBlackPoint ()
 Default value for the input black point.
 
static constexpr qreal defaultInputGamma ()
 Default value for the input gamma.
 
static constexpr qreal defaultInputWhitePoint ()
 Default value for the input white point.
 
static constexpr qreal defaultOutputBlackPoint ()
 Default value for the output black point.
 
static constexpr qreal defaultOutputWhitePoint ()
 Default value for the output white point.
 

Private Member Functions

void invalidate ()
 

Private Attributes

QVector< qreal > m_fTransfer
 
qreal m_inputBlackPoint
 
qreal m_inputGamma
 
qreal m_inputLevelsDelta
 
qreal m_inputWhitePoint
 
qreal m_inverseInputGamma
 
bool m_mustRecomputeFTransfer
 
bool m_mustRecomputeU16Transfer
 
QString m_name
 
qreal m_outputBlackPoint
 
qreal m_outputLevelsDelta
 
qreal m_outputWhitePoint
 
QVector< quint16 > m_u16Transfer
 

Detailed Description

This class holds the parameters for a levels adjustment. It is modeled after KisCubicCurve and has similar interface and functionality.

Definition at line 21 of file KisLevelsCurve.h.

Constructor & Destructor Documentation

◆ KisLevelsCurve() [1/4]

KisLevelsCurve::KisLevelsCurve ( )

Definition at line 15 of file KisLevelsCurve.cpp.

18{}
static constexpr qreal defaultInputGamma()
Default value for the input gamma.
static constexpr qreal defaultOutputBlackPoint()
Default value for the output black point.
static constexpr qreal defaultOutputWhitePoint()
Default value for the output white point.
static constexpr qreal defaultInputWhitePoint()
Default value for the input white point.
static constexpr qreal defaultInputBlackPoint()
Default value for the input black point.

◆ KisLevelsCurve() [2/4]

KisLevelsCurve::KisLevelsCurve ( qreal inputBlackPoint,
qreal inputWhitePoint,
qreal inputGamma,
qreal outputBlackPoint,
qreal outputWhitePoint )

Definition at line 20 of file KisLevelsCurve.cpp.

32{}
qreal outputBlackPoint() const
Get the output black point.
qreal inputBlackPoint() const
Get the input black point.
qreal inputGamma() const
Get the gamma value.
qreal inputWhitePoint() const
Get the input white point.
bool m_mustRecomputeFTransfer
qreal outputWhitePoint() const
Get the output white point.
bool m_mustRecomputeU16Transfer

◆ KisLevelsCurve() [3/4]

KisLevelsCurve::KisLevelsCurve ( const QString & text)
See also
toString()
fromString()

Definition at line 34 of file KisLevelsCurve.cpp.

36{
37 fromString(text);
38}
void fromString(const QString &text, bool *ok=nullptr)
Parses the parameters from a given text.

References fromString().

◆ KisLevelsCurve() [4/4]

KisLevelsCurve::KisLevelsCurve ( const KisLevelsCurve & rhs)
default

Member Function Documentation

◆ defaultInputBlackPoint()

static constexpr qreal KisLevelsCurve::defaultInputBlackPoint ( )
inlinestaticconstexpr

Default value for the input black point.

Definition at line 27 of file KisLevelsCurve.h.

27{ return 0.0; }

◆ defaultInputGamma()

static constexpr qreal KisLevelsCurve::defaultInputGamma ( )
inlinestaticconstexpr

Default value for the input gamma.

Definition at line 35 of file KisLevelsCurve.h.

35{ return 1.0; }

◆ defaultInputWhitePoint()

static constexpr qreal KisLevelsCurve::defaultInputWhitePoint ( )
inlinestaticconstexpr

Default value for the input white point.

Definition at line 31 of file KisLevelsCurve.h.

31{ return 1.0; }

◆ defaultOutputBlackPoint()

static constexpr qreal KisLevelsCurve::defaultOutputBlackPoint ( )
inlinestaticconstexpr

Default value for the output black point.

Definition at line 39 of file KisLevelsCurve.h.

39{ return 0.0; }

◆ defaultOutputWhitePoint()

static constexpr qreal KisLevelsCurve::defaultOutputWhitePoint ( )
inlinestaticconstexpr

Default value for the output white point.

Definition at line 43 of file KisLevelsCurve.h.

43{ return 1.0; }

◆ floatTransfer()

const QVector< qreal > & KisLevelsCurve::floatTransfer ( int size = 256) const

Returns a vector of size.

Parameters
sizewith values obtained by evaluating the function formed by the levels parameters from 0.0 to 1.0. The resulting values are in the range [0, 1]
sizeThe size of the returned vector
Returns
const QVector<qreal>& The vector with the values
See also
value()
uint16Transfer()

Definition at line 193 of file KisLevelsCurve.cpp.

194{
195 if (!m_mustRecomputeFTransfer && size == m_fTransfer.size()) {
196 return m_fTransfer;
197 }
198
199 m_fTransfer.resize(size);
200
201 for (int i = 0; i < size; ++i) {
202 m_fTransfer[i] = value(static_cast<qreal>(i) / static_cast<qreal>(size - 1));
203 }
204
206 return m_fTransfer;
207}
qreal value(qreal x) const
Evaluates the function formed by the levels parameters for a given x. The input and output values are...
QVector< qreal > m_fTransfer
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References m_fTransfer, m_mustRecomputeFTransfer, and value().

◆ fromString()

void KisLevelsCurve::fromString ( const QString & text,
bool * ok = nullptr )

Parses the parameters from a given text.

See also
toString

Definition at line 219 of file KisLevelsCurve.cpp.

220{
221 KIS_SAFE_ASSERT_RECOVER(!text.isEmpty()) {
222 resetAll();
223 if (ok) {
224 *ok = false;
225 }
226 return;
227 }
228
229 const QStringList data = text.split(';');
230 KIS_SAFE_ASSERT_RECOVER(data.size() == 5) {
231 resetAll();
232 if (ok) {
233 *ok = false;
234 }
235 return;
236 }
237
238 qreal values[5];
239 bool ok_;
240 for (int i = 0; i < 5; ++i) {
241 ok_ = false;
242 values[i] = KisDomUtils::toDouble(data.at(i), &ok_);
244 resetAll();
245 if (ok) {
246 *ok = false;
247 }
248 return;
249 }
250 }
251
252 m_inputBlackPoint = values[0];
253 m_inputWhitePoint = values[1];
254 m_inputGamma = values[2];
255 m_outputBlackPoint = values[3];
256 m_outputWhitePoint = values[4];
260 invalidate();
261
262 if (ok) {
263 *ok = true;
264 }
265}
void resetAll()
Resets the input and output levels (and gamma)
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
double toDouble(const QString &str, bool *ok=nullptr)

References invalidate(), KIS_SAFE_ASSERT_RECOVER, m_inputBlackPoint, m_inputGamma, m_inputLevelsDelta, m_inputWhitePoint, m_inverseInputGamma, m_outputBlackPoint, m_outputLevelsDelta, m_outputWhitePoint, resetAll(), and KisDomUtils::toDouble().

◆ inputBlackPoint()

qreal KisLevelsCurve::inputBlackPoint ( ) const

Get the input black point.

Definition at line 64 of file KisLevelsCurve.cpp.

65{
66 return m_inputBlackPoint;
67}

References m_inputBlackPoint.

◆ inputGamma()

qreal KisLevelsCurve::inputGamma ( ) const

Get the gamma value.

Definition at line 74 of file KisLevelsCurve.cpp.

75{
76 return m_inputGamma;
77}

References m_inputGamma.

◆ inputWhitePoint()

qreal KisLevelsCurve::inputWhitePoint ( ) const

Get the input white point.

Definition at line 69 of file KisLevelsCurve.cpp.

70{
71 return m_inputWhitePoint;
72}

References m_inputWhitePoint.

◆ invalidate()

void KisLevelsCurve::invalidate ( )
private

Definition at line 267 of file KisLevelsCurve.cpp.

268{
271}

References m_mustRecomputeFTransfer, and m_mustRecomputeU16Transfer.

◆ isIdentity()

bool KisLevelsCurve::isIdentity ( ) const

Check whether the level info maps all values to themselves.

Definition at line 155 of file KisLevelsCurve.cpp.

156{
157 return
158 m_inputBlackPoint == 0.0 &&
159 m_inputWhitePoint == 1.0 &&
160 m_inputGamma == 1.0 &&
161 m_outputBlackPoint == 0.0 &&
162 m_outputWhitePoint == 1.0;
163}

References m_inputBlackPoint, m_inputGamma, m_inputWhitePoint, m_outputBlackPoint, and m_outputWhitePoint.

◆ name()

const QString & KisLevelsCurve::name ( ) const

Get the name associated with this levels info object.

Definition at line 165 of file KisLevelsCurve.cpp.

166{
167 return m_name;
168}

References m_name.

◆ operator=()

KisLevelsCurve & KisLevelsCurve::operator= ( const KisLevelsCurve & rhs)
default

◆ operator==()

bool KisLevelsCurve::operator== ( const KisLevelsCurve & rhs) const

◆ outputBlackPoint()

qreal KisLevelsCurve::outputBlackPoint ( ) const

Get the output black point.

Definition at line 79 of file KisLevelsCurve.cpp.

80{
81 return m_outputBlackPoint;
82}

References m_outputBlackPoint.

◆ outputWhitePoint()

qreal KisLevelsCurve::outputWhitePoint ( ) const

Get the output white point.

Definition at line 84 of file KisLevelsCurve.cpp.

85{
86 return m_outputWhitePoint;
87}

References m_outputWhitePoint.

◆ resetAll()

◆ resetInputLevels()

◆ resetOutputLevels()

◆ setInputBlackPoint()

void KisLevelsCurve::setInputBlackPoint ( qreal newInputBlackPoint)

Set the input black point.

Definition at line 89 of file KisLevelsCurve.cpp.

90{
91 m_inputBlackPoint = newInputBlackPoint;
93 invalidate();
94}

References invalidate(), m_inputBlackPoint, m_inputLevelsDelta, and m_inputWhitePoint.

◆ setInputGamma()

void KisLevelsCurve::setInputGamma ( qreal newInputGamma)

Set the gamma value.

Definition at line 103 of file KisLevelsCurve.cpp.

104{
105 m_inputGamma = newInputGamma;
107 invalidate();
108}

References invalidate(), m_inputGamma, and m_inverseInputGamma.

◆ setInputWhitePoint()

void KisLevelsCurve::setInputWhitePoint ( qreal newInputWhitePoint)

Set the input white point.

Definition at line 96 of file KisLevelsCurve.cpp.

97{
98 m_inputWhitePoint = newInputWhitePoint;
100 invalidate();
101}

References invalidate(), m_inputBlackPoint, m_inputLevelsDelta, and m_inputWhitePoint.

◆ setName()

void KisLevelsCurve::setName ( const QString & newName)

Set the name associated with this levels info object. This allows us to carry around a display name for the level info internally. It could potentially be useful anywhere level info are used in the UI.

Definition at line 170 of file KisLevelsCurve.cpp.

171{
172 m_name = newName;
173}

References m_name.

◆ setOutputBlackPoint()

void KisLevelsCurve::setOutputBlackPoint ( qreal newOutputBlackPoint)

Set the output black point.

Definition at line 110 of file KisLevelsCurve.cpp.

111{
112 m_outputBlackPoint = newOutputBlackPoint;
114 invalidate();
115}

References invalidate(), m_outputBlackPoint, m_outputLevelsDelta, and m_outputWhitePoint.

◆ setOutputWhitePoint()

void KisLevelsCurve::setOutputWhitePoint ( qreal newOutputWhitePoint)

Set the output white point.

Definition at line 117 of file KisLevelsCurve.cpp.

118{
119 m_outputWhitePoint = newOutputWhitePoint;
121 invalidate();
122}

References invalidate(), m_outputBlackPoint, m_outputLevelsDelta, and m_outputWhitePoint.

◆ toString()

QString KisLevelsCurve::toString ( ) const

Get a text representation of the parameters. The format is: "input_black_point;input_white_point;input_gamma;output_black_point;output_white_point". For example: "0;1;0.6;0;1", "0.2;0.8;1.2;0.25;0.75".

See also
fromString()

Definition at line 209 of file KisLevelsCurve.cpp.

References m_inputBlackPoint, m_inputGamma, m_inputWhitePoint, m_outputBlackPoint, m_outputWhitePoint, and KisDomUtils::toString().

◆ uint16Transfer()

const QVector< quint16 > & KisLevelsCurve::uint16Transfer ( int size = 256) const

Returns a vector of size.

Parameters
sizewith values obtained by evaluating the function formed by the levels parameters from 0.0 to 1.0. The resulting values are scaled to the range [0, 0xFF]
sizeThe size of the returned vector
Returns
const QVector<quint16>& The vector with the values
See also
value()
floatTransfer()

Definition at line 175 of file KisLevelsCurve.cpp.

176{
177
178 if (!m_mustRecomputeU16Transfer && size == m_u16Transfer.size()) {
179 return m_u16Transfer;
180 }
181
182 m_u16Transfer.resize(size);
183
184 for (int i = 0; i < size; ++i) {
185 const qreal x = static_cast<qreal>(i) / static_cast<qreal>(size - 1);
186 m_u16Transfer[i] = static_cast<quint16>(qRound(value(x) * static_cast<qreal>(0xFFFF)));
187 }
188
190 return m_u16Transfer;
191}
QVector< quint16 > m_u16Transfer

References m_mustRecomputeU16Transfer, m_u16Transfer, and value().

◆ value()

qreal KisLevelsCurve::value ( qreal x) const

Evaluates the function formed by the levels parameters for a given x. The input and output values are normalized.

Definition at line 53 of file KisLevelsCurve.cpp.

54{
55 if (x <= m_inputBlackPoint)
56 return m_outputBlackPoint;
57 else if (x < m_inputWhitePoint) {
59 } else {
60 return m_outputWhitePoint;
61 }
62}

References m_inputBlackPoint, m_inputLevelsDelta, m_inputWhitePoint, m_inverseInputGamma, m_outputBlackPoint, m_outputLevelsDelta, and m_outputWhitePoint.

Member Data Documentation

◆ m_fTransfer

QVector<qreal> KisLevelsCurve::m_fTransfer
mutableprivate

Definition at line 174 of file KisLevelsCurve.h.

◆ m_inputBlackPoint

qreal KisLevelsCurve::m_inputBlackPoint
private

Definition at line 169 of file KisLevelsCurve.h.

◆ m_inputGamma

qreal KisLevelsCurve::m_inputGamma
private

Definition at line 169 of file KisLevelsCurve.h.

◆ m_inputLevelsDelta

qreal KisLevelsCurve::m_inputLevelsDelta
private

Definition at line 171 of file KisLevelsCurve.h.

◆ m_inputWhitePoint

qreal KisLevelsCurve::m_inputWhitePoint
private

Definition at line 169 of file KisLevelsCurve.h.

◆ m_inverseInputGamma

qreal KisLevelsCurve::m_inverseInputGamma
private

Definition at line 171 of file KisLevelsCurve.h.

◆ m_mustRecomputeFTransfer

bool KisLevelsCurve::m_mustRecomputeFTransfer
mutableprivate

Definition at line 176 of file KisLevelsCurve.h.

◆ m_mustRecomputeU16Transfer

bool KisLevelsCurve::m_mustRecomputeU16Transfer
mutableprivate

Definition at line 175 of file KisLevelsCurve.h.

◆ m_name

QString KisLevelsCurve::m_name
private

Definition at line 172 of file KisLevelsCurve.h.

◆ m_outputBlackPoint

qreal KisLevelsCurve::m_outputBlackPoint
private

Definition at line 170 of file KisLevelsCurve.h.

◆ m_outputLevelsDelta

qreal KisLevelsCurve::m_outputLevelsDelta
private

Definition at line 171 of file KisLevelsCurve.h.

◆ m_outputWhitePoint

qreal KisLevelsCurve::m_outputWhitePoint
private

Definition at line 170 of file KisLevelsCurve.h.

◆ m_u16Transfer

QVector<quint16> KisLevelsCurve::m_u16Transfer
mutableprivate

Definition at line 173 of file KisLevelsCurve.h.


The documentation for this class was generated from the following files: