diff options
author | Manuel Castilla <manzanillawork@gmail.com> | 2021-08-23 16:30:31 +0300 |
---|---|---|
committer | Manuel Castilla <manzanillawork@gmail.com> | 2021-08-23 18:08:45 +0300 |
commit | daa7c59e38c8fe464004b3becd6956b880c38c92 (patch) | |
tree | c579e1eb7908bc24429fad527b9ae58fda4c67d7 /source/blender/compositor/operations/COM_GammaCorrectOperation.cc | |
parent | 344aca3b1bf2718904455ea6cef1ffd8bedf51a6 (diff) |
Compositor: Full frame Bokeh Blur and Blur nodes
Adds full frame implementation to these nodes operations.
When enabling "extend bounds" node option, tiled implementation
result is slightly different because it's using `TranslateOperation`
with bilinear sampling for centering.
Full frame always uses nearest to don't lose image quality.
It has the disadvantage of causing image jiggling on backdrop
when switching size values as it's not pixel perfect.
This is fixed by rounding to even.
No functional changes.
Part of T88150.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D12167
Diffstat (limited to 'source/blender/compositor/operations/COM_GammaCorrectOperation.cc')
-rw-r--r-- | source/blender/compositor/operations/COM_GammaCorrectOperation.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.cc b/source/blender/compositor/operations/COM_GammaCorrectOperation.cc index 16b79fddd06..1bff3b965c6 100644 --- a/source/blender/compositor/operations/COM_GammaCorrectOperation.cc +++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.cc @@ -26,6 +26,7 @@ GammaCorrectOperation::GammaCorrectOperation() this->addInputSocket(DataType::Color); this->addOutputSocket(DataType::Color); this->m_inputProgram = nullptr; + flags.can_be_constant = true; } void GammaCorrectOperation::initExecution() { @@ -58,6 +59,34 @@ void GammaCorrectOperation::executePixelSampled(float output[4], } } +void GammaCorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) +{ + const MemoryBuffer *input = inputs[0]; + for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) { + float color[4]; + input->read_elem(it.x, it.y, color); + if (color[3] > 0.0f) { + color[0] /= color[3]; + color[1] /= color[3]; + color[2] /= color[3]; + } + + /* Check for negative to avoid nan's. */ + it.out[0] = color[0] > 0.0f ? color[0] * color[0] : 0.0f; + it.out[1] = color[1] > 0.0f ? color[1] * color[1] : 0.0f; + it.out[2] = color[2] > 0.0f ? color[2] * color[2] : 0.0f; + it.out[3] = color[3]; + + if (color[3] > 0.0f) { + it.out[0] *= color[3]; + it.out[1] *= color[3]; + it.out[2] *= color[3]; + } + } +} + void GammaCorrectOperation::deinitExecution() { this->m_inputProgram = nullptr; @@ -68,6 +97,7 @@ GammaUncorrectOperation::GammaUncorrectOperation() this->addInputSocket(DataType::Color); this->addOutputSocket(DataType::Color); this->m_inputProgram = nullptr; + flags.can_be_constant = true; } void GammaUncorrectOperation::initExecution() { @@ -100,6 +130,33 @@ void GammaUncorrectOperation::executePixelSampled(float output[4], } } +void GammaUncorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) +{ + const MemoryBuffer *input = inputs[0]; + for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) { + float color[4]; + input->read_elem(it.x, it.y, color); + if (color[3] > 0.0f) { + color[0] /= color[3]; + color[1] /= color[3]; + color[2] /= color[3]; + } + + it.out[0] = color[0] > 0.0f ? sqrtf(color[0]) : 0.0f; + it.out[1] = color[1] > 0.0f ? sqrtf(color[1]) : 0.0f; + it.out[2] = color[2] > 0.0f ? sqrtf(color[2]) : 0.0f; + it.out[3] = color[3]; + + if (color[3] > 0.0f) { + it.out[0] *= color[3]; + it.out[1] *= color[3]; + it.out[2] *= color[3]; + } + } +} + void GammaUncorrectOperation::deinitExecution() { this->m_inputProgram = nullptr; |