* Added new dilate/erode function
[blender.git] / source / blender / compositor / operations / COM_DilateErodeOperation.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
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.
8  *
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.
13  *
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.
17  *
18  * Contributor: 
19  *              Jeroen Bakker 
20  *              Monique Dewanchand
21  */
22
23 #ifndef _COM_DilateErodeOperation_h
24 #define _COM_DilateErodeOperation_h
25 #include "COM_NodeOperation.h"
26
27
28 class DilateErodeDistanceOperation : public NodeOperation {
29 private:
30         /**
31           * Cached reference to the inputProgram
32           */
33         SocketReader * inputProgram;
34         
35         float distance;
36         float _switch;
37         float inset;
38         
39         /**
40           * determines the area of interest to track pixels
41           * keep this one as small as possible for speed gain.
42           */
43         int scope;
44 public:
45         DilateErodeDistanceOperation();
46         
47         /**
48           * the inner loop of this program
49           */
50         void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data);
51         
52         /**
53           * Initialize the execution
54           */
55         void initExecution();
56         
57         void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
58         /**
59           * Deinitialize the execution
60           */
61         void deinitExecution();
62         
63         void setDistance(float distance) {this->distance = distance;}
64         void setSwitch(float sw) {this->_switch = sw;}
65         void setInset(float inset) {this->inset = inset;}
66         
67         bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
68
69 };
70
71 class DilateDistanceOperation : public NodeOperation {
72 private:
73         /**
74           * Cached reference to the inputProgram
75           */
76         SocketReader * inputProgram;
77 protected:
78         float distance;
79         int scope;
80 public:
81         DilateDistanceOperation();
82         
83         /**
84           * the inner loop of this program
85           */
86         void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data);
87         
88         /**
89           * Initialize the execution
90           */
91         void initExecution();
92         
93         void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
94         /**
95           * Deinitialize the execution
96           */
97         void deinitExecution();
98         
99         void setDistance(float distance) {this->distance = distance;}
100         bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
101 };
102 class ErodeDistanceOperation : public DilateDistanceOperation {
103 public:
104         ErodeDistanceOperation();
105         
106         /**
107           * the inner loop of this program
108           */
109         void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data);
110 };
111
112 class DilateStepOperation : public NodeOperation {
113 protected:
114         /**
115           * Cached reference to the inputProgram
116           */
117         SocketReader * inputProgram;
118         
119         int iterations;
120         
121         float *cached_buffer;
122 public:
123         DilateStepOperation();
124         
125         /**
126           * the inner loop of this program
127           */
128         void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data);
129         
130         /**
131           * Initialize the execution
132           */
133         void initExecution();
134         
135         void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
136         /**
137           * Deinitialize the execution
138           */
139         void deinitExecution();
140         
141         void setIterations(int iterations) {this->iterations = iterations;}
142         
143         bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
144 };
145
146 class ErodeStepOperation : public DilateStepOperation {
147 public:
148         ErodeStepOperation();
149         
150         void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
151 };
152
153 #endif