From 153b45037f5d27cf125d56ebb9aa77aca53d0981 Mon Sep 17 00:00:00 2001 From: Manuel Castilla Date: Mon, 23 Aug 2021 15:30:46 +0200 Subject: Compositor: Full frame matte nodes Adds full frame implementation to Channel Key, Chroma Key, Color Key, Color Spill, Cryptomatte, Difference Key, Distance Key, Keying, Keying Screen and Luminance Key nodes. The other nodes in "Matte" sub-menu are submitted separately. No functional changes. Part of T88150. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D12220 --- .../operations/COM_ChannelMatteOperation.cc | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source/blender/compositor/operations/COM_ChannelMatteOperation.cc') diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc index ec4331dc231..65742d0cfcc 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc @@ -27,6 +27,7 @@ ChannelMatteOperation::ChannelMatteOperation() addOutputSocket(DataType::Value); this->m_inputImageProgram = nullptr; + flags.can_be_constant = true; } void ChannelMatteOperation::initExecution() @@ -121,4 +122,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 inputs) +{ + for (BuffersIterator 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 -- cgit v1.2.3