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

#include <kis_gbr_brush.h>

+ Inheritance diagram for KisGbrBrush:

Classes

struct  Private
 

Public Member Functions

KoResourceSP clone () const override
 
QString defaultFileExtension () const override
 
 KisGbrBrush (const KisGbrBrush &rhs)
 
 KisGbrBrush (const QImage &image, const QString &name=QString())
 Load brush as a copy from the specified QImage (handy when you need to copy a brush!)
 
 KisGbrBrush (const QString &filename)
 Construct brush to load filename later as brush.
 
 KisGbrBrush (const QString &filename, const QByteArray &data, qint32 &dataPos)
 Load brush from the specified data, at position dataPos, and set the filename.
 
 KisGbrBrush (KisPaintDeviceSP image, int x, int y, int w, int h)
 Load brush from the specified paint device, in the specified region.
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
virtual void makeMaskImage (bool preserveAlpha)
 
KisGbrBrushoperator= (const KisGbrBrush &rhs)
 
QPair< QString, QString > resourceType () const override
 
bool saveToDevice (QIODevice *dev) const override
 
 ~KisGbrBrush () 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 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)
 

Protected Member Functions

void setBrushTipImage (const QImage &image) override
 
void toXML (QDomDocument &d, QDomElement &e) const override
 
- 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)
 

Private Member Functions

bool init ()
 
bool initFromPaintDev (KisPaintDeviceSP image, int x, int y, int w, int h)
 

Private Attributes

Private *const d
 

Friends

class KisBrushExport
 
class KisImageBrushesPipe
 

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"
 

Detailed Description

Definition at line 26 of file kis_gbr_brush.h.

Constructor & Destructor Documentation

◆ KisGbrBrush() [1/5]

KisGbrBrush::KisGbrBrush ( const QString & filename)

Construct brush to load filename later as brush.

Definition at line 69 of file kis_gbr_brush.cpp.

71 , d(new Private)
72{
74}
virtual void setSpacing(double spacing)
KisColorfulBrush()=default
Private *const d
#define DEFAULT_SPACING
QString filename

References DEFAULT_SPACING, and KisBrush::setSpacing().

◆ KisGbrBrush() [2/5]

KisGbrBrush::KisGbrBrush ( const QString & filename,
const QByteArray & data,
qint32 & dataPos )

Load brush from the specified data, at position dataPos, and set the filename.

Definition at line 76 of file kis_gbr_brush.cpp.

80 , d(new Private)
81{
83
84 d->data = QByteArray::fromRawData(data.data() + dataPos, data.size() - dataPos);
85 init();
86 d->data.clear();
87 dataPos += d->header_size + (width() * height() * d->bytes);
88}
qint32 width() const
qint32 height() const

References KisGbrBrush::Private::bytes, d, KisGbrBrush::Private::data, DEFAULT_SPACING, KisGbrBrush::Private::header_size, KisBrush::height(), init(), KisBrush::setSpacing(), and KisBrush::width().

◆ KisGbrBrush() [3/5]

KisGbrBrush::KisGbrBrush ( KisPaintDeviceSP image,
int x,
int y,
int w,
int h )

Load brush from the specified paint device, in the specified region.

Definition at line 90 of file kis_gbr_brush.cpp.

92 , d(new Private)
93{
95 initFromPaintDev(image, x, y, w, h);
96}
bool initFromPaintDev(KisPaintDeviceSP image, int x, int y, int w, int h)
QImage image

References DEFAULT_SPACING, KoResource::image, initFromPaintDev(), and KisBrush::setSpacing().

◆ KisGbrBrush() [4/5]

KisGbrBrush::KisGbrBrush ( const QImage & image,
const QString & name = QString() )

Load brush as a copy from the specified QImage (handy when you need to copy a brush!)

Definition at line 98 of file kis_gbr_brush.cpp.

100 , d(new Private)
101{
103
105 setName(name);
106}
void setBrushTipImage(const QImage &image) override
void setName(const QString &name)
QString name

References DEFAULT_SPACING, KoResource::image, KoResource::name, setBrushTipImage(), KoResource::setName(), and KisBrush::setSpacing().

◆ ~KisGbrBrush()

KisGbrBrush::~KisGbrBrush ( )
override

Definition at line 120 of file kis_gbr_brush.cpp.

121{
122 delete d;
123}

References d.

◆ KisGbrBrush() [5/5]

KisGbrBrush::KisGbrBrush ( const KisGbrBrush & rhs)

Definition at line 108 of file kis_gbr_brush.cpp.

109 : KisColorfulBrush(rhs)
110 , d(new Private(*rhs.d))
111{
112 d->data = QByteArray();
113}

References d, and KisGbrBrush::Private::data.

Member Function Documentation

◆ clone()

KoResourceSP KisGbrBrush::clone ( ) const
overridevirtual

Implements KoResource.

Reimplemented in KisImagePipeBrush.

Definition at line 115 of file kis_gbr_brush.cpp.

116{
117 return KoResourceSP(new KisGbrBrush(*this));
118}
KisGbrBrush(const QString &filename)
Construct brush to load filename later as brush.
QSharedPointer< KoResource > KoResourceSP

References KisGbrBrush().

◆ defaultFileExtension()

QString KisGbrBrush::defaultFileExtension ( ) const
overridevirtual
Returns
default file extension for saving the brush

Reimplemented from KoResource.

Reimplemented in KisImagePipeBrush.

Definition at line 421 of file kis_gbr_brush.cpp.

422{
423 return QString(".gbr");
424}

◆ init()

bool KisGbrBrush::init ( )
private

Definition at line 132 of file kis_gbr_brush.cpp.

133{
135
136 if (sizeof(GimpBrushHeader) > (uint)d->data.size()) {
137 qWarning() << filename() << "GBR could not be loaded: expected header size larger than bytearray size. Header Size:" << sizeof(GimpBrushHeader) << "Byte array size" << d->data.size();
138 return false;
139 }
140
141 memcpy(&bh, d->data.constData(), sizeof(GimpBrushHeader));
142 bh.header_size = qFromBigEndian(bh.header_size);
144
145 bh.version = qFromBigEndian(bh.version);
146 d->version = bh.version;
147
148 bh.width = qFromBigEndian(bh.width);
149 bh.height = qFromBigEndian(bh.height);
150
151 bh.bytes = qFromBigEndian(bh.bytes);
152 d->bytes = bh.bytes;
153
154 bh.magic_number = qFromBigEndian(bh.magic_number);
156
157 if (bh.version == 1) {
158 // No spacing in version 1 files so use Gimp default
159 bh.spacing = static_cast<int>(DEFAULT_SPACING * 100);
160 }
161 else {
162 bh.spacing = qFromBigEndian(bh.spacing);
163
164 if (bh.spacing > 1000) {
165 qWarning() << filename() << "GBR could not be loaded, spacing above 1000. Spacing:" << bh.spacing;
166 return false;
167 }
168 }
169
170 setSpacing(bh.spacing / 100.0);
171
172 if (bh.header_size > (uint)d->data.size() || bh.header_size == 0) {
173 qWarning() << "GBR could not be loaded: header size larger than bytearray size. Header Size:" << bh.header_size << "Byte array size" << d->data.size();
174 return false;
175 }
176
177 QString name;
178
179 if (bh.version == 1) {
180 // Version 1 has no magic number or spacing, so the name
181 // is at a different offset. Character encoding is undefined.
182 const char *text = d->data.constData() + sizeof(GimpBrushV1Header);
183 name = QString::fromLatin1(text, bh.header_size - sizeof(GimpBrushV1Header) - 1);
184 }
185 else {
186 // ### Version = 3->cinepaint; may be float16 data!
187 // Version >=2: UTF-8 encoding is used
188 name = QString::fromUtf8(d->data.constData() + sizeof(GimpBrushHeader),
189 bh.header_size - sizeof(GimpBrushHeader) - 1);
190 }
191
192 setName(name);
193
194 if (bh.width == 0 || bh.height == 0) {
195 qWarning() << filename() << "GBR loading failed: width or height is 0" << bh.width << bh.height;
196 return false;
197 }
198
199 QImage::Format imageFormat;
200
201 if (bh.bytes == 1) {
202 imageFormat = QImage::Format_Indexed8;
203 } else {
204 imageFormat = QImage::Format_ARGB32;
205 }
206
207 QImage image(QImage(bh.width, bh.height, imageFormat));
208
209 if (image.isNull()) {
210 qWarning() << filename() << "GBR loading failed; image could not be created from following dimensions" << bh.width << bh.height
211 << "QImage::Format" << imageFormat;
212 return false;
213 }
214
215 qint32 k = bh.header_size;
216
217 if (bh.bytes == 1) {
218 QVector<QRgb> table;
219 for (int i = 0; i < 256; ++i) table.append(qRgb(i, i, i));
220 image.setColorTable(table);
221 // Grayscale
222
223 if (static_cast<qint32>(k + bh.width * bh.height) > d->data.size()) {
224 qWarning() << filename() << "GBR file dimensions bigger than bytearray size. Header:"<< k << "Width:" << bh.width << "height" << bh.height
225 << "expected byte array size:" << (k + (bh.width * bh.height)) << "actual byte array size" << d->data.size();
226 return false;
227 }
228
232
233 for (quint32 y = 0; y < bh.height; y++) {
234 uchar *pixel = reinterpret_cast<uchar *>(image.scanLine(y));
235 for (quint32 x = 0; x < bh.width; x++, k++) {
236 qint32 val = 255 - static_cast<uchar>(d->data.at(k));
237 *pixel = val;
238 ++pixel;
239 }
240 }
241 } else if (bh.bytes == 4) {
242 // RGBA
243
244 if (static_cast<qint32>(k + (bh.width * bh.height * 4)) > d->data.size()) {
245 qWarning() << filename() << "GBR file dimensions bigger than bytearray size. Header:"<< k << "Width:" << bh.width << "height" << bh.height
246 << "expected byte array size:" << (k + (bh.width * bh.height * 4)) << "actual byte array size" << d->data.size();
247 return false;
248 }
249
252
253 for (quint32 y = 0; y < bh.height; y++) {
254 QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(y));
255 for (quint32 x = 0; x < bh.width; x++, k += 4) {
256 *pixel = qRgba(d->data.at(k), d->data.at(k + 1), d->data.at(k + 2), d->data.at(k + 3));
257 ++pixel;
258 }
259 }
260
262 }
263 else {
264 warnKrita << filename() << "WARNING: loading of GBR brushes with" << bh.bytes << "bytes per pixel is not supported";
265 return false;
266 }
267
268 setWidth(image.width());
269 setHeight(image.height());
270 if (!d->data.isEmpty()) {
271 d->data.clear(); // Save some memory, we're using enough of it as it is.
272 }
273 setValid(image.width() != 0 && image.height() != 0);
275 return true;
276}
unsigned int uint
virtual void setBrushType(enumBrushType type)
void setWidth(qint32 width)
void setHeight(qint32 height)
virtual void setBrushApplication(enumBrushApplication brushApplication)
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
unsigned int QRgb
#define warnKrita
Definition kis_debug.h:87
All fields are in MSB on disk!
void setValid(bool valid)

References ALPHAMASK, GimpBrushHeader::bytes, KisGbrBrush::Private::bytes, d, KisGbrBrush::Private::data, DEFAULT_SPACING, KoResource::filename, GimpBrushHeader::header_size, KisGbrBrush::Private::header_size, GimpBrushHeader::height, IMAGE, KoResource::image, LIGHTNESSMAP, GimpBrushHeader::magic_number, KisGbrBrush::Private::magic_number, MASK, KoResource::name, KisBrush::setBrushApplication(), setBrushTipImage(), KisBrush::setBrushType(), KisColorfulBrush::setHasColorAndTransparency(), KisBrush::setHeight(), KoResource::setName(), KisBrush::setSpacing(), KoResource::setValid(), KisBrush::setWidth(), GimpBrushHeader::spacing, GimpBrushHeader::version, KisGbrBrush::Private::version, warnKrita, and GimpBrushHeader::width.

◆ initFromPaintDev()

bool KisGbrBrush::initFromPaintDev ( KisPaintDeviceSP image,
int x,
int y,
int w,
int h )
private

◆ loadFromDevice()

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

Implements KoResource.

Reimplemented in KisImagePipeBrush.

Definition at line 125 of file kis_gbr_brush.cpp.

126{
127 Q_UNUSED(resourcesInterface);
128 d->data = dev->readAll();
129 return init();
130}

References d, KisGbrBrush::Private::data, and init().

◆ makeMaskImage()

void KisGbrBrush::makeMaskImage ( bool preserveAlpha)
virtual

Convert the mask to inverted gray scale, so it is alpha mask. It can be used as MASK brush type. This operates on the data of the brush, so it destruct the original brush data.

Parameters
preserveAlphaconvert to grayscale, but save as full RGBA format, to allow preserving lightness option

Reimplemented in KisImagePipeBrush.

Definition at line 371 of file kis_gbr_brush.cpp.

372{
373 if (!isImageType()) {
374 return;
375 }
376
377 QImage brushTip = brushTipImage();
378
379 if (!preserveAlpha) {
380 const int imageWidth = brushTip.width();
381 const int imageHeight = brushTip.height();
382 QImage image(imageWidth, imageHeight, QImage::Format_Indexed8);
383 QVector<QRgb> table;
384 for (int i = 0; i < 256; ++i) {
385 table.append(qRgb(i, i, i));
386 }
387 image.setColorTable(table);
388
389 for (int y = 0; y < imageHeight; y++) {
390 QRgb *pixel = reinterpret_cast<QRgb *>(brushTip.scanLine(y));
391 uchar * dstPixel = image.scanLine(y);
392 for (int x = 0; x < imageWidth; x++) {
393 QRgb c = pixel[x];
394 float alpha = qAlpha(c) / 255.0f;
395 // linear interpolation with maximum gray value which is transparent in the mask
396 //int a = (qGray(c) * alpha) + ((1.0 - alpha) * 255);
397 // single multiplication version
398 int a = 255 + int(alpha * (qGray(c) - 255));
399 dstPixel[x] = (uchar)a;
400 }
401 }
404 }
405 else {
406 setBrushTipImage(brushTip);
408 }
409
413}
void resetOutlineCache()
void clearBrushPyramid()
virtual bool isImageType() const
QImage brushTipImage() const override
brushImage the image the brush tip can paint with. Not all brush types have a single image.

References ALPHAMASK, KisColorfulBrush::brushTipImage(), KisBrush::clearBrushPyramid(), IMAGE, KoResource::image, KisColorfulBrush::isImageType(), MASK, KisBrush::resetOutlineCache(), KisBrush::setBrushApplication(), setBrushTipImage(), and KisBrush::setBrushType().

◆ operator=()

KisGbrBrush & KisGbrBrush::operator= ( const KisGbrBrush & rhs)

◆ resourceType()

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

Reimplemented from KisBrush.

Definition at line 58 of file kis_gbr_brush.h.

58 {
59 return QPair<QString, QString>(ResourceType::Brushes, ResourceSubType::GbrBrushes);
60 }
const QString GbrBrushes
const QString Brushes

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

◆ saveToDevice()

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

Reimplemented from KoResource.

Reimplemented in KisImagePipeBrush.

Definition at line 291 of file kis_gbr_brush.cpp.

292{
293 if (!valid() || brushTipImage().isNull()) {
294 qWarning() << "this brush is not valid, set a brush tip image" << filename();
295 return false;
296 }
298 QByteArray utf8Name = name().toUtf8(); // Names in v2 brushes are in UTF-8
299 char const* name = utf8Name.data();
300 int nameLength = qstrlen(name);
301 int wrote;
302
303 bh.header_size = qToBigEndian((quint32)sizeof(GimpBrushHeader) + nameLength + 1);
304 bh.version = qToBigEndian((quint32)2); // Only RGBA8 data needed atm, no cinepaint stuff
305 bh.width = qToBigEndian((quint32)width());
306 bh.height = qToBigEndian((quint32)height());
307 // Hardcoded, 4 bytes RGBA or 1 byte GREY
308 if (!isImageType()) {
309 bh.bytes = qToBigEndian((quint32)1);
310 }
311 else {
312 bh.bytes = qToBigEndian((quint32)4);
313 }
314 bh.magic_number = qToBigEndian((quint32)GimpV2BrushMagic);
315 bh.spacing = qToBigEndian(static_cast<quint32>(spacing() * 100.0));
316
317 // Write header: first bh, then the name
318 QByteArray bytes = QByteArray::fromRawData(reinterpret_cast<char*>(&bh), sizeof(GimpBrushHeader));
319 wrote = dev->write(bytes);
320 bytes.clear();
321
322 if (wrote == -1) {
323 return false;
324 }
325
326 wrote = dev->write(name, nameLength + 1);
327
328 if (wrote == -1) {
329 return false;
330 }
331
332 int k = 0;
333
334 QImage image = brushTipImage();
335
336 if (!isImageType()) {
337 bytes.resize(width() * height());
338 for (qint32 y = 0; y < height(); y++) {
339 for (qint32 x = 0; x < width(); x++) {
340 QRgb c = image.pixel(x, y);
341 bytes[k++] = static_cast<char>(255 - qRed(c)); // red == blue == green
342 }
343 }
344 } else {
345 bytes.resize(width() * height() * 4);
346 for (qint32 y = 0; y < height(); y++) {
347 for (qint32 x = 0; x < width(); x++) {
348 // order for gimp brushes, v2 is: RGBA
349 QRgb pixel = image.pixel(x, y);
350 bytes[k++] = static_cast<char>(qRed(pixel));
351 bytes[k++] = static_cast<char>(qGreen(pixel));
352 bytes[k++] = static_cast<char>(qBlue(pixel));
353 bytes[k++] = static_cast<char>(qAlpha(pixel));
354 }
355 }
356 }
357
358 wrote = dev->write(bytes);
359 if (wrote == -1) {
360 return false;
361 }
362 return true;
363}
double spacing() const
quint32 const GimpV2BrushMagic

References KisColorfulBrush::brushTipImage(), GimpBrushHeader::bytes, KoResource::filename, GimpV2BrushMagic, GimpBrushHeader::header_size, KisBrush::height(), GimpBrushHeader::height, KoResource::image, KisColorfulBrush::isImageType(), GimpBrushHeader::magic_number, KoResource::name, KisBrush::spacing(), GimpBrushHeader::spacing, KoResource::valid, GimpBrushHeader::version, KisBrush::width(), and GimpBrushHeader::width.

◆ setBrushTipImage()

void KisGbrBrush::setBrushTipImage ( const QImage & image)
overrideprotectedvirtual

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 from KisBrush.

Definition at line 365 of file kis_gbr_brush.cpp.

366{
368 setValid(true);
369}
virtual void setBrushTipImage(const QImage &image)

References KoResource::image, KisBrush::setBrushTipImage(), and KoResource::setValid().

◆ toXML()

void KisGbrBrush::toXML ( QDomDocument & ,
QDomElement & element ) const
overrideprotectedvirtual

Serialize this brush to XML.

Reimplemented from KisColorfulBrush.

Definition at line 415 of file kis_gbr_brush.cpp.

416{
417 predefinedBrushToXML("gbr_brush", e);
419}
void predefinedBrushToXML(const QString &type, QDomElement &e) const
void toXML(QDomDocument &d, QDomElement &e) const override

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

Friends And Related Symbol Documentation

◆ KisBrushExport

friend class KisBrushExport
friend

Definition at line 82 of file kis_gbr_brush.h.

◆ KisImageBrushesPipe

friend class KisImageBrushesPipe
friend

save the content of this brush to an IO device

Definition at line 81 of file kis_gbr_brush.h.

Member Data Documentation

◆ d

Private* const KisGbrBrush::d
private

Definition at line 94 of file kis_gbr_brush.h.


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