Blender V4.3
COM_MetaData.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <string>
8
9#include "BKE_cryptomatte.hh"
10#include "BLI_function_ref.hh"
11#include "BLI_map.hh"
12
13#include "MEM_guardedalloc.h"
14
15/* Forward declarations. */
16struct RenderResult;
17
18namespace blender::compositor {
19
20/* Cryptomatte includes hash in its meta data keys. The hash is generated from the render
21 * layer/pass name. Compositing happens without the knowledge of the original layer and pass. The
22 * next keys are used to transfer the cryptomatte meta data in a neutral way. The file output node
23 * will generate a hash based on the layer name configured by the user.
24 *
25 * The `{hash}` has no special meaning except to make sure that the meta data stays unique. */
26constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_HASH("cryptomatte/{hash}/hash");
27constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_CONVERSION("cryptomatte/{hash}/conversion");
28constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_MANIFEST("cryptomatte/{hash}/manifest");
29constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_NAME("cryptomatte/{hash}/name");
30
31class MetaData {
32 private:
34 void add_cryptomatte_entry(const blender::StringRef layer_name,
35 const blender::StringRefNull key,
36 const blender::StringRef value);
37
38 public:
39 /* The pixels in the result represents data, which is not to be color-managed. */
40 bool is_data = false;
41 /* The result stores a 4D vector as opposed to a 3D vector. This is the case for things like
42 * velocity passes, and we need to mark them as 4D in order to write them to file correctly. This
43 * field can be ignored for results that are not of type Vector. */
44 bool is_4d_vector = false;
45
46 void add(const blender::StringRef key, const blender::StringRef value);
47
48 bool is_cryptomatte_layer() const;
49
57 void add_to_render_result(RenderResult *render_result) const;
58
59 /* Invokes the given callback on each entry of the meta data. */
60 void for_each_entry(FunctionRef<void(const std::string &, const std::string &)> callback) const;
61
62#ifdef WITH_CXX_GUARDEDALLOC
63 MEM_CXX_CLASS_ALLOC_FUNCS("COM:MetaData")
64#endif
65};
66
68 std::unique_ptr<MetaData> meta_data;
69 std::string hash_key;
70 std::string conversion_key;
71 std::string manifest_key;
72
74 void set_cryptomatte_keys(blender::StringRef cryptomatte_layer_name);
75 /* C type callback function (StampCallback). */
76 static void extract_cryptomatte_meta_data(void *_data,
77 const char *propname,
78 char *propvalue,
79 int /*len*/);
80};
81
82} // namespace blender::compositor
Read Guarded memory(de)allocation.
void add_to_render_result(RenderResult *render_result) const
void for_each_entry(FunctionRef< void(const std::string &, const std::string &)> callback) const
void add(const blender::StringRef key, const blender::StringRef value)
void replace_hash_neutral_cryptomatte_keys(const blender::StringRef layer_name)
DEGForeachIDComponentCallback callback
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_CONVERSION("cryptomatte/{hash}/conversion")
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_HASH("cryptomatte/{hash}/hash")
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_MANIFEST("cryptomatte/{hash}/manifest")
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_NAME("cryptomatte/{hash}/name")
static void extract_cryptomatte_meta_data(void *_data, const char *propname, char *propvalue, int)
void add_meta_data(blender::StringRef key, blender::StringRefNull value)
void set_cryptomatte_keys(blender::StringRef cryptomatte_layer_name)