Blender V5.3
BKE_cryptomatte.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <algorithm>
12#include <optional>
13#include <string>
14
15#include "BKE_cryptomatte.h"
16
17#include "BLI_hash_mm3.hh"
18#include "BLI_map.hh"
19#include "BLI_string_ref.hh"
20
21namespace blender {
22
23struct ID;
24
26
36std::string BKE_cryptomatte_meta_data_key(StringRef layer_name, StringRefNull key_name);
37
54
57
59 CryptomatteHash(const char *name, int name_len)
60 {
61 hash = BLI_hash_mm3(reinterpret_cast<const unsigned char *>(name), name_len, 0);
62 }
63
65 std::string hex_encoded() const;
66
79 float float_encoded() const
80 {
81 uint32_t mantissa = hash & ((1 << 23) - 1);
82 uint32_t exponent = (hash >> 23) & ((1 << 8) - 1);
83 exponent = std::max(exponent, uint32_t(1));
84 exponent = std::min(exponent, uint32_t(254));
85 exponent = exponent << 23;
86 uint32_t sign = (hash >> 31);
87 sign = sign << 31;
88 uint32_t float_bits = sign | exponent | mantissa;
89 float f;
90 memcpy(&f, &float_bits, sizeof(uint32_t));
91 return f;
92 }
93};
94
97
98 MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteLayer")
99
101 uint32_t add_ID(const ID &id);
102 void add_hash(StringRef name, CryptomatteHash cryptomatte_hash);
103 std::string manifest() const;
104
105 std::optional<std::string> operator[](float encoded_hash) const;
106};
107
111
118
119 /* C type callback function (StampCallback). */
120 static void extract_layer_names(void *_data,
121 const char *propname,
122 char *propvalue,
123 int propvalue_maxncpy);
124 /* C type callback function (StampCallback). */
125 static void extract_layer_manifest(void *_data,
126 const char *propname,
127 char *propvalue,
128 int propvalue_maxncpy);
129};
130
133
136 {
137 BKE_cryptomatte_free(session);
138 }
139};
140
141using CryptomatteSessionPtr = std::unique_ptr<CryptomatteSession, CryptomatteSessionDeleter>;
142
143} // namespace bke::cryptomatte
144} // namespace blender
constexpr T sign(T) RET
StringRef BKE_cryptomatte_extract_layer_name(StringRef render_pass_name)
std::unique_ptr< CryptomatteSession, CryptomatteSessionDeleter > CryptomatteSessionPtr
const Vector< std::string > & BKE_cryptomatte_layer_names_get(const CryptomatteSession &session)
CryptomatteLayer * BKE_cryptomatte_layer_get(CryptomatteSession &session, StringRef layer_name)
std::string BKE_cryptomatte_meta_data_key(StringRef layer_name, StringRefNull key_name)
BMesh Iterators.
uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed)
Definition hash_mm3.cc:75
unsigned int uint32_t
Definition BKE_text.h:81
void BKE_cryptomatte_free(struct CryptomatteSession *session)
static CryptomatteHash from_hex_encoded(StringRef hex_encoded)
CryptomatteHash(const char *name, int name_len)
Map< std::string, CryptomatteHash > hashes
static std::unique_ptr< CryptomatteLayer > read_from_manifest(StringRefNull manifest)
void add_hash(StringRef name, CryptomatteHash cryptomatte_hash)
static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int propvalue_maxncpy)
static StringRef extract_layer_hash(StringRefNull key)
static void extract_layer_names(void *_data, const char *propname, char *propvalue, int propvalue_maxncpy)