Blender V5.3
node_composite_image_coordinates.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
8
10
12{
13 b.add_input<decl::Color>("Image"_ustr)
14 .hide_value()
16 .structure_type(StructureType::Dynamic);
17
18 b.add_output<decl::Vector>("Uniform"_ustr)
19 .dimensions(2)
20 .structure_type(StructureType::Dynamic)
21 .description(
22 "Zero centered coordinates normalizes along the larger dimension for uniform scaling");
23 b.add_output<decl::Vector>("Normalized"_ustr)
24 .dimensions(2)
25 .structure_type(StructureType::Dynamic)
26 .description("Normalized coordinates with half pixel offsets");
27 b.add_output<decl::IntVector>("Pixel"_ustr)
28 .dimensions(2)
29 .structure_type(StructureType::Dynamic)
30 .description("Integer pixel coordinates");
31}
32
33using namespace blender::compositor;
34
36 public:
38 {
39 InputDescriptor &image_descriptor = this->get_input_descriptor("Image");
40 image_descriptor.skip_type_conversion = true;
41 }
42
43 void execute() override
44 {
45 const Result &input = this->get_input("Image");
46 if (input.is_single_value()) {
48 return;
49 }
50
51 const Domain domain = input.domain();
52
53 Result &uniform_coordinates_result = this->get_result("Uniform");
54 if (uniform_coordinates_result.should_compute()) {
55 const Result &uniform_coordinates = this->context().cache_manager().image_coordinates.get(
56 this->context(), domain, CoordinatesType::Uniform);
57 uniform_coordinates_result.share_data(uniform_coordinates);
58 uniform_coordinates_result.domain().transformation = domain.transformation;
59 }
60
61 Result &normalized_coordinates_result = this->get_result("Normalized");
62 if (normalized_coordinates_result.should_compute()) {
63 const Result &normalized_coordinates = this->context().cache_manager().image_coordinates.get(
64 this->context(), domain, CoordinatesType::Normalized);
65 normalized_coordinates_result.share_data(normalized_coordinates);
66 normalized_coordinates_result.domain().transformation = domain.transformation;
67 }
68
69 Result &pixel_coordinates_result = this->get_result("Pixel");
70 if (pixel_coordinates_result.should_compute()) {
71 const Result &pixel_coordinates = this->context().cache_manager().image_coordinates.get(
72 this->context(), domain, CoordinatesType::Pixel);
73 pixel_coordinates_result.share_data(pixel_coordinates);
74 pixel_coordinates_result.domain().transformation = domain.transformation;
75 }
76 }
77};
78
80{
81 return new ImageCoordinatesOperation(context, node);
82}
83
84static void node_register()
85{
86 static bke::bNodeType ntype;
87
88 cmp_node_type_base(&ntype, "CompositorNodeImageCoordinates"_ustr);
89 ntype.ui_name = "Image Coordinates";
90 ntype.ui_description = "Returns the coordinates of the pixels of an image";
92 ntype.declare = node_declare;
94
96}
98
99} // namespace blender::nodes::node_composite_image_coordinates_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Result & get(Context &context, const Domain &domain, const CoordinatesType type)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
InputDescriptor & get_input_descriptor(StringRef identifier)
Definition operation.cc:132
void share_data(const Result &source)
Definition result.cc:996
bool should_compute() const
Definition result.cc:1124
const CompositorInputRealizationMode & compositor_realization_mode() const
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
NodeDeclareFunction declare
Definition BKE_node.hh:393