Revision: 59823
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59823
Author:   lukastoenne
Date:     2013-09-05 10:45:21 +0000 (Thu, 05 Sep 2013)
Log Message:
-----------
Fix #36113, Translate's wrapping has 1 pixel gap in X and Y after scale node.
The issue with wrapping is that it requires correct interpolation of the border 
pixels. Since interpolation is done at the far left end of the node tree in 
buffer/image/etc read operations, the wrapping
setting can not be used directly in those operations (otherwise in-line 
translate operations would cause conflicts). To make wrapping work correctly we 
need to add a buffer in front of the translate
operation, which can then be interpolated correctly based on wrapping. The 
WrapOperation becomes a variant of ReadBufferOperation, which uses its wrapping 
setting to determine the correct "extend" mode
for interpolation of the buffer.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp
    
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.h
    trunk/blender/source/blender/compositor/operations/COM_WrapOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_WrapOperation.h

Modified: trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp 
2013-09-05 10:45:19 UTC (rev 59822)
+++ trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp 
2013-09-05 10:45:21 UTC (rev 59823)
@@ -24,6 +24,7 @@
 
 #include "COM_TranslateOperation.h"
 #include "COM_WrapOperation.h"
+#include "COM_WriteBufferOperation.h"
 #include "COM_ExecutionSystem.h"
 
 TranslateNode::TranslateNode(bNode *editorNode) : Node(editorNode)
@@ -43,10 +44,15 @@
        NodeTranslateData *data = (NodeTranslateData *)bnode->storage;
 
        if (data->wrap_axis) {
+               WriteBufferOperation *writeOperation = new 
WriteBufferOperation();
                WrapOperation *wrapOperation = new WrapOperation();
+               wrapOperation->setMemoryProxy(writeOperation->getMemoryProxy());
                wrapOperation->setWrapping(data->wrap_axis);
-               
inputSocket->relinkConnections(wrapOperation->getInputSocket(0), 0, graph);
+               
+               
inputSocket->relinkConnections(writeOperation->getInputSocket(0), 0, graph);
                addLink(graph, wrapOperation->getOutputSocket(), 
operation->getInputSocket(0));
+               
+               graph->addOperation(writeOperation);
                graph->addOperation(wrapOperation);
        }
        else {

Modified: 
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.cpp  
    2013-09-05 10:45:19 UTC (rev 59822)
+++ 
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.cpp  
    2013-09-05 10:45:21 UTC (rev 59823)
@@ -66,6 +66,21 @@
        }
 }
 
+void ReadBufferOperation::executePixelExtend(float output[4], float x, float 
y, PixelSampler sampler,
+                                             MemoryBufferExtend extend_x, 
MemoryBufferExtend extend_y)
+{
+       if (m_single_value) {
+               /* write buffer has a single value stored at (0,0) */
+               m_buffer->read(output, 0, 0);
+       }
+       else if (sampler == COM_PS_NEAREST) {
+               m_buffer->read(output, x, y, extend_x, extend_y);
+       }
+       else {
+               m_buffer->readBilinear(output, x, y, extend_x, extend_y);
+       }
+}
+
 void ReadBufferOperation::executePixel(float output[4], float x, float y, 
float dx, float dy, PixelSampler sampler)
 {
        if (m_single_value) {

Modified: 
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.h
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.h    
    2013-09-05 10:45:19 UTC (rev 59822)
+++ 
trunk/blender/source/blender/compositor/operations/COM_ReadBufferOperation.h    
    2013-09-05 10:45:21 UTC (rev 59823)
@@ -41,6 +41,8 @@
        
        void *initializeTileData(rcti *rect);
        void executePixel(float output[4], float x, float y, PixelSampler 
sampler);
+       void executePixelExtend(float output[4], float x, float y, PixelSampler 
sampler,
+                               MemoryBufferExtend extend_x, MemoryBufferExtend 
extend_y);
        void executePixel(float output[4], float x, float y, float dx, float 
dy, PixelSampler sampler);
        const bool isReadBufferOperation() const { return true; }
        void setOffset(unsigned int offset) { this->m_offset = offset; }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_WrapOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_WrapOperation.cpp    
2013-09-05 10:45:19 UTC (rev 59822)
+++ trunk/blender/source/blender/compositor/operations/COM_WrapOperation.cpp    
2013-09-05 10:45:21 UTC (rev 59823)
@@ -23,23 +23,11 @@
 
 #include "COM_WrapOperation.h"
 
-WrapOperation::WrapOperation() : NodeOperation()
+WrapOperation::WrapOperation() : ReadBufferOperation()
 {
-       this->addInputSocket(COM_DT_COLOR);
-       this->addOutputSocket(COM_DT_COLOR);
-       this->setResolutionInputSocketIndex(0);
-       this->m_inputOperation = NULL;
+       this->m_wrappingType = CMP_NODE_WRAP_NONE;
 }
-void WrapOperation::initExecution()
-{
-       this->m_inputOperation = this->getInputSocketReader(0);
-}
 
-void WrapOperation::deinitExecution()
-{
-       this->m_inputOperation = NULL;
-}
-
 inline float WrapOperation::getWrappedOriginalXPos(float x)
 {
        if (this->getWidth() == 0) return 0;
@@ -59,6 +47,7 @@
        float nx, ny;
        nx = x;
        ny = y;
+       MemoryBufferExtend extend_x = COM_MB_CLIP, extend_y = COM_MB_CLIP;
        switch (m_wrappingType) {
                case CMP_NODE_WRAP_NONE:
                        //Intentionally empty, originalXPos and originalYPos 
have been set before
@@ -66,20 +55,23 @@
                case CMP_NODE_WRAP_X:
                        // wrap only on the x-axis
                        nx = this->getWrappedOriginalXPos(x);
+                       extend_x = COM_MB_REPEAT;
                        break;
                case CMP_NODE_WRAP_Y:
                        // wrap only on the y-axis
                        ny = this->getWrappedOriginalYPos(y);
+                       extend_y = COM_MB_REPEAT;
                        break;
                case CMP_NODE_WRAP_XY:
                        // wrap on both
                        nx = this->getWrappedOriginalXPos(x);
                        ny = this->getWrappedOriginalYPos(y);
+                       extend_x = COM_MB_REPEAT;
+                       extend_y = COM_MB_REPEAT;
                        break;
        }
 
-       this->m_inputOperation->read(output, nx, ny, sampler);
-
+       executePixelExtend(output, nx, ny, sampler, extend_x, extend_y);
 }
 
 bool WrapOperation::determineDependingAreaOfInterest(rcti *input, 
ReadBufferOperation *readOperation, rcti *output)
@@ -110,7 +102,7 @@
                }
        }
 
-       return NodeOperation::determineDependingAreaOfInterest(&newInput, 
readOperation, output);
+       return ReadBufferOperation::determineDependingAreaOfInterest(&newInput, 
readOperation, output);
 }
 
 void WrapOperation::setWrapping(int wrapping_type)

Modified: trunk/blender/source/blender/compositor/operations/COM_WrapOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_WrapOperation.h      
2013-09-05 10:45:19 UTC (rev 59822)
+++ trunk/blender/source/blender/compositor/operations/COM_WrapOperation.h      
2013-09-05 10:45:21 UTC (rev 59823)
@@ -23,20 +23,16 @@
 #ifndef _COM_WrapOperation_h_
 #define _COM_WrapOperation_h_
 
-#include "COM_NodeOperation.h"
+#include "COM_ReadBufferOperation.h"
 
-class WrapOperation : public NodeOperation {
+class WrapOperation : public ReadBufferOperation {
 private:
-       SocketReader *m_inputOperation;
        int m_wrappingType;
 public:
        WrapOperation();
        bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation 
*readOperation, rcti *output);
        void executePixel(float output[4], float x, float y, PixelSampler 
sampler);
 
-       void initExecution();
-       void deinitExecution();
-
        void setWrapping(int wrapping_type);
        float getWrappedOriginalXPos(float x);
        float getWrappedOriginalYPos(float y);

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

Reply via email to