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

#include <kis_png_brush.h>

+ Inheritance diagram for KisPngBrush:

Public Member Functions

KoResourceSP clone () const override
 
QString defaultFileExtension () const override
 
 KisPngBrush (const KisPngBrush &rhs)
 
 KisPngBrush (const QString &filename)
 Construct brush to load filename later as brush.
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
KisPngBrushoperator= (const KisPngBrush &rhs)=delete
 
QPair< QString, QString > resourceType () const override
 
bool saveToDevice (QIODevice *dev) const override
 
void toXML (QDomDocument &d, QDomElement &e) const override
 
- Public Member Functions inherited from KisColorfulBrush
qreal adjustedMidPoint () const
 
quint8 adjustmentMidPoint () const
 
bool autoAdjustMidPoint () const
 
qreal brightnessAdjustment () const
 
QImage brushTipImage () const override
 brushImage the image the brush tip can paint with. Not all brush types have a single image.
 
qreal contrastAdjustment () const
 
qreal estimatedSourceMidPoint () const
 
bool hasColorAndTransparency () const
 
virtual bool isImageType () const
 
 KisColorfulBrush ()=default
 
 KisColorfulBrush (const KisColorfulBrush &rhs)=default
 
 KisColorfulBrush (const QString &filename)
 
virtual void setAdjustmentMidPoint (quint8 value)
 
virtual void setAutoAdjustMidPoint (bool autoAdjustMidPoint)
 
virtual void setBrightnessAdjustment (qreal value)
 
virtual void setContrastAdjustment (qreal value)
 
void setHasColorAndTransparency (bool value)
 
- Public Member Functions inherited from KisScalingSizeBrush
 KisScalingSizeBrush ()
 
 KisScalingSizeBrush (const KisScalingSizeBrush &rhs)
 
 KisScalingSizeBrush (const QString &filename)
 
void setUserEffectiveSize (qreal value) override
 
qreal userEffectiveSize () const override
 
- Public Member Functions inherited from KisBrush
qreal angle () const
 
virtual bool applyingGradient () const
 
bool autoSpacingActive () const
 
qreal autoSpacingCoeff () const
 
virtual enumBrushApplication brushApplication () const
 
virtual quint32 brushIndex () const
 
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
 
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)
 
double spacing () const
 
virtual bool supportsCaching () const
 
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 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)
 
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 ()
 
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)
 

Additional Inherited Members

- Static Public Member Functions inherited from KisBrush
static KisBrushSP fromXML (const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)
 
static KoResourceLoadResult fromXMLLoadResult (const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)
 
- 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
 
- Static Public Attributes inherited from KisBrush
static const QString brushTypeMetaDataKey = "image-based-brush"
 
- Protected Member Functions inherited from KisBrush
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)
 

Detailed Description

Definition at line 12 of file kis_png_brush.h.

Constructor & Destructor Documentation

◆ KisPngBrush() [1/2]

KisPngBrush::KisPngBrush ( const QString & filename)

Construct brush to load filename later as brush.

Definition at line 18 of file kis_png_brush.cpp.

20{
22 setSpacing(0.25);
23}
virtual void setSpacing(double spacing)
virtual void setBrushType(enumBrushType type)
KisColorfulBrush()=default
@ INVALID
Definition kis_brush.h:31
QString filename

References INVALID, KisBrush::setBrushType(), and KisBrush::setSpacing().

◆ KisPngBrush() [2/2]

KisPngBrush::KisPngBrush ( const KisPngBrush & rhs)

Definition at line 25 of file kis_png_brush.cpp.

26 : KisColorfulBrush(rhs)
27{
28}

Member Function Documentation

◆ clone()

KoResourceSP KisPngBrush::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 30 of file kis_png_brush.cpp.

31{
32 return KoResourceSP(new KisPngBrush(*this));
33}
KisPngBrush(const QString &filename)
Construct brush to load filename later as brush.
QSharedPointer< KoResource > KoResourceSP

References KisPngBrush().

◆ defaultFileExtension()

QString KisPngBrush::defaultFileExtension ( ) const
overridevirtual
Returns
the default file extension which should be used when saving the resource

Reimplemented from KoResource.

Definition at line 130 of file kis_png_brush.cpp.

131{
132 return QString(".png");
133}

◆ loadFromDevice()

bool KisPngBrush::loadFromDevice ( QIODevice * dev,
KisResourcesInterfaceSP resourcesInterface )
overridevirtual

Implements KoResource.

Definition at line 35 of file kis_png_brush.cpp.

36{
37 Q_UNUSED(resourcesInterface);
38
39 // Workaround for some OS (Debian, Ubuntu), where loading directly from the QIODevice
40 // fails with "libpng error: IDAT: CRC error"
41 QByteArray data = dev->readAll();
42 QBuffer buf(&data);
43 buf.open(QIODevice::ReadOnly);
44 QImageReader reader(&buf, "PNG");
45
46 if (!reader.canRead()) {
47 dbgKrita << "Could not read brush" << filename() << ". Error:" << reader.errorString();
48 setValid(false);
49 return false;
50 }
51
52 if (reader.textKeys().contains("brush_spacing")) {
53 setSpacing(KisDomUtils::toDouble(reader.text("brush_spacing")));
54 }
55
56 if (reader.textKeys().contains("brush_name")) {
57 setName(reader.text("brush_name"));
58 }
59 else {
60 QFileInfo info(filename());
61 setName(info.completeBaseName());
62 }
63
64 QImage image = reader.read();
65
66 if (image.isNull()) {
67 dbgKrita << "Could not create image for" << filename() << ". Error:" << reader.errorString();
68 setValid(false);
69 return false;
70 }
71
72 setValid(true);
73
74 bool hasAlpha = false;
75 for (int y = 0; y < image.height(); y++) {
76 for (int x = 0; x < image.width(); x++) {
77 if (qAlpha(image.pixel(x, y)) != 255) {
78 hasAlpha = true;
79 break;
80 }
81 }
82 }
83
84 const bool isAllGray = image.allGray();
85
86 if (isAllGray && !hasAlpha) {
87 // Make sure brush tips all have a white background
88 // NOTE: drawing it over white background can probably be skipped now...
89 // Any images with an Alpha channel should be loaded as RGBA so
90 // they can have the lightness and gradient options available
91 QImage base(image.size(), image.format());
92 if ((int)base.format() < (int)QImage::Format_RGB32) {
93 base.convertTo(QImage::Format_ARGB32);
94 }
95 QPainter gc(&base);
96 gc.fillRect(base.rect(), Qt::white);
97 gc.drawImage(0, 0, image);
98 gc.end();
99 QImage converted = base.convertToFormat(QImage::Format_Grayscale8);
100 setBrushTipImage(converted);
104 }
105 else {
106 // see bug https://bugs.kde.org/show_bug.cgi?id=484115 if you want to edit this condition
107 // keep it in sync with KisColorfulBrush code
108 if ((int)image.format() != (int)QImage::Format_ARGB32) {
109 image.convertTo(QImage::Format_ARGB32);
110 }
111
115 setHasColorAndTransparency(!isAllGray);
116 }
117
118
121
122 return valid();
123}
qint32 width() const
virtual void setBrushTipImage(const QImage &image)
void setWidth(qint32 width)
qint32 height() const
void setHeight(qint32 height)
virtual void setBrushApplication(enumBrushApplication brushApplication)
QImage brushTipImage() const override
brushImage the image the brush tip can paint with. Not all brush types have a single image.
void setHasColorAndTransparency(bool value)
@ IMAGE
Definition kis_brush.h:33
@ MASK
Definition kis_brush.h:32
@ ALPHAMASK
Definition kis_brush.h:39
@ LIGHTNESSMAP
Definition kis_brush.h:41
#define dbgKrita
Definition kis_debug.h:45
double toDouble(const QString &str, bool *ok=nullptr)
void setValid(bool valid)
void setName(const QString &name)
QImage image

References ALPHAMASK, KisColorfulBrush::brushTipImage(), dbgKrita, KoResource::filename, KisBrush::height(), IMAGE, KoResource::image, LIGHTNESSMAP, MASK, KisBrush::setBrushApplication(), KisBrush::setBrushTipImage(), KisBrush::setBrushType(), KisColorfulBrush::setHasColorAndTransparency(), KisBrush::setHeight(), KoResource::setName(), KisBrush::setSpacing(), KoResource::setValid(), KisBrush::setWidth(), KisDomUtils::toDouble(), KoResource::valid, and KisBrush::width().

◆ operator=()

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

◆ resourceType()

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

Reimplemented from KisBrush.

Definition at line 27 of file kis_png_brush.h.

27 {
28 return QPair<QString, QString>(ResourceType::Brushes, ResourceSubType::PngBrushes);
29 }
const QString PngBrushes
const QString Brushes

References ResourceType::Brushes, and ResourceSubType::PngBrushes.

◆ saveToDevice()

bool KisPngBrush::saveToDevice ( QIODevice * dev) const
overridevirtual

Reimplemented from KoResource.

Definition at line 125 of file kis_png_brush.cpp.

126{
127 return brushTipImage().save(dev, "PNG");
128}

References KisColorfulBrush::brushTipImage().

◆ toXML()

void KisPngBrush::toXML ( QDomDocument & ,
QDomElement & element ) const
overridevirtual

Serialize this brush to XML.

Reimplemented from KisColorfulBrush.

Definition at line 135 of file kis_png_brush.cpp.

136{
137 predefinedBrushToXML("png_brush", e);
139}
void predefinedBrushToXML(const QString &type, QDomElement &e) const
Private *const d
Definition kis_brush.h:387
void toXML(QDomDocument &d, QDomElement &e) const override

References KisBrush::d, KisBrush::predefinedBrushToXML(), and KisColorfulBrush::toXML().


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