Blender V5.3
node_geo_image_info.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_image.hh"
6
7#include "IMB_imbuf.hh"
8#include "IMB_imbuf_types.hh"
9
10#include "MOV_read.hh"
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.add_input<decl::Image>("Image"_ustr).optional_label();
19 b.add_input<decl::Int>("Frame"_ustr)
20 .min(0)
21 .description(
22 "Which frame to use for videos. Note that different frames in videos can "
23 "have different resolutions");
24
25 b.add_output<decl::Int>("Width"_ustr);
26 b.add_output<decl::Int>("Height"_ustr);
27 b.add_output<decl::Bool>("Has Alpha"_ustr).description("Whether the image has an alpha channel");
28
29 b.add_output<decl::Int>("Frame Count"_ustr)
30 .description("The number of animation frames. If a single image, then 1");
31 b.add_output<decl::Float>("FPS"_ustr)
32 .description("Animation playback speed in frames per second. If a single image, then 0");
33}
34
36{
37 Image *image = params.extract_input<Image *>("Image"_ustr);
38 const int frame = params.extract_input<int>("Frame"_ustr);
39 if (!image) {
41 return;
42 }
43
44 ImageUser image_user;
45 BKE_imageuser_default(&image_user);
46 image_user.frames = std::numeric_limits<int>::max();
47 image_user.framenr = BKE_image_is_animated(image) ? frame : 0;
48
49 void *lock;
50 ImBuf *ibuf = BKE_image_acquire_ibuf(image, &image_user, &lock);
52 if (!ibuf) {
54 return;
55 }
56
57 params.set_output("Has Alpha"_ustr, ibuf->can_contain_alpha());
58 params.set_output("Width"_ustr, ibuf->x);
59 params.set_output("Height"_ustr, ibuf->y);
60
61 int frames = 1;
62 float fps = 0.0f;
63
64 if (ImageAnim *ianim = image->anims.first()) {
65 MovieReader *anim = ianim->anim;
66 if (anim) {
67 frames = MOV_get_duration_frames(anim);
68 fps = MOV_get_fps(anim);
69 }
70 }
71
72 params.set_output("Frame Count"_ustr, frames);
73 params.set_output("FPS"_ustr, fps);
74}
75
76static void node_register()
77{
78 static bke::bNodeType ntype;
79
80 geo_node_type_base(&ntype, "GeometryNodeImageInfo"_ustr, GEO_NODE_IMAGE_INFO);
81 ntype.ui_name = "Image Info";
82 ntype.ui_description = "Retrieve information about an image";
83 ntype.enum_name_legacy = "IMAGE_INFO";
85 ntype.declare = node_declare;
89}
91
92} // namespace blender::nodes::node_geo_image_info_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_IMAGE_INFO
#define BLI_SCOPED_DEFER(function_to_defer)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
volatile int lock
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
bool BKE_image_is_animated(Image *image)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
float MOV_get_fps(const MovieReader *anim)
int MOV_get_duration_frames(const MovieReader *anim)
void BKE_imageuser_default(ImageUser *iuser)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
#define min(a, b)
Definition sort.cc:38
bool can_contain_alpha() const
static constexpr int _240
Definition BKE_node.hh:250
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393