author | leseb <leseb> | 2002-06-27 08:42:50 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-27 08:42:50 (UTC) |
commit | 596749dc52cc89b5325f9089b79d0b9cc8240682 (patch) (side-by-side diff) | |
tree | 7d400323444c6ea5c1bfb5d9c2f8dfb3a2a01435 /noncore/graphics/drawpad/filltool.cpp | |
parent | 4080b87bd8f9a76217ba8ae06f2a1b2ca9bcc285 (diff) | |
download | opie-596749dc52cc89b5325f9089b79d0b9cc8240682.zip opie-596749dc52cc89b5325f9089b79d0b9cc8240682.tar.gz opie-596749dc52cc89b5325f9089b79d0b9cc8240682.tar.bz2 |
Try to take AA into account when filling
Diffstat (limited to 'noncore/graphics/drawpad/filltool.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp index d323cc2..0177e1c 100644 --- a/noncore/graphics/drawpad/filltool.cpp +++ b/noncore/graphics/drawpad/filltool.cpp @@ -21,2 +21,4 @@ +const int FILL_THRESHOLD = 65536; + FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) @@ -40,3 +42,19 @@ void FillTool::mousePressEvent(QMouseEvent* e) if (m_oldRgb != m_fillRgb) { + if (m_pDrawPad->antiAliasing()) { + m_mask.create(m_image.width(), m_image.height(), 8, 2); + m_mask.fill(0); + + fillMaskLine(x, y); + + for (int i = 0; i < m_image.width(); i++) { + for (int j = 0; j < m_image.height(); j++) { + if (m_mask.pixelIndex(i, j) == 1) { + setInterpolatedPixel(i, j); + } + } + } + + } else { fillLine(x, y); + } @@ -90 +108,53 @@ void FillTool::fillLine(int x, int y) } + +void FillTool::fillMaskLine(int x, int y) +{ + if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { + if (m_mask.pixelIndex(x, y) == 0) { + if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { + int x1, x2; + + x1 = x - 1; + x2 = x + 1; + + while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { + x1--; + } + + while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { + x2++; + } + + for (int i = x1 + 1; i < x2; i++) { + m_mask.setPixel(i, y, 1); + } + + for (int i = x1 + 1; i < x2; i++) { + fillMaskLine(i, y - 1); + } + + for (int i = x1 + 1; i < x2; i++) { + fillMaskLine(i, y + 1); + } + } + } + } +} + +void FillTool::setInterpolatedPixel(int x, int y) +{ + int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255); + int fillGreen = QMIN(QMAX(qGreen(m_fillRgb) + qGreen(m_image.pixel(x, y)) - qGreen(m_oldRgb), 0), 255); + int fillBlue = QMIN(QMAX(qBlue(m_fillRgb) + qBlue(m_image.pixel(x, y)) - qBlue(m_oldRgb), 0), 255); + + m_image.setPixel(x, y, qRgb(fillRed, fillGreen, fillBlue)); +} + +int FillTool::rgbDistance(QRgb rgb1, QRgb rgb2) +{ + int redDistance = qRed(rgb2) - qRed(rgb1); + int greenDistance = qGreen(rgb2) - qGreen(rgb1); + int blueDistance = qBlue(rgb2) - qBlue(rgb1); + + return (redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance); +} |