Blender V4.3
COM_MovieDistortionOperation.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
6
7#include "DNA_defaults.h"
8
9#include "BKE_movieclip.h"
10
11namespace blender::compositor {
12
14{
18 movie_clip_ = nullptr;
19 apply_ = distortion;
20
22}
23
25{
26 if (movie_clip_) {
27 MovieTracking *tracking = &movie_clip_->tracking;
29 int calibration_width, calibration_height;
30
32 BKE_movieclip_get_size(movie_clip_, &clip_user, &calibration_width, &calibration_height);
33
34 float delta[2];
35 rcti full_frame;
36 full_frame.xmin = full_frame.ymin = 0;
37 full_frame.xmax = this->get_width();
38 full_frame.ymax = this->get_height();
40 tracking, this->get_width(), this->get_height(), &full_frame, !apply_, delta);
41
42 /* 5 is just in case we didn't hit real max of distortion in
43 * BKE_tracking_max_undistortion_delta_across_bound
44 */
45 margin_[0] = delta[0] + 5;
46 margin_[1] = delta[1] + 5;
47
48 calibration_width_ = calibration_width;
49 calibration_height_ = calibration_height;
50 pixel_aspect_ = tracking->camera.pixel_aspect;
51 }
52 else {
53 margin_[0] = margin_[1] = 0;
54 }
55}
56
58{
59 if (movie_clip_) {
60 MovieTracking *tracking = &movie_clip_->tracking;
62 }
63 else {
64 distortion_ = nullptr;
65 }
66}
67
69{
70 movie_clip_ = nullptr;
71 if (distortion_ != nullptr) {
73 }
74}
75
77 const rcti &output_area,
78 rcti &r_input_area)
79{
80 BLI_assert(input_idx == 0);
81 UNUSED_VARS_NDEBUG(input_idx);
82 r_input_area.xmin = output_area.xmin - margin_[0];
83 r_input_area.ymin = output_area.ymin - margin_[1];
84 r_input_area.xmax = output_area.xmax + margin_[0];
85 r_input_area.ymax = output_area.ymax + margin_[1];
86}
87
89 const rcti &area,
91{
92 const MemoryBuffer *input_img = inputs[0];
93 if (distortion_ == nullptr) {
94 output->copy_from(input_img, area);
95 return;
96 }
97
98 /* `float overscan = 0.0f;` */
99 const float pixel_aspect = pixel_aspect_;
100 const float w = float(this->get_width()) /* `/ (1 + overscan)` */;
101 const float h = float(this->get_height()) /* `/ (1 + overscan)` */;
102 const float aspx = w / float(calibration_width_);
103 const float aspy = h / float(calibration_height_);
104 float xy[2];
105 float distorted_xy[2];
106 for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
107 xy[0] = (it.x + 0.5f /* `- 0.5 * overscan * w` */) / aspx;
108 xy[1] = (it.y + 0.5f /* `- 0.5 * overscan * h` */) / aspy / pixel_aspect;
109
110 if (apply_) {
112 }
113 else {
115 }
116
117 const float u = distorted_xy[0] * aspx /* `+ 0.5 * overscan * w` */;
118 const float v = (distorted_xy[1] * aspy /* `+ 0.5 * overscan * h` */) * pixel_aspect;
119 input_img->read_elem_bilinear(u - 0.5f, v - 0.5f, it.out);
120 }
121}
122
123} // namespace blender::compositor
void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr)
void BKE_movieclip_get_size(struct MovieClip *clip, const struct MovieClipUser *user, int *r_width, int *r_height)
void BKE_tracking_distortion_undistort_v2(struct MovieDistortion *distortion, const float co[2], float r_co[2])
Definition tracking.cc:2402
void BKE_tracking_max_distortion_delta_across_bound(struct MovieTracking *tracking, int image_width, int image_height, const struct rcti *rect, bool undistort, float r_delta[2])
void BKE_tracking_distortion_distort_v2(struct MovieDistortion *distortion, const float co[2], float r_co[2])
Definition tracking.cc:2384
void BKE_tracking_distortion_free(struct MovieDistortion *distortion)
Definition tracking.cc:2414
struct MovieDistortion * BKE_tracking_distortion_new(struct MovieTracking *tracking, int calibration_width, int calibration_height)
Definition tracking.cc:2263
#define BLI_assert(a)
Definition BLI_assert.h:50
#define UNUSED_VARS_NDEBUG(...)
#define DNA_struct_default_get(struct_name)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
a MemoryBuffer contains access to the data
void copy_from(const MemoryBuffer *src, const rcti &area)
void read_elem_bilinear(float x, float y, float *out) const
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override
Get input operation area being read by this operation on rendering given output area.
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void set_canvas_input_index(unsigned int index)
set the index of the input socket that will determine the canvas of this operation
draw_view in_light_buf[] float
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
struct MovieTracking tracking
int ymin
int ymax
int xmin
int xmax
int xy[2]
Definition wm_draw.cc:170