Blender  V3.3
node_composite_colorbalance.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
8 #include "RNA_access.h"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
13 #include "node_composite_util.hh"
14 
15 /* ******************* Color Balance ********************************* */
16 
17 /* Sync functions update formula parameters for other modes, such that the result is comparable.
18  * Note that the results are not exactly the same due to differences in color handling
19  * (sRGB conversion happens for LGG),
20  * but this keeps settings comparable. */
21 
23 {
24  NodeColorBalance *n = (NodeColorBalance *)node->storage;
25 
26  for (int c = 0; c < 3; c++) {
27  n->slope[c] = (2.0f - n->lift[c]) * n->gain[c];
28  n->offset[c] = (n->lift[c] - 1.0f) * n->gain[c];
29  n->power[c] = (n->gamma[c] != 0.0f) ? 1.0f / n->gamma[c] : 1000000.0f;
30  }
31 }
32 
34 {
35  NodeColorBalance *n = (NodeColorBalance *)node->storage;
36 
37  for (int c = 0; c < 3; c++) {
38  float d = n->slope[c] + n->offset[c];
39  n->lift[c] = (d != 0.0f ? n->slope[c] + 2.0f * n->offset[c] / d : 0.0f);
40  n->gain[c] = d;
41  n->gamma[c] = (n->power[c] != 0.0f) ? 1.0f / n->power[c] : 1000000.0f;
42  }
43 }
44 
46 
48 {
49  b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
50  b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
51  b.add_output<decl::Color>(N_("Image"));
52 }
53 
55 {
56  NodeColorBalance *n = MEM_cnew<NodeColorBalance>(__func__);
57 
58  n->lift[0] = n->lift[1] = n->lift[2] = 1.0f;
59  n->gamma[0] = n->gamma[1] = n->gamma[2] = 1.0f;
60  n->gain[0] = n->gain[1] = n->gain[2] = 1.0f;
61 
62  n->slope[0] = n->slope[1] = n->slope[2] = 1.0f;
63  n->offset[0] = n->offset[1] = n->offset[2] = 0.0f;
64  n->power[0] = n->power[1] = n->power[2] = 1.0f;
65  node->storage = n;
66 }
67 
69 {
70  uiLayout *split, *col, *row;
71 
72  uiItemR(layout, ptr, "correction_method", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
73 
74  if (RNA_enum_get(ptr, "correction_method") == 0) {
75 
76  split = uiLayoutSplit(layout, 0.0f, false);
77  col = uiLayoutColumn(split, false);
78  uiTemplateColorPicker(col, ptr, "lift", true, true, false, true);
79  row = uiLayoutRow(col, false);
80  uiItemR(row, ptr, "lift", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
81 
82  col = uiLayoutColumn(split, false);
83  uiTemplateColorPicker(col, ptr, "gamma", true, true, true, true);
84  row = uiLayoutRow(col, false);
85  uiItemR(row, ptr, "gamma", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
86 
87  col = uiLayoutColumn(split, false);
88  uiTemplateColorPicker(col, ptr, "gain", true, true, true, true);
89  row = uiLayoutRow(col, false);
90  uiItemR(row, ptr, "gain", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
91  }
92  else {
93 
94  split = uiLayoutSplit(layout, 0.0f, false);
95  col = uiLayoutColumn(split, false);
96  uiTemplateColorPicker(col, ptr, "offset", true, true, false, true);
97  row = uiLayoutRow(col, false);
98  uiItemR(row, ptr, "offset", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
99  uiItemR(col, ptr, "offset_basis", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
100 
101  col = uiLayoutColumn(split, false);
102  uiTemplateColorPicker(col, ptr, "power", true, true, false, true);
103  row = uiLayoutRow(col, false);
104  uiItemR(row, ptr, "power", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
105 
106  col = uiLayoutColumn(split, false);
107  uiTemplateColorPicker(col, ptr, "slope", true, true, false, true);
108  row = uiLayoutRow(col, false);
109  uiItemR(row, ptr, "slope", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
110  }
111 }
112 
114  bContext *UNUSED(C),
115  PointerRNA *ptr)
116 {
117  uiItemR(layout, ptr, "correction_method", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
118 
119  if (RNA_enum_get(ptr, "correction_method") == 0) {
120 
121  uiTemplateColorPicker(layout, ptr, "lift", true, true, false, true);
122  uiItemR(layout, ptr, "lift", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
123 
124  uiTemplateColorPicker(layout, ptr, "gamma", true, true, true, true);
125  uiItemR(layout, ptr, "gamma", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
126 
127  uiTemplateColorPicker(layout, ptr, "gain", true, true, true, true);
128  uiItemR(layout, ptr, "gain", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
129  }
130  else {
131  uiTemplateColorPicker(layout, ptr, "offset", true, true, false, true);
132  uiItemR(layout, ptr, "offset", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
133 
134  uiTemplateColorPicker(layout, ptr, "power", true, true, false, true);
135  uiItemR(layout, ptr, "power", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
136 
137  uiTemplateColorPicker(layout, ptr, "slope", true, true, false, true);
138  uiItemR(layout, ptr, "slope", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
139  }
140 }
141 
142 } // namespace blender::nodes::node_composite_colorbalance_cc
143 
145 {
147 
148  static bNodeType ntype;
149 
154  node_type_size(&ntype, 400, 200, 400);
157  &ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage);
158 
159  nodeRegisterType(&ntype);
160 }
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition: node.cc:4396
#define CMP_NODE_COLORBALANCE
Definition: BKE_node.h:1255
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:347
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
@ PROP_FACTOR
Definition: RNA_types.h:144
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
uiLayout * uiLayoutSplit(uiLayout *layout, float percentage, bool align)
void uiTemplateColorPicker(uiLayout *layout, struct PointerRNA *ptr, const char *propname, bool value_slider, bool lock, bool lock_luminosity, bool cubic)
OperationNode * node
bNodeTree * ntree
uint col
static unsigned c
Definition: RandGen.cpp:83
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition: abc_util.cc:92
static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *node)
static void cmp_node_colorbalance_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_composit_buts_colorbalance_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node)
void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node)
void register_node_type_cmp_colorbalance()
void cmp_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons_ex)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:246
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480