Commit ebdd8f8c authored by Blackbeard (alberto flores)'s avatar Blackbeard (alberto flores) 🚢

Convert brushTip to MaskImage

parent 0b2ef645
......@@ -25,7 +25,7 @@
#include <KoShapePainter.h>
#define DEFAULT_SPACING 5.0
#define DEFAULT_SPACING 1.0
KisVectorShapeObject::KisVectorShapeObject(const QString& filename)
: KisScalingSizeBrush(filename)
......@@ -84,6 +84,50 @@ void KisVectorShapeObject::renderImage(int width, int height)
// m_image = theImage;
}
void KisVectorShapeObject::makeMaskImage()
{
if (!hasColor()) {
return;
}
QImage brushTip = brushTipImage();
if (brushTip.width() == width() && brushTip.height() == height()) {
int imageWidth = width();
int imageHeight = height();
QImage image(imageWidth, imageHeight, QImage::Format_Indexed8);
QVector<QRgb> table;
for (int i = 0; i < 256; ++i) {
table.append(qRgb(i, i, i));
}
image.setColorTable(table);
for (int y = 0; y < imageHeight; y++) {
QRgb *pixel = reinterpret_cast<QRgb *>(brushTip.scanLine(y));
uchar * dstPixel = image.scanLine(y);
for (int x = 0; x < imageWidth; x++) {
QRgb c = pixel[x];
float alpha = qAlpha(c) / 255.0f;
// linear interpolation with maximum gray value which is transparent in the mask
//int a = (qGray(c) * alpha) + ((1.0 - alpha) * 255);
// single multiplication version
int a = 255 + alpha * (qGray(c) - 255);
dstPixel[x] = (uchar)a;
}
}
setBrushTipImage(image);
}
setHasColor(false);
// setUseColorAsMask(false);
resetBoundary();
clearBrushPyramid();
}
enumBrushType KisVectorShapeObject::brushType() const
{
return MASK;
......
......@@ -65,6 +65,12 @@ public:
/**
* Convert the mask to inverted gray scale, so it is alpha mask.
* It can be used as MASK brush type. This operates on the date of the brush,
* so it destruct the original brush data
*/
virtual void makeMaskImage();
/**
* @return a preview of the brush
......
......@@ -81,6 +81,13 @@ public:
addBrush(brush);
}
void makeMaskImage() {
Q_FOREACH (KisVectorShapeObject * brush, m_brushes) {
brush->makeMaskImage();
}
}
private:
int m_currentIndex;
KisVectorBrushParasite m_parasite;
......@@ -117,7 +124,7 @@ KisVectorAnimatedBrush::~KisVectorAnimatedBrush()
enumBrushType KisVectorAnimatedBrush::brushType() const
{
return PIPE_IMAGE;
return MASK;
}
KisBrush* KisVectorAnimatedBrush::clone() const
......@@ -305,3 +312,8 @@ KisFixedPaintDeviceSP KisVectorAnimatedBrush::paintDevice(
return m_d->brushesPipe.paintDevice(colorSpace, shape, info, subPixelX, subPixelY);
}
void KisVectorAnimatedBrush::makeMaskImage()
{
m_d->brushesPipe.makeMaskImage();
// setUseColorAsMask(false);
}
......@@ -74,6 +74,7 @@ public:
const KisPaintInformation& info,
double subPixelX = 0, double subPixelY = 0) const override;
void makeMaskImage() override;
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment