Blender  V2.93
COM_OutputFileNode.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_OutputFileNode.h"
20 #include "COM_ExecutionSystem.h"
22 
23 #include "BKE_scene.h"
24 
25 #include "BLI_path_util.h"
26 
27 namespace blender::compositor {
28 
29 OutputFileNode::OutputFileNode(bNode *editorNode) : Node(editorNode)
30 {
31  /* pass */
32 }
33 
34 void OutputFileNode::add_input_sockets(OutputOpenExrMultiLayerOperation &operation) const
35 {
36  for (NodeInput *input : inputs) {
37  NodeImageMultiFileSocket *sockdata =
38  (NodeImageMultiFileSocket *)input->getbNodeSocket()->storage;
39  /* note: layer becomes an empty placeholder if the input is not linked */
40  operation.add_layer(sockdata->layer, input->getDataType(), input->isLinked());
41  }
42 }
43 
44 void OutputFileNode::map_input_sockets(NodeConverter &converter,
45  OutputOpenExrMultiLayerOperation &operation) const
46 {
47  bool previewAdded = false;
48  int index = 0;
49  for (NodeInput *input : inputs) {
50  converter.mapInputSocket(input, operation.getInputSocket(index++));
51 
52  if (!previewAdded) {
53  converter.addNodeInputPreview(input);
54  previewAdded = true;
55  }
56  }
57 }
58 
60  const CompositorContext &context) const
61 {
63  const bool is_multiview = (context.getRenderData()->scemode & R_MULTIVIEW) != 0;
64 
65  if (!context.isRendering()) {
66  /* only output files when rendering a sequence -
67  * otherwise, it overwrites the output files just
68  * scrubbing through the timeline when the compositor updates.
69  */
70  return;
71  }
72 
73  if (storage->format.imtype == R_IMF_IMTYPE_MULTILAYER) {
74  const bool use_half_float = (storage->format.depth == R_IMF_CHAN_DEPTH_16);
75  /* single output operation for the multilayer file */
76  OutputOpenExrMultiLayerOperation *outputOperation;
77 
78  if (is_multiview && storage->format.views_format == R_IMF_VIEWS_MULTIVIEW) {
79  outputOperation = new OutputOpenExrMultiLayerMultiViewOperation(context.getScene(),
80  context.getRenderData(),
81  context.getbNodeTree(),
82  storage->base_path,
83  storage->format.exr_codec,
84  use_half_float,
85  context.getViewName());
86  }
87  else {
88  outputOperation = new OutputOpenExrMultiLayerOperation(context.getScene(),
89  context.getRenderData(),
90  context.getbNodeTree(),
91  storage->base_path,
92  storage->format.exr_codec,
93  use_half_float,
94  context.getViewName());
95  }
96  converter.addOperation(outputOperation);
97 
98  /* First add all inputs. Inputs are stored in a Vector and can be moved to a different
99  * memory address during this time.*/
100  add_input_sockets(*outputOperation);
101  /* After adding the sockets the memory addresses will stick. */
102  map_input_sockets(converter, *outputOperation);
103  }
104  else { /* single layer format */
105  bool previewAdded = false;
106  for (NodeInput *input : inputs) {
107  if (input->isLinked()) {
108  NodeImageMultiFileSocket *sockdata =
109  (NodeImageMultiFileSocket *)input->getbNodeSocket()->storage;
110  ImageFormatData *format = (sockdata->use_node_format ? &storage->format :
111  &sockdata->format);
112  char path[FILE_MAX];
113 
114  /* combine file path for the input */
115  BLI_join_dirfile(path, FILE_MAX, storage->base_path, sockdata->path);
116 
117  NodeOperation *outputOperation = nullptr;
118 
119  if (is_multiview && format->views_format == R_IMF_VIEWS_MULTIVIEW) {
120  outputOperation = new OutputOpenExrSingleLayerMultiViewOperation(
121  context.getRenderData(),
122  context.getbNodeTree(),
123  input->getDataType(),
124  format,
125  path,
126  context.getViewSettings(),
127  context.getDisplaySettings(),
128  context.getViewName(),
129  sockdata->save_as_render);
130  }
131  else if ((!is_multiview) || (format->views_format == R_IMF_VIEWS_INDIVIDUAL)) {
132  outputOperation = new OutputSingleLayerOperation(context.getRenderData(),
133  context.getbNodeTree(),
134  input->getDataType(),
135  format,
136  path,
137  context.getViewSettings(),
138  context.getDisplaySettings(),
139  context.getViewName(),
140  sockdata->save_as_render);
141  }
142  else { /* R_IMF_VIEWS_STEREO_3D */
143  outputOperation = new OutputStereoOperation(context.getRenderData(),
144  context.getbNodeTree(),
145  input->getDataType(),
146  format,
147  path,
148  sockdata->layer,
149  context.getViewSettings(),
150  context.getDisplaySettings(),
151  context.getViewName(),
152  sockdata->save_as_render);
153  }
154 
155  converter.addOperation(outputOperation);
156  converter.mapInputSocket(input, outputOperation->getInputSocket(0));
157 
158  if (!previewAdded) {
159  converter.addNodeInputPreview(input);
160  previewAdded = true;
161  }
162  }
163  }
164  }
165 }
166 
167 } // namespace blender::compositor
#define FILE_MAX
void BLI_join_dirfile(char *__restrict dst, const size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1737
#define R_MULTIVIEW
#define R_IMF_IMTYPE_MULTILAYER
@ R_IMF_CHAN_DEPTH_16
@ R_IMF_VIEWS_MULTIVIEW
@ R_IMF_VIEWS_INDIVIDUAL
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addNodeInputPreview(NodeInput *input)
void addOperation(NodeOperation *operation)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperation contains calculation logic.
NodeOperationInput * getInputSocket(unsigned int index)
Vector< NodeInput * > inputs
the list of actual input-sockets
Definition: COM_Node.h:68
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void add_layer(const char *name, DataType datatype, bool use_layer)
format
Definition: logImageCore.h:47
ImageFormatData format
void * storage