[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/krita
From: Edward Apap <schumifer () hotmail ! com>
Date: 2010-01-24 18:18:52
Message-ID: 1264357132.338456.32287.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1079650 by eapap:
* Implemented variable radius selection feathering
M +2 -0 plugins/extensions/modify_selection/CMakeLists.txt
A plugins/extensions/modify_selection/dlg_feather_selection.cc \
[License: GPL (v2+)] A \
plugins/extensions/modify_selection/dlg_feather_selection.h [License: GPL (v2+)] M \
+28 -0 plugins/extensions/modify_selection/modify_selection.cc M +1 -0 \
plugins/extensions/modify_selection/modify_selection.h M +1 -0 \
plugins/extensions/modify_selection/modify_selection.rc A \
plugins/extensions/modify_selection/wdg_feather_selection.ui M +50 -50 \
plugins/extensions/modify_selection/wdg_grow_selection.ui M +48 -51 \
ui/kis_selection_manager.cc M +1 -2 ui/kis_selection_manager.h
--- trunk/koffice/krita/plugins/extensions/modify_selection/CMakeLists.txt \
#1079649:1079650 @@ -4,6 +4,7 @@
dlg_grow_selection.cc
dlg_shrink_selection.cc
dlg_border_selection.cc
+ dlg_feather_selection.cc
modify_selection.cc
)
@@ -12,6 +13,7 @@
wdg_grow_selection.ui
wdg_shrink_selection.ui
wdg_border_selection.ui
+ wdg_feather_selection.ui
)
kde4_add_plugin(kritamodifyselection ${kritamodifyselection_PART_SRCS})
--- trunk/koffice/krita/plugins/extensions/modify_selection/modify_selection.cc \
#1079649:1079650 @@ -52,6 +52,7 @@
#include "dlg_grow_selection.h"
#include "dlg_shrink_selection.h"
#include "dlg_border_selection.h"
+#include "dlg_feather_selection.h"
K_PLUGIN_FACTORY(ModifySelectionFactory, registerPlugin<ModifySelection>();)
K_EXPORT_PLUGIN(ModifySelectionFactory("krita"))
@@ -74,18 +75,23 @@
actionCollection()->addAction("shrinkselection", b);
KAction* c = new KAction(i18n("Border selection..."), this);
actionCollection()->addAction("borderselection", c);
+ KAction* d = new KAction(i18n("Feather selection..."), this);
+ actionCollection()->addAction("featherselection", d);
Q_CHECK_PTR(a);
Q_CHECK_PTR(b);
Q_CHECK_PTR(c);
+ Q_CHECK_PTR(d);
connect(a, SIGNAL(triggered()), this, SLOT(slotGrowSelection()));
connect(b, SIGNAL(triggered()), this, SLOT(slotShrinkSelection()));
connect(c, SIGNAL(triggered()), this, SLOT(slotBorderSelection()));
+ connect(d, SIGNAL(triggered()), this, SLOT(slotFeatherSelection()));
m_view->selectionManager()->addSelectionAction(a);
m_view->selectionManager()->addSelectionAction(b);
m_view->selectionManager()->addSelectionAction(c);
+ m_view->selectionManager()->addSelectionAction(d);
}
}
@@ -165,4 +171,26 @@
delete dlgBorderSelection;
}
+void ModifySelection::slotFeatherSelection()
+{
+ KisImageWSP image = m_view->image();
+
+ if (!image) return;
+
+ DlgFeatherSelection * dlgFeatherSelection = new DlgFeatherSelection(m_view, \
"FeatherSelection"); + Q_CHECK_PTR(dlgFeatherSelection);
+
+ dlgFeatherSelection->setCaption(i18n("Feather Selection"));
+
+ KisConfig cfg;
+
+ if (dlgFeatherSelection->exec() == QDialog::Accepted) {
+ qint32 radius = dlgFeatherSelection->radius();
+
+ m_view->selectionManager()->feather(radius);
+ }
+
+ delete dlgFeatherSelection;
+}
+
#include "modify_selection.moc"
--- trunk/koffice/krita/plugins/extensions/modify_selection/modify_selection.h \
#1079649:1079650 @@ -38,6 +38,7 @@
void slotGrowSelection();
void slotShrinkSelection();
void slotBorderSelection();
+ void slotFeatherSelection();
private:
--- trunk/koffice/krita/plugins/extensions/modify_selection/modify_selection.rc \
#1079649:1079650 @@ -2,6 +2,7 @@
<kpartgui library="kritamodifyselection" version="6">
<MenuBar>
<Menu name="Select"><text>&Select</text>
+ <Action name="featherselection"/>
<Action name="growselection"/>
<Action name="shrinkselection"/>
<Action name="borderselection"/>
--- trunk/koffice/krita/plugins/extensions/modify_selection/wdg_grow_selection.ui \
#1079649:1079650 @@ -1,51 +1,51 @@
-<ui version="4.0" stdsetdef="1" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
- <class>WdgGrowSelection</class>
- <widget class="QWidget" name="WdgGrowSelection" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>255</width>
- <height>101</height>
- </rect>
- </property>
- <layout class="QGridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="textLabel1" >
- <property name="text" >
- <string>Grow selection by</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QSpinBox" name="radiusSpinBox" >
- <property name="maximum" >
- <number>10000</number>
- </property>
- <property name="minimum" >
- <number>1</number>
- </property>
- <property name="value" >
- <number>1</number>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="QComboBox" name="comboBox1" >
- <item>
- <property name="text" >
- <string>pixels</string>
- </property>
- </item>
- </widget>
- </item>
- </layout>
- </widget>
- <layoutdefault spacing="6" margin="11" />
- <tabstops>
- <tabstop>radiusSpinBox</tabstop>
- </tabstops>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WdgGrowSelection</class>
+ <widget class="QWidget" name="WdgGrowSelection">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>255</width>
+ <height>80</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout">
+ <item row="1" column="0">
+ <widget class="QSpinBox" name="radiusSpinBox">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>10000</number>
+ </property>
+ <property name="value">
+ <number>1</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="comboBox1">
+ <item>
+ <property name="text">
+ <string>pixels</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="textLabel1">
+ <property name="text">
+ <string>Grow selection by</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <tabstops>
+ <tabstop>radiusSpinBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
</ui>
--- trunk/koffice/krita/ui/kis_selection_manager.cc #1079649:1079650
@@ -99,7 +99,6 @@
m_reselect(0),
m_invert(0),
m_toNewLayer(0),
- m_feather(0),
m_smooth(0),
m_load(0),
m_save(0),
@@ -172,11 +171,6 @@
m_cutToNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_J));
connect(m_cutToNewLayer, SIGNAL(triggered()), this, SLOT(cutToNewLayer()));
- m_feather = new KAction(i18n("Feather"), this);
- collection->addAction("feather", m_feather);
- m_feather->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_D));
- connect(m_feather, SIGNAL(triggered()), this, SLOT(feather()));
-
m_fillForegroundColor = new KAction(i18n("Fill with Foreground Color"), this);
collection->addAction("fill_selection_foreground_color", m_fillForegroundColor);
m_fillForegroundColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Backspace));
@@ -281,7 +275,6 @@
bool hasPixelSelection = enable && l->selection() && \
l->selection()->hasPixelSelection() && !m_view->selection()->isDeselected();
m_invert->setEnabled(hasPixelSelection);
- m_feather->setEnabled(hasPixelSelection);
m_smooth->setEnabled(enable);
// m_load->setEnabled(enable);
@@ -738,50 +731,6 @@
paste();
}
-
-void KisSelectionManager::feather()
-{
- KisImageWSP image = m_view->image();
- if (!image) return;
- if (!m_view->selection())
- return;
-
- KisPixelSelectionSP selection = \
m_view->selection()->getOrCreatePixelSelection();
- KisSelectionTransaction * t = new KisSelectionTransaction(i18n("Feather..."), \
image, m_view->selection());
- Q_CHECK_PTR(t);
-
-
- // XXX: we should let gaussian blur & others influence alpha channels as well
- // (on demand of the caller)
-
- KisConvolutionPainter painter(selection);
-
- KisConvolutionKernelSP k = new KisConvolutionKernel(3, 3, 0, 16);
-
- k->data()[0] = 1;
- k->data()[1] = 2;
- k->data()[2] = 1;
- k->data()[3] = 2;
- k->data()[4] = 4;
- k->data()[5] = 2;
- k->data()[6] = 1;
- k->data()[7] = 2;
- k->data()[8] = 1;
-
- QRect rect = selection->selectedExactRect();
- // Make sure we've got enough space around the edges.
- rect = QRect(rect.x() - 3, rect.y() - 3, rect.width() + 6, rect.height() + 6);
- rect &= QRect(0, 0, image->width(), image->height());
- painter.setChannelFlags(selection->colorSpace()->channelFlags(false, true, \
false, false));
- painter.applyMatrix(k, selection, rect.topLeft(), rect.topLeft(), rect.size(), \
BORDER_AVOID);
- painter.end();
-
- m_view->document()->addCommand(t);
- m_view->selection()->setDirty(image->bounds());
- selectionChanged();
-
-}
-
void KisSelectionManager::toggleDisplaySelection()
{
KisCanvasDecoration* decoration = m_view->canvasBase()->decoration("selection");
@@ -1489,6 +1438,54 @@
selectionChanged();
}
+void KisSelectionManager::feather(qint32 radius)
+{
+ KisImageWSP image = m_view->image();
+ if (!image) return;
+ if (!m_view->selection())
+ return;
+
+ KisPixelSelectionSP selection = \
m_view->selection()->getOrCreatePixelSelection(); + KisSelectionTransaction * t = \
new KisSelectionTransaction(i18n("Feather..."), image, m_view->selection()); + \
Q_CHECK_PTR(t); +
+ // compute horizontal kernel
+ const uint kernelSize = radius * 2 + 1;
+ Matrix<qreal, Dynamic, Dynamic> gaussianMatrix(1, kernelSize);
+
+ const qreal multiplicand = 1 / (2 * M_PI * radius * radius);
+ const qreal exponentMultiplicand = 1 / (2 * radius * radius);
+
+ for (uint x = 0; x < kernelSize; x++)
+ {
+ uint xDistance = qAbs((int)radius - (int)x);
+ gaussianMatrix(0, x) = multiplicand * exp( -(qreal)((xDistance * xDistance) \
+ (radius * radius)) * exponentMultiplicand ); + }
+
+ KisConvolutionKernelSP kernelHoriz = \
KisConvolutionKernel::fromMatrix(gaussianMatrix, 0, gaussianMatrix.sum()); + \
KisConvolutionKernelSP kernelVertical = \
KisConvolutionKernel::fromMatrix(gaussianMatrix.transpose(), 0, \
gaussianMatrix.sum()); +
+ QRect rect = selection->selectedExactRect();
+ // Make sure we've got enough space around the edges.
+ rect.adjust(-kernelSize, -kernelSize, kernelSize, kernelSize);
+ rect &= QRect(0, 0, image->width(), image->height());
+
+ KisPaintDeviceSP interm = new KisPaintDevice(selection->colorSpace());
+ KisConvolutionPainter horizPainter(interm);
+ horizPainter.setChannelFlags(interm->colorSpace()->channelFlags(false, true, \
false, false)); + horizPainter.applyMatrix(kernelHoriz, selection, rect.topLeft(), \
rect.topLeft(), rect.size(), BORDER_AVOID); + horizPainter.end();
+
+ KisConvolutionPainter verticalPainter(selection);
+ verticalPainter.setChannelFlags(selection->colorSpace()->channelFlags(false, \
true, false, false)); + verticalPainter.applyMatrix(kernelVertical, interm, \
rect.topLeft(), rect.topLeft(), rect.size(), BORDER_AVOID); + \
verticalPainter.end(); +
+ m_view->document()->addCommand(t);
+ m_view->selection()->setDirty(image->bounds());
+ selectionChanged();
+}
+
#define RINT(x) floor ((x) + 0.5)
void KisSelectionManager::computeBorder(qint32 *circ, qint32 xradius, qint32 \
yradius)
--- trunk/koffice/krita/ui/kis_selection_manager.h #1079649:1079650
@@ -84,7 +84,6 @@
void invert();
void smooth();
void copySelectionToNewLayer();
- void feather();
void toggleDisplaySelection();
void shapeSelectionChanged();
@@ -96,6 +95,7 @@
void grow(qint32 xradius, qint32 yradius);
void shrink(qint32 xradius, qint32 yradius, bool edge_lock);
void border(qint32 xradius, qint32 yradius);
+ void feather(qint32 radius);
// the following functions are needed for the siox tool
// they might be also useful on its own
void erode();
@@ -132,7 +132,6 @@
KAction *m_reselect;
KAction *m_invert;
KAction *m_toNewLayer;
- KAction *m_feather;
KAction *m_smooth;
KAction *m_load;
KAction *m_save;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic