Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/operations/COM_BrightnessOperation.cc
| Show All 22 Lines | |||||
| BrightnessOperation::BrightnessOperation() | BrightnessOperation::BrightnessOperation() | ||||
| { | { | ||||
| this->addInputSocket(DataType::Color); | this->addInputSocket(DataType::Color); | ||||
| this->addInputSocket(DataType::Value); | this->addInputSocket(DataType::Value); | ||||
| this->addInputSocket(DataType::Value); | this->addInputSocket(DataType::Value); | ||||
| this->addOutputSocket(DataType::Color); | this->addOutputSocket(DataType::Color); | ||||
| this->m_inputProgram = nullptr; | this->m_inputProgram = nullptr; | ||||
| this->m_use_premultiply = false; | this->m_use_premultiply = false; | ||||
| flags.can_be_constant = true; | |||||
| } | } | ||||
| void BrightnessOperation::setUsePremultiply(bool use_premultiply) | void BrightnessOperation::setUsePremultiply(bool use_premultiply) | ||||
| { | { | ||||
| this->m_use_premultiply = use_premultiply; | this->m_use_premultiply = use_premultiply; | ||||
| } | } | ||||
| void BrightnessOperation::initExecution() | void BrightnessOperation::initExecution() | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void BrightnessOperation::executePixelSampled(float output[4], | ||||
| output[1] = a * inputValue[1] + b; | output[1] = a * inputValue[1] + b; | ||||
| output[2] = a * inputValue[2] + b; | output[2] = a * inputValue[2] + b; | ||||
| output[3] = inputValue[3]; | output[3] = inputValue[3]; | ||||
| if (this->m_use_premultiply) { | if (this->m_use_premultiply) { | ||||
| straight_to_premul_v4(output); | straight_to_premul_v4(output); | ||||
| } | } | ||||
| } | } | ||||
| 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() | void BrightnessOperation::deinitExecution() | ||||
| { | { | ||||
| this->m_inputProgram = nullptr; | this->m_inputProgram = nullptr; | ||||
| this->m_inputBrightnessProgram = nullptr; | this->m_inputBrightnessProgram = nullptr; | ||||
| this->m_inputContrastProgram = nullptr; | this->m_inputContrastProgram = nullptr; | ||||
| } | } | ||||
| } // namespace blender::compositor | } // namespace blender::compositor | ||||