diff options
author | Manuel Castilla <manzanillawork@gmail.com> | 2021-07-19 20:44:10 +0300 |
---|---|---|
committer | Manuel Castilla <manzanillawork@gmail.com> | 2021-07-19 23:05:39 +0300 |
commit | 9aa88a66040e0f93df5e68a28436056dec94524a (patch) | |
tree | b7070e2ce17fdcb8ae31d542bd8e3b16938d9810 /source/blender/compositor | |
parent | b35efa932e03232057e10a4c06291bd362d0cd56 (diff) |
Compositor: Full frame Brightness node
Adds full frame implementation to this node operation.
No functional changes.
2.4x faster than tiled fallback.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D11677
Diffstat (limited to 'source/blender/compositor')
-rw-r--r-- | source/blender/compositor/operations/COM_BrightnessOperation.cc | 45 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_BrightnessOperation.h | 8 |
2 files changed, 51 insertions, 2 deletions
diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.cc b/source/blender/compositor/operations/COM_BrightnessOperation.cc index 92cab47318a..7878eca2bbd 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.cc +++ b/source/blender/compositor/operations/COM_BrightnessOperation.cc @@ -28,6 +28,7 @@ BrightnessOperation::BrightnessOperation() this->addOutputSocket(DataType::Color); this->m_inputProgram = nullptr; this->m_use_premultiply = false; + flags.can_be_constant = true; } void BrightnessOperation::setUsePremultiply(bool use_premultiply) @@ -85,6 +86,50 @@ void BrightnessOperation::executePixelSampled(float output[4], } } +void BrightnessOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) +{ + float tmp_color[4]; + for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) { + const float *in_color = it.in(0); + const float brightness = *it.in(1) / 100.0f; + const float contrast = *it.in(2); + float delta = contrast / 200.0f; + /* + * The algorithm is by Werner D. Streidt + * (http://visca.com/ffactory/archives/5-99/msg00021.html) + * Extracted of OpenCV demhist.c + */ + float a, b; + if (contrast > 0) { + a = 1.0f - delta * 2.0f; + a = 1.0f / max_ff(a, FLT_EPSILON); + b = a * (brightness - delta); + } + else { + delta *= -1; + a = max_ff(1.0f - delta * 2.0f, 0.0f); + b = a * brightness + delta; + } + const float *color; + if (this->m_use_premultiply) { + premul_to_straight_v4_v4(tmp_color, in_color); + color = tmp_color; + } + else { + color = in_color; + } + it.out[0] = a * color[0] + b; + it.out[1] = a * color[1] + b; + it.out[2] = a * color[2] + b; + it.out[3] = color[3]; + if (this->m_use_premultiply) { + straight_to_premul_v4(it.out); + } + } +} + void BrightnessOperation::deinitExecution() { this->m_inputProgram = nullptr; diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.h b/source/blender/compositor/operations/COM_BrightnessOperation.h index 7c33e0b35ec..64b4fa0dbe2 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.h +++ b/source/blender/compositor/operations/COM_BrightnessOperation.h @@ -18,11 +18,11 @@ #pragma once -#include "COM_NodeOperation.h" +#include "COM_MultiThreadedOperation.h" namespace blender::compositor { -class BrightnessOperation : public NodeOperation { +class BrightnessOperation : public MultiThreadedOperation { private: /** * Cached reference to the inputProgram @@ -52,6 +52,10 @@ class BrightnessOperation : public NodeOperation { void deinitExecution() override; void setUsePremultiply(bool use_premultiply); + + void update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) override; }; } // namespace blender::compositor |