diff options
Diffstat (limited to 'source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc')
-rw-r--r-- | source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc new file mode 100644 index 00000000000..5b1dfb4a02c --- /dev/null +++ b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc @@ -0,0 +1,91 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2021, Blender Foundation. + */ + +#include "COM_ConvertColorSpaceOperation.h" + +namespace blender::compositor { + +ConvertColorSpaceOperation::ConvertColorSpaceOperation() +{ + this->add_input_socket(DataType::Color); + this->add_output_socket(DataType::Color); + this->input_program_ = nullptr; + color_processor_ = nullptr; +} + +void ConvertColorSpaceOperation::set_settings(NodeConvertColorSpace *node_color_space) +{ + this->settings_ = node_color_space; +} + +void ConvertColorSpaceOperation::init_execution() +{ + if (BLI_strnlen(settings_->from_color_space, sizeof(settings_->from_color_space)) == 0 || + BLI_strnlen(settings_->to_color_space, sizeof(settings_->to_color_space)) == 0) { + return; + } + + int in_colorspace_index = IMB_colormanagement_colorspace_get_named_index( + settings_->from_color_space); + int out_colorspace_index = IMB_colormanagement_colorspace_get_named_index( + settings_->to_color_space); + + if (in_colorspace_index == 0 || out_colorspace_index == 0) { + return; + } + + this->input_program_ = this->get_input_socket_reader(0); + + color_processor_ = IMB_colormanagement_colorspace_processor_new(settings_->from_color_space, + settings_->to_color_space); +} + +void ConvertColorSpaceOperation::execute_pixel_sampled(float output[4], + float x, + float y, + PixelSampler sampler) +{ + this->input_program_->read_sampled(output, x, y, sampler); + if (color_processor_ != nullptr) { + IMB_colormanagement_processor_apply_pixel(color_processor_, output, 3); + } +} + +void ConvertColorSpaceOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) +{ + for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) { + copy_v4_v4(it.out, it.in(0)); + } + + if (color_processor_ != nullptr) { + output->apply_processor(*color_processor_, area); + } +} + +void ConvertColorSpaceOperation::deinit_execution() +{ + if (color_processor_ != nullptr) { + IMB_colormanagement_processor_free(color_processor_); + } + this->input_program_ = nullptr; + this->color_processor_ = nullptr; +} + +} // namespace blender::compositor |