Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[blender.git] / source / blender / compositor / nodes / COM_ChromaMatteNode.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_ChromaMatteNode.h"
23 #include "BKE_node.h"
24 #include "COM_ChromaMatteOperation.h"
25 #include "COM_ConvertRGBToYCCOperation.h"
26 #include "COM_SetAlphaOperation.h"
27
28 ChromaMatteNode::ChromaMatteNode(bNode *editorNode) : Node(editorNode)
29 {
30         /* pass */
31 }
32
33 void ChromaMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
34 {
35         InputSocket *inputSocketImage = this->getInputSocket(0);
36         InputSocket *inputSocketKey = this->getInputSocket(1);
37         OutputSocket *outputSocketImage = this->getOutputSocket(0);
38         OutputSocket *outputSocketMatte = this->getOutputSocket(1);
39
40         ConvertRGBToYCCOperation *operationRGBToYCC_Image = new ConvertRGBToYCCOperation();
41         ConvertRGBToYCCOperation *operationRGBToYCC_Key = new ConvertRGBToYCCOperation();
42         operationRGBToYCC_Image->setMode(0); /* BLI_YCC_ITU_BT601 */
43         operationRGBToYCC_Key->setMode(0); /* BLI_YCC_ITU_BT601 */
44
45         ChromaMatteOperation *operation = new ChromaMatteOperation();
46         bNode *editorsnode = getbNode();
47         operation->setSettings((NodeChroma *)editorsnode->storage);
48
49         inputSocketImage->relinkConnections(operationRGBToYCC_Image->getInputSocket(0), 0, graph);
50         inputSocketKey->relinkConnections(operationRGBToYCC_Key->getInputSocket(0), 0, graph);
51
52         addLink(graph, operationRGBToYCC_Image->getOutputSocket(), operation->getInputSocket(0));
53         addLink(graph, operationRGBToYCC_Key->getOutputSocket(), operation->getInputSocket(1));
54
55         graph->addOperation(operationRGBToYCC_Image);
56         graph->addOperation(operationRGBToYCC_Key);
57         graph->addOperation(operation);
58
59         if (outputSocketMatte->isConnected()) {
60                 outputSocketMatte->relinkConnections(operation->getOutputSocket());
61         }
62
63         SetAlphaOperation *operationAlpha = new SetAlphaOperation();
64         addLink(graph, operationRGBToYCC_Image->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
65         addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));
66
67         graph->addOperation(operationAlpha);
68         addPreviewOperation(graph, context, operationAlpha->getOutputSocket());
69
70         if (outputSocketImage->isConnected()) {
71                 outputSocketImage->relinkConnections(operationAlpha->getOutputSocket());
72         }
73 }