Blender V4.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
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
21#include "BKE_cryptomatte.h"
22
23struct ID;
24
26
36std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name,
37 const StringRefNull key_name);
38
55
58
60 CryptomatteHash(const char *name, int name_len)
61 {
62 hash = BLI_hash_mm3((const unsigned char *)name, name_len, 0);
63 }
64
66 std::string hex_encoded() const;
67
80 float float_encoded() const
81 {
82 uint32_t mantissa = hash & ((1 << 23) - 1);
83 uint32_t exponent = (hash >> 23) & ((1 << 8) - 1);
84 exponent = std::max(exponent, uint32_t(1));
85 exponent = std::min(exponent, uint32_t(254));
86 exponent = exponent << 23;
87 uint32_t sign = (hash >> 31);
88 sign = sign << 31;
89 uint32_t float_bits = sign | exponent | mantissa;
90 float f;
91 memcpy(&f, &float_bits, sizeof(uint32_t));
92 return f;
93 }
94};
95
98
99#ifdef WITH_CXX_GUARDEDALLOC
100 MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteLayer")
101#endif
102
103 static std::unique_ptr<CryptomatteLayer> read_from_manifest(blender::StringRefNull manifest);
104 uint32_t add_ID(const ID &id);
105 void add_hash(blender::StringRef name, CryptomatteHash cryptomatte_hash);
106 std::string manifest() const;
107
108 std::optional<std::string> operator[](float encoded_hash) const;
109};
110
114
121
122 /* C type callback function (StampCallback). */
123 static void extract_layer_names(void *_data,
124 const char *propname,
125 char *propvalue,
126 int propvalue_maxncpy);
127 /* C type callback function (StampCallback). */
128 static void extract_layer_manifest(void *_data,
129 const char *propname,
130 char *propvalue,
131 int propvalue_maxncpy);
132};
133
135 const CryptomatteSession &session);
137 const StringRef layer_name);
138
141 {
142 BKE_cryptomatte_free(session);
143 }
144};
145
146using CryptomatteSessionPtr = std::unique_ptr<CryptomatteSession, CryptomatteSessionDeleter>;
147
148} // namespace blender::bke::cryptomatte
void BKE_cryptomatte_free(struct CryptomatteSession *session)
uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed)
Definition hash_mm3.cc:73
CryptomatteLayer * BKE_cryptomatte_layer_get(CryptomatteSession &session, const StringRef layer_name)
std::unique_ptr< CryptomatteSession, CryptomatteSessionDeleter > CryptomatteSessionPtr
StringRef BKE_cryptomatte_extract_layer_name(const StringRef render_pass_name)
std::string BKE_cryptomatte_meta_data_key(const StringRef layer_name, const StringRefNull key_name)
const blender::Vector< std::string > & BKE_cryptomatte_layer_names_get(const CryptomatteSession &session)
unsigned int uint32_t
Definition stdint.h:80
Definition DNA_ID.h:413
static CryptomatteHash from_hex_encoded(blender::StringRef hex_encoded)
CryptomatteHash(const char *name, int name_len)
void add_hash(blender::StringRef name, CryptomatteHash cryptomatte_hash)
blender::Map< std::string, CryptomatteHash > hashes
static std::unique_ptr< CryptomatteLayer > read_from_manifest(blender::StringRefNull manifest)
std::optional< std::string > operator[](float encoded_hash) const
static void extract_layer_manifest(void *_data, const char *propname, char *propvalue, int propvalue_maxncpy)
static blender::StringRef extract_layer_hash(blender::StringRefNull key)
static void extract_layer_names(void *_data, const char *propname, char *propvalue, int propvalue_maxncpy)
blender::Map< std::string, std::string > hash_to_layer_name