|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "bluredbrush.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tropcm.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qcolor></qcolor>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static QVector<qrgb> colorTable;</qrgb>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QImage rasterToQImage(const TRasterP &ras, bool premultiplied = false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QImage image;
|
|
Toshihiro Shimizu |
890ddd |
if (TRaster32P ras32 = ras)
|
|
Toshihiro Shimizu |
890ddd |
image = QImage(ras->getRawData(), ras->getLx(), ras->getLy(),
|
|
Toshihiro Shimizu |
890ddd |
premultiplied ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);
|
|
Toshihiro Shimizu |
890ddd |
else if (TRasterGR8P ras8 = ras) {
|
|
Toshihiro Shimizu |
890ddd |
image = QImage(ras->getRawData(), ras->getLx(), ras->getLy(), ras->getWrap(), QImage::Format_Indexed8);
|
|
Toshihiro Shimizu |
890ddd |
image.setColorTable(colorTable);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return image;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId, bool selective)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!out.getPointer() || !in.getPointer())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
assert(out->getSize() == in->getSize());
|
|
Toshihiro Shimizu |
890ddd |
int x, y;
|
|
Toshihiro Shimizu |
890ddd |
if (!selective) {
|
|
Toshihiro Shimizu |
890ddd |
for (y = 0; y < out->getLy(); y++) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x < out->getLx(); x++) {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
assert(x >= 0 && x < in->getLx());
|
|
Toshihiro Shimizu |
890ddd |
assert(y >= 0 && y < in->getLy());
|
|
Toshihiro Shimizu |
890ddd |
assert(x >= 0 && x < out->getLx());
|
|
Toshihiro Shimizu |
890ddd |
assert(y >= 0 && y < out->getLy());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *inPix = &in->pixels(y)[x];
|
|
Toshihiro Shimizu |
890ddd |
if (inPix->m == 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
TPixelCM32 *outPix = &out->pixels(y)[x];
|
|
Toshihiro Shimizu |
890ddd |
bool sameStyleId = styleId == outPix->getInk();
|
|
Toshihiro Shimizu |
890ddd |
int tone = sameStyleId ? outPix->getTone() * (255 - inPix->m) / 255 : outPix->getTone();
|
|
Toshihiro Shimizu |
890ddd |
int ink = !sameStyleId && outPix->getTone() < 255 - inPix->m ? outPix->getInk() : styleId;
|
|
Shinya Kitaoka |
12c444 |
*outPix = TPixelCM32(ink, outPix->getPaint(), std::min(255 - inPix->m, tone));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
for (y = 0; y < out->getLy(); y++) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x < out->getLx(); x++) {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
assert(x >= 0 && x < in->getLx());
|
|
Toshihiro Shimizu |
890ddd |
assert(y >= 0 && y < in->getLy());
|
|
Toshihiro Shimizu |
890ddd |
assert(x >= 0 && x < out->getLx());
|
|
Toshihiro Shimizu |
890ddd |
assert(y >= 0 && y < out->getLy());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *inPix = &in->pixels(y)[x];
|
|
Toshihiro Shimizu |
890ddd |
if (inPix->m == 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
TPixelCM32 *outPix = &out->pixels(y)[x];
|
|
Toshihiro Shimizu |
890ddd |
bool sameStyleId = styleId == outPix->getInk();
|
|
Toshihiro Shimizu |
890ddd |
int tone = sameStyleId ? outPix->getTone() * (255 - inPix->m) / 255 : outPix->getTone();
|
|
Toshihiro Shimizu |
890ddd |
int ink = outPix->getTone() < 255 && !sameStyleId && outPix->getTone() <= 255 - inPix->m ? outPix->getInk() : styleId;
|
|
Shinya Kitaoka |
12c444 |
*outPix = TPixelCM32(ink, outPix->getPaint(), std::min(255 - inPix->m, tone));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void eraseFromRasterCM(const TRasterCM32P &out, const TRaster32P &in,
|
|
Shinya Kitaoka |
3bfa54 |
bool selective, int selectedStyleId, const std::wstring &mode)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!out.getPointer() || !in.getPointer())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
assert(out->getSize() == in->getSize());
|
|
Toshihiro Shimizu |
890ddd |
bool eraseLine = mode == L"Lines" || mode == L"Lines & Areas";
|
|
Toshihiro Shimizu |
890ddd |
bool eraseAreas = mode == L"Areas" || mode == L"Lines & Areas";
|
|
Toshihiro Shimizu |
890ddd |
int x, y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (y = 0; y < out->getLy(); y++) {
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x < out->getLx(); x++) {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
assert(y >= 0 && y < in->getLy());
|
|
Toshihiro Shimizu |
890ddd |
assert(y >= 0 && y < out->getLy());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *inPix = &in->pixels(y)[x];
|
|
Toshihiro Shimizu |
890ddd |
if (inPix->m == 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
TPixelCM32 *outPix = &out->pixels(y)[x];
|
|
Toshihiro Shimizu |
890ddd |
bool eraseInk = !selective || (selective && selectedStyleId == outPix->getInk());
|
|
Toshihiro Shimizu |
890ddd |
bool erasePaint = !selective || (selective && selectedStyleId == outPix->getPaint());
|
|
Toshihiro Shimizu |
890ddd |
int paint = eraseAreas && erasePaint ? 0 : outPix->getPaint();
|
|
Shinya Kitaoka |
12c444 |
int tone = inPix->m > 0 && eraseLine && eraseInk ? std::max(outPix->getTone(), (int)inPix->m) : outPix->getTone();
|
|
Toshihiro Shimizu |
890ddd |
*outPix = TPixelCM32(outPix->getInk(), paint, tone);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP rasterFromQImage(const QImage &image) //no need of const& - Qt uses implicit sharing...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QImage::Format format = image.format();
|
|
Toshihiro Shimizu |
890ddd |
if (format == QImage::Format_ARGB32 || format == QImage::Format_ARGB32_Premultiplied)
|
|
Toshihiro Shimizu |
890ddd |
return TRaster32P(image.width(), image.height(), image.width(), (TPixelRGBM32 *)image.bits(), false);
|
|
Toshihiro Shimizu |
890ddd |
if (format == QImage::Format_Indexed8)
|
|
Toshihiro Shimizu |
890ddd |
return TRasterGR8P(image.width(), image.height(), image.bytesPerLine(), (TPixelGR8 *)image.bits(), false);
|
|
Toshihiro Shimizu |
890ddd |
return TRasterP();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=======================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//BluredBrush
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//=======================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BluredBrush::BluredBrush(const TRaster32P &ras, int size,
|
|
Toshihiro Shimizu |
890ddd |
const QRadialGradient &gradient, bool doDinamicOpacity)
|
|
Toshihiro Shimizu |
890ddd |
: m_ras(ras), m_size(size), m_lastPoint(0, 0), m_oldOpacity(0), m_enableDinamicOpacity(doDinamicOpacity)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_rasImage = rasterToQImage(m_ras, false);
|
|
Toshihiro Shimizu |
890ddd |
m_gradient = gradient;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (colorTable.size() == 0) {
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < 256; i++)
|
|
Toshihiro Shimizu |
890ddd |
colorTable.append(QColor(i, i, i).rgb());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BluredBrush::~BluredBrush()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BluredBrush::addPoint(const TThickPoint &p, double opacity)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double radius = p.thick * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
double brushRadius = m_size * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
double scaleFactor = radius / brushRadius;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPainter painter(&m_rasImage);
|
|
Toshihiro Shimizu |
890ddd |
painter.setRenderHint(QPainter::Antialiasing);
|
|
Toshihiro Shimizu |
890ddd |
painter.setPen(Qt::NoPen);
|
|
Toshihiro Shimizu |
890ddd |
painter.setBrush(m_gradient);
|
|
Toshihiro Shimizu |
890ddd |
painter.setMatrix(QMatrix(scaleFactor, 0.0, 0.0, scaleFactor, p.x - radius, p.y - radius), false);
|
|
Toshihiro Shimizu |
890ddd |
if (m_enableDinamicOpacity)
|
|
Toshihiro Shimizu |
890ddd |
painter.setOpacity(opacity);
|
|
Toshihiro Shimizu |
890ddd |
painter.drawEllipse(0, 0, m_size, m_size);
|
|
Toshihiro Shimizu |
890ddd |
painter.end();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_lastPoint = p;
|
|
Toshihiro Shimizu |
890ddd |
m_oldOpacity = opacity;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BluredBrush::addArc(const TThickPoint &pa, const TThickPoint &pb, const TThickPoint &pc, double opacityA, double opacityC)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QPainter painter(&m_rasImage);
|
|
Toshihiro Shimizu |
890ddd |
painter.setRenderHint(QPainter::Antialiasing);
|
|
Toshihiro Shimizu |
890ddd |
painter.setPen(Qt::NoPen);
|
|
Toshihiro Shimizu |
890ddd |
//painter.setBrush(m_gradient);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickQuadratic q(pa, pb, pc);
|
|
Toshihiro Shimizu |
890ddd |
double brushRadius = m_size * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
double t = 0;
|
|
Toshihiro Shimizu |
890ddd |
while (t <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
t = getNextPadPosition(q, t);
|
|
Toshihiro Shimizu |
890ddd |
if (t > 1)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point = q.getThickPoint(t);
|
|
Toshihiro Shimizu |
890ddd |
double radius = point.thick * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
double scaleFactor = radius / brushRadius;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
painter.setMatrix(QMatrix(scaleFactor, 0.0, 0.0, scaleFactor, point.x - radius, point.y - radius), false);
|
|
Toshihiro Shimizu |
890ddd |
if (m_enableDinamicOpacity) {
|
|
Toshihiro Shimizu |
890ddd |
double opacity = opacityA + ((opacityC - opacityA) * t);
|
|
Toshihiro Shimizu |
890ddd |
if (fabs(opacity - m_oldOpacity) > 0.01)
|
|
Toshihiro Shimizu |
890ddd |
opacity = opacity > m_oldOpacity ? m_oldOpacity + 0.01 : m_oldOpacity - 0.01;
|
|
Toshihiro Shimizu |
890ddd |
painter.setOpacity(opacity);
|
|
Toshihiro Shimizu |
890ddd |
painter.setCompositionMode(QPainter::CompositionMode_DestinationAtop);
|
|
Toshihiro Shimizu |
890ddd |
m_oldOpacity = opacity;
|
|
Toshihiro Shimizu |
890ddd |
painter.setBrush(QColor(0, 0, 0, 255));
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
painter.setBrush(m_gradient);
|
|
Toshihiro Shimizu |
890ddd |
painter.drawEllipse(0, 0, m_size, m_size);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_lastPoint = point;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
painter.end();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double BluredBrush::getNextPadPosition(const TThickQuadratic &q, double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p = m_lastPoint;
|
|
Toshihiro Shimizu |
890ddd |
double d = 0.12 * p.thick;
|
|
Toshihiro Shimizu |
890ddd |
d = d >= 1.0 ? d : 1.0;
|
|
Toshihiro Shimizu |
890ddd |
double d2 = d * d;
|
|
Toshihiro Shimizu |
890ddd |
if (norm2(q.getP2() - p) < d2)
|
|
Toshihiro Shimizu |
890ddd |
return 2.0;
|
|
Toshihiro Shimizu |
890ddd |
double t2 = (t + 1) * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p2 = q.getThickPoint(t2);
|
|
Toshihiro Shimizu |
890ddd |
double distance2 = norm2(p2 - p);
|
|
Toshihiro Shimizu |
890ddd |
double lastTMin = t;
|
|
Toshihiro Shimizu |
890ddd |
double lastTMax = 1;
|
|
Toshihiro Shimizu |
890ddd |
while (!areAlmostEqual(d2, distance2, 0.25) && t2 != lastTMin && t2 != lastTMax) {
|
|
Toshihiro Shimizu |
890ddd |
if (distance2 > d2) {
|
|
Toshihiro Shimizu |
890ddd |
lastTMax = t2;
|
|
Toshihiro Shimizu |
890ddd |
t2 = (lastTMin + t2) * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
lastTMin = t2;
|
|
Toshihiro Shimizu |
890ddd |
t2 = (lastTMax + t2) * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
p2 = q.getThickPoint(t2);
|
|
Toshihiro Shimizu |
890ddd |
distance2 = norm2(p2 - p);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return t2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BluredBrush::updateDrawing(const TRasterP ras, const TRasterP rasBackup, const TPixel32 &color,
|
|
Toshihiro Shimizu |
890ddd |
const TRect &bbox, double opacity) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect rasRect = ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
TRect targetRect = bbox * rasRect;
|
|
Toshihiro Shimizu |
890ddd |
if (targetRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
QImage image = rasterToQImage(ras, true);
|
|
Toshihiro Shimizu |
890ddd |
QRect qTargetRect(targetRect.x0, targetRect.y0, targetRect.getLx(), targetRect.getLy());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QImage app(qTargetRect.size(), QImage::Format_ARGB32_Premultiplied);
|
|
Toshihiro Shimizu |
890ddd |
QPainter p2(&app);
|
|
Toshihiro Shimizu |
890ddd |
p2.setBrush(QColor(color.r, color.g, color.b));
|
|
Toshihiro Shimizu |
890ddd |
p2.drawRect(app.rect().adjusted(-1, -1, 0, 0));
|
|
Toshihiro Shimizu |
890ddd |
p2.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
Toshihiro Shimizu |
890ddd |
p2.drawImage(QPoint(), m_rasImage, qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p2.end();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ras->getPixelSize() == 4) {
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(&image);
|
|
Toshihiro Shimizu |
890ddd |
p.setClipRect(qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
Toshihiro Shimizu |
890ddd |
p.drawImage(qTargetRect, rasterToQImage(rasBackup, true), qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p.begin(&image);
|
|
Toshihiro Shimizu |
890ddd |
p.setOpacity(m_enableDinamicOpacity ? 1 : opacity);
|
|
Toshihiro Shimizu |
890ddd |
p.drawImage(qTargetRect, app, app.rect());
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
QImage targetImage = rasterToQImage(rasBackup).copy(qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
targetImage = targetImage.convertToFormat(QImage::Format_ARGB32_Premultiplied, colorTable);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(&targetImage);
|
|
Toshihiro Shimizu |
890ddd |
p.setOpacity(m_enableDinamicOpacity ? 1 : opacity);
|
|
Toshihiro Shimizu |
890ddd |
p.drawImage(QPoint(), app, app.rect());
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
targetImage = targetImage.convertToFormat(QImage::Format_Indexed8, colorTable);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterGR8P targetRas = rasterFromQImage(targetImage);
|
|
Toshihiro Shimizu |
890ddd |
ras->copy(targetRas, targetRect.getP00());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BluredBrush::eraseDrawing(const TRasterP ras, const TRasterP rasBackup, const TRect &bbox, double opacity) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!ras)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect rasRect = ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
TRect targetRect = bbox * rasRect;
|
|
Toshihiro Shimizu |
890ddd |
if (targetRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
QRect qTargetRect(targetRect.x0, targetRect.y0, targetRect.getLx(), targetRect.getLy());
|
|
Toshihiro Shimizu |
890ddd |
if (ras->getPixelSize() == 4) {
|
|
Toshihiro Shimizu |
890ddd |
QImage image = rasterToQImage(ras, true);
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(&image);
|
|
Toshihiro Shimizu |
890ddd |
p.setClipRect(qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
Toshihiro Shimizu |
890ddd |
p.drawImage(qTargetRect, rasterToQImage(rasBackup, true), qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
|
Toshihiro Shimizu |
890ddd |
p.setOpacity(opacity);
|
|
Toshihiro Shimizu |
890ddd |
p.drawImage(qTargetRect, m_rasImage, qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
} else if (ras->getPixelSize() != 4) {
|
|
Toshihiro Shimizu |
890ddd |
QImage targetImage = rasterToQImage(rasBackup).copy(qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
targetImage = targetImage.convertToFormat(QImage::Format_ARGB32_Premultiplied, colorTable);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QImage app(qTargetRect.size(), QImage::Format_ARGB32_Premultiplied);
|
|
Toshihiro Shimizu |
890ddd |
QPainter p2(&app);
|
|
Toshihiro Shimizu |
890ddd |
p2.setBrush(QColor(255, 255, 255));
|
|
Toshihiro Shimizu |
890ddd |
p2.drawRect(app.rect().adjusted(-1, -1, 0, 0));
|
|
Toshihiro Shimizu |
890ddd |
p2.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
Toshihiro Shimizu |
890ddd |
p2.drawImage(QPoint(), m_rasImage, qTargetRect);
|
|
Toshihiro Shimizu |
890ddd |
p2.end();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(&targetImage);
|
|
Toshihiro Shimizu |
890ddd |
p.setOpacity(opacity);
|
|
Toshihiro Shimizu |
890ddd |
p.drawImage(QPoint(), app, app.rect());
|
|
Toshihiro Shimizu |
890ddd |
p.end();
|
|
Toshihiro Shimizu |
890ddd |
targetImage = targetImage.convertToFormat(QImage::Format_Indexed8, colorTable);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterGR8P targetRas = rasterFromQImage(targetImage);
|
|
Toshihiro Shimizu |
890ddd |
ras->copy(targetRas, targetRect.getP00());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BluredBrush::updateDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM, const TRect &bbox,
|
|
Toshihiro Shimizu |
890ddd |
int styleId, bool selective) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!rasCM)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect rasRect = rasCM->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
TRect targetRect = bbox * rasRect;
|
|
Toshihiro Shimizu |
890ddd |
if (targetRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
rasCM->copy(rasBackupCM->extract(targetRect), targetRect.getP00());
|
|
Toshihiro Shimizu |
890ddd |
putOnRasterCM(rasCM->extract(targetRect), m_ras->extract(targetRect), styleId, selective);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BluredBrush::eraseDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM, const TRect &bbox,
|
|
Shinya Kitaoka |
3bfa54 |
bool selective, int selectedStyleId, const std::wstring &mode) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!rasCM)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect rasRect = rasCM->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
TRect targetRect = bbox * rasRect;
|
|
Toshihiro Shimizu |
890ddd |
if (targetRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
rasCM->extract(targetRect)->copy(rasBackupCM->extract(targetRect));
|
|
Toshihiro Shimizu |
890ddd |
eraseFromRasterCM(rasCM->extract(targetRect), m_ras->extract(targetRect), selective, selectedStyleId, mode);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
TRect BluredBrush::getBoundFromPoints(const std::vector<tthickpoint> &points) const</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(points.size() <= 3);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p = points[0];
|
|
Toshihiro Shimizu |
890ddd |
double radius = p.thick * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
TRectD rectD(p - TPointD(radius, radius), p + TPointD(radius, radius));
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 1; i < (int)points.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
p = points[i];
|
|
Toshihiro Shimizu |
890ddd |
radius = p.thick * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
rectD = rectD + TRectD(p - TPointD(radius, radius), p + TPointD(radius, radius));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TRect rect(tfloor(rectD.x0), tfloor(rectD.y0), tceil(rectD.x1), tceil(rectD.y1));
|
|
Toshihiro Shimizu |
890ddd |
return rect;
|
|
Toshihiro Shimizu |
890ddd |
}
|