Debian Codegraph @

libs/image/kis_cubic_curve.h

raw symbols SCIP
1 /*
2 * SPDX-FileCopyrightText: 2010 Cyrille Berger <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef _KIS_CUBIC_CURVE_H_
8 #define _KIS_CUBIC_CURVE_H_
9
10 #include <boost/operators.hpp>
11
12 #include<QList>
13 #include<QVector>
14 #include<QPointF>
15 #include<QVariant>
16
17 #include "kis_cubic_curve_spline.h"
18
19 #include <kritaimage_export.h>
20
21 const QString DEFAULT_CURVE_STRING = "0,0;1,1;";
22
23 class KRITAIMAGE_EXPORT KisCubicCurvePoint
24 {
25 public:
26 KisCubicCurvePoint() = default;
27 KisCubicCurvePoint(const KisCubicCurvePoint&) = default;
28 KisCubicCurvePoint(const QPointF &position, bool setAsCorner = false);
29 KisCubicCurvePoint(qreal x, qreal y, bool setAsCorner = false);
30 KisCubicCurvePoint& operator=(const KisCubicCurvePoint&) = default;
31
32 bool operator==(const KisCubicCurvePoint &other) const;
33
34 qreal x() const;
35 qreal y() const;
36 const QPointF& position() const;
37 bool isSetAsCorner() const;
38
39 void setX(qreal newX);
40 void setY(qreal newY);
41 void setPosition(const QPointF &newPosition);
42 void setAsCorner(bool newIsSetAsCorner);
43
44 private:
45 QPointF m_position;
46 bool m_isCorner { false };
47 };
48
49 Q_DECLARE_METATYPE(KisCubicCurvePoint)
50
51 /**
52 * Hold the data for a cubic curve.
53 */
54 class KRITAIMAGE_EXPORT KisCubicCurve : public boost::equality_comparable<KisCubicCurve>
55 {
56 public:
57 KisCubicCurve();
58
59 KisCubicCurve(const QList<QPointF>& points);
60 KisCubicCurve(const QList<KisCubicCurvePoint>& points);
61
62 KisCubicCurve(const QString &curveString);
63 KisCubicCurve(const KisCubicCurve& curve);
64 ~KisCubicCurve();
65 KisCubicCurve& operator=(const KisCubicCurve& curve);
66 bool operator==(const KisCubicCurve& curve) const;
67 public:
68 qreal value(qreal x) const;
69 /**
70 * Deprecated. Use curvePoints instead
71 */
72 Q_DECL_DEPRECATED QList<QPointF> points() const;
73 const QList<KisCubicCurvePoint>& curvePoints() const;
74 void setPoints(const QList<QPointF>& points);
75 void setPoints(const QList<KisCubicCurvePoint>& points);
76 void setPoint(int idx, const KisCubicCurvePoint& point);
77 void setPoint(int idx, const QPointF& position, bool setAsCorner);
78 void setPoint(int idx, const QPointF& position);
79 void setPointPosition(int idx, const QPointF& position);
80 void setPointAsCorner(int idx, bool setAsCorner);
81 /**
82 * Add a point to the curve, the list of point is always sorted.
83 * @return the index of the inserted point
84 */
85 int addPoint(const KisCubicCurvePoint& point);
86 int addPoint(const QPointF& position, bool setAsCorner);
87 int addPoint(const QPointF& position);
88 void removePoint(int idx);
89
90 /*
91 * Check whether the curve maps all values to themselves.
92 */
93 bool isIdentity() const;
94
95 /*
96 * Check whether the curve maps all values to given constant.
97 */
98 bool isConstant(qreal c) const;
99
100 /**
101 * This allows us to carry around a display name for the curve internally. It is used
102 * currently in Sketch for perchannel, but would potentially be useful anywhere
103 * curves are used in the UI
104 */
105 void setName(const QString& name);
106 const QString& name() const;
107
108 static qreal interpolateLinear(qreal normalizedValue, const QVector<qreal> &transfer);
109
110 public:
111 const QVector<quint16> uint16Transfer(int size = 256) const;
112 const QVector<qreal> floatTransfer(int size = 256) const;
113 public:
114 QString toString() const;
115 Q_DECL_DEPRECATED void fromString(const QString&);
116 private:
117 struct Data;
118 struct Private;
119 Private* const d {nullptr};
120 };
121
122 Q_DECLARE_METATYPE(KisCubicCurve)
123
124 #endif