2
* Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "kis_colorspace.h"
22
#include "kis_iterators_pixel.h"
23
#include "kis_paint_device.h"
24
#include "kis_boundary.h"
26
KisBoundary::KisBoundary(KisPaintDevice* dev) {
28
m_fuzzyness = 255 / 2;
31
bool KisBoundary::isDark(Q_UINT8 val) {
32
return val < m_fuzzyness;
35
void KisBoundary::generateBoundary(int w, int h) {
39
KisColorSpace* cs = m_device->colorSpace();
42
for (int currentY = - 1; currentY < h; currentY++) {
43
KisHLineIteratorPixel topIt = m_device->createHLineIterator(0, currentY, w, false);
44
KisHLineIteratorPixel botIt = m_device->createHLineIterator(0, currentY + 1, w, false);
48
m_horSegments.append(QValueList<PointPair>());
50
while (!topIt.isDone()) {
51
darkTop = cs->getAlpha(topIt.rawData());
52
darkBot = cs->getAlpha(botIt.rawData());
53
if (darkTop != darkBot) {
55
m_horSegments.back().append(qMakePair(KisPoint(botIt.x(), botIt.y()), 1));
63
for (int currentX = - 1; currentX < w; currentX++) {
64
KisVLineIteratorPixel leftIt = m_device->createVLineIterator(currentX, 0, h, false);
65
KisVLineIteratorPixel rightIt = m_device->createVLineIterator(currentX + 1, 0, h, false);
69
m_vertSegments.append(QValueList<PointPair>());
71
while (!leftIt.isDone()) {
72
darkLeft = cs->getAlpha(leftIt.rawData());
73
darkRight = cs->getAlpha(rightIt.rawData());
74
if (darkLeft != darkRight) {
76
m_vertSegments.back().append(qMakePair(KisPoint(rightIt.x(), rightIt.y()), 1));