Blender V5.0
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")
14 .hide_value()
16 .structure_type(StructureType::Dynamic);
17
18 b.add_output<decl::Vector>("Uniform")
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")
24 .dimensions(2)
25 .structure_type(StructureType::Dynamic)
26 .description("Normalized coordinates with half pixel offsets");
27 b.add_output<decl::Vector>("Pixel")
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 Result &uniform_coordinates_result = this->get_result("Uniform");
47 Result &normalized_coordinates_result = this->get_result("Normalized");
48 Result &pixel_coordinates_result = this->get_result("Pixel");
49 if (input.is_single_value()) {
50 if (uniform_coordinates_result.should_compute()) {
51 uniform_coordinates_result.allocate_invalid();
52 }
53 if (normalized_coordinates_result.should_compute()) {
54 normalized_coordinates_result.allocate_invalid();
55 }
56 if (pixel_coordinates_result.should_compute()) {
57 pixel_coordinates_result.allocate_invalid();
58 }
59 return;
60 }
61
62 const Domain domain = input.domain();
63
64 if (uniform_coordinates_result.should_compute()) {
65 const Result &uniform_coordinates = this->context().cache_manager().image_coordinates.get(
66 this->context(), domain.size, CoordinatesType::Uniform);
67 uniform_coordinates_result.wrap_external(uniform_coordinates);
68 uniform_coordinates_result.transform(domain.transformation);
69 }
70
71 if (normalized_coordinates_result.should_compute()) {
72 const Result &normalized_coordinates = this->context().cache_manager().image_coordinates.get(
74 normalized_coordinates_result.wrap_external(normalized_coordinates);
75 normalized_coordinates_result.transform(domain.transformation);
76 }
77
78 if (pixel_coordinates_result.should_compute()) {
79 const Result &pixel_coordinates = this->context().cache_manager().image_coordinates.get(
80 this->context(), domain.size, CoordinatesType::Pixel);
81 pixel_coordinates_result.wrap_external(pixel_coordinates);
82 pixel_coordinates_result.transform(domain.transformation);
83 }
84 }
85};
86
88{
89 return new ImageCoordinatesOperation(context, node);
90}
91
92static void register_node()
93{
94 static blender::bke::bNodeType ntype;
95
96 cmp_node_type_base(&ntype, "CompositorNodeImageCoordinates");
97 ntype.ui_name = "Image Coordinates";
98 ntype.ui_description = "Returns the coordinates of the pixels of an image";
100 ntype.declare = node_declare;
102
104}
106
107} // namespace blender::nodes::node_composite_image_coordinates_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Result & get(Context &context, const int2 &size, const CoordinatesType type)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
InputDescriptor & get_input_descriptor(StringRef identifier)
Definition operation.cc:158
void wrap_external(blender::gpu::Texture *texture)
Definition result.cc:584
void transform(const float3x3 &transformation)
Definition result.cc:625
bool is_single_value() const
Definition result.cc:758
const CompositorInputRealizationMode & compositor_realization_mode() const
#define input
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:348
NodeDeclareFunction declare
Definition BKE_node.hh:362