Blender  V3.3
COM_MovieClipAttributeOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 #include "BKE_movieclip.h"
7 #include "BKE_tracking.h"
8 
9 namespace blender::compositor {
10 
12 {
14  framenumber_ = 0;
15  attribute_ = MCA_X;
16  invert_ = false;
18  is_value_calculated_ = false;
19  stabilization_resolution_socket_ = nullptr;
20 }
21 
23 {
24  if (!is_value_calculated_) {
25  calc_value();
26  }
27 }
28 
29 void MovieClipAttributeOperation::calc_value()
30 {
31  BLI_assert(this->get_flags().is_canvas_set);
32  is_value_calculated_ = true;
33  if (clip_ == nullptr) {
34  return;
35  }
36  float loc[2], scale, angle;
37  loc[0] = 0.0f;
38  loc[1] = 0.0f;
39  scale = 1.0f;
40  angle = 0.0f;
41  int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip_, framenumber_);
42  NodeOperation &stabilization_operation =
43  stabilization_resolution_socket_ ?
44  stabilization_resolution_socket_->get_link()->get_operation() :
45  *this;
47  clip_framenr,
48  stabilization_operation.get_width(),
49  stabilization_operation.get_height(),
50  loc,
51  &scale,
52  &angle);
53  switch (attribute_) {
54  case MCA_SCALE:
55  value_ = scale;
56  break;
57  case MCA_ANGLE:
58  value_ = angle;
59  break;
60  case MCA_X:
61  value_ = loc[0];
62  break;
63  case MCA_Y:
64  value_ = loc[1];
65  break;
66  }
67  if (invert_) {
68  if (attribute_ != MCA_SCALE) {
69  value_ = -value_;
70  }
71  else {
72  value_ = 1.0f / value_;
73  }
74  }
75 }
76 
78  float /*x*/,
79  float /*y*/,
80  PixelSampler /*sampler*/)
81 {
82  output[0] = value_;
83 }
84 
85 void MovieClipAttributeOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
86 {
87  r_area = preferred_area;
88 }
89 
91 {
92  if (!is_value_calculated_) {
93  calc_value();
94  }
95  return &value_;
96 }
97 
98 } // namespace blender::compositor
float BKE_movieclip_remap_scene_to_clip_frame(const struct MovieClip *clip, float framenr)
void BKE_tracking_stabilization_data_get(struct MovieClip *clip, int framenr, int width, int height, float translation[2], float *scale, float *angle)
#define BLI_assert(a)
Definition: BLI_assert.h:46
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
NodeOperationOutput * get_link() const
void add_output_socket(DataType datatype)
const NodeOperationFlags get_flags() const
ccl_global KernelShaderEvalInput ccl_global float * output