Blender V5.3
node_composite_combine_color.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_color_c.hh"
6
8
10
11#include "GPU_material.hh"
12
13#include "COM_result.hh"
14
16
18
20
21static void node_init(bNodeTree * /*ntree*/, bNode *node)
22{
23 NodeCMPCombSepColor *data = MEM_new<NodeCMPCombSepColor>(__func__);
25 data->ycc_mode = BLI_YCC_ITU_BT709;
26 node->storage = data;
27}
28
30{
31 b.is_function_node();
32 b.add_input<decl::Float>("Red"_ustr)
33 .default_value(0.0f)
34 .min(0.0f)
35 .max(1.0f)
37 .label_fn([](const bNode &node) {
38 switch (node_storage(node).mode) {
40 default:
41 return IFACE_("Red");
44 return IFACE_("Hue");
47 return IFACE_("Y");
48 }
49 });
50 b.add_input<decl::Float>("Green"_ustr)
51 .default_value(0.0f)
52 .min(0.0f)
53 .max(1.0f)
55 .label_fn([](const bNode &node) {
56 switch (node_storage(node).mode) {
58 default:
59 return IFACE_("Green");
62 return IFACE_("Saturation");
64 return IFACE_("Cb");
66 return IFACE_("U");
67 }
68 });
69 b.add_input<decl::Float>("Blue"_ustr)
70 .default_value(0.0f)
71 .min(0.0f)
72 .max(1.0f)
74 .label_fn([](const bNode &node) {
75 switch (node_storage(node).mode) {
77 default:
78 return IFACE_("Blue");
80 return CTX_IFACE_(BLT_I18NCONTEXT_COLOR, "Value");
82 return IFACE_("Lightness");
84 return IFACE_("Cr");
86 return IFACE_("V");
87 }
88 });
89 b.add_input<decl::Float>("Alpha"_ustr)
90 .default_value(1.0f)
91 .min(0.0f)
92 .max(1.0f)
94 b.add_output<decl::Color>("Image"_ustr);
95}
96
97using namespace blender::compositor;
98
99static int node_gpu_material(GPUMaterial *material,
100 bNode *node,
101 bNodeExecData * /*execdata*/,
102 GPUNodeStack *inputs,
103 GPUNodeStack *outputs)
104{
105 switch (node_storage(*node).mode) {
107 return GPU_stack_link(material, node, "node_composite_combine_rgba", inputs, outputs);
109 return GPU_stack_link(material, node, "node_composite_combine_hsva", inputs, outputs);
111 return GPU_stack_link(material, node, "node_composite_combine_hsla", inputs, outputs);
113 return GPU_stack_link(
114 material, node, "node_composite_combine_yuva_itu_709", inputs, outputs);
116 switch (node_storage(*node).ycc_mode) {
118 return GPU_stack_link(
119 material, node, "node_composite_combine_ycca_itu_601", inputs, outputs);
121 return GPU_stack_link(
122 material, node, "node_composite_combine_ycca_itu_709", inputs, outputs);
124 return GPU_stack_link(
125 material, node, "node_composite_combine_ycca_jpeg", inputs, outputs);
126 }
127 }
128
129 return false;
130}
131
133
135{
136 static auto rgba_function = mf::build::SI4_SO<float, float, float, float, Color>(
137 "Combine Color RGBA",
138 [](const float r, const float g, const float b, const float a) -> Color {
139 return Color(r, g, b, a);
140 },
141 mf::build::exec_presets::Materialized());
142
143 static auto hsva_function = mf::build::SI4_SO<float, float, float, float, Color>(
144 "Combine Color HSVA",
145 [](const float h, const float s, const float v, const float a) -> Color {
147 hsv_to_rgb(h, s, v, &result.r, &result.g, &result.b);
148 result.a = a;
149 return result;
150 },
151 mf::build::exec_presets::Materialized());
152
153 static auto hsla_function = mf::build::SI4_SO<float, float, float, float, Color>(
154 "Combine Color HSLA",
155 [](const float h, const float s, const float l, const float a) -> Color {
157 hsl_to_rgb(h, s, l, &result.r, &result.g, &result.b);
158 result.a = a;
159 return result;
160 },
161 mf::build::exec_presets::Materialized());
162
163 static auto yuva_function = mf::build::SI4_SO<float, float, float, float, Color>(
164 "Combine Color YUVA",
165 [](const float y, const float u, const float v, const float a) -> Color {
168 result.a = a;
169 return result;
170 },
171 mf::build::exec_presets::Materialized());
172
173 static auto ycca_itu_601_function = mf::build::SI4_SO<float, float, float, float, Color>(
174 "Combine Color YCCA ITU 601",
175 [](const float y, const float cb, const float cr, const float a) -> Color {
177 ycc_to_rgb(y * 255.0f,
178 cb * 255.0f,
179 cr * 255.0f,
180 &result.r,
181 &result.g,
182 &result.b,
184 result.a = a;
185 return result;
186 },
187 mf::build::exec_presets::Materialized());
188
189 static auto ycca_itu_709_function = mf::build::SI4_SO<float, float, float, float, Color>(
190 "Combine Color YCCA ITU 709",
191 [](const float y, const float cb, const float cr, const float a) -> Color {
193 ycc_to_rgb(y * 255.0f,
194 cb * 255.0f,
195 cr * 255.0f,
196 &result.r,
197 &result.g,
198 &result.b,
200 result.a = a;
201 return result;
202 },
203 mf::build::exec_presets::Materialized());
204
205 static auto ycca_jpeg_function = mf::build::SI4_SO<float, float, float, float, Color>(
206 "Combine Color YCCA JPEG",
207 [](const float y, const float cb, const float cr, const float a) -> Color {
209 ycc_to_rgb(y * 255.0f,
210 cb * 255.0f,
211 cr * 255.0f,
212 &result.r,
213 &result.g,
214 &result.b,
216 result.a = a;
217 return result;
218 },
219 mf::build::exec_presets::Materialized());
220
221 switch (node_storage(builder.node()).mode) {
223 builder.set_matching_fn(rgba_function);
224 break;
226 builder.set_matching_fn(hsva_function);
227 break;
229 builder.set_matching_fn(hsla_function);
230 break;
232 builder.set_matching_fn(yuva_function);
233 break;
235 switch (node_storage(builder.node()).ycc_mode) {
237 builder.set_matching_fn(ycca_itu_601_function);
238 break;
240 builder.set_matching_fn(ycca_itu_709_function);
241 break;
243 builder.set_matching_fn(ycca_jpeg_function);
244 break;
245 }
246 }
247}
248
249static void node_register()
250{
251 static bke::bNodeType ntype;
252
253 cmp_node_type_base(&ntype, "CompositorNodeCombineColor"_ustr, CMP_NODE_COMBINE_COLOR);
254 ntype.ui_name = "Combine Color";
255 ntype.ui_description = "Combine an image from its composite color channels";
256 ntype.enum_name_legacy = "COMBINE_COLOR";
258 ntype.declare = node_declare;
259 ntype.initfunc = node_init;
261 ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage);
264
266}
268
269} // namespace blender::nodes::node_composite_combine_color_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define CMP_NODE_COMBINE_COLOR
#define BLI_YUV_ITU_BT709
#define BLI_YCC_JFIF_0_255
#define BLI_YCC_ITU_BT601
#define BLI_YCC_ITU_BT709
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_COLOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
ColorSceneLinear4f< eAlpha::Premultiplied > Color
Definition COM_result.hh:96
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:25
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
@ CMP_NODE_COMBSEP_COLOR_HSL
@ CMP_NODE_COMBSEP_COLOR_YCC
@ CMP_NODE_COMBSEP_COLOR_YUV
@ CMP_NODE_COMBSEP_COLOR_HSV
@ CMP_NODE_COMBSEP_COLOR_RGB
ATTR_WARN_UNUSED_RESULT const BMVert * v
BMesh const char void * data
void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:42
void yuv_to_rgb(float y, float u, float v, float *r_r, float *r_g, float *r_b, int colorspace)
Definition math_color.cc:95
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
@ PROP_FACTOR
Definition RNA_types.hh:308
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393