Blender V5.3
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"_ustr)
19 .hide_value()
21 .structure_type(StructureType::Dynamic);
22
23 b.add_output<decl::IntVector>("Dimensions"_ustr)
24 .dimensions(2)
25 .description("The dimensions of the image in pixels with transformations applied");
26 b.add_output<decl::IntVector>("Resolution"_ustr)
27 .dimensions(2)
28 .description("The original resolution of the image in pixels before any transformations");
29 b.add_output<decl::Vector>("Location"_ustr).dimensions(2);
30 b.add_output<decl::Float>("Rotation"_ustr);
31 b.add_output<decl::Vector>("Scale"_ustr).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()) {
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 = domain.realize_transformation();
58 dimensions_result.set_single_value(realized_domain.data_size);
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(domain.data_size);
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(location);
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(scale);
87 }
88 }
89};
90
92{
93 return new ImageInfoOperation(context, node);
94}
95
96static void node_register()
97{
98 static bke::bNodeType ntype;
99
100 cmp_node_type_base(&ntype, "CompositorNodeImageInfo"_ustr, CMP_NODE_IMAGE_INFO);
101 ntype.ui_name = "Image Info";
102 ntype.ui_description = "Returns information about an image";
103 ntype.nclass = NODE_CLASS_INPUT;
104 ntype.declare = node_declare;
106
108}
110
111} // namespace blender::nodes::node_composite_image_info_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define CMP_NODE_IMAGE_INFO
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Domain realize_transformation(const bool realize_translation=false) const
Definition domain.cc:59
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
bool should_compute() const
Definition result.cc:1124
void set_single_value(const T &value)
const CompositorInputRealizationMode & compositor_realization_mode() const
float3x3 scale(float3x3 mat, float2 scale)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
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, const bNode &node)
static void node_declare(NodeDeclarationBuilder &b)
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