[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45579] branches/tile/source/blender/ compositor: TileBranch
Jeroen Bakker
j.bakker at atmind.nl
Thu Apr 12 22:21:02 CEST 2012
Revision: 45579
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45579
Author: jbakker
Date: 2012-04-12 20:21:02 +0000 (Thu, 12 Apr 2012)
Log Message:
-----------
TileBranch
* Added absolute scale and scene scale options
Modified Paths:
--------------
branches/tile/source/blender/compositor/nodes/COM_ScaleNode.cpp
branches/tile/source/blender/compositor/operations/COM_ScaleOperation.cpp
branches/tile/source/blender/compositor/operations/COM_ScaleOperation.h
Modified: branches/tile/source/blender/compositor/nodes/COM_ScaleNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_ScaleNode.cpp 2012-04-12 17:34:29 UTC (rev 45578)
+++ branches/tile/source/blender/compositor/nodes/COM_ScaleNode.cpp 2012-04-12 20:21:02 UTC (rev 45579)
@@ -24,6 +24,8 @@
#include "COM_ScaleOperation.h"
#include "COM_ExecutionSystem.h"
+#include "BKE_node.h"
+#include "COM_SetValueOperation.h"
ScaleNode::ScaleNode(bNode *editorNode) : Node(editorNode) {
}
@@ -33,11 +35,57 @@
InputSocket *inputXSocket = this->getInputSocket(1);
InputSocket *inputYSocket = this->getInputSocket(2);
OutputSocket *outputSocket = this->getOutputSocket(0);
- ScaleOperation *operation = new ScaleOperation();
-
- inputSocket->relinkConnections(operation->getInputSocket(0), true, 0, graph);
- inputXSocket->relinkConnections(operation->getInputSocket(1), true, 1, graph);
- inputYSocket->relinkConnections(operation->getInputSocket(2), true, 2, graph);
- outputSocket->relinkConnections(operation->getOutputSocket(0));
- graph->addOperation(operation);
+ bNode* bnode = this->getbNode();
+ switch (bnode->custom1) {
+ case CMP_SCALE_RELATIVE: {
+ ScaleOperation *operation = new ScaleOperation();
+
+ inputSocket->relinkConnections(operation->getInputSocket(0), true, 0, graph);
+ inputXSocket->relinkConnections(operation->getInputSocket(1), true, 1, graph);
+ inputYSocket->relinkConnections(operation->getInputSocket(2), true, 2, graph);
+ outputSocket->relinkConnections(operation->getOutputSocket(0));
+ graph->addOperation(operation);
+ }
+ break;
+ case CMP_SCALE_SCENEPERCENT: {
+ SetValueOperation * scaleFactorOperation = new SetValueOperation();
+ scaleFactorOperation->setValue(context->getScene()->r.size/100.0f);
+ ScaleOperation * operation = new ScaleOperation();
+ inputSocket->relinkConnections(operation->getInputSocket(0), true, 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);
+ }
+ break;
+
+ case CMP_SCALE_RENDERPERCENT: {
+ SetValueOperation * scaleWidthOperation = new SetValueOperation();
+ SetValueOperation * scaleHeightOperation = new SetValueOperation();
+ const RenderData* data = &context->getScene()->r;
+ scaleWidthOperation->setValue(data->xsch*data->size/100.0f);
+ scaleHeightOperation->setValue(data->ysch*data->size/100.0f);
+ ScaleAbsoluteOperation * operation = new ScaleAbsoluteOperation();
+ inputSocket->relinkConnections(operation->getInputSocket(0), true, 0, graph);
+ addLink(graph, scaleWidthOperation->getOutputSocket(), operation->getInputSocket(1));
+ addLink(graph, scaleHeightOperation->getOutputSocket(), operation->getInputSocket(2));
+ outputSocket->relinkConnections(operation->getOutputSocket(0));
+ graph->addOperation(scaleWidthOperation);
+ graph->addOperation(scaleHeightOperation);
+ graph->addOperation(operation);
+ }
+ break;
+
+ case CMP_SCALE_ABSOLUTE: {
+ ScaleAbsoluteOperation *operation = new ScaleAbsoluteOperation(); // TODO: what is the use of this one.... perhaps some issues when the ui was updated....
+
+ inputSocket->relinkConnections(operation->getInputSocket(0), true, 0, graph);
+ inputXSocket->relinkConnections(operation->getInputSocket(1), true, 1, graph);
+ inputYSocket->relinkConnections(operation->getInputSocket(2), true, 2, graph);
+ outputSocket->relinkConnections(operation->getOutputSocket(0));
+ graph->addOperation(operation);
+ }
+ break;
+ }
}
Modified: branches/tile/source/blender/compositor/operations/COM_ScaleOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_ScaleOperation.cpp 2012-04-12 17:34:29 UTC (rev 45578)
+++ branches/tile/source/blender/compositor/operations/COM_ScaleOperation.cpp 2012-04-12 20:21:02 UTC (rev 45579)
@@ -81,3 +81,74 @@
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+
+// SCALE ABSOLUTE
+ScaleAbsoluteOperation::ScaleAbsoluteOperation() : NodeOperation() {
+ this->addInputSocket(COM_DT_COLOR);
+ this->addInputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_VALUE);
+ this->addOutputSocket(COM_DT_COLOR);
+ this->setResolutionInputSocketIndex(0);
+ this->inputOperation = NULL;
+ this->inputXOperation= NULL;
+ this->inputYOperation = NULL;
+}
+void ScaleAbsoluteOperation::initExecution() {
+ this->inputOperation = this->getInputSocketReader(0);
+ this->inputXOperation = this->getInputSocketReader(1);
+ this->inputYOperation = this->getInputSocketReader(2);
+ this->centerX = this->getWidth()/2.0;
+ this->centerY = this->getHeight()/2.0;
+}
+
+void ScaleAbsoluteOperation::deinitExecution() {
+ this->inputOperation = NULL;
+ this->inputXOperation = NULL;
+ this->inputYOperation = NULL;
+}
+
+
+void ScaleAbsoluteOperation::executePixel(float *color,float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) {
+ float scaleX[4];
+ float scaleY[4];
+
+ this->inputXOperation->read(scaleX, x, y, sampler, inputBuffers);
+ this->inputYOperation->read(scaleY, x, y, sampler, inputBuffers);
+
+ const float scx = scaleX[0]; // target absolute scale
+ const float scy = scaleY[0]; // target absolute scale
+ const float width = this->getWidth();
+ const float height = this->getHeight();
+ //div
+ float relativeXScale = scx/width;
+ float relativeYScale = scy/height;
+
+ float nx = this->centerX+ (x - this->centerX) / relativeXScale;
+ float ny = this->centerY+ (y - this->centerY) / relativeYScale;
+ this->inputOperation->read(color, nx, ny, sampler, inputBuffers);
+}
+
+bool ScaleAbsoluteOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) {
+ rcti newInput;
+ float scaleX[4];
+ float scaleY[4];
+
+ this->inputXOperation->read(scaleX, 0, 0, COM_PS_NEAREST, NULL);
+ this->inputYOperation->read(scaleY, 0, 0, COM_PS_NEAREST, NULL);
+
+ const float scx = scaleX[0];
+ const float scy = scaleY[0];
+ const float width = this->getWidth();
+ const float height = this->getHeight();
+ //div
+ float relateveXScale = scx/width;
+ float relateveYScale = scy/height;
+
+ newInput.xmax = this->centerX+ (input->xmax - this->centerX) / relateveXScale;
+ newInput.xmin = this->centerX+ (input->xmin - this->centerX) / relateveXScale;
+ newInput.ymax = this->centerY+ (input->ymax - this->centerY) / relateveYScale;
+ newInput.ymin = this->centerY+ (input->ymin - this->centerY) / relateveYScale;
+
+ return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
+}
+
Modified: branches/tile/source/blender/compositor/operations/COM_ScaleOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_ScaleOperation.h 2012-04-12 17:34:29 UTC (rev 45578)
+++ branches/tile/source/blender/compositor/operations/COM_ScaleOperation.h 2012-04-12 20:21:02 UTC (rev 45579)
@@ -30,16 +30,30 @@
SocketReader *inputOperation;
SocketReader *inputXOperation;
SocketReader *inputYOperation;
- float centerX;
- float centerY;
+ float centerX;
+ float centerY;
public:
- ScaleOperation();
- bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
+ ScaleOperation();
+ bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
- void initExecution();
- void deinitExecution();
+ void initExecution();
+ void deinitExecution();
+};
+class ScaleAbsoluteOperation: public NodeOperation {
+ SocketReader *inputOperation;
+ SocketReader *inputXOperation;
+ SocketReader *inputYOperation;
+ float centerX;
+ float centerY;
+public:
+ ScaleAbsoluteOperation();
+ bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
+ void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
+
+ void initExecution();
+ void deinitExecution();
};
#endif
More information about the Bf-blender-cvs
mailing list