30 N_(
"HSV (Hue, Saturation, Value) color space")},
35 N_(
"YUV (Y - luma, U V - chroma) color space")},
40 N_(
"YCbCr (Y - luma, Cb - blue-difference chroma, Cr - red-difference chroma) color space")},
41 {0,
nullptr, 0,
nullptr,
nullptr},
54 {0,
nullptr, 0,
nullptr,
nullptr},
67 {0,
nullptr, 0,
nullptr,
nullptr},
80 {0,
nullptr, 0,
nullptr,
nullptr},
93 {0,
nullptr, 0,
nullptr,
nullptr},
101 N_(
"Limit by single channel")},
106 N_(
"Limit by maximum of other channels")},
107 {0,
nullptr, 0,
nullptr,
nullptr},
112 b.use_custom_socket_order();
113 b.allow_any_socket_order();
114 b.is_function_node();
115 b.add_input<
decl::Color>(
"Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
116 b.add_output<
decl::Color>(
"Image"_ustr).align_with_previous();
124 .description(
"Channel values lower than this minimum are keyed");
130 .description(
"Channel values higher than this maximum are not keyed");
235 b.add_input<
decl::Menu>(
"YCbCr Limit Channel"_ustr)
262 node->storage = MEM_new<NodeChroma>(__func__);
273 return GPU_stack_link(material,
node,
"node_composite_channel_matte", inputs, outputs);
278 switch (color_space) {
304 const int rgb_channel,
305 const int hsv_channel,
306 const int yuv_channel,
307 const int ycc_channel)
309 switch (color_space) {
327 const int matte_channel,
328 const int limit_channel)
333 return int2((matte_channel + 1) % 3, (matte_channel + 2) % 3);
337 return int2(limit_channel);
344 const int rgb_key_channel,
345 const int hsv_key_channel,
346 const int yuv_key_channel,
347 const int ycc_key_channel,
349 const int rgb_limit_channel,
350 const int hsv_limit_channel,
351 const int yuv_limit_channel,
352 const int ycc_limit_channel,
358 color_space, rgb_key_channel, hsv_key_channel, yuv_key_channel, ycc_key_channel);
360 color_space, rgb_limit_channel, hsv_limit_channel, yuv_limit_channel, ycc_limit_channel);
363 float matte_value = channels[matte_channel];
364 float limit_value =
math::max(channels[limit_channels.x], channels[limit_channels.y]);
366 float alpha = 1.0f - (matte_value - limit_value);
367 if (alpha > maximum) {
370 else if (alpha < minimum) {
374 alpha = (alpha - minimum) / (maximum - minimum);
378 output_color =
color * matte;
385 static auto function =
386 mf::build::detail::build_multi_function_with_n_inputs_two_outputs<Color, float>(
389 const float &minimum,
390 const float &maximum,
402 float &matte) ->
void {
408 rgb_key_channel.
value,
409 hsv_key_channel.
value,
410 yuv_key_channel.
value,
411 ycc_key_channel.
value,
413 rgb_limit_channel.
value,
414 hsv_limit_channel.
value,
415 yuv_limit_channel.
value,
416 ycc_limit_channel.
value,
419 output_color =
Color(out_color);
421 mf::build::exec_presets::SomeSpanOrSingle<0>(),
445 ntype.
ui_description =
"Create matte based on differences in color channels";
#define CMP_NODE_CHANNEL_MATTE
#define BLI_YUV_ITU_BT709
#define BLI_YCC_ITU_BT709
#define BLT_I18NCONTEXT_COLOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
std::optional< std::string > translation_context
bool menu_input_may_be(UString identifier, int enum_value) const
void node_register_type(bNodeType &ntype)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
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))
ColorSceneLinear4f< eAlpha::Premultiplied > Color
T min(const T &a, const T &b)
T max(const T &a, const T &b)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static float3 compute_channels(const float4 color, const CMPNodeChannelMatteColorSpace color_space)
static const EnumPropertyItem yuv_channel_items[]
static const EnumPropertyItem color_space_items[]
static void node_register()
static int get_channel_index(const CMPNodeChannelMatteColorSpace color_space, const int rgb_channel, const int hsv_channel, const int yuv_channel, const int ycc_channel)
static void node_declare(NodeDeclarationBuilder &b)
static int2 compute_limit_channels(const CMPNodeChannelMatteLimitAlgorithm limit_method, const int matte_channel, const int limit_channel)
static void channel_key(const float4 color, const float minimum, const float maximum, const CMPNodeChannelMatteColorSpace color_space, const int rgb_key_channel, const int hsv_key_channel, const int yuv_key_channel, const int ycc_key_channel, const CMPNodeChannelMatteLimitAlgorithm limit_method, const int rgb_limit_channel, const int hsv_limit_channel, const int yuv_limit_channel, const int ycc_limit_channel, float4 &output_color, float &matte)
static const EnumPropertyItem hsv_channel_items[]
static const EnumPropertyItem rgb_channel_items[]
static const EnumPropertyItem limit_method_items[]
static const EnumPropertyItem ycbcr_channel_items[]
static void node_init(bNodeTree *, bNode *node)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
CMPNodeChannelMatteColorSpace
@ CMP_NODE_CHANNEL_MATTE_CS_HSV
@ CMP_NODE_CHANNEL_MATTE_CS_YUV
@ CMP_NODE_CHANNEL_MATTE_CS_RGB
@ CMP_NODE_CHANNEL_MATTE_CS_YCC
void rgb_to_yuv(float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace)
CMPNodeChannelMatteLimitAlgorithm
@ CMP_NODE_CHANNEL_MATTE_LIMIT_ALGORITHM_SINGLE
@ CMP_NODE_CHANNEL_MATTE_LIMIT_ALGORITHM_MAX
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
CCL_NAMESPACE_BEGIN struct Window V