Blender  V2.93
BKE_cryptomatte.hh
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 #pragma once
25 
26 #include <optional>
27 #include <string>
28 
29 #include "BKE_cryptomatte.h"
30 
31 #include "BLI_map.hh"
32 #include "BLI_string_ref.hh"
33 
34 #include "BKE_cryptomatte.h"
35 
36 struct ID;
37 
39 
40 /* Format to a cryptomatte meta data key.
41  *
42  * Cryptomatte stores meta data. The keys are formatted containing a hash that
43  * is generated from its layer name.
44  *
45  * The output of this function is:
46  * 'cryptomatte/{hash of layer_name}/{key_name}'.
47  */
48 std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name,
49  const StringRefNull key_name);
50 
51 /* Extract the cryptomatte layer name from the given `render_pass_name`.
52  *
53  * Cryptomatte passes are formatted with a trailing number for storing multiple samples that belong
54  * to the same cryptomatte layer. This function would remove the trailing numbers to determine the
55  * cryptomatte layer name.
56  *
57  * # Example
58  *
59  * A render_pass_name could be 'View Layer.CryptoMaterial02'. The cryptomatte layer would be 'View
60  * Layer.CryptoMaterial'.
61  *
62  * NOTE: The return type is a sub-string of `render_pass_name` and therefore cannot outlive the
63  * `render_pass_name` internal data.
64  */
66 
69 
71  CryptomatteHash(const char *name, const int name_len);
73 
74  std::string hex_encoded() const;
75  float float_encoded() const;
76 };
77 
80 
81 #ifdef WITH_CXX_GUARDEDALLOC
82  MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteLayer")
83 #endif
84 
85  static std::unique_ptr<CryptomatteLayer> read_from_manifest(blender::StringRefNull manifest);
86  uint32_t add_ID(const struct ID &id);
87  void add_hash(blender::StringRef name, CryptomatteHash cryptomatte_hash);
88  std::string manifest() const;
89 
90  std::optional<std::string> operator[](float encoded_hash) const;
91 };
92 
96 
103 
104  /* C type callback function (StampCallback). */
105  static void extract_layer_names(void *_data, const char *propname, char *propvalue, int len);
106  /* C type callback function (StampCallback). */
107  static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int len);
108 };
109 
111  const CryptomatteSession &session);
112 
115  {
116  BKE_cryptomatte_free(session);
117  }
118 };
119 
120 using CryptomatteSessionPtr = std::unique_ptr<CryptomatteSession, CryptomatteSessionDeleter>;
121 
122 } // namespace blender::bke::cryptomatte
void BKE_cryptomatte_free(struct CryptomatteSession *session)
Definition: cryptomatte.cc:166
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
std::unique_ptr< CryptomatteSession, CryptomatteSessionDeleter > CryptomatteSessionPtr
const blender::Vector< std::string > & BKE_cryptomatte_layer_names_get(const CryptomatteSession &session)
Definition: cryptomatte.cc:654
unsigned int uint32_t
Definition: stdint.h:83
Definition: DNA_ID.h:273
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
blender::Map< std::string, std::string > hash_to_layer_name
uint len