Blender V5.3
node_fn_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
6
7#include "BLI_math_color_c.hh"
8
10#include "UI_resources.hh"
11
12#include "NOD_rna_define.hh"
13
14#include "RNA_enum_types.hh"
15
17
19
21{
22 b.is_function_node();
23 b.add_input<decl::Float>("Red"_ustr)
24 .default_value(0.0f)
25 .min(0.0f)
26 .max(1.0f)
27 .subtype(PROP_FACTOR)
28 .label_fn([](const bNode &node) {
29 switch (node_storage(node).mode) {
31 default:
32 return IFACE_("Red");
35 return IFACE_("Hue");
36 }
37 });
38 b.add_input<decl::Float>("Green"_ustr)
39 .default_value(0.0f)
40 .min(0.0f)
41 .max(1.0f)
42 .subtype(PROP_FACTOR)
43 .label_fn([](const bNode &node) {
44 switch (node_storage(node).mode) {
46 default:
47 return IFACE_("Green");
50 return IFACE_("Saturation");
51 }
52 });
53 b.add_input<decl::Float>("Blue"_ustr)
54 .default_value(0.0f)
55 .min(0.0f)
56 .max(1.0f)
57 .subtype(PROP_FACTOR)
58 .label_fn([](const bNode &node) {
59 switch (node_storage(node).mode) {
61 default:
62 return IFACE_("Blue");
64 return CTX_IFACE_(BLT_I18NCONTEXT_COLOR, "Value");
66 return IFACE_("Lightness");
67 }
68 });
69 b.add_input<decl::Float>("Alpha"_ustr)
70 .default_value(1.0f)
71 .min(0.0f)
72 .max(1.0f)
73 .subtype(PROP_FACTOR);
74 b.add_output<decl::Color>("Color"_ustr);
75};
76
77static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
78{
79 layout.prop(ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
80}
81
82static void node_init(bNodeTree * /*tree*/, bNode *node)
83{
84 NodeCombSepColor *data = MEM_new<NodeCombSepColor>(__func__);
86 node->storage = data;
87}
88
89static const mf::MultiFunction *get_multi_function(const bNode &bnode)
90{
91 const NodeCombSepColor &storage = node_storage(bnode);
92
93 static auto rgba_fn = mf::build::SI4_SO<float, float, float, float, ColorGeometry4f>(
94 "RGB", [](float r, float g, float b, float a) { return ColorGeometry4f(r, g, b, a); });
95 static auto hsva_fn = mf::build::SI4_SO<float, float, float, float, ColorGeometry4f>(
96 "HSV", [](float h, float s, float v, float a) {
98 hsv_to_rgb(h, s, v, &color.r, &color.g, &color.b);
99 color.a = a;
100 return color;
101 });
102 static auto hsla_fn = mf::build::SI4_SO<float, float, float, float, ColorGeometry4f>(
103 "HSL", [](float h, float s, float l, float a) {
105 hsl_to_rgb(h, s, l, &color.r, &color.g, &color.b);
106 color.a = a;
107 return color;
108 });
109
110 switch (storage.mode) {
112 return &rgba_fn;
114 return &hsva_fn;
116 return &hsla_fn;
117 }
118
120 return nullptr;
121}
122
124{
125 const mf::MultiFunction *fn = get_multi_function(builder.node());
126 builder.set_matching_fn(fn);
127}
128
129static void node_rna(StructRNA *srna)
130{
132 "mode",
133 "Mode",
134 "Mode of color processing",
137}
138
139static void node_register()
140{
141 static bke::bNodeType ntype;
142
143 fn_node_type_base(&ntype, "FunctionNodeCombineColor"_ustr, FN_NODE_COMBINE_COLOR);
144 ntype.ui_name = "Combine Color";
145 ntype.ui_description =
146 "Combine four channels into a single color, based on a particular color model";
147 ntype.enum_name_legacy = "COMBINE_COLOR";
149 ntype.declare = node_declare;
150 ntype.initfunc = node_init;
152 ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
155
157
158 node_rna(ntype.rna_ext.srna);
159}
161
162} // namespace blender::nodes::node_fn_combine_color_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define FN_NODE_COMBINE_COLOR
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_COLOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
#define BLI_assert_unreachable()
btScalar max
void set_matching_fn(const mf::MultiFunction *fn)
#define storage(slot, qualifiers)
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
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_init(bNodeTree *, bNode *node)
static const mf::MultiFunction * get_multi_function(const bNode &bnode)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
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
ATTR_WARN_UNUSED_RESULT const BMVert * v
@ NODE_COMBSEP_COLOR_HSL
@ NODE_COMBSEP_COLOR_HSV
@ NODE_COMBSEP_COLOR_RGB
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 fn_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
const EnumPropertyItem rna_enum_node_combsep_color_items[]
@ PROP_FACTOR
Definition RNA_types.hh:308
#define min(a, b)
Definition sort.cc:38
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
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
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)