Blender  V2.93
COM_MaskOperation.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 2012, Blender Foundation.
17  */
18 
19 #include "COM_MaskOperation.h"
20 
21 #include "MEM_guardedalloc.h"
22 
23 #include "BLI_listbase.h"
24 #include "BLI_math.h"
25 
26 #include "BKE_lib_id.h"
27 #include "BKE_mask.h"
28 
29 namespace blender::compositor {
30 
32 {
34  this->m_mask = nullptr;
35  this->m_maskWidth = 0;
36  this->m_maskHeight = 0;
37  this->m_maskWidthInv = 0.0f;
38  this->m_maskHeightInv = 0.0f;
39  this->m_frame_shutter = 0.0f;
40  this->m_frame_number = 0;
41  this->m_rasterMaskHandleTot = 1;
42  memset(this->m_rasterMaskHandles, 0, sizeof(this->m_rasterMaskHandles));
43 }
44 
46 {
47  if (this->m_mask && this->m_rasterMaskHandles[0] == nullptr) {
48  if (this->m_rasterMaskHandleTot == 1) {
50 
52  this->m_mask,
53  this->m_maskWidth,
54  this->m_maskHeight,
55  true,
56  true,
57  this->m_do_feather);
58  }
59  else {
60  /* make a throw away copy of the mask */
61  const float frame = (float)this->m_frame_number - this->m_frame_shutter;
62  const float frame_step = (this->m_frame_shutter * 2.0f) / this->m_rasterMaskHandleTot;
63  float frame_iter = frame;
64 
65  Mask *mask_temp = (Mask *)BKE_id_copy_ex(
66  nullptr, &this->m_mask->id, nullptr, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA);
67 
68  /* trick so we can get unkeyed edits to display */
69  {
70  MaskLayer *masklay;
71  MaskLayerShape *masklay_shape;
72 
73  for (masklay = (MaskLayer *)mask_temp->masklayers.first; masklay;
74  masklay = masklay->next) {
75  masklay_shape = BKE_mask_layer_shape_verify_frame(masklay, this->m_frame_number);
76  BKE_mask_layer_shape_from_mask(masklay, masklay_shape);
77  }
78  }
79 
80  for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
82 
83  /* re-eval frame info */
84  BKE_mask_evaluate(mask_temp, frame_iter, true);
85 
87  mask_temp,
88  this->m_maskWidth,
89  this->m_maskHeight,
90  true,
91  true,
92  this->m_do_feather);
93 
94  frame_iter += frame_step;
95  }
96 
97  BKE_id_free(nullptr, &mask_temp->id);
98  }
99  }
100 }
101 
103 {
104  for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
105  if (this->m_rasterMaskHandles[i]) {
107  this->m_rasterMaskHandles[i] = nullptr;
108  }
109  }
110 }
111 
112 void MaskOperation::determineResolution(unsigned int resolution[2],
113  unsigned int preferredResolution[2])
114 {
115  if (this->m_maskWidth == 0 || this->m_maskHeight == 0) {
116  NodeOperation::determineResolution(resolution, preferredResolution);
117  }
118  else {
119  unsigned int nr[2];
120 
121  nr[0] = this->m_maskWidth;
122  nr[1] = this->m_maskHeight;
123 
124  NodeOperation::determineResolution(resolution, nr);
125 
126  resolution[0] = this->m_maskWidth;
127  resolution[1] = this->m_maskHeight;
128  }
129 }
130 
132  float x,
133  float y,
134  PixelSampler /*sampler*/)
135 {
136  const float xy[2] = {
137  (x * this->m_maskWidthInv) + this->m_mask_px_ofs[0],
138  (y * this->m_maskHeightInv) + this->m_mask_px_ofs[1],
139  };
140 
141  if (this->m_rasterMaskHandleTot == 1) {
142  if (this->m_rasterMaskHandles[0]) {
143  output[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[0], xy);
144  }
145  else {
146  output[0] = 0.0f;
147  }
148  }
149  else {
150  /* In case loop below fails. */
151  output[0] = 0.0f;
152 
153  for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
154  if (this->m_rasterMaskHandles[i]) {
156  }
157  }
158 
159  /* until we get better falloff */
160  output[0] /= this->m_rasterMaskHandleTot;
161  }
162 }
163 
164 } // namespace blender::compositor
typedef float(TangentPoint)[2]
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:145
@ LIB_ID_COPY_NO_ANIMDATA
Definition: BKE_lib_id.h:120
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_id_free(struct Main *bmain, void *idv)
void BKE_mask_evaluate(struct Mask *mask, const float ctime, const bool do_newframe)
Definition: mask.c:1595
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask, const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather)
float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2])
struct MaskLayerShape * BKE_mask_layer_shape_verify_frame(struct MaskLayer *masklay, const int frame)
Definition: mask.c:1803
void BKE_mask_layer_shape_from_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape)
Definition: mask.c:1645
MaskRasterHandle * BKE_maskrasterize_handle_new(void)
_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
Read Guarded memory(de)allocation.
#define output
struct MaskRasterHandle * m_rasterMaskHandles[CMP_NODE_MASK_MBLUR_SAMPLES_MAX]
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) override
void addOutputSocket(DataType datatype)
virtual void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
determine the resolution of this node
void * first
Definition: DNA_listBase.h:47
struct MaskLayer * next
ListBase masklayers