Blender  V2.93
COM_MovieClipNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_MovieClipNode.h"
21 #include "COM_ExecutionSystem.h"
22 #include "COM_MovieClipOperation.h"
23 #include "COM_SetValueOperation.h"
24 
25 #include "BKE_movieclip.h"
26 #include "BKE_tracking.h"
27 
28 #include "DNA_movieclip_types.h"
29 
30 #include "IMB_imbuf.h"
31 
32 namespace blender::compositor {
33 
34 MovieClipNode::MovieClipNode(bNode *editorNode) : Node(editorNode)
35 {
36  /* pass */
37 }
38 
40  const CompositorContext &context) const
41 {
42  NodeOutput *outputMovieClip = this->getOutputSocket(0);
43  NodeOutput *alphaMovieClip = this->getOutputSocket(1);
44  NodeOutput *offsetXMovieClip = this->getOutputSocket(2);
45  NodeOutput *offsetYMovieClip = this->getOutputSocket(3);
46  NodeOutput *scaleMovieClip = this->getOutputSocket(4);
47  NodeOutput *angleMovieClip = this->getOutputSocket(5);
48 
49  bNode *editorNode = this->getbNode();
50  MovieClip *movieClip = (MovieClip *)editorNode->id;
51  MovieClipUser *movieClipUser = (MovieClipUser *)editorNode->storage;
52  bool cacheFrame = !context.isRendering();
53 
54  ImBuf *ibuf = nullptr;
55  if (movieClip) {
56  if (cacheFrame) {
57  ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser);
58  }
59  else {
61  movieClip, movieClipUser, movieClip->flag, MOVIECLIP_CACHE_SKIP);
62  }
63  }
64 
65  // always connect the output image
66  MovieClipOperation *operation = new MovieClipOperation();
67  operation->setMovieClip(movieClip);
68  operation->setMovieClipUser(movieClipUser);
69  operation->setFramenumber(context.getFramenumber());
70  operation->setCacheFrame(cacheFrame);
71 
72  converter.addOperation(operation);
73  converter.mapOutputSocket(outputMovieClip, operation->getOutputSocket());
74  converter.addPreview(operation->getOutputSocket());
75 
76  MovieClipAlphaOperation *alphaOperation = new MovieClipAlphaOperation();
77  alphaOperation->setMovieClip(movieClip);
78  alphaOperation->setMovieClipUser(movieClipUser);
79  alphaOperation->setFramenumber(context.getFramenumber());
80  alphaOperation->setCacheFrame(cacheFrame);
81 
82  converter.addOperation(alphaOperation);
83  converter.mapOutputSocket(alphaMovieClip, alphaOperation->getOutputSocket());
84 
86  float loc[2], scale, angle;
87  loc[0] = 0.0f;
88  loc[1] = 0.0f;
89  scale = 1.0f;
90  angle = 0.0f;
91 
92  if (ibuf) {
93  if (stab->flag & TRACKING_2D_STABILIZATION) {
94  int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movieClip,
95  context.getFramenumber());
96 
98  movieClip, clip_framenr, ibuf->x, ibuf->y, loc, &scale, &angle);
99  }
100  }
101 
102  converter.addOutputValue(offsetXMovieClip, loc[0]);
103  converter.addOutputValue(offsetYMovieClip, loc[1]);
104  converter.addOutputValue(scaleMovieClip, scale);
105  converter.addOutputValue(angleMovieClip, angle);
106 
107  if (ibuf) {
108  IMB_freeImBuf(ibuf);
109  }
110 }
111 
112 } // 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:1354
struct ImBuf * BKE_movieclip_get_ibuf(struct MovieClip *clip, struct MovieClipUser *user)
Definition: movieclip.c:1349
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
void IMB_freeImBuf(struct ImBuf *ibuf)
Definition: allocimbuf.c:211
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 setMovieClipUser(MovieClipUser *imageuser)
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void addOutputValue(NodeOutput *output, float value)
void addPreview(NodeOperationOutput *output)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
struct MovieTracking tracking
MovieTrackingStabilization stabilization
struct ID * id
void * storage