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, QColor black, QColor white)
 
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 98 of file kis_painting_tweaks.cpp.

99{
100 const qreal r2 = 1.0 - r1;
101
102 return QColor::fromRgbF(
103 c1.redF() * r1 + c2.redF() * r2,
104 c1.greenF() * r1 + c2.greenF() * r2,
105 c1.blueF() * r1 + c2.blueF() * r2);
106}
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 108 of file kis_painting_tweaks.cpp.

109{
110 const qreal dr = c1.redF() - c2.redF();
111 const qreal dg = c1.greenF() - c2.greenF();
112 const qreal db = c1.blueF() - c2.blueF();
113
114 return std::sqrt(2 * pow2(dr) + 4 * pow2(dg) + 3 * pow2(db));
115}
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 117 of file kis_painting_tweaks.cpp.

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

References colorDifference().

◆ initAntsPen()

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

Definition at line 41 of file kis_painting_tweaks.cpp.

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

◆ 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 169 of file kis_painting_tweaks.cpp.

170{
171 qreal r = c.redF();
172 qreal g = c.greenF();
173 qreal b = c.blueF();
174 if (sRGBtrc) {
175 if (r < 1.0) {
176 r = sRgbTRCToLinear.upperBound(r).value();
177 }
178 if (g < 1.0) {
179 g = sRgbTRCToLinear.upperBound(g).value();
180 }
181 if (b < 1.0) {
182 b = sRgbTRCToLinear.upperBound(b).value();
183 }
184 }
185 qreal lumi = (r * .2126) + (g * .7152) + (b * .0722);
186 if (sRGBtrc && lumi < 1.0) {
187 lumi = linearToSRGBTRC.lowerBound(lumi).value();
188 }
189 return lumi;
190}
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 127 of file kis_painting_tweaks.h.

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

◆ rectToVertices()

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

Definition at line 117 of file kis_painting_tweaks.h.

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

◆ 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 155 of file kis_painting_tweaks.cpp.

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

◆ 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 141 of file kis_painting_tweaks.cpp.

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