Revision: 48873
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48873
Author:   jbakker
Date:     2012-07-12 19:19:03 +0000 (Thu, 12 Jul 2012)
Log Message:
-----------
Small optimizations in compositor.
Most of them are not noticeable.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
    
trunk/blender/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp
    trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.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/compositor/operations/COM_MixBaseOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MixBaseOperation.h
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl
    
trunk/blender/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
    
trunk/blender/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h

Modified: trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp 
2012-07-12 19:11:38 UTC (rev 48872)
+++ trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp 
2012-07-12 19:19:03 UTC (rev 48873)
@@ -121,7 +121,7 @@
        if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
            y >= this->m_rect.ymin && y < this->m_rect.ymax)
        {
-               const int offset = (this->m_chunkWidth * y + x) * 
COM_NUMBER_OF_CHANNELS;
+               const int offset = (this->m_chunkWidth * (y-this->m_rect.ymin) 
+ x-this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
                copy_v4_v4(&this->m_buffer[offset], color);
        }
 }
@@ -131,7 +131,7 @@
        if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
            y >= this->m_rect.ymin && y < this->m_rect.ymax)
        {
-               const int offset = (this->m_chunkWidth * y + x) * 
COM_NUMBER_OF_CHANNELS;
+               const int offset = (this->m_chunkWidth * (y-this->m_rect.ymin) 
+ x-this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
                add_v4_v4(&this->m_buffer[offset], color);
        }
 }

Modified: 
trunk/blender/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp
  2012-07-12 19:11:38 UTC (rev 48872)
+++ 
trunk/blender/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp
  2012-07-12 19:19:03 UTC (rev 48873)
@@ -35,7 +35,7 @@
 
 void SingleThreadedNodeOperation::executePixel(float *color, int x, int y, 
MemoryBuffer *inputBuffers[], void *data)
 {
-       this->m_cachedInstance->read(color, x, y);
+       this->m_cachedInstance->readNoCheck(color, x, y);
 }
 
 void SingleThreadedNodeOperation::deinitExecution()

Modified: trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp   
2012-07-12 19:11:38 UTC (rev 48872)
+++ trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp   
2012-07-12 19:19:03 UTC (rev 48873)
@@ -99,9 +99,7 @@
 #ifdef COM_DEFOCUS_SEARCH      
        InverseSearchRadiusOperation *search = new 
InverseSearchRadiusOperation();
        addLink(graph, radiusOperation->getOutputSocket(0), 
search->getInputSocket(0));
-       addLink(graph, depthOperation, search->getInputSocket(1));
        search->setMaxBlur(data->maxblur);
-       search->setThreshold(data->bthresh);
        graph->addOperation(search);
 #endif
        VariableSizeBokehBlurOperation *operation = new 
VariableSizeBokehBlurOperation();
@@ -116,7 +114,7 @@
        addLink(graph, bokeh->getOutputSocket(), operation->getInputSocket(1));
        addLink(graph, radiusOperation->getOutputSocket(), 
operation->getInputSocket(2));
 #ifdef COM_DEFOCUS_SEARCH
-       addLink(graph, search->getOutputSocket(), operation->getInputSocket(4));
+       addLink(graph, search->getOutputSocket(), operation->getInputSocket(3));
 #endif
        if (data->gamco) {
                GammaCorrectOperation *correct = new GammaCorrectOperation();

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
       2012-07-12 19:11:38 UTC (rev 48872)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
       2012-07-12 19:19:03 UTC (rev 48873)
@@ -194,3 +194,156 @@
                return 
BlurBaseOperation::determineDependingAreaOfInterest(&newInput, readOperation, 
output);
        }
 }
+
+// reference image
+GaussianBokehBlurReferenceOperation::GaussianBokehBlurReferenceOperation() : 
NodeOperation()
+{
+       this->addInputSocket(COM_DT_COLOR);
+       this->addInputSocket(COM_DT_VALUE);
+       this->addOutputSocket(COM_DT_COLOR);
+       this->setComplex(true);
+       this->m_gausstab = NULL;
+       this->m_inputImage = NULL;
+       this->m_inputSize = NULL;
+}
+
+void *GaussianBokehBlurReferenceOperation::initializeTileData(rcti *rect, 
MemoryBuffer **memoryBuffers)
+{
+       void *buffer = getInputOperation(0)->initializeTileData(NULL, 
memoryBuffers);
+       return buffer;
+}
+
+void GaussianBokehBlurReferenceOperation::initExecution()
+{
+       // setup gaustab
+       this->m_data->image_in_width = this->getWidth();
+       this->m_data->image_in_height = this->getHeight();
+       if (this->m_data->relative) {
+               switch (this->m_data->aspect) {
+                       case CMP_NODE_BLUR_ASPECT_NONE:
+                               this->m_data->sizex = 
(int)(this->m_data->percentx * 0.01f * this->m_data->image_in_width);
+                               this->m_data->sizey = 
(int)(this->m_data->percenty * 0.01f * this->m_data->image_in_height);
+                               break;
+                       case CMP_NODE_BLUR_ASPECT_Y:
+                               this->m_data->sizex = 
(int)(this->m_data->percentx * 0.01f * this->m_data->image_in_width);
+                               this->m_data->sizey = 
(int)(this->m_data->percenty * 0.01f * this->m_data->image_in_width);
+                               break;
+                       case CMP_NODE_BLUR_ASPECT_X:
+                               this->m_data->sizex = 
(int)(this->m_data->percentx * 0.01f * this->m_data->image_in_height);
+                               this->m_data->sizey = 
(int)(this->m_data->percenty * 0.01f * this->m_data->image_in_height);
+                               break;
+               }
+       }
+       
+       updateGauss();
+       this->m_inputImage = this->getInputSocketReader(0);
+       this->m_inputSize = this->getInputSocketReader(1);
+}
+
+void GaussianBokehBlurReferenceOperation::updateGauss()
+{
+       int n;
+       float *dgauss;
+       float *ddgauss;
+       int j, i;
+
+       n = (2 * radx + 1) * (2 * rady + 1);
+
+       /* create a full filter image */
+       ddgauss = new float[n];
+       dgauss = ddgauss;
+       for (j = -rady; j <= rady; j++) {
+               for (i = -radx; i <= radx; i++, dgauss++) {
+                       float fj = (float)j / radyf;
+                       float fi = (float)i / radxf;
+                       float dist = sqrt(fj * fj + fi * fi);
+                       *dgauss = RE_filter_value(this->m_data->filtertype, 
dist);
+               }
+       }
+       this->m_gausstab = ddgauss;
+}
+
+void GaussianBokehBlurReferenceOperation::executePixel(float *color, int x, 
int y, MemoryBuffer *inputBuffers[], void *data)
+{
+       float tempColor[4];
+       float tempSize[4];
+       tempColor[0] = 0;
+       tempColor[1] = 0;
+       tempColor[2] = 0;
+       tempColor[3] = 0;
+       float multiplier_accum = 0;
+       MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
+       float *buffer = inputBuffer->getBuffer();
+       int bufferwidth = inputBuffer->getWidth();
+       int bufferstartx = inputBuffer->getRect()->xmin;
+       int bufferstarty = inputBuffer->getRect()->ymin;
+       this->m_inputSize->read(tempSize, x, y, inputBuffers, data);
+       float size = tempSize[0];
+       CLAMP(size, 0.0f, 1.0f);
+       float sizeX = ceil(this->m_data->sizex * size);
+       float sizeY = ceil(this->m_data->sizey * size);
+
+       if (sizeX <= 0.5f && sizeY <= 0.5f) {
+               this->m_inputImage->read(color, x, y, inputBuffers, data);
+               return;
+       }
+       
+       int miny = y - sizeY;
+       int maxy = y + sizeY;
+       int minx = x - sizeX;
+       int maxx = x + sizeX;
+       miny = max(miny, inputBuffer->getRect()->ymin);
+       minx = max(minx, inputBuffer->getRect()->xmin);
+       maxy = min(maxy, inputBuffer->getRect()->ymax);
+       maxx = min(maxx, inputBuffer->getRect()->xmax);
+
+       int step = QualityStepHelper::getStep();
+       int offsetadd = QualityStepHelper::getOffsetAdd();
+       for (int ny = miny; ny < maxy; ny += step) {
+               int u = ny - y;
+               float uf = ((u/sizeY)*radyf)+radyf;
+               int indexu = uf * (radx*2+1);
+               int bufferindex = ((minx - bufferstartx) * 4) + ((ny - 
bufferstarty) * 4 * bufferwidth);
+               for (int nx = minx; nx < maxx; nx += step) {
+                       int v = nx - x;
+                       float vf = ((v/sizeX)*radxf)+radxf;
+                       int index = indexu + vf;
+                       const float multiplier = this->m_gausstab[index];
+                       madd_v4_v4fl(tempColor, &buffer[bufferindex], 
multiplier);
+                       multiplier_accum += multiplier;
+                       index += step;
+                       bufferindex += offsetadd;
+               }
+       }
+
+       mul_v4_v4fl(color, tempColor, 1.0f / multiplier_accum);
+}
+
+void GaussianBokehBlurReferenceOperation::deinitExecution()
+{
+       delete [] this->m_gausstab;
+       this->m_gausstab = NULL;
+       this->m_inputImage = NULL;
+       this->m_inputSize = NULL;
+       
+}
+
+bool 
GaussianBokehBlurReferenceOperation::determineDependingAreaOfInterest(rcti 
*input, ReadBufferOperation *readOperation, rcti *output)
+{
+       rcti newInput;
+       NodeOperation *operation = this->getInputOperation(1);
+       
+       if (operation->determineDependingAreaOfInterest(input, readOperation, 
output)) {
+               return true;
+       }
+       else {
+               int addx = this->m_data->sizex+2;
+               int addy = this->m_data->sizey+2;
+               newInput.xmax = input->xmax + addx;
+               newInput.xmin = input->xmin - addx;
+               newInput.ymax = input->ymax + addy;
+               newInput.ymin = input->ymin - addy;
+               return 
NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, 
output);
+       }
+}
+

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
   2012-07-12 19:11:38 UTC (rev 48872)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
   2012-07-12 19:19:03 UTC (rev 48873)
@@ -118,17 +118,19 @@
 bool GaussianXBlurOperation::determineDependingAreaOfInterest(rcti *input, 
ReadBufferOperation *readOperation, rcti *output)
 {
        rcti newInput;
-       rcti sizeInput;
-       sizeInput.xmin = 0;
-       sizeInput.ymin = 0;
-       sizeInput.xmax = 5;
-       sizeInput.ymax = 5;
        
-       NodeOperation *operation = this->getInputOperation(1);
-       if (operation->determineDependingAreaOfInterest(&sizeInput, 
readOperation, output)) {
-               return true;
+       if (!this->m_sizeavailable) {
+               rcti sizeInput;
+               sizeInput.xmin = 0;
+               sizeInput.ymin = 0;
+               sizeInput.xmax = 5;
+               sizeInput.ymax = 5;
+               NodeOperation *operation = this->getInputOperation(1);
+               if (operation->determineDependingAreaOfInterest(&sizeInput, 
readOperation, output)) {
+                       return true;
+               }
        }
-       else {
+       {
                if (this->m_sizeavailable && this->m_gausstab != NULL) {
                        newInput.xmax = input->xmax + this->m_rad;
                        newInput.xmin = input->xmin - this->m_rad;

Modified: 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
   2012-07-12 19:11:38 UTC (rev 48872)
+++ 
trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
   2012-07-12 19:19:03 UTC (rev 48873)
@@ -116,17 +116,19 @@
 bool GaussianYBlurOperation::determineDependingAreaOfInterest(rcti *input, 
ReadBufferOperation *readOperation, rcti *output)
 {

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to