Blender  V3.3
COM_MaskOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. */
3 
4 #include "COM_MaskOperation.h"
5 
6 #include "BKE_lib_id.h"
7 #include "BKE_mask.h"
8 
9 namespace blender::compositor {
10 
12 {
14  mask_ = nullptr;
15  mask_width_ = 0;
16  mask_height_ = 0;
17  mask_width_inv_ = 0.0f;
18  mask_height_inv_ = 0.0f;
19  frame_shutter_ = 0.0f;
20  frame_number_ = 0;
22  memset(raster_mask_handles_, 0, sizeof(raster_mask_handles_));
23 }
24 
26 {
27  if (mask_ && raster_mask_handles_[0] == nullptr) {
28  if (raster_mask_handle_tot_ == 1) {
30 
33  }
34  else {
35  /* make a throw away copy of the mask */
36  const float frame = (float)frame_number_ - frame_shutter_;
37  const float frame_step = (frame_shutter_ * 2.0f) / raster_mask_handle_tot_;
38  float frame_iter = frame;
39 
40  Mask *mask_temp = (Mask *)BKE_id_copy_ex(
41  nullptr, &mask_->id, nullptr, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA);
42 
43  /* trick so we can get unkeyed edits to display */
44  {
45  MaskLayer *masklay;
46  MaskLayerShape *masklay_shape;
47 
48  for (masklay = (MaskLayer *)mask_temp->masklayers.first; masklay;
49  masklay = masklay->next) {
50  masklay_shape = BKE_mask_layer_shape_verify_frame(masklay, frame_number_);
51  BKE_mask_layer_shape_from_mask(masklay, masklay_shape);
52  }
53  }
54 
55  for (unsigned int i = 0; i < raster_mask_handle_tot_; i++) {
57 
58  /* re-eval frame info */
59  BKE_mask_evaluate(mask_temp, frame_iter, true);
60 
62  mask_temp,
65  true,
66  true,
67  do_feather_);
68 
69  frame_iter += frame_step;
70  }
71 
72  BKE_id_free(nullptr, &mask_temp->id);
73  }
74  }
75 }
76 
78 {
79  for (unsigned int i = 0; i < raster_mask_handle_tot_; i++) {
80  if (raster_mask_handles_[i]) {
82  raster_mask_handles_[i] = nullptr;
83  }
84  }
85 }
86 
87 void MaskOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
88 {
89  if (mask_width_ == 0 || mask_height_ == 0) {
90  r_area = COM_AREA_NONE;
91  }
92  else {
93  r_area = preferred_area;
94  r_area.xmax = r_area.xmin + mask_width_;
95  r_area.ymax = r_area.ymin + mask_height_;
96  }
97 }
98 
100  float x,
101  float y,
102  PixelSampler /*sampler*/)
103 {
104  const float xy[2] = {
105  (x * mask_width_inv_) + mask_px_ofs_[0],
107  };
108 
109  if (raster_mask_handle_tot_ == 1) {
110  if (raster_mask_handles_[0]) {
112  }
113  else {
114  output[0] = 0.0f;
115  }
116  }
117  else {
118  /* In case loop below fails. */
119  output[0] = 0.0f;
120 
121  for (unsigned int i = 0; i < raster_mask_handle_tot_; i++) {
122  if (raster_mask_handles_[i]) {
124  }
125  }
126 
127  /* until we get better falloff */
129  }
130 }
131 
133  const rcti &area,
135 {
136  Vector<MaskRasterHandle *> handles = get_non_null_handles();
137  if (handles.size() == 0) {
138  output->fill(area, COM_VALUE_ZERO);
139  return;
140  }
141 
142  float xy[2];
143  for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
144  xy[0] = it.x * mask_width_inv_ + mask_px_ofs_[0];
145  xy[1] = it.y * mask_height_inv_ + mask_px_ofs_[1];
146  *it.out = 0.0f;
147  for (MaskRasterHandle *handle : handles) {
148  *it.out += BKE_maskrasterize_handle_sample(handle, xy);
149  }
150 
151  /* Until we get better falloff. */
152  *it.out /= raster_mask_handle_tot_;
153  }
154 }
155 
156 Vector<MaskRasterHandle *> MaskOperation::get_non_null_handles() const
157 {
159  for (int i = 0; i < raster_mask_handle_tot_; i++) {
161  if (handle == nullptr) {
162  continue;
163  }
164  handles.append(handle);
165  }
166  return handles;
167 }
168 
169 } // namespace blender::compositor
typedef float(TangentPoint)[2]
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:187
@ LIB_ID_COPY_NO_ANIMDATA
Definition: BKE_lib_id.h:154
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, int flag)
void BKE_id_free(struct Main *bmain, void *idv)
struct MaskLayerShape * BKE_mask_layer_shape_verify_frame(struct MaskLayer *masklay, int frame)
Definition: mask.c:1771
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2])
void BKE_mask_evaluate(struct Mask *mask, float ctime, bool do_newframe)
Definition: mask.c:1568
void BKE_mask_layer_shape_from_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape)
Definition: mask.c:1617
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask, int width, int height, bool do_aspect_correct, bool do_mask_aa, bool do_feather)
MaskRasterHandle * BKE_maskrasterize_handle_new(void)
#define UNUSED(x)
_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
struct MaskRasterHandle * raster_mask_handles_[CMP_NODE_MASK_MBLUR_SAMPLES_MAX]
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
a MemoryBuffer contains access to the data of a chunk
void add_output_socket(DataType datatype)
ccl_global KernelShaderEvalInput ccl_global float * output
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
constexpr float COM_VALUE_ZERO[1]
Definition: COM_defines.h:67
constexpr rcti COM_AREA_NONE
Definition: COM_defines.h:112
static bNodeSocketTemplate inputs[]
void * first
Definition: DNA_listBase.h:31
struct MaskLayer * next
ListBase masklayers
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63
ParamHandle ** handles
int xy[2]
Definition: wm_draw.c:135