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