Blender  V2.93
COM_MetaData.h
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  * Copyright 2021, Blender Foundation.
17  */
18 
19 #pragma once
20 
21 #include <string>
22 
23 #include "BKE_cryptomatte.hh"
24 #include "BLI_map.hh"
25 
26 #include "MEM_guardedalloc.h"
27 
28 /* Forward declarations. */
29 struct RenderResult;
30 
31 namespace blender::compositor {
32 
33 /* Cryptomatte includes hash in its meta data keys. The hash is generated from the render
34  * layer/pass name. Compositing happens without the knowledge of the original layer and pass. The
35  * next keys are used to transfer the cryptomatte meta data in a neutral way. The file output node
36  * will generate a hash based on the layer name configured by the user.
37  *
38  * The `{hash}` has no special meaning except to make sure that the meta data stays unique. */
39 constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_HASH("cryptomatte/{hash}/hash");
40 constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_CONVERSION("cryptomatte/{hash}/conversion");
41 constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_MANIFEST("cryptomatte/{hash}/manifest");
42 constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_NAME("cryptomatte/{hash}/name");
43 
44 class MetaData {
45  private:
47  void addCryptomatteEntry(const blender::StringRef layer_name,
48  const blender::StringRefNull key,
49  const blender::StringRef value);
50 
51  public:
52  void add(const blender::StringRef key, const blender::StringRef value);
54  void addToRenderResult(RenderResult *render_result) const;
55 #ifdef WITH_CXX_GUARDEDALLOC
56  MEM_CXX_CLASS_ALLOC_FUNCS("COM:MetaData")
57 #endif
58 };
59 
61  std::unique_ptr<MetaData> meta_data;
62  std::string hash_key;
63  std::string conversion_key;
64  std::string manifest_key;
65 
67  void setCryptomatteKeys(blender::StringRef cryptomatte_layer_name);
68  /* C type callback function (StampCallback). */
69  static void extract_cryptomatte_meta_data(void *_data,
70  const char *propname,
71  char *propvalue,
72  int UNUSED(len));
73 };
74 
75 } // namespace blender::compositor
#define UNUSED(x)
Read Guarded memory(de)allocation.
void replaceHashNeutralCryptomatteKeys(const blender::StringRef layer_name)
Definition: COM_MetaData.cc:45
void add(const blender::StringRef key, const blender::StringRef value)
Definition: COM_MetaData.cc:29
void addToRenderResult(RenderResult *render_result) const
Definition: COM_MetaData.cc:67
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_CONVERSION("cryptomatte/{hash}/conversion")
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_HASH("cryptomatte/{hash}/hash")
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_MANIFEST("cryptomatte/{hash}/manifest")
constexpr blender::StringRef META_DATA_KEY_CRYPTOMATTE_NAME("cryptomatte/{hash}/name")
void setCryptomatteKeys(blender::StringRef cryptomatte_layer_name)
Definition: COM_MetaData.cc:82
static void extract_cryptomatte_meta_data(void *_data, const char *propname, char *propvalue, int UNUSED(len))
Definition: COM_MetaData.cc:92
void addMetaData(blender::StringRef key, blender::StringRefNull value)
Definition: COM_MetaData.cc:74
uint len