Krita Source Code Documentation
Loading...
Searching...
No Matches
KisBrush Class Referenceabstract

#include <kis_brush.h>

+ Inheritance diagram for KisBrush:

Classes

class  ColoringInformation
 
class  PaintDeviceColoringInformation
 
class  PlainColoringInformation
 
struct  Private
 

Public Member Functions

qreal angle () const
 
virtual bool applyingGradient () const
 
bool autoSpacingActive () const
 
qreal autoSpacingCoeff () const
 
virtual enumBrushApplication brushApplication () const
 
virtual quint32 brushIndex () const
 
virtual QImage brushTipImage () const
 brushImage the image the brush tip can paint with. Not all brush types have a single image.
 
virtual enumBrushType brushType () const
 
virtual bool canPaintFor (const KisPaintInformation &)
 
virtual QSizeF characteristicSize (KisDabShape const &) const
 
void clearBrushPyramid ()
 
virtual void coldInitBrush ()
 
virtual void generateMaskAndApplyMaskOrCreateDab (KisFixedPaintDeviceSP dst, ColoringInformation *coloringInfo, KisDabShape const &, const KisPaintInformation &info, double subPixelX, double subPixelY, qreal softnessFactor, qreal lightnessStrength) const
 
void generateMaskAndApplyMaskOrCreateDab (KisFixedPaintDeviceSP dst, ColoringInformation *coloringInfo, KisDabShape const &, const KisPaintInformation &info, double subPixelX=0, double subPixelY=0, qreal softnessFactor=DEFAULT_SOFTNESS_FACTOR) const
 
qint32 height () const
 
QPointF hotSpot (KisDabShape const &, const KisPaintInformation &info) const
 
virtual bool isPiercedApprox () const
 
 KisBrush ()
 
 KisBrush (const KisBrush &rhs)
 
 KisBrush (const QString &filename)
 
virtual void lodLimitations (KisPaintopLodLimitations *l) const
 
void mask (KisFixedPaintDeviceSP dst, const KisPaintDeviceSP src, KisDabShape const &shape, const KisPaintInformation &info, double subPixelX=0, double subPixelY=0, qreal softnessFactor=DEFAULT_SOFTNESS_FACTOR, qreal lightnessStrength=DEFAULT_LIGHTNESS_STRENGTH) const
 
void mask (KisFixedPaintDeviceSP dst, const KoColor &color, KisDabShape const &shape, const KisPaintInformation &info, double subPixelX=0, double subPixelY=0, qreal softnessFactor=DEFAULT_SOFTNESS_FACTOR, qreal lightnessStrength=DEFAULT_LIGHTNESS_STRENGTH) const
 
double maskAngle (double angle=0) const
 
virtual qint32 maskHeight (KisDabShape const &, qreal subPixelX, qreal subPixelY, const KisPaintInformation &info) const
 
virtual qint32 maskWidth (KisDabShape const &, qreal subPixelX, qreal subPixelY, const KisPaintInformation &info) const
 
virtual void notifyBrushIsGoingToBeClonedForStroke ()
 
virtual void notifyStrokeStarted ()
 
KisBrushoperator= (const KisBrush &rhs)=delete
 
virtual KisOptimizedBrushOutline outline (bool forcePreciseOutline=false) const
 
virtual KisFixedPaintDeviceSP outlineSourceImage () const
 
virtual KisFixedPaintDeviceSP paintDevice (const KoColorSpace *colorSpace, KisDabShape const &, const KisPaintInformation &info, double subPixelX=0, double subPixelY=0) const
 
virtual void prepareForSeqNo (const KisPaintInformation &info, int seqNo)
 
virtual bool preserveLightness () const
 
QPair< QString, QString > resourceType () const override
 
qreal scale () const
 
virtual void setAngle (qreal _angle)
 
void setAutoSpacing (bool active, qreal coeff)
 
virtual void setBrushApplication (enumBrushApplication brushApplication)
 
virtual void setBrushTipImage (const QImage &image)
 
virtual void setGradient (KoAbstractGradientSP gradient)
 
virtual void setScale (qreal _scale)
 
virtual void setSpacing (double spacing)
 
virtual void setUserEffectiveSize (qreal value)=0
 
double spacing () const
 
virtual bool supportsCaching () const
 
virtual void toXML (QDomDocument &, QDomElement &) const
 
virtual qreal userEffectiveSize () const =0
 
qint32 width () const
 
 ~KisBrush () override
 
- Public Member Functions inherited from KoResource
bool active () const
 
void addMetaData (QString key, QVariant value)
 store the given key, value pair in the resource
 
virtual void clearSideLoadedResources ()
 
virtual KoResourceSP clone () const =0
 
virtual QString defaultFileExtension () const
 
virtual QList< KoResourceLoadResultembeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
QString filename () const
 
QImage image () const
 
bool isDirty () const
 
virtual bool isEphemeral () const
 
virtual bool isSerializable () const
 
 KoResource ()
 
 KoResource (const KoResource &rhs)
 
 KoResource (const QString &filename)
 
virtual QList< KoResourceLoadResultlinkedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
bool load (KisResourcesInterfaceSP resourcesInterface)
 
virtual bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface)=0
 
QString md5Sum (bool generateIfEmpty=true) const
 
QMap< QString, QVariant > metadata () const
 get a map with all the metadata
 
virtual QString name () const
 
KoResourceoperator= (const KoResource &rhs)=delete
 
bool permanent () const
 
virtual QList< int > requiredCanvasResources () const
 
QList< KoResourceLoadResultrequiredResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
int resourceId () const
 
bool save ()
 
virtual bool saveToDevice (QIODevice *dev) const
 
void setActive (bool active)
 
void setDirty (bool value)
 Mark the preset as modified but not saved.
 
void setFilename (const QString &filename)
 
void setImage (const QImage &image)
 
void setMD5Sum (const QString &md5sum)
 Set the md5sum of this resource. It must be in hex-encoded string format.
 
void setName (const QString &name)
 
void setPermanent (bool permanent)
 
void setResourceId (int id)
 
void setStorageLocation (const QString &location)
 
void setValid (bool valid)
 
void setVersion (int version)
 
virtual QList< KoResourceLoadResultsideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
KoResourceSignature signature () const
 
QString storageLocation () const
 
QList< KoResourceLoadResulttakeSideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface)
 
virtual QImage thumbnail () const
 thumbnail the thumbnail image to use in resource selectors
 
virtual QString thumbnailPath () const
 thumbnailPath returns the path to a separate thumbnail image, outside the actual resource file itself. If the path is relative, it is supposed start in the same location as the resource itself. If it's absolute, that is, it starts with "/", it is from the root of the storage.
 
virtual void updateThumbnail ()
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Member Functions

static KisBrushSP fromXML (const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)
 
static KoResourceLoadResult fromXMLLoadResult (const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)
 

Static Public Attributes

static const QString brushTypeMetaDataKey = "image-based-brush"
 

Protected Member Functions

void generateOutlineCache ()
 
bool outlineCacheIsValid () const
 
void predefinedBrushToXML (const QString &type, QDomElement &e) const
 
void resetOutlineCache ()
 
virtual void setBrushType (enumBrushType type)
 
void setHeight (qint32 height)
 
void setHotSpot (QPointF)
 
void setWidth (qint32 width)
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Public Attributes inherited from KoResource
bool active {true}
 
QString filename
 
QImage image
 
QString md5sum
 
QMap< QString, QVariant > metadata
 
bool modified {false}
 
QString name
 
bool permanent {false}
 
int resourceId {-1}
 
QString storageLocation
 
bool valid {false}
 
int version {-1}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

KisBrush is the base class for brush resources. A brush resource defines one or more images that are used to potato-stamp along the drawn path. The brush type defines how this brush is used – the important difference is between masks (which take the current painting color) and images (which do not). It is up to the paintop to make use of this feature.

Brushes must be serializable to an xml representation and provide a factory class that can recreate or retrieve the brush based on this representation.

XXX: This api is still a big mess – it needs a good refactoring. And the whole KoResource architecture is way over-designed.

Definition at line 66 of file kis_brush.h.

Constructor & Destructor Documentation

◆ KisBrush() [1/3]

KisBrush::KisBrush ( )

Definition at line 198 of file kis_brush.cpp.

199 : KoResource(QString())
200 , d(new Private)
201{
202}
Private *const d
Definition kis_brush.h:387

◆ KisBrush() [2/3]

KisBrush::KisBrush ( const QString & filename)

Definition at line 204 of file kis_brush.cpp.

206 , d(new Private)
207{
208}
QString filename

◆ ~KisBrush()

KisBrush::~KisBrush ( )
override

Definition at line 216 of file kis_brush.cpp.

217{
218 delete d;
219}

References d.

◆ KisBrush() [3/3]

KisBrush::KisBrush ( const KisBrush & rhs)

Definition at line 210 of file kis_brush.cpp.

211 : KoResource(rhs)
212 , d(new Private(*rhs.d))
213{
214}

Member Function Documentation

◆ angle()

qreal KisBrush::angle ( ) const

Definition at line 743 of file kis_brush.cpp.

744{
745 return d->angle;
746}

References KisBrush::Private::angle, and d.

◆ applyingGradient()

bool KisBrush::applyingGradient ( ) const
virtual

Definition at line 308 of file kis_brush.cpp.

309{
310 return d->brushApplication == GRADIENTMAP;
311}
@ GRADIENTMAP
Definition kis_brush.h:42
enumBrushApplication brushApplication

References KisBrush::Private::brushApplication, d, and GRADIENTMAP.

◆ autoSpacingActive()

bool KisBrush::autoSpacingActive ( ) const

Definition at line 538 of file kis_brush.cpp.

539{
540 return d->autoSpacingActive;
541}

References KisBrush::Private::autoSpacingActive, and d.

◆ autoSpacingCoeff()

qreal KisBrush::autoSpacingCoeff ( ) const

Definition at line 543 of file kis_brush.cpp.

544{
545 return d->autoSpacingCoeff;
546}

References KisBrush::Private::autoSpacingCoeff, and d.

◆ brushApplication()

enumBrushApplication KisBrush::brushApplication ( ) const
virtual

Definition at line 298 of file kis_brush.cpp.

299{
300 return d->brushApplication;
301}

References KisBrush::Private::brushApplication, and d.

◆ brushIndex()

quint32 KisBrush::brushIndex ( ) const
virtual
Returns
the currently selected index of the brush if the brush consists of multiple images
See also
prepareForSeqNo()

Reimplemented in KisImagePipeBrush, and KisTextBrush.

Definition at line 516 of file kis_brush.cpp.

517{
518 return 0;
519}

◆ brushTipImage()

QImage KisBrush::brushTipImage ( ) const
virtual

brushImage the image the brush tip can paint with. Not all brush types have a single image.

Returns
a valid QImage.

Reimplemented in KisAbrBrush, and KisColorfulBrush.

Definition at line 221 of file kis_brush.cpp.

222{
224 return d->brushTipImage;
225}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisBrush::Private::brushTipImage, d, and KIS_SAFE_ASSERT_RECOVER_NOOP.

◆ brushType()

enumBrushType KisBrush::brushType ( ) const
virtual

The brush type defines how the brush is used.

Definition at line 430 of file kis_brush.cpp.

431{
432 return d->brushType;
433}
enumBrushType brushType

References KisBrush::Private::brushType, and d.

◆ canPaintFor()

