From: Till Theato Date: Thu, 6 Jan 2011 20:54:09 +0000 (+0000) Subject: Bezier Spline: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d62dc84c034423b48e37ede84b8bf20e25608f27;p=kdenlive Bezier Spline: - add modes Saturation and Hue (were missing from XML GUI) - document - some small cleanups svn path=/trunk/kdenlive/; revision=5279 --- diff --git a/effects/frei0r_bezier_curves.xml b/effects/frei0r_bezier_curves.xml index 5df3f464..5bdc3c9a 100644 --- a/effects/frei0r_bezier_curves.xml +++ b/effects/frei0r_bezier_curves.xml @@ -4,7 +4,7 @@ Color curves adjustment Till Theato, Maksim Golovkin - + Channel @@ -13,6 +13,6 @@ - Bézier Curve(Spline) Widget + Bézier Spline Widget diff --git a/src/beziercurve/beziersplineeditor.h b/src/beziercurve/beziersplineeditor.h index 819ac4f5..eee65c8c 100644 --- a/src/beziercurve/beziersplineeditor.h +++ b/src/beziercurve/beziersplineeditor.h @@ -74,18 +74,24 @@ private: modes m_mode; int m_zoomLevel; int m_gridLines; - /** Whether to show only handles for the selected point for all points. */ + /** Whether to show handles for all points or only for the selected one. */ bool m_showAllHandles; + /** Background */ QPixmap m_pixmap; + /** A copy of m_pixmap but scaled to fit the size of the edit region */ QPixmap *m_pixmapCache; + /** Whether we have to regenerate the pixmap cache because the pixmap or the size of the edit region changed. */ bool m_pixmapIsDirty; int m_currentPointIndex; point_types m_currentPointType; double m_grabOffsetX; double m_grabOffsetY; + /** selected point before it was modified by dragging (at the time of the mouse press) */ BPoint m_grabPOriginal; + /** point with the index currentPointIndex + 1 at the time of the mouse press */ BPoint m_grabPNext; + /** point with the index currentPointIndex - 1 at the time of the mouse press */ BPoint m_grabPPrevious; /** @brief Finds the point nearest to @param p and returns it's index. diff --git a/src/beziercurve/cubicbezierspline.cpp b/src/beziercurve/cubicbezierspline.cpp index 881d20af..9a2be606 100644 --- a/src/beziercurve/cubicbezierspline.cpp +++ b/src/beziercurve/cubicbezierspline.cpp @@ -168,7 +168,11 @@ void CubicBezierSpline::keepSorted() QPointF CubicBezierSpline::point(double t, const QList< QPointF >& points) { - // coefficients from Bernstein basis polynomial of degree 3 + /* + * Calculating a point on the bezier curve using the coefficients from Bernstein basis polynomial of degree 3. + * Using the De Casteljau algorithm would be slightly faster for when calculating a lot of values + * but the difference is far from noticable in this needcase + */ double c1 = (1-t) * (1-t) * (1-t); double c2 = 3 * t * (1-t) * (1-t); double c3 = 3 * t * t * (1-t); @@ -195,7 +199,7 @@ void CubicBezierSpline::update() << m_points.at(i+1).h1 << m_points.at(i+1).p; - int numberOfValues = (int)((points[3].x() - points[0].x()) * m_precision * 5); + int numberOfValues = (int)((points[3].x() - points[0].x()) * m_precision * 10); if (numberOfValues == 0) numberOfValues = 1; double step = 1 / (double)numberOfValues; diff --git a/src/beziercurve/cubicbezierspline.h b/src/beziercurve/cubicbezierspline.h index ebf15e3d..d28b0ae8 100644 --- a/src/beziercurve/cubicbezierspline.h +++ b/src/beziercurve/cubicbezierspline.h @@ -33,15 +33,40 @@ public: CubicBezierSpline(const CubicBezierSpline &spline, QObject* parent = 0); CubicBezierSpline& operator=(const CubicBezierSpline &spline); + /** @brief Loads the points from the string @param spline. + * + * x, y values have to be separated with a ';' + * handles and points with a '#' + * and the nodes with a '|' + * So that you get: h1x;h1y#px;py#h2x;h2y|h1x;h1y#... */ void fromString(const QString &spline); + /** @brief Returns the points stoed in a string. + * + * x, y values have are separated with a ';' + * handles and points with a '#' + * and the nodes with a '|' + * So that you get: h1x;h1y#px;py#h2x;h2y|h1x;h1y#... */ QString toString() const; + /** @brief Returns a list of the points defining the spline. */ QList points(); + /** @brief Finds the closest point in the pre-calculated spline to @param x. + * @param x x value + * @param cont (default = false) Whether to start searching at the previously requested x and skip all values before it. + This makes requesting a lot of increasing x's faster. */ qreal value(qreal x, bool cont = false); + /** @brief Sets the point at index @param ix to @param point and returns its index (it might have changed during validation). */ int setPoint(int ix, const BPoint &point); + /** @brief Adds @param point and returns its index. */ int addPoint(const BPoint &point); + /** @brief Removes the point at @param ix. */ void removePoint(int ix); + + /** @brief Sets the precision to @param pre. + * + * The precision influences the number of points that are calculated for the spline: + * number of values = precision * 10 */ void setPrecision(int pre); int getPrecision(); @@ -53,11 +78,13 @@ private: int indexOf(const BPoint &p); QList m_points; + /** x, y pairs */ QMap m_spline; + /** iterator used when searching for a value in in continue mode (see @function value). */ QMap ::const_iterator m_i; + /** Whether the spline represents the points and the precision. */ bool m_validSpline; int m_precision; - }; #endif diff --git a/src/widgets/bezierspline_ui.ui b/src/widgets/bezierspline_ui.ui index f7c5f0b2..efac92ae 100644 --- a/src/widgets/bezierspline_ui.ui +++ b/src/widgets/bezierspline_ui.ui @@ -6,15 +6,21 @@ 0 0 - 351 - 78 + 345 + 67 Form - + + 0 + + + 0 + + @@ -205,7 +211,7 @@ - + Show background indicating changes caused by modifying the curve. @@ -224,7 +230,7 @@ - + ... @@ -234,7 +240,7 @@ - + ... @@ -244,7 +250,7 @@ - + Increases the number of lines in the grid.<br />After 8 lines it will begin from 0 again. @@ -257,7 +263,7 @@ - + Qt::Horizontal @@ -270,7 +276,7 @@ - + Reset the selected spline @@ -283,7 +289,7 @@ - + Show handles for all points or only for the selected one @@ -302,6 +308,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + +