Blender V5.0
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.h"
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").default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
24 b.add_input<decl::Float>("Green").default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
25 b.add_input<decl::Float>("Blue").default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
26 b.add_input<decl::Float>("Alpha").default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
27 b.add_output<decl::Color>("Color");
28};
29
30static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
31{
32 layout->prop(ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
33}
34
35static void node_update(bNodeTree * /*tree*/, bNode *node)
36{
37 const NodeCombSepColor &storage = node_storage(*node);
39}
40
41static void node_init(bNodeTree * /*tree*/, bNode *node)
42{
45 node->storage = data;
46}
47
48static const mf::MultiFunction *get_multi_function(const bNode &bnode)
49{
50 const NodeCombSepColor &storage = node_storage(bnode);
51
52 static auto rgba_fn = mf::build::SI4_SO<float, float, float, float, ColorGeometry4f>(
53 "RGB", [](float r, float g, float b, float a) { return ColorGeometry4f(r, g, b, a); });
54 static auto hsva_fn = mf::build::SI4_SO<float, float, float, float, ColorGeometry4f>(
55 "HSV", [](float h, float s, float v, float a) {
57 hsv_to_rgb(h, s, v, &color.r, &color.g, &color.b);
58 color.a = a;
59 return color;
60 });
61 static auto hsla_fn = mf::build::SI4_SO<float, float, float, float, ColorGeometry4f>(
62 "HSL", [](float h, float s, float l, float a) {
64 hsl_to_rgb(h, s, l, &color.r, &color.g, &color.b);
65 color.a = a;
66 return color;
67 });
68
69 switch (storage.mode) {
71 return &rgba_fn;
73 return &hsva_fn;
75 return &hsla_fn;
76 }
77
79 return nullptr;
80}
81
83{
84 const mf::MultiFunction *fn = get_multi_function(builder.node());
85 builder.set_matching_fn(fn);
86}
87
88static void node_rna(StructRNA *srna)
89{
91 "mode",
92 "Mode",
93 "Mode of color processing",
96}
97
98static void node_register()
99{
100 static blender::bke::bNodeType ntype;
101
102 fn_node_type_base(&ntype, "FunctionNodeCombineColor", FN_NODE_COMBINE_COLOR);
103 ntype.ui_name = "Combine Color";
104 ntype.ui_description =
105 "Combine four channels into a single color, based on a particular color model";
106 ntype.enum_name_legacy = "COMBINE_COLOR";
108 ntype.declare = node_declare;
109 ntype.updatefunc = node_update;
110 ntype.initfunc = node_init;
112 ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
115
117
118 node_rna(ntype.rna_ext.srna);
119}
121
122} // namespace blender::nodes::node_fn_combine_color_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define FN_NODE_COMBINE_COLOR
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:38
NodeCombSepColorMode
@ NODE_COMBSEP_COLOR_RGB
@ NODE_COMBSEP_COLOR_HSV
@ NODE_COMBSEP_COLOR_HSL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
@ PROP_FACTOR
Definition RNA_types.hh:251
#define UI_ITEM_NONE
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)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
static void node_declare(NodeDeclarationBuilder &b)
static void node_update(bNodeTree *, bNode *node)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
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)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void fn_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
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
void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode)
Definition node_util.cc:227
const EnumPropertyItem rna_enum_node_combsep_color_items[]
#define min(a, b)
Definition sort.cc:36
StructRNA * srna
ListBase inputs
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:281
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4238