Blender V4.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 "UI_resources.hh"
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.add_input<decl::Image>("Image").hide_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.get_input<Image *>("Image");
36 const int frame = params.get_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 = 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 ImBufAnim *anim = ianim->anim;
64 if (anim) {
65 frames = IMB_anim_get_duration(anim, IMB_TC_NONE);
66
67 short fps_sec = 0;
68 float fps_sec_base = 0.0f;
69 IMB_anim_get_fps(anim, true, &fps_sec, &fps_sec_base);
70 fps = float(fps_sec) / fps_sec_base;
71 }
72 }
73
74 params.set_output("Frame Count", frames);
75 params.set_output("FPS", fps);
76}
77
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:404
#define BLI_SCOPED_DEFER(function_to_defer)
#define ELEM(...)
bool IMB_anim_get_fps(const ImBufAnim *anim, bool no_av_base, short *r_frs_sec, float *r_frs_sec_base)
int IMB_anim_get_duration(ImBufAnim *anim, IMB_Timecode_Type tc)
@ IMB_TC_NONE
Contains defines and structs used throughout the imbuf module.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
volatile int lock
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
unsigned char planes
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347