diff options
Diffstat (limited to 'source/blender/compositor/nodes')
-rw-r--r-- | source/blender/compositor/nodes/COM_ConvertColorSpaceNode.cc | 100 | ||||
-rw-r--r-- | source/blender/compositor/nodes/COM_ConvertColorSpaceNode.h | 46 |
2 files changed, 146 insertions, 0 deletions
diff --git a/source/blender/compositor/nodes/COM_ConvertColorSpaceNode.cc b/source/blender/compositor/nodes/COM_ConvertColorSpaceNode.cc new file mode 100644 index 00000000000..4e7bbefc22d --- /dev/null +++ b/source/blender/compositor/nodes/COM_ConvertColorSpaceNode.cc @@ -0,0 +1,100 @@ +/* + * 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_ConvertColorSpaceNode.h" + +#include "BKE_node.h" + +#include "BLI_utildefines.h" + +#include "COM_ConvertColorSpaceOperation.h" +#include "COM_ConvertOperation.h" +#include "COM_ExecutionSystem.h" +#include "COM_ImageOperation.h" +#include "COM_MultilayerImageOperation.h" + +#include "CLG_log.h" + +static CLG_LogRef LOG = {"compositor"}; + +namespace blender::compositor { + +ConvertColorSpaceNode::ConvertColorSpaceNode(bNode *editorNode) : Node(editorNode) +{ + /* pass */ +} + +void ConvertColorSpaceNode::convert_to_operations(NodeConverter &converter, + const CompositorContext &UNUSED(context)) const +{ + bNode *b_node = get_bnode(); + + NodeInput *inputSocketImage = this->get_input_socket(0); + NodeOutput *outputSocketImage = this->get_output_socket(0); + + NodeConvertColorSpace *settings = static_cast<NodeConvertColorSpace *>(b_node->storage); + + if (!performs_conversion(*settings)) { + converter.map_output_socket(get_output_socket(0), + converter.add_input_proxy(get_input_socket(0), false)); + return; + } + + ConvertColorSpaceOperation *operation = new ConvertColorSpaceOperation(); + operation->set_settings((NodeConvertColorSpace *)b_node->storage); + converter.add_operation(operation); + + converter.map_input_socket(inputSocketImage, operation->get_input_socket(0)); + converter.map_output_socket(outputSocketImage, operation->get_output_socket()); +} + +bool ConvertColorSpaceNode::performs_conversion(NodeConvertColorSpace &settings) const +{ + bNode *b_node = get_bnode(); + + if (IMB_colormanagement_space_name_is_data(settings.from_color_space)) { + CLOG_INFO(&LOG, + 2, + "Color space conversion bypassed for node: %s. From color space is data: %s.", + b_node->name, + settings.from_color_space); + return false; + } + + if (IMB_colormanagement_space_name_is_data(settings.to_color_space)) { + CLOG_INFO(&LOG, + 2, + "Color space conversion bypassed for node: %s. To color space is data: %s.", + b_node->name, + settings.to_color_space); + return false; + } + + if (STREQLEN( + settings.from_color_space, settings.to_color_space, sizeof(settings.from_color_space))) { + CLOG_INFO(&LOG, + 2, + "Color space conversion bypassed for node: %s. To and from are the same: %s.", + b_node->name, + settings.from_color_space); + return false; + } + return true; +} + +} // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_ConvertColorSpaceNode.h b/source/blender/compositor/nodes/COM_ConvertColorSpaceNode.h new file mode 100644 index 00000000000..b3460abea27 --- /dev/null +++ b/source/blender/compositor/nodes/COM_ConvertColorSpaceNode.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#pragma once + +#include "COM_Node.h" +#include "COM_defines.h" +#include "DNA_image_types.h" +#include "DNA_node_types.h" + +#include "RE_engine.h" +#include "RE_pipeline.h" + +namespace blender::compositor { + +/** + * \brief ImageNode + * \ingroup Node + */ +class ConvertColorSpaceNode : public Node { + public: + ConvertColorSpaceNode(bNode *editorNode); + void convert_to_operations(NodeConverter &converter, + const CompositorContext &context) const override; + + private: + /** \brief check if the given settings changes color space. */ + bool performs_conversion(NodeConvertColorSpace &settings) const; +}; + +} // namespace blender::compositor |