Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2012-11-10 23:11:25 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2012-11-10 23:11:25 +0400
commitf81e30a41f961fe681d06fb98fec6e722297292e (patch)
treeb5dac6a3f8488035ba25428fd1fcd6ed76632904 /source/blender/compositor
parent45cd54bcd11d9b1fb62d986328917ca5cebf9b17 (diff)
Solved issue with distorted compositor results in some cases
Originally issue was discovered when using stabilization and movie distortion nodes, but in fact issue was caused by render layer node always doing nearest interpolation. Now made it so this node will respect sampler passed to it's executePixel function and do an interpolation. Added two new functions to do bilinear/bicubic interpolation in float buffer with variable number of components per element, so it could interpolate 1, 3 and 4 component vectors. This functions currently mostly duplicates the same functions from imageprocess.c and it should actually be de-duplicated. Think it's ok to leave a bit of time with such duplication, since functions should be generalized one more time to support byte buffers, which could backfire on readability. Also removed mark as complex from stabilization node, which isn't needed sine int fact this node is not complex.
Diffstat (limited to 'source/blender/compositor')
-rw-r--r--source/blender/compositor/nodes/COM_ScaleNode.cpp22
-rw-r--r--source/blender/compositor/nodes/COM_Stabilize2dNode.cpp2
-rw-r--r--source/blender/compositor/operations/COM_MovieDistortionOperation.cpp1
-rw-r--r--source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp55
-rw-r--r--source/blender/compositor/operations/COM_RenderLayersBaseProg.h1
-rw-r--r--source/blender/compositor/operations/COM_ScaleOperation.cpp51
-rw-r--r--source/blender/compositor/operations/COM_ScaleOperation.h18
7 files changed, 100 insertions, 50 deletions
diff --git a/source/blender/compositor/nodes/COM_ScaleNode.cpp b/source/blender/compositor/nodes/COM_ScaleNode.cpp
index c51782b77af..d535e71a33c 100644
--- a/source/blender/compositor/nodes/COM_ScaleNode.cpp
+++ b/source/blender/compositor/nodes/COM_ScaleNode.cpp
@@ -26,6 +26,7 @@
#include "COM_ExecutionSystem.h"
#include "BKE_node.h"
#include "COM_SetValueOperation.h"
+#include "COM_SetSamplerOperation.h"
ScaleNode::ScaleNode(bNode *editorNode) : Node(editorNode)
{
@@ -38,7 +39,9 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
InputSocket *inputXSocket = this->getInputSocket(1);
InputSocket *inputYSocket = this->getInputSocket(2);
OutputSocket *outputSocket = this->getOutputSocket(0);
+ BaseScaleOperation *scaleoperation;
bNode *bnode = this->getbNode();
+
switch (bnode->custom1) {
case CMP_SCALE_RELATIVE: {
ScaleOperation *operation = new ScaleOperation();
@@ -46,8 +49,8 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
inputXSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
inputYSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
- outputSocket->relinkConnections(operation->getOutputSocket(0));
- graph->addOperation(operation);
+
+ scaleoperation = operation;
}
break;
case CMP_SCALE_SCENEPERCENT: {
@@ -57,9 +60,9 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
addLink(graph, scaleFactorOperation->getOutputSocket(), operation->getInputSocket(1));
addLink(graph, scaleFactorOperation->getOutputSocket(), operation->getInputSocket(2));
- outputSocket->relinkConnections(operation->getOutputSocket(0));
graph->addOperation(scaleFactorOperation);
- graph->addOperation(operation);
+
+ scaleoperation = operation;
}
break;
@@ -75,9 +78,9 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
operation->setNewWidth(rd->xsch * rd->size / 100.0f);
operation->setNewHeight(rd->ysch * rd->size / 100.0f);
inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
- outputSocket->relinkConnections(operation->getOutputSocket(0));
operation->getInputSocket(0)->getConnection()->setIgnoreResizeCheck(true);
- graph->addOperation(operation);
+
+ scaleoperation = operation;
}
break;
@@ -87,9 +90,12 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c
inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
inputXSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
inputYSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
- outputSocket->relinkConnections(operation->getOutputSocket(0));
- graph->addOperation(operation);
+
+ scaleoperation = operation;
}
break;
}
+
+ outputSocket->relinkConnections(scaleoperation->getOutputSocket(0));
+ graph->addOperation(scaleoperation);
}
diff --git a/source/blender/compositor/nodes/COM_Stabilize2dNode.cpp b/source/blender/compositor/nodes/COM_Stabilize2dNode.cpp
index b28ee3eade1..a579503a829 100644
--- a/source/blender/compositor/nodes/COM_Stabilize2dNode.cpp
+++ b/source/blender/compositor/nodes/COM_Stabilize2dNode.cpp
@@ -72,6 +72,8 @@ void Stabilize2dNode::convertToOperations(ExecutionSystem *graph, CompositorCont
addLink(graph, scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(1));
addLink(graph, scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(2));
+ scaleOperation->setSampler((PixelSampler)this->getbNode()->custom1);
+
addLink(graph, scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
addLink(graph, angleAttribute->getOutputSocket(), rotateOperation->getInputSocket(1));
rotateOperation->setDoDegree2RadConversion(false);
diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp b/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
index 7106b015fe6..29d8bbea2db 100644
--- a/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
+++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
@@ -49,7 +49,6 @@ MovieDistortionOperation::MovieDistortionOperation(bool distortion) : NodeOperat
this->m_movieClip = NULL;
this->m_cache = NULL;
this->m_distortion = distortion;
- setComplex(true);
}
void MovieDistortionOperation::initExecution()
diff --git a/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp b/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp
index a4015c6283f..f4160a5fbcb 100644
--- a/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp
+++ b/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp
@@ -69,6 +69,46 @@ void RenderLayersBaseProg::initExecution()
}
}
+void RenderLayersBaseProg::doInterpolation(float output[4], float x, float y, PixelSampler sampler)
+{
+ unsigned int offset;
+ int ix, iy;
+ int width = this->getWidth(), height = this->getHeight();
+
+ switch (sampler) {
+ case COM_PS_NEAREST:
+ ix = x;
+ iy = y;
+ offset = (iy * width + ix) * this->m_elementsize;
+
+ if (this->m_elementsize == 1)
+ output[0] = this->m_inputBuffer[offset];
+ else if (this->m_elementsize == 3)
+ copy_v3_v3(output, &this->m_inputBuffer[offset]);
+ else
+ copy_v4_v4(output, &this->m_inputBuffer[offset]);
+
+ break;
+
+ case COM_PS_BILINEAR:
+ BLI_bilinear_interpolation(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
+ break;
+
+ case COM_PS_BICUBIC:
+ BLI_bicubic_interpolation(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
+ break;
+ }
+
+ if (this->m_elementsize == 1) {
+ output[1] = 0.0f;
+ output[2] = 0.0f;
+ output[3] = 0.0f;
+ }
+ else if (this->m_elementsize == 3) {
+ output[3] = 1.0f;
+ }
+}
+
void RenderLayersBaseProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
int ix = x;
@@ -78,20 +118,7 @@ void RenderLayersBaseProg::executePixel(float output[4], float x, float y, Pixel
zero_v4(output);
}
else {
- unsigned int offset = (iy * this->getWidth() + ix) * this->m_elementsize;
- if (this->m_elementsize == 1) {
- output[0] = this->m_inputBuffer[offset];
- output[1] = 0.0f;
- output[2] = 0.0f;
- output[3] = 0.0f;
- }
- else if (this->m_elementsize == 3) {
- copy_v3_v3(output, &this->m_inputBuffer[offset]);
- output[3] = 1.0f;
- }
- else {
- copy_v4_v4(output, &this->m_inputBuffer[offset]);
- }
+ doInterpolation(output, x, y, sampler);
}
}
diff --git a/source/blender/compositor/operations/COM_RenderLayersBaseProg.h b/source/blender/compositor/operations/COM_RenderLayersBaseProg.h
index ea57d4bc421..3916862a0b3 100644
--- a/source/blender/compositor/operations/COM_RenderLayersBaseProg.h
+++ b/source/blender/compositor/operations/COM_RenderLayersBaseProg.h
@@ -80,6 +80,7 @@ protected:
*/
inline float *getInputBuffer() { return this->m_inputBuffer; }
+ void doInterpolation(float output[4], float x, float y, PixelSampler sampler);
public:
/**
* setter for the scene field. Will be called from
diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cpp b/source/blender/compositor/operations/COM_ScaleOperation.cpp
index 276b2f54b6e..9e8f5af0ef0 100644
--- a/source/blender/compositor/operations/COM_ScaleOperation.cpp
+++ b/source/blender/compositor/operations/COM_ScaleOperation.cpp
@@ -29,7 +29,16 @@
* note: use bilinear because bicubic makes fuzzy even when not scaling at all (1:1)
*/
-ScaleOperation::ScaleOperation() : NodeOperation()
+BaseScaleOperation::BaseScaleOperation()
+{
+#ifdef USE_FORCE_BILINEAR
+ m_sampler = (int) COM_PS_BILINEAR;
+#else
+ m_sampler = -1;
+#endif
+}
+
+ScaleOperation::ScaleOperation() : BaseScaleOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addInputSocket(COM_DT_VALUE);
@@ -59,22 +68,20 @@ void ScaleOperation::deinitExecution()
void ScaleOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
-#ifdef USE_FORCE_BILINEAR
- sampler = COM_PS_BILINEAR;
-#endif
+ PixelSampler effective_sampler = getEffectiveSampler(sampler);
float scaleX[4];
float scaleY[4];
- this->m_inputXOperation->read(scaleX, x, y, sampler);
- this->m_inputYOperation->read(scaleY, x, y, sampler);
+ this->m_inputXOperation->read(scaleX, x, y, effective_sampler);
+ this->m_inputYOperation->read(scaleY, x, y, effective_sampler);
const float scx = scaleX[0];
const float scy = scaleY[0];
float nx = this->m_centerX + (x - this->m_centerX) / scx;
float ny = this->m_centerY + (y - this->m_centerY) / scy;
- this->m_inputOperation->read(output, nx, ny, sampler);
+ this->m_inputOperation->read(output, nx, ny, effective_sampler);
}
bool ScaleOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
@@ -94,12 +101,12 @@ bool ScaleOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOpe
newInput.ymax = this->m_centerY + (input->ymax - this->m_centerY) / scy;
newInput.ymin = this->m_centerY + (input->ymin - this->m_centerY) / scy;
- return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
+ return BaseScaleOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
// SCALE ABSOLUTE
-ScaleAbsoluteOperation::ScaleAbsoluteOperation() : NodeOperation()
+ScaleAbsoluteOperation::ScaleAbsoluteOperation() : BaseScaleOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addInputSocket(COM_DT_VALUE);
@@ -129,15 +136,13 @@ void ScaleAbsoluteOperation::deinitExecution()
void ScaleAbsoluteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
-#ifdef USE_FORCE_BILINEAR
- sampler = COM_PS_BILINEAR;
-#endif
+ PixelSampler effective_sampler = getEffectiveSampler(sampler);
float scaleX[4];
float scaleY[4];
- this->m_inputXOperation->read(scaleX, x, y, sampler);
- this->m_inputYOperation->read(scaleY, x, y, sampler);
+ this->m_inputXOperation->read(scaleX, x, y, effective_sampler);
+ this->m_inputYOperation->read(scaleY, x, y, effective_sampler);
const float scx = scaleX[0]; // target absolute scale
const float scy = scaleY[0]; // target absolute scale
@@ -151,7 +156,7 @@ void ScaleAbsoluteOperation::executePixel(float output[4], float x, float y, Pix
float nx = this->m_centerX + (x - this->m_centerX) / relativeXScale;
float ny = this->m_centerY + (y - this->m_centerY) / relativeYScale;
- this->m_inputOperation->read(output, nx, ny, sampler);
+ this->m_inputOperation->read(output, nx, ny, effective_sampler);
}
bool ScaleAbsoluteOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
@@ -176,12 +181,12 @@ bool ScaleAbsoluteOperation::determineDependingAreaOfInterest(rcti *input, ReadB
newInput.ymax = this->m_centerY + (input->ymax - this->m_centerY) / relateveYScale;
newInput.ymin = this->m_centerY + (input->ymin - this->m_centerY) / relateveYScale;
- return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
+ return BaseScaleOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
// Absolute fixed siez
-ScaleFixedSizeOperation::ScaleFixedSizeOperation() : NodeOperation()
+ScaleFixedSizeOperation::ScaleFixedSizeOperation() : BaseScaleOperation()
{
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
this->addOutputSocket(COM_DT_COLOR);
@@ -250,17 +255,15 @@ void ScaleFixedSizeOperation::deinitExecution()
void ScaleFixedSizeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
-#ifdef USE_FORCE_BILINEAR
- sampler = COM_PS_BILINEAR;
-#endif
+ PixelSampler effective_sampler = getEffectiveSampler(sampler);
if (this->m_is_offset) {
float nx = ((x - this->m_offsetX) * this->m_relX);
float ny = ((y - this->m_offsetY) * this->m_relY);
- this->m_inputOperation->read(output, nx, ny, sampler);
+ this->m_inputOperation->read(output, nx, ny, effective_sampler);
}
else {
- this->m_inputOperation->read(output, x * this->m_relX, y * this->m_relY, sampler);
+ this->m_inputOperation->read(output, x * this->m_relX, y * this->m_relY, effective_sampler);
}
}
@@ -273,7 +276,7 @@ bool ScaleFixedSizeOperation::determineDependingAreaOfInterest(rcti *input, Read
newInput.ymax = input->ymax * this->m_relY;
newInput.ymin = input->ymin * this->m_relY;
- return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
+ return BaseScaleOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
void ScaleFixedSizeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
@@ -281,7 +284,7 @@ void ScaleFixedSizeOperation::determineResolution(unsigned int resolution[2], un
unsigned int nr[2];
nr[0] = this->m_newWidth;
nr[1] = this->m_newHeight;
- NodeOperation::determineResolution(resolution, nr);
+ BaseScaleOperation::determineResolution(resolution, nr);
resolution[0] = this->m_newWidth;
resolution[1] = this->m_newHeight;
}
diff --git a/source/blender/compositor/operations/COM_ScaleOperation.h b/source/blender/compositor/operations/COM_ScaleOperation.h
index 4239ff063fb..f42cdbd78ed 100644
--- a/source/blender/compositor/operations/COM_ScaleOperation.h
+++ b/source/blender/compositor/operations/COM_ScaleOperation.h
@@ -25,7 +25,19 @@
#include "COM_NodeOperation.h"
-class ScaleOperation : public NodeOperation {
+class BaseScaleOperation : public NodeOperation {
+public:
+ void setSampler(PixelSampler sampler) { this->m_sampler = (int) sampler; }
+
+protected:
+ BaseScaleOperation();
+
+ PixelSampler getEffectiveSampler(PixelSampler sampler) { return (m_sampler == -1) ? sampler : (PixelSampler) m_sampler; }
+
+ int m_sampler;
+};
+
+class ScaleOperation : public BaseScaleOperation {
private:
SocketReader *m_inputOperation;
SocketReader *m_inputXOperation;
@@ -41,7 +53,7 @@ public:
void deinitExecution();
};
-class ScaleAbsoluteOperation : public NodeOperation {
+class ScaleAbsoluteOperation : public BaseScaleOperation {
SocketReader *m_inputOperation;
SocketReader *m_inputXOperation;
SocketReader *m_inputYOperation;
@@ -57,7 +69,7 @@ public:
void deinitExecution();
};
-class ScaleFixedSizeOperation : public NodeOperation {
+class ScaleFixedSizeOperation : public BaseScaleOperation {
SocketReader *m_inputOperation;
int m_newWidth;
int m_newHeight;