Blender V4.5
node_composite_sepcomb_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_assert.h"
6#include "BLI_math_color.h"
8
10
11#include "NOD_multi_function.hh"
12
13#include "GPU_material.hh"
14
16
17static void node_cmp_combsep_color_init(bNodeTree * /*ntree*/, bNode *node)
18{
21 data->ycc_mode = BLI_YCC_ITU_BT709;
22 node->storage = data;
23}
24
26{
27 bNodeSocket *sock1 = (bNodeSocket *)sockets->first;
28 bNodeSocket *sock2 = sock1->next;
29 bNodeSocket *sock3 = sock2->next;
30
34
35 switch (mode) {
37 node_sock_label(sock1, "Red");
38 node_sock_label(sock2, "Green");
39 node_sock_label(sock3, "Blue");
40 break;
42 node_sock_label(sock1, "Hue");
43 node_sock_label(sock2, "Saturation");
44 node_sock_label(sock3, "Value");
45 break;
47 node_sock_label(sock1, "Hue");
48 node_sock_label(sock2, "Saturation");
49 node_sock_label(sock3, "Lightness");
50 break;
52 node_sock_label(sock1, "Y");
53 node_sock_label(sock2, "Cb");
54 node_sock_label(sock3, "Cr");
55 break;
57 node_sock_label(sock1, "Y");
58 node_sock_label(sock2, "U");
59 node_sock_label(sock3, "V");
60 break;
61 default:
63 break;
64 }
65}
66
67/* **************** SEPARATE COLOR ******************** */
68
70
72
74{
75 b.add_input<decl::Color>("Image")
76 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
77 .compositor_domain_priority(0);
78 b.add_output<decl::Float>("Red");
79 b.add_output<decl::Float>("Green");
80 b.add_output<decl::Float>("Blue");
81 b.add_output<decl::Float>("Alpha");
82}
83
84static void cmp_node_separate_color_update(bNodeTree * /*ntree*/, bNode *node)
85{
86 const NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)node->storage;
88}
89
90using namespace blender::compositor;
91
92static int node_gpu_material(GPUMaterial *material,
93 bNode *node,
94 bNodeExecData * /*execdata*/,
97{
98 switch (node_storage(*node).mode) {
100 return GPU_stack_link(material, node, "node_composite_separate_rgba", inputs, outputs);
102 return GPU_stack_link(material, node, "node_composite_separate_hsva", inputs, outputs);
104 return GPU_stack_link(material, node, "node_composite_separate_hsla", inputs, outputs);
106 return GPU_stack_link(
107 material, node, "node_composite_separate_yuva_itu_709", inputs, outputs);
109 switch (node_storage(*node).ycc_mode) {
111 return GPU_stack_link(
112 material, node, "node_composite_separate_ycca_itu_601", inputs, outputs);
114 return GPU_stack_link(
115 material, node, "node_composite_separate_ycca_itu_709", inputs, outputs);
117 return GPU_stack_link(
118 material, node, "node_composite_separate_ycca_jpeg", inputs, outputs);
119 }
120 }
121
122 return false;
123}
124
126{
127 static auto rgba_function = mf::build::SI1_SO4<float4, float, float, float, float>(
128 "Separate Color RGBA",
129 [](const float4 &color, float &r, float &g, float &b, float &a) -> void {
130 r = color.x;
131 g = color.y;
132 b = color.z;
133 a = color.w;
134 },
135 mf::build::exec_presets::AllSpanOrSingle());
136
137 static auto hsva_function = mf::build::SI1_SO4<float4, float, float, float, float>(
138 "Separate Color HSVA",
139 [](const float4 &color, float &h, float &s, float &v, float &a) -> void {
140 rgb_to_hsv(color.x, color.y, color.z, &h, &s, &v);
141 a = color.w;
142 },
143 mf::build::exec_presets::AllSpanOrSingle());
144
145 static auto hsla_function = mf::build::SI1_SO4<float4, float, float, float, float>(
146 "Separate Color HSLA",
147 [](const float4 &color, float &h, float &s, float &l, float &a) -> void {
148 rgb_to_hsl(color.x, color.y, color.z, &h, &s, &l);
149 a = color.w;
150 },
151 mf::build::exec_presets::AllSpanOrSingle());
152
153 static auto yuva_function = mf::build::SI1_SO4<float4, float, float, float, float>(
154 "Separate Color YUVA",
155 [](const float4 &color, float &y, float &u, float &v, float &a) -> void {
156 rgb_to_yuv(color.x, color.y, color.z, &y, &u, &v, BLI_YUV_ITU_BT709);
157 a = color.w;
158 },
159 mf::build::exec_presets::AllSpanOrSingle());
160
161 static auto ycca_itu_601_function = mf::build::SI1_SO4<float4, float, float, float, float>(
162 "Separate Color YCCA ITU 601",
163 [](const float4 &color, float &y, float &cb, float &cr, float &a) -> void {
164 rgb_to_ycc(color.x, color.y, color.z, &y, &cb, &cr, BLI_YCC_ITU_BT601);
165 y /= 255.0f;
166 cb /= 255.0f;
167 cr /= 255.0f;
168 a = color.w;
169 },
170 mf::build::exec_presets::AllSpanOrSingle());
171
172 static auto ycca_itu_709_function = mf::build::SI1_SO4<float4, float, float, float, float>(
173 "Separate Color YCCA ITU 709",
174 [](const float4 &color, float &y, float &cb, float &cr, float &a) -> void {
175 rgb_to_ycc(color.x, color.y, color.z, &y, &cb, &cr, BLI_YCC_ITU_BT709);
176 y /= 255.0f;
177 cb /= 255.0f;
178 cr /= 255.0f;
179 a = color.w;
180 },
181 mf::build::exec_presets::AllSpanOrSingle());
182
183 static auto ycca_jpeg_function = mf::build::SI1_SO4<float4, float, float, float, float>(
184 "Separate Color YCCA JPEG",
185 [](const float4 &color, float &y, float &cb, float &cr, float &a) -> void {
186 rgb_to_ycc(color.x, color.y, color.z, &y, &cb, &cr, BLI_YCC_JFIF_0_255);
187 y /= 255.0f;
188 cb /= 255.0f;
189 cr /= 255.0f;
190 a = color.w;
191 },
192 mf::build::exec_presets::AllSpanOrSingle());
193
194 switch (node_storage(builder.node()).mode) {
196 builder.set_matching_fn(rgba_function);
197 break;
199 builder.set_matching_fn(hsva_function);
200 break;
202 builder.set_matching_fn(hsla_function);
203 break;
205 builder.set_matching_fn(yuva_function);
206 break;
208 switch (node_storage(builder.node()).ycc_mode) {
210 builder.set_matching_fn(ycca_itu_601_function);
211 break;
213 builder.set_matching_fn(ycca_itu_709_function);
214 break;
216 builder.set_matching_fn(ycca_jpeg_function);
217 break;
218 }
219 }
220}
221
222} // namespace blender::nodes::node_composite_separate_color_cc
223
225{
227
228 static blender::bke::bNodeType ntype;
229
230 cmp_node_type_base(&ntype, "CompositorNodeSeparateColor", CMP_NODE_SEPARATE_COLOR);
231 ntype.ui_name = "Separate Color";
232 ntype.ui_description = "Split an image into its composite color channels";
233 ntype.enum_name_legacy = "SEPARATE_COLOR";
235 ntype.declare = file_ns::cmp_node_separate_color_declare;
238 ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage);
239 ntype.updatefunc = file_ns::cmp_node_separate_color_update;
240 ntype.gpu_fn = file_ns::node_gpu_material;
241 ntype.build_multi_function = file_ns::node_build_multi_function;
242
244}
246
247/* **************** COMBINE COLOR ******************** */
248
250
252
254{
255 b.add_input<decl::Float>("Red")
256 .default_value(0.0f)
257 .min(0.0f)
258 .max(1.0f)
259 .subtype(PROP_FACTOR)
260 .compositor_domain_priority(0);
261 b.add_input<decl::Float>("Green")
262 .default_value(0.0f)
263 .min(0.0f)
264 .max(1.0f)
265 .subtype(PROP_FACTOR)
266 .compositor_domain_priority(1);
267 b.add_input<decl::Float>("Blue")
268 .default_value(0.0f)
269 .min(0.0f)
270 .max(1.0f)
271 .subtype(PROP_FACTOR)
272 .compositor_domain_priority(2);
273 b.add_input<decl::Float>("Alpha")
274 .default_value(1.0f)
275 .min(0.0f)
276 .max(1.0f)
277 .subtype(PROP_FACTOR)
278 .compositor_domain_priority(3);
279 b.add_output<decl::Color>("Image");
280}
281
282static void cmp_node_combine_color_update(bNodeTree * /*ntree*/, bNode *node)
283{
284 const NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)node->storage;
286}
287
288using namespace blender::compositor;
289
290static int node_gpu_material(GPUMaterial *material,
291 bNode *node,
292 bNodeExecData * /*execdata*/,
295{
296 switch (node_storage(*node).mode) {
298 return GPU_stack_link(material, node, "node_composite_combine_rgba", inputs, outputs);
300 return GPU_stack_link(material, node, "node_composite_combine_hsva", inputs, outputs);
302 return GPU_stack_link(material, node, "node_composite_combine_hsla", inputs, outputs);
304 return GPU_stack_link(
305 material, node, "node_composite_combine_yuva_itu_709", inputs, outputs);
307 switch (node_storage(*node).ycc_mode) {
309 return GPU_stack_link(
310 material, node, "node_composite_combine_ycca_itu_601", inputs, outputs);
312 return GPU_stack_link(
313 material, node, "node_composite_combine_ycca_itu_709", inputs, outputs);
315 return GPU_stack_link(
316 material, node, "node_composite_combine_ycca_jpeg", inputs, outputs);
317 }
318 }
319
320 return false;
321}
322
324{
325 static auto rgba_function = mf::build::SI4_SO<float, float, float, float, float4>(
326 "Combine Color RGBA",
327 [](const float r, const float g, const float b, const float a) -> float4 {
328 return float4(r, g, b, a);
329 },
330 mf::build::exec_presets::Materialized());
331
332 static auto hsva_function = mf::build::SI4_SO<float, float, float, float, float4>(
333 "Combine Color HSVA",
334 [](const float h, const float s, const float v, const float a) -> float4 {
336 hsv_to_rgb(h, s, v, &result.x, &result.y, &result.z);
337 result.w = a;
338 return result;
339 },
340 mf::build::exec_presets::Materialized());
341
342 static auto hsla_function = mf::build::SI4_SO<float, float, float, float, float4>(
343 "Combine Color HSLA",
344 [](const float h, const float s, const float l, const float a) -> float4 {
346 hsl_to_rgb(h, s, l, &result.x, &result.y, &result.z);
347 result.w = a;
348 return result;
349 },
350 mf::build::exec_presets::Materialized());
351
352 static auto yuva_function = mf::build::SI4_SO<float, float, float, float, float4>(
353 "Combine Color YUVA",
354 [](const float y, const float u, const float v, const float a) -> float4 {
357 result.w = a;
358 return result;
359 },
360 mf::build::exec_presets::Materialized());
361
362 static auto ycca_itu_601_function = mf::build::SI4_SO<float, float, float, float, float4>(
363 "Combine Color YCCA ITU 601",
364 [](const float y, const float cb, const float cr, const float a) -> float4 {
366 ycc_to_rgb(y * 255.0f,
367 cb * 255.0f,
368 cr * 255.0f,
369 &result.x,
370 &result.y,
371 &result.z,
373 result.w = a;
374 return result;
375 },
376 mf::build::exec_presets::Materialized());
377
378 static auto ycca_itu_709_function = mf::build::SI4_SO<float, float, float, float, float4>(
379 "Combine Color YCCA ITU 709",
380 [](const float y, const float cb, const float cr, const float a) -> float4 {
382 ycc_to_rgb(y * 255.0f,
383 cb * 255.0f,
384 cr * 255.0f,
385 &result.x,
386 &result.y,
387 &result.z,
389 result.w = a;
390 return result;
391 },
392 mf::build::exec_presets::Materialized());
393
394 static auto ycca_jpeg_function = mf::build::SI4_SO<float, float, float, float, float4>(
395 "Combine Color YCCA JPEG",
396 [](const float y, const float cb, const float cr, const float a) -> float4 {
398 ycc_to_rgb(y * 255.0f,
399 cb * 255.0f,
400 cr * 255.0f,
401 &result.x,
402 &result.y,
403 &result.z,
405 result.w = a;
406 return result;
407 },
408 mf::build::exec_presets::Materialized());
409
410 switch (node_storage(builder.node()).mode) {
412 builder.set_matching_fn(rgba_function);
413 break;
415 builder.set_matching_fn(hsva_function);
416 break;
418 builder.set_matching_fn(hsla_function);
419 break;
421 builder.set_matching_fn(yuva_function);
422 break;
424 switch (node_storage(builder.node()).ycc_mode) {
426 builder.set_matching_fn(ycca_itu_601_function);
427 break;
429 builder.set_matching_fn(ycca_itu_709_function);
430 break;
432 builder.set_matching_fn(ycca_jpeg_function);
433 break;
434 }
435 }
436}
437
438} // namespace blender::nodes::node_composite_combine_color_cc
439
441{
443
444 static blender::bke::bNodeType ntype;
445
446 cmp_node_type_base(&ntype, "CompositorNodeCombineColor", CMP_NODE_COMBINE_COLOR);
447 ntype.ui_name = "Combine Color";
448 ntype.ui_description = "Combine an image from its composite color channels";
449 ntype.enum_name_legacy = "COMBINE_COLOR";
451 ntype.declare = file_ns::cmp_node_combine_color_declare;
454 ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage);
455 ntype.updatefunc = file_ns::cmp_node_combine_color_update;
456 ntype.gpu_fn = file_ns::node_gpu_material;
457 ntype.build_multi_function = file_ns::node_build_multi_function;
458
460}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define CMP_NODE_SEPARATE_COLOR
#define CMP_NODE_COMBINE_COLOR
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_YUV_ITU_BT709
void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l)
#define BLI_YCC_JFIF_0_255
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
#define BLI_YCC_ITU_BT601
void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
void rgb_to_yuv(float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace)
Definition math_color.cc:67
void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:38
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:91
#define BLI_YCC_ITU_BT709
CMPNodeCombSepColorMode
@ CMP_NODE_COMBSEP_COLOR_YCC
@ CMP_NODE_COMBSEP_COLOR_YUV
@ CMP_NODE_COMBSEP_COLOR_RGB
@ CMP_NODE_COMBSEP_COLOR_HSV
@ CMP_NODE_COMBSEP_COLOR_HSL
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:239
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
void set_matching_fn(const mf::MultiFunction *fn)
VecBase< float, 4 > float4
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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:5603
static void cmp_node_combine_color_update(bNodeTree *, bNode *node)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_combine_color_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void cmp_node_separate_color_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_separate_color_update(bNodeTree *, bNode *node)
VecBase< float, 4 > float4
static void node_cmp_combsep_color_label(const ListBase *sockets, CMPNodeCombSepColorMode mode)
static void register_node_type_cmp_combine_color()
static void register_node_type_cmp_separate_color()
static void node_cmp_combsep_color_init(bNodeTree *, bNode *node)
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
void node_sock_label_clear(bNodeSocket *sock)
Definition node_util.cc:78
void node_sock_label(bNodeSocket *sock, const char *name)
Definition node_util.cc:73
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
#define min(a, b)
Definition sort.cc:36
void * first
struct bNodeSocket * next
ListBase inputs
void * storage
ListBase outputs
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:344
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:269
max
Definition text_draw.cc:251