Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_OutputFileNode.cc « nodes « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50989f73986d0b32891d5412228c26ae8f46e320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2011 Blender Foundation. */

#include "COM_OutputFileNode.h"

namespace blender::compositor {

OutputFileNode::OutputFileNode(bNode *editor_node) : Node(editor_node)
{
  /* pass */
}

void OutputFileNode::add_input_sockets(OutputOpenExrMultiLayerOperation &operation) const
{
  for (NodeInput *input : inputs_) {
    NodeImageMultiFileSocket *sockdata =
        (NodeImageMultiFileSocket *)input->get_bnode_socket()->storage;
    /* NOTE: layer becomes an empty placeholder if the input is not linked. */
    operation.add_layer(sockdata->layer, input->get_data_type(), input->is_linked());
  }
}

void OutputFileNode::map_input_sockets(NodeConverter &converter,
                                       OutputOpenExrMultiLayerOperation &operation) const
{
  bool preview_added = false;
  int index = 0;
  for (NodeInput *input : inputs_) {
    converter.map_input_socket(input, operation.get_input_socket(index++));

    if (!preview_added) {
      converter.add_node_input_preview(input);
      preview_added = true;
    }
  }
}

void OutputFileNode::add_preview_to_first_linked_input(NodeConverter &converter) const
{
  if (get_input_sockets().is_empty()) {
    return;
  }

  NodeInput *first_socket = this->get_input_socket(0);
  if (first_socket->is_linked()) {
    converter.add_node_input_preview(first_socket);
  }
}

void OutputFileNode::convert_to_operations(NodeConverter &converter,
                                           const CompositorContext &context) const
{
  const NodeImageMultiFile *storage = (const NodeImageMultiFile *)this->get_bnode()->storage;
  const bool is_multiview = (context.get_render_data()->scemode & R_MULTIVIEW) != 0;

  add_preview_to_first_linked_input(converter);

  if (!context.is_rendering()) {
    /* only output files when rendering a sequence -
     * otherwise, it overwrites the output files just
     * scrubbing through the timeline when the compositor updates.
     */
    return;
  }

  if (storage->format.imtype == R_IMF_IMTYPE_MULTILAYER) {
    const bool use_half_float = (storage->format.depth == R_IMF_CHAN_DEPTH_16);
    /* Single output operation for the multi-layer file. */
    OutputOpenExrMultiLayerOperation *output_operation;

    if (is_multiview && storage->format.views_format == R_IMF_VIEWS_MULTIVIEW) {
      output_operation = new OutputOpenExrMultiLayerMultiViewOperation(context.get_scene(),
                                                                       context.get_render_data(),
                                                                       context.get_bnodetree(),
                                                                       storage->base_path,
                                                                       storage->format.exr_codec,
                                                                       use_half_float,
                                                                       context.get_view_name());
    }
    else {
      output_operation = new OutputOpenExrMultiLayerOperation(context.get_scene(),
                                                              context.get_render_data(),
                                                              context.get_bnodetree(),
                                                              storage->base_path,
                                                              storage->format.exr_codec,
                                                              use_half_float,
                                                              context.get_view_name());
    }
    converter.add_operation(output_operation);

    /* First add all inputs. Inputs are stored in a Vector and can be moved to a different
     * memory address during this time. */
    add_input_sockets(*output_operation);
    /* After adding the sockets the memory addresses will stick. */
    map_input_sockets(converter, *output_operation);
  }
  else { /* single layer format */
    for (NodeInput *input : inputs_) {
      if (input->is_linked()) {
        NodeImageMultiFileSocket *sockdata =
            (NodeImageMultiFileSocket *)input->get_bnode_socket()->storage;
        const ImageFormatData *format = (sockdata->use_node_format ? &storage->format :
                                                                     &sockdata->format);
        char path[FILE_MAX];

        /* combine file path for the input */
        BLI_path_join(path, FILE_MAX, storage->base_path, sockdata->path);

        NodeOperation *output_operation = nullptr;

        if (is_multiview && format->views_format == R_IMF_VIEWS_MULTIVIEW) {
          output_operation = new OutputOpenExrSingleLayerMultiViewOperation(
              context.get_scene(),
              context.get_render_data(),
              context.get_bnodetree(),
              input->get_data_type(),
              format,
              path,
              context.get_view_name(),
              sockdata->save_as_render);
        }
        else if ((!is_multiview) || (format->views_format == R_IMF_VIEWS_INDIVIDUAL)) {
          output_operation = new OutputSingleLayerOperation(context.get_scene(),
                                                            context.get_render_data(),
                                                            context.get_bnodetree(),
                                                            input->get_data_type(),
                                                            format,
                                                            path,
                                                            context.get_view_name(),
                                                            sockdata->save_as_render);
        }
        else { /* R_IMF_VIEWS_STEREO_3D */
          output_operation = new OutputStereoOperation(context.get_scene(),
                                                       context.get_render_data(),
                                                       context.get_bnodetree(),
                                                       input->get_data_type(),
                                                       format,
                                                       path,
                                                       sockdata->layer,
                                                       context.get_view_name(),
                                                       sockdata->save_as_render);
        }

        converter.add_operation(output_operation);
        converter.map_input_socket(input, output_operation->get_input_socket(0));
      }
    }
  }
}

}  // namespace blender::compositor