Commit 2f888b32 authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Fix NaN values from hairy brushes

A hairy brush with ink deplation enabled for opacity, without
weights, would use unitialized data from Bristle::m_inkAmount
which would later get converted from double to float.

Bristle members are now always initialized, and intermediary
values clamped to correct range.

CCBUG: 344437
parent a6a6626b
......@@ -18,26 +18,13 @@
#include "bristle.h"
Bristle::Bristle()
{
init(0, 0, 0);
}
Bristle::Bristle(float x, float y, float length)
{
init(x, y, length);
}
void Bristle::init(float x, float y, float length)
{
m_x = x;
m_y = y;
m_prevX = x;
m_prevY = y;
m_length = length;
m_counter = 0;
m_enabled = true;
}
: m_x(x)
, m_y(y)
, m_prevX(x)
, m_prevY(y)
, m_length(length)
{}
Bristle::~Bristle()
{
......
......@@ -26,8 +26,8 @@ class Bristle
{
public:
Bristle() = default;
Bristle(float x, float y, float length);
Bristle();
~Bristle();
inline float x() const {
......@@ -102,18 +102,18 @@ private:
void init(float x, float y, float length);
// coordinates of bristle
float m_x;
float m_y;
float m_prevX;
float m_prevY;
float m_length; // z - coordinate
float m_x{0.0f};
float m_y{0.0f};
float m_prevX{0.0f};
float m_prevY{0.0f};
float m_length{0.0f}; // z - coordinate
KoColor m_color;
float m_inkAmount;
float m_inkAmount{0.0f};
// new dimension in bristle
int m_counter;
int m_counter{0};
bool m_enabled;
bool m_enabled{true};
};
#endif
......@@ -284,19 +284,18 @@ void HairyBrush::opacityDepletion(Bristle* bristle, KoColor& bristleColor, qreal
{
qreal opacity = OPACITY_OPAQUE_F;
if (m_properties->useWeights) {
opacity = qBound(0.0,
(pressure * m_properties->pressureWeight) +
(bristle->length() * m_properties->bristleLengthWeight) +
(bristle->inkAmount() * m_properties->bristleInkAmountWeight) +
((1.0 - inkDeplation) * m_properties->inkDepletionWeight), 1.0);
opacity = pressure * m_properties->pressureWeight +
bristle->length() * m_properties->bristleLengthWeight +
bristle->inkAmount() * m_properties->bristleInkAmountWeight +
(1.0 - inkDeplation) * m_properties->inkDepletionWeight;
}
else {
opacity =
bristle->length() *
bristle->inkAmount();
}
bristleColor.setOpacity(opacity);
opacity = qBound(0.0, opacity, 1.0);
}
inline void HairyBrush::addBristleInk(Bristle *bristle,const QPointF &pos, const KoColor &color)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment