File indexing completed on 2024-05-19 04:26:10

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