11#include <QImageReader>
37 Q_UNUSED(resourcesInterface);
41 QByteArray data = dev->readAll();
43 buf.open(QIODevice::ReadOnly);
44 QImageReader reader(&buf,
"PNG");
46 if (!reader.canRead()) {
47 dbgKrita <<
"Could not read brush" <<
filename() <<
". Error:" << reader.errorString();
52 if (reader.textKeys().contains(
"brush_spacing")) {
56 if (reader.textKeys().contains(
"brush_name")) {
57 setName(reader.text(
"brush_name"));
61 setName(info.completeBaseName());
64 QImage
image = reader.read();
67 dbgKrita <<
"Could not create image for" <<
filename() <<
". Error:" << reader.errorString();
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) {
84 const bool isAllGray =
image.allGray();
86 if (isAllGray && !hasAlpha) {
92 if ((
int)base.format() < (
int)QImage::Format_RGB32) {
93 base.convertTo(QImage::Format_ARGB32);
96 gc.fillRect(base.rect(), Qt::white);
97 gc.drawImage(0, 0,
image);
99 QImage converted = base.convertToFormat(QImage::Format_Grayscale8);
108 if ((
int)
image.format() != (
int)QImage::Format_ARGB32) {
109 image.convertTo(QImage::Format_ARGB32);
132 return QString(
".png");
virtual void setSpacing(double spacing)
virtual void setBrushType(enumBrushType type)
void predefinedBrushToXML(const QString &type, QDomElement &e) const
virtual void setBrushTipImage(const QImage &image)
void setWidth(qint32 width)
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)
void toXML(QDomDocument &d, QDomElement &e) const override
bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
QString defaultFileExtension() const override
void toXML(QDomDocument &d, QDomElement &e) const override
bool saveToDevice(QIODevice *dev) const override
KoResourceSP clone() const override
KisPngBrush(const QString &filename)
Construct brush to load filename later as brush.
QSharedPointer< KoResource > KoResourceSP
double toDouble(const QString &str, bool *ok=nullptr)
void setValid(bool valid)
void setName(const QString &name)