Blender V5.0
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
21struct ID;
22
24
34std::string BKE_cryptomatte_meta_data_key(StringRef layer_name, StringRefNull key_name);
35
52
54 uint32_t hash;
55
56 CryptomatteHash(uint32_t hash);
57 CryptomatteHash(const char *name, int name_len)
58 {
59 hash = BLI_hash_mm3((const unsigned char *)name, name_len, 0);
60 }
61
63 std::string hex_encoded() const;
64
77 float float_encoded() const
78 {
79 uint32_t mantissa = hash & ((1 << 23) - 1);
80 uint32_t exponent = (hash >> 23) & ((1 << 8) - 1);
81 exponent = std::max(exponent, uint32_t(1));
82 exponent = std::min(exponent, uint32_t(254));
83 exponent = exponent << 23;
84 uint32_t sign = (hash >> 31);
85 sign = sign << 31;
86 uint32_t float_bits = sign | exponent | mantissa;
87 float f;
88 memcpy(&f, &float_bits, sizeof(uint32_t));
89 return f;
90 }
91};
92
95
96 MEM_CXX_CLASS_ALLOC_FUNCS("cryptomatte:CryptomatteLayer")
97
99 uint32_t add_ID(const ID &id);
100 void add_hash(blender::StringRef name, CryptomatteHash cryptomatte_hash);
101 std::string manifest() const;
102
103 std::optional<std::string> operator[](float encoded_hash) const;
104};
105
109
116
117 /* C type callback function (StampCallback). */
118 static void extract_layer_names(void *_data,
119 const char *propname,
120 char *propvalue,
121 int propvalue_maxncpy);
122 /* C type callback function (StampCallback). */
123 static void extract_layer_manifest(void *_data,
124 const char *propname,
125 char *propvalue,
126 int propvalue_maxncpy);
127};
128
130 const CryptomatteSession &session);
132
135 {
136 BKE_cryptomatte_free(session);
137 }
138};
139
140using CryptomatteSessionPtr = std::unique_ptr<CryptomatteSession, CryptomatteSessionDeleter>;
141
142} // 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
constexpr T sign(T) RET
StringRef BKE_cryptomatte_extract_layer_name(StringRef render_pass_name)
std::unique_ptr< CryptomatteSession, CryptomatteSessionDeleter > CryptomatteSessionPtr
CryptomatteLayer * BKE_cryptomatte_layer_get(CryptomatteSession &session, StringRef layer_name)
std::string BKE_cryptomatte_meta_data_key(StringRef layer_name, StringRefNull key_name)
const blender::Vector< std::string > & BKE_cryptomatte_layer_names_get(const CryptomatteSession &session)
const char * name
Definition DNA_ID.h:414
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)
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