Blender  V2.93
COM_MovieDistortionOperation.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 
20 
21 #include "BKE_movieclip.h"
22 #include "BKE_tracking.h"
23 
24 #include "BLI_linklist.h"
25 
26 namespace blender::compositor {
27 
29 {
33  this->m_inputOperation = nullptr;
34  this->m_movieClip = nullptr;
35  this->m_apply = distortion;
36 }
37 
39 {
40  this->m_inputOperation = this->getInputSocketReader(0);
41  if (this->m_movieClip) {
42  MovieTracking *tracking = &this->m_movieClip->tracking;
43  MovieClipUser clipUser = {0};
44  int calibration_width, calibration_height;
45 
47  BKE_movieclip_get_size(this->m_movieClip, &clipUser, &calibration_width, &calibration_height);
48 
49  float delta[2];
50  rcti full_frame;
51  full_frame.xmin = full_frame.ymin = 0;
52  full_frame.xmax = this->m_width;
53  full_frame.ymax = this->m_height;
55  tracking, this->m_width, this->m_height, &full_frame, !this->m_apply, delta);
56 
57  /* 5 is just in case we didn't hit real max of distortion in
58  * BKE_tracking_max_undistortion_delta_across_bound
59  */
60  m_margin[0] = delta[0] + 5;
61  m_margin[1] = delta[1] + 5;
62 
64  tracking, calibration_width, calibration_height);
65  this->m_calibration_width = calibration_width;
66  this->m_calibration_height = calibration_height;
67  this->m_pixel_aspect = tracking->camera.pixel_aspect;
68  }
69  else {
70  m_margin[0] = m_margin[1] = 0;
71  this->m_distortion = nullptr;
72  }
73 }
74 
76 {
77  this->m_inputOperation = nullptr;
78  this->m_movieClip = nullptr;
79  if (this->m_distortion != nullptr) {
81  }
82 }
83 
85  float x,
86  float y,
87  PixelSampler /*sampler*/)
88 {
89  if (this->m_distortion != nullptr) {
90  /* float overscan = 0.0f; */
91  const float pixel_aspect = this->m_pixel_aspect;
92  const float w = (float)this->m_width /* / (1 + overscan) */;
93  const float h = (float)this->m_height /* / (1 + overscan) */;
94  const float aspx = w / (float)this->m_calibration_width;
95  const float aspy = h / (float)this->m_calibration_height;
96  float in[2];
97  float out[2];
98 
99  in[0] = (x /* - 0.5 * overscan * w */) / aspx;
100  in[1] = (y /* - 0.5 * overscan * h */) / aspy / pixel_aspect;
101 
102  if (this->m_apply) {
104  }
105  else {
107  }
108 
109  float u = out[0] * aspx /* + 0.5 * overscan * w */,
110  v = (out[1] * aspy /* + 0.5 * overscan * h */) * pixel_aspect;
111 
112  this->m_inputOperation->readSampled(output, u, v, PixelSampler::Bilinear);
113  }
114  else {
115  this->m_inputOperation->readSampled(output, x, y, PixelSampler::Bilinear);
116  }
117 }
118 
120  ReadBufferOperation *readOperation,
121  rcti *output)
122 {
123  rcti newInput;
124  newInput.xmin = input->xmin - m_margin[0];
125  newInput.ymin = input->ymin - m_margin[1];
126  newInput.xmax = input->xmax + m_margin[0];
127  newInput.ymax = input->ymax + m_margin[1];
128  return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
129 }
130 
131 } // namespace blender::compositor
typedef float(TangentPoint)[2]
void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr)
Definition: movieclip.c:1633
void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height)
Definition: movieclip.c:1540
struct MovieDistortion * BKE_tracking_distortion_new(struct MovieTracking *tracking, int calibration_width, int calibration_height)
Definition: tracking.c:2406
void BKE_tracking_distortion_undistort_v2(struct MovieDistortion *distortion, const float co[2], float r_co[2])
Definition: tracking.c:2541
void BKE_tracking_distortion_distort_v2(struct MovieDistortion *distortion, const float co[2], float r_co[2])
Definition: tracking.c:2523
void BKE_tracking_distortion_free(struct MovieDistortion *distortion)
Definition: tracking.c:2553
void BKE_tracking_max_distortion_delta_across_bound(struct MovieTracking *tracking, int image_width, int image_height, struct rcti *rect, bool undistort, float delta[2])
Definition: tracking.c:2636
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define output
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
void setResolutionInputSocketIndex(unsigned int index)
set the index of the input socket that will determine the resolution of this operation
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
struct MovieTracking tracking
MovieTrackingCamera camera
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79