[Bf-blender-cvs] [d481c6651d1] master: Compositor: Full frame color nodes

Manuel Castilla noreply at git.blender.org
Tue Aug 10 16:26:16 CEST 2021


Commit: d481c6651d149bdc83a8c0bbb675d3d296f7c530
Author: Manuel Castilla
Date:   Tue Aug 10 15:25:10 2021 +0200
Branches: master
https://developer.blender.org/rBd481c6651d149bdc83a8c0bbb675d3d296f7c530

Compositor: Full frame color nodes

Adds full frame implementation to "Alpha Over",
"Hue Saturation Value", "Invert", "Tonemap" and "ZCombine" nodes.
The other nodes in "Color" submenu are implemented separately.
No functional changes.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D12092

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

M	source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
M	source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
M	source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
M	source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
M	source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
M	source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
M	source/blender/compositor/operations/COM_ChangeHSVOperation.cc
M	source/blender/compositor/operations/COM_ChangeHSVOperation.h
M	source/blender/compositor/operations/COM_InvertOperation.cc
M	source/blender/compositor/operations/COM_InvertOperation.h
M	source/blender/compositor/operations/COM_TonemapOperation.cc
M	source/blender/compositor/operations/COM_TonemapOperation.h
M	source/blender/compositor/operations/COM_ZCombineOperation.cc
M	source/blender/compositor/operations/COM_ZCombineOperation.h

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

diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
index 0c656753a51..30e7fab4027 100644
--- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
+++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc
@@ -20,6 +20,11 @@
 
 namespace blender::compositor {
 
+AlphaOverKeyOperation::AlphaOverKeyOperation()
+{
+  this->flags.can_be_constant = true;
+}
+
 void AlphaOverKeyOperation::executePixelSampled(float output[4],
                                                 float x,
                                                 float y,
@@ -50,4 +55,29 @@ void AlphaOverKeyOperation::executePixelSampled(float output[4],
   }
 }
 
+void AlphaOverKeyOperation::update_memory_buffer_row(PixelCursor &p)
+{
+  for (; p.out < p.row_end; p.next()) {
+    const float *color1 = p.color1;
+    const float *over_color = p.color2;
+    const float value = *p.value;
+
+    if (over_color[3] <= 0.0f) {
+      copy_v4_v4(p.out, color1);
+    }
+    else if (value == 1.0f && over_color[3] >= 1.0f) {
+      copy_v4_v4(p.out, over_color);
+    }
+    else {
+      const float premul = value * over_color[3];
+      const float mul = 1.0f - premul;
+
+      p.out[0] = (mul * color1[0]) + premul * over_color[0];
+      p.out[1] = (mul * color1[1]) + premul * over_color[1];
+      p.out[2] = (mul * color1[2]) + premul * over_color[2];
+      p.out[3] = (mul * color1[3]) + value * over_color[3];
+    }
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
index 83713d18971..960fbc98fe9 100644
--- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
+++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h
@@ -28,10 +28,14 @@ namespace blender::compositor {
  */
 class AlphaOverKeyOperation : public MixBaseOperation {
  public:
+  AlphaOverKeyOperation();
+
   /**
    * The inner loop of this operation.
    */
   void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+  void update_memory_buffer_row(PixelCursor &p) override;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
index c68c79d2263..0cc179ea209 100644
--- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
+++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc
@@ -23,6 +23,7 @@ namespace blender::compositor {
 AlphaOverMixedOperation::AlphaOverMixedOperation()
 {
   this->m_x = 0.0f;
+  this->flags.can_be_constant = true;
 }
 
 void AlphaOverMixedOperation::executePixelSampled(float output[4],
@@ -56,4 +57,30 @@ void AlphaOverMixedOperation::executePixelSampled(float output[4],
   }
 }
 
+void AlphaOverMixedOperation::update_memory_buffer_row(PixelCursor &p)
+{
+  for (; p.out < p.row_end; p.next()) {
+    const float *color1 = p.color1;
+    const float *over_color = p.color2;
+    const float value = *p.value;
+
+    if (over_color[3] <= 0.0f) {
+      copy_v4_v4(p.out, color1);
+    }
+    else if (value == 1.0f && over_color[3] >= 1.0f) {
+      copy_v4_v4(p.out, over_color);
+    }
+    else {
+      const float addfac = 1.0f - this->m_x + over_color[3] * this->m_x;
+      const float premul = value * addfac;
+      const float mul = 1.0f - value * over_color[3];
+
+      p.out[0] = (mul * color1[0]) + premul * over_color[0];
+      p.out[1] = (mul * color1[1]) + premul * over_color[1];
+      p.out[2] = (mul * color1[2]) + premul * over_color[2];
+      p.out[3] = (mul * color1[3]) + value * over_color[3];
+    }
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
index e2b3af84162..2b88cd5f421 100644
--- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
+++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h
@@ -45,6 +45,8 @@ class AlphaOverMixedOperation : public MixBaseOperation {
   {
     this->m_x = x;
   }
+
+  void update_memory_buffer_row(PixelCursor &p) override;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
index 3dd4607e273..a57e8c7f8a3 100644
--- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
+++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc
@@ -20,6 +20,11 @@
 
 namespace blender::compositor {
 
+AlphaOverPremultiplyOperation::AlphaOverPremultiplyOperation()
+{
+  this->flags.can_be_constant = true;
+}
+
 void AlphaOverPremultiplyOperation::executePixelSampled(float output[4],
                                                         float x,
                                                         float y,
@@ -50,4 +55,28 @@ void AlphaOverPremultiplyOperation::executePixelSampled(float output[4],
   }
 }
 
+void AlphaOverPremultiplyOperation::update_memory_buffer_row(PixelCursor &p)
+{
+  for (; p.out < p.row_end; p.next()) {
+    const float *color1 = p.color1;
+    const float *over_color = p.color2;
+    const float value = *p.value;
+
+    if (over_color[3] <= 0.0f) {
+      copy_v4_v4(p.out, color1);
+    }
+    else if (value == 1.0f && over_color[3] >= 1.0f) {
+      copy_v4_v4(p.out, over_color);
+    }
+    else {
+      const float mul = 1.0f - value * over_color[3];
+
+      p.out[0] = (mul * color1[0]) + value * over_color[0];
+      p.out[1] = (mul * color1[1]) + value * over_color[1];
+      p.out[2] = (mul * color1[2]) + value * over_color[2];
+      p.out[3] = (mul * color1[3]) + value * over_color[3];
+    }
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
index f1d4b668fce..701bc07cc27 100644
--- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
+++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h
@@ -28,10 +28,14 @@ namespace blender::compositor {
  */
 class AlphaOverPremultiplyOperation : public MixBaseOperation {
  public:
+  AlphaOverPremultiplyOperation();
+
   /**
    * The inner loop of this operation.
    */
   void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+  void update_memory_buffer_row(PixelCursor &p) override;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.cc b/source/blender/compositor/operations/COM_ChangeHSVOperation.cc
index eee007ce9e6..1e3e7806968 100644
--- a/source/blender/compositor/operations/COM_ChangeHSVOperation.cc
+++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.cc
@@ -28,6 +28,7 @@ ChangeHSVOperation::ChangeHSVOperation()
   this->addInputSocket(DataType::Value);
   this->addOutputSocket(DataType::Color);
   this->m_inputOperation = nullptr;
+  this->flags.can_be_constant = true;
 }
 
 void ChangeHSVOperation::initExecution()
@@ -71,4 +72,26 @@ void ChangeHSVOperation::executePixelSampled(float output[4],
   output[3] = inputColor1[3];
 }
 
+void ChangeHSVOperation::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);
+    const float hue = *it.in(1);
+    it.out[0] = color[0] + (hue - 0.5f);
+    if (it.out[0] > 1.0f) {
+      it.out[0] -= 1.0f;
+    }
+    else if (it.out[0] < 0.0f) {
+      it.out[0] += 1.0f;
+    }
+    const float saturation = *it.in(2);
+    const float value = *it.in(3);
+    it.out[1] = color[1] * saturation;
+    it.out[2] = color[2] * value;
+    it.out[3] = color[3];
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.h b/source/blender/compositor/operations/COM_ChangeHSVOperation.h
index d38b4be3efe..e7bc3274f25 100644
--- a/source/blender/compositor/operations/COM_ChangeHSVOperation.h
+++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.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 ChangeHSVOperation : public NodeOperation {
+class ChangeHSVOperation : public MultiThreadedOperation {
  private:
   SocketReader *m_inputOperation;
   SocketReader *m_hueOperation;
@@ -46,6 +46,10 @@ class ChangeHSVOperation : public NodeOperation {
    * The inner loop of this operation.
    */
   void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+  void update_memory_buffer_partial(MemoryBuffer *output,
+                                    const rcti &area,
+                                    Span<MemoryBuffer *> inputs) override;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_InvertOperation.cc b/source/blender/compositor/operations/COM_InvertOperation.cc
index 339e40a5d1f..4f71a1d0d1d 100644
--- a/source/blender/compositor/operations/COM_InvertOperation.cc
+++ b/source/blender/compositor/operations/COM_InvertOperation.cc
@@ -30,6 +30,7 @@ InvertOperation::InvertOperation()
   this->m_color = true;
   this->m_alpha = false;
   setResolutionInputSocketIndex(1);
+  this->flags.can_be_constant = true;
 }
 void InvertOperation::initExecution()
 {
@@ -70,4 +71,31 @@ void InvertOperation::deinitExecution()
   this->m_inputColorProgram = nullptr;
 }
 
+void InvertOperation::update_memory_buffer_partia

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list