bool KisBrush::canPaintFor ( const KisPaintInformation & )
virtual

Returns true if this brush can return something useful for the info. This is used by Pipe Brushes that can't paint sometimes

Reimplemented in KisImagePipeBrush.

Definition at line 400 of file kis_brush.cpp.

401{
402 return true;
403}

◆ characteristicSize()

QSizeF KisBrush::characteristicSize ( KisDabShape const & shape) const
virtual
Returns
the logical size of the brush, that is the size measured in floating point value.

This value should not be used for calculating future dab sizes because it doesn't take any rounding into account. The only use of this metric is calculation of brush-size derivatives like hotspots and spacing.

Reimplemented in KisAutoBrush.

Definition at line 477 of file kis_brush.cpp.

478{
479 KisDabShape normalizedShape(
480 shape.scale() * d->scale,
481 shape.ratio(),
482 normalizeAngle(shape.rotation() + d->angle));
484 QSize(width(), height()), normalizedShape);
485}
qint32 width() const
qint32 height() const
static QSizeF characteristicSize(const QSize &originalSize, KisDabShape const &)
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngle(T a)
Definition kis_global.h:121

References KisBrush::Private::angle, KisQImagePyramid::characteristicSize(), d, height(), normalizeAngle(), KisDabShape::ratio(), KisDabShape::rotation(), KisBrush::Private::scale, KisDabShape::scale(), and width().

◆ clearBrushPyramid()

void KisBrush::clearBrushPyramid ( )

Definition at line 565 of file kis_brush.cpp.

566{
567 d->brushPyramid.reset();
568}
KisLazySharedCacheStorageLinked< KisQImagePyramid, const KisBrush * > brushPyramid

References KisBrush::Private::brushPyramid, and d.

◆ coldInitBrush()

void KisBrush::coldInitBrush ( )
virtual

Reimplemented in KisAutoBrush, and KisImagePipeBrush.

Definition at line 767 of file kis_brush.cpp.

768{
769 d->brushPyramid.initialize(this);
771}
void generateOutlineCache()

References KisBrush::Private::brushPyramid, d, and generateOutlineCache().

◆ fromXML()

KisBrushSP KisBrush::fromXML ( const QDomElement & element,
KisResourcesInterfaceSP resourcesInterface )
static

Definition at line 453 of file kis_brush.cpp.

454{
455 KoResourceLoadResult result = fromXMLLoadResult(element, resourcesInterface);
456
457 KisBrushSP brush = result.resource<KisBrush>();
458 if (!brush) {
459 QDomElement el;
460 brush = KisBrushRegistry::instance()->get("auto_brush")->createBrush(el, resourcesInterface).resource<KisBrush>();
461 }
462 return brush;
463}
virtual KoResourceLoadResult createBrush(const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)=0
static KisBrushRegistry * instance()
static KoResourceLoadResult fromXMLLoadResult(const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)
T get(const QString &id) const
KoResourceSP resource() const noexcept

References KisBrushFactory::createBrush(), fromXMLLoadResult(), KoGenericRegistry< T >::get(), KisBrushRegistry::instance(), and KoResourceLoadResult::resource().

◆ fromXMLLoadResult()

KoResourceLoadResult KisBrush::fromXMLLoadResult ( const QDomElement & element,
KisResourcesInterfaceSP resourcesInterface )
static

Definition at line 465 of file kis_brush.cpp.

466{
467 KoResourceLoadResult result = KisBrushRegistry::instance()->createBrush(element, resourcesInterface);
468
469 KisBrushSP brush = result.resource<KisBrush>();
470 if (brush && element.attribute("BrushVersion", "1") == "1") {
471 brush->setScale(brush->scale() * 2.0);
472 }
473
474 return result;
475}
KoResourceLoadResult createBrush(const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)

References KisBrushRegistry::createBrush(), KisBrushRegistry::instance(), and KoResourceLoadResult::resource().

◆ generateMaskAndApplyMaskOrCreateDab() [1/2]

void KisBrush::generateMaskAndApplyMaskOrCreateDab ( KisFixedPaintDeviceSP dst,
ColoringInformation * coloringInfo,
KisDabShape const & shape,
const KisPaintInformation & info,
double subPixelX,
double subPixelY,
qreal softnessFactor,
qreal lightnessStrength ) const
virtual

Create a mask and either mask dst (that is, change all alpha values of the existing pixels to those of the mask) or, if coloringInfo is present, clear dst and fill dst with pixels according to coloringInfo, masked according to the generated mask.

Parameters
dstthe destination that will be draw on the image, and this function will edit its alpha channel
coloringInfocoloring information that will be copied on the dab, it can be null
shapea shape applied on the alpha mask
infothe painting information (this is only and should only be used by KisImagePipeBrush and only to be backward compatible with the Gimp, KisImagePipeBrush is ignoring scale and angle information)
subPixelXsub position of the brush (contained between 0.0 and 1.0)
subPixelYsub position of the brush (contained between 0.0 and 1.0)
softnessFactorsoftness factor of the brush
Returns
a mask computed from the grey-level values of the pixels in the brush.

Reimplemented in KisTextBrush, KisImagePipeBrush, and KisAutoBrush.

Definition at line 591 of file kis_brush.cpp.

