File indexing completed on 2024-05-12 15:58:13

0001 /*
0002  *  SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef _KIS_CUBIC_CURVE_H_
0008 #define _KIS_CUBIC_CURVE_H_
0009 
0010 #include<QList>
0011 #include<QVector>
0012 #include<QVariant>
0013 
0014 #include <kritaimage_export.h>
0015 
0016 class QPointF;
0017 
0018 const QString DEFAULT_CURVE_STRING = "0,0;1,1;";
0019 
0020 /**
0021  * Hold the data for a cubic curve.
0022  */
0023 class KRITAIMAGE_EXPORT KisCubicCurve
0024 {
0025 public:
0026     KisCubicCurve();
0027     KisCubicCurve(const QList<QPointF>& points);
0028     KisCubicCurve(const QVector<QPointF>& points);
0029     KisCubicCurve(const KisCubicCurve& curve);
0030     ~KisCubicCurve();
0031     KisCubicCurve& operator=(const KisCubicCurve& curve);
0032     bool operator==(const KisCubicCurve& curve) const;
0033 public:
0034     qreal value(qreal x) const;
0035     const QList<QPointF>& points() const;
0036     void setPoints(const QList<QPointF>& points);
0037     void setPoint(int idx, const QPointF& point);
0038     /**
0039      * Add a point to the curve, the list of point is always sorted.
0040      * @return the index of the inserted point
0041      */
0042     int addPoint(const QPointF& point);
0043     void removePoint(int idx);
0044 
0045     /*
0046      * Check whether the curve maps all values to themselves.
0047      */
0048     bool isIdentity() const;
0049 
0050     /*
0051      * Check whether the curve maps all values to given constant.
0052      */
0053     bool isConstant(qreal c) const;
0054 
0055     /**
0056      * This allows us to carry around a display name for the curve internally. It is used
0057      * currently in Sketch for perchannel, but would potentially be useful anywhere
0058      * curves are used in the UI
0059      */
0060     void setName(const QString& name);
0061     const QString& name() const;
0062 
0063     static qreal interpolateLinear(qreal normalizedValue, const QVector<qreal> &transfer);
0064 
0065 public:
0066     const QVector<quint16> uint16Transfer(int size = 256) const;
0067     const QVector<qreal> floatTransfer(int size = 256) const;
0068 public:
0069     QString toString() const;
0070     void fromString(const QString&);
0071 private:
0072     struct Data;
0073     struct Private;
0074     Private* const d {nullptr};
0075 };
0076 
0077 Q_DECLARE_METATYPE(KisCubicCurve)
0078 
0079 #endif