Cleanup: remove non-existing function declarations
[blender.git] / source / blender / compositor / intern / COM_Converter.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
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.
8  *
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.
13  *
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.
17  *
18  * Contributor:
19  *      Jeroen Bakker
20  *      Monique Dewanchand
21  */
22
23 #include <string.h>
24
25 extern "C" {
26 #include "DNA_node_types.h"
27
28 #include "BKE_node.h"
29 }
30
31 #include "COM_NodeOperationBuilder.h"
32 #include "COM_NodeOperation.h"
33
34 #include "COM_AlphaOverNode.h"
35 #include "COM_BilateralBlurNode.h"
36 #include "COM_BlurNode.h"
37 #include "COM_BokehBlurNode.h"
38 #include "COM_BokehImageNode.h"
39 #include "COM_BoxMaskNode.h"
40 #include "COM_BrightnessNode.h"
41 #include "COM_ChannelMatteNode.h"
42 #include "COM_ChromaMatteNode.h"
43 #include "COM_ColorBalanceNode.h"
44 #include "COM_ColorCorrectionNode.h"
45 #include "COM_ColorCurveNode.h"
46 #include "COM_ColorMatteNode.h"
47 #include "COM_ColorNode.h"
48 #include "COM_ColorRampNode.h"
49 #include "COM_ColorSpillNode.h"
50 #include "COM_ColorToBWNode.h"
51 #include "COM_CombineColorNode.h"
52 #include "COM_CompositorNode.h"
53 #include "COM_ConvertAlphaNode.h"
54 #include "COM_ConvertOperation.h"
55 #include "COM_Converter.h"
56 #include "COM_CornerPinNode.h"
57 #include "COM_CropNode.h"
58 #include "COM_CryptomatteNode.h"
59 #include "COM_DefocusNode.h"
60 #include "COM_DespeckleNode.h"
61 #include "COM_DifferenceMatteNode.h"
62 #include "COM_DilateErodeNode.h"
63 #include "COM_DirectionalBlurNode.h"
64 #include "COM_DisplaceNode.h"
65 #include "COM_DistanceMatteNode.h"
66 #include "COM_DoubleEdgeMaskNode.h"
67 #include "COM_EllipseMaskNode.h"
68 #include "COM_ExecutionSystem.h"
69 #include "COM_FilterNode.h"
70 #include "COM_FlipNode.h"
71 #include "COM_GammaNode.h"
72 #include "COM_GlareNode.h"
73 #include "COM_HueSaturationValueCorrectNode.h"
74 #include "COM_HueSaturationValueNode.h"
75 #include "COM_IDMaskNode.h"
76 #include "COM_ImageNode.h"
77 #include "COM_InpaintNode.h"
78 #include "COM_InvertNode.h"
79 #include "COM_KeyingNode.h"
80 #include "COM_KeyingScreenNode.h"
81 #include "COM_LensDistortionNode.h"
82 #include "COM_LuminanceMatteNode.h"
83 #include "COM_MapUVNode.h"
84 #include "COM_MapValueNode.h"
85 #include "COM_MapRangeNode.h"
86 #include "COM_MaskNode.h"
87 #include "COM_MathNode.h"
88 #include "COM_MixNode.h"
89 #include "COM_MovieClipNode.h"
90 #include "COM_MovieDistortionNode.h"
91 #include "COM_NormalNode.h"
92 #include "COM_NormalizeNode.h"
93 #include "COM_OutputFileNode.h"
94 #include "COM_RenderLayersNode.h"
95 #include "COM_RotateNode.h"
96 #include "COM_ScaleNode.h"
97 #include "COM_ScaleOperation.h"
98 #include "COM_SeparateColorNode.h"
99 #include "COM_SetAlphaNode.h"
100 #include "COM_SetValueOperation.h"
101 #include "COM_SplitViewerNode.h"
102 #include "COM_Stabilize2dNode.h"
103 #include "COM_SunBeamsNode.h"
104 #include "COM_SwitchNode.h"
105 #include "COM_SwitchViewNode.h"
106 #include "COM_TextureNode.h"
107 #include "COM_TimeNode.h"
108 #include "COM_TonemapNode.h"
109 #include "COM_TransformNode.h"
110 #include "COM_TranslateNode.h"
111 #include "COM_TranslateOperation.h"
112 #include "COM_TrackPositionNode.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"
119 #include "COM_PixelateNode.h"
120 #include "COM_PlaneTrackDeformNode.h"
121
122 bool Converter::is_fast_node(bNode *b_node)
123 {
124         return !(b_node->type == CMP_NODE_BLUR ||
125                  b_node->type == CMP_NODE_VECBLUR ||
126                  b_node->type == CMP_NODE_BILATERALBLUR ||
127                  b_node->type == CMP_NODE_DEFOCUS ||
128                  b_node->type == CMP_NODE_BOKEHBLUR ||
129                  b_node->type == CMP_NODE_GLARE ||
130                  b_node->type == CMP_NODE_DBLUR ||
131                  b_node->type == CMP_NODE_MOVIEDISTORTION ||
132                  b_node->type == CMP_NODE_LENSDIST ||
133                  b_node->type == CMP_NODE_DOUBLEEDGEMASK ||
134                  b_node->type == CMP_NODE_DILATEERODE);
135 }
136
137 Node *Converter::convert(bNode *b_node)
138 {
139         Node *node = NULL;
140
141         /* ignore undefined nodes with missing or invalid node data */
142         if (!nodeIsRegistered(b_node))
143                 return NULL;
144
145         switch (b_node->type) {
146                 case CMP_NODE_COMPOSITE:
147                         node = new CompositorNode(b_node);
148                         break;
149                 case CMP_NODE_R_LAYERS:
150                         node = new RenderLayersNode(b_node);
151                         break;
152                 case CMP_NODE_TEXTURE:
153                         node = new TextureNode(b_node);
154                         break;
155                 case CMP_NODE_RGBTOBW:
156                         node = new ColorToBWNode(b_node);
157                         break;
158                 case CMP_NODE_MIX_RGB:
159                         node = new MixNode(b_node);
160                         break;
161                 case CMP_NODE_TRANSLATE:
162                         node = new TranslateNode(b_node);
163                         break;
164                 case CMP_NODE_SCALE:
165                         node = new ScaleNode(b_node);
166                         break;
167                 case CMP_NODE_ROTATE:
168                         node = new RotateNode(b_node);
169                         break;
170                 case CMP_NODE_FLIP:
171                         node = new FlipNode(b_node);
172                         break;
173                 case CMP_NODE_FILTER:
174                         node = new FilterNode(b_node);
175                         break;
176                 case CMP_NODE_ID_MASK:
177                         node = new IDMaskNode(b_node);
178                         break;
179                 case CMP_NODE_BRIGHTCONTRAST:
180                         node = new BrightnessNode(b_node);
181                         break;
182                 case CMP_NODE_SEPRGBA:
183                         node = new SeparateRGBANode(b_node);
184                         break;
185                 case CMP_NODE_COMBRGBA:
186                         node = new CombineRGBANode(b_node);
187                         break;
188                 case CMP_NODE_SEPHSVA:
189                         node = new SeparateHSVANode(b_node);
190                         break;
191                 case CMP_NODE_COMBHSVA:
192                         node = new CombineHSVANode(b_node);
193                         break;
194                 case CMP_NODE_SEPYUVA:
195                         node = new SeparateYUVANode(b_node);
196                         break;
197                 case CMP_NODE_COMBYUVA:
198                         node = new CombineYUVANode(b_node);
199                         break;
200                 case CMP_NODE_SEPYCCA:
201                         node = new SeparateYCCANode(b_node);
202                         break;
203                 case CMP_NODE_COMBYCCA:
204                         node = new CombineYCCANode(b_node);
205                         break;
206                 case CMP_NODE_ALPHAOVER:
207                         node = new AlphaOverNode(b_node);
208                         break;
209                 case CMP_NODE_COLORBALANCE:
210                         node = new ColorBalanceNode(b_node);
211                         break;
212                 case CMP_NODE_VIEWER:
213                         node = new ViewerNode(b_node);
214                         break;
215                 case CMP_NODE_SPLITVIEWER:
216                         node = new SplitViewerNode(b_node);
217                         break;
218                 case CMP_NODE_INVERT:
219                         node = new InvertNode(b_node);
220                         break;
221                 case NODE_GROUP:
222                 case NODE_GROUP_INPUT:
223                 case NODE_GROUP_OUTPUT:
224                         /* handled in NodeCompiler */
225                         break;
226                 case CMP_NODE_NORMAL:
227                         node = new NormalNode(b_node);
228                         break;
229                 case CMP_NODE_NORMALIZE:
230                         node = new NormalizeNode(b_node);
231                         break;
232                 case CMP_NODE_IMAGE:
233                         node = new ImageNode(b_node);
234                         break;
235                 case CMP_NODE_SETALPHA:
236                         node = new SetAlphaNode(b_node);
237                         break;
238                 case CMP_NODE_PREMULKEY:
239                         node = new ConvertAlphaNode(b_node);
240                         break;
241                 case CMP_NODE_MATH:
242                         node = new MathNode(b_node);
243                         break;
244                 case CMP_NODE_HUE_SAT:
245                         node = new HueSaturationValueNode(b_node);
246                         break;
247                 case CMP_NODE_COLORCORRECTION:
248                         node = new ColorCorrectionNode(b_node);
249                         break;
250                 case CMP_NODE_MASK_BOX:
251                         node = new BoxMaskNode(b_node);
252                         break;
253                 case CMP_NODE_MASK_ELLIPSE:
254                         node = new EllipseMaskNode(b_node);
255                         break;
256                 case CMP_NODE_GAMMA:
257                         node = new GammaNode(b_node);
258                         break;
259                 case CMP_NODE_CURVE_RGB:
260                         node = new ColorCurveNode(b_node);
261                         break;
262                 case CMP_NODE_CURVE_VEC:
263                         node = new VectorCurveNode(b_node);
264                         break;
265                 case CMP_NODE_HUECORRECT:
266                         node = new HueSaturationValueCorrectNode(b_node);
267                         break;
268                 case CMP_NODE_MAP_UV:
269                         node = new MapUVNode(b_node);
270                         break;
271                 case CMP_NODE_DISPLACE:
272                         node = new DisplaceNode(b_node);
273                         break;
274                 case CMP_NODE_VALTORGB:
275                         node = new ColorRampNode(b_node);
276                         break;
277                 case CMP_NODE_DIFF_MATTE:
278                         node = new DifferenceMatteNode(b_node);
279                         break;
280                 case CMP_NODE_LUMA_MATTE:
281                         node = new LuminanceMatteNode(b_node);
282                         break;
283                 case CMP_NODE_DIST_MATTE:
284                         node = new DistanceMatteNode(b_node);
285                         break;
286                 case CMP_NODE_CHROMA_MATTE:
287                         node = new ChromaMatteNode(b_node);
288                         break;
289                 case CMP_NODE_COLOR_MATTE:
290                         node = new ColorMatteNode(b_node);
291                         break;
292                 case CMP_NODE_CHANNEL_MATTE:
293                         node = new ChannelMatteNode(b_node);
294                         break;
295                 case CMP_NODE_BLUR:
296                         node = new BlurNode(b_node);
297                         break;
298                 case CMP_NODE_BOKEHIMAGE:
299                         node = new BokehImageNode(b_node);
300                         break;
301                 case CMP_NODE_BOKEHBLUR:
302                         node = new BokehBlurNode(b_node);
303                         break;
304                 case CMP_NODE_DILATEERODE:
305                         node = new DilateErodeNode(b_node);
306                         break;
307                 case CMP_NODE_INPAINT:
308                         node = new InpaintNode(b_node);
309                         break;
310                 case CMP_NODE_DESPECKLE:
311                         node = new DespeckleNode(b_node);
312                         break;
313                 case CMP_NODE_LENSDIST:
314                         node = new LensDistortionNode(b_node);
315                         break;
316                 case CMP_NODE_RGB:
317                         node = new ColorNode(b_node);
318                         break;
319                 case CMP_NODE_VALUE:
320                         node = new ValueNode(b_node);
321                         break;
322                 case CMP_NODE_TIME:
323                         node = new TimeNode(b_node);
324                         break;
325                 case CMP_NODE_DBLUR:
326                         node = new DirectionalBlurNode(b_node);
327                         break;
328                 case CMP_NODE_ZCOMBINE:
329                         node = new ZCombineNode(b_node);
330                         break;
331                 case CMP_NODE_TONEMAP:
332                         node = new TonemapNode(b_node);
333                         break;
334                 case CMP_NODE_SWITCH:
335                         node = new SwitchNode(b_node);
336                         break;
337                 case CMP_NODE_SWITCH_VIEW:
338                         node = new SwitchViewNode(b_node);
339                         break;
340                 case CMP_NODE_GLARE:
341                         node = new GlareNode(b_node);
342                         break;
343                 case CMP_NODE_MOVIECLIP:
344                         node = new MovieClipNode(b_node);
345                         break;
346                 case CMP_NODE_COLOR_SPILL:
347                         node = new ColorSpillNode(b_node);
348                         break;
349                 case CMP_NODE_OUTPUT_FILE:
350                         node = new OutputFileNode(b_node);
351                         break;
352                 case CMP_NODE_MAP_VALUE:
353                         node = new MapValueNode(b_node);
354                         break;
355                 case CMP_NODE_MAP_RANGE:
356                         node = new MapRangeNode(b_node);
357                         break;
358                 case CMP_NODE_TRANSFORM:
359                         node = new TransformNode(b_node);
360                         break;
361                 case CMP_NODE_STABILIZE2D:
362                         node = new Stabilize2dNode(b_node);
363                         break;
364                 case CMP_NODE_BILATERALBLUR:
365                         node = new BilateralBlurNode(b_node);
366                         break;
367                 case CMP_NODE_VECBLUR:
368                         node = new VectorBlurNode(b_node);
369                         break;
370                 case CMP_NODE_MOVIEDISTORTION:
371                         node = new MovieDistortionNode(b_node);
372                         break;
373                 case CMP_NODE_VIEW_LEVELS:
374                         node = new ViewLevelsNode(b_node);
375                         break;
376                 case CMP_NODE_DEFOCUS:
377                         node = new DefocusNode(b_node);
378                         break;
379                 case CMP_NODE_DOUBLEEDGEMASK:
380                         node = new DoubleEdgeMaskNode(b_node);
381                         break;
382                 case CMP_NODE_CROP:
383                         node = new CropNode(b_node);
384                         break;
385                 case CMP_NODE_MASK:
386                         node = new MaskNode(b_node);
387                         break;
388                 case CMP_NODE_KEYINGSCREEN:
389                         node = new KeyingScreenNode(b_node);
390                         break;
391                 case CMP_NODE_KEYING:
392                         node = new KeyingNode(b_node);
393                         break;
394                 case CMP_NODE_TRACKPOS:
395                         node = new TrackPositionNode(b_node);
396                         break;
397                 /* not implemented yet */
398                 case CMP_NODE_PIXELATE:
399                         node = new PixelateNode(b_node);
400                         break;
401                 case CMP_NODE_PLANETRACKDEFORM:
402                         node = new PlaneTrackDeformNode(b_node);
403                         break;
404                 case CMP_NODE_CORNERPIN:
405                         node = new CornerPinNode(b_node);
406                         break;
407                 case CMP_NODE_SUNBEAMS:
408                         node = new SunBeamsNode(b_node);
409                         break;
410                 case CMP_NODE_CRYPTOMATTE:
411                         node = new CryptomatteNode(b_node);
412                         break;
413         }
414         return node;
415 }
416
417 NodeOperation *Converter::convertDataType(NodeOperationOutput *from, NodeOperationInput *to)
418 {
419         DataType fromDatatype = from->getDataType();
420         DataType toDatatype = to->getDataType();
421
422         if (fromDatatype == COM_DT_VALUE && toDatatype == COM_DT_COLOR) {
423                 return new ConvertValueToColorOperation();
424         }
425         else if (fromDatatype == COM_DT_VALUE && toDatatype == COM_DT_VECTOR) {
426                 return new ConvertValueToVectorOperation();
427         }
428         else if (fromDatatype == COM_DT_COLOR && toDatatype == COM_DT_VALUE) {
429                 return new ConvertColorToValueOperation();
430         }
431         else if (fromDatatype == COM_DT_COLOR && toDatatype == COM_DT_VECTOR) {
432                 return new ConvertColorToVectorOperation();
433         }
434         else if (fromDatatype == COM_DT_VECTOR && toDatatype == COM_DT_VALUE) {
435                 return new ConvertVectorToValueOperation();
436         }
437         else if (fromDatatype == COM_DT_VECTOR && toDatatype == COM_DT_COLOR) {
438                 return new ConvertVectorToColorOperation();
439         }
440
441         return NULL;
442 }
443
444 void Converter::convertResolution(NodeOperationBuilder &builder, NodeOperationOutput *fromSocket, NodeOperationInput *toSocket)
445 {
446         InputResizeMode mode = toSocket->getResizeMode();
447
448         NodeOperation *toOperation = &toSocket->getOperation();
449         const float toWidth = toOperation->getWidth();
450         const float toHeight = toOperation->getHeight();
451         NodeOperation *fromOperation = &fromSocket->getOperation();
452         const float fromWidth = fromOperation->getWidth();
453         const float fromHeight = fromOperation->getHeight();
454         bool doCenter = false;
455         bool doScale = false;
456         float addX = (toWidth - fromWidth) / 2.0f;
457         float addY = (toHeight - fromHeight) / 2.0f;
458         float scaleX = 0;
459         float scaleY = 0;
460
461         switch (mode) {
462                 case COM_SC_NO_RESIZE:
463                         break;
464                 case COM_SC_CENTER:
465                         doCenter = true;
466                         break;
467                 case COM_SC_FIT_WIDTH:
468                         doCenter = true;
469                         doScale = true;
470                         scaleX = scaleY = toWidth / fromWidth;
471                         break;
472                 case COM_SC_FIT_HEIGHT:
473                         doCenter = true;
474                         doScale = true;
475                         scaleX = scaleY = toHeight / fromHeight;
476                         break;
477                 case COM_SC_FIT:
478                         doCenter = true;
479                         doScale = true;
480                         scaleX = toWidth / fromWidth;
481                         scaleY = toHeight / fromHeight;
482                         if (scaleX < scaleY) {
483                                 scaleX = scaleY;
484                         }
485                         else {
486                                 scaleY = scaleX;
487                         }
488                         break;
489                 case COM_SC_STRETCH:
490                         doCenter = true;
491                         doScale = true;
492                         scaleX = toWidth / fromWidth;
493                         scaleY = toHeight / fromHeight;
494                         break;
495
496         }
497
498         if (doCenter) {
499                 NodeOperation *first = NULL;
500                 ScaleOperation *scaleOperation = NULL;
501                 if (doScale) {
502                         scaleOperation = new ScaleOperation();
503                         scaleOperation->getInputSocket(1)->setResizeMode(COM_SC_NO_RESIZE);
504                         scaleOperation->getInputSocket(2)->setResizeMode(COM_SC_NO_RESIZE);
505                         first = scaleOperation;
506                         SetValueOperation *sxop = new SetValueOperation();
507                         sxop->setValue(scaleX);
508                         builder.addLink(sxop->getOutputSocket(), scaleOperation->getInputSocket(1));
509                         SetValueOperation *syop = new SetValueOperation();
510                         syop->setValue(scaleY);
511                         builder.addLink(syop->getOutputSocket(), scaleOperation->getInputSocket(2));
512                         builder.addOperation(sxop);
513                         builder.addOperation(syop);
514
515                         unsigned int resolution[2] = {fromOperation->getWidth(),
516                                                       fromOperation->getHeight()};
517                         scaleOperation->setResolution(resolution);
518                         sxop->setResolution(resolution);
519                         syop->setResolution(resolution);
520                         builder.addOperation(scaleOperation);
521                 }
522
523                 TranslateOperation *translateOperation = new TranslateOperation();
524                 translateOperation->getInputSocket(1)->setResizeMode(COM_SC_NO_RESIZE);
525                 translateOperation->getInputSocket(2)->setResizeMode(COM_SC_NO_RESIZE);
526                 if (!first) first = translateOperation;
527                 SetValueOperation *xop = new SetValueOperation();
528                 xop->setValue(addX);
529                 builder.addLink(xop->getOutputSocket(), translateOperation->getInputSocket(1));
530                 SetValueOperation *yop = new SetValueOperation();
531                 yop->setValue(addY);
532                 builder.addLink(yop->getOutputSocket(), translateOperation->getInputSocket(2));
533                 builder.addOperation(xop);
534                 builder.addOperation(yop);
535
536                 unsigned int resolution[2] = {toOperation->getWidth(),
537                                               toOperation->getHeight()};
538                 translateOperation->setResolution(resolution);
539                 xop->setResolution(resolution);
540                 yop->setResolution(resolution);
541                 builder.addOperation(translateOperation);
542
543                 if (doScale) {
544                         translateOperation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
545                         builder.addLink(scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0));
546                 }
547
548                 /* remove previous link and replace */
549                 builder.removeInputLink(toSocket);
550                 first->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
551                 toSocket->setResizeMode(COM_SC_NO_RESIZE);
552                 builder.addLink(fromSocket, first->getInputSocket(0));
553                 builder.addLink(translateOperation->getOutputSocket(), toSocket);
554         }
555 }