Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[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_ConvertRGBToYCCOperation.h"
28
29 DistanceMatteNode::DistanceMatteNode(bNode *editorNode) : Node(editorNode)
30 {
31         /* pass */
32 }
33
34 void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
35 {
36         InputSocket *inputSocketImage = this->getInputSocket(0);
37         InputSocket *inputSocketKey = this->getInputSocket(1);
38         OutputSocket *outputSocketImage = this->getOutputSocket(0);
39         OutputSocket *outputSocketMatte = this->getOutputSocket(1);
40
41         NodeOperation *operation;
42         bNode *editorsnode = getbNode();
43         NodeChroma *storage = (NodeChroma *)editorsnode->storage;
44
45         /* work in RGB color space */
46         if (storage->channel == 1) {
47                 operation = new DistanceRGBMatteOperation();
48                 ((DistanceRGBMatteOperation *) operation)->setSettings(storage);
49
50                 inputSocketImage->relinkConnections(operation->getInputSocket(0), 0, graph);
51                 inputSocketKey->relinkConnections(operation->getInputSocket(1), 1, graph);
52         }
53         /* work in YCbCr color space */
54         else {
55                 operation = new DistanceYCCMatteOperation();
56                 ((DistanceYCCMatteOperation *) operation)->setSettings(storage);
57
58                 ConvertRGBToYCCOperation *operationYCCImage = new ConvertRGBToYCCOperation();
59                 inputSocketImage->relinkConnections(operationYCCImage->getInputSocket(0), 0, graph);
60                 addLink(graph, operationYCCImage->getOutputSocket(), operation->getInputSocket(0));
61                 graph->addOperation(operationYCCImage);
62
63                 ConvertRGBToYCCOperation *operationYCCMatte = new ConvertRGBToYCCOperation();
64                 inputSocketKey->relinkConnections(operationYCCMatte->getInputSocket(0), 1, graph);
65                 addLink(graph, operationYCCMatte->getOutputSocket(), operation->getInputSocket(1));
66                 graph->addOperation(operationYCCMatte);
67         }
68
69         if (outputSocketMatte->isConnected()) {
70                 outputSocketMatte->relinkConnections(operation->getOutputSocket());
71         }
72
73         graph->addOperation(operation);
74
75         SetAlphaOperation *operationAlpha = new SetAlphaOperation();
76         addLink(graph, operation->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
77         addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));
78
79         graph->addOperation(operationAlpha);
80         addPreviewOperation(graph, context, operationAlpha->getOutputSocket());
81
82         if (outputSocketImage->isConnected()) {
83                 outputSocketImage->relinkConnections(operationAlpha->getOutputSocket());
84         }
85 }