Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-01-10 10:57:53 +0300
committerJeroen Bakker <jeroen@blender.org>2022-01-10 10:59:00 +0300
commit6beaa297918b24de00d26886e981312b041748b0 (patch)
treec81515e9f1c9e65dbb789e56c1032624db167fca /source/blender/compositor
parenteb7333e772bd9313bf3530eb02e0d036563efe90 (diff)
Compositing Convert color space node
Compositor node to convert between color spaces. Conversion is skipped when converting between the same color spaces or to or from data spaces. Implementation done for tiled and full frame compositor. Reviewed By: Blendify, jbakker Differential Revision: https://developer.blender.org/D12481
Diffstat (limited to 'source/blender/compositor')
-rw-r--r--source/blender/compositor/CMakeLists.txt5
-rw-r--r--source/blender/compositor/intern/COM_Converter.cc4
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.cc17
-rw-r--r--source/blender/compositor/intern/COM_MemoryBuffer.h7
-rw-r--r--source/blender/compositor/nodes/COM_ConvertColorSpaceNode.cc100
-rw-r--r--source/blender/compositor/nodes/COM_ConvertColorSpaceNode.h46
-rw-r--r--source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc91
-rw-r--r--source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h57
8 files changed, 327 insertions, 0 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 10e385e0187..f59fd885871 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -39,6 +39,7 @@ set(INC
../../../extern/clew/include
../../../intern/atomic
../../../intern/guardedalloc
+ ../../../intern/clog
)
set(INC_SYS
@@ -242,6 +243,8 @@ set(SRC
nodes/COM_ColorToBWNode.h
nodes/COM_ConvertAlphaNode.cc
nodes/COM_ConvertAlphaNode.h
+ nodes/COM_ConvertColorSpaceNode.cc
+ nodes/COM_ConvertColorSpaceNode.h
nodes/COM_GammaNode.cc
nodes/COM_GammaNode.h
nodes/COM_HueSaturationValueCorrectNode.cc
@@ -567,6 +570,8 @@ set(SRC
operations/COM_DotproductOperation.cc
operations/COM_DotproductOperation.h
+ operations/COM_ConvertColorSpaceOperation.cc
+ operations/COM_ConvertColorSpaceOperation.h
# Matte operation
operations/COM_BoxMaskOperation.cc
diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc
index 0af4ff7d98d..1b98a04cf96 100644
--- a/source/blender/compositor/intern/COM_Converter.cc
+++ b/source/blender/compositor/intern/COM_Converter.cc
@@ -46,6 +46,7 @@
#include "COM_CombineColorNode.h"
#include "COM_CompositorNode.h"
#include "COM_ConvertAlphaNode.h"
+#include "COM_ConvertColorSpaceNode.h"
#include "COM_ConvertOperation.h"
#include "COM_Converter.h"
#include "COM_CornerPinNode.h"
@@ -426,6 +427,9 @@ Node *COM_convert_bnode(bNode *b_node)
case CMP_NODE_POSTERIZE:
node = new PosterizeNode(b_node);
break;
+ case CMP_NODE_CONVERT_COLOR_SPACE:
+ node = new ConvertColorSpaceNode(b_node);
+ break;
}
return node;
}
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc
index ae925f796ee..dcc279e3b88 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cc
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc
@@ -289,6 +289,23 @@ void MemoryBuffer::copy_from(const uchar *src,
}
}
+void MemoryBuffer::apply_processor(ColormanageProcessor &processor, const rcti area)
+{
+ const int width = BLI_rcti_size_x(&area);
+ const int height = BLI_rcti_size_y(&area);
+ float *out = get_elem(area.xmin, area.ymin);
+ /* If area allows continuous memory do conversion in one step. Otherwise per row. */
+ if (get_width() == width) {
+ IMB_colormanagement_processor_apply(&processor, out, width, height, get_num_channels(), false);
+ }
+ else {
+ for (int y = 0; y < height; y++) {
+ IMB_colormanagement_processor_apply(&processor, out, width, 1, get_num_channels(), false);
+ out += row_stride;
+ }
+ }
+}
+
static void colorspace_to_scene_linear(MemoryBuffer *buf, const rcti &area, ColorSpace *colorspace)
{
const int width = BLI_rcti_size_x(&area);
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index dd18a7403da..1765fb93035 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -26,6 +26,8 @@
#include "BLI_math_interp.h"
#include "BLI_rect.h"
+#include "IMB_colormanagement.h"
+
struct ImBuf;
namespace blender::compositor {
@@ -578,6 +580,11 @@ class MemoryBuffer {
return state_ == MemoryBufferState::Temporary;
}
+ /**
+ * \brief Apply a color processor on the given area.
+ */
+ void apply_processor(ColormanageProcessor &processor, const rcti area);
+
void copy_from(const MemoryBuffer *src, const rcti &area);
void copy_from(const MemoryBuffer *src, const rcti &area, int to_x, int to_y);
void copy_from(const MemoryBuffer *src,
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
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
diff --git a/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h
new file mode 100644
index 00000000000..c065224eadc
--- /dev/null
+++ b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h
@@ -0,0 +1,57 @@
+/*
+ * 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_ConvertColorSpaceNode.h"
+#include "COM_MultiThreadedOperation.h"
+#include "IMB_colormanagement.h"
+
+namespace blender::compositor {
+
+class ConvertColorSpaceOperation : public MultiThreadedOperation {
+ private:
+ SocketReader *input_program_;
+ NodeConvertColorSpace *settings_;
+ ColormanageProcessor *color_processor_;
+
+ public:
+ ConvertColorSpaceOperation();
+
+ void set_settings(NodeConvertColorSpace *node_color_space);
+ /**
+ * The inner loop of this operation.
+ */
+ void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override;
+
+ /**
+ * Initialize the execution
+ */
+ void init_execution() override;
+
+ /**
+ * Deinitialize the execution
+ */
+ void deinit_execution() override;
+
+ void update_memory_buffer_partial(MemoryBuffer *output,
+ const rcti &area,
+ Span<MemoryBuffer *> inputs) override;
+};
+
+} // namespace blender::compositor