2 * Copyright 2011, Blender Foundation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include "COM_AlphaOverNode.h"
28 #include "COM_BilateralBlurNode.h"
29 #include "COM_BlurNode.h"
30 #include "COM_BokehBlurNode.h"
31 #include "COM_BokehImageNode.h"
32 #include "COM_BoxMaskNode.h"
33 #include "COM_BrightnessNode.h"
34 #include "COM_ChannelMatteNode.h"
35 #include "COM_ChromaMatteNode.h"
36 #include "COM_ColorBalanceNode.h"
37 #include "COM_ColorCorrectionNode.h"
38 #include "COM_ColorCurveNode.h"
39 #include "COM_ColorMatteNode.h"
40 #include "COM_ColorNode.h"
41 #include "COM_ColorRampNode.h"
42 #include "COM_ColorSpillNode.h"
43 #include "COM_ColorToBWNode.h"
44 #include "COM_CombineHSVANode.h"
45 #include "COM_CombineRGBANode.h"
46 #include "COM_CombineYCCANode.h"
47 #include "COM_CombineYUVANode.h"
48 #include "COM_CompositorNode.h"
49 #include "COM_ConvertAlphaNode.h"
50 #include "COM_ConvertColorToVectorOperation.h"
51 #include "COM_ConvertColourToValueProg.h"
52 #include "COM_ConvertValueToColourProg.h"
53 #include "COM_ConvertValueToVectorOperation.h"
54 #include "COM_ConvertVectorToColorOperation.h"
55 #include "COM_ConvertVectorToValueOperation.h"
56 #include "COM_Converter.h"
57 #include "COM_CropNode.h"
58 #include "COM_DefocusNode.h"
59 #include "COM_DifferenceMatteNode.h"
60 #include "COM_DilateErodeNode.h"
61 #include "COM_DirectionalBlurNode.h"
62 #include "COM_DisplaceNode.h"
63 #include "COM_DistanceMatteNode.h"
64 #include "COM_DoubleEdgeMaskNode.h"
65 #include "COM_EllipseMaskNode.h"
66 #include "COM_ExecutionSystem.h"
67 #include "COM_ExecutionSystemHelper.h"
68 #include "COM_FilterNode.h"
69 #include "COM_FlipNode.h"
70 #include "COM_GammaNode.h"
71 #include "COM_GlareNode.h"
72 #include "COM_GroupNode.h"
73 #include "COM_HueSaturationValueCorrectNode.h"
74 #include "COM_HueSaturationValueNode.h"
75 #include "COM_IDMaskNode.h"
76 #include "COM_ImageNode.h"
77 #include "COM_InvertNode.h"
78 #include "COM_KeyingNode.h"
79 #include "COM_KeyingScreenNode.h"
80 #include "COM_LensDistortionNode.h"
81 #include "COM_LuminanceMatteNode.h"
82 #include "COM_MapUVNode.h"
83 #include "COM_MapValueNode.h"
84 #include "COM_MaskNode.h"
85 #include "COM_MathNode.h"
86 #include "COM_MixNode.h"
87 #include "COM_MovieClipNode.h"
88 #include "COM_MovieDistortionNode.h"
89 #include "COM_MuteNode.h"
90 #include "COM_NormalNode.h"
91 #include "COM_NormalizeNode.h"
92 #include "COM_OutputFileNode.h"
93 #include "COM_RenderLayersNode.h"
94 #include "COM_RotateNode.h"
95 #include "COM_ScaleNode.h"
96 #include "COM_ScaleOperation.h"
97 #include "COM_SeparateHSVANode.h"
98 #include "COM_SeparateRGBANode.h"
99 #include "COM_SeparateYCCANode.h"
100 #include "COM_SeparateYUVANode.h"
101 #include "COM_SetAlphaNode.h"
102 #include "COM_SetValueOperation.h"
103 #include "COM_SocketConnection.h"
104 #include "COM_SplitViewerNode.h"
105 #include "COM_Stabilize2dNode.h"
106 #include "COM_SwitchNode.h"
107 #include "COM_TextureNode.h"
108 #include "COM_TimeNode.h"
109 #include "COM_TonemapNode.h"
110 #include "COM_TransformNode.h"
111 #include "COM_TranslateNode.h"
112 #include "COM_TranslateOperation.h"
113 #include "COM_ValueNode.h"
114 #include "COM_VectorBlurNode.h"
115 #include "COM_VectorCurveNode.h"
116 #include "COM_ViewLevelsNode.h"
117 #include "COM_ViewerNode.h"
118 #include "COM_ZCombineNode.h"
120 Node *Converter::convert(bNode *b_node)
124 if (b_node->flag & NODE_MUTED) {
125 node = new MuteNode(b_node);
129 switch (b_node->type) {
130 case CMP_NODE_COMPOSITE:
131 node = new CompositorNode(b_node);
133 case CMP_NODE_R_LAYERS:
134 node = new RenderLayersNode(b_node);
136 case CMP_NODE_TEXTURE:
137 node = new TextureNode(b_node);
139 case CMP_NODE_RGBTOBW:
140 node = new ColourToBWNode(b_node);
142 case CMP_NODE_MIX_RGB:
143 node = new MixNode(b_node);
145 case CMP_NODE_TRANSLATE:
146 node = new TranslateNode(b_node);
149 node = new ScaleNode(b_node);
151 case CMP_NODE_ROTATE:
152 node = new RotateNode(b_node);
155 node = new FlipNode(b_node);
157 case CMP_NODE_FILTER:
158 node = new FilterNode(b_node);
160 case CMP_NODE_ID_MASK:
161 node = new IDMaskNode(b_node);
163 case CMP_NODE_BRIGHTCONTRAST:
164 node = new BrightnessNode(b_node);
166 case CMP_NODE_SEPRGBA:
167 node = new SeparateRGBANode(b_node);
169 case CMP_NODE_COMBRGBA:
170 node = new CombineRGBANode(b_node);
172 case CMP_NODE_SEPHSVA:
173 node = new SeparateHSVANode(b_node);
175 case CMP_NODE_COMBHSVA:
176 node = new CombineHSVANode(b_node);
178 case CMP_NODE_SEPYUVA:
179 node = new SeparateYUVANode(b_node);
181 case CMP_NODE_COMBYUVA:
182 node = new CombineYUVANode(b_node);
184 case CMP_NODE_SEPYCCA:
185 node = new SeparateYCCANode(b_node);
187 case CMP_NODE_COMBYCCA:
188 node = new CombineYCCANode(b_node);
190 case CMP_NODE_ALPHAOVER:
191 node = new AlphaOverNode(b_node);
193 case CMP_NODE_COLORBALANCE:
194 node = new ColorBalanceNode(b_node);
196 case CMP_NODE_VIEWER:
197 node = new ViewerNode(b_node);
199 case CMP_NODE_SPLITVIEWER:
200 node = new SplitViewerNode(b_node);
202 case CMP_NODE_INVERT:
203 node = new InvertNode(b_node);
206 node = new GroupNode(b_node);
208 case CMP_NODE_NORMAL:
209 node = new NormalNode(b_node);
211 case CMP_NODE_NORMALIZE:
212 node = new NormalizeNode(b_node);
215 node = new ImageNode(b_node);
217 case CMP_NODE_SETALPHA:
218 node = new SetAlphaNode(b_node);
220 case CMP_NODE_PREMULKEY:
221 node = new ConvertAlphaNode(b_node);
224 node = new MathNode(b_node);
226 case CMP_NODE_HUE_SAT:
227 node = new HueSaturationValueNode(b_node);
229 case CMP_NODE_COLORCORRECTION:
230 node = new ColorCorrectionNode(b_node);
232 case CMP_NODE_MASK_BOX:
233 node = new BoxMaskNode(b_node);
235 case CMP_NODE_MASK_ELLIPSE:
236 node = new EllipseMaskNode(b_node);
239 node = new GammaNode(b_node);
241 case CMP_NODE_CURVE_RGB:
242 node = new ColorCurveNode(b_node);
244 case CMP_NODE_CURVE_VEC:
245 node = new VectorCurveNode(b_node);
247 case CMP_NODE_HUECORRECT:
248 node = new HueSaturationValueCorrectNode(b_node);
250 case CMP_NODE_MAP_UV:
251 node = new MapUVNode(b_node);
253 case CMP_NODE_DISPLACE:
254 node = new DisplaceNode(b_node);
256 case CMP_NODE_VALTORGB:
257 node = new ColorRampNode(b_node);
259 case CMP_NODE_DIFF_MATTE:
260 node = new DifferenceMatteNode(b_node);
262 case CMP_NODE_LUMA_MATTE:
263 node = new LuminanceMatteNode(b_node);
265 case CMP_NODE_DIST_MATTE:
266 node = new DistanceMatteNode(b_node);
268 case CMP_NODE_CHROMA_MATTE:
269 node = new ChromaMatteNode(b_node);
271 case CMP_NODE_COLOR_MATTE:
272 node = new ColorMatteNode(b_node);
274 case CMP_NODE_CHANNEL_MATTE:
275 node = new ChannelMatteNode(b_node);
278 node = new BlurNode(b_node);
280 case CMP_NODE_BOKEHIMAGE:
281 node = new BokehImageNode(b_node);
283 case CMP_NODE_BOKEHBLUR:
284 node = new BokehBlurNode(b_node);
286 case CMP_NODE_DILATEERODE:
287 node = new DilateErodeNode(b_node);
289 case CMP_NODE_LENSDIST:
290 node = new LensDistortionNode(b_node);
293 node = new ColorNode(b_node);
296 node = new ValueNode(b_node);
299 node = new TimeNode(b_node);
302 node = new DirectionalBlurNode(b_node);
304 case CMP_NODE_ZCOMBINE:
305 node = new ZCombineNode(b_node);
307 case CMP_NODE_TONEMAP:
308 node = new TonemapNode(b_node);
310 case CMP_NODE_SWITCH:
311 node = new SwitchNode(b_node);
314 node = new GlareNode(b_node);
316 case CMP_NODE_MOVIECLIP:
317 node = new MovieClipNode(b_node);
319 case CMP_NODE_COLOR_SPILL:
320 node = new ColorSpillNode(b_node);
322 case CMP_NODE_OUTPUT_FILE:
323 node = new OutputFileNode(b_node);
325 case CMP_NODE_MAP_VALUE:
326 node = new MapValueNode(b_node);
328 case CMP_NODE_TRANSFORM:
329 node = new TransformNode(b_node);
331 case CMP_NODE_STABILIZE2D:
332 node = new Stabilize2dNode(b_node);
334 case CMP_NODE_BILATERALBLUR:
335 node = new BilateralBlurNode(b_node);
337 case CMP_NODE_VECBLUR:
338 node = new VectorBlurNode(b_node);
340 case CMP_NODE_MOVIEDISTORTION:
341 node = new MovieDistortionNode(b_node);
343 case CMP_NODE_VIEW_LEVELS:
344 node = new ViewLevelsNode(b_node);
346 case CMP_NODE_DEFOCUS:
347 node = new DefocusNode(b_node);
349 case CMP_NODE_DOUBLEEDGEMASK:
350 node = new DoubleEdgeMaskNode(b_node);
353 node = new CropNode(b_node);
356 node = new MaskNode(b_node);
358 case CMP_NODE_KEYINGSCREEN:
359 node = new KeyingScreenNode(b_node);
361 case CMP_NODE_KEYING:
362 node = new KeyingNode(b_node);
364 /* not inplemented yet */
366 node = new MuteNode(b_node);
371 void Converter::convertDataType(SocketConnection *connection, ExecutionSystem *system)
373 OutputSocket *outputSocket = connection->getFromSocket();
374 InputSocket *inputSocket = connection->getToSocket();
375 DataType fromDatatype = outputSocket->getDataType();
376 DataType toDatatype = inputSocket->getDataType();
377 NodeOperation *converter = NULL;
378 if (fromDatatype == COM_DT_VALUE && toDatatype == COM_DT_COLOR) {
379 converter = new ConvertValueToColourProg();
381 else if (fromDatatype == COM_DT_VALUE && toDatatype == COM_DT_VECTOR) {
382 converter = new ConvertValueToVectorOperation();
384 else if (fromDatatype == COM_DT_COLOR && toDatatype == COM_DT_VALUE) {
385 converter = new ConvertColourToValueProg();
387 else if (fromDatatype == COM_DT_COLOR && toDatatype == COM_DT_VECTOR) {
388 converter = new ConvertColorToVectorOperation();
390 else if (fromDatatype == COM_DT_VECTOR && toDatatype == COM_DT_VALUE) {
391 converter = new ConvertVectorToValueOperation();
393 else if (fromDatatype == COM_DT_VECTOR && toDatatype == COM_DT_COLOR) {
394 converter = new ConvertVectorToColorOperation();
396 if (converter != NULL) {
397 inputSocket->relinkConnections(converter->getInputSocket(0));
398 ExecutionSystemHelper::addLink(system->getConnections(), converter->getOutputSocket(), inputSocket);
399 system->addOperation(converter);
403 void Converter::convertResolution(SocketConnection *connection, ExecutionSystem *system)
405 InputSocketResizeMode mode = connection->getToSocket()->getResizeMode();
407 NodeOperation *toOperation = (NodeOperation *)connection->getToNode();
408 const float toWidth = toOperation->getWidth();
409 const float toHeight = toOperation->getHeight();
410 NodeOperation *fromOperation = (NodeOperation *)connection->getFromNode();
411 const float fromWidth = fromOperation->getWidth();
412 const float fromHeight = fromOperation->getHeight();
413 bool doCenter = false;
414 bool doScale = false;
415 float addX = (toWidth - fromWidth) / 2.0f;
416 float addY = (toHeight - fromHeight) / 2.0f;
421 case COM_SC_NO_RESIZE:
426 case COM_SC_FIT_WIDTH:
429 scaleX = scaleY = toWidth / fromWidth;
431 case COM_SC_FIT_HEIGHT:
434 scaleX = scaleY = toHeight / fromHeight;
439 scaleX = toWidth / fromWidth;
440 scaleY = toHeight / fromHeight;
441 if (scaleX < scaleY) {
451 scaleX = toWidth / fromWidth;
452 scaleY = toHeight / fromHeight;
458 NodeOperation *first = NULL;
460 ScaleOperation *scaleOperation = NULL;
462 scaleOperation = new ScaleOperation();
463 first = scaleOperation;
464 SetValueOperation *sxop = new SetValueOperation();
465 sxop->setValue(scaleX);
466 c = ExecutionSystemHelper::addLink(system->getConnections(), sxop->getOutputSocket(), scaleOperation->getInputSocket(1));
467 c->setIgnoreResizeCheck(true);
468 SetValueOperation *syop = new SetValueOperation();
469 syop->setValue(scaleY);
470 c = ExecutionSystemHelper::addLink(system->getConnections(), syop->getOutputSocket(), scaleOperation->getInputSocket(2));
471 c->setIgnoreResizeCheck(true);
472 system->addOperation(sxop);
473 system->addOperation(syop);
475 unsigned int resolution[2] = {fromWidth, fromHeight};
476 scaleOperation->setResolution(resolution);
477 sxop->setResolution(resolution);
478 syop->setResolution(resolution);
479 system->addOperation(scaleOperation);
481 c->setIgnoreResizeCheck(true);
484 TranslateOperation *translateOperation = new TranslateOperation();
485 if (!first) first = translateOperation;
486 SetValueOperation *xop = new SetValueOperation();
488 c = ExecutionSystemHelper::addLink(system->getConnections(), xop->getOutputSocket(), translateOperation->getInputSocket(1));
489 c->setIgnoreResizeCheck(true);
490 SetValueOperation *yop = new SetValueOperation();
492 c = ExecutionSystemHelper::addLink(system->getConnections(), yop->getOutputSocket(), translateOperation->getInputSocket(2));
493 c->setIgnoreResizeCheck(true);
494 system->addOperation(xop);
495 system->addOperation(yop);
497 unsigned int resolution[2] = {toWidth, toHeight};
498 translateOperation->setResolution(resolution);
499 xop->setResolution(resolution);
500 yop->setResolution(resolution);
501 system->addOperation(translateOperation);
504 c = ExecutionSystemHelper::addLink(system->getConnections(), scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0));
505 c->setIgnoreResizeCheck(true);
508 InputSocket *inputSocket = connection->getToSocket();
509 inputSocket->relinkConnections(first->getInputSocket(0));
510 c = ExecutionSystemHelper::addLink(system->getConnections(), translateOperation->getOutputSocket(), inputSocket);
511 c->setIgnoreResizeCheck(true);
514 connection->setIgnoreResizeCheck(true);