summaryrefslogtreecommitdiffstats
path: root/krita/core/kis_boundary.cc
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/core/kis_boundary.cc
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/core/kis_boundary.cc')
-rw-r--r--krita/core/kis_boundary.cc83
1 files changed, 83 insertions, 0 deletions
diff --git a/krita/core/kis_boundary.cc b/krita/core/kis_boundary.cc
new file mode 100644
index 00000000..24524aeb
--- /dev/null
+++ b/krita/core/kis_boundary.cc
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#include <qpixmap.h>
+#include <qpainter.h>
+
+#include "kis_colorspace.h"
+#include "kis_iterators_pixel.h"
+#include "kis_paint_device.h"
+#include "kis_boundary.h"
+
+KisBoundary::KisBoundary(KisPaintDevice* dev) {
+ m_device = dev;
+ m_fuzzyness = 255 / 2;
+}
+
+bool KisBoundary::isDark(Q_UINT8 val) {
+ return val < m_fuzzyness;
+}
+
+void KisBoundary::generateBoundary(int w, int h) {
+ if (!m_device)
+ return;
+
+ KisColorSpace* cs = m_device->colorSpace();
+
+ // Horizontal
+ for (int currentY = - 1; currentY < h; currentY++) {
+ KisHLineIteratorPixel topIt = m_device->createHLineIterator(0, currentY, w, false);
+ KisHLineIteratorPixel botIt = m_device->createHLineIterator(0, currentY + 1, w, false);
+ bool darkTop;
+ bool darkBot;
+
+ m_horSegments.append(QValueList<PointPair>());
+
+ while (!topIt.isDone()) {
+ darkTop = cs->getAlpha(topIt.rawData());
+ darkBot = cs->getAlpha(botIt.rawData());
+ if (darkTop != darkBot) {
+ // detected a change
+ m_horSegments.back().append(qMakePair(KisPoint(botIt.x(), botIt.y()), 1));
+ }
+ ++topIt;
+ ++botIt;
+ }
+ }
+
+ // Vertical
+ for (int currentX = - 1; currentX < w; currentX++) {
+ KisVLineIteratorPixel leftIt = m_device->createVLineIterator(currentX, 0, h, false);
+ KisVLineIteratorPixel rightIt = m_device->createVLineIterator(currentX + 1, 0, h, false);
+ bool darkLeft;
+ bool darkRight;
+
+ m_vertSegments.append(QValueList<PointPair>());
+
+ while (!leftIt.isDone()) {
+ darkLeft = cs->getAlpha(leftIt.rawData());
+ darkRight = cs->getAlpha(rightIt.rawData());
+ if (darkLeft != darkRight) {
+ // detected a change
+ m_vertSegments.back().append(qMakePair(KisPoint(rightIt.x(), rightIt.y()), 1));
+ }
+ ++leftIt;
+ ++rightIt;
+ }
+ }
+}
+