Cleanup: trailing whitespace (comment blocks)
[blender.git] / source / blender / compositor / nodes / COM_ViewerNode.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 "COM_ViewerNode.h"
24 #include "BKE_global.h"
25 #include "BKE_image.h"
26 #include "BLI_listbase.h"
27 #include "BKE_scene.h"
28
29 #include "COM_ViewerOperation.h"
30 #include "COM_ExecutionSystem.h"
31
32 ViewerNode::ViewerNode(bNode *editorNode) : Node(editorNode)
33 {
34         /* pass */
35 }
36
37 void ViewerNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
38 {
39         bNode *editorNode = this->getbNode();
40         bool do_output = (editorNode->flag & NODE_DO_OUTPUT_RECALC || context.isRendering()) && (editorNode->flag & NODE_DO_OUTPUT);
41         bool ignore_alpha = (editorNode->custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA) != 0;
42
43         NodeInput *imageSocket = this->getInputSocket(0);
44         NodeInput *alphaSocket = this->getInputSocket(1);
45         NodeInput *depthSocket = this->getInputSocket(2);
46         Image *image = (Image *)this->getbNode()->id;
47         ImageUser *imageUser = (ImageUser *) this->getbNode()->storage;
48         ViewerOperation *viewerOperation = new ViewerOperation();
49         viewerOperation->setbNodeTree(context.getbNodeTree());
50         viewerOperation->setImage(image);
51         viewerOperation->setImageUser(imageUser);
52         viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
53         viewerOperation->setCenterX(editorNode->custom3);
54         viewerOperation->setCenterY(editorNode->custom4);
55         /* alpha socket gives either 1 or a custom alpha value if "use alpha" is enabled */
56         viewerOperation->setUseAlphaInput(ignore_alpha || alphaSocket->isLinked());
57         viewerOperation->setRenderData(context.getRenderData());
58         viewerOperation->setViewName(context.getViewName());
59
60         viewerOperation->setViewSettings(context.getViewSettings());
61         viewerOperation->setDisplaySettings(context.getDisplaySettings());
62
63         viewerOperation->setResolutionInputSocketIndex(0);
64         if (!imageSocket->isLinked()) {
65                 if (alphaSocket->isLinked()) {
66                         viewerOperation->setResolutionInputSocketIndex(1);
67                 }
68         }
69
70         converter.addOperation(viewerOperation);
71         converter.mapInputSocket(imageSocket, viewerOperation->getInputSocket(0));
72         /* only use alpha link if "use alpha" is enabled */
73         if (ignore_alpha)
74                 converter.addInputValue(viewerOperation->getInputSocket(1), 1.0f);
75         else
76                 converter.mapInputSocket(alphaSocket, viewerOperation->getInputSocket(1));
77         converter.mapInputSocket(depthSocket, viewerOperation->getInputSocket(2));
78
79         converter.addNodeInputPreview(imageSocket);
80
81         if (do_output)
82                 converter.registerViewer(viewerOperation);
83 }