Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/operations/COM_GlareThresholdOperation.cc
| Show All 17 Lines | |||||
| #include "COM_GlareThresholdOperation.h" | #include "COM_GlareThresholdOperation.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| namespace blender::compositor { | namespace blender::compositor { | ||||
| GlareThresholdOperation::GlareThresholdOperation() | GlareThresholdOperation::GlareThresholdOperation() : FullFrameBufferedOperation(DataType::Color) | ||||
| { | { | ||||
| this->addInputSocket(DataType::Color, ResizeMode::FitAny); | this->addInputSocket(DataType::Color, ResizeMode::FitAny); | ||||
| this->addOutputSocket(DataType::Color); | this->addOutputSocket(DataType::Color); | ||||
| this->m_inputProgram = nullptr; | this->m_inputProgram = nullptr; | ||||
| } | } | ||||
| void GlareThresholdOperation::determineResolution(unsigned int resolution[2], | void GlareThresholdOperation::determineResolution(unsigned int resolution[2], | ||||
| unsigned int preferredResolution[2]) | unsigned int preferredResolution[2]) | ||||
| { | { | ||||
| NodeOperation::determineResolution(resolution, preferredResolution); | NodeOperation::determineResolution(resolution, preferredResolution); | ||||
| resolution[0] = resolution[0] / (1 << this->m_settings->quality); | resolution[0] = resolution[0] / (1 << this->m_settings->quality); | ||||
| resolution[1] = resolution[1] / (1 << this->m_settings->quality); | resolution[1] = resolution[1] / (1 << this->m_settings->quality); | ||||
| } | } | ||||
| void GlareThresholdOperation::initExecution() | void GlareThresholdOperation::initExecution() | ||||
| { | { | ||||
| FullFrameBufferedOperation::initExecution(); | |||||
| this->m_inputProgram = this->getInputSocketReader(0); | this->m_inputProgram = this->getInputSocketReader(0); | ||||
| } | } | ||||
| void GlareThresholdOperation::executePixelSampled(float output[4], | void GlareThresholdOperation::executePixelSampled(float output[4], | ||||
| float x, | float x, | ||||
| float y, | float y, | ||||
| PixelSampler sampler) | PixelSampler sampler) | ||||
| { | { | ||||
| Show All 9 Lines | if (IMB_colormanagement_get_luminance(output) >= threshold) { | ||||
| output[1] = MAX2(output[1], 0.0f); | output[1] = MAX2(output[1], 0.0f); | ||||
| output[2] = MAX2(output[2], 0.0f); | output[2] = MAX2(output[2], 0.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| zero_v3(output); | zero_v3(output); | ||||
| } | } | ||||
| } | } | ||||
| void GlareThresholdOperation::update_memory_buffer(MemoryBuffer *output_buffer, | |||||
| rcti *output_rect, | |||||
| blender::Span<MemoryBuffer *> inputs) | |||||
| { | |||||
| MemoryBuffer &output = *output_buffer; | |||||
| MemoryBuffer &input = *inputs[0]; | |||||
| int start_x = output_rect->xmin; | |||||
| for (int y = output_rect->ymin; y < output_rect->ymax; y++) { | |||||
| float *output_elem = output.get_elem(start_x, y); | |||||
| const float *output_row_end = output.get_row_end(y); | |||||
| const float *input_elem = input.get_elem(start_x, y); | |||||
| while (output_elem < output_row_end) { | |||||
| const float threshold = this->m_settings->threshold; | |||||
| if (IMB_colormanagement_get_luminance(input_elem) >= threshold) { | |||||
| copy_v3_v3(output_elem, input_elem); | |||||
| output_elem[0] -= threshold; | |||||
| output_elem[1] -= threshold; | |||||
| output_elem[2] -= threshold; | |||||
| output_elem[0] = MAX2(output_elem[0], 0.0f); | |||||
| output_elem[1] = MAX2(output_elem[1], 0.0f); | |||||
| output_elem[2] = MAX2(output_elem[2], 0.0f); | |||||
| } | |||||
| else { | |||||
| zero_v3(output_elem); | |||||
| } | |||||
| output_elem[3] = input_elem[3]; | |||||
| output_elem += output.elem_jump; | |||||
| input_elem += input.elem_jump; | |||||
| } | |||||
| } | |||||
| } | |||||
| void GlareThresholdOperation::deinitExecution() | void GlareThresholdOperation::deinitExecution() | ||||
| { | { | ||||
| FullFrameBufferedOperation::deinitExecution(); | |||||
| this->m_inputProgram = nullptr; | this->m_inputProgram = nullptr; | ||||
| } | } | ||||
| } // namespace blender::compositor | } // namespace blender::compositor | ||||