596{
598 Q_UNUSED(info_);
599 Q_UNUSED(softnessFactor);
600
601 QImage outputImage = d->brushPyramid.value(this)->createImage(KisDabShape(
602 shape.scale() * d->scale, shape.ratio(),
603 -normalizeAngle(shape.rotation() + d->angle)),
604 subPixelX, subPixelY);
605
606 qint32 maskWidth = outputImage.width();
607 qint32 maskHeight = outputImage.height();
608
609 dst->setRect(QRect(0, 0, maskWidth, maskHeight));
611
612 KIS_SAFE_ASSERT_RECOVER_RETURN(coloringInformation);
613
614 quint8* color = 0;
615 if (dynamic_cast<PlainColoringInformation*>(coloringInformation)) {
616 color = const_cast<quint8*>(coloringInformation->color());
617 }
618
619 const KoColorSpace *cs = dst->colorSpace();
620 const quint32 pixelSize = cs->pixelSize();
621 const quint32 maskPixelSize = sizeof(QRgb);
622 quint8 *rowPointer = dst->data();
623
624 const bool preserveLightness = this->preserveLightness();
625 bool applyGradient = this->applyingGradient();
626 QScopedPointer<KoColor> fallbackColor;
627
628 if (applyGradient) {
629 if (d->cachedGradient) {
631 d->cachedGradient->setColorSpace(cs); //convert gradient to colorspace so we don't have to convert each pixel
632 } else {
633 fallbackColor.reset(new KoColor(Qt::red, cs));
634 color = fallbackColor->data();
635 applyGradient = false;
636 }
637 }
638
639 KoColor gradientcolor(Qt::blue, cs);
640 for (int y = 0; y < maskHeight; y++) {
641 const quint8* maskPointer = outputImage.constScanLine(y);
642 if (color) {
643 if (preserveLightness) {
644 cs->fillGrayBrushWithColorAndLightnessWithStrength(rowPointer, reinterpret_cast<const QRgb*>(maskPointer), color, lightnessStrength, maskWidth);
645 }
646 else if (applyGradient) {
647 quint8* pixel = rowPointer;
648 for (int x = 0; x < maskWidth; x++) {
649 const QRgb* maskQRgb = reinterpret_cast<const QRgb*>(maskPointer);
650 qreal maskOpacity = qreal(qAlpha(*maskQRgb)) / 255.0;
651 if (maskOpacity > 0) {
652 qreal gradientvalue = qreal(qGray(*maskQRgb)) / 255.0;
653 gradientcolor.setColor(d->cachedGradient->cachedAt(gradientvalue), cs);
654 }
655 qreal gradientOpacity = gradientcolor.opacityF();
656 qreal opacity = gradientOpacity * maskOpacity;
657 gradientcolor.setOpacity(opacity);
658 memcpy(pixel, gradientcolor.data(), pixelSize);
659
660 maskPointer += maskPixelSize;
661 pixel += pixelSize;
662 }
663 }
664 else {
665 cs->fillGrayBrushWithColor(rowPointer, reinterpret_cast<const QRgb*>(maskPointer), color, maskWidth);
666 }
667 }
668 else {
669 {
670 quint8 *dst = rowPointer;
671 for (int x = 0; x < maskWidth; x++) {
672 memcpy(dst, coloringInformation->color(), pixelSize);
673 coloringInformation->nextColumn();
674 dst += pixelSize;
675 }
676 }
677
678 QScopedArrayPointer<quint8> alphaArray(new quint8[maskWidth]);
679 fetchPremultipliedRed(reinterpret_cast<const QRgb*>(maskPointer), alphaArray.data(), maskWidth);
680 cs->applyAlphaU8Mask(rowPointer, alphaArray.data(), maskWidth);
681 }
682
683 rowPointer += maskWidth * pixelSize;
684
685 if (!color) {
686 coloringInformation->nextRow();
687 }
688 }
689
690
691}
virtual qint32 maskHeight(KisDabShape const &, qreal subPixelX, qreal subPixelY, const KisPaintInformation &info) const
virtual bool applyingGradient() const
virtual bool preserveLightness() const
virtual qint32 maskWidth(KisDabShape const &, qreal subPixelX, qreal subPixelY, const KisPaintInformation &info) const
void setRect(const QRect &rc)
const KoColorSpace * colorSpace() const
virtual quint32 pixelSize() const =0
virtual void applyAlphaU8Mask(quint8 *pixels, const quint8 *alpha, qint32 nPixels) const =0
virtual void fillGrayBrushWithColor(quint8 *dst, const QRgb *brush, quint8 *brushColor, qint32 nPixels) const =0
virtual void fillGrayBrushWithColorAndLightnessWithStrength(quint8 *dst, const QRgb *brush, quint8 *brushColor, qreal strength, qint32 nPixels) const
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
unsigned int QRgb
void applyGradient(KisPaintDeviceSP device, KisPixelSelectionSP selection, const QRect &applyRect, const QVector< KoColor > &table, bool edgeHidden, int jitter, const KisLayerStyleFilterEnvironment *env)
QSharedPointer< KoCachedGradient > cachedGradient

References KisBrush::Private::angle, KoColorSpace::applyAlphaU8Mask(), applyingGradient(), KisBrush::Private::brushPyramid, KisBrush::Private::cachedGradient, KisBrush::ColoringInformation::color(), KisFixedPaintDevice::colorSpace(), d, KisFixedPaintDevice::data(), KoColor::data(), KoColorSpace::fillGrayBrushWithColor(), KoColorSpace::fillGrayBrushWithColorAndLightnessWithStrength(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisFixedPaintDevice::lazyGrowBufferWithoutInitialization(), maskHeight(), maskWidth(), KisBrush::ColoringInformation::nextColumn(), KisBrush::ColoringInformation::nextRow(), normalizeAngle(), KoColor::opacityF(), KoColorSpace::pixelSize(), preserveLightness(), KisDabShape::ratio(), KisDabShape::rotation(), KisBrush::Private::scale, KisDabShape::scale(), KoColor::setColor(), KoColor::setOpacity(), KisFixedPaintDevice::setRect(), and KoResource::valid.

◆ generateMaskAndApplyMaskOrCreateDab() [2/2]

void KisBrush::generateMaskAndApplyMaskOrCreateDab ( KisFixedPaintDeviceSP dst,
ColoringInformation * coloringInfo,
KisDabShape const & shape,
const KisPaintInformation & info,
double subPixelX = 0,
double subPixelY = 0,
qreal softnessFactor = DEFAULT_SOFTNESS_FACTOR ) const

Definition at line 582 of file kis_brush.cpp.

587{
588 generateMaskAndApplyMaskOrCreateDab(dst, coloringInformation, shape, info_, subPixelX, subPixelY, softnessFactor, DEFAULT_LIGHTNESS_STRENGTH);
589}
virtual void generateMaskAndApplyMaskOrCreateDab(KisFixedPaintDeviceSP dst, ColoringInformation *coloringInfo, KisDabShape const &, const KisPaintInformation &info, double subPixelX, double subPixelY, qreal softnessFactor, qreal lightnessStrength) const
static const qreal DEFAULT_LIGHTNESS_STRENGTH
Definition kis_brush.h:46

References DEFAULT_LIGHTNESS_STRENGTH, and generateMaskAndApplyMaskOrCreateDab().

◆ generateOutlineCache()

void KisBrush::generateOutlineCache ( )
protected

Definition at line 718 of file kis_brush.cpp.

719{
720 d->brushOutline.initialize(this);
721}
KisLazySharedCacheStorageLinked< KisOptimizedBrushOutline, const KisBrush * > brushOutline

References KisBrush::Private::brushOutline, and d.

◆ height()

qint32 KisBrush::height ( ) const
Returns
the height (for scale == 1.0)

Definition at line 237 of file kis_brush.cpp.

238{
239 return d->height;
240}

References d, and KisBrush::Private::height.

◆ hotSpot()

QPointF KisBrush::hotSpot ( KisDabShape const & shape,
const KisPaintInformation & info ) const

Definition at line 265 of file kis_brush.cpp.

266{
267 Q_UNUSED(info);
268
269 QSizeF metric = characteristicSize(shape);
270
271 qreal w = metric.width();
272 qreal h = metric.height();
273
274 // The smallest brush we can produce is a single pixel.
275 if (w < 1) {
276 w = 1;
277 }
278
279 if (h < 1) {
280 h = 1;
281 }
282
283 // XXX: This should take d->hotSpot into account, though it
284 // isn't specified by gimp brushes so it would default to the center
285 // anyway.
286 QPointF p(w / 2, h / 2);
287 return p;
288}
const Params2D p
virtual QSizeF characteristicSize(KisDabShape const &) const

References characteristicSize(), and p.

◆ isPiercedApprox()

bool KisBrush::isPiercedApprox ( ) const
virtual

Returns true if the brush has a bunch of pixels almost fully transparent in the very center. If the brush is pierced, then dulling mode may not work correctly due to empty samples.

WARNING: this method is relatively expensive since it iterates up to 100 pixels of the brush.

Reimplemented in KisAutoBrush.

Definition at line 325 of file kis_brush.cpp.

326{
327 QImage image = brushTipImage();
328
329 qreal w = image.width();
330 qreal h = image.height();
331
332 if (w < 3 && h < 3) { return false; }
333
334 qreal xPortion = qMin(0.1, 5.0 / w);
335 qreal yPortion = qMin(0.1, 5.0 / h);
336
337 int x0 = std::floor((0.5 - xPortion) * w);
338 int x1 = std::ceil((0.5 + xPortion) * w);
339
340 int y0 = std::floor((0.5 - yPortion) * h);
341 int y1 = std::ceil((0.5 + yPortion) * h);
342
343 const int maxNumSamples = (x1 - x0 + 1) * (y1 - y0 + 1);
344 const int failedPixelsThreshold = 0.1 * maxNumSamples;
345 const int thresholdValue = 0.95 * 255;
346 int failedPixels = 0;
347
348 for (int y = y0; y <= y1; y++) {
349 for (int x = x0; x <= x1; x++) {
350 QRgb pixel = image.pixel(x,y);
351
352 if (qRed(pixel) > thresholdValue) {
353 failedPixels++;
354 }
355 }
356 }
357
358 return failedPixels > failedPixelsThreshold;
359}
virtual QImage brushTipImage() const
brushImage the image the brush tip can paint with. Not all brush types have a single image.
QImage image

References brushTipImage(), and KoResource::image.

◆ lodLimitations()

void KisBrush::lodLimitations ( KisPaintopLodLimitations * l) const
virtual

Reimplemented in KisAutoBrush.

Definition at line 755 of file kis_brush.cpp.

756{
757 if (spacing() > 0.5) {
758 l->limitations << KoID("huge-spacing", i18nc("PaintOp instant preview limitation", "Spacing > 0.5, consider disabling Instant Preview"));
759 }
760}
double spacing() const
Definition KoID.h:30

References KisPaintopLodLimitations::limitations, and spacing().

◆ mask() [1/2]

void KisBrush::mask ( KisFixedPaintDeviceSP dst,
const KisPaintDeviceSP src,
KisDabShape const & shape,
const KisPaintInformation & info,
double subPixelX = 0,
double subPixelY = 0,
qreal softnessFactor = DEFAULT_SOFTNESS_FACTOR,
qreal lightnessStrength = DEFAULT_LIGHTNESS_STRENGTH ) const

clear dst and fill it with a mask colored with the corresponding colors of src

Definition at line 576 of file kis_brush.cpp.

577{
578 PaintDeviceColoringInformation pdci(src, maskWidth(shape, subPixelX, subPixelY, info));
579 generateMaskAndApplyMaskOrCreateDab(dst, &pdci, shape, info, subPixelX, subPixelY, softnessFactor, lightnessStrength);
580}

References generateMaskAndApplyMaskOrCreateDab(), and maskWidth().

◆ mask() [2/2]

void KisBrush::mask ( KisFixedPaintDeviceSP dst,
const KoColor & color,
KisDabShape const & shape,
const KisPaintInformation & info,
double subPixelX = 0,
double subPixelY = 0,
qreal softnessFactor = DEFAULT_SOFTNESS_FACTOR,
qreal lightnessStrength = DEFAULT_LIGHTNESS_STRENGTH ) const

clear dst fill it with a mask colored with KoColor

Definition at line 570 of file kis_brush.cpp.

571{
572 PlainColoringInformation pci(color.data());
573 generateMaskAndApplyMaskOrCreateDab(dst, &pci, shape, info, subPixelX, subPixelY, softnessFactor, lightnessStrength);
574}
quint8 * data()
Definition KoColor.h:144

References KoColor::data(), and generateMaskAndApplyMaskOrCreateDab().

◆ maskAngle()

double KisBrush::maskAngle ( double angle = 0) const
Returns
the angle of the mask adding the given angle

Definition at line 511 of file kis_brush.cpp.

512{
513 return normalizeAngle(angle + d->angle);
514}
qreal angle() const

References KisBrush::Private::angle, angle(), d, and normalizeAngle().

◆ maskHeight()

qint32 KisBrush::maskHeight ( KisDabShape const & shape,
qreal subPixelX,
qreal subPixelY,
const KisPaintInformation & info ) const
virtual
Returns
the height of the mask for the given scale and angle

Reimplemented in KisAutoBrush.

Definition at line 499 of file kis_brush.cpp.

500{
501 Q_UNUSED(info);
502
503 qreal angle = normalizeAngle(shape.rotation() + d->angle);
504 qreal scale = shape.scale() * d->scale;
505
506 return KisQImagePyramid::imageSize(QSize(width(), height()),
507 KisDabShape(scale, shape.ratio(), angle),
508 subPixelX, subPixelY).height();
509}
qreal scale() const
static QSize imageSize(const QSize &originalSize, KisDabShape const &, qreal subPixelX, qreal subPixelY)

References KisBrush::Private::angle, angle(), d, height(), KisQImagePyramid::imageSize(), normalizeAngle(), KisDabShape::ratio(), KisDabShape::rotation(), KisBrush::Private::scale, scale(), KisDabShape::scale(), and width().

◆ maskWidth()

qint32 KisBrush::maskWidth ( KisDabShape const & shape,
qreal subPixelX,
qreal subPixelY,
const KisPaintInformation & info ) const
virtual
Returns
the width of the mask for the given scale and angle

Reimplemented in KisAutoBrush.

Definition at line 487 of file kis_brush.cpp.

488{
489 Q_UNUSED(info);
490
491 qreal angle = normalizeAngle(shape.rotation() + d->angle);
492 qreal scale = shape.scale() * d->scale;
493
494 return KisQImagePyramid::imageSize(QSize(width(), height()),
495 KisDabShape(scale, shape.ratio(), angle),
496 subPixelX, subPixelY).width();
497}

References KisBrush::Private::angle, angle(), d, height(), KisQImagePyramid::imageSize(), normalizeAngle(), KisDabShape::ratio(), KisDabShape::rotation(), KisBrush::Private::scale, scale(), KisDabShape::scale(), and width().

◆ notifyBrushIsGoingToBeClonedForStroke()

void KisBrush::notifyBrushIsGoingToBeClonedForStroke ( )
virtual

Is called by the paint op before it is going to clone the brush into multiple instances to pass to different threads. During this call the brush is free to prepare some structures that may be shared by all the clones without excessive recalculation.

Default implementation for all image-based brushes: just recreate the shared pyramid

Reimplemented in KisAutoBrush, and KisImagePipeBrush.

Definition at line 552 of file kis_brush.cpp.

553{
556 d->brushPyramid.initialize(this);
557}

References KisBrush::Private::brushPyramid, and d.

◆ notifyStrokeStarted()

void KisBrush::notifyStrokeStarted ( )
virtual

Is called by the paint op when a paintop starts a stroke. The point is that we store brushes a server while the paint ops are are recreated all the time. Is means that upon a stroke start the brushes may need to clear its state.

Reimplemented in KisImagePipeBrush, and KisTextBrush.

Definition at line 548 of file kis_brush.cpp.

549{
550}

◆ operator=()

KisBrush & KisBrush::operator= ( const KisBrush & rhs)
delete

◆ outline()

KisOptimizedBrushOutline KisBrush::outline ( bool forcePreciseOutline = false) const
virtual

Reimplemented in KisAutoBrush, and KisImagePipeBrush.

Definition at line 748 of file kis_brush.cpp.

749{
750 Q_UNUSED(forcePreciseOutline);
751
752 return *d->brushOutline.value(this);
753}

References KisBrush::Private::brushOutline, and d.

◆ outlineCacheIsValid()

bool KisBrush::outlineCacheIsValid ( ) const
protected

Definition at line 723 of file kis_brush.cpp.

724{
725 return !d->brushOutline.isNull();
726}

References KisBrush::Private::brushOutline, and d.

◆ outlineSourceImage()

KisFixedPaintDeviceSP KisBrush::outlineSourceImage ( ) const
virtual

Is a paint device of the brush that should be used for generation of the brush outline. Usually, it is the same device returned by brushTipImage(), but might be different in some types of brushes, like in KisAutoBrush.

We need to generate the mask manually, skipping the construction of the image pyramid

Reimplemented in KisAutoBrush.

Definition at line 372 of file kis_brush.cpp.

373{
381 const QImage image = brushTipImage().convertToFormat(QImage::Format_ARGB32);
382
383 dev->setRect(image.rect());
385
386 const int maskWidth = image.width();
387 const int maskHeight = image.height();
388
389 quint8 *dstPtr = dev->data();
390
391 for (int y = 0; y < maskHeight; y++) {
392 const QRgb* maskPointer = reinterpret_cast<const QRgb*>(image.constScanLine(y));
393 fetchPremultipliedRed(maskPointer, dstPtr, maskWidth);
394 dstPtr += maskWidth;
395 }
396
397 return dev;
398}
static KoColorSpaceRegistry * instance()
const KoColorSpace * alpha8()

References KoColorSpaceRegistry::alpha8(), brushTipImage(), KisFixedPaintDevice::data(), KoResource::image, KoColorSpaceRegistry::instance(), KisFixedPaintDevice::lazyGrowBufferWithoutInitialization(), maskHeight(), maskWidth(), and KisFixedPaintDevice::setRect().

◆ paintDevice()

KisFixedPaintDeviceSP KisBrush::paintDevice ( const KoColorSpace * colorSpace,
KisDabShape const & shape,
const KisPaintInformation & info,
double subPixelX = 0,
double subPixelY = 0 ) const
virtual

Return a fixed paint device that contains a correctly scaled image dab.

Reimplemented in KisAutoBrush, KisTextBrush, and KisImagePipeBrush.

Definition at line 693 of file kis_brush.cpp.

697{
698 Q_ASSERT(valid());
699 Q_UNUSED(info);
700 double angle = normalizeAngle(shape.rotation() + d->angle);
701 double scale = shape.scale() * d->scale;
702
703 QImage outputImage = d->brushPyramid.value(this)->createImage(
704 KisDabShape(scale, shape.ratio(), -angle), subPixelX, subPixelY);
705
706 KisFixedPaintDeviceSP dab = new KisFixedPaintDevice(colorSpace);
707 Q_CHECK_PTR(dab);
708 dab->convertFromQImage(outputImage, "");
709
710 return dab;
711}
virtual void convertFromQImage(const QImage &image, const QString &srcProfileName)

References KisBrush::Private::angle, angle(), KisBrush::Private::brushPyramid, KisFixedPaintDevice::convertFromQImage(), d, normalizeAngle(), KisDabShape::ratio(), KisDabShape::rotation(), KisBrush::Private::scale, scale(), KisDabShape::scale(), and KoResource::valid.

◆ predefinedBrushToXML()

void KisBrush::predefinedBrushToXML ( const QString & type,
QDomElement & e ) const
protected

Definition at line 435 of file kis_brush.cpp.

436{
437 e.setAttribute("type", type);
438 e.setAttribute("filename", filename());
439 e.setAttribute("md5sum", md5Sum());
440 e.setAttribute("spacing", QString::number(spacing()));
441 e.setAttribute("useAutoSpacing", QString::number(autoSpacingActive()));
442 e.setAttribute("autoSpacingCoeff", QString::number(autoSpacingCoeff()));
443 e.setAttribute("angle", QString::number(angle()));
444 e.setAttribute("scale", QString::number(scale()));
445 e.setAttribute("brushApplication", QString::number((int)brushApplication()));
446}
virtual enumBrushApplication brushApplication() const
bool autoSpacingActive() const
qreal autoSpacingCoeff() const
QString md5Sum(bool generateIfEmpty=true) const

References angle(), autoSpacingActive(), autoSpacingCoeff(), brushApplication(), KoResource::filename, KoResource::md5Sum(), scale(), and spacing().

◆ prepareForSeqNo()

void KisBrush::prepareForSeqNo ( const KisPaintInformation & info,
int seqNo )
virtual

Is called by the multithreaded queue to prepare a specific brush tip for the particular seqNo.

NOTE: one should use always call prepareForSeqNo() before using the brush

Currently, this is used by pipe'd brushes to implement incremental and random parasites

Reimplemented in KisImagePipeBrush, and KisTextBrush.

Definition at line 559 of file kis_brush.cpp.

560{
561 Q_UNUSED(info);
562 Q_UNUSED(seqNo);
563}

◆ preserveLightness()

bool KisBrush::preserveLightness ( ) const
virtual

Definition at line 303 of file kis_brush.cpp.

304{
306}
@ LIGHTNESSMAP
Definition kis_brush.h:41

References KisBrush::Private::brushApplication, d, and LIGHTNESSMAP.

◆ resetOutlineCache()

void KisBrush::resetOutlineCache ( )
protected

Definition at line 713 of file kis_brush.cpp.

714{
715 d->brushOutline.reset();
716}

References KisBrush::Private::brushOutline, and d.

◆ resourceType()

QPair< QString, QString > KisBrush::resourceType ( ) const
inlineoverridevirtual
Returns
the resource type

Implements KoResource.

Reimplemented in KisGbrBrush, KisPngBrush, and KisSvgBrush.

Definition at line 121 of file kis_brush.h.

121 {
122 return QPair<QString, QString>(ResourceType::Brushes, "");
123 }
const QString Brushes

References ResourceType::Brushes.

◆ scale()

qreal KisBrush::scale ( ) const

Definition at line 733 of file kis_brush.cpp.

734{
735 return d->scale;
736}

References d, and KisBrush::Private::scale.

◆ setAngle()

void KisBrush::setAngle ( qreal _angle)
virtual

Reimplemented in KisImagePipeBrush, and KisTextBrush.

Definition at line 738 of file kis_brush.cpp.

739{
740 d->angle = _rotation;
741}

References KisBrush::Private::angle, and d.

◆ setAutoSpacing()

void KisBrush::setAutoSpacing ( bool active,
qreal coeff )

◆ setBrushApplication()

void KisBrush::setBrushApplication ( enumBrushApplication brushApplication)
virtual

Reimplemented in KisImagePipeBrush.

Definition at line 290 of file kis_brush.cpp.

291{
295 }
296}
void clearBrushPyramid()

References KisBrush::Private::brushApplication, brushApplication(), clearBrushPyramid(), and d.

◆ setBrushTipImage()

void KisBrush::setBrushTipImage ( const QImage & image)
virtual

The image is used to represent the brush in the gui, and may also, depending on the brush type be used to define the actual brush instance.

Reimplemented in KisAbrBrush, and KisGbrBrush.

Definition at line 405 of file kis_brush.cpp.

406{
408
409 if (!image.isNull()) {
410 if (image.width() > 128 || image.height() > 128) {
411 KoResource::setImage(image.scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation));
412 }
413 else {
415 }
416 setWidth(image.width());
417 setHeight(image.height());
418 }
421}
void resetOutlineCache()
void setWidth(qint32 width)
void setHeight(qint32 height)
void setImage(const QImage &image)

References KisBrush::Private::brushTipImage, clearBrushPyramid(), d, KoResource::image, resetOutlineCache(), setHeight(), KoResource::setImage(), and setWidth().

◆ setBrushType()

void KisBrush::setBrushType ( enumBrushType type)
protectedvirtual

XXX

Definition at line 423 of file kis_brush.cpp.

424{
425 d->brushType = type;
427 QVariant::fromValue(type == IMAGE || type == PIPE_IMAGE));
428}
static const QString brushTypeMetaDataKey
Definition kis_brush.h:343
@ IMAGE
Definition kis_brush.h:33
@ PIPE_IMAGE
Definition kis_brush.h:35
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource

References KoResource::addMetaData(), KisBrush::Private::brushType, brushTypeMetaDataKey, d, IMAGE, and PIPE_IMAGE.

◆ setGradient()

void KisBrush::setGradient ( KoAbstractGradientSP gradient)
virtual

Reimplemented in KisImagePipeBrush.

Definition at line 313 of file kis_brush.cpp.

313 {
314 if (gradient && gradient->valid()) {
315 d->gradient = gradient;
316
317 if (!d->cachedGradient) {
318 d->cachedGradient = toQShared(new KoCachedGradient(d->gradient, 256, d->gradient->colorSpace()));
319 } else {
320 d->cachedGradient->setGradient(d->gradient, 256, d->gradient->colorSpace());
321 }
322 }
323}
QSharedPointer< T > toQShared(T *ptr)
KoAbstractGradientSP gradient

References KisBrush::Private::cachedGradient, d, KisBrush::Private::gradient, and toQShared().

◆ setHeight()

void KisBrush::setHeight ( qint32 height)
protected

Definition at line 242 of file kis_brush.cpp.

243{
244 d->height = height;
245}

References d, KisBrush::Private::height, and height().

◆ setHotSpot()

void KisBrush::setHotSpot ( QPointF pt)
protected

Definition at line 247 of file kis_brush.cpp.

248{
249 double x = pt.x();
250 double y = pt.y();
251
252 if (x < 0)
253 x = 0;
254 else if (x >= width())
255 x = width() - 1;
256
257 if (y < 0)
258 y = 0;
259 else if (y >= height())
260 y = height() - 1;
261
262 d->hotSpot = QPointF(x, y);
263}

References d, height(), KisBrush::Private::hotSpot, and width().

◆ setScale()

void KisBrush::setScale ( qreal _scale)
virtual

Reimplemented in KisImagePipeBrush, and KisTextBrush.

Definition at line 728 of file kis_brush.cpp.

729{
730 d->scale = _scale;
731}

References d, and KisBrush::Private::scale.

◆ setSpacing()

void KisBrush::setSpacing ( double spacing)
virtual

Change the spacing of the brush.

Parameters
spacinga spacing of 1.0 means that strokes will be separated from one time the size of the brush.

Reimplemented in KisImagePipeBrush, and KisTextBrush.

Definition at line 521 of file kis_brush.cpp.

522{
523 if (s < 0.02) s = 0.02;
524 d->spacing = s;
525}

References d, and KisBrush::Private::spacing.

◆ setUserEffectiveSize()

virtual void KisBrush::setUserEffectiveSize ( qreal value)
pure virtual

Implemented in KisAutoBrush, and KisScalingSizeBrush.

◆ setWidth()

void KisBrush::setWidth ( qint32 width)
protected

Definition at line 232 of file kis_brush.cpp.

233{
234 d->width = width;
235}

References d, KisBrush::Private::width, and width().

◆ spacing()

double KisBrush::spacing ( ) const
Returns
the spacing between two strokes for this brush

Definition at line 527 of file kis_brush.cpp.

528{
529 return d->spacing;
530}

References d, and KisBrush::Private::spacing.

◆ supportsCaching()

bool KisBrush::supportsCaching ( ) const
virtual

Reimplemented in KisAutoBrush.

Definition at line 762 of file kis_brush.cpp.

763{
764 return true;
765}

◆ toXML()

void KisBrush::toXML ( QDomDocument & ,
QDomElement & element ) const
virtual

Serialize this brush to XML.

Reimplemented in KisAutoBrush, KisTextBrush, KisAbrBrush, KisGbrBrush, KisPngBrush, KisSvgBrush, and KisColorfulBrush.

Definition at line 448 of file kis_brush.cpp.

449{
450 element.setAttribute("BrushVersion", "2");
451}

◆ userEffectiveSize()

virtual qreal KisBrush::userEffectiveSize ( ) const
pure virtual

Implemented in KisAutoBrush, and KisScalingSizeBrush.

◆ width()

qint32 KisBrush::width ( ) const
Returns
the width (for scale == 1.0)

Definition at line 227 of file kis_brush.cpp.

228{
229 return d->width;
230}

References d, and KisBrush::Private::width.

Member Data Documentation

◆ brushTypeMetaDataKey

const QString KisBrush::brushTypeMetaDataKey = "image-based-brush"
static

Definition at line 343 of file kis_brush.h.

◆ d

Private* const KisBrush::d
private

Definition at line 387 of file kis_brush.h.


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