Files
test/source/blender/blenkernel/BKE_image_save.h
Omar Emara 931c188ce5 Compositor: Refactor File Output node
This patches refactors the compositor File Output mechanism and
implements the file output node for the Realtime Compositor. The
refactor was done for the following reasons:

1. The existing file output mechanism relied on a global EXR image
   resource where the result of each compositor execution for each
   view was accumulated and stored in the global resource, until the
   last view is executed, when the EXR is finally saved. Aside from
   relying on global resources, this can cause effective memory leaks
   since the compositor can be interrupted before the EXR is written and
   closed.
2. We need common code to share between all compositors since we now
   have multiple compositor implementations.
3. We needed to take the opportunity to fix some of the issues with the
   existing implementation, like lossy compression of data passes,
   and inability to save single values passes.

The refactor first introduced a new structure called the Compositor
Render Context. This context stores compositor information related to
the render pipeline and is persistent across all compositor executions
of all views. Its extended lifetime relative to a single compositor
execution lends itself well to store data that is accumulated across
views. The context currently has a map of File Output objects. Those
objects wrap a Render Result structure and can be used to construct
multi-view images which can then be saved after all views are executed
using the existing BKE_image_render_write function.

Minor adjustments were made to the BKE and RE modules to allow saving
using the BKE_image_render_write function. Namely, the function now
allows the use of a source image format for saving as well as the
ability to not save the render result as a render by introducing two new
default arguments. Further, for multi-layer EXR saving, the existent of
a single unnamed render layer will omit the layer name from the EXR
channel full name, and only the pass, view, and channel ID will remain.
Finally, the Render Result to Image Buffer conversion now take he number
of channels into account, instead of always assuming color channels.

The patch implements the File Output node in the Realtime Compositor
using the aforementioned mechanisms, replaces the implementation of the
CPU compositor using the same Realtime Compositor implementation, and
setup the necessary logic in the render pipeline code.

Pull Request: https://projects.blender.org/blender/blender/pulls/113982
2023-12-13 11:08:03 +01:00

90 lines
2.7 KiB
C

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "DNA_scene_types.h"
/** \file
* \ingroup bke
*/
#ifdef __cplusplus
extern "C" {
#endif
struct Image;
struct ImageUser;
struct Main;
struct RenderResult;
struct ReportList;
struct Scene;
/* Image datablock saving. */
typedef struct ImageSaveOptions {
/* Context within which image is saved. */
struct Main *bmain;
struct Scene *scene;
/* Format and absolute file path. */
struct ImageFormatData im_format;
char filepath[1024]; /* 1024 = FILE_MAX */
/* Options. */
bool relative;
bool save_copy;
bool save_as_render;
bool do_newpath;
/* Keep track of previous values for auto updates in UI. */
bool prev_save_as_render;
int prev_imtype;
} ImageSaveOptions;
bool BKE_image_save_options_init(ImageSaveOptions *opts,
struct Main *bmain,
struct Scene *scene,
struct Image *ima,
struct ImageUser *iuser,
const bool guess_path,
const bool save_as_render);
void BKE_image_save_options_update(struct ImageSaveOptions *opts, const struct Image *ima);
void BKE_image_save_options_free(struct ImageSaveOptions *opts);
bool BKE_image_save(struct ReportList *reports,
struct Main *bmain,
struct Image *ima,
struct ImageUser *iuser,
const struct ImageSaveOptions *opts);
/* Render saving. */
/**
* Save single or multi-layer OpenEXR files from the render result.
* Optionally saves only a specific view or layer.
*/
bool BKE_image_render_write_exr(struct ReportList *reports,
const struct RenderResult *rr,
const char *filepath,
const struct ImageFormatData *imf,
const bool save_as_render,
const char *view,
int layer);
/**
* \param filepath_basis: May be used as-is, or used as a basis for multi-view images.
* \param format: The image format to use for saving, if null, the scene format will be used.
*/
bool BKE_image_render_write(struct ReportList *reports,
struct RenderResult *rr,
const struct Scene *scene,
const bool stamp,
const char *filepath_basis,
const struct ImageFormatData *format = nullptr,
bool save_as_render = true);
#ifdef __cplusplus
}
#endif