[Bf-blender-cvs] [c02ff5222e0] ui-asset-view-template: Cleanup: Make node_composite_cryptomatte CPP.

Jeroen Bakker noreply at git.blender.org
Wed Mar 3 21:45:20 CET 2021


Commit: c02ff5222e09686beb5c444a7307ae4ca1cda65d
Author: Jeroen Bakker
Date:   Wed Mar 3 12:34:03 2021 +0100
Branches: ui-asset-view-template
https://developer.blender.org/rBc02ff5222e09686beb5c444a7307ae4ca1cda65d

Cleanup: Make node_composite_cryptomatte CPP.

Core API of cryptomatte is also CPP.

===================================================================

M	source/blender/nodes/CMakeLists.txt
R066	source/blender/nodes/composite/nodes/node_composite_cryptomatte.c	source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc

===================================================================

diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 8c5081555fc..50e29d4a447 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -62,7 +62,7 @@ set(SRC
   composite/nodes/node_composite_composite.c
   composite/nodes/node_composite_cornerpin.c
   composite/nodes/node_composite_crop.c
-  composite/nodes/node_composite_cryptomatte.c
+  composite/nodes/node_composite_cryptomatte.cc
   composite/nodes/node_composite_curves.c
   composite/nodes/node_composite_defocus.c
   composite/nodes/node_composite_denoise.c
diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
similarity index 66%
rename from source/blender/nodes/composite/nodes/node_composite_cryptomatte.c
rename to source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
index f5308fe2671..8705c230e57 100644
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
@@ -27,36 +27,40 @@
 #include "BLI_utildefines.h"
 #include "node_composite_util.h"
 
-static CryptomatteEntry *cryptomatte_find(NodeCryptomatte *n, float encoded_hash)
+#include <optional>
+
+extern "C" {
+static std::optional<CryptomatteEntry *> cryptomatte_find(const NodeCryptomatte &n,
+                                                          float encoded_hash)
 {
-  LISTBASE_FOREACH (CryptomatteEntry *, entry, &n->entries) {
+  LISTBASE_FOREACH (CryptomatteEntry *, entry, &n.entries) {
     if (entry->encoded_hash == encoded_hash) {
-      return entry;
+      return std::make_optional(entry);
     }
   }
-  return NULL;
+  return std::nullopt;
 }
 
-static void cryptomatte_add(NodeCryptomatte *n, float f)
+static void cryptomatte_add(NodeCryptomatte &n, float f)
 {
   /* Check if entry already exist. */
-  if (cryptomatte_find(n, f) != NULL) {
+  if (cryptomatte_find(n, f)) {
     return;
   }
-  CryptomatteEntry *entry = MEM_callocN(sizeof(CryptomatteEntry), __func__);
+  CryptomatteEntry *entry = static_cast<CryptomatteEntry *>(
+      MEM_callocN(sizeof(CryptomatteEntry), __func__));
   entry->encoded_hash = f;
-  BLI_addtail(&n->entries, entry);
+  BLI_addtail(&n.entries, entry);
 }
 
-static void cryptomatte_remove(NodeCryptomatte *n, float f)
+static void cryptomatte_remove(NodeCryptomatte &n, float f)
 {
-  CryptomatteEntry *entry = cryptomatte_find(n, f);
-  if (entry == NULL) {
+  std::optional<CryptomatteEntry *> entry = cryptomatte_find(n, f);
+  if (!entry) {
     return;
   }
-
-  BLI_remlink(&n->entries, entry);
-  MEM_freeN(entry);
+  BLI_remlink(&n.entries, entry.value());
+  MEM_freeN(entry.value());
 }
 
 static bNodeSocketTemplate outputs[] = {
@@ -68,9 +72,9 @@ static bNodeSocketTemplate outputs[] = {
 
 void ntreeCompositCryptomatteSyncFromAdd(bNodeTree *UNUSED(ntree), bNode *node)
 {
-  NodeCryptomatte *n = node->storage;
+  NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
   if (n->add[0] != 0.0f) {
-    cryptomatte_add(n, n->add[0]);
+    cryptomatte_add(*n, n->add[0]);
     n->add[0] = 0.0f;
     n->add[1] = 0.0f;
     n->add[2] = 0.0f;
@@ -79,9 +83,9 @@ void ntreeCompositCryptomatteSyncFromAdd(bNodeTree *UNUSED(ntree), bNode *node)
 
 void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *UNUSED(ntree), bNode *node)
 {
-  NodeCryptomatte *n = node->storage;
+  NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
   if (n->remove[0] != 0.0f) {
-    cryptomatte_remove(n, n->remove[0]);
+    cryptomatte_remove(*n, n->remove[0]);
     n->remove[0] = 0.0f;
     n->remove[1] = 0.0f;
     n->remove[2] = 0.0f;
@@ -90,22 +94,22 @@ void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *UNUSED(ntree), bNode *nod
 
 bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node)
 {
-  NodeCryptomatte *n = node->storage;
+  NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
   char sockname[32];
   n->num_inputs++;
   BLI_snprintf(sockname, sizeof(sockname), "Crypto %.2d", n->num_inputs - 1);
   bNodeSocket *sock = nodeAddStaticSocket(
-      ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, sockname);
+      ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, nullptr, sockname);
   return sock;
 }
 
 int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node)
 {
-  NodeCryptomatte *n = node->storage;
+  NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
   if (n->num_inputs < 2) {
     return 0;
   }
-  bNodeSocket *sock = node->inputs.last;
+  bNodeSocket *sock = static_cast<bNodeSocket *>(node->inputs.last);
   nodeRemoveSocket(ntree, node, sock);
   n->num_inputs--;
   return 1;
@@ -113,7 +117,8 @@ int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node)
 
 static void init(bNodeTree *ntree, bNode *node)
 {
-  NodeCryptomatte *user = MEM_callocN(sizeof(NodeCryptomatte), "cryptomatte user");
+  NodeCryptomatte *user = static_cast<NodeCryptomatte *>(
+      MEM_callocN(sizeof(NodeCryptomatte), __func__));
   node->storage = user;
 
   nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "image", "Image");
@@ -126,7 +131,7 @@ static void init(bNodeTree *ntree, bNode *node)
 
 static void node_free_cryptomatte(bNode *node)
 {
-  NodeCryptomatte *nc = node->storage;
+  NodeCryptomatte *nc = static_cast<NodeCryptomatte *>(node->storage);
 
   if (nc) {
     BLI_freelistN(&nc->entries);
@@ -138,8 +143,8 @@ static void node_copy_cryptomatte(bNodeTree *UNUSED(dest_ntree),
                                   bNode *dest_node,
                                   const bNode *src_node)
 {
-  NodeCryptomatte *src_nc = src_node->storage;
-  NodeCryptomatte *dest_nc = MEM_dupallocN(src_nc);
+  NodeCryptomatte *src_nc = static_cast<NodeCryptomatte *>(src_node->storage);
+  NodeCryptomatte *dest_nc = static_cast<NodeCryptomatte *>(MEM_dupallocN(src_nc));
 
   BLI_duplicatelist(&dest_nc->entries, &src_nc->entries);
   dest_node->storage = dest_nc;
@@ -150,8 +155,9 @@ void register_node_type_cmp_cryptomatte(void)
   static bNodeType ntype;
 
   cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE, "Cryptomatte", NODE_CLASS_CONVERTOR, 0);
-  node_type_socket_templates(&ntype, NULL, outputs);
+  node_type_socket_templates(&ntype, nullptr, outputs);
   node_type_init(&ntype, init);
   node_type_storage(&ntype, "NodeCryptomatte", node_free_cryptomatte, node_copy_cryptomatte);
   nodeRegisterType(&ntype);
 }
+}



More information about the Bf-blender-cvs mailing list