[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47988] trunk/blender/source/blender: feather option for dilate/erode node - needed for alpha masks so we can ( blur in/out), currently only positive values supported.
Campbell Barton
ideasman42 at gmail.com
Sat Jun 16 15:46:30 CEST 2012
Revision: 47988
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47988
Author: campbellbarton
Date: 2012-06-16 13:46:20 +0000 (Sat, 16 Jun 2012)
Log Message:
-----------
feather option for dilate/erode node - needed for alpha masks so we can (blur in/out), currently only positive values supported.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/node.c
trunk/blender/source/blender/compositor/CMakeLists.txt
trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.cpp
trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.h
trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h
trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
trunk/blender/source/blender/makesdna/DNA_node_types.h
trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
Added Paths:
-----------
trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/blenkernel/intern/node.c 2012-06-16 13:46:20 UTC (rev 47988)
@@ -2098,4 +2098,3 @@
}
}
}
-
Modified: trunk/blender/source/blender/compositor/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/compositor/CMakeLists.txt 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/compositor/CMakeLists.txt 2012-06-16 13:46:20 UTC (rev 47988)
@@ -288,6 +288,10 @@
nodes/COM_BokehBlurNode.h
nodes/COM_DirectionalBlurNode.cpp
nodes/COM_DirectionalBlurNode.h
+ operations/COM_GaussianAlphaXBlurOperation.cpp
+ operations/COM_GaussianAlphaXBlurOperation.h
+ operations/COM_GaussianAlphaYBlurOperation.cpp
+ operations/COM_GaussianAlphaYBlurOperation.h
operations/COM_GaussianXBlurOperation.cpp
operations/COM_GaussianXBlurOperation.h
operations/COM_GaussianYBlurOperation.cpp
Modified: trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.cpp 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.cpp 2012-06-16 13:46:20 UTC (rev 47988)
@@ -25,6 +25,8 @@
#include "COM_ExecutionSystem.h"
#include "COM_DilateErodeOperation.h"
#include "COM_AntiAliasOperation.h"
+#include "COM_GaussianAlphaXBlurOperation.h"
+#include "COM_GaussianAlphaYBlurOperation.h"
#include "BLI_math.h"
DilateErodeNode::DilateErodeNode(bNode *editorNode) : Node(editorNode)
@@ -70,6 +72,53 @@
graph->addOperation(operation);
}
}
+ else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_FEATHER) {
+ /* this uses a modified gaussian blur function otherwise its far too slow */
+ if (editorNode->custom2 > 0) {
+
+ CompositorQuality quality = context->getQuality();
+
+ /* initialize node data */
+ NodeBlurData *data = (NodeBlurData *)&this->alpha_blur;
+ memset(data, 0, sizeof(*data));
+ data->sizex = data->sizey = editorNode->custom2;
+ data->filtertype = R_FILTER_GAUSS;
+
+ GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation();
+ operationx->setData(data);
+ operationx->setQuality(quality);
+ this->getInputSocket(0)->relinkConnections(operationx->getInputSocket(0), 0, graph);
+ this->getInputSocket(1)->relinkConnections(operationx->getInputSocket(1), 1, graph);
+ graph->addOperation(operationx);
+ GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation();
+ operationy->setData(data);
+ operationy->setQuality(quality);
+ this->getOutputSocket(0)->relinkConnections(operationy->getOutputSocket());
+ graph->addOperation(operationy);
+ addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0));
+ addLink(graph, operationx->getInputSocket(1)->getConnection()->getFromSocket(), operationy->getInputSocket(1));
+ addPreviewOperation(graph, operationy->getOutputSocket());
+
+ /* TODO? */
+ /* see gaussian blue node for original usage */
+#if 0
+ if (!connectedSizeSocket) {
+ operationx->setSize(size);
+ operationy->setSize(size);
+ }
+#else
+ operationx->setSize(1.0f);
+ operationy->setSize(1.0f);
+#endif
+ }
+ else {
+ ErodeDistanceOperation *operation = new ErodeDistanceOperation();
+ operation->setDistance(-editorNode->custom2);
+ this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
+ this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
+ graph->addOperation(operation);
+ }
+ }
else {
if (editorNode->custom2 > 0) {
DilateStepOperation *operation = new DilateStepOperation();
Modified: trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.h
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.h 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.h 2012-06-16 13:46:20 UTC (rev 47988)
@@ -30,6 +30,7 @@
* @ingroup Node
*/
class DilateErodeNode : public Node {
+ NodeBlurData alpha_blur; /* only used for blurring alpha, since the dilate/erode node doesnt have this */
public:
DilateErodeNode(bNode *editorNode);
void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
Modified: trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp 2012-06-16 13:46:20 UTC (rev 47988)
@@ -27,11 +27,11 @@
#include "RE_pipeline.h"
}
-BlurBaseOperation::BlurBaseOperation() : NodeOperation()
+BlurBaseOperation::BlurBaseOperation(DataType data_type=COM_DT_COLOR) : NodeOperation()
{
- this->addInputSocket(COM_DT_COLOR);
+ this->addInputSocket(data_type);
this->addInputSocket(COM_DT_VALUE);
- this->addOutputSocket(COM_DT_COLOR);
+ this->addOutputSocket(data_type);
this->setComplex(true);
this->inputProgram = NULL;
this->data = NULL;
@@ -89,6 +89,24 @@
return gausstab;
}
+/* normalized distance from the current (inverted so 1.0 is close and 0.0 is far) */
+float *BlurBaseOperation::make_dist_fac_inverse(int rad)
+{
+ float *dist_fac_invert, val;
+ int i, n;
+
+ n = 2 * rad + 1;
+
+ dist_fac_invert = new float[n];
+
+ for (i = -rad; i <= rad; i++) {
+ val = 1.0f - fabsf(((float)i / (float)rad));
+ dist_fac_invert[i + rad] = val;
+ }
+
+ return dist_fac_invert;
+}
+
void BlurBaseOperation::deinitExecution()
{
this->inputProgram = NULL;
Modified: trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h 2012-06-16 13:46:20 UTC (rev 47988)
@@ -35,8 +35,9 @@
SocketReader *inputProgram;
SocketReader *inputSize;
NodeBlurData *data;
- BlurBaseOperation();
+ BlurBaseOperation(DataType data_type);
float *make_gausstab(int rad);
+ float *make_dist_fac_inverse(int rad);
float size;
bool deleteData;
bool sizeavailable;
Modified: trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp 2012-06-16 09:54:11 UTC (rev 47987)
+++ trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp 2012-06-16 13:46:20 UTC (rev 47988)
@@ -26,7 +26,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
-FastGaussianBlurOperation::FastGaussianBlurOperation() : BlurBaseOperation()
+FastGaussianBlurOperation::FastGaussianBlurOperation() : BlurBaseOperation(COM_DT_COLOR)
{
this->iirgaus = NULL;
}
Added: trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp (rev 0)
+++ trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp 2012-06-16 13:46:20 UTC (rev 47988)
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * 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.
+ *
+ * Contributor:
+ * Jeroen Bakker
+ * Monique Dewanchand
+ * Campbell Barton
+ */
+
+#include "COM_GaussianAlphaXBlurOperation.h"
+#include "BLI_math.h"
+
+extern "C" {
+ #include "RE_pipeline.h"
+}
+
+GaussianAlphaXBlurOperation::GaussianAlphaXBlurOperation() : BlurBaseOperation(COM_DT_VALUE)
+{
+ this->gausstab = NULL;
+ this->rad = 0;
+}
+
+void *GaussianAlphaXBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
+{
+ if (!this->sizeavailable) {
+ updateGauss(memoryBuffers);
+ }
+ void *buffer = getInputOperation(0)->initializeTileData(NULL, memoryBuffers);
+ return buffer;
+}
+
+void GaussianAlphaXBlurOperation::initExecution()
+{
+ BlurBaseOperation::initExecution();
+
+ if (this->sizeavailable) {
+ float rad = size * this->data->sizex;
+ if (rad < 1)
+ rad = 1;
+
+ this->rad = rad;
+ this->gausstab = BlurBaseOperation::make_gausstab(rad);
+ this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad);
+ }
+}
+
+void GaussianAlphaXBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
+{
+ if (this->gausstab == NULL) {
+ updateSize(memoryBuffers);
+ float rad = size * this->data->sizex;
+ if (rad < 1)
+ rad = 1;
+
+ this->rad = rad;
+ this->gausstab = BlurBaseOperation::make_gausstab(rad);
+ }
+
+ if (this->distbuf_inv == NULL) {
+ updateSize(memoryBuffers);
+ float rad = size * this->data->sizex;
+ if (rad < 1)
+ rad = 1;
+
+ this->rad = rad;
+ this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad);
+ }
+}
+
+void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
+{
+ MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
+ float *buffer = inputBuffer->getBuffer();
+ int bufferwidth = inputBuffer->getWidth();
+ int bufferstartx = inputBuffer->getRect()->xmin;
+ int bufferstarty = inputBuffer->getRect()->ymin;
+
+ int miny = y;
+ int maxy = y;
+ int minx = x - this->rad;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list