Blender V4.5
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").hide_value().compositor_realization_mode(
15
16 b.add_output<decl::Vector>("Uniform").dimensions(2).description(
17 "Zero centered coordinates normalizes along the larger dimension for uniform scaling");
18 b.add_output<decl::Vector>("Normalized")
19 .dimensions(2)
20 .description("Normalized coordinates with half pixel offsets");
21 b.add_output<decl::Vector>("Pixel").dimensions(2).description("Integer pixel coordinates");
22}
23
24using namespace blender::compositor;
25
27 public:
29 {
30 InputDescriptor &image_descriptor = this->get_input_descriptor("Image");
31 image_descriptor.skip_type_conversion = true;
32 }
33
34 void execute() override
35 {
36 const Result &input = this->get_input("Image");
37 Result &uniform_coordinates_result = this->get_result("Uniform");
38 Result &normalized_coordinates_result = this->get_result("Normalized");
39 Result &pixel_coordinates_result = this->get_result("Pixel");
40 if (input.is_single_value()) {
41 if (uniform_coordinates_result.should_compute()) {
42 uniform_coordinates_result.allocate_invalid();
43 }
44 if (normalized_coordinates_result.should_compute()) {
45 normalized_coordinates_result.allocate_invalid();
46 }
47 if (pixel_coordinates_result.should_compute()) {
48 pixel_coordinates_result.allocate_invalid();
49 }
50 return;
51 }
52
53 const Domain domain = input.domain();
54
55 if (uniform_coordinates_result.should_compute()) {
56 const Result &uniform_coordinates = this->context().cache_manager().image_coordinates.get(
57 this->context(), domain.size, CoordinatesType::Uniform);
58 uniform_coordinates_result.wrap_external(uniform_coordinates);
59 uniform_coordinates_result.transform(domain.transformation);
60 }
61
62 if (normalized_coordinates_result.should_compute()) {
63 const Result &normalized_coordinates = this->context().cache_manager().image_coordinates.get(
65 normalized_coordinates_result.wrap_external(normalized_coordinates);
66 normalized_coordinates_result.transform(domain.transformation);
67 }
68
69 if (pixel_coordinates_result.should_compute()) {
70 const Result &pixel_coordinates = this->context().cache_manager().image_coordinates.get(
71 this->context(), domain.size, CoordinatesType::Pixel);
72 pixel_coordinates_result.wrap_external(pixel_coordinates);
73 pixel_coordinates_result.transform(domain.transformation);
74 }
75 }
76};
77
79{
80 return new ImageCoordinatesOperation(context, node);
81}
82
83static void register_node()
84{
85 static blender::bke::bNodeType ntype;
86
87 cmp_node_type_base(&ntype, "CompositorNodeImageCoordinates");
88 ntype.ui_name = "Image Coordinates";
89 ntype.ui_description = "Returns the coordinates of the pixels of an image";
91 ntype.declare = node_declare;
93
95}
97
98} // namespace blender::nodes::node_composite_image_coordinates_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#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 transform(const float3x3 &transformation)
Definition result.cc:489
void wrap_external(GPUTexture *texture)
Definition result.cc:448
bool is_single_value() const
Definition result.cc:622
const CompositorInputRealizationMode & compositor_realization_mode() const
#define input
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
NodeDeclareFunction declare
Definition BKE_node.hh:355