Blender V4.3
COM_MovieClipNode.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "COM_MovieClipNode.h"
6
8
9#include "BKE_movieclip.h"
10#include "BKE_tracking.h"
11
12#include "DNA_movieclip_types.h"
13
14#include "IMB_imbuf.hh"
15
16namespace blender::compositor {
17
18MovieClipNode::MovieClipNode(bNode *editor_node) : Node(editor_node)
19{
20 /* pass */
21}
22
24 const CompositorContext &context) const
25{
26 NodeOutput *output_movie_clip = this->get_output_socket(0);
27 NodeOutput *alpha_movie_clip = this->get_output_socket(1);
28 NodeOutput *offset_xmovie_clip = this->get_output_socket(2);
29 NodeOutput *offset_ymovie_clip = this->get_output_socket(3);
30 NodeOutput *scale_movie_clip = this->get_output_socket(4);
31 NodeOutput *angle_movie_clip = this->get_output_socket(5);
32
33 const bNode *editor_node = this->get_bnode();
34 MovieClip *movie_clip = (MovieClip *)editor_node->id;
35 MovieClipUser *movie_clip_user = (MovieClipUser *)editor_node->storage;
36 bool cache_frame = !context.is_rendering();
37
38 ImBuf *ibuf = nullptr;
39 if (movie_clip) {
40 if (cache_frame) {
41 ibuf = BKE_movieclip_get_ibuf(movie_clip, movie_clip_user);
42 }
43 else {
45 movie_clip, movie_clip_user, movie_clip->flag, MOVIECLIP_CACHE_SKIP);
46 }
47 }
48
49 /* Always connect the output image. */
50 MovieClipOperation *operation = new MovieClipOperation();
51 operation->set_movie_clip(movie_clip);
52 operation->set_movie_clip_user(movie_clip_user);
53 operation->set_framenumber(context.get_framenumber());
54 operation->set_cache_frame(cache_frame);
55
56 converter.add_operation(operation);
57 converter.map_output_socket(output_movie_clip, operation->get_output_socket());
58 converter.add_preview(operation->get_output_socket());
59
60 MovieClipAlphaOperation *alpha_operation = new MovieClipAlphaOperation();
61 alpha_operation->set_movie_clip(movie_clip);
62 alpha_operation->set_movie_clip_user(movie_clip_user);
63 alpha_operation->set_framenumber(context.get_framenumber());
64 alpha_operation->set_cache_frame(cache_frame);
65
66 converter.add_operation(alpha_operation);
67 converter.map_output_socket(alpha_movie_clip, alpha_operation->get_output_socket());
68
70 float loc[2], scale, angle;
71 loc[0] = 0.0f;
72 loc[1] = 0.0f;
73 scale = 1.0f;
74 angle = 0.0f;
75
76 if (ibuf) {
77 if (stab->flag & TRACKING_2D_STABILIZATION) {
78 int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movie_clip,
79 context.get_framenumber());
80
82 movie_clip, clip_framenr, ibuf->x, ibuf->y, loc, &scale, &angle);
83 }
84 }
85
86 converter.add_output_value(offset_xmovie_clip, loc[0]);
87 converter.add_output_value(offset_ymovie_clip, loc[1]);
88 converter.add_output_value(scale_movie_clip, scale);
89 converter.add_output_value(angle_movie_clip, angle);
90
91 if (ibuf) {
92 IMB_freeImBuf(ibuf);
93 }
94}
95
96} // 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(struct MovieClip *clip, const struct MovieClipUser *user)
struct ImBuf * BKE_movieclip_get_ibuf_flag(struct MovieClip *clip, const struct MovieClipUser *user, int flag, int cache_flag)
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
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:125
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:239
NodeOutput * get_output_socket(unsigned int index=0) const
Definition COM_Node.cc:85
const bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition COM_Node.h:65
void IMB_freeImBuf(ImBuf *)
struct MovieTracking tracking
MovieTrackingStabilization stabilization
struct ID * id
void * storage