2 * Copyright 2012, Blender Foundation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "COM_MaskOperation.h"
26 #include "MEM_guardedalloc.h"
28 #include "BLI_listbase.h"
31 #include "DNA_scene_types.h"
35 #include "../../../../intern/raskter/raskter.h"
38 MaskOperation::MaskOperation() : NodeOperation()
40 this->addOutputSocket(COM_DT_VALUE);
44 this->framenumber = 0;
45 this->rasterizedMask = NULL;
49 void MaskOperation::initExecution()
52 this->rasterizedMask = NULL;
55 void MaskOperation::deinitExecution()
57 if (this->rasterizedMask) {
58 MEM_freeN(rasterizedMask);
59 this->rasterizedMask = NULL;
63 void *MaskOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
65 if (this->rasterizedMask)
66 return this->rasterizedMask;
72 if (this->rasterizedMask == NULL) {
73 int width = this->getWidth();
74 int height = this->getHeight();
77 buffer = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask");
78 BKE_mask_rasterize(mask, width, height, buffer, TRUE, this->do_smooth, this->do_feather);
79 if (this->do_smooth) {
80 PLX_antialias_buffer(buffer, width, height);
83 this->rasterizedMask = buffer;
86 return this->rasterizedMask;
89 void MaskOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
91 if (maskWidth == 0 || maskHeight == 0) {
92 NodeOperation::determineResolution(resolution, preferredResolution);
100 NodeOperation::determineResolution(resolution, nr);
102 resolution[0] = maskWidth;
103 resolution[1] = maskHeight;
107 void MaskOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
113 float *buffer = (float *) data;
114 int index = (y * this->getWidth() + x);
116 color[0] = buffer[index];