Blender V4.5
node_composite_sepcomb_ycca.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_assert.h"
10#include "BLI_math_color.h"
12
14
15#include "NOD_multi_function.hh"
16
17#include "GPU_material.hh"
18
20
21/* **************** SEPARATE YCCA ******************** */
22
24
26{
27 b.add_input<decl::Color>("Image")
28 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
29 .compositor_domain_priority(0);
30 b.add_output<decl::Float>("Y").translation_context(BLT_I18NCONTEXT_COLOR);
31 b.add_output<decl::Float>("Cb");
32 b.add_output<decl::Float>("Cr");
33 b.add_output<decl::Float>("A").translation_context(BLT_I18NCONTEXT_COLOR);
34}
35
36static void node_composit_init_mode_sepycca(bNodeTree * /*ntree*/, bNode *node)
37{
38 node->custom1 = 1; /* BLI_YCC_ITU_BT709 */
39}
40
41using namespace blender::compositor;
42
43static int node_gpu_material(GPUMaterial *material,
44 bNode *node,
45 bNodeExecData * /*execdata*/,
48{
49 switch (node->custom1) {
51 return GPU_stack_link(
52 material, node, "node_composite_separate_ycca_itu_601", inputs, outputs);
54 return GPU_stack_link(
55 material, node, "node_composite_separate_ycca_itu_709", inputs, outputs);
57 return GPU_stack_link(material, node, "node_composite_separate_ycca_jpeg", inputs, outputs);
58 }
59
60 return false;
61}
62
64{
65 static auto ycca_itu_601_function = mf::build::SI1_SO4<float4, float, float, float, float>(
66 "Separate Color YCCA ITU 601",
67 [](const float4 &color, float &y, float &cb, float &cr, float &a) -> void {
68 rgb_to_ycc(color.x, color.y, color.z, &y, &cb, &cr, BLI_YCC_ITU_BT601);
69 y /= 255.0f;
70 cb /= 255.0f;
71 cr /= 255.0f;
72 a = color.w;
73 },
74 mf::build::exec_presets::AllSpanOrSingle());
75
76 static auto ycca_itu_709_function = mf::build::SI1_SO4<float4, float, float, float, float>(
77 "Separate Color YCCA ITU 709",
78 [](const float4 &color, float &y, float &cb, float &cr, float &a) -> void {
79 rgb_to_ycc(color.x, color.y, color.z, &y, &cb, &cr, BLI_YCC_ITU_BT709);
80 y /= 255.0f;
81 cb /= 255.0f;
82 cr /= 255.0f;
83 a = color.w;
84 },
85 mf::build::exec_presets::AllSpanOrSingle());
86
87 static auto ycca_jpeg_function = mf::build::SI1_SO4<float4, float, float, float, float>(
88 "Separate Color YCCA JPEG",
89 [](const float4 &color, float &y, float &cb, float &cr, float &a) -> void {
90 rgb_to_ycc(color.x, color.y, color.z, &y, &cb, &cr, BLI_YCC_JFIF_0_255);
91 y /= 255.0f;
92 cb /= 255.0f;
93 cr /= 255.0f;
94 a = color.w;
95 },
96 mf::build::exec_presets::AllSpanOrSingle());
97
98 switch (builder.node().custom1) {
100 builder.set_matching_fn(ycca_itu_601_function);
101 break;
103 builder.set_matching_fn(ycca_itu_709_function);
104 break;
106 builder.set_matching_fn(ycca_jpeg_function);
107 break;
108 }
109}
110
111} // namespace blender::nodes::node_composite_separate_ycca_cc
112
114{
116
117 static blender::bke::bNodeType ntype;
118
119 cmp_node_type_base(&ntype, "CompositorNodeSepYCCA", CMP_NODE_SEPYCCA_LEGACY);
120 ntype.ui_name = "Separate YCbCrA (Legacy)";
121 ntype.ui_description = "Deprecated";
122 ntype.enum_name_legacy = "SEPYCCA";
124 ntype.declare = file_ns::cmp_node_sepycca_declare;
125 ntype.initfunc = file_ns::node_composit_init_mode_sepycca;
126 ntype.gather_link_search_ops = nullptr;
127 ntype.gpu_fn = file_ns::node_gpu_material;
128 ntype.build_multi_function = file_ns::node_build_multi_function;
129
131}
133
134/* **************** COMBINE YCCA ******************** */
135
137
139{
140 b.add_input<decl::Float>("Y")
141 .min(0.0f)
142 .max(1.0f)
144 .translation_context(BLT_I18NCONTEXT_COLOR);
145 b.add_input<decl::Float>("Cb")
146 .default_value(0.5f)
147 .min(0.0f)
148 .max(1.0f)
150 b.add_input<decl::Float>("Cr")
151 .default_value(0.5f)
152 .min(0.0f)
153 .max(1.0f)
155 b.add_input<decl::Float>("A")
156 .default_value(1.0f)
157 .min(0.0f)
158 .max(1.0f)
160 .translation_context(BLT_I18NCONTEXT_COLOR);
161 b.add_output<decl::Color>("Image");
162}
163
164static void node_composit_init_mode_combycca(bNodeTree * /*ntree*/, bNode *node)
165{
166 node->custom1 = 1; /* BLI_YCC_ITU_BT709 */
167}
168
169using namespace blender::compositor;
170
171static int node_gpu_material(GPUMaterial *material,
172 bNode *node,
173 bNodeExecData * /*execdata*/,
176{
177 switch (node->custom1) {
179 return GPU_stack_link(
180 material, node, "node_composite_combine_ycca_itu_601", inputs, outputs);
182 return GPU_stack_link(
183 material, node, "node_composite_combine_ycca_itu_709", inputs, outputs);
185 return GPU_stack_link(material, node, "node_composite_combine_ycca_jpeg", inputs, outputs);
186 }
187
188 return false;
189}
190
192{
193 static auto ycca_itu_601_function = mf::build::SI4_SO<float, float, float, float, float4>(
194 "Combine Color YCCA ITU 601",
195 [](const float y, const float cb, const float cr, const float a) -> float4 {
197 ycc_to_rgb(y * 255.0f,
198 cb * 255.0f,
199 cr * 255.0f,
200 &result.x,
201 &result.y,
202 &result.z,
204 result.w = a;
205 return result;
206 },
207 mf::build::exec_presets::Materialized());
208
209 static auto ycca_itu_709_function = mf::build::SI4_SO<float, float, float, float, float4>(
210 "Combine Color YCCA ITU 709",
211 [](const float y, const float cb, const float cr, const float a) -> float4 {
213 ycc_to_rgb(y * 255.0f,
214 cb * 255.0f,
215 cr * 255.0f,
216 &result.x,
217 &result.y,
218 &result.z,
220 result.w = a;
221 return result;
222 },
223 mf::build::exec_presets::Materialized());
224
225 static auto ycca_jpeg_function = mf::build::SI4_SO<float, float, float, float, float4>(
226 "Combine Color YCCA JPEG",
227 [](const float y, const float cb, const float cr, const float a) -> float4 {
229 ycc_to_rgb(y * 255.0f,
230 cb * 255.0f,
231 cr * 255.0f,
232 &result.x,
233 &result.y,
234 &result.z,
236 result.w = a;
237 return result;
238 },
239 mf::build::exec_presets::Materialized());
240
241 switch (builder.node().custom1) {
243 builder.set_matching_fn(ycca_itu_601_function);
244 break;
246 builder.set_matching_fn(ycca_itu_709_function);
247 break;
249 builder.set_matching_fn(ycca_jpeg_function);
250 break;
251 }
252}
253
254} // namespace blender::nodes::node_composite_combine_ycca_cc
255
257{
259
260 static blender::bke::bNodeType ntype;
261
262 cmp_node_type_base(&ntype, "CompositorNodeCombYCCA", CMP_NODE_COMBYCCA_LEGACY);
263 ntype.ui_name = "Combine YCbCrA (Legacy)";
264 ntype.ui_description = "Deprecated";
265 ntype.enum_name_legacy = "COMBYCCA";
267 ntype.declare = file_ns::cmp_node_combycca_declare;
268 ntype.initfunc = file_ns::node_composit_init_mode_combycca;
269 ntype.gather_link_search_ops = nullptr;
270 ntype.gpu_fn = file_ns::node_gpu_material;
271 ntype.build_multi_function = file_ns::node_build_multi_function;
272
274}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define CMP_NODE_COMBYCCA_LEGACY
#define CMP_NODE_SEPYCCA_LEGACY
#define BLI_YCC_JFIF_0_255
void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
#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)
#define BLI_YCC_ITU_BT709
#define BLT_I18NCONTEXT_COLOR
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
static void node_composit_init_mode_combycca(bNodeTree *, bNode *node)
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_combycca_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_composit_init_mode_sepycca(bNodeTree *, bNode *node)
static void cmp_node_sepycca_declare(NodeDeclarationBuilder &b)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
VecBase< float, 4 > float4
static void register_node_type_cmp_sepycca()
static void register_node_type_cmp_combycca()
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[]
#define min(a, b)
Definition sort.cc:36
int16_t custom1
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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:371
NodeDeclareFunction declare
Definition BKE_node.hh:355