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:
authorMonique Dewanchand <m.dewanchand@atmind.nl>2013-01-31 19:08:37 +0400
committerMonique Dewanchand <m.dewanchand@atmind.nl>2013-01-31 19:08:37 +0400
commita5cef69a0dc0b86d13d2fd16695db77094804c96 (patch)
tree14b0cc6af503f4f2ed6cbecd023effa77a7378ee /source/blender/compositor/operations/COM_TranslateOperation.cpp
parent3a4c317b877c3c5c061808d2aa8a437fe30d5eee (diff)
Apply patch [#33999] Wrapping mode for the "translate" compositing node
this patch enables the translate node to wrap around the image borders. This is especially needed if the translate node is not used to position elements on a layer but when it is used instead for seamless backgrounds like mountains or clouds that should be repeated over time (by animating the x/y values). No trunk without docs! So here is my documentation: http://wiki.blender.org/index.php/User:Plasmasolutions/TranslateNodeExtension The code is properly documented and should be easy to read and understand. When there are any problems or issues, please comment, I'll tackle them right away! Greetings, Thomas Beck * optimized determination dependant areas * fixed some issues with scale node There are still some issues when scaling very small values (x=0.0001) - At Mind -
Diffstat (limited to 'source/blender/compositor/operations/COM_TranslateOperation.cpp')
-rw-r--r--source/blender/compositor/operations/COM_TranslateOperation.cpp118
1 files changed, 110 insertions, 8 deletions
diff --git a/source/blender/compositor/operations/COM_TranslateOperation.cpp b/source/blender/compositor/operations/COM_TranslateOperation.cpp
index 761f55a1455..c34931471c7 100644
--- a/source/blender/compositor/operations/COM_TranslateOperation.cpp
+++ b/source/blender/compositor/operations/COM_TranslateOperation.cpp
@@ -15,9 +15,10 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * Contributor:
- * Jeroen Bakker
+ * Contributor:
+ * Jeroen Bakker
* Monique Dewanchand
+ * Thomas Beck (plasmasolutions.de)
*/
#include "COM_TranslateOperation.h"
@@ -40,6 +41,12 @@ void TranslateOperation::initExecution()
this->m_inputXOperation = this->getInputSocketReader(1);
this->m_inputYOperation = this->getInputSocketReader(2);
+ ensureDelta();
+
+ //Calculate the relative offset once per execution, no need to do this per pixel
+ this->m_relativeOffsetX = fmodf(this->getDeltaX(), this->getWidth());
+ this->m_relativeOffsetY = fmodf(this->getDeltaY(), this->getHeight());
+
}
void TranslateOperation::deinitExecution()
@@ -53,18 +60,113 @@ void TranslateOperation::deinitExecution()
void TranslateOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
ensureDelta();
- this->m_inputOperation->read(output, x - this->getDeltaX(), y - this->getDeltaY(), sampler);
+
+ float originalXPos = x - this->getDeltaX();
+ float originalYPos = y - this->getDeltaY();
+
+ switch(m_wrappingType) {
+ case 0:
+ //Intentionally empty, originalXPos and originalYPos have been set before
+ break;
+ case 1:
+ // wrap only on the x-axis
+ originalXPos = this->getWrappedOriginalXPos(x);
+ break;
+ case 2:
+ // wrap only on the y-axis
+ originalYPos = this->getWrappedOriginalYPos(y);
+ break;
+ case 3:
+ // wrap on both
+ originalXPos = this->getWrappedOriginalXPos(x);
+ originalYPos = this->getWrappedOriginalYPos(y);
+ break;
+ }
+
+ this->m_inputOperation->read(output, originalXPos , originalYPos, sampler);
+
}
bool TranslateOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
- ensureDelta();
rcti newInput;
-
- newInput.xmax = input->xmax - this->getDeltaX();
+
+ ensureDelta();
+
newInput.xmin = input->xmin - this->getDeltaX();
- newInput.ymax = input->ymax - this->getDeltaY();
+ newInput.xmax = input->xmax - this->getDeltaX();
newInput.ymin = input->ymin - this->getDeltaY();
-
+ newInput.ymax = input->ymax - this->getDeltaY();
+
+ if (m_wrappingType == 1 || m_wrappingType == 3){
+ // wrap only on the x-axis if tile is wrapping
+ newInput.xmin = getWrappedOriginalXPos(input->xmin);
+ newInput.xmax = getWrappedOriginalXPos(input->xmax);
+ if(newInput.xmin > newInput.xmax){
+ newInput.xmin = 0;
+ newInput.xmax = this->getWidth();
+ }
+ }
+ if(m_wrappingType == 2 || m_wrappingType == 3) {
+ // wrap only on the y-axis if tile is wrapping
+ newInput.ymin = getWrappedOriginalYPos(input->ymin);
+ newInput.ymax = getWrappedOriginalYPos(input->ymax);
+ if (newInput.ymin > newInput.ymax){
+ newInput.ymin = 0;
+ newInput.ymax = this->getHeight();
+ }
+ }
+
+
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
+
+void TranslateOperation::setWrapping(char wrapping_type)
+{
+ m_wrappingType = wrapping_type;
+}
+
+float TranslateOperation::getWrappedOriginalXPos(float x)
+{
+ float originalXPos = 0;
+
+ // Positive offset: Append image data from the left
+ if ( this->m_relativeOffsetX > 0 ) {
+ if ( x < this->m_relativeOffsetX )
+ originalXPos = this->getWidth() - this->m_relativeOffsetX + x;
+ else
+ originalXPos = x - this->m_relativeOffsetX;
+ } else {
+ // Negative offset: Append image data from the right
+ if (x < (this->getWidth() + this->m_relativeOffsetX))
+ originalXPos = x - this->m_relativeOffsetX;
+ else
+ originalXPos = x - (this->getWidth() + this->m_relativeOffsetX);
+ }
+
+ while (originalXPos < 0) originalXPos += this->m_width;
+ return fmodf(originalXPos, this->getWidth());
+}
+
+
+float TranslateOperation::getWrappedOriginalYPos(float y)
+{
+ float originalYPos = 0;
+
+ // Positive offset: Append image data from the bottom
+ if ( this->m_relativeOffsetY > 0 ) {
+ if ( y < this->m_relativeOffsetY )
+ originalYPos = this->getHeight()- this->m_relativeOffsetY + y;
+ else
+ originalYPos = y - this->m_relativeOffsetY;
+ } else {
+ // Negative offset: Append image data from the top
+ if (y < (this->getHeight() + this->m_relativeOffsetY))
+ originalYPos = y - this->m_relativeOffsetY;
+ else
+ originalYPos = y - (this->getHeight() + this->m_relativeOffsetY);
+ }
+
+ while (originalYPos < 0) originalYPos += this->m_height;
+ return fmodf(originalYPos, this->getHeight());
+}