~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/core/kis_boundary.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
#include <qpixmap.h>
 
19
#include <qpainter.h>
 
20
 
 
21
#include "kis_colorspace.h"
 
22
#include "kis_iterators_pixel.h"
 
23
#include "kis_paint_device.h"
 
24
#include "kis_boundary.h"
 
25
 
 
26
KisBoundary::KisBoundary(KisPaintDevice* dev) {
 
27
    m_device = dev;
 
28
    m_fuzzyness = 255 / 2;
 
29
}
 
30
 
 
31
bool KisBoundary::isDark(Q_UINT8 val) {
 
32
    return val < m_fuzzyness;
 
33
}
 
34
 
 
35
void KisBoundary::generateBoundary(int w, int h) {
 
36
    if (!m_device)
 
37
        return;
 
38
 
 
39
    KisColorSpace* cs = m_device->colorSpace();
 
40
 
 
41
    // Horizontal
 
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);
 
45
        bool darkTop;
 
46
        bool darkBot;
 
47
 
 
48
        m_horSegments.append(QValueList<PointPair>());
 
49
 
 
50
        while (!topIt.isDone()) {
 
51
            darkTop = cs->getAlpha(topIt.rawData());
 
52
            darkBot = cs->getAlpha(botIt.rawData());
 
53
            if (darkTop != darkBot) {
 
54
                // detected a change
 
55
                m_horSegments.back().append(qMakePair(KisPoint(botIt.x(), botIt.y()), 1));
 
56
            }
 
57
            ++topIt;
 
58
            ++botIt;
 
59
        }
 
60
    }
 
61
 
 
62
    // Vertical
 
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);
 
66
        bool darkLeft;
 
67
        bool darkRight;
 
68
 
 
69
        m_vertSegments.append(QValueList<PointPair>());
 
70
 
 
71
        while (!leftIt.isDone()) {
 
72
            darkLeft = cs->getAlpha(leftIt.rawData());
 
73
            darkRight = cs->getAlpha(rightIt.rawData());
 
74
            if (darkLeft != darkRight) {
 
75
                // detected a change
 
76
                m_vertSegments.back().append(qMakePair(KisPoint(rightIt.x(), rightIt.y()), 1));
 
77
            }
 
78
            ++leftIt;
 
79
            ++rightIt;
 
80
        }
 
81
    }
 
82
}
 
83