Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Castilla <manzanillawork@gmail.com>2021-08-15 17:33:09 +0300
committerManuel Castilla <manzanillawork@gmail.com>2021-08-15 17:33:09 +0300
commit1be813c8e5721226190fd6b3a8be296c45a52787 (patch)
tree6d218921c06d8493905dff840d66d3c03125afee /source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
parenta9ba0e67ccb90d66a59a7680e9e5c11ac3996c89 (diff)
Compositor: Full frame Luminance Key node
Diffstat (limited to 'source/blender/compositor/operations/COM_LuminanceMatteOperation.cc')
-rw-r--r--source/blender/compositor/operations/COM_LuminanceMatteOperation.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
index 5ca16e40ce3..5ff6be6b8f6 100644
--- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
@@ -78,4 +78,39 @@ void LuminanceMatteOperation::executePixelSampled(float output[4],
output[0] = min_ff(alpha, inColor[3]);
}
+void LuminanceMatteOperation::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 luminance = IMB_colormanagement_get_luminance(color);
+
+ /* One line thread-friend algorithm:
+ * `it.out[0] = MIN2(color[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));`
+ */
+
+ /* Test range. */
+ const float high = m_settings->t1;
+ const float low = m_settings->t2;
+ float alpha;
+ if (luminance > high) {
+ alpha = 1.0f;
+ }
+ else if (luminance < low) {
+ alpha = 0.0f;
+ }
+ else { /* Blend. */
+ alpha = (luminance - low) / (high - low);
+ }
+
+ /* 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[0] = MIN2(alpha, color[3]);
+ }
+}
+
} // namespace blender::compositor