add node scale offset for old compositor too - also fix for error in last commit.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 15 Jun 2012 08:01:41 +0000 (08:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 15 Jun 2012 08:01:41 +0000 (08:01 +0000)
source/blender/compositor/operations/COM_ScaleOperation.cpp
source/blender/nodes/composite/nodes/node_composite_scale.c

index 45e8469..2e23df7 100644 (file)
@@ -223,13 +223,13 @@ void ScaleFixedSizeOperation::initExecution()
                                /* 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;
+                               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;
+                               this->offsetY += ((h_src - (h_src * div)) / (h_src / h_dst)) / 2.0f;
                        }
 
                        this->is_offset = true;
index fd4bd64..1df6772 100644 (file)
@@ -57,6 +57,7 @@ static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, b
                CompBuf *stackbuf, *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA);
                ImBuf *ibuf;
                int newx, newy;
+               float ofsx = 0.0f, ofsy = 0.0f;
 
                if (node->custom1 == CMP_SCALE_RELATIVE) {
                        newx = MAX2((int)(in[1]->vec[0] * cbuf->x), 1);
@@ -67,6 +68,21 @@ static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, b
                        newy = cbuf->y * (rd->size / 100.0f);
                }
                else if (node->custom1 == CMP_SCALE_RENDERPERCENT) {
+
+                       if (node->custom3 != 0.0f || node->custom4 != 0.0f) {
+                               const float w_dst = (rd->xsch * rd->size) / 100;
+                               const float h_dst = (rd->ysch * rd->size) / 100;
+
+                               if (w_dst > h_dst) {
+                                       ofsx = node->custom3 * w_dst;
+                                       ofsy = node->custom4 * w_dst;
+                               }
+                               else {
+                                       ofsx = node->custom3 * h_dst;
+                                       ofsy = node->custom4 * h_dst;
+                               }
+                       }
+
                        /* supports framing options */
                        if (node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) {
                                /* apply aspect from clip */
@@ -133,8 +149,8 @@ static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, b
                        IMB_freeImBuf(ibuf);
 
                        /* also do the translation vector */
-                       stackbuf->xof = (int)(((float)newx / (float)cbuf->x) * (float)cbuf->xof);
-                       stackbuf->yof = (int)(((float)newy / (float)cbuf->y) * (float)cbuf->yof);
+                       stackbuf->xof = (int)(ofsx + (((float)newx / (float)cbuf->x) * (float)cbuf->xof));
+                       stackbuf->yof = (int)(ofsy + (((float)newy / (float)cbuf->y) * (float)cbuf->yof));
                }
                else {
                        stackbuf = dupalloc_compbuf(cbuf);