From 91d0ef0a7eaa74df92f1e30299ba0e1720658eb6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 14 Jun 2012 18:55:35 +0000 Subject: scale node for new compositor now supports framing option. --- .../compositor/operations/COM_ScaleOperation.cpp | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'source/blender/compositor/operations/COM_ScaleOperation.cpp') diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cpp b/source/blender/compositor/operations/COM_ScaleOperation.cpp index f0c3b41b61a..aea4da920a0 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.cpp +++ b/source/blender/compositor/operations/COM_ScaleOperation.cpp @@ -190,6 +190,38 @@ void ScaleFixedSizeOperation::initExecution() this->inputOperation = this->getInputSocketReader(0); this->relX = inputOperation->getWidth() / (float)this->newWidth; this->relY = inputOperation->getHeight() / (float)this->newHeight; + + if (this->is_aspect) { + /* apply aspect from clip */ + const float w_src = inputOperation->getWidth(); + const float h_src = inputOperation->getHeight(); + + /* destination aspect is already applied from the camera frame */ + const float w_dst = this->newWidth; + const float h_dst = this->newHeight; + + const float asp_src = w_src / h_src; + const float asp_dst = w_dst / h_dst; + + this->offsetX = 0.0f; + this->offsetY = 0.0f; + + if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) { + if ((asp_src > asp_dst) == (this->is_crop == true)) { + /* fit X */ + const float div = asp_src / asp_dst; + this->relX /= div; + this->offsetX = ((w_src - (w_src * div)) / (w_src / w_dst)) / 2.0f; + } + else { + /* fit Y */ + const float div = asp_dst / asp_src; + this->relY /= div; + this->offsetY = ((h_src - (h_src * div)) / (h_src / h_dst)) / 2.0f; + } + } + + } } void ScaleFixedSizeOperation::deinitExecution() @@ -204,7 +236,14 @@ void ScaleFixedSizeOperation::executePixel(float *color, float x, float y, Pixel sampler = COM_PS_BICUBIC; #endif - this->inputOperation->read(color, x * relX, y * relY, sampler, inputBuffers); + if (this->is_aspect) { + float nx = ((x - this->offsetX) * relX); + float ny = ((y - this->offsetY) * relY); + this->inputOperation->read(color, nx, ny, sampler, inputBuffers); + } + else { + this->inputOperation->read(color, x * relX, y * relY, sampler, inputBuffers); + } } bool ScaleFixedSizeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) -- cgit v1.2.3