Blender V5.3
node_composite_file_output.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <cstring>
6
7#include "BLI_assert.hh"
8#include "BLI_cpp_type.hh"
10#include "BLI_index_range.hh"
11#include "BLI_listbase.hh"
12#include "BLI_path_utils.hh"
13#include "BLI_string.hh"
14
15#include "BLT_translation.hh"
16
17#include "MEM_guardedalloc.h"
18
19#include "DNA_node_types.h"
20#include "DNA_scene_types.h"
21
22#include "BLO_read_write.hh"
23
24#include "BKE_context.hh"
25#include "BKE_cryptomatte.hh"
26#include "BKE_image.hh"
27#include "BKE_image_format.hh"
28#include "BKE_main.hh"
29#include "BKE_scene.hh"
30
31#include "RNA_access.hh"
32
33#include "UI_interface.hh"
35#include "UI_resources.hh"
36
37#include "WM_api.hh"
38
39#include "IMB_imbuf.hh"
40
41#include "GPU_state.hh"
42#include "GPU_texture.hh"
43
44#include "COM_node_operation.hh"
45#include "COM_utilities.hh"
46
53
55
57
59
61{
62 b.use_custom_socket_order();
63 b.allow_any_socket_order();
64
65 b.add_default_layout();
66
67 const bNodeTree *node_tree = b.tree_or_null();
68 const bNode *node = b.node_or_null();
69 if (!node_tree || !node) {
70 return;
71 }
72
73 const NodeCompositorFileOutput &storage = node_storage(*node);
74
75 /* Inputs for multi-layer files need to be the same size, while they can be different for
76 * individual file outputs. */
77 const bool is_multi_layer = storage.format.imtype == R_IMF_IMTYPE_MULTILAYER;
78 const CompositorInputRealizationMode realization_mode =
81
82 for (const int i : IndexRange(storage.items_count)) {
83 const NodeCompositorFileOutputItem &item = storage.items[i];
84 const eNodeSocketDatatype socket_type = item.socket_type;
85 const std::string identifier = FileOutputItemsAccessor::socket_identifier_for_item(item);
86 BaseSocketDeclarationBuilder *declaration = nullptr;
87 if (socket_type == SOCK_VECTOR) {
88 declaration = &b.add_input<decl::Vector>(UString(item.name), UString(identifier))
89 .dimensions(item.vector_socket_dimensions);
90 }
91 else {
92 declaration = &b.add_input(socket_type, UString(item.name), UString(identifier));
93 }
94 declaration->structure_type(StructureType::Dynamic)
95 .compositor_realization_mode(realization_mode)
96 .socket_name_ptr(&node_tree->id, *FileOutputItemsAccessor::item_srna, &item, "name");
97 }
98
99 b.add_input<decl::Extend>(""_ustr, "__extend__"_ustr)
100 .custom_draw(socket_items::ui::draw_extend_socket_fn<FileOutputItemsAccessor>());
101}
102
103static void node_init(bNodeTree *node_tree, bNode *node)
104{
105 NodeCompositorFileOutput *data = MEM_new<NodeCompositorFileOutput>(__func__);
106 node->storage = data;
107 data->save_as_render = true;
108 data->use_file_extension = true;
109 data->file_name = BLI_strdup("{blend_name}");
110
111 BKE_image_format_init(&data->format);
114}
115
116static void node_init_api(const bContext *C, PointerRNA *node_ptr)
117{
118 bNode *node = node_ptr->data_as<bNode>();
119 NodeCompositorFileOutput &data = node_storage(*node);
120 Scene *scene = CTX_data_scene(C);
121 const RenderData *render_data = &scene->r;
122 STRNCPY(data.directory, render_data->pic);
123}
124
126{
128 NodeCompositorFileOutput &data = node_storage(*node);
130 MEM_SAFE_DELETE(data.file_name);
131 MEM_delete(&data);
132}
133
134static void node_copy_storage(bNodeTree * /*destination_node_tree*/,
135 bNode *destination_node,
136 const bNode *source_node)
137{
138 const NodeCompositorFileOutput &source_storage = node_storage(*source_node);
139 NodeCompositorFileOutput *destination_storage = MEM_new<NodeCompositorFileOutput>(
140 __func__, dna::shallow_copy(source_storage));
141 destination_storage->file_name = BLI_strdup_null(source_storage.file_name);
142 BKE_image_format_copy(&destination_storage->format, &source_storage.format);
143 destination_node->storage = destination_storage;
144 socket_items::copy_array<FileOutputItemsAccessor>(*source_node, *destination_node);
145}
146
152
157
158/* Computes the path of the image to be saved based on the given parameters. The given file name
159 * suffix, if not empty, will be added to the file name. If the given view is not empty, its file
160 * suffix will be appended to the name. The frame number, scene, and node are provides for variable
161 * substitution in the path. If there are any errors processing the path, they will be returned. */
163 const StringRefNull file_name,
164 const StringRefNull file_name_suffix,
165 const char *view,
166 const int frame_number,
167 const ImageFormatData &format,
168 const Main &bmain,
169 const Scene &scene,
170 const bNode &node,
171 const bool is_animation_render,
172 char *r_image_path)
173{
174 char base_path[FILE_MAX] = "";
175 STRNCPY(base_path, directory.c_str());
176 const std::string full_file_name = file_name + file_name_suffix;
177 BLI_path_append(base_path, FILE_MAX, full_file_name.c_str());
178
179 bke::path_templates::VariableMap template_variables;
181 BKE_add_template_variables_general(template_variables, &node.owner_tree().id, project);
182 });
183 BKE_add_template_variables_for_render_path(template_variables, scene);
184 BKE_add_template_variables_for_node(template_variables, node);
185
186 /* Substitute #### frame variables if not doing an animation render. For animation renders, this
187 * is handled internally by the following function. */
188 if (!is_animation_render) {
189 BLI_path_frame(base_path, FILE_MAX, frame_number, 0);
190 }
191
192 return BKE_image_path_from_imformat(r_image_path,
193 base_path,
195 &template_variables,
196 frame_number,
197 &format,
198 bool(node_storage(node).use_file_extension),
199 is_animation_render,
201}
202
203static void node_draw_buttons(ui::Layout &layout, bContext * /*context*/, PointerRNA *node_pointer)
204{
205 layout.prop(node_pointer, "directory", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
206 layout.prop(node_pointer, "file_name", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
207}
208
209static void format_layout(ui::Layout *layout,
210 bContext *context,
211 PointerRNA *format_pointer,
212 PointerRNA *node_or_item_pointer)
213{
214 ui::Layout &col = layout->column(true);
215 col.use_property_split_set(true);
216 col.use_property_decorate_set(false);
217 col.prop(node_or_item_pointer,
218 "save_as_render",
220 std::nullopt,
221 ICON_NONE);
222 const bool save_as_render = RNA_boolean_get(node_or_item_pointer, "save_as_render");
223 uiTemplateImageSettings(layout, context, format_pointer, save_as_render);
224
225 if (!save_as_render) {
226 ui::Layout *column = &layout->column(true);
227 col.use_property_split_set(true);
228 col.use_property_decorate_set(false);
229
230 PointerRNA linear_settings_ptr = RNA_pointer_get(format_pointer, "linear_colorspace_settings");
231 column->prop(&linear_settings_ptr, "name", UI_ITEM_NONE, IFACE_("Color Space"), ICON_NONE);
232 }
233
234 Scene *scene = CTX_data_scene(context);
235 const bool is_multiview = scene->r.scemode & R_MULTIVIEW;
236 if (is_multiview) {
237 uiTemplateImageFormatViews(layout, format_pointer, nullptr);
238 }
239}
240
241static void output_path_layout(ui::Layout &layout,
242 const StringRefNull directory,
243 const StringRefNull file_name,
244 const StringRefNull file_name_suffix,
245 const char *view,
246 const ImageFormatData &format,
247 const Main &bmain,
248 const Scene &scene,
249 const bNode &node)
250{
251
252 char image_path[FILE_MAX];
253 const Vector<bke::path_templates::Error> path_errors = compute_image_path(directory,
254 file_name,
255 file_name_suffix,
256 view,
257 scene.r.cfra,
258 format,
259 bmain,
260 scene,
261 node,
262 false,
263 image_path);
264
265 if (path_errors.is_empty()) {
266 layout.label(image_path, ICON_FILE_IMAGE);
267 }
268 else {
269 for (const bke::path_templates::Error &error : path_errors) {
270 layout.label(BKE_path_template_error_to_string(error, image_path).c_str(),
271 ICON_STATUS_ERROR);
272 }
273 }
274}
275
276static void output_paths_layout(ui::Layout &layout,
277 bContext *context,
278 const StringRefNull file_name_suffix,
279 const bNode &node,
280 const ImageFormatData &format)
281{
282 const NodeCompositorFileOutput &storage = node_storage(node);
283 const StringRefNull directory = storage.directory;
284 const std::string file_name = storage.file_name ? storage.file_name : "";
285 const Main &main = *CTX_data_main(context);
286 const Scene &scene = *CTX_data_scene(context);
287
288 if (bool(scene.r.scemode & R_MULTIVIEW) && format.views_format == R_IMF_VIEWS_INDIVIDUAL) {
289 for (SceneRenderView &view : scene.r.views) {
290 if (!BKE_scene_multiview_is_render_view_active(&scene.r, &view)) {
291 continue;
292 }
293
295 layout, directory, file_name, file_name_suffix, view.name, format, main, scene, node);
296 }
297 }
298 else {
300 layout, directory, file_name, file_name_suffix, "", format, main, scene, node);
301 }
302}
303
304static void item_layout(ui::Layout &layout,
305 bContext *context,
306 PointerRNA *node_pointer,
307 PointerRNA *item_pointer,
308 const bool is_multi_layer)
309{
310 layout.use_property_split_set(true);
311 layout.use_property_decorate_set(false);
312 layout.prop(item_pointer, "socket_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
313 if (RNA_enum_get(item_pointer, "socket_type") == SOCK_VECTOR) {
314 layout.prop(item_pointer, "vector_socket_dimensions", UI_ITEM_NONE, std::nullopt, ICON_NONE);
315 }
316
317 if (is_multi_layer) {
318 return;
319 }
320
321 layout.prop(
322 item_pointer, "override_node_format", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
323 const bool override_node_format = RNA_boolean_get(item_pointer, "override_node_format");
324
325 PointerRNA node_format_pointer = RNA_pointer_get(node_pointer, "format");
326 PointerRNA item_format_pointer = RNA_pointer_get(item_pointer, "format");
327 PointerRNA *format_pointer = override_node_format ? &item_format_pointer : &node_format_pointer;
328
329 if (override_node_format) {
330 if (ui::Layout *panel = layout.panel(context, "item_format", false, IFACE_("Item Format"))) {
331 format_layout(panel, context, format_pointer, item_pointer);
332 }
333 }
334}
335
337 bContext *context,
338 PointerRNA *node_pointer)
339{
340 node_draw_buttons(layout, context, node_pointer);
341
342 PointerRNA format_pointer = RNA_pointer_get(node_pointer, "format");
343 const bool is_multi_layer = RNA_enum_get(&format_pointer, "file_format") ==
345 layout.prop(&format_pointer, "media_type", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
346 if (ui::Layout *panel = layout.panel(context, "node_format", false, IFACE_("Node Format"))) {
347 format_layout(panel, context, &format_pointer, node_pointer);
348 }
349
350 const char *panel_name = is_multi_layer ? IFACE_("Layers") : IFACE_("Images");
351 if (ui::Layout *panel = layout.panel(context, "file_output_items", false, panel_name)) {
352 bNodeTree &tree = *reinterpret_cast<bNodeTree *>(node_pointer->owner_id);
353 bNode &node = *node_pointer->data_as<bNode>();
354 socket_items::ui::draw_items_list_with_operators<FileOutputItemsAccessor>(
355 context, panel, tree, node);
356 socket_items::ui::draw_active_item_props<FileOutputItemsAccessor>(
357 tree, node, [&](PointerRNA *item_pointer) {
358 item_layout(*panel, context, node_pointer, item_pointer, is_multi_layer);
359 });
360 }
361
362 if (ui::Layout *panel = layout.panel(context, "output_paths", true, IFACE_("Output Paths"))) {
363 const bNode &node = *node_pointer->data_as<bNode>();
364 const ImageFormatData &node_format = *format_pointer.data_as<ImageFormatData>();
365
366 panel->prop(
367 node_pointer, "use_file_extension", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
368
369 if (is_multi_layer) {
370 output_paths_layout(*panel, context, "", node, node_format);
371 }
372 else {
373 const NodeCompositorFileOutput &storage = node_storage(node);
374 for (const int i : IndexRange(storage.items_count)) {
375 const NodeCompositorFileOutputItem &item = storage.items[i];
376 const auto &format = item.override_node_format ? item.format : storage.format;
377 output_paths_layout(*panel, context, item.name, node, format);
378 }
379 }
380 }
381}
382
383static void node_blend_write(const bNodeTree & /*tree*/, const bNode &node, BlendWriter &writer)
384{
385 const NodeCompositorFileOutput &data = node_storage(node);
386 writer.write_string(data.file_name);
387 BKE_image_format_blend_write(&writer, const_cast<ImageFormatData *>(&data.format));
389}
390
391static void node_blend_read(bNodeTree & /*tree*/, bNode &node, BlendDataReader &reader)
392{
393 NodeCompositorFileOutput &data = node_storage(node);
394 BLO_read_string(&reader, &data.file_name);
395 BKE_image_format_blend_read_data(&reader, &data.format);
397}
398
399static void node_extra_info(NodeExtraInfoParams &parameters)
400{
401 SpaceNode *space_node = CTX_wm_space_node(&parameters.C);
402 if (space_node->node_tree_sub_type != SNODE_COMPOSITOR_SCENE) {
404 row.text = RPT_("Node Unsupported");
405 row.tooltip = TIP_("The File Output node is only supported for scene compositing");
406 row.icon = ICON_STATUS_ERROR;
407 parameters.rows.append(std::move(row));
408 }
409}
410
412{
413 const bNodeSocket &origin_socket = params.other_socket();
414 if (origin_socket.in_out != SOCK_OUT) {
415 return;
416 }
417 const eNodeSocketDatatype origin_socket_type = origin_socket.type;
419 return;
420 }
421 params.add_item("File Output", [](LinkSearchOpParams &params) {
422 bNode &node = params.add_node("CompositorNodeOutputFile"_ustr);
423 const eNodeSocketDatatype socket_type = params.socket.type;
424 if (socket_type == SOCK_VECTOR) {
426 params.node_tree,
427 node,
428 socket_type,
429 params.socket.name,
430 params.socket.default_value_typed<bNodeSocketValueVector>()->dimensions);
431 }
432 else {
434 params.node_tree, node, socket_type, params.socket.name);
435 }
436 params.update_and_connect_available_socket(node, UString(params.socket.name));
437 });
438}
439
440using namespace blender::compositor;
441
443 public:
445
446 void execute() override
447 {
448 if (this->is_multi_layer()) {
449 this->execute_multi_layer();
450 }
451 else {
452 this->execute_single_layer();
453 }
454 }
455
456 /* --------------------
457 * Single Layer Images.
458 */
459
461 {
462 const NodeCompositorFileOutput &storage = node_storage(this->node());
463 for (const int i : IndexRange(storage.items_count)) {
464 const NodeCompositorFileOutputItem &item = storage.items[i];
465 const std::string identifier = FileOutputItemsAccessor::socket_identifier_for_item(item);
466 const Result &result = this->get_input(identifier);
467 /* We only write images, not single values. */
468 if (result.is_single_value()) {
469 continue;
470 }
471
472 /* The image saving code expects EXR images to have a different structure than standard
473 * images. In particular, in EXR images, the buffers need to be stored in passes that are, in
474 * turn, stored in a render layer. On the other hand, in non-EXR images, the buffers need to
475 * be stored in views. An exception to this is stereo images, which needs to have the same
476 * structure as non-EXR images. */
477 const auto &format = item.override_node_format ? item.format :
478 node_storage(this->node()).format;
479 const bool save_as_render = item.override_node_format ?
480 item.save_as_render :
481 node_storage(this->node()).save_as_render;
482 const bool is_exr = format.imtype == R_IMF_IMTYPE_OPENEXR;
483 const int views_count = BKE_scene_multiview_num_views_get(
484 &this->context().get_render_data());
485 if (is_exr && !(format.views_format == R_IMF_VIEWS_STEREO_3D && views_count == 2)) {
487 continue;
488 }
489
490 char image_path[FILE_MAX];
492 format, item.name, "", image_path);
493 if (!path_errors.is_empty()) {
494 continue;
495 }
496
497 const int2 size = result.domain().data_size;
498 FileOutput &file_output = this->context().render_context()->get_file_output(
499 image_path, format, size, save_as_render);
500
501 this->add_view_for_result(file_output, result, context().get_view_name().data());
502
503 this->add_meta_data_for_result(file_output, result, item.name);
504 }
505 }
506
507 /* -----------------------------------
508 * Single Layer Multi-View EXR Images.
509 */
510
512 const ImageFormatData &format,
513 const char *layer_name)
514 {
515 const bool has_views = format.views_format != R_IMF_VIEWS_INDIVIDUAL;
516
517 /* The EXR stores all views in the same file, so we supply an empty view to make sure the file
518 * name does not contain a view suffix. */
519 const char *path_view = has_views ? "" : this->context().get_view_name().data();
520
521 char image_path[FILE_MAX];
523 format, layer_name, path_view, image_path);
524 if (!path_errors.is_empty()) {
525 return;
526 }
527
528 const int2 size = result.domain().data_size;
529 FileOutput &file_output = this->context().render_context()->get_file_output(
530 image_path, format, size, true);
531
532 /* The EXR stores all views in the same file, so we add the actual render view. Otherwise, we
533 * add a default unnamed view. */
534 const char *view_name = has_views ? this->context().get_view_name().data() : "";
535 file_output.add_view(view_name);
536 this->add_pass_for_result(file_output, result, "", view_name);
537
538 this->add_meta_data_for_result(file_output, result, layer_name);
539 }
540
541 /* -----------------------
542 * Multi-Layer EXR Images.
543 */
544
546 {
547 /* We only write images, not single values. */
548 const int2 size = this->compute_domain().data_size;
549 if (size == int2(1)) {
550 return;
551 }
552
553 const ImageFormatData format = node_storage(this->node()).format;
554 const bool store_views_in_single_file = this->is_multi_view_exr();
555 const char *view = this->context().get_view_name().data();
556
557 /* If we are saving all views in a single multi-layer file, we supply an empty view to make
558 * sure the file name does not contain a view suffix. */
559 char image_path[FILE_MAX];
560 const char *write_view = store_views_in_single_file ? "" : view;
562 format, "", write_view, image_path);
563 if (!path_errors.is_empty()) {
564 return;
565 }
566
567 FileOutput &file_output = this->context().render_context()->get_file_output(
568 image_path, format, size, true);
569
570 /* If we are saving views in separate files, we needn't store the view in the channel names, so
571 * we add an unnamed view. */
572 const char *pass_view = store_views_in_single_file ? view : "";
573 file_output.add_view(pass_view);
574
575 const NodeCompositorFileOutput &storage = node_storage(node());
576 for (const int i : IndexRange(storage.items_count)) {
577 const NodeCompositorFileOutputItem &item = storage.items[i];
578 const std::string identifier = FileOutputItemsAccessor::socket_identifier_for_item(item);
579 const Result &input_result = this->get_input(identifier);
580 this->add_pass_for_result(file_output, input_result, item.name, pass_view);
581
582 this->add_meta_data_for_result(file_output, input_result, item.name);
583 }
584 }
585
586 /* Read the data stored in the given result and add a pass of the given name, view, and read
587 * buffer. The pass channel identifiers follows the EXR conventions. */
589 const Result &result,
590 const char *pass_name,
591 const char *view_name)
592 {
593 Result data = this->context().create_result(result.type());
594 if (result.is_single_value()) {
595 /* For single values, we fill a buffer that covers the domain of the operation with the value
596 * of the result. */
597 data.allocate_texture(this->compute_domain(), true, ResultStorageType::CPUImage);
598 const GPointer single_value = result.single_value();
599 const int64_t pixel_count = int64_t(data.domain().data_size.x) * data.domain().data_size.y;
600 single_value.type()->fill_assign_n(
601 single_value.get(), data.cpu_data_for_write().data(), pixel_count);
602 }
603 else if (this->context().use_gpu()) {
604 Result result_cpu = result.download_to_cpu();
605 data.share_data(result_cpu);
606 result_cpu.release();
607 }
608 else {
609 data.share_data(result);
610 }
611
612 switch (result.type()) {
614 /* Use lowercase rgba for Cryptomatte layers because the EXR internal compression rules
615 * specify that all uppercase RGBA channels will be compressed, and Cryptomatte should not
616 * be compressed. */
617 if (result.meta_data.is_cryptomatte_layer()) {
618 file_output.add_pass(pass_name, view_name, "rgba", data);
619 }
620 else {
621 file_output.add_pass(pass_name, view_name, "RGBA", data);
622 }
623 break;
625 file_output.add_pass(pass_name, view_name, "XYZ", data);
626 break;
628 file_output.add_pass(pass_name, view_name, "XYZW", data);
629 break;
631 file_output.add_pass(pass_name, view_name, "V", data);
632 break;
634 file_output.add_pass(pass_name, view_name, "XY", data);
635 break;
636 case ResultType::Int2:
637 case ResultType::Int3:
638 case ResultType::Int4:
639 case ResultType::Int:
640 case ResultType::Bool:
642 case ResultType::Menu:
647 case ResultType::Font:
649 case ResultType::Text:
650 case ResultType::Mask:
653 /* Not supported. */
655 break;
656 }
657
658 data.release();
659 }
660
661 /* Read the data stored the given result and add a view of the given name and read buffer. */
662 void add_view_for_result(FileOutput &file_output, const Result &result, const char *view_name)
663 {
664 Result data = this->context().create_result(result.type());
665 if (this->context().use_gpu()) {
666 Result result_cpu = result.download_to_cpu();
667 data.share_data(result_cpu);
668 result_cpu.release();
669 }
670 else {
671 data.share_data(result);
672 }
673
674 switch (result.type()) {
676 file_output.add_view(view_name, data);
677 break;
679 file_output.add_view(view_name, data);
680 break;
682 file_output.add_view(view_name, data);
683 break;
685 file_output.add_view(view_name, data);
686 break;
688 case ResultType::Int2:
689 case ResultType::Int:
690 case ResultType::Int3:
691 case ResultType::Int4:
692 case ResultType::Bool:
694 case ResultType::Menu:
699 case ResultType::Font:
701 case ResultType::Text:
702 case ResultType::Mask:
705 /* Not supported. */
707 break;
708 }
709
710 data.release();
711 }
712
713 /* Add Cryptomatte meta data to the file if they exist for the given result of the given layer
714 * name. We do not write any other meta data for now. */
715 void add_meta_data_for_result(FileOutput &file_output, const Result &result, const char *name)
716 {
718
719 if (result.meta_data.is_cryptomatte_layer()) {
720 file_output.add_meta_data(
721 bke::cryptomatte::BKE_cryptomatte_meta_data_key(cryptomatte_layer_name, "name"),
722 cryptomatte_layer_name);
723 }
724
725 if (!result.meta_data.cryptomatte.manifest.empty()) {
726 file_output.add_meta_data(
727 bke::cryptomatte::BKE_cryptomatte_meta_data_key(cryptomatte_layer_name, "manifest"),
728 result.meta_data.cryptomatte.manifest);
729 }
730
731 if (!result.meta_data.cryptomatte.hash.empty()) {
732 file_output.add_meta_data(
733 bke::cryptomatte::BKE_cryptomatte_meta_data_key(cryptomatte_layer_name, "hash"),
734 result.meta_data.cryptomatte.hash);
735 }
736
737 if (!result.meta_data.cryptomatte.conversion.empty()) {
738 file_output.add_meta_data(
739 bke::cryptomatte::BKE_cryptomatte_meta_data_key(cryptomatte_layer_name, "conversion"),
740 result.meta_data.cryptomatte.conversion);
741 }
742
743 for (const auto &item : result.meta_data.fields.items()) {
744 file_output.add_meta_data(item.key, item.value);
745 }
746 }
747
749 const char *file_name_suffix,
750 const char *view,
751 char *r_image_path)
752 {
754 this->get_directory(),
755 this->get_file_name(),
756 file_name_suffix,
757 view,
758 this->context().get_frame_number(),
759 format,
760 this->context().get_main(),
761 this->context().get_scene(),
762 this->node(),
763 this->is_animation_render(),
764 r_image_path);
765
766 if (!path_errors.is_empty()) {
768 nullptr, RPT_ERROR, "Invalid path template in File Output node. Skipping writing file.");
769 }
770
771 return path_errors;
772 }
773
775 {
776 return node_storage(this->node()).format.imtype == R_IMF_IMTYPE_MULTILAYER;
777 }
778
780 {
781 const char *file_name = node_storage(this->node()).file_name;
782 return file_name ? file_name : "";
783 }
784
786 {
787 return node_storage(this->node()).directory;
788 }
789
790 /* If true, save views in a multi-view EXR file, otherwise, save each view in its own file. */
792 {
793 if (!this->is_multi_view_scene()) {
794 return false;
795 }
796
797 return node_storage(this->node()).format.views_format == R_IMF_VIEWS_MULTIVIEW;
798 }
799
801 {
802 return this->context().get_render_data().scemode & R_MULTIVIEW;
803 }
804
806 {
808 if (!this->is_multi_layer()) {
809 return domain;
810 }
811
812 /* Reset the location of the domain in multi-layer case such that translations take effect,
813 * this will result in clipping but is more expected for the user. */
814 domain.transformation.location() = float2(0.0f);
815 return domain;
816 }
817
819 {
820 if (!this->context().render_context()) {
821 return false;
822 }
824 }
825};
826
828{
829 return new FileOutputOperation(context, node);
830}
831
832static void node_register()
833{
834 static bke::bNodeType ntype;
835
836 cmp_node_type_base(&ntype, "CompositorNodeOutputFile"_ustr, CMP_NODE_OUTPUT_FILE);
837 ntype.ui_name = "File Output";
838 ntype.ui_description = "Write image file to disk";
839 ntype.enum_name_legacy = "OUTPUT_FILE";
841 ntype.declare = node_declare;
846 ntype.initfunc = node_init;
848 bke::node_type_storage(ntype, "NodeCompositorFileOutput", node_free_storage, node_copy_storage);
854
856}
858
859} // namespace blender::nodes::node_composite_file_output_cc
860
861namespace blender::nodes {
862
863StructRNA **FileOutputItemsAccessor::item_srna = &RNA_NodeCompositorFileOutputItem;
864
866{
867 writer->write_string(item.name);
868 BKE_image_format_blend_write(writer, const_cast<ImageFormatData *>(&item.format));
869}
870
876
878{
879 char file_name[FILE_MAX] = "";
880 STRNCPY(file_name, name.data());
881 BLI_path_make_safe(file_name);
882 return file_name;
883}
884
885} // namespace blender::nodes
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:479
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define CMP_NODE_OUTPUT_FILE
#define FILE_MAX
#define RPT_(msgid)
#define TIP_(msgid)
#define IFACE_(msgid)
Read Blender memory allocation and freeing.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define BLI_assert_unreachable()
void fill_assign_n(const void *value, void *dst, int64_t n) const
const CPPType * type() const
const void * get() const
constexpr IndexRange()=default
constexpr const char * c_str() const
UString()=default
constexpr const char * data() const
Result create_result(ResultType type, ResultPrecision precision)
virtual StringRef get_view_name() const
virtual const RenderData & get_render_data() const
virtual RenderContext * render_context() const
void add_view(const char *view_name)
void add_pass(const char *pass_name, const char *view_name, const char *channels, const Result &data)
void add_meta_data(std::string key, std::string value)
NodeOperation(Context &context, const bNode &node)
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
virtual Domain compute_domain()
Definition operation.cc:62
FileOutput & get_file_output(std::string path, ImageFormatData format, int2 size, bool save_as_render)
BaseSocketDeclarationBuilder & compositor_realization_mode(CompositorInputRealizationMode value)
BaseSocketDeclarationBuilder & structure_type(StructureType structure_type)
BaseSocketDeclarationBuilder & socket_name_ptr(PointerRNA ptr, StringRef property_name)
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
void execute_single_layer_multi_view_exr(const Result &result, const ImageFormatData &format, const char *layer_name)
Vector< bke::path_templates::Error > get_image_path(const ImageFormatData &format, const char *file_name_suffix, const char *view, char *r_image_path)
void add_pass_for_result(FileOutput &file_output, const Result &result, const char *pass_name, const char *view_name)
void add_meta_data_for_result(FileOutput &file_output, const Result &result, const char *name)
void add_view_for_result(FileOutput &file_output, const Result &result, const char *view_name)
#define main()
#define storage(slot, qualifiers)
StringRef BKE_cryptomatte_extract_layer_name(StringRef render_pass_name)
std::string BKE_cryptomatte_meta_data_key(StringRef layer_name, StringRefNull key_name)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_draw_buttons_extended(ui::Layout &layout, bContext *context, PointerRNA *node_pointer)
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
static void node_init_api(const bContext *C, PointerRNA *node_ptr)
static void output_path_layout(ui::Layout &layout, const StringRefNull directory, const StringRefNull file_name, const StringRefNull file_name_suffix, const char *view, const ImageFormatData &format, const Main &bmain, const Scene &scene, const bNode &node)
static bool node_insert_link(bke::NodeInsertLinkParams &params)
static void node_draw_buttons(ui::Layout &layout, bContext *, PointerRNA *node_pointer)
static void node_extra_info(NodeExtraInfoParams &parameters)
static void node_declare(NodeDeclarationBuilder &b)
static void format_layout(ui::Layout *layout, bContext *context, PointerRNA *format_pointer, PointerRNA *node_or_item_pointer)
static Vector< bke::path_templates::Error > compute_image_path(const StringRefNull directory, const StringRefNull file_name, const StringRefNull file_name_suffix, const char *view, const int frame_number, const ImageFormatData &format, const Main &bmain, const Scene &scene, const bNode &node, const bool is_animation_render, char *r_image_path)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static void node_init(bNodeTree *node_tree, bNode *node)
static void node_copy_storage(bNodeTree *, bNode *destination_node, const bNode *source_node)
static void item_layout(ui::Layout &layout, bContext *context, PointerRNA *node_pointer, PointerRNA *item_pointer, const bool is_multi_layer)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void output_paths_layout(ui::Layout &layout, bContext *context, const StringRefNull file_name_suffix, const bNode &node, const ImageFormatData &format)
void blend_write(BlendWriter *writer, const bNode &node)
void blend_read_data(BlendDataReader *reader, bNode &node)
void copy_array(const bNode &src_node, bNode &dst_node)
Accessor::ItemT * add_item_with_socket_type_and_name(bNodeTree &ntree, bNode &node, const eNodeSocketDatatype socket_type, const char *name, std::optional< int > dimensions=std::nullopt)
bool try_add_item_via_any_extend_socket(bNodeTree &ntree, bNode &extend_node, bNode &storage_node, bNodeLink &link, const std::optional< StringRef > socket_identifier=std::nullopt, typename Accessor::ItemT **r_new_item=nullptr)
bool BKE_scene_multiview_is_render_view_active(const RenderData *rd, const SceneRenderView *srv)
Definition scene.cc:3241
__int64 int64_t
Definition BKE_text.h:90
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void uiTemplateImageFormatViews(ui::Layout *layout, PointerRNA *imfptr, PointerRNA *ptr)
void BKE_image_format_media_type_set(ImageFormatData *format, ID *owner_id, const MediaType media_type)
void BKE_add_template_variables_general(bke::path_templates::VariableMap &variables, const ID *path_owner_id, const bke::BlenderProject *project)
bool BLI_path_make_safe(char *path) ATTR_NONNULL(1)
@ MEDIA_TYPE_MULTI_LAYER_IMAGE
void BKE_image_format_blend_write(BlendWriter *writer, ImageFormatData *imf)
bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1)
size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file) ATTR_NONNULL(1
const char * BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3390
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:1063
Vector< bke::path_templates::Error > BKE_image_path_from_imformat(char *filepath, const char *base, const char *relbase, const bke::path_templates::VariableMap *template_variables, int frame, const ImageFormatData *im_format, bool use_ext, bool use_frames, const char *suffix)
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
int BKE_scene_multiview_num_views_get(const RenderData *rd)
Definition scene.cc:3193
std::string BKE_path_template_error_to_string(const bke::path_templates::Error &error, StringRef path)
void BKE_add_template_variables_for_render_path(bke::path_templates::VariableMap &variables, const Scene &scene)
void BKE_add_template_variables_for_node(bke::path_templates::VariableMap &variables, const bNode &owning_node)
@ R_IMF_IMTYPE_MULTILAYER
@ SNODE_COMPOSITOR_SCENE
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void BKE_image_format_blend_read_data(BlendDataReader *reader, ImageFormatData *imf)
SpaceNode * CTX_wm_space_node(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void uiTemplateImageSettings(ui::Layout *layout, bContext *C, PointerRNA *imfptr, bool color_management, const char *panel_idname=nullptr)
void BKE_image_format_init(ImageFormatData *imf)
void BKE_image_format_free(ImageFormatData *imf)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
@ R_IMF_VIEWS_MULTIVIEW
@ R_IMF_VIEWS_INDIVIDUAL
@ R_IMF_VIEWS_STEREO_3D
Scene * CTX_data_scene(const bContext *C)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
void BKE_image_format_update_color_space_for_type(ImageFormatData *format)
void BKE_image_format_copy(ImageFormatData *imf_dst, const ImageFormatData *imf_src)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:6653
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void write_string(const char *data)
T * data_as() const
Definition RNA_types.hh:139
ListBaseT< SceneRenderView > views
struct RenderData r
eNodeSocketDatatype type
eNodeSocketInOut in_out
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
NodeBlendWriteFunction blend_write_storage_content
Definition BKE_node.hh:421
void(*) register_operators()
Definition BKE_node.hh:448
std::string ui_description
Definition BKE_node.hh:271
NodeBlendDataReadFunction blend_data_read_storage_content
Definition BKE_node.hh:422
void(*) initfunc_api(const bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:333
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
NodeExtraInfoFunction get_extra_info
Definition BKE_node.hh:412
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:292
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:409
NodeDeclareFunction declare
Definition BKE_node.hh:393
bool(*) insert_link(NodeInsertLinkParams &params)
Definition BKE_node.hh:364
static std::string validate_name(const StringRef name)
static std::string socket_identifier_for_item(const NodeCompositorFileOutputItem &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
Vector< NodeExtraInfoRow > & rows
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)