Blender  V2.93
COM_ScaleNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_ScaleNode.h"
20 
21 #include "BKE_node.h"
22 #include "COM_ExecutionSystem.h"
23 #include "COM_ScaleOperation.h"
25 #include "COM_SetValueOperation.h"
26 
27 namespace blender::compositor {
28 
29 ScaleNode::ScaleNode(bNode *editorNode) : Node(editorNode)
30 {
31  /* pass */
32 }
33 
35  const CompositorContext &context) const
36 {
37  bNode *bnode = this->getbNode();
38 
39  NodeInput *inputSocket = this->getInputSocket(0);
40  NodeInput *inputXSocket = this->getInputSocket(1);
41  NodeInput *inputYSocket = this->getInputSocket(2);
42  NodeOutput *outputSocket = this->getOutputSocket(0);
43 
44  switch (bnode->custom1) {
45  case CMP_SCALE_RELATIVE: {
46  ScaleOperation *operation = new ScaleOperation();
47  converter.addOperation(operation);
48 
49  converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
50  converter.mapInputSocket(inputXSocket, operation->getInputSocket(1));
51  converter.mapInputSocket(inputYSocket, operation->getInputSocket(2));
52  converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
53 
54  operation->setVariableSize(inputXSocket->isLinked() || inputYSocket->isLinked());
55  break;
56  }
58  SetValueOperation *scaleFactorOperation = new SetValueOperation();
59  scaleFactorOperation->setValue(context.getRenderPercentageAsFactor());
60  converter.addOperation(scaleFactorOperation);
61 
62  ScaleOperation *operation = new ScaleOperation();
63  converter.addOperation(operation);
64 
65  converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
66  converter.addLink(scaleFactorOperation->getOutputSocket(), operation->getInputSocket(1));
67  converter.addLink(scaleFactorOperation->getOutputSocket(), operation->getInputSocket(2));
68  converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
69 
70  operation->setVariableSize(inputXSocket->isLinked() || inputYSocket->isLinked());
71 
72  break;
73  }
75  const RenderData *rd = context.getRenderData();
76  const float render_size_factor = context.getRenderPercentageAsFactor();
78  /* framing options */
79  operation->setIsAspect((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) != 0);
80  operation->setIsCrop((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0);
81  operation->setOffset(bnode->custom3, bnode->custom4);
82  operation->setNewWidth(rd->xsch * render_size_factor);
83  operation->setNewHeight(rd->ysch * render_size_factor);
85  converter.addOperation(operation);
86 
87  converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
88  converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
89 
90  operation->setVariableSize(inputXSocket->isLinked() || inputYSocket->isLinked());
91 
92  break;
93  }
94  case CMP_SCALE_ABSOLUTE: {
95  /* TODO: what is the use of this one.... perhaps some issues when the ui was updated... */
97  converter.addOperation(operation);
98 
99  converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
100  converter.mapInputSocket(inputXSocket, operation->getInputSocket(1));
101  converter.mapInputSocket(inputYSocket, operation->getInputSocket(2));
102  converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
103 
104  operation->setVariableSize(inputXSocket->isLinked() || inputYSocket->isLinked());
105 
106  break;
107  }
108  }
109 }
110 
111 } // namespace blender::compositor
#define CMP_SCALE_ABSOLUTE
Definition: BKE_node.h:1245
#define CMP_SCALE_SCENEPERCENT
Definition: BKE_node.h:1246
#define CMP_SCALE_RENDERSIZE_FRAME_CROP
Definition: BKE_node.h:1250
#define CMP_SCALE_RENDERSIZE_FRAME_ASPECT
Definition: BKE_node.h:1249
#define CMP_SCALE_RENDERPERCENT
Definition: BKE_node.h:1247
#define CMP_SCALE_RELATIVE
Definition: BKE_node.h:1244
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
void setResizeMode(ResizeMode resizeMode)
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
ScaleNode(bNode *editorNode)
@ None
The bottom left of the input image is the bottom left of the working area of the node,...
short custom1
float custom4
short custom2
float custom3