Revision: 47315
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47315
Author:   mdewanchand
Date:     2012-06-01 11:50:32 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
Optimize Gaussian blurs

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_BlurNode.cpp
    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_GaussianBokehBlurOperation.cpp
    
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
    
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
    
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.h
    
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
    
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.h

Modified: trunk/blender/source/blender/compositor/nodes/COM_BlurNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_BlurNode.cpp      
2012-06-01 11:46:25 UTC (rev 47314)
+++ trunk/blender/source/blender/compositor/nodes/COM_BlurNode.cpp      
2012-06-01 11:50:32 UTC (rev 47315)
@@ -37,10 +37,11 @@
 {
        bNode *editorNode = this->getbNode();
        NodeBlurData * data = (NodeBlurData*)editorNode->storage;
-#if 0
+       InputSocket * inputSizeSocket = this->getInputSocket(1);
+       bool connectedSizeSocket = inputSizeSocket->isConnected();
+
        const bNodeSocket *sock = this->getInputSocket(1)->getbNodeSocket();
        const float size = ((const 
bNodeSocketValueFloat*)sock->default_value)->value;
-#endif
        
        CompositorQuality quality = context->getQuality();
        
@@ -71,6 +72,11 @@
                addLink(graph, operationx->getOutputSocket(), 
operationy->getInputSocket(0));
                addLink(graph, 
operationx->getInputSocket(1)->getConnection()->getFromSocket(), 
operationy->getInputSocket(1));
                addPreviewOperation(graph, operationy->getOutputSocket(), 5);
+
+               if (!connectedSizeSocket) {
+                       operationx->setSize(size);
+                       operationy->setSize(size);
+               }
        }
        else {
                GaussianBokehBlurOperation *operation = new 
GaussianBokehBlurOperation();
@@ -81,5 +87,9 @@
                graph->addOperation(operation);
                
this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
                addPreviewOperation(graph, operation->getOutputSocket(), 5);
+
+               if (!connectedSizeSocket) {
+                       operation->setSize(size);
+               }
        }
 }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp    
    2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp    
    2012-06-01 11:50:32 UTC (rev 47315)
@@ -37,6 +37,7 @@
        this->data = NULL;
        this->size = 1.0f;
        this->deleteData = false;
+       this->sizeavailable=false;
 }
 void BlurBaseOperation::initExecution()
 {

Modified: 
trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h  
2012-06-01 11:46:25 UTC (rev 47314)
+++ trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.h  
2012-06-01 11:50:32 UTC (rev 47315)
@@ -39,6 +39,7 @@
        float *make_gausstab(int rad);
        float size;
        bool deleteData;
+       bool sizeavailable;
        void updateSize(MemoryBuffer **memoryBuffers);
 public:
        /**
@@ -54,5 +55,7 @@
        void setData(NodeBlurData *data) {this->data = data;}
        
        void deleteDataWhenFinished() {this->deleteData = true;}
+
+       void setSize(float size) {this->size = size; sizeavailable = true;}
 };
 #endif

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
       2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
       2012-06-01 11:50:32 UTC (rev 47315)
@@ -34,11 +34,20 @@
 
 void *GaussianBokehBlurOperation::initializeTileData(rcti *rect, MemoryBuffer 
**memoryBuffers)
 {
-       updateGauss(memoryBuffers);
+       if (!sizeavailable) {
+               updateGauss(memoryBuffers);
+       }
        void *buffer = getInputOperation(0)->initializeTileData(NULL, 
memoryBuffers);
        return buffer;
 }
 
+void GaussianBokehBlurOperation::initExecution()
+{
+       if (this->sizeavailable) {
+               updateGauss(NULL);
+       }
+}
+
 void GaussianBokehBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
 {
        if (this->gausstab == NULL) {
@@ -51,8 +60,9 @@
                int j, i;
                const float width = this->getWidth();
                const float height = this->getHeight();
-               updateSize(memoryBuffers);
-               
+               if (!sizeavailable) {
+                       updateSize(memoryBuffers);
+               }
                radxf = size*(float)this->data->sizex;
                if (radxf>width/2.0f)
                        radxf = width/2.0f;
@@ -163,20 +173,21 @@
                return true;
        }
        else {
-               if (this->gausstab) {
+               if (this->sizeavailable && this->gausstab != NULL) {
+                       newInput.xmin = 0;
+                       newInput.ymin = 0;
+                       newInput.xmax = this->getWidth();
+                       newInput.ymax = this->getHeight();
+               }
+               else {
                        int addx = radx;
                        int addy = rady;
                        newInput.xmax = input->xmax + addx;
                        newInput.xmin = input->xmin - addx;
                        newInput.ymax = input->ymax + addy;
                        newInput.ymin = input->ymin - addy;
+
                }
-               else {
-                       newInput.xmin = 0;
-                       newInput.ymin = 0;
-                       newInput.xmax = this->getWidth();
-                       newInput.ymax = this->getHeight();
-               }
                return 
BlurBaseOperation::determineDependingAreaOfInterest(&newInput, readOperation, 
output);
        }
 }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
 2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h
 2012-06-01 11:50:32 UTC (rev 47315)
@@ -34,7 +34,7 @@
 
 public:
        GaussianBokehBlurOperation();
-
+       void initExecution();
        void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
        /**
          * the inner loop of this program

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
   2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
   2012-06-01 11:50:32 UTC (rev 47315)
@@ -36,11 +36,25 @@
 
 void *GaussianXBlurOperation::initializeTileData(rcti *rect, MemoryBuffer 
**memoryBuffers)
 {
-       updateGauss(memoryBuffers);
+       if (!this->sizeavailable) {
+               updateGauss(memoryBuffers);
+       }
        void *buffer = getInputOperation(0)->initializeTileData(NULL, 
memoryBuffers);
        return buffer;
 }
 
+void GaussianXBlurOperation::initExecution()
+{
+       if (this->sizeavailable) {
+               float rad = size*this->data->sizex;
+               if (rad<1)
+                       rad = 1;
+
+               this->rad = rad;
+               this->gausstab = BlurBaseOperation::make_gausstab(rad);
+       }
+}
+
 void GaussianXBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
 {
        if (this->gausstab == NULL) {
@@ -118,18 +132,18 @@
                return true;
        }
        else {
-               if (this->gausstab == NULL) {
+               if (this->sizeavailable && this->gausstab != NULL) {
+                       newInput.xmax = input->xmax + rad;
+                       newInput.xmin = input->xmin - rad;
+                       newInput.ymax = input->ymax;
+                       newInput.ymin = input->ymin;
+               }
+               else {
                        newInput.xmax = this->getWidth();
                        newInput.xmin = 0;
                        newInput.ymax = this->getHeight();
                        newInput.ymin = 0;
                }
-               else {
-                       newInput.xmax = input->xmax + rad;
-                       newInput.xmin = input->xmin - rad;
-                       newInput.ymax = input->ymax;
-                       newInput.ymin = input->ymin;
-               }
                return 
NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, 
output);
        }
 }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.h
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.h 
    2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.h 
    2012-06-01 11:50:32 UTC (rev 47315)
@@ -34,13 +34,18 @@
        GaussianXBlurOperation();
 
        /**
-         * the inner loop of this program
+         *@brief the inner loop of this program
          */
        void executePixel(float *color, int x, int y, MemoryBuffer 
*inputBuffers[], void *data);
        
        /**
-         * Deinitialize the execution
+         *@brief initialize the execution
          */
+       void initExecution();
+
+       /**
+         *@brief Deinitialize the execution
+         */
        void deinitExecution();
        
        void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
   2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
   2012-06-01 11:50:32 UTC (rev 47315)
@@ -35,11 +35,25 @@
 
 void *GaussianYBlurOperation::initializeTileData(rcti *rect, MemoryBuffer 
**memoryBuffers)
 {
-       updateGauss(memoryBuffers);
+       if (!this->sizeavailable) {
+               updateGauss(memoryBuffers);
+       }
        void *buffer = getInputOperation(0)->initializeTileData(NULL, 
memoryBuffers);
        return buffer;
 }
 
+void GaussianYBlurOperation::initExecution()
+{
+       if (this->sizeavailable) {
+               float rad = size*this->data->sizex;
+               if (rad<1)
+                       rad = 1;
+
+               this->rad = rad;
+               this->gausstab = BlurBaseOperation::make_gausstab(rad);
+       }
+}
+
 void GaussianYBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
 {
        if (this->gausstab == NULL) {
@@ -115,18 +129,18 @@
                return true;
        }
        else {
-               if (this->gausstab == NULL) {
+               if (this->sizeavailable && this->gausstab != NULL) {
+                       newInput.xmax = input->xmax;
+                       newInput.xmin = input->xmin;
+                       newInput.ymax = input->ymax + rad;
+                       newInput.ymin = input->ymin - rad;
+               }
+               else {
                        newInput.xmax = this->getWidth();
                        newInput.xmin = 0;
                        newInput.ymax = this->getHeight();
                        newInput.ymin = 0;
                }
-               else {
-                       newInput.xmax = input->xmax;
-                       newInput.xmin = input->xmin;
-                       newInput.ymax = input->ymax + rad;
-                       newInput.ymin = input->ymin - rad;
-               }
                return 
NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, 
output);
        }
 }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.h
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.h 
    2012-06-01 11:46:25 UTC (rev 47314)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.h 
    2012-06-01 11:50:32 UTC (rev 47315)
@@ -39,6 +39,11 @@
        void executePixel(float *color, int x, int y, MemoryBuffer 
*inputBuffers[], void *data);
        
        /**
+         *@brief initialize the execution
+         */
+       void initExecution();
+
+       /**
          * Deinitialize the execution
          */
        void deinitExecution();

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to