This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/compositor/operations/COM_MovieClipOperation.cc
Manuel Castilla 1c42d4930a Cleanup: convert camelCase naming to snake_case in Compositor
To convert old code to the current convention and
use a single code style.
2021-10-13 23:41:14 +02:00

155 lines
4.5 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2011, Blender Foundation.
*/
#include "COM_MovieClipOperation.h"
#include "BKE_image.h"
#include "BKE_movieclip.h"
#include "IMB_imbuf.h"
namespace blender::compositor {
MovieClipBaseOperation::MovieClipBaseOperation()
{
movie_clip_ = nullptr;
movie_clip_buffer_ = nullptr;
movie_clip_user_ = nullptr;
movie_clipwidth_ = 0;
movie_clipheight_ = 0;
framenumber_ = 0;
}
void MovieClipBaseOperation::init_execution()
{
if (movie_clip_) {
BKE_movieclip_user_set_frame(movie_clip_user_, framenumber_);
ImBuf *ibuf;
if (cache_frame_) {
ibuf = BKE_movieclip_get_ibuf(movie_clip_, movie_clip_user_);
}
else {
ibuf = BKE_movieclip_get_ibuf_flag(
movie_clip_, movie_clip_user_, movie_clip_->flag, MOVIECLIP_CACHE_SKIP);
}
if (ibuf) {
movie_clip_buffer_ = ibuf;
if (ibuf->rect_float == nullptr || ibuf->userflags & IB_RECT_INVALID) {
IMB_float_from_rect(ibuf);
ibuf->userflags &= ~IB_RECT_INVALID;
}
}
}
}
void MovieClipBaseOperation::deinit_execution()
{
if (movie_clip_buffer_) {
IMB_freeImBuf(movie_clip_buffer_);
movie_clip_buffer_ = nullptr;
}
}
void MovieClipBaseOperation::determine_canvas(const rcti &UNUSED(preferred_area), rcti &r_area)
{
r_area = COM_AREA_NONE;
if (movie_clip_) {
int width, height;
BKE_movieclip_get_size(movie_clip_, movie_clip_user_, &width, &height);
BLI_rcti_init(&r_area, 0, width, 0, height);
}
}
void MovieClipBaseOperation::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
ImBuf *ibuf = movie_clip_buffer_;
if (ibuf == nullptr) {
zero_v4(output);
}
else if (ibuf->rect == nullptr && ibuf->rect_float == nullptr) {
/* Happens for multilayer exr, i.e. */
zero_v4(output);
}
else {
switch (sampler) {
case PixelSampler::Nearest:
nearest_interpolation_color(ibuf, nullptr, output, x, y);
break;
case PixelSampler::Bilinear:
bilinear_interpolation_color(ibuf, nullptr, output, x, y);
break;
case PixelSampler::Bicubic:
bicubic_interpolation_color(ibuf, nullptr, output, x, y);
break;
}
}
}
void MovieClipBaseOperation::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> UNUSED(inputs))
{
if (movie_clip_buffer_) {
output->copy_from(movie_clip_buffer_, area);
}
else {
output->fill(area, COM_COLOR_TRANSPARENT);
}
}
MovieClipOperation::MovieClipOperation() : MovieClipBaseOperation()
{
this->add_output_socket(DataType::Color);
}
MovieClipAlphaOperation::MovieClipAlphaOperation() : MovieClipBaseOperation()
{
this->add_output_socket(DataType::Value);
}
void MovieClipAlphaOperation::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
float result[4];
MovieClipBaseOperation::execute_pixel_sampled(result, x, y, sampler);
output[0] = result[3];
}
void MovieClipAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> UNUSED(inputs))
{
if (movie_clip_buffer_) {
output->copy_from(movie_clip_buffer_, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0);
}
else {
output->fill(area, COM_VALUE_ZERO);
}
}
} // namespace blender::compositor