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

#include <kis_cubic_curve.h>

+ Inheritance diagram for KisCubicCurve:

Public Member Functions

int addPoint (const KisCubicCurvePoint &point)
 
int addPoint (const QPointF &position)
 
int addPoint (const QPointF &position, bool setAsCorner)
 
const QList< KisCubicCurvePoint > & curvePoints () const
 
 Data ()
 
 Data (const Data &data)
 
const QVector< qreal > floatTransfer (int size=256) const
 
Q_DECL_DEPRECATED void fromString (const QString &)
 
void invalidate ()
 
bool isConstant (qreal c) const
 
bool isIdentity () const
 
void keepSorted ()
 
 KisCubicCurve ()
 
 KisCubicCurve (const KisCubicCurve &curve)
 
 KisCubicCurve (const QList< KisCubicCurvePoint > &points)
 
 KisCubicCurve (const QList< QPointF > &points)
 
 KisCubicCurve (const QString &curveString)
 
const QString & name () const
 
KisCubicCurveoperator= (const KisCubicCurve &curve)
 
bool operator== (const KisCubicCurve &curve) const
 
Q_DECL_DEPRECATED QList< QPointF > points () const
 
void removePoint (int idx)
 
void setName (const QString &name)
 
void setPoint (int idx, const KisCubicCurvePoint &point)
 
void setPoint (int idx, const QPointF &position)
 
void setPoint (int idx, const QPointF &position, bool setAsCorner)
 
void setPointAsCorner (int idx, bool setAsCorner)
 
void setPointPosition (int idx, const QPointF &position)
 
void setPoints (const QList< KisCubicCurvePoint > &points)
 
void setPoints (const QList< QPointF > &points)
 
QString toString () const
 
const QVector< quint16 > uint16Transfer (int size=256) const
 
void updateSpline ()
 
template<typename _T_ , typename _T2_ >
void updateTransfer (QVector< _T_ > *transfer, bool &valid, _T2_ min, _T2_ max, int size)
 
qreal value (qreal x)
 
qreal value (qreal x) const
 
 ~Data ()
 
 ~KisCubicCurve ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Member Functions

static qreal interpolateLinear (qreal normalizedValue, const QVector< qreal > &transfer)
 

Public Attributes

QSharedDataPointer< Datadata
 
QVector< qreal > fTransfer
 
QString name
 
QList< KisCubicCurvePointpoints
 
KisCubicSpline< KisCubicCurvePoint, qreal > spline
 
QVector< quint16 > u16Transfer
 
QVector< quint8 > u8Transfer
 
bool validFTransfer {false}
 
bool validSpline {false}
 
bool validU16Transfer {false}
 
bool validU8Transfer {false}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Attributes

Private *const d {nullptr}
 

Detailed Description

Hold the data for a cubic curve.

Definition at line 76 of file kis_cubic_curve.cpp.

Constructor & Destructor Documentation

◆ ~Data()

KisCubicCurve::~Data ( )
inline

Definition at line 83 of file kis_cubic_curve.cpp.

83 {
84 }

◆ KisCubicCurve() [1/5]

KisCubicCurve::KisCubicCurve ( )

Definition at line 158 of file kis_cubic_curve.cpp.

159 : d(new Private)
160{
161 d->data = new Data;
162 d->data->points.append({ 0.0, 0.0, false });
163 d->data->points.append({ 1.0, 1.0, false });
164}
Private *const d

References d, and Data().

◆ KisCubicCurve() [2/5]

KisCubicCurve::KisCubicCurve ( const QList< QPointF > & points)

Definition at line 166 of file kis_cubic_curve.cpp.

167 : d(new Private)
168{
169 d->data = new Data;
170 d->data->points.reserve(points.size());
171 Q_FOREACH(const QPointF p, points) {
172 d->data->points.append({ p, false });
173 }
174 d->data->keepSorted();
175}
const Params2D p
QList< KisCubicCurvePoint > points

References d, Data(), p, and points.

◆ KisCubicCurve() [3/5]

KisCubicCurve::KisCubicCurve ( const QList< KisCubicCurvePoint > & points)

Definition at line 177 of file kis_cubic_curve.cpp.

178 : d(new Private)
179{
180 d->data = new Data;
181 d->data->points = points;
182 d->data->keepSorted();
183}

References d, Data(), and points.

◆ KisCubicCurve() [4/5]

KisCubicCurve::KisCubicCurve ( const QString & curveString)

Definition at line 190 of file kis_cubic_curve.cpp.

191 : d(new Private)
192{
193 // Curve string format: a semi-colon separated list of point entries.
194 // Previous point entry format: a pair of numbers, separated by a comma,
195 // that represent the x and y coordinates of the point, in that order.
196 // Examples: identity "0.0,0.0;1.0,1.0;"
197 // U-shaped curve "0.0,1.0;0.5,0.0;1.0,1.0"
198 // New point entry format: a list of comma separated point properties. The
199 // first and second properties are required and should be numbers
200 // that represent the x and y coordinates of the point, in that order.
201 // After those, some optional properties/flags may be present or not.
202 // If there are no optional properties for any point entry, then the
203 // format of the string is identical to the old one.
204 // Currently, only the "is_corner" flag is supported. All other
205 // present optional properties are ignored.
206 // Examples: identity "0.0,0.0;1.0,1.0;"
207 // V-shaped curve "0.0,1.0;0.5,0.0,is_corner;1.0,1.0"
208
209 d->data = new Data;
210
211 KIS_SAFE_ASSERT_RECOVER(!curveString.isEmpty()) {
212 *this = KisCubicCurve();
213 return;
214 }
215
216 const QStringList data = curveString.split(';', Qt::SkipEmptyParts);
217
219 Q_FOREACH (const QString &entry, data) {
220 const QStringList entryData = entry.split(',', Qt::SkipEmptyParts);
221 KIS_SAFE_ASSERT_RECOVER(entryData.size() > 1) {
222 *this = KisCubicCurve();
223 return;
224 }
225 bool ok;
226 const qreal x = KisDomUtils::toDouble(entryData[0], &ok);
228 *this = KisCubicCurve();
229 return;
230 }
231 const qreal y = KisDomUtils::toDouble(entryData[1], &ok);
233 *this = KisCubicCurve();
234 return;
235 }
236 bool isCorner = false;
237 for (int i = 2; i < entryData.size(); ++i) {
238 if (entryData[i] == "is_corner") {
239 isCorner = true;
240 }
241 }
242 points.append({ x, y, isCorner });
243 }
244
246}
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
double toDouble(const QString &str, bool *ok=nullptr)
void setPoints(const QList< QPointF > &points)
QSharedDataPointer< Data > data

References d, Data(), data, KIS_SAFE_ASSERT_RECOVER, KisCubicCurve(), points, setPoints(), and KisDomUtils::toDouble().

◆ KisCubicCurve() [5/5]

KisCubicCurve::KisCubicCurve ( const KisCubicCurve & curve)

Definition at line 185 of file kis_cubic_curve.cpp.

186 : d(new Private(*curve.d))
187{
188}

◆ ~KisCubicCurve()

KisCubicCurve::~KisCubicCurve ( )

Definition at line 248 of file kis_cubic_curve.cpp.

249{
250 delete d;
251}

References d.

Member Function Documentation

◆ addPoint() [1/3]

int KisCubicCurve::addPoint ( const KisCubicCurvePoint & point)

Add a point to the curve, the list of point is always sorted.

Returns
the index of the inserted point

Definition at line 337 of file kis_cubic_curve.cpp.

338{
339 d->data.detach();
340 d->data->points.append(point);
341 d->data->keepSorted();
342 d->data->invalidate();
343
344 return d->data->points.indexOf(point);
345}

References d.

◆ addPoint() [2/3]

int KisCubicCurve::addPoint ( const QPointF & position)

Definition at line 352 of file kis_cubic_curve.cpp.

353{
354 return addPoint({ position, false });
355}
int addPoint(const KisCubicCurvePoint &point)

References addPoint().

◆ addPoint() [3/3]

int KisCubicCurve::addPoint ( const QPointF & position,
bool setAsCorner )

Definition at line 347 of file kis_cubic_curve.cpp.

348{
349 return addPoint({ position, setAsCorner });
350}

References addPoint().

◆ curvePoints()

const QList< KisCubicCurvePoint > & KisCubicCurve::curvePoints ( ) const

Definition at line 282 of file kis_cubic_curve.cpp.

283{
284 return d->data->points;
285}

References d.

◆ Data() [1/2]

KisCubicCurve::Data ( )
inline

Definition at line 77 of file kis_cubic_curve.cpp.

77 {
78 }

◆ Data() [2/2]

KisCubicCurve::Data ( const Data & data)
inline

Definition at line 79 of file kis_cubic_curve.cpp.

79 : QSharedData() {
80 points = data.points;
81 name = data.name;
82 }

◆ floatTransfer()

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

Definition at line 468 of file kis_cubic_curve.cpp.

469{
470 d->data->updateTransfer<qreal, qreal>(&d->data->fTransfer, d->data->validFTransfer, 0.0, 1.0, size);
471 return d->data->fTransfer;
472}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d.

◆ fromString()

void KisCubicCurve::fromString ( const QString & string)

Definition at line 457 of file kis_cubic_curve.cpp.

458{
459 *this = KisCubicCurve(string);
460}

References KisCubicCurve().

◆ interpolateLinear()

qreal KisCubicCurve::interpolateLinear ( qreal normalizedValue,
const QVector< qreal > & transfer )
static

Definition at line 400 of file kis_cubic_curve.cpp.

401{
402 const qreal maxValue = transfer.size() - 1;
403
404 const qreal bilinearX = qBound(0.0, maxValue * normalizedValue, maxValue);
405 const qreal xFloored = std::floor(bilinearX);
406 const qreal xCeiled = std::ceil(bilinearX);
407
408 const qreal t = bilinearX - xFloored;
409
410 constexpr qreal eps = 1e-6;
411
412 qreal newValue = normalizedValue;
413
414 if (t < eps) {
415 newValue = transfer[int(xFloored)];
416 } else if (t > (1.0 - eps)) {
417 newValue = transfer[int(xCeiled)];
418 } else {
419 qreal a = transfer[int(xFloored)];
420 qreal b = transfer[int(xCeiled)];
421
422 newValue = a + t * (b - a);
423 }
424
425 return KisAlgebra2D::copysign(newValue, normalizedValue);
426}
const qreal eps
T copysign(T x, T y)

References KisAlgebra2D::copysign(), and eps.

◆ invalidate()

void KisCubicCurve::invalidate ( )

◆ isConstant()

bool KisCubicCurve::isConstant ( qreal c) const

Definition at line 382 of file kis_cubic_curve.cpp.

383{
384 const QList<KisCubicCurvePoint> &points = d->data->points;
385
386 Q_FOREACH (const KisCubicCurvePoint &pt, points) {
387 if (!qFuzzyCompare(c, pt.y())) {
388 return false;
389 }
390 }
391
392 return true;
393}
static bool qFuzzyCompare(half p1, half p2)

References d, points, qFuzzyCompare(), and KisCubicCurvePoint::y().

◆ isIdentity()

bool KisCubicCurve::isIdentity ( ) const

Definition at line 364 of file kis_cubic_curve.cpp.

365{
366 const QList<KisCubicCurvePoint> &points = d->data->points;
367
368 if (points.first().x() != 0.0 || points.first().y() != 0.0 ||
369 points.last().x() != 1.0 || points.last().y() != 1.0) {
370 return false;
371 }
372
373 for (int i = 1; i < points.size() - 1; i++) {
374 if (!qFuzzyCompare(points[i].x(), points[i].y())) {
375 return false;
376 }
377 }
378
379 return true;
380}

References d, points, and qFuzzyCompare().

◆ keepSorted()

void KisCubicCurve::keepSorted ( )

◆ name()

const QString & KisCubicCurve::name ( ) const

◆ operator=()

KisCubicCurve & KisCubicCurve::operator= ( const KisCubicCurve & curve)

Definition at line 253 of file kis_cubic_curve.cpp.

254{
255 if (&curve != this) {
256 *d = *curve.d;
257 }
258 return *this;
259}

References d.

◆ operator==()

bool KisCubicCurve::operator== ( const KisCubicCurve & curve) const

Definition at line 261 of file kis_cubic_curve.cpp.

262{
263 if (d->data == curve.d->data) return true;
264 return d->data->points == curve.d->data->points;
265}

References d.

◆ points()

Q_DECL_DEPRECATED QList< QPointF > KisCubicCurve::points ( ) const

Deprecated. Use curvePoints instead

◆ removePoint()

void KisCubicCurve::removePoint ( int idx)

Definition at line 357 of file kis_cubic_curve.cpp.

358{
359 d->data.detach();
360 d->data->points.removeAt(idx);
361 d->data->invalidate();
362}

References d.

◆ setName()

void KisCubicCurve::setName ( const QString & name)

This allows us to carry around a display name for the curve internally. It is used currently in Sketch for perchannel, but would potentially be useful anywhere curves are used in the UI

Definition at line 428 of file kis_cubic_curve.cpp.

429{
430 d->data->name = name;
431}

References d, and name.

◆ setPoint() [1/3]

void KisCubicCurve::setPoint ( int idx,
const KisCubicCurvePoint & point )

Definition at line 304 of file kis_cubic_curve.cpp.

305{
306 d->data.detach();
307 d->data->points[idx] = point;
308 d->data->keepSorted();
309 d->data->invalidate();
310}

References d.

◆ setPoint() [2/3]

void KisCubicCurve::setPoint ( int idx,
const QPointF & position )

Definition at line 317 of file kis_cubic_curve.cpp.

318{
319 setPointPosition(idx, position);
320}
void setPointPosition(int idx, const QPointF &position)

References setPointPosition().

◆ setPoint() [3/3]

void KisCubicCurve::setPoint ( int idx,
const QPointF & position,
bool setAsCorner )

Definition at line 312 of file kis_cubic_curve.cpp.

313{
314 setPoint(idx, { position, setAsCorner });
315}
void setPoint(int idx, const KisCubicCurvePoint &point)

References setPoint().

◆ setPointAsCorner()

void KisCubicCurve::setPointAsCorner ( int idx,
bool setAsCorner )

Definition at line 330 of file kis_cubic_curve.cpp.

331{
332 d->data.detach();
333 d->data->points[idx].setAsCorner(setAsCorner);
334 d->data->invalidate();
335}

References d.

◆ setPointPosition()

void KisCubicCurve::setPointPosition ( int idx,
const QPointF & position )

Definition at line 322 of file kis_cubic_curve.cpp.

323{
324 d->data.detach();
325 d->data->points[idx].setPosition(position);
326 d->data->keepSorted();
327 d->data->invalidate();
328}

References d.

◆ setPoints() [1/2]

void KisCubicCurve::setPoints ( const QList< KisCubicCurvePoint > & points)

Definition at line 297 of file kis_cubic_curve.cpp.

298{
299 d->data.detach();
300 d->data->points = points;
301 d->data->invalidate();
302}

References d, and points.

◆ setPoints() [2/2]

void KisCubicCurve::setPoints ( const QList< QPointF > & points)

Definition at line 287 of file kis_cubic_curve.cpp.

288{
289 d->data.detach();
290 d->data->points.clear();
291 Q_FOREACH(const QPointF &p, points) {
292 d->data->points.append({ p, false });
293 }
294 d->data->invalidate();
295}

References d, p, and points.

◆ toString()

QString KisCubicCurve::toString ( ) const

Definition at line 433 of file kis_cubic_curve.cpp.

434{
435 // See comments in KisCubicCurve(const QString &curveString) for the
436 // specification of the string format
437
438 QString sCurve;
439
440 if(d->data->points.count() < 1)
441 return sCurve;
442
443 Q_FOREACH (const KisCubicCurvePoint &point, d->data->points) {
444 sCurve += QString::number(point.x());
445 sCurve += ',';
446 sCurve += QString::number(point.y());
447 if (point.isSetAsCorner()) {
448 sCurve += ',';
449 sCurve += "is_corner";
450 }
451 sCurve += ';';
452 }
453
454 return sCurve;
455}
bool isSetAsCorner() const

References d, KisCubicCurvePoint::isSetAsCorner(), KisCubicCurvePoint::x(), and KisCubicCurvePoint::y().

◆ uint16Transfer()

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

Definition at line 462 of file kis_cubic_curve.cpp.

463{
464 d->data->updateTransfer<quint16, int>(&d->data->u16Transfer, d->data->validU16Transfer, 0x0, 0xFFFF, size);
465 return d->data->u16Transfer;
466}

References d.

◆ updateSpline()

void KisCubicCurve::updateSpline ( )

◆ updateTransfer()

template<typename _T_ , typename _T2_ >
void KisCubicCurve::updateTransfer ( QVector< _T_ > * transfer,
bool & valid,
_T2_ min,
_T2_ max,
int size )

◆ value() [1/2]

qreal KisCubicCurve::value ( qreal x)

◆ value() [2/2]

qreal KisCubicCurve::value ( qreal x) const

Definition at line 267 of file kis_cubic_curve.cpp.

268{
269 qreal value = d->data->value(x);
270 return value;
271}
qreal value(qreal x)

References d, and value().

Member Data Documentation

◆ d

Private* const KisCubicCurve::d {nullptr}
private

Definition at line 119 of file kis_cubic_curve.h.

119{nullptr};

◆ data

QSharedDataPointer<Data> KisCubicCurve::data

Definition at line 155 of file kis_cubic_curve.cpp.

◆ fTransfer

QVector<qreal> KisCubicCurve::fTransfer
mutable

Definition at line 94 of file kis_cubic_curve.cpp.

◆ name

const QString & KisCubicCurve::name
mutable

Definition at line 86 of file kis_cubic_curve.cpp.

◆ points

QList< QPointF > KisCubicCurve::points

Definition at line 88 of file kis_cubic_curve.cpp.

◆ spline

KisCubicSpline<KisCubicCurvePoint, qreal> KisCubicCurve::spline
mutable

Definition at line 87 of file kis_cubic_curve.cpp.

◆ u16Transfer

QVector<quint16> KisCubicCurve::u16Transfer
mutable

Definition at line 92 of file kis_cubic_curve.cpp.

◆ u8Transfer

QVector<quint8> KisCubicCurve::u8Transfer
mutable

Definition at line 90 of file kis_cubic_curve.cpp.

◆ validFTransfer

bool KisCubicCurve::validFTransfer {false}
mutable

Definition at line 95 of file kis_cubic_curve.cpp.

95{false};

◆ validSpline

bool KisCubicCurve::validSpline {false}
mutable

Definition at line 89 of file kis_cubic_curve.cpp.

89{false};

◆ validU16Transfer

bool KisCubicCurve::validU16Transfer {false}
mutable

Definition at line 93 of file kis_cubic_curve.cpp.

93{false};

◆ validU8Transfer

bool KisCubicCurve::validU8Transfer {false}
mutable

Definition at line 91 of file kis_cubic_curve.cpp.

91{false};

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