Blender V5.3
node_composite_separate_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::Color>("Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
33 b.add_output<decl::Float>("Red"_ustr).label_fn([](const bNode &node) {
34 switch (node_storage(node).mode) {
36 default:
37 return IFACE_("Red");
40 return IFACE_("Hue");
43 return IFACE_("Y");
44 }
45 });
46 b.add_output<decl::Float>("Green"_ustr).label_fn([](const bNode &node) {
47 switch (node_storage(node).mode) {
49 default:
50 return IFACE_("Green");
53 return IFACE_("Saturation");
55 return IFACE_("Cb");
57 return IFACE_("U");
58 }
59 });
60 b.add_output<decl::Float>("Blue"_ustr).label_fn([](const bNode &node) {
61 switch (node_storage(node).mode) {
63 default:
64 return IFACE_("Blue");
66 return CTX_IFACE_(BLT_I18NCONTEXT_COLOR, "Value");
68 return IFACE_("Lightness");
70 return IFACE_("Cr");
72 return IFACE_("V");
73 }
74 });
75 b.add_output<decl::Float>("Alpha"_ustr);
76}
77
78static int node_gpu_material(GPUMaterial *material,
79 bNode *node,
80 bNodeExecData * /*execdata*/,
81 GPUNodeStack *inputs,
82 GPUNodeStack *outputs)
83{
84 switch (node_storage(*node).mode) {
86 return GPU_stack_link(material, node, "node_composite_separate_rgba", inputs, outputs);
88 return GPU_stack_link(material, node, "node_composite_separate_hsva", inputs, outputs);
90 return GPU_stack_link(material, node, "node_composite_separate_hsla", inputs, outputs);
92 return GPU_stack_link(
93 material, node, "node_composite_separate_yuva_itu_709", inputs, outputs);
95 switch (node_storage(*node).ycc_mode) {
97 return GPU_stack_link(
98 material, node, "node_composite_separate_ycca_itu_601", inputs, outputs);
100 return GPU_stack_link(
101 material, node, "node_composite_separate_ycca_itu_709", inputs, outputs);
103 return GPU_stack_link(
104 material, node, "node_composite_separate_ycca_jpeg", inputs, outputs);
105 }
106 }
107
108 return false;
109}
110
112
114{
115 static auto rgba_function = mf::build::SI1_SO4<Color, float, float, float, float>(
116 "Separate Color RGBA",
117 [](const Color &color, float &r, float &g, float &b, float &a) -> void {
118 r = color.r;
119 g = color.g;
120 b = color.b;
121 a = color.a;
122 },
123 mf::build::exec_presets::AllSpanOrSingle());
124
125 static auto hsva_function = mf::build::SI1_SO4<Color, float, float, float, float>(
126 "Separate Color HSVA",
127 [](const Color &color, float &h, float &s, float &v, float &a) -> void {
128 rgb_to_hsv(color.r, color.g, color.b, &h, &s, &v);
129 a = color.a;
130 },
131 mf::build::exec_presets::AllSpanOrSingle());
132
133 static auto hsla_function = mf::build::SI1_SO4<Color, float, float, float, float>(
134 "Separate Color HSLA",
135 [](const Color &color, float &h, float &s, float &l, float &a) -> void {
136 rgb_to_hsl(color.r, color.g, color.b, &h, &s, &l);
137 a = color.a;
138 },
139 mf::build::exec_presets::AllSpanOrSingle());
140
141 static auto yuva_function = mf::build::SI1_SO4<Color, float, float, float, float>(
142 "Separate Color YUVA",
143 [](const Color &color, float &y, float &u, float &v, float &a) -> void {
144 rgb_to_yuv(color.r, color.g, color.b, &y, &u, &v, BLI_YUV_ITU_BT709);
145 a = color.a;
146 },
147 mf::build::exec_presets::AllSpanOrSingle());
148
149 static auto ycca_itu_601_function = mf::build::SI1_SO4<Color, float, float, float, float>(
150 "Separate Color YCCA ITU 601",
151 [](const Color &color, float &y, float &cb, float &cr, float &a) -> void {
152 rgb_to_ycc(color.r, color.g, color.b, &y, &cb, &cr, BLI_YCC_ITU_BT601);
153 y /= 255.0f;
154 cb /= 255.0f;
155 cr /= 255.0f;
156 a = color.a;
157 },
158 mf::build::exec_presets::AllSpanOrSingle());
159
160 static auto ycca_itu_709_function = mf::build::SI1_SO4<Color, float, float, float, float>(
161 "Separate Color YCCA ITU 709",
162 [](const Color &color, float &y, float &cb, float &cr, float &a) -> void {
163 rgb_to_ycc(color.r, color.g, color.b, &y, &cb, &cr, BLI_YCC_ITU_BT709);
164 y /= 255.0f;
165 cb /= 255.0f;
166 cr /= 255.0f;
167 a = color.a;
168 },
169 mf::build::exec_presets::AllSpanOrSingle());
170
171 static auto ycca_jpeg_function = mf::build::SI1_SO4<Color, float, float, float, float>(
172 "Separate Color YCCA JPEG",
173 [](const Color &color, float &y, float &cb, float &cr, float &a) -> void {
174 rgb_to_ycc(color.r, color.g, color.b, &y, &cb, &cr, BLI_YCC_JFIF_0_255);
175 y /= 255.0f;
176 cb /= 255.0f;
177 cr /= 255.0f;
178 a = color.a;
179 },
180 mf::build::exec_presets::AllSpanOrSingle());
181
182 switch (node_storage(builder.node()).mode) {
184 builder.set_matching_fn(rgba_function);
185 break;
187 builder.set_matching_fn(hsva_function);
188 break;
190 builder.set_matching_fn(hsla_function);
191 break;
193 builder.set_matching_fn(yuva_function);
194 break;
196 switch (node_storage(builder.node()).ycc_mode) {
198 builder.set_matching_fn(ycca_itu_601_function);
199 break;
201 builder.set_matching_fn(ycca_itu_709_function);
202 break;
204 builder.set_matching_fn(ycca_jpeg_function);
205 break;
206 }
207 }
208}
209
210static void node_register()
211{
212 static bke::bNodeType ntype;
213
214 cmp_node_type_base(&ntype, "CompositorNodeSeparateColor"_ustr, CMP_NODE_SEPARATE_COLOR);
215 ntype.ui_name = "Separate Color";
216 ntype.ui_description = "Split an image into its composite color channels";
217 ntype.enum_name_legacy = "SEPARATE_COLOR";
219 ntype.declare = node_declare;
220 ntype.initfunc = node_init;
222 ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage);
225
227}
229
230} // namespace blender::nodes::node_composite_separate_color_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define CMP_NODE_SEPARATE_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 int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l)
@ 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
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
BMesh const char void * data
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:71
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
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