Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/operations/COM_MovieDistortionOperation.cc
| Show All 23 Lines | |||||
| #include "BLI_linklist.h" | #include "BLI_linklist.h" | ||||
| namespace blender::compositor { | namespace blender::compositor { | ||||
| MovieDistortionOperation::MovieDistortionOperation(bool distortion) | MovieDistortionOperation::MovieDistortionOperation(bool distortion) | ||||
| { | { | ||||
| this->addInputSocket(DataType::Color); | this->addInputSocket(DataType::Color); | ||||
| this->addOutputSocket(DataType::Color); | this->addOutputSocket(DataType::Color); | ||||
| this->setResolutionInputSocketIndex(0); | this->set_canvas_input_index(0); | ||||
| this->m_inputOperation = nullptr; | this->m_inputOperation = nullptr; | ||||
| this->m_movieClip = nullptr; | this->m_movieClip = nullptr; | ||||
| this->m_apply = distortion; | this->m_apply = distortion; | ||||
| } | } | ||||
| void MovieDistortionOperation::initExecution() | void MovieDistortionOperation::initExecution() | ||||
| { | { | ||||
| this->m_inputOperation = this->getInputSocketReader(0); | this->m_inputOperation = this->getInputSocketReader(0); | ||||
| if (this->m_movieClip) { | if (this->m_movieClip) { | ||||
| MovieTracking *tracking = &this->m_movieClip->tracking; | MovieTracking *tracking = &this->m_movieClip->tracking; | ||||
| MovieClipUser clipUser = {0}; | MovieClipUser clipUser = {0}; | ||||
| int calibration_width, calibration_height; | int calibration_width, calibration_height; | ||||
| BKE_movieclip_user_set_frame(&clipUser, this->m_framenumber); | BKE_movieclip_user_set_frame(&clipUser, this->m_framenumber); | ||||
| BKE_movieclip_get_size(this->m_movieClip, &clipUser, &calibration_width, &calibration_height); | BKE_movieclip_get_size(this->m_movieClip, &clipUser, &calibration_width, &calibration_height); | ||||
| float delta[2]; | float delta[2]; | ||||
| rcti full_frame; | rcti full_frame; | ||||
| full_frame.xmin = full_frame.ymin = 0; | full_frame.xmin = full_frame.ymin = 0; | ||||
| full_frame.xmax = this->m_width; | full_frame.xmax = this->getWidth(); | ||||
| full_frame.ymax = this->m_height; | full_frame.ymax = this->getHeight(); | ||||
| BKE_tracking_max_distortion_delta_across_bound( | BKE_tracking_max_distortion_delta_across_bound( | ||||
| tracking, this->m_width, this->m_height, &full_frame, !this->m_apply, delta); | tracking, this->getWidth(), this->getHeight(), &full_frame, !this->m_apply, delta); | ||||
| /* 5 is just in case we didn't hit real max of distortion in | /* 5 is just in case we didn't hit real max of distortion in | ||||
| * BKE_tracking_max_undistortion_delta_across_bound | * BKE_tracking_max_undistortion_delta_across_bound | ||||
| */ | */ | ||||
| m_margin[0] = delta[0] + 5; | m_margin[0] = delta[0] + 5; | ||||
| m_margin[1] = delta[1] + 5; | m_margin[1] = delta[1] + 5; | ||||
| this->m_distortion = BKE_tracking_distortion_new( | this->m_distortion = BKE_tracking_distortion_new( | ||||
| Show All 20 Lines | |||||
| void MovieDistortionOperation::executePixelSampled(float output[4], | void MovieDistortionOperation::executePixelSampled(float output[4], | ||||
| float x, | float x, | ||||
| float y, | float y, | ||||
| PixelSampler /*sampler*/) | PixelSampler /*sampler*/) | ||||
| { | { | ||||
| if (this->m_distortion != nullptr) { | if (this->m_distortion != nullptr) { | ||||
| /* float overscan = 0.0f; */ | /* float overscan = 0.0f; */ | ||||
| const float pixel_aspect = this->m_pixel_aspect; | const float pixel_aspect = this->m_pixel_aspect; | ||||
| const float w = (float)this->m_width /* / (1 + overscan) */; | const float w = (float)this->getWidth() /* / (1 + overscan) */; | ||||
| const float h = (float)this->m_height /* / (1 + overscan) */; | const float h = (float)this->getHeight() /* / (1 + overscan) */; | ||||
| const float aspx = w / (float)this->m_calibration_width; | const float aspx = w / (float)this->m_calibration_width; | ||||
| const float aspy = h / (float)this->m_calibration_height; | const float aspy = h / (float)this->m_calibration_height; | ||||
| float in[2]; | float in[2]; | ||||
| float out[2]; | float out[2]; | ||||
| in[0] = (x /* - 0.5 * overscan * w */) / aspx; | in[0] = (x /* - 0.5 * overscan * w */) / aspx; | ||||
| in[1] = (y /* - 0.5 * overscan * h */) / aspy / pixel_aspect; | in[1] = (y /* - 0.5 * overscan * h */) / aspy / pixel_aspect; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void MovieDistortionOperation::update_memory_buffer_partial(MemoryBuffer *output, | ||||
| const MemoryBuffer *input_img = inputs[0]; | const MemoryBuffer *input_img = inputs[0]; | ||||
| if (this->m_distortion == nullptr) { | if (this->m_distortion == nullptr) { | ||||
| output->copy_from(input_img, area); | output->copy_from(input_img, area); | ||||
| return; | return; | ||||
| } | } | ||||
| /* `float overscan = 0.0f;` */ | /* `float overscan = 0.0f;` */ | ||||
| const float pixel_aspect = this->m_pixel_aspect; | const float pixel_aspect = this->m_pixel_aspect; | ||||
| const float w = (float)this->m_width /* `/ (1 + overscan)` */; | const float w = (float)this->getWidth() /* `/ (1 + overscan)` */; | ||||
| const float h = (float)this->m_height /* `/ (1 + overscan)` */; | const float h = (float)this->getHeight() /* `/ (1 + overscan)` */; | ||||
| const float aspx = w / (float)this->m_calibration_width; | const float aspx = w / (float)this->m_calibration_width; | ||||
| const float aspy = h / (float)this->m_calibration_height; | const float aspy = h / (float)this->m_calibration_height; | ||||
| float xy[2]; | float xy[2]; | ||||
| float distorted_xy[2]; | float distorted_xy[2]; | ||||
| for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) { | for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) { | ||||
| xy[0] = (it.x /* `- 0.5 * overscan * w` */) / aspx; | xy[0] = (it.x /* `- 0.5 * overscan * w` */) / aspx; | ||||
| xy[1] = (it.y /* `- 0.5 * overscan * h` */) / aspy / pixel_aspect; | xy[1] = (it.y /* `- 0.5 * overscan * h` */) / aspy / pixel_aspect; | ||||
| Show All 14 Lines | |||||