Blender  V2.93
cryptomatte.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  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BKE_cryptomatte.h"
25 #include "BKE_cryptomatte.hh"
26 #include "BKE_image.h"
27 #include "BKE_main.h"
28 
29 #include "DNA_layer_types.h"
30 #include "DNA_material_types.h"
31 #include "DNA_node_types.h"
32 #include "DNA_object_types.h"
33 #include "DNA_scene_types.h"
34 
35 #include "BLI_compiler_attrs.h"
36 #include "BLI_dynstr.h"
37 #include "BLI_hash_mm3.h"
38 #include "BLI_listbase.h"
39 #include "BLI_string.h"
40 
41 #include "RE_pipeline.h"
42 
43 #include "MEM_guardedalloc.h"
44 
45 #include <cctype>
46 #include <cstring>
47 #include <iomanip>
48 #include <sstream>
49 #include <string>
50 #include <string_view>
51 
54  /* Layer names in order of creation. */
56 
57  CryptomatteSession() = default;
58  CryptomatteSession(const Main *bmain);
59  CryptomatteSession(StampData *stamp_data);
61 
63  std::optional<std::string> operator[](float encoded_hash) const;
64 
65 #ifdef WITH_CXX_GUARDEDALLOC
66  MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteSession")
67 #endif
68 };
69 
71 {
72  if (!BLI_listbase_is_empty(&bmain->objects)) {
73  blender::bke::cryptomatte::CryptomatteLayer &objects = add_layer("CryptoObject");
74  LISTBASE_FOREACH (ID *, id, &bmain->objects) {
75  objects.add_ID(*id);
76  }
77  }
78  if (!BLI_listbase_is_empty(&bmain->materials)) {
79  blender::bke::cryptomatte::CryptomatteLayer &materials = add_layer("CryptoMaterial");
80  LISTBASE_FOREACH (ID *, id, &bmain->materials) {
81  materials.add_ID(*id);
82  }
83  }
84 }
85 
87 {
89  callback_data.session = this;
91  &callback_data,
92  stamp_data,
94  false);
96  &callback_data,
97  stamp_data,
99  false);
100 }
101 
103 {
104  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
105  eViewLayerCryptomatteFlags cryptoflags = static_cast<eViewLayerCryptomatteFlags>(
106  view_layer->cryptomatte_flag & VIEW_LAYER_CRYPTOMATTE_ALL);
107  if (cryptoflags == 0) {
108  cryptoflags = static_cast<eViewLayerCryptomatteFlags>(VIEW_LAYER_CRYPTOMATTE_ALL);
109  }
110 
111  if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_OBJECT) {
112  add_layer(blender::StringRefNull(view_layer->name) + ".CryptoObject");
113  }
114  if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_ASSET) {
115  add_layer(blender::StringRefNull(view_layer->name) + ".CryptoAsset");
116  }
117  if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_MATERIAL) {
118  add_layer(blender::StringRefNull(view_layer->name) + ".CryptoMaterial");
119  }
120  }
121 }
122 
124 {
125  if (!layer_names.contains(layer_name)) {
126  layer_names.append(layer_name);
127  }
128  return layers.lookup_or_add_default(layer_name);
129 }
130 
131 std::optional<std::string> CryptomatteSession::operator[](float encoded_hash) const
132 {
134  std::optional<std::string> result = layer[encoded_hash];
135  if (result) {
136  return result;
137  }
138  }
139  return std::nullopt;
140 }
141 
143 {
144  CryptomatteSession *session = new CryptomatteSession();
145  return session;
146 }
147 
149  const struct RenderResult *render_result)
150 {
151  CryptomatteSession *session = new CryptomatteSession(render_result->stamp_data);
152  return session;
153 }
154 
156 {
158  return session;
159 }
160 
161 void BKE_cryptomatte_add_layer(struct CryptomatteSession *session, const char *layer_name)
162 {
163  session->add_layer(layer_name);
164 }
165 
167 {
168  BLI_assert(session != nullptr);
169  delete session;
170 }
171 
172 uint32_t BKE_cryptomatte_hash(const char *name, const int name_len)
173 {
175  return hash.hash;
176 }
177 
179  const char *layer_name,
180  const Object *object)
181 {
182  blender::bke::cryptomatte::CryptomatteLayer *layer = session->layers.lookup_ptr(layer_name);
183  BLI_assert(layer);
184  return layer->add_ID(object->id);
185 }
186 
188  const char *layer_name,
189  const Material *material)
190 {
191  if (material == nullptr) {
192  return 0.0f;
193  }
194  blender::bke::cryptomatte::CryptomatteLayer *layer = session->layers.lookup_ptr(layer_name);
195  BLI_assert(layer);
196  return layer->add_ID(material->id);
197 }
198 
200  const char *layer_name,
201  const Object *object)
202 {
203  const Object *asset_object = object;
204  while (asset_object->parent != nullptr) {
205  asset_object = asset_object->parent;
206  }
207  return BKE_cryptomatte_object_hash(session, layer_name, asset_object);
208 }
209 
211 {
213 }
214 
215 /* Find an ID in the given main that matches the given encoded float. */
217  const float encoded_hash,
218  char *r_name,
219  int name_len)
220 {
221  std::optional<std::string> name = (*session)[encoded_hash];
222  if (!name) {
223  return false;
224  }
225 
226  BLI_strncpy(r_name, name->c_str(), name_len);
227  return true;
228 }
229 
231 {
232  DynStr *matte_id = BLI_dynstr_new();
233  bool first = true;
234  LISTBASE_FOREACH (CryptomatteEntry *, entry, &node_storage->entries) {
235  if (!first) {
236  BLI_dynstr_append(matte_id, ",");
237  }
238  if (BLI_strnlen(entry->name, sizeof(entry->name)) != 0) {
239  BLI_dynstr_nappend(matte_id, entry->name, sizeof(entry->name));
240  }
241  else {
242  BLI_dynstr_appendf(matte_id, "<%.9g>", entry->encoded_hash);
243  }
244  first = false;
245  }
246  char *result = BLI_dynstr_get_cstring(matte_id);
247  BLI_dynstr_free(matte_id);
248  return result;
249 }
250 
251 void BKE_cryptomatte_matte_id_to_entries(NodeCryptomatte *node_storage, const char *matte_id)
252 {
253  BLI_freelistN(&node_storage->entries);
254 
255  if (matte_id == nullptr) {
256  MEM_SAFE_FREE(node_storage->matte_id);
257  return;
258  }
259  /* Update the matte_id so the files can be opened in versions that don't
260  * use `CryptomatteEntry`. */
261  if (matte_id != node_storage->matte_id && node_storage->matte_id &&
262  STREQ(node_storage->matte_id, matte_id)) {
263  MEM_SAFE_FREE(node_storage->matte_id);
264  node_storage->matte_id = static_cast<char *>(MEM_dupallocN(matte_id));
265  }
266 
267  std::istringstream ss(matte_id);
268  while (ss.good()) {
269  CryptomatteEntry *entry = nullptr;
270  std::string token;
271  getline(ss, token, ',');
272  /* Ignore empty tokens. */
273  if (token.length() > 0) {
274  size_t first = token.find_first_not_of(' ');
275  size_t last = token.find_last_not_of(' ');
276  if (first == std::string::npos || last == std::string::npos) {
277  break;
278  }
279  token = token.substr(first, (last - first + 1));
280  if (*token.begin() == '<' && *(--token.end()) == '>') {
281  float encoded_hash = atof(token.substr(1, token.length() - 2).c_str());
282  entry = (CryptomatteEntry *)MEM_callocN(sizeof(CryptomatteEntry), __func__);
283  entry->encoded_hash = encoded_hash;
284  }
285  else {
286  const char *name = token.c_str();
287  int name_len = token.length();
288  entry = (CryptomatteEntry *)MEM_callocN(sizeof(CryptomatteEntry), __func__);
289  STRNCPY(entry->name, name);
290  uint32_t hash = BKE_cryptomatte_hash(name, name_len);
292  }
293  }
294  if (entry != nullptr) {
295  BLI_addtail(&node_storage->entries, entry);
296  }
297  }
298 }
299 
300 static std::string cryptomatte_determine_name(const ViewLayer *view_layer,
301  const blender::StringRefNull cryptomatte_layer_name)
302 {
303  std::stringstream stream;
304  const size_t view_layer_name_len = BLI_strnlen(view_layer->name, sizeof(view_layer->name));
305  stream << std::string(view_layer->name, view_layer_name_len) << "." << cryptomatte_layer_name;
306  return stream.str();
307 }
308 
310 {
311  return BLI_hash_mm3(reinterpret_cast<const unsigned char *>(name.data()), name.size(), 0);
312 }
313 
314 static void add_render_result_meta_data(RenderResult *render_result,
315  const blender::StringRef layer_name,
316  const blender::StringRefNull key_name,
317  const blender::StringRefNull value)
318 {
320  render_result,
321  blender::bke::cryptomatte::BKE_cryptomatte_meta_data_key(layer_name, key_name).c_str(),
322  value.data());
323 }
324 
326  RenderResult *render_result,
327  const ViewLayer *view_layer)
328 {
330  session->layers.items()) {
331  const blender::StringRefNull layer_name(item.key);
332  const blender::bke::cryptomatte::CryptomatteLayer &layer = item.value;
333 
334  const std::string manifest = layer.manifest();
335  const std::string name = cryptomatte_determine_name(view_layer, layer_name);
336 
337  add_render_result_meta_data(render_result, name, "name", name);
338  add_render_result_meta_data(render_result, name, "hash", "MurmurHash3_32");
339  add_render_result_meta_data(render_result, name, "conversion", "uint32_to_float32");
340  add_render_result_meta_data(render_result, name, "manifest", manifest);
341  }
342 }
343 
344 namespace blender::bke::cryptomatte {
345 namespace manifest {
346 constexpr StringRef WHITESPACES = " \t\n\v\f\r";
347 
349 {
350  size_t skip = ref.find_first_not_of(WHITESPACES);
351  if (skip == blender::StringRef::not_found) {
352  return ref;
353  }
354  return ref.drop_prefix(skip);
355 }
356 
357 static constexpr int quoted_string_len_(blender::StringRef ref)
358 {
359  int len = 1;
360  bool skip_next = false;
361  while (len < ref.size()) {
362  char current_char = ref[len];
363  if (skip_next) {
364  skip_next = false;
365  }
366  else {
367  if (current_char == '\\') {
368  skip_next = true;
369  }
370  if (current_char == '\"') {
371  len += 1;
372  break;
373  }
374  }
375  len += 1;
376  }
377  return len;
378 }
379 
380 static std::string unquote_(const blender::StringRef ref)
381 {
382  std::ostringstream stream;
383  for (char c : ref) {
384  if (c != '\\') {
385  stream << c;
386  }
387  }
388  return stream.str();
389 }
390 
392 {
393  StringRef ref = manifest;
394  ref = skip_whitespaces_(ref);
395  if (ref.is_empty() || ref.front() != '{') {
396  return false;
397  }
398  ref = ref.drop_prefix(1);
399  while (!ref.is_empty()) {
400  char front = ref.front();
401 
402  if (front == '\"') {
403  const int quoted_name_len = quoted_string_len_(ref);
404  const int name_len = quoted_name_len - 2;
405  std::string name = unquote_(ref.substr(1, name_len));
406  ref = ref.drop_prefix(quoted_name_len);
407  ref = skip_whitespaces_(ref);
408 
409  if (ref.is_empty()) {
410  return false;
411  }
412  char colon = ref.front();
413  if (colon != ':') {
414  return false;
415  }
416  ref = ref.drop_prefix(1);
417  ref = skip_whitespaces_(ref);
418 
419  if (ref.is_empty() || ref.front() != '\"') {
420  return false;
421  }
422 
423  const int quoted_hash_len = quoted_string_len_(ref);
424  if (quoted_hash_len < 2) {
425  return false;
426  }
427  const int hash_len = quoted_hash_len - 2;
429  ref = ref.drop_prefix(quoted_hash_len);
430  layer.add_hash(name, hash);
431  }
432  else if (front == ',') {
433  ref = ref.drop_prefix(1);
434  }
435  else if (front == '}') {
436  ref = ref.drop_prefix(1);
437  ref = skip_whitespaces_(ref);
438  break;
439  }
440  ref = skip_whitespaces_(ref);
441  }
442 
443  if (!ref.is_empty()) {
444  return false;
445  }
446 
447  return true;
448 }
449 
450 static std::string to_manifest(const CryptomatteLayer *layer)
451 {
452  std::stringstream manifest;
453 
454  bool is_first = true;
455  const blender::Map<std::string, CryptomatteHash> &const_map = layer->hashes;
456  manifest << "{";
458  if (is_first) {
459  is_first = false;
460  }
461  else {
462  manifest << ",";
463  }
464  manifest << quoted(item.key) << ":\"" << (item.value.hex_encoded()) << "\"";
465  }
466  manifest << "}";
467  return manifest.str();
468 }
469 
470 } // namespace manifest
471 
472 /* Return the hash of the given cryptomatte layer name.
473  *
474  * The cryptomatte specification limits the hash to 7 characters.
475  * The 7 position limitation solves issues when using cryptomatte together with OpenEXR.
476  * The specification suggests to use the first 7 chars of the hashed layer_name.
477  */
478 static std::string cryptomatte_layer_name_hash(const StringRef layer_name)
479 {
480  std::stringstream stream;
481  const uint32_t render_pass_identifier = cryptomatte_determine_identifier(layer_name);
482  stream << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex
483  << render_pass_identifier;
484  return stream.str().substr(0, 7);
485 }
486 
487 std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name, const StringRefNull key_name)
488 {
489  return "cryptomatte/" + cryptomatte_layer_name_hash(layer_name) + "/" + key_name;
490 }
491 
492 /* Extracts the cryptomatte name from a render pass name.
493  *
494  * Example: A render pass could be named `CryptoObject00`. This
495  * function would remove the trailing digits and return `CryptoObject`. */
497 {
498  int64_t last_token = render_pass_name.size();
499  while (last_token > 0 && std::isdigit(render_pass_name[last_token - 1])) {
500  last_token -= 1;
501  }
502  return render_pass_name.substr(0, last_token);
503 }
504 
506 {
507 }
508 
509 CryptomatteHash::CryptomatteHash(const char *name, const int name_len)
510 {
511  hash = BLI_hash_mm3((const unsigned char *)name, name_len, 0);
512 }
513 
515 {
517  std::istringstream(hex_encoded) >> std::hex >> result.hash;
518  return result;
519 }
520 
521 std::string CryptomatteHash::hex_encoded() const
522 {
523  std::stringstream encoded;
524  encoded << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex << hash;
525  return encoded.str();
526 }
527 
528 /* Convert a cryptomatte hash to a float.
529  *
530  * Cryptomatte hashes are stored in float textures and images. The conversion is taken from the
531  * cryptomatte specification. See Floating point conversion section in
532  * https://github.com/Psyop/Cryptomatte/blob/master/specification/cryptomatte_specification.pdf.
533  *
534  * The conversion uses as many 32 bit floating point values as possible to minimize hash
535  * collisions. Unfortunately not all 32 bits can be used as NaN and Inf can be problematic.
536  *
537  * Note that this conversion assumes to be running on a L-endian system. */
539 {
540  uint32_t mantissa = hash & ((1 << 23) - 1);
541  uint32_t exponent = (hash >> 23) & ((1 << 8) - 1);
542  exponent = MAX2(exponent, (uint32_t)1);
543  exponent = MIN2(exponent, (uint32_t)254);
544  exponent = exponent << 23;
545  uint32_t sign = (hash >> 31);
546  sign = sign << 31;
547  uint32_t float_bits = sign | exponent | mantissa;
548  float f;
549  memcpy(&f, &float_bits, sizeof(uint32_t));
550  return f;
551 }
552 
553 std::unique_ptr<CryptomatteLayer> CryptomatteLayer::read_from_manifest(
554  blender::StringRefNull manifest)
555 {
556  std::unique_ptr<CryptomatteLayer> layer = std::make_unique<CryptomatteLayer>();
558  return layer;
559 }
560 
562 {
563  const char *name = &id.name[2];
564  const int name_len = BLI_strnlen(name, MAX_NAME - 2);
565  uint32_t cryptohash_int = BKE_cryptomatte_hash(name, name_len);
566 
567  add_hash(blender::StringRef(name, name_len), cryptohash_int);
568 
569  return cryptohash_int;
570 }
571 
573 {
574  hashes.add_overwrite(name, cryptomatte_hash);
575 }
576 
577 std::optional<std::string> CryptomatteLayer::operator[](float encoded_hash) const
578 {
581  if (BKE_cryptomatte_hash_to_float(item.value.hash) == encoded_hash) {
582  return std::make_optional(item.key);
583  }
584  }
585  return std::nullopt;
586 }
587 
588 std::string CryptomatteLayer::manifest() const
589 {
591 }
592 
594 {
595  BLI_assert(key.startswith("cryptomatte/"));
596 
597  size_t start_index = key.find_first_of('/');
598  size_t end_index = key.find_last_of('/');
599  if (start_index == blender::StringRef::not_found) {
600  return "";
601  }
602  if (end_index == blender::StringRef::not_found) {
603  return "";
604  }
605  if (end_index <= start_index) {
606  return "";
607  }
608  return key.substr(start_index + 1, end_index - start_index - 1);
609 }
610 
612  const char *propname,
613  char *propvalue,
614  int UNUSED(len))
615 {
617 
618  blender::StringRefNull key(propname);
619  if (!key.startswith("cryptomatte/")) {
620  return;
621  }
622  if (!key.endswith("/name")) {
623  return;
624  }
625  blender::StringRef layer_hash = extract_layer_hash(key);
626  data->hash_to_layer_name.add(layer_hash, propvalue);
627 }
628 
629 /* C type callback function (StampCallback). */
631  const char *propname,
632  char *propvalue,
633  int UNUSED(len))
634 {
636 
637  blender::StringRefNull key(propname);
638  if (!key.startswith("cryptomatte/")) {
639  return;
640  }
641  if (!key.endswith("/manifest")) {
642  return;
643  }
644  blender::StringRef layer_hash = extract_layer_hash(key);
645  if (!data->hash_to_layer_name.contains(layer_hash)) {
646  return;
647  }
648 
649  blender::StringRef layer_name = data->hash_to_layer_name.lookup(layer_hash);
650  blender::bke::cryptomatte::CryptomatteLayer &layer = data->session->add_layer(layer_name);
652 }
653 
655  const CryptomatteSession &session)
656 {
657  return session.layer_names;
658 }
659 
660 } // namespace blender::bke::cryptomatte
void BKE_render_result_stamp_data(struct RenderResult *rr, const char *key, const char *value)
Definition: image.c:2727
void BKE_stamp_info_callback(void *data, struct StampData *stamp_data, StampCallback callback, bool noskip)
Definition: image.c:2686
#define BLI_assert(a)
Definition: BLI_assert.h:58
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
Definition: BLI_dynstr.c:133
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed)
Definition: hash_mm3.c:86
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
#define STRNCPY(dst, src)
Definition: BLI_string.h:163
size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string.c:878
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define UNUSED(x)
#define MAX2(a, b)
#define MIN2(a, b)
#define STREQ(a, b)
#define MAX_NAME
Definition: DNA_defs.h:62
eViewLayerCryptomatteFlags
@ VIEW_LAYER_CRYPTOMATTE_MATERIAL
@ VIEW_LAYER_CRYPTOMATTE_ASSET
@ VIEW_LAYER_CRYPTOMATTE_OBJECT
#define VIEW_LAYER_CRYPTOMATTE_ALL
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
ValueIterator values() const
Definition: BLI_map.hh:806
Value & lookup_or_add_default(const Key &key)
Definition: BLI_map.hh:594
ItemIterator items() const
Definition: BLI_map.hh:825
const Value * lookup_ptr(const Key &key) const
Definition: BLI_map.hh:477
constexpr const char * data() const
static constexpr int64_t not_found
constexpr const char & front() const
constexpr int64_t find_last_of(StringRef chars, int64_t pos=INT64_MAX) const
constexpr int64_t find_first_not_of(StringRef chars, int64_t pos=0) const
constexpr bool is_empty() const
constexpr bool startswith(StringRef prefix) const
constexpr StringRef substr(int64_t start, const int64_t size) const
constexpr bool endswith(StringRef suffix) const
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
constexpr int64_t size() const
constexpr StringRef drop_prefix(const int64_t n) const
bool contains(const T &value) const
Definition: BLI_vector.hh:804
void append(const T &value)
Definition: BLI_vector.hh:438
void BKE_cryptomatte_add_layer(struct CryptomatteSession *session, const char *layer_name)
Definition: cryptomatte.cc:161
uint32_t BKE_cryptomatte_hash(const char *name, const int name_len)
Definition: cryptomatte.cc:172
static void add_render_result_meta_data(RenderResult *render_result, const blender::StringRef layer_name, const blender::StringRefNull key_name, const blender::StringRefNull value)
Definition: cryptomatte.cc:314
struct CryptomatteSession * BKE_cryptomatte_init_from_render_result(const struct RenderResult *render_result)
Definition: cryptomatte.cc:148
void BKE_cryptomatte_free(CryptomatteSession *session)
Definition: cryptomatte.cc:166
CryptomatteSession * BKE_cryptomatte_init(void)
Definition: cryptomatte.cc:142
float BKE_cryptomatte_hash_to_float(uint32_t cryptomatte_hash)
Definition: cryptomatte.cc:210
char * BKE_cryptomatte_entries_to_matte_id(NodeCryptomatte *node_storage)
Definition: cryptomatte.cc:230
void BKE_cryptomatte_store_metadata(const struct CryptomatteSession *session, RenderResult *render_result, const ViewLayer *view_layer)
Definition: cryptomatte.cc:325
struct CryptomatteSession * BKE_cryptomatte_init_from_scene(const struct Scene *scene)
Definition: cryptomatte.cc:155
uint32_t BKE_cryptomatte_asset_hash(CryptomatteSession *session, const char *layer_name, const Object *object)
Definition: cryptomatte.cc:199
static uint32_t cryptomatte_determine_identifier(const blender::StringRef name)
Definition: cryptomatte.cc:309
bool BKE_cryptomatte_find_name(const CryptomatteSession *session, const float encoded_hash, char *r_name, int name_len)
Definition: cryptomatte.cc:216
void BKE_cryptomatte_matte_id_to_entries(NodeCryptomatte *node_storage, const char *matte_id)
Definition: cryptomatte.cc:251
uint32_t BKE_cryptomatte_object_hash(CryptomatteSession *session, const char *layer_name, const Object *object)
Definition: cryptomatte.cc:178
static std::string cryptomatte_determine_name(const ViewLayer *view_layer, const blender::StringRefNull cryptomatte_layer_name)
Definition: cryptomatte.cc:300
uint32_t BKE_cryptomatte_material_hash(CryptomatteSession *session, const char *layer_name, const Material *material)
Definition: cryptomatte.cc:187
Scene scene
Material material
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static unsigned c
Definition: RandGen.cpp:97
double sign(double arg)
Definition: utility.h:250
static bool from_manifest(CryptomatteLayer &layer, blender::StringRefNull manifest)
Definition: cryptomatte.cc:391
static constexpr int quoted_string_len_(blender::StringRef ref)
Definition: cryptomatte.cc:357
static std::string unquote_(const blender::StringRef ref)
Definition: cryptomatte.cc:380
static constexpr blender::StringRef skip_whitespaces_(blender::StringRef ref)
Definition: cryptomatte.cc:348
static std::string to_manifest(const CryptomatteLayer *layer)
Definition: cryptomatte.cc:450
StringRef BKE_cryptomatte_extract_layer_name(const StringRef render_pass_name)
Definition: cryptomatte.cc:496
std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name, const StringRefNull key_name)
Definition: cryptomatte.cc:487
static std::string cryptomatte_layer_name_hash(const StringRef layer_name)
Definition: cryptomatte.cc:478
const blender::Vector< std::string > & BKE_cryptomatte_layer_names_get(const CryptomatteSession &session)
Definition: cryptomatte.cc:654
#define hash
Definition: noise.c:169
unsigned int uint32_t
Definition: stdint.h:83
__int64 int64_t
Definition: stdint.h:92
CryptomatteSession()=default
blender::Map< std::string, blender::bke::cryptomatte::CryptomatteLayer > layers
Definition: cryptomatte.cc:53
std::optional< std::string > operator[](float encoded_hash) const
Definition: cryptomatte.cc:131
blender::bke::cryptomatte::CryptomatteLayer & add_layer(std::string layer_name)
Definition: cryptomatte.cc:123
blender::Vector< std::string > layer_names
Definition: cryptomatte.cc:55
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
ListBase materials
Definition: BKE_main.h:152
ListBase objects
Definition: BKE_main.h:148
struct Object * parent
struct StampData * stamp_data
Definition: RE_pipeline.h:157
ListBase view_layers
char name[64]
static CryptomatteHash from_hex_encoded(blender::StringRef hex_encoded)
Definition: cryptomatte.cc:514
void add_hash(blender::StringRef name, CryptomatteHash cryptomatte_hash)
Definition: cryptomatte.cc:572
blender::Map< std::string, CryptomatteHash > hashes
static std::unique_ptr< CryptomatteLayer > read_from_manifest(blender::StringRefNull manifest)
Definition: cryptomatte.cc:553
std::optional< std::string > operator[](float encoded_hash) const
Definition: cryptomatte.cc:577
uint32_t add_ID(const struct ID &id)
Definition: cryptomatte.cc:561
static void extract_layer_names(void *_data, const char *propname, char *propvalue, int len)
Definition: cryptomatte.cc:611
static blender::StringRef extract_layer_hash(blender::StringRefNull key)
Definition: cryptomatte.cc:593
static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int len)
Definition: cryptomatte.cc:630
static const char hex[17]
Definition: thumbs.c:173
uint len