Blender  V2.93
COM_MetaData.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2021, Blender Foundation.
17  */
18 
19 #include "COM_MetaData.h"
20 
21 #include "BKE_image.h"
22 
23 #include "RE_pipeline.h"
24 
25 #include <string_view>
26 
27 namespace blender::compositor {
28 
30 {
31  entries_.add(key, value);
32 }
33 
34 void MetaData::addCryptomatteEntry(const blender::StringRef layer_name,
35  const blender::StringRefNull key,
36  const blender::StringRef value)
37 {
39 }
40 
41 /* Replace the hash neutral cryptomatte keys with hashed versions.
42  *
43  * When a conversion happens it will also add the cryptomatte name key with the given
44  * `layer_name`.*/
46 {
47  std::string cryptomatte_hash = entries_.pop_default(META_DATA_KEY_CRYPTOMATTE_HASH, "");
48  std::string cryptomatte_conversion = entries_.pop_default(META_DATA_KEY_CRYPTOMATTE_CONVERSION,
49  "");
50  std::string cryptomatte_manifest = entries_.pop_default(META_DATA_KEY_CRYPTOMATTE_MANIFEST, "");
51 
52  if (cryptomatte_hash.length() || cryptomatte_conversion.length() ||
53  cryptomatte_manifest.length()) {
54  addCryptomatteEntry(layer_name, "name", layer_name);
55  }
56  if (cryptomatte_hash.length()) {
57  addCryptomatteEntry(layer_name, "hash", cryptomatte_hash);
58  }
59  if (cryptomatte_conversion.length()) {
60  addCryptomatteEntry(layer_name, "conversion", cryptomatte_conversion);
61  }
62  if (cryptomatte_manifest.length()) {
63  addCryptomatteEntry(layer_name, "manifest", cryptomatte_manifest);
64  }
65 }
66 
67 void MetaData::addToRenderResult(RenderResult *render_result) const
68 {
69  for (Map<std::string, std::string>::Item entry : entries_.items()) {
70  BKE_render_result_stamp_data(render_result, entry.key.c_str(), entry.value.c_str());
71  }
72 }
73 
75 {
76  if (!meta_data) {
77  meta_data = std::make_unique<MetaData>();
78  }
79  meta_data->add(key, value);
80 }
81 
83 {
85  "manifest");
87  "hash");
89  "conversion");
90 }
91 
93  const char *propname,
94  char *propvalue,
95  int UNUSED(len))
96 {
98  blender::StringRefNull key(propname);
99  if (key == data->hash_key) {
100  data->addMetaData(META_DATA_KEY_CRYPTOMATTE_HASH, propvalue);
101  }
102  else if (key == data->conversion_key) {
103  data->addMetaData(META_DATA_KEY_CRYPTOMATTE_CONVERSION, propvalue);
104  }
105  else if (key == data->manifest_key) {
106  data->addMetaData(META_DATA_KEY_CRYPTOMATTE_MANIFEST, propvalue);
107  }
108 }
109 
110 } // namespace blender::compositor
void BKE_render_result_stamp_data(struct RenderResult *rr, const char *key, const char *value)
Definition: image.c:2727
#define UNUSED(x)
uint64_t hash_key
Definition: array_store.c:214
bool add(const Key &key, const Value &value)
Definition: BLI_map.hh:264
ItemIterator items() const
Definition: BLI_map.hh:825
Value pop_default(const Key &key, const Value &default_value)
Definition: BLI_map.hh:408
void replaceHashNeutralCryptomatteKeys(const blender::StringRef layer_name)
Definition: COM_MetaData.cc:45
void add(const blender::StringRef key, const blender::StringRef value)
Definition: COM_MetaData.cc:29
void addToRenderResult(RenderResult *render_result) const
Definition: COM_MetaData.cc:67
std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name, const StringRefNull key_name)
Definition: cryptomatte.cc:487
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")
void setCryptomatteKeys(blender::StringRef cryptomatte_layer_name)
Definition: COM_MetaData.cc:82
static void extract_cryptomatte_meta_data(void *_data, const char *propname, char *propvalue, int UNUSED(len))
Definition: COM_MetaData.cc:92
void addMetaData(blender::StringRef key, blender::StringRefNull value)
Definition: COM_MetaData.cc:74
uint len