diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-01-12 18:19:54 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-01-12 18:24:26 +0300 |
commit | 957e292c5864cba3cf62c7c59dc644422660034f (patch) | |
tree | b182f75cf4d61dd3401f4dbe59d3ab3df1642897 /source/blender/compositor/operations/COM_OutputFileOperation.cpp | |
parent | c3b68fa7b1cafa6c4e4b73830597582606082b6d (diff) |
Fix T64953: Add cryptomatte meta data to file output node.
This change will try to add meta data when using a multilayered open
exr file output node in the compositor. It adds the current scene meta
data and converts existing cryptomatte keys so it follows the
naming that is configured in the file output node.
This change supports the basic use-case where the compositor is
used to output cryptomatte layers with a different naming scheme to
support external compositors. In this case the Multilayered OpenEXR
files are used and the meta data is read from the render result.
Meta data is found when render layer node is connected with the
file output node without any other nodes in between. Redirects and empty
node groups are allowed.
The patch has been verified to work with external compositors.
See https://devtalk.blender.org/t/making-sense-of-cryptomatte-usage-in-third-party-programs/16576/17
See patch for example files.
Reviewed By: Sergey Sharybin
Differential Revision: https://developer.blender.org/D10016
Diffstat (limited to 'source/blender/compositor/operations/COM_OutputFileOperation.cpp')
-rw-r--r-- | source/blender/compositor/operations/COM_OutputFileOperation.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cpp b/source/blender/compositor/operations/COM_OutputFileOperation.cpp index 2676ab1b9ca..216b754f676 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cpp +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cpp @@ -18,12 +18,15 @@ #include "COM_OutputFileOperation.h" +#include "COM_MetaData.h" + #include <cstring> #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BKE_cryptomatte.hh" #include "BKE_global.h" #include "BKE_image.h" #include "BKE_main.h" @@ -36,6 +39,8 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#include "RE_pipeline.h" + void add_exr_channels(void *exrhandle, const char *layerName, const DataType datatype, @@ -299,13 +304,15 @@ OutputOpenExrLayer::OutputOpenExrLayer(const char *name_, DataType datatype_, bo this->imageInput = nullptr; } -OutputOpenExrMultiLayerOperation::OutputOpenExrMultiLayerOperation(const RenderData *rd, +OutputOpenExrMultiLayerOperation::OutputOpenExrMultiLayerOperation(const Scene *scene, + const RenderData *rd, const bNodeTree *tree, const char *path, char exr_codec, bool exr_half_float, const char *viewName) { + this->m_scene = scene; this->m_rd = rd; this->m_tree = tree; @@ -323,6 +330,26 @@ void OutputOpenExrMultiLayerOperation::add_layer(const char *name, this->m_layers.push_back(OutputOpenExrLayer(name, datatype, use_layer)); } +StampData *OutputOpenExrMultiLayerOperation::createStampData() const +{ + /* StampData API doesn't provide functions to modify an instance without having a RenderResult. + */ + RenderResult render_result; + StampData *stamp_data = BKE_stamp_info_from_scene_static(m_scene); + render_result.stamp_data = stamp_data; + for (int i = 0; i < this->m_layers.size(); i++) { + const OutputOpenExrLayer *layer = &this->m_layers[i]; + std::unique_ptr<MetaData> meta_data = layer->imageInput->getMetaData(); + if (meta_data) { + blender::StringRef layer_name = blender::BKE_cryptomatte_extract_layer_name( + blender::StringRef(layer->name, BLI_strnlen(layer->name, sizeof(layer->name)))); + meta_data->replaceHashNeutralCryptomatteKeys(layer_name); + meta_data->addToRenderResult(&render_result); + } + } + return stamp_data; +} + void OutputOpenExrMultiLayerOperation::initExecution() { for (unsigned int i = 0; i < this->m_layers.size(); i++) { @@ -386,7 +413,8 @@ void OutputOpenExrMultiLayerOperation::deinitExecution() } /* when the filename has no permissions, this can fail */ - if (IMB_exr_begin_write(exrhandle, filename, width, height, this->m_exr_codec, nullptr)) { + StampData *stamp_data = createStampData(); + if (IMB_exr_begin_write(exrhandle, filename, width, height, this->m_exr_codec, stamp_data)) { IMB_exr_write_channels(exrhandle); } else { @@ -404,5 +432,6 @@ void OutputOpenExrMultiLayerOperation::deinitExecution() this->m_layers[i].imageInput = nullptr; } + BKE_stamp_data_free(stamp_data); } } |