Blender V5.0
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").optional_label();
19 b.add_input<decl::Int>("Frame").min(0).description(
20 "Which frame to use for videos. Note that different frames in videos can "
21 "have different resolutions");
22
23 b.add_output<decl::Int>("Width");
24 b.add_output<decl::Int>("Height");
25 b.add_output<decl::Bool>("Has Alpha").description("Whether the image has an alpha channel");
26
27 b.add_output<decl::Int>("Frame Count")
28 .description("The number of animation frames. If a single image, then 1");
29 b.add_output<decl::Float>("FPS").description(
30 "Animation playback speed in frames per second. If a single image, then 0");
31}
32
34{
35 Image *image = params.extract_input<Image *>("Image");
36 const int frame = params.extract_input<int>("Frame");
37 if (!image) {
38 params.set_default_remaining_outputs();
39 return;
40 }
41
42 ImageUser image_user;
43 BKE_imageuser_default(&image_user);
44 image_user.frames = std::numeric_limits<int>::max();
45 image_user.framenr = BKE_image_is_animated(image) ? frame : 0;
46
47 void *lock;
48 ImBuf *ibuf = BKE_image_acquire_ibuf(image, &image_user, &lock);
49 BLI_SCOPED_DEFER([&]() { BKE_image_release_ibuf(image, ibuf, lock); });
50 if (!ibuf) {
51 params.set_default_remaining_outputs();
52 return;
53 }
54
55 params.set_output("Has Alpha", ELEM(ibuf->planes, 32, 16));
56 params.set_output("Width", ibuf->x);
57 params.set_output("Height", ibuf->y);
58
59 int frames = 1;
60 float fps = 0.0f;
61
62 if (ImageAnim *ianim = static_cast<ImageAnim *>(image->anims.first)) {
63 MovieReader *anim = ianim->anim;
64 if (anim) {
66 fps = MOV_get_fps(anim);
67 }
68 }
69
70 params.set_output("Frame Count", frames);
71 params.set_output("FPS", fps);
72}
73
74static void node_register()
75{
76 static blender::bke::bNodeType ntype;
77
78 geo_node_type_base(&ntype, "GeometryNodeImageInfo", GEO_NODE_IMAGE_INFO);
79 ntype.ui_name = "Image Info";
80 ntype.ui_description = "Retrieve information about an image";
81 ntype.enum_name_legacy = "IMAGE_INFO";
83 ntype.declare = node_declare;
87}
89
90} // namespace blender::nodes::node_geo_image_info_cc
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
void BKE_imageuser_default(ImageUser *iuser)
bool BKE_image_is_animated(Image *image)
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_IMAGE_INFO
#define BLI_SCOPED_DEFER(function_to_defer)
#define ELEM(...)
@ IMB_TC_NONE
Definition MOV_enums.hh:46
#define NOD_REGISTER_NODE(REGISTER_FUNC)
volatile int lock
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int MOV_get_duration_frames(MovieReader *anim, IMB_Timecode_Type tc)
float MOV_get_fps(const MovieReader *anim)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
unsigned char planes
ListBase anims
void * first
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362