Blender  V2.93
COM_ViewerNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_ViewerNode.h"
20 #include "BKE_global.h"
21 #include "BKE_image.h"
22 #include "BKE_scene.h"
23 #include "BLI_listbase.h"
24 
25 #include "COM_ExecutionSystem.h"
26 #include "COM_ViewerOperation.h"
27 
28 namespace blender::compositor {
29 
30 ViewerNode::ViewerNode(bNode *editorNode) : Node(editorNode)
31 {
32  /* pass */
33 }
34 
36  const CompositorContext &context) const
37 {
38  bNode *editorNode = this->getbNode();
39  bool do_output = (editorNode->flag & NODE_DO_OUTPUT_RECALC || context.isRendering()) &&
40  (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((ChunkOrdering)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  }
76  else {
77  converter.mapInputSocket(alphaSocket, viewerOperation->getInputSocket(1));
78  }
79  converter.mapInputSocket(depthSocket, viewerOperation->getInputSocket(2));
80 
81  converter.addNodeInputPreview(imageSocket);
82 
83  if (do_output) {
84  converter.registerViewer(viewerOperation);
85  }
86 }
87 
88 } // namespace blender::compositor
#define NODE_DO_OUTPUT
#define NODE_DO_OUTPUT_RECALC
#define CMP_NODE_OUTPUT_IGNORE_ALPHA
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addNodeInputPreview(NodeInput *input)
void addInputValue(NodeOperationInput *input, float value)
void addOperation(NodeOperation *operation)
void registerViewer(ViewerOperation *viewer)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperationInput * getInputSocket(unsigned int index)
void setResolutionInputSocketIndex(unsigned int index)
set the index of the input socket that will determine the resolution of this operation
void setbNodeTree(const bNodeTree *tree)
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void setViewSettings(const ColorManagedViewSettings *viewSettings)
void setChunkOrder(ChunkOrdering tileOrder)
void setRenderData(const RenderData *rd)
void setDisplaySettings(const ColorManagedDisplaySettings *displaySettings)
void setImageUser(ImageUser *imageUser)
void setViewName(const char *viewName)
ChunkOrdering
The order of chunks to be scheduled.
Definition: COM_defines.h:65
short custom1
struct ID * id
float custom4
void * storage
short custom2
float custom3