Blender V5.0
node_composite_image_info.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#include "BLI_math_matrix.hh"
8
11
13
15
17{
18 b.add_input<decl::Color>("Image")
19 .hide_value()
21 .structure_type(StructureType::Dynamic);
22
23 b.add_output<decl::Vector>("Dimensions")
24 .dimensions(2)
25 .description("The dimensions of the image in pixels with transformations applied");
26 b.add_output<decl::Vector>("Resolution")
27 .dimensions(2)
28 .description("The original resolution of the image in pixels before any transformations");
29 b.add_output<decl::Vector>("Location").dimensions(2);
30 b.add_output<decl::Float>("Rotation");
31 b.add_output<decl::Vector>("Scale").dimensions(2);
32}
33
34using namespace blender::compositor;
35
37 public:
39 {
40 InputDescriptor &image_descriptor = this->get_input_descriptor("Image");
41 image_descriptor.skip_type_conversion = true;
42 }
43
44 void execute() override
45 {
46 const Result &input = this->get_input("Image");
47 if (input.is_single_value()) {
48 this->execute_invalid();
49 return;
50 }
51
52 const Domain domain = input.domain();
53
54 Result &dimensions_result = this->get_result("Dimensions");
55 if (dimensions_result.should_compute()) {
56 dimensions_result.allocate_single_value();
57 const Domain realized_domain =
59 domain);
60 dimensions_result.set_single_value(float2(realized_domain.size));
61 }
62
63 Result &resolution_result = this->get_result("Resolution");
64 if (resolution_result.should_compute()) {
65 resolution_result.allocate_single_value();
66 resolution_result.set_single_value(float2(domain.size));
67 }
68
69 math::AngleRadian rotation;
70 float2 location, scale;
71 math::to_loc_rot_scale(domain.transformation, location, rotation, scale);
72
73 Result &location_result = this->get_result("Location");
74 if (location_result.should_compute()) {
75 location_result.allocate_single_value();
76 location_result.set_single_value(location);
77 }
78
79 Result &rotation_result = this->get_result("Rotation");
80 if (rotation_result.should_compute()) {
81 rotation_result.allocate_single_value();
82 rotation_result.set_single_value(float(rotation));
83 }
84
85 Result &scale_result = this->get_result("Scale");
86 if (scale_result.should_compute()) {
87 scale_result.allocate_single_value();
88 scale_result.set_single_value(scale);
89 }
90 }
91
93 {
94 Result &dimensions_result = this->get_result("Dimensions");
95 if (dimensions_result.should_compute()) {
96 dimensions_result.allocate_invalid();
97 }
98
99 Result &resolution_result = this->get_result("Resolution");
100 if (resolution_result.should_compute()) {
101 resolution_result.allocate_invalid();
102 }
103
104 Result &location_result = this->get_result("Location");
105 if (location_result.should_compute()) {
106 location_result.allocate_invalid();
107 }
108
109 Result &rotation_result = this->get_result("Rotation");
110 if (rotation_result.should_compute()) {
111 rotation_result.allocate_invalid();
112 }
113
114 Result &scale_result = this->get_result("Scale");
115 if (scale_result.should_compute()) {
116 scale_result.allocate_invalid();
117 }
118 }
119};
120
122{
123 return new ImageInfoOperation(context, node);
124}
125
126} // namespace blender::nodes::node_composite_image_info_cc
127
129{
131
132 static blender::bke::bNodeType ntype;
133
134 cmp_node_type_base(&ntype, "CompositorNodeImageInfo", CMP_NODE_IMAGE_INFO);
135 ntype.ui_name = "Image Info";
136 ntype.ui_description = "Returns information about an image";
137 ntype.nclass = NODE_CLASS_INPUT;
138 ntype.declare = file_ns::node_declare;
139 ntype.get_compositor_operation = file_ns::get_compositor_operation;
140
142}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define CMP_NODE_IMAGE_INFO
#define NOD_REGISTER_NODE(REGISTER_FUNC)
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
static Domain compute_realized_transformation_domain(Context &context, const Domain &domain, const bool realize_translation=false)
void set_single_value(const T &value)
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
AngleRadianBase< float > AngleRadian
void to_loc_rot_scale(const MatBase< T, 3, 3 > &mat, VecBase< T, 2 > &r_location, AngleRadianBase< T > &r_rotation, VecBase< T, 2 > &r_scale)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_declare(NodeDeclarationBuilder &b)
VecBase< float, 2 > float2
static void register_node_type_cmp_image_info()
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