Krita Source Code Documentation
Loading...
Searching...
No Matches
KisGradientPainter Class Reference

#include <kis_gradient_painter.h>

+ Inheritance diagram for KisGradientPainter:

Classes

struct  ProcessRegion
 

Public Types

enum  enumDither {
  DitherNone , DitherBlueNoise , DitherBayer2 , DitherBayer4 ,
  DitherBayer8
}
 
enum  enumGradientRepeat { GradientRepeatNone , GradientRepeatForwards , GradientRepeatAlternate }
 
enum  enumGradientShape {
  GradientShapeLinear , GradientShapeBiLinear , GradientShapeRadial , GradientShapeSquare ,
  GradientShapeConical , GradientShapeConicalSymetric , GradientShapeSpiral , GradientShapeReverseSpiral ,
  GradientShapePolygonal
}
 
- Public Types inherited from KisPainter
enum  FillStyle {
  FillStyleNone , FillStyleForegroundColor , FillStyleBackgroundColor , FillStylePattern ,
  FillStyleGenerator
}
 This enum contains the styles with which we can fill things like polygons and ellipses. More...
 
enum  StrokeStyle { StrokeStyleNone , StrokeStyleBrush }
 The style of the brush stroke around polygons and so. More...
 

Public Member Functions

 KisGradientPainter ()
 
 KisGradientPainter (KisPaintDeviceSP device)
 
 KisGradientPainter (KisPaintDeviceSP device, KisSelectionSP selection)
 
bool paintGradient (const QPointF &gradientVectorStart, const QPointF &gradientVectorEnd, enumGradientRepeat repeat, double antiAliasThreshold, bool reverseGradient, const QRect &applyRect, enumDither dither=DitherNone, int ditherSteps=defaultDitherSteps)
 
template<class T >
bool paintGradient (const QPointF &gradientVectorStart, const QPointF &gradientVectorEnd, enumGradientRepeat repeat, double antiAliasThreshold, bool reverseGradient, enumDither dither, int ditherSteps, const QRect &applyRect, T &paintPolicy)
 
bool paintGradient (const QPointF &gradientVectorStart, const QPointF &gradientVectorEnd, enumGradientRepeat repeat, double antiAliasThreshold, bool reverseGradient, qint32 startx, qint32 starty, qint32 width, qint32 height, enumDither dither=DitherNone, int ditherSteps=defaultDitherSteps)
 
void precalculateShape ()
 
void setGradientShape (enumGradientShape shape)
 
 ~KisGradientPainter () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisPainter
void addDirtyRect (const QRect &r)
 
void addDirtyRects (const QVector< QRect > &rects)
 
bool antiAliasPolygonFill ()
 Return whether a polygon's filled area should be anti-aliased or not.
 
void applyDevice (const QRect &applyRect, const KisRenderedDab &dab, KisRandomAccessorSP dstIt, const KoColorSpace *srcColorSpace, KoCompositeOp::ParameterInfo &localParamInfo)
 
void applyDeviceWithSelection (const QRect &applyRect, const KisRenderedDab &dab, KisRandomAccessorSP dstIt, KisRandomConstAccessorSP maskIt, const KoColorSpace *srcColorSpace, KoCompositeOp::ParameterInfo &localParamInfo)
 
const KoColor & backgroundColor () const
 Returns the current background color.
 
void begin (KisPaintDeviceSP device)
 
void begin (KisPaintDeviceSP device, KisSelectionSP selection)
 
void beginTransaction (const KUndo2MagicString &transactionName=KUndo2MagicString(), int timedID=-1)
 Begin an undoable paint operation.
 
void bitBlt (const QPoint &pos, const KisPaintDeviceSP srcDev, const QRect &srcRect)
 
void bitBlt (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bitBltOldData (const QPoint &pos, const KisPaintDeviceSP srcDev, const QRect &srcRect)
 
void bitBltOldData (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bitBltWithFixedSelection (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, qint32 selX, qint32 selY, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bitBltWithFixedSelection (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, qint32 srcWidth, qint32 srcHeight)
 
void bltFixed (const QPoint &pos, const KisFixedPaintDeviceSP srcDev, const QRect &srcRect)
 
void bltFixed (const QRect &rc, const QList< KisRenderedDab > allSrcDevices)
 
void bltFixed (qint32 dstX, qint32 dstY, const KisFixedPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bltFixedWithFixedSelection (qint32 dstX, qint32 dstY, const KisFixedPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, qint32 selX, qint32 selY, qint32 srcX, qint32 srcY, quint32 srcWidth, quint32 srcHeight)
 
void bltFixedWithFixedSelection (qint32 dstX, qint32 dstY, const KisFixedPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, quint32 srcWidth, quint32 srcHeight)
 
const QVector< QPair< QPointF, QPointF > > calculateAllMirroredPoints (const QPair< QPointF, QPointF > &pair)
 
const QVector< QPointF > calculateAllMirroredPoints (const QPointF &pos)
 
const QVector< QRect > calculateAllMirroredRects (const QRect &rc)
 
template<class T >
QVector< T > calculateMirroredObjects (const T &object)
 
QBitArray channelFlags ()
 
const KoCompositeOp * compositeOp (const KoColorSpace *srcCS)
 
QString compositeOpId ()
 Returns the current composite op Id.
 
void copyMirrorInformationFrom (const KisPainter *other)
 
void deleteTransaction ()
 
KisPaintDeviceSP device ()
 
const KisPaintDeviceSP device () const
 Returns the current paint device.
 
void drawDDALine (const QPointF &start, const QPointF &end)
 
void drawLine (const QPointF &start, const QPointF &end)
 
void drawLine (const QPointF &start, const QPointF &end, qreal width, bool antialias)
 
void drawPainterPath (const QPainterPath &path, const QPen &pen)
 
void drawPainterPath (const QPainterPath &path, const QPen &pen, const QRect &requestedRect)
 
void drawThickLine (const QPointF &start, const QPointF &end, int startWidth, int endWidth)
 
void drawWobblyLine (const QPointF &start, const QPointF &end)
 
void drawWuLine (const QPointF &start, const QPointF &end)
 
void end ()
 
KUndo2Command * endAndTakeTransaction ()
 
void endTransaction (KisPostExecutionUndoAdapter *undoAdapter)
 
void endTransaction (KisUndoAdapter *undoAdapter)
 Finish the undoable paint operation.
 
void fill (qint32 x, qint32 y, qint32 width, qint32 height, const KoColor &color)
 
void fillPainterPath (const QPainterPath &path)
 
void fillPainterPath (const QPainterPath &path, const QRect &requestedRect)
 
void fillPainterPathImpl (const QPainterPath &path, const QRect &requestedRect)
 
FillStyle fillStyle () const
 Returns the current fill style.
 
qreal flow () const
 
const KisFilterConfigurationSP generator () const
 
void getBezierCurvePoints (const QPointF &pos1, const QPointF &control1, const QPointF &control2, const QPointF &pos2, vQPointF &points) const
 
const KoAbstractGradientSP gradient () const
 
bool hasDirtyRegion () const
 
bool hasHorizontalMirroring () const
 
bool hasMirroring () const
 
bool hasVerticalMirroring () const
 
bool isOpacityUnit () const
 
 KisPainter ()
 Construct painter without a device.
 
 KisPainter (KisPaintDeviceSP device)
 Construct a painter, and begin painting on the device.
 
 KisPainter (KisPaintDeviceSP device, KisSelectionSP selection)
 Construct a painter, and begin painting on the device. All actions will be masked by the given selection.
 
void mirrorDab (Qt::Orientation direction, KisRenderedDab *dab, bool skipMirrorPixels=false) const
 
void mirrorRect (Qt::Orientation direction, QRect *rc) const
 
qreal opacityF () const
 Returns the opacity that is used in painting.
 
void paintAt (const KisPaintInformation &pos, KisDistanceInformation *savedDist)
 
void paintBezierCurve (const KisPaintInformation &pi1, const QPointF &control1, const QPointF &control2, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance)
 
const KoColor & paintColor () const
 Returns the color that will be used to paint with.
 
void paintEllipse (const qreal x, const qreal y, const qreal w, const qreal h)
 
void paintEllipse (const QRectF &rect)
 
void paintLine (const KisPaintInformation &pi1, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance)
 
KisPaintOp * paintOp () const
 
void paintPainterPath (const QPainterPath &path)
 
void paintPolygon (const vQPointF &points)
 
void paintPolyline (const QVector< QPointF > &points, int index=0, int numPoints=-1)
 
void paintRect (const qreal x, const qreal y, const qreal w, const qreal h)
 
void paintRect (const QRectF &rect)
 
const KoPatternSP pattern () const
 Returns the currently set pattern.
 
QTransform patternTransform ()
 get the current transform on the pattern.
 
KisPaintOpPresetSP preset () const
 Return the paintop preset.
 
 Private (KisPainter *_q)
 
 Private (KisPainter *_q, const KoColorSpace *cs)
 
void putTransaction (KisTransaction *transaction)
 continue a transaction started somewhere else
 
void renderDabWithMirroringNonIncremental (QRect rc, KisPaintDeviceSP dab)
 
void renderMirrorMask (QRect rc, KisFixedPaintDeviceSP dab)
 
void renderMirrorMask (QRect rc, KisFixedPaintDeviceSP dab, KisFixedPaintDeviceSP mask)
 
void renderMirrorMask (QRect rc, KisPaintDeviceSP dab)
 
void renderMirrorMask (QRect rc, KisPaintDeviceSP dab, int sx, int sy, KisFixedPaintDeviceSP mask)
 
void renderMirrorMaskSafe (QRect rc, KisFixedPaintDeviceSP dab, bool preserveDab)
 
void renderMirrorMaskSafe (QRect rc, KisFixedPaintDeviceSP dab, KisFixedPaintDeviceSP mask, bool preserveDab)
 
void renderMirrorMaskSafe (QRect rc, KisPaintDeviceSP dab, int sx, int sy, KisFixedPaintDeviceSP mask, bool preserveMask)
 
void revertTransaction ()
 Cancel all the changes made by the painter.
 
KisRunnableStrokeJobsInterface * runnableStrokeJobsInterface () const
 
KisSelectionSP selection ()
 
void setAntiAliasPolygonFill (bool antiAliasPolygonFill)
 Set whether a polygon's filled area should be anti-aliased or not. The default is true.
 
void setAverageOpacity (qreal averageOpacity)
 
void setBackgroundColor (const KoColor &color)
 
void setChannelFlags (QBitArray channelFlags)
 
void setColorConversionFlags (KoColorConversionTransformation::ConversionFlags conversionFlags)
 
void setCompositeOpId (const KoCompositeOp *op)
 
void setCompositeOpId (const QString &op)
 Set the composite op for this painter by string.
 
void setFillStyle (FillStyle fillStyle)
 Set the current style with which to fill.
 
void setFlow (qreal flow)
 
void setGenerator (KisFilterConfigurationSP generator)
 Set the current generator (a generator can be used to fill an area.
 
void setGradient (const KoAbstractGradientSP gradient)
 
void setMaskImageSize (qint32 width, qint32 height)
 
void setMirrorInformation (const QPointF &axesCenter, bool mirrorHorizontally, bool mirrorVertically)
 
void setOpacityF (qreal opacity)
 
void setOpacityToUnit ()
 
void setOpacityU8 (quint8 opacity)
 Set the opacity which is used in painting (like filling polygons)
 
void setOpacityUpdateAverage (qreal opacity)
 
void setPaintColor (const KoColor &color)
 
void setPaintOpPreset (KisPaintOpPresetSP preset, KisNodeSP node, KisImageSP image)
 
void setPattern (const KoPatternSP pattern)
 Set the current pattern.
 
void setPatternTransform (QTransform transform)
 Set the transform on the pattern.
 
void setProgress (KoUpdater *progressUpdater)
 
void setRenderingIntent (KoColorConversionTransformation::Intent intent)
 
void setRunnableStrokeJobsInterface (KisRunnableStrokeJobsInterface *interface)
 
void setSelection (KisSelectionSP selection)
 
void setStrokeStyle (StrokeStyle strokeStyle)
 Set the current brush stroke style.
 
StrokeStyle strokeStyle () const
 Returns the current brush stroke style.
 
QVector< QRect > takeDirtyRegion ()
 
KisTransaction * takeTransaction ()
 take transaction out of the reach of KisPainter
 
bool tryReduceSourceRect (const KisPaintDevice *srcDev, QRect *srcRect, qint32 *srcX, qint32 *srcY, qint32 *srcWidth, qint32 *srcHeight, qint32 *dstX, qint32 *dstY)
 
virtual ~KisPainter ()
 

Static Public Member Functions

static bool isBayerDither (enumDither dither)
 
- Static Public Member Functions inherited from KisPainter
static qreal blendAverageOpacity (qreal opacity, qreal averageOpacity)
 
static bool checkDeviceHasTransparency (KisPaintDeviceSP dev)
 
static KisPaintDeviceSP convertToAlphaAsAlpha (KisPaintDeviceSP src)
 
static KisPaintDeviceSP convertToAlphaAsGray (KisPaintDeviceSP src)
 
static KisPaintDeviceSP convertToAlphaAsPureAlpha (KisPaintDeviceSP src)
 
static void copyAreaOptimized (const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
 
static void copyAreaOptimized (const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect, KisSelectionSP selection)
 
static void copyAreaOptimizedOldData (const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
 

Public Attributes

QVector< ProcessRegion > processRegions
 
enumGradientShape shape
 
- Public Attributes inherited from Private
KisCanvas2 * canvas
 
int displayedFrame
 
int intendedFrame
 
- Public Attributes inherited from KisPainter
bool antiAliasPolygonFill {true}
 
QPointF axesCenter
 
KoColor backgroundColor
 
const KoCompositeOp * cachedCompositeOp {nullptr}
 
const KoColorSpace * cachedSourceColorSpace {nullptr}
 
const KoColorSpace * colorSpace {nullptr}
 
QString compositeOpId
 
KoColorConversionTransformation::ConversionFlags conversionFlags {KoColorConversionTransformation::Empty}
 
KoColor customColor
 
KisPaintDeviceSP device
 
QVector< QRect > dirtyRects
 
QPointF duplicateOffset
 
QScopedPointer< KisRunnableStrokeJobsInterface > fakeRunnableStrokeJobsInterface
 
KisFillPainter * fillPainter {nullptr}
 
FillStyle fillStyle {FillStyleNone}
 
KisFilterConfigurationSP generator
 
KoAbstractGradientSP gradient
 
bool isOpacityUnit {true}
 
qint32 maskImageHeight {255}
 
qint32 maskImageWidth {255}
 
QPainter * maskPainter {nullptr}
 
bool mirrorHorizontally {false}
 
bool mirrorVertically {false}
 
KoColor paintColor
 
KisPaintOp * paintOp {nullptr}
 
KisPaintOpPresetSP paintOpPreset
 
KoCompositeOp::ParameterInfo paramInfo
 
KoPatternSP pattern
 
QTransform patternTransform
 
quint32 pixelSize {0}
 
KisPaintDeviceSP polygon
 
QImage polygonMaskImage
 
KoColorProfile * profile {nullptr}
 
KoUpdater * progressUpdater {nullptr}
 
KisPainter * q {nullptr}
 
KoColorConversionTransformation::Intent renderingIntent {KoColorConversionTransformation::IntentPerceptual}
 
KisRunnableStrokeJobsInterface * runnableStrokeJobsInterface {nullptr}
 
KisSelectionSP selection
 
KisPaintLayer * sourceLayer {nullptr}
 
StrokeStyle strokeStyle {StrokeStyleBrush}
 
KisTransaction * transaction {nullptr}
 

Static Public Attributes

static constexpr int defaultDitherSteps = 2
 

Private Attributes

const QScopedPointer< Private > m_d
 

Additional Inherited Members

- Protected Member Functions inherited from KisPainter
void fillPolygon (const vQPointF &points, FillStyle fillStyle)
 Fill the polygon defined by points with the fillStyle.
 
void init ()
 Initialize, set everything to '0' or defaults.
 
KoUpdater * progressUpdater ()
 

Detailed Description

XXX: Docs!

Definition at line 1045 of file kis_gradient_painter.cc.

Member Enumeration Documentation

◆ enumDither

Enumerator
DitherNone 
DitherBlueNoise 
DitherBayer2 
DitherBayer4 
DitherBayer8 

Definition at line 52 of file kis_gradient_painter.h.

◆ enumGradientRepeat

Enumerator
GradientRepeatNone 
GradientRepeatForwards 
GradientRepeatAlternate 

Definition at line 46 of file kis_gradient_painter.h.

◆ enumGradientShape

Enumerator
GradientShapeLinear 
GradientShapeBiLinear 
GradientShapeRadial 
GradientShapeSquare 
GradientShapeConical 
GradientShapeConicalSymetric 
GradientShapeSpiral 
GradientShapeReverseSpiral 
GradientShapePolygonal 

Definition at line 34 of file kis_gradient_painter.h.

Constructor & Destructor Documentation

◆ KisGradientPainter() [1/3]

KisGradientPainter::KisGradientPainter ( )

Definition at line 1063 of file kis_gradient_painter.cc.

1064 : m_d(new Private())
1065{
1066}
const QScopedPointer< Private > m_d

◆ KisGradientPainter() [2/3]

KisGradientPainter::KisGradientPainter ( KisPaintDeviceSP device)

Definition at line 1068 of file kis_gradient_painter.cc.

1069 : KisPainter(device),
1070 m_d(new Private())
1071{
1072}
KisPainter()
Construct painter without a device.
KisPaintDeviceSP device

◆ KisGradientPainter() [3/3]

KisGradientPainter::KisGradientPainter ( KisPaintDeviceSP device,
KisSelectionSP selection )

Definition at line 1074 of file kis_gradient_painter.cc.

1076 m_d(new Private())
1077{
1078}
KisSelectionSP selection

◆ ~KisGradientPainter()

KisGradientPainter::~KisGradientPainter ( )
override

Definition at line 1080 of file kis_gradient_painter.cc.

1081{
1082}

Member Function Documentation

◆ isBayerDither()

bool KisGradientPainter::isBayerDither ( enumDither dither)
static

Definition at line 1414 of file kis_gradient_painter.cc.

1415{
1416 return dither == KisGradientPainter::DitherBayer2 ||
1419}

References DitherBayer2, DitherBayer4, and DitherBayer8.

◆ paintGradient() [1/3]

bool KisGradientPainter::paintGradient ( const QPointF & gradientVectorStart,
const QPointF & gradientVectorEnd,
enumGradientRepeat repeat,
double antiAliasThreshold,
bool reverseGradient,
const QRect & applyRect,
enumDither dither = DitherNone,
int ditherSteps = defaultDitherSteps )

Definition at line 1164 of file kis_gradient_painter.cc.

1172{
1173 // The following combinations of options have aliasing artifacts
1174 // where the first color meets the last color of the gradient.
1175 // so antialias threshold is used to compute if the pixel is in
1176 // the smoothing area. Then linear interpolation is used to blend
1177 // between the first and last colors
1178 if (antiAliasThreshold > DBL_EPSILON) {
1179 if ((m_d->shape == GradientShapeLinear || m_d->shape == GradientShapeBiLinear ||
1180 m_d->shape == GradientShapeRadial || m_d->shape == GradientShapeSquare ||
1182 && repeat == GradientRepeatForwards) {
1183 RepeatForwardsPaintPolicy paintPolicy(m_d->shape);
1184 return paintGradient(gradientVectorStart,
1185 gradientVectorEnd,
1186 repeat,
1187 antiAliasThreshold,
1188 reverseGradient,
1189 dither,
1190 ditherSteps,
1191 applyRect,
1192 paintPolicy);
1193
1194 } else if (m_d->shape == GradientShapeConical) {
1195 ConicalGradientPaintPolicy paintPolicy;
1196 return paintGradient(gradientVectorStart,
1197 gradientVectorEnd,
1198 repeat,
1199 antiAliasThreshold,
1200 reverseGradient,
1201 dither,
1202 ditherSteps,
1203 applyRect,
1204 paintPolicy);
1205
1206 } else if ((m_d->shape == GradientShapeSpiral || m_d->shape == GradientShapeReverseSpiral) &&
1207 repeat == GradientRepeatNone) {
1208 SpyralGradientRepeatNonePaintPolicy paintPolicy(m_d->shape == GradientShapeReverseSpiral);
1209 return paintGradient(gradientVectorStart,
1210 gradientVectorEnd,
1211 repeat,
1212 antiAliasThreshold,
1213 reverseGradient,
1214 dither,
1215 ditherSteps,
1216 applyRect,
1217 paintPolicy);
1218 }
1219 }
1220
1221 // Default behavior: no antialiasing required
1222 NoAntialiasPaintPolicy paintPolicy;
1223 return paintGradient(gradientVectorStart,
1224 gradientVectorEnd,
1225 repeat,
1226 antiAliasThreshold,
1227 reverseGradient,
1228 dither,
1229 ditherSteps,
1230 applyRect,
1231 paintPolicy);
1232}
bool paintGradient(const QPointF &gradientVectorStart, const QPointF &gradientVectorEnd, enumGradientRepeat repeat, double antiAliasThreshold, bool reverseGradient, qint32 startx, qint32 starty, qint32 width, qint32 height, enumDither dither=DitherNone, int ditherSteps=defaultDitherSteps)

References GradientRepeatForwards, GradientRepeatNone, GradientShapeBiLinear, GradientShapeConical, GradientShapeLinear, GradientShapeRadial, GradientShapeReverseSpiral, GradientShapeSpiral, GradientShapeSquare, m_d, and paintGradient().

◆ paintGradient() [2/3]

template<class T >
bool KisGradientPainter::paintGradient ( const QPointF & gradientVectorStart,
const QPointF & gradientVectorEnd,
enumGradientRepeat repeat,
double antiAliasThreshold,
bool reverseGradient,
enumDither dither,
int ditherSteps,
const QRect & applyRect,
T & paintPolicy )

Definition at line 1235 of file kis_gradient_painter.cc.

1244{
1245 if (!gradient()) return false;
1246
1247 QRect requestedRect = applyRect;
1248
1249 //If the device has a selection only iterate over that selection united with our area of interest
1250 if (selection()) {
1251 requestedRect &= selection()->selectedExactRect();
1252 }
1253
1255
1256 switch (m_d->shape) {
1257 case GradientShapeLinear: {
1258 Private::ProcessRegion r(toQShared(new LinearGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1259 requestedRect);
1260 m_d->processRegions.clear();
1261 m_d->processRegions << r;
1262 break;
1263 }
1264 case GradientShapeBiLinear: {
1265 Private::ProcessRegion r(toQShared(new BiLinearGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1266 requestedRect);
1267 m_d->processRegions.clear();
1268 m_d->processRegions << r;
1269 break;
1270 }
1271 case GradientShapeRadial: {
1272 Private::ProcessRegion r(toQShared(new RadialGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1273 requestedRect);
1274 m_d->processRegions.clear();
1275 m_d->processRegions << r;
1276 break;
1277 }
1278 case GradientShapeSquare: {
1279 Private::ProcessRegion r(toQShared(new SquareGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1280 requestedRect);
1281 m_d->processRegions.clear();
1282 m_d->processRegions << r;
1283 break;
1284 }
1285 case GradientShapeConical: {
1286 Private::ProcessRegion r(toQShared(new ConicalGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1287 requestedRect);
1288 m_d->processRegions.clear();
1289 m_d->processRegions << r;
1290 break;
1291 }
1293 Private::ProcessRegion r(toQShared(new ConicalSymetricGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1294 requestedRect);
1295 m_d->processRegions.clear();
1296 m_d->processRegions << r;
1297 break;
1298 }
1299 case GradientShapeSpiral: {
1300 Private::ProcessRegion r(toQShared(new SpiralGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1301 requestedRect);
1302 m_d->processRegions.clear();
1303 m_d->processRegions << r;
1304 break;
1305 }
1307 Private::ProcessRegion r(toQShared(new ReverseSpiralGradientStrategy(gradientVectorStart, gradientVectorEnd)),
1308 requestedRect);
1309 m_d->processRegions.clear();
1310 m_d->processRegions << r;
1311 break;
1312 }
1315 repeat = GradientRepeatNone;
1316 break;
1317 }
1318
1319 if (isBayerDither(dither)) {
1320 // Wrap each shape strategy in a dithering filter.
1321 for (Private::ProcessRegion& region : m_d->processRegions) {
1322 region.precalculatedShapeStrategy = toQShared(new DitheredGradientStrategy(dither, ditherSteps, region.precalculatedShapeStrategy));
1323 }
1324 }
1325
1326 GradientRepeatStrategy *repeatStrategy = 0;
1327
1328 switch (repeat) {
1329 case GradientRepeatNone:
1330 repeatStrategy = GradientRepeatNoneStrategy::instance();
1331 break;
1333 repeatStrategy = GradientRepeatForwardsStrategy::instance();
1334 break;
1336 if (m_d->shape == GradientShapeSpiral || m_d->shape == GradientShapeReverseSpiral) {repeatStrategy = GradientRepeatModuloDivisiveContinuousHalfStrategy::instance();}
1337 else {repeatStrategy = GradientRepeatAlternateStrategy::instance();}
1338 break;
1339 }
1340 Q_ASSERT(repeatStrategy != 0);
1341
1342
1344
1345 KoID depthId;
1346 const KoColorSpace *destCs = dev->colorSpace();
1347
1348 if (destCs->colorDepthId() == Integer8BitsColorDepthID) {
1349 depthId = Integer16BitsColorDepthID;
1350 } else {
1351 depthId = destCs->colorDepthId();
1352 }
1353
1354 const KoColorSpace *mixCs = KoColorSpaceRegistry::instance()->colorSpace(destCs->colorModelId().id(), depthId.id(), destCs->profile());
1355 const quint32 mixPixelSize = mixCs->pixelSize();
1356
1358 tmp->setDefaultBounds(dev->defaultBounds());
1359 tmp->clear();
1360
1361 const KisDitherOp* op = mixCs->ditherOp(destCs->colorDepthId().id(), dither == DitherBlueNoise ? DITHER_BEST : DITHER_NONE);
1362
1363 Q_FOREACH (const Private::ProcessRegion &r, m_d->processRegions) {
1364 QRect processRect = r.processRect;
1365 QSharedPointer<KisGradientShapeStrategy> shapeStrategy = r.precalculatedShapeStrategy;
1366
1367 KoCachedGradient cachedGradient(gradient(), qMax(processRect.width(), processRect.height()), mixCs);
1368
1370
1371 paintPolicy.setup(gradientVectorStart,
1372 gradientVectorEnd,
1373 shapeStrategy,
1374 repeatStrategy,
1375 antiAliasThreshold,
1376 reverseGradient,
1377 &cachedGradient);
1378
1379 while (it.nextPixel()) {
1380 const quint8 *const pixel {paintPolicy.colorAt(it.x(), it.y())};
1381 memcpy(it.rawData(), pixel, mixPixelSize);
1382 }
1383
1385 KisRandomConstAccessorSP srcIt = tmp->createRandomConstAccessorNG();
1386
1387 int rows = 1;
1388 int columns = 1;
1389
1390 for (int y = processRect.y(); y <= processRect.bottom(); y += rows) {
1391 rows = qMin(srcIt->numContiguousRows(y), qMin(dstIt->numContiguousRows(y), processRect.bottom() - y + 1));
1392
1393 for (int x = processRect.x(); x <= processRect.right(); x += columns) {
1394 columns = qMin(srcIt->numContiguousColumns(x), qMin(dstIt->numContiguousColumns(x), processRect.right() - x + 1));
1395
1396 srcIt->moveTo(x, y);
1397 dstIt->moveTo(x, y);
1398
1399 const qint32 srcRowStride = srcIt->rowStride(x, y);
1400 const qint32 dstRowStride = dstIt->rowStride(x, y);
1401 const quint8 *srcPtr = srcIt->rawDataConst();
1402 quint8 *dstPtr = dstIt->rawData();
1403
1404 op->dither(srcPtr, srcRowStride, dstPtr, dstRowStride, x, y, columns, rows);
1405 }
1406 }
1407 }
1408
1409 bitBlt(requestedRect.topLeft(), dev, requestedRect);
1410
1411 return true;
1412}
@ DITHER_NONE
Definition KisDitherOp.h:22
@ DITHER_BEST
Definition KisDitherOp.h:24
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
virtual quint8 * rawData()=0
virtual const quint8 * rawDataConst() const =0
virtual void dither(const quint8 *src, quint8 *dst, int x, int y) const =0
KisPaintDeviceSP createCompositionSourceDevice() const
const KoColorSpace * colorSpace() const
KisDefaultBoundsBaseSP defaultBounds() const
KisRandomAccessorSP createRandomAccessorNG()
KoUpdater * progressUpdater
void bitBlt(qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
KoAbstractGradientSP gradient
virtual qint32 rowStride(qint32 x, qint32 y) const =0
virtual qint32 numContiguousRows(qint32 y) const =0
virtual void moveTo(qint32 x, qint32 y)=0
virtual qint32 numContiguousColumns(qint32 x) const =0
virtual quint32 pixelSize() const =0
virtual const KisDitherOp * ditherOp(const QString &depth, DitherType type) const
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
Definition KoID.h:30
QString id() const
Definition KoID.cpp:63
QSharedPointer< T > toQShared(T *ptr)
static bool isBayerDither(enumDither dither)
QVector< ProcessRegion > processRegions
QRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()

References KisPainter::bitBlt(), KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), KisPaintDevice::colorSpace(), KoColorSpaceRegistry::colorSpace(), KisPaintDevice::createCompositionSourceDevice(), KisPaintDevice::createRandomAccessorNG(), KisPaintDevice::defaultBounds(), KisPainter::device, KisDitherOp::dither(), DITHER_BEST, DITHER_NONE, DitherBlueNoise, KoColorSpace::ditherOp(), KisPainter::gradient, GradientRepeatAlternate, GradientRepeatForwards, GradientRepeatNone, GradientShapeBiLinear, GradientShapeConical, GradientShapeConicalSymetric, GradientShapeLinear, GradientShapePolygonal, GradientShapeRadial, GradientShapeReverseSpiral, GradientShapeSpiral, GradientShapeSquare, KoID::id(), KoColorSpaceRegistry::instance(), Integer16BitsColorDepthID, Integer8BitsColorDepthID, isBayerDither(), m_d, KisRandomConstAccessorNG::moveTo(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisRandomConstAccessorNG::numContiguousColumns(), KisRandomConstAccessorNG::numContiguousRows(), KoColorSpace::pixelSize(), precalculateShape(), KoColorSpace::profile(), KisPainter::progressUpdater, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisBaseAccessor::rawData(), KisBaseConstAccessor::rawDataConst(), KisRandomConstAccessorNG::rowStride(), KisSelection::selectedExactRect(), KisPainter::selection, toQShared(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().

◆ paintGradient() [3/3]

bool KisGradientPainter::paintGradient ( const QPointF & gradientVectorStart,
const QPointF & gradientVectorEnd,
enumGradientRepeat repeat,
double antiAliasThreshold,
bool reverseGradient,
qint32 startx,
qint32 starty,
qint32 width,
qint32 height,
enumDither dither = DitherNone,
int ditherSteps = defaultDitherSteps )

Paint a gradient in the rect between startx, starty, width and height.

Definition at line 1142 of file kis_gradient_painter.cc.

1153{
1154 return paintGradient(gradientVectorStart,
1155 gradientVectorEnd,
1156 repeat,
1157 antiAliasThreshold,
1158 reverseGradient,
1159 QRect(startx, starty, width, height),
1160 dither,
1161 ditherSteps);
1162}

References paintGradient().

◆ precalculateShape()

void KisGradientPainter::precalculateShape ( )

TODO: make this call happen asynchronously when the user does nothing

Definition at line 1108 of file kis_gradient_painter.cc.

1109{
1110 if (!m_d->processRegions.isEmpty()) return;
1111
1112 QPainterPath path;
1113
1114 if (selection()) {
1115 if (!selection()->outlineCacheValid()) {
1117 }
1118
1119 KIS_ASSERT_RECOVER_RETURN(selection()->outlineCacheValid());
1120 KIS_ASSERT_RECOVER_RETURN(!selection()->outlineCache().isEmpty());
1121
1122 path = selection()->outlineCache();
1123 } else {
1124 path.addRect(device()->defaultBounds()->bounds());
1125 }
1126
1128
1129 Q_FOREACH (const QPainterPath &subpath, splitPaths) {
1130 QRect boundingRect = subpath.boundingRect().toAlignedRect();
1131
1132 if (boundingRect.width() < 3 || boundingRect.height() < 3) {
1133 boundingRect = kisGrowRect(boundingRect, 2);
1134 }
1135
1136 Private::ProcessRegion r(toQShared(createPolygonShapeStrategy(subpath, boundingRect)),
1137 boundingRect);
1138 m_d->processRegions << r;
1139 }
1140}
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
#define bounds(x, a, b)
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
KisGradientShapeStrategy * createPolygonShapeStrategy(const QPainterPath &path, const QRect &boundingRect)
QList< QPainterPath > splitDisjointPaths(const QPainterPath &path)
void recalculateOutlineCache()
QPainterPath outlineCache() const

References bounds, createPolygonShapeStrategy(), KisPainter::device, KIS_ASSERT_RECOVER_RETURN, kisGrowRect(), m_d, KisSelection::outlineCache(), KisSelection::recalculateOutlineCache(), KisPainter::selection, KritaUtils::splitDisjointPaths(), and toQShared().

◆ setGradientShape()

void KisGradientPainter::setGradientShape ( enumGradientShape shape)

Definition at line 1084 of file kis_gradient_painter.cc.

1085{
1086 m_d->shape = shape;
1087}

References m_d, and shape.

Member Data Documentation

◆ defaultDitherSteps

constexpr int KisGradientPainter::defaultDitherSteps = 2
staticconstexpr

Definition at line 60 of file kis_gradient_painter.h.

◆ m_d

const QScopedPointer<Private> KisGradientPainter::m_d
private

Definition at line 106 of file kis_gradient_painter.h.

◆ processRegions

QVector<ProcessRegion> KisGradientPainter::processRegions

Definition at line 1060 of file kis_gradient_painter.cc.

◆ shape

enumGradientShape KisGradientPainter::shape

Definition at line 1047 of file kis_gradient_painter.cc.


The documentation for this class was generated from the following files: