[Bf-blender-cvs] [70cc988a907] compositor-full-frame: Compositor: Full frame Channel Key node

Manuel Castilla noreply at git.blender.org
Fri Aug 13 18:24:17 CEST 2021


Commit: 70cc988a907713cd1d0883e5ed5ad81b8de7a78e
Author: Manuel Castilla
Date:   Fri Aug 13 09:15:28 2021 +0200
Branches: compositor-full-frame
https://developer.blender.org/rB70cc988a907713cd1d0883e5ed5ad81b8de7a78e

Compositor: Full frame Channel Key node

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

M	source/blender/compositor/operations/COM_ChannelMatteOperation.cc
M	source/blender/compositor/operations/COM_ChannelMatteOperation.h

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

diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
index ec4331dc231..32371885a84 100644
--- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
@@ -121,4 +121,37 @@ void ChannelMatteOperation::executePixelSampled(float output[4],
   output[0] = MIN2(alpha, inColor[3]);
 }
 
+void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
+                                                         const rcti &area,
+                                                         Span<MemoryBuffer *> inputs)
+{
+  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+    const float *color = it.in(0);
+
+    /* Matte operation. */
+    float alpha = color[this->m_ids[0]] - MAX2(color[this->m_ids[1]], color[this->m_ids[2]]);
+
+    /* Flip because 0.0 is transparent, not 1.0. */
+    alpha = 1.0f - alpha;
+
+    /* Test range. */
+    if (alpha > m_limit_max) {
+      alpha = color[3]; /* Whatever it was prior. */
+    }
+    else if (alpha < m_limit_min) {
+      alpha = 0.0f;
+    }
+    else { /* Blend. */
+      alpha = (alpha - m_limit_min) / m_limit_range;
+    }
+
+    /* Store matte(alpha) value in [0] to go with
+     * COM_SetAlphaMultiplyOperation and the Value output.
+     */
+
+    /* Don't make something that was more transparent less transparent. */
+    *it.out = MIN2(alpha, color[3]);
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.h b/source/blender/compositor/operations/COM_ChannelMatteOperation.h
index 6e9dcccd36e..ba50105dd3b 100644
--- a/source/blender/compositor/operations/COM_ChannelMatteOperation.h
+++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.h
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include "COM_MixOperation.h"
+#include "COM_MultiThreadedOperation.h"
 
 namespace blender::compositor {
 
@@ -26,7 +26,7 @@ namespace blender::compositor {
  * this program converts an input color to an output value.
  * it assumes we are in sRGB color space.
  */
-class ChannelMatteOperation : public NodeOperation {
+class ChannelMatteOperation : public MultiThreadedOperation {
  private:
   SocketReader *m_inputImageProgram;
 
@@ -71,6 +71,10 @@ class ChannelMatteOperation : public NodeOperation {
     this->m_limit_channel = nodeChroma->channel;
     this->m_matte_channel = custom2;
   }
+
+  void update_memory_buffer_partial(MemoryBuffer *output,
+                                    const rcti &area,
+                                    Span<MemoryBuffer *> inputs) override;
 };
 
 }  // namespace blender::compositor



More information about the Bf-blender-cvs mailing list