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