Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaintingTweaks Namespace Reference

Classes

class  PenBrushSaver
 

Functions

QColor blendColors (const QColor &c1, const QColor &c2, qreal r1)
 
qreal colorDifference (const QColor &c1, const QColor &c2)
 
void dragColor (QColor *color, const QColor &baseColor, qreal threshold)
 
void initAntsPen (QPen *antsPen, QPen *outlinePen, int antLength, int antSpace)
 
qreal luminosityCoarse (const QColor &c, bool sRGBtrc=true)
 luminosityCoarse This calculates the luminosity of the given QColor. It uses a very coarse (10 step) lut to linearize the sRGB trc, and then uses rec709 values to calculate the luminosity. Because of the effect of linearization, this is still more precise than one that just calculates based on coefficients.
 
void rectToTexCoords (QVector2D *texCoords, const QRectF &rc)
 
void rectToVertices (QVector3D *vertices, const QRectF &rc)
 
QRect safeClipBoundingRect (const QPainter &painter)
 
QRegion safeClipRegion (const QPainter &painter)
 

Variables

static QMap< qreal, qreal > linearToSRGBTRC
 
static QMap< qreal, qreal > sRgbTRCToLinear
 

Function Documentation

◆ blendColors()

QColor KRITAGLOBAL_EXPORT KisPaintingTweaks::blendColors ( const QColor & c1,
const QColor & c2,
qreal r1 )

Definition at line 97 of file kis_painting_tweaks.cpp.

98{
99 const qreal r2 = 1.0 - r1;
100
101 return QColor::fromRgbF(
102 c1.redF() * r1 + c2.redF() * r2,
103 c1.greenF() * r1 + c2.greenF() * r2,
104 c1.blueF() * r1 + c2.blueF() * r2);
105}
QPointF r2
QPointF r1

References r1, and r2.

◆ colorDifference()

qreal KRITAGLOBAL_EXPORT KisPaintingTweaks::colorDifference ( const QColor & c1,
const QColor & c2 )
Returns
an approximate difference between c1 and c2 in a (nonlinear) range [0, 3]

The colors are compared using the formula: difference = sqrt(2 * diff_R^2 + 4 * diff_G^2 + 3 * diff_B^2)

Definition at line 107 of file kis_painting_tweaks.cpp.

108{
109 const qreal dr = c1.redF() - c2.redF();
110 const qreal dg = c1.greenF() - c2.greenF();
111 const qreal db = c1.blueF() - c2.blueF();
112
113 return std::sqrt(2 * pow2(dr) + 4 * pow2(dg) + 3 * pow2(db));
114}
T pow2(const T &x)
Definition kis_global.h:166

References pow2().

◆ dragColor()

void KRITAGLOBAL_EXPORT KisPaintingTweaks::dragColor ( QColor * color,
const QColor & baseColor,
qreal threshold )

Make the color color differ from baseColor for at least threshold value

Definition at line 116 of file kis_painting_tweaks.cpp.

117{
118 while (colorDifference(*color, baseColor) < threshold) {
119
120 QColor newColor = *color;
121
122 if (newColor.lightnessF() > baseColor.lightnessF()) {
123 newColor = newColor.lighter(120);
124 } else {
125 newColor = newColor.darker(120);
126 }
127
128 if (newColor == *color) {
129 break;
130 }
131
132 *color = newColor;
133 }
134}
qreal colorDifference(const QColor &c1, const QColor &c2)

References colorDifference().

◆ initAntsPen()

KRITAGLOBAL_EXPORT void KisPaintingTweaks::initAntsPen ( QPen * antsPen,
QPen * outlinePen,
int antLength,
int antSpace )

Definition at line 41 of file kis_painting_tweaks.cpp.

43{
44 QVector<qreal> antDashPattern;
45 antDashPattern << antLength << antSpace;
46
47 *antsPen = QPen(Qt::CustomDashLine);
48 antsPen->setDashPattern(antDashPattern);
49 antsPen->setCosmetic(true);
50 antsPen->setColor(Qt::black);
51
52 *outlinePen = QPen(Qt::SolidLine);
53 outlinePen->setCosmetic(true);
54 outlinePen->setColor(Qt::white);
55}

◆ luminosityCoarse()

qreal KRITAGLOBAL_EXPORT KisPaintingTweaks::luminosityCoarse ( const QColor & c,
bool sRGBtrc = true )

luminosityCoarse This calculates the luminosity of the given QColor. It uses a very coarse (10 step) lut to linearize the sRGB trc, and then uses rec709 values to calculate the luminosity. Because of the effect of linearization, this is still more precise than one that just calculates based on coefficients.

Parameters
cthe color to calculate the luminosity of.
sRGBtrcwhether to linearize the sRGB trc.
Returns
a delinearized luminosity value, quantized to steps of 0.1.

Definition at line 168 of file kis_painting_tweaks.cpp.

169{
170 qreal r = c.redF();
171 qreal g = c.greenF();
172 qreal b = c.blueF();
173 if (sRGBtrc) {
174 if (r < 1.0) {
175 r = sRgbTRCToLinear.upperBound(r).value();
176 }
177 if (g < 1.0) {
178 g = sRgbTRCToLinear.upperBound(g).value();
179 }
180 if (b < 1.0) {
181 b = sRgbTRCToLinear.upperBound(b).value();
182 }
183 }
184 qreal lumi = (r * .2126) + (g * .7152) + (b * .0722);
185 if (sRGBtrc && lumi < 1.0) {
186 lumi = linearToSRGBTRC.lowerBound(lumi).value();
187 }
188 return lumi;
189}
static QMap< qreal, qreal > linearToSRGBTRC
static QMap< qreal, qreal > sRgbTRCToLinear

References linearToSRGBTRC, and sRgbTRCToLinear.

◆ rectToTexCoords()

void KisPaintingTweaks::rectToTexCoords ( QVector2D * texCoords,
const QRectF & rc )
inline

Definition at line 126 of file kis_painting_tweaks.h.

127 {
128 texCoords[0] = QVector2D(rc.left(), rc.bottom());
129 texCoords[1] = QVector2D(rc.left(), rc.top());
130 texCoords[2] = QVector2D(rc.right(), rc.bottom());
131 texCoords[3] = QVector2D(rc.left(), rc.top());
132 texCoords[4] = QVector2D(rc.right(), rc.top());
133 texCoords[5] = QVector2D(rc.right(), rc.bottom());
134 }

◆ rectToVertices()

void KisPaintingTweaks::rectToVertices ( QVector3D * vertices,
const QRectF & rc )
inline

Definition at line 116 of file kis_painting_tweaks.h.

117 {
118 vertices[0] = QVector3D(rc.left(), rc.bottom(), 0.f);
119 vertices[1] = QVector3D(rc.left(), rc.top(), 0.f);
120 vertices[2] = QVector3D(rc.right(), rc.bottom(), 0.f);
121 vertices[3] = QVector3D(rc.left(), rc.top(), 0.f);
122 vertices[4] = QVector3D(rc.right(), rc.top(), 0.f);
123 vertices[5] = QVector3D(rc.right(), rc.bottom(), 0.f);
124 }

◆ safeClipBoundingRect()

KRITAGLOBAL_EXPORT QRect KisPaintingTweaks::safeClipBoundingRect ( const QPainter & painter)
See also
safeClipRegion()

Definition at line 36 of file kis_painting_tweaks.cpp.

37{
38 return painter.clipBoundingRect().toAlignedRect();
39}

◆ safeClipRegion()

KRITAGLOBAL_EXPORT QRegion KisPaintingTweaks::safeClipRegion ( const QPainter & painter)

This is a workaround for QPainter::clipRegion() bug. When zoom is about 2000% and rotation is in a range[-5;5] degrees, the generated region will have about 20k+ rectangles inside. Their processing will be really slow. These functions work around the issue.

Definition at line 20 of file kis_painting_tweaks.cpp.

21{
22 const QTransform t = painter.transform();
23
24 QRegion region = t.type() <= QTransform::TxScale ?
25 painter.clipRegion() :
26 QRegion(painter.clipBoundingRect().toAlignedRect());
27
28 if (region.rectCount() > 1000) {
29 qWarning() << "WARNING: KisPaintingTweaks::safeClipRegion: too many rectangles in the region!" << ppVar(region.rectCount());
30 region = QRegion(painter.clipBoundingRect().toAlignedRect());
31 }
32
33 return region;
34}
#define ppVar(var)
Definition kis_debug.h:155

References ppVar.

Variable Documentation

◆ linearToSRGBTRC

QMap<qreal, qreal> KisPaintingTweaks::linearToSRGBTRC
static
Initial value:
{
{0.0, 0.0},
{0.01002, 0.1},
{0.0331, 0.2},
{0.07324, 0.3},
{0.13287, 0.4},
{0.21404, 0.5},
{0.31855, 0.6},
{0.44799, 0.7},
{0.60383, 0.8},
{0.78741, 0.9},
{1.0, 1.0}
}

Definition at line 154 of file kis_painting_tweaks.cpp.

154 {
155 {0.0, 0.0},
156 {0.01002, 0.1},
157 {0.0331, 0.2},
158 {0.07324, 0.3},
159 {0.13287, 0.4},
160 {0.21404, 0.5},
161 {0.31855, 0.6},
162 {0.44799, 0.7},
163 {0.60383, 0.8},
164 {0.78741, 0.9},
165 {1.0, 1.0}
166};

◆ sRgbTRCToLinear

QMap<qreal, qreal> KisPaintingTweaks::sRgbTRCToLinear
static
Initial value:
{
{0.0, 0.0},
{0.1, 0.01002},
{0.2, 0.0331},
{0.3, 0.07324},
{0.4, 0.13287},
{0.5, 0.21404},
{0.6, 0.31855},
{0.7, 0.44799},
{0.8, 0.60383},
{0.9, 0.78741},
{1.0, 1.0}
}

Definition at line 140 of file kis_painting_tweaks.cpp.

140 {
141 {0.0, 0.0},
142 {0.1, 0.01002},
143 {0.2, 0.0331},
144 {0.3, 0.07324},
145 {0.4, 0.13287},
146 {0.5, 0.21404},
147 {0.6, 0.31855},
148 {0.7, 0.44799},
149 {0.8, 0.60383},
150 {0.9, 0.78741},
151 {1.0, 1.0}
152};