Blender  V3.3
COM_MovieClipNode.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_MovieClipNode.h"
5 
7 
8 #include "BKE_movieclip.h"
9 #include "BKE_tracking.h"
10 
11 #include "DNA_movieclip_types.h"
12 
13 #include "IMB_imbuf.h"
14 
15 namespace blender::compositor {
16 
17 MovieClipNode::MovieClipNode(bNode *editor_node) : Node(editor_node)
18 {
19  /* pass */
20 }
21 
23  const CompositorContext &context) const
24 {
25  NodeOutput *output_movie_clip = this->get_output_socket(0);
26  NodeOutput *alpha_movie_clip = this->get_output_socket(1);
27  NodeOutput *offset_xmovie_clip = this->get_output_socket(2);
28  NodeOutput *offset_ymovie_clip = this->get_output_socket(3);
29  NodeOutput *scale_movie_clip = this->get_output_socket(4);
30  NodeOutput *angle_movie_clip = this->get_output_socket(5);
31 
32  bNode *editor_node = this->get_bnode();
33  MovieClip *movie_clip = (MovieClip *)editor_node->id;
34  MovieClipUser *movie_clip_user = (MovieClipUser *)editor_node->storage;
35  bool cache_frame = !context.is_rendering();
36 
37  ImBuf *ibuf = nullptr;
38  if (movie_clip) {
39  if (cache_frame) {
40  ibuf = BKE_movieclip_get_ibuf(movie_clip, movie_clip_user);
41  }
42  else {
44  movie_clip, movie_clip_user, movie_clip->flag, MOVIECLIP_CACHE_SKIP);
45  }
46  }
47 
48  /* Always connect the output image. */
49  MovieClipOperation *operation = new MovieClipOperation();
50  operation->set_movie_clip(movie_clip);
51  operation->set_movie_clip_user(movie_clip_user);
52  operation->set_framenumber(context.get_framenumber());
53  operation->set_cache_frame(cache_frame);
54 
55  converter.add_operation(operation);
56  converter.map_output_socket(output_movie_clip, operation->get_output_socket());
57  converter.add_preview(operation->get_output_socket());
58 
59  MovieClipAlphaOperation *alpha_operation = new MovieClipAlphaOperation();
60  alpha_operation->set_movie_clip(movie_clip);
61  alpha_operation->set_movie_clip_user(movie_clip_user);
62  alpha_operation->set_framenumber(context.get_framenumber());
63  alpha_operation->set_cache_frame(cache_frame);
64 
65  converter.add_operation(alpha_operation);
66  converter.map_output_socket(alpha_movie_clip, alpha_operation->get_output_socket());
67 
69  float loc[2], scale, angle;
70  loc[0] = 0.0f;
71  loc[1] = 0.0f;
72  scale = 1.0f;
73  angle = 0.0f;
74 
75  if (ibuf) {
76  if (stab->flag & TRACKING_2D_STABILIZATION) {
77  int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movie_clip,
78  context.get_framenumber());
79 
81  movie_clip, clip_framenr, ibuf->x, ibuf->y, loc, &scale, &angle);
82  }
83  }
84 
85  converter.add_output_value(offset_xmovie_clip, loc[0]);
86  converter.add_output_value(offset_ymovie_clip, loc[1]);
87  converter.add_output_value(scale_movie_clip, scale);
88  converter.add_output_value(angle_movie_clip, angle);
89 
90  if (ibuf) {
91  IMB_freeImBuf(ibuf);
92  }
93 }
94 
95 } // namespace blender::compositor
float BKE_movieclip_remap_scene_to_clip_frame(const struct MovieClip *clip, float framenr)
#define MOVIECLIP_CACHE_SKIP
struct ImBuf * BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, struct MovieClipUser *user, int flag, int cache_flag)
Definition: movieclip.c:1334
struct ImBuf * BKE_movieclip_get_ibuf(struct MovieClip *clip, struct MovieClipUser *user)
Definition: movieclip.c:1329
void BKE_tracking_stabilization_data_get(struct MovieClip *clip, int framenr, int width, int height, float translation[2], float *scale, float *angle)
@ TRACKING_2D_STABILIZATION
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
Overall context of the compositor.
void set_movie_clip_user(MovieClipUser *imageuser)
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_preview(NodeOperationOutput *output)
void add_operation(NodeOperation *operation)
void add_output_value(NodeOutput *output, float value)
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:238
NodeOutput * get_output_socket(unsigned int index=0) const
Definition: COM_Node.cc:84
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
struct MovieTracking tracking
MovieTrackingStabilization stabilization
struct ID * id
void * storage