Cleanup: comment line length (editors)
[blender.git] / source / blender / compositor / nodes / COM_DistanceMatteNode.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  *      Dalai Felinto
20  */
21
22 #include "COM_DistanceMatteNode.h"
23 #include "BKE_node.h"
24 #include "COM_DistanceRGBMatteOperation.h"
25 #include "COM_DistanceYCCMatteOperation.h"
26 #include "COM_SetAlphaOperation.h"
27 #include "COM_ConvertOperation.h"
28
29 DistanceMatteNode::DistanceMatteNode(bNode *editorNode) : Node(editorNode)
30 {
31         /* pass */
32 }
33
34 void DistanceMatteNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
35 {
36         bNode *editorsnode = getbNode();
37         NodeChroma *storage = (NodeChroma *)editorsnode->storage;
38
39         NodeInput *inputSocketImage = this->getInputSocket(0);
40         NodeInput *inputSocketKey = this->getInputSocket(1);
41         NodeOutput *outputSocketImage = this->getOutputSocket(0);
42         NodeOutput *outputSocketMatte = this->getOutputSocket(1);
43
44         SetAlphaOperation *operationAlpha = new SetAlphaOperation();
45         converter.addOperation(operationAlpha);
46
47         /* work in RGB color space */
48         NodeOperation *operation;
49         if (storage->channel == 1) {
50                 DistanceRGBMatteOperation *matte = new DistanceRGBMatteOperation();
51                 matte->setSettings(storage);
52                 converter.addOperation(matte);
53
54                 converter.mapInputSocket(inputSocketImage, matte->getInputSocket(0));
55                 converter.mapInputSocket(inputSocketImage, operationAlpha->getInputSocket(0));
56
57                 converter.mapInputSocket(inputSocketKey, matte->getInputSocket(1));
58
59                 operation = matte;
60         }
61         /* work in YCbCr color space */
62         else {
63                 DistanceYCCMatteOperation *matte = new DistanceYCCMatteOperation();
64                 matte->setSettings(storage);
65                 converter.addOperation(matte);
66
67                 ConvertRGBToYCCOperation *operationYCCImage = new ConvertRGBToYCCOperation();
68                 ConvertRGBToYCCOperation *operationYCCMatte = new ConvertRGBToYCCOperation();
69                 operationYCCImage->setMode(BLI_YCC_ITU_BT709);
70                 operationYCCMatte->setMode(BLI_YCC_ITU_BT709);
71                 converter.addOperation(operationYCCImage);
72                 converter.addOperation(operationYCCMatte);
73
74                 converter.mapInputSocket(inputSocketImage, operationYCCImage->getInputSocket(0));
75                 converter.addLink(operationYCCImage->getOutputSocket(), matte->getInputSocket(0));
76                 converter.addLink(operationYCCImage->getOutputSocket(), operationAlpha->getInputSocket(0));
77
78                 converter.mapInputSocket(inputSocketKey, operationYCCMatte->getInputSocket(0));
79                 converter.addLink(operationYCCMatte->getOutputSocket(), matte->getInputSocket(1));
80
81                 operation = matte;
82         }
83
84         converter.mapOutputSocket(outputSocketMatte, operation->getOutputSocket(0));
85         converter.addLink(operation->getOutputSocket(), operationAlpha->getInputSocket(1));
86
87         if (storage->channel != 1) {
88                 ConvertYCCToRGBOperation *inv_convert = new ConvertYCCToRGBOperation();
89                 inv_convert->setMode(BLI_YCC_ITU_BT709);
90
91                 converter.addOperation(inv_convert);
92                 converter.addLink(operationAlpha->getOutputSocket(0), inv_convert->getInputSocket(0));
93                 converter.mapOutputSocket(outputSocketImage, inv_convert->getOutputSocket());
94                 converter.addPreview(inv_convert->getOutputSocket());
95         }
96         else {
97                 converter.mapOutputSocket(outputSocketImage, operationAlpha->getOutputSocket());
98                 converter.addPreview(operationAlpha->getOutputSocket());
99         }
100 }