krita
kis_boundary.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qpixmap.h>
00019 #include <qpainter.h>
00020
00021 #include "kis_colorspace.h"
00022 #include "kis_iterators_pixel.h"
00023 #include "kis_paint_device.h"
00024 #include "kis_boundary.h"
00025
00026 KisBoundary::KisBoundary(KisPaintDevice* dev) {
00027 m_device = dev;
00028 m_fuzzyness = 255 / 2;
00029 }
00030
00031 bool KisBoundary::isDark(Q_UINT8 val) {
00032 return val < m_fuzzyness;
00033 }
00034
00035 void KisBoundary::generateBoundary(int w, int h) {
00036 if (!m_device)
00037 return;
00038
00039 KisColorSpace* cs = m_device->colorSpace();
00040
00041
00042 for (int currentY = - 1; currentY < h; currentY++) {
00043 KisHLineIteratorPixel topIt = m_device->createHLineIterator(0, currentY, w, false);
00044 KisHLineIteratorPixel botIt = m_device->createHLineIterator(0, currentY + 1, w, false);
00045 bool darkTop;
00046 bool darkBot;
00047
00048 m_horSegments.append(QValueList<PointPair>());
00049
00050 while (!topIt.isDone()) {
00051 darkTop = cs->getAlpha(topIt.rawData());
00052 darkBot = cs->getAlpha(botIt.rawData());
00053 if (darkTop != darkBot) {
00054
00055 m_horSegments.back().append(qMakePair(KisPoint(botIt.x(), botIt.y()), 1));
00056 }
00057 ++topIt;
00058 ++botIt;
00059 }
00060 }
00061
00062
00063 for (int currentX = - 1; currentX < w; currentX++) {
00064 KisVLineIteratorPixel leftIt = m_device->createVLineIterator(currentX, 0, h, false);
00065 KisVLineIteratorPixel rightIt = m_device->createVLineIterator(currentX + 1, 0, h, false);
00066 bool darkLeft;
00067 bool darkRight;
00068
00069 m_vertSegments.append(QValueList<PointPair>());
00070
00071 while (!leftIt.isDone()) {
00072 darkLeft = cs->getAlpha(leftIt.rawData());
00073 darkRight = cs->getAlpha(rightIt.rawData());
00074 if (darkLeft != darkRight) {
00075
00076 m_vertSegments.back().append(qMakePair(KisPoint(rightIt.x(), rightIt.y()), 1));
00077 }
00078 ++leftIt;
00079 ++rightIt;
00080 }
00081 }
00082 }
00083
|