sams last ladspa icons, libopus/vp9, mixer fixer, plugin resets, fmt frmsz, shm fixes
[goodguy/history.git] / cinelerra-5.1 / plugins / chromakeyhsv / chromakey.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef CHROMAKEY_H
23 #define CHROMAKEY_H
24
25
26
27
28 #include "colorpicker.h"
29 #include "guicast.h"
30 #include "loadbalance.h"
31 #include "pluginvclient.h"
32
33
34 class ChromaKeyHSV;
35 class ChromaKeyHSV;
36 class ChromaKeyWindow;
37
38 enum {
39         CHROMAKEY_POSTPROCESS_NONE,
40         CHROMAKEY_POSTPROCESS_BLUR,
41         CHROMAKEY_POSTPROCESS_DILATE
42 };
43
44 class ChromaKeyConfig
45 {
46 public:
47         ChromaKeyConfig();
48         void reset();
49         void copy_from(ChromaKeyConfig &src);
50         int equivalent(ChromaKeyConfig &src);
51         void interpolate(ChromaKeyConfig &prev,
52                 ChromaKeyConfig &next,
53                 int64_t prev_frame,
54                 int64_t next_frame,
55                 int64_t current_frame);
56         int get_color();
57
58         // Output mode
59         bool  show_mask;
60         // Key color definition
61         float red;
62         float green;
63         float blue;
64         // Key shade definition
65         float min_brightness;
66         float max_brightness;
67         float saturation;
68         float min_saturation;
69         float tolerance;
70         // Mask feathering
71         float in_slope;
72         float out_slope;
73         float alpha_offset;
74         // Spill light compensation
75         float spill_threshold;
76         float spill_amount;
77 };
78
79 class ChromaKeyColor : public BC_GenericButton
80 {
81 public:
82         ChromaKeyColor(ChromaKeyHSV *plugin,
83                 ChromaKeyWindow *gui,
84                 int x,
85                 int y);
86
87         int handle_event();
88
89         ChromaKeyHSV *plugin;
90         ChromaKeyWindow *gui;
91 };
92
93 class ChromaKeyReset : public BC_GenericButton
94 {
95 public:
96         ChromaKeyReset(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
97         int handle_event();
98         ChromaKeyHSV *plugin;
99         ChromaKeyWindow *gui;
100 };
101
102
103
104 class ChromaKeyMinBrightness : public BC_FSlider
105 {
106         public:
107                 ChromaKeyMinBrightness(ChromaKeyHSV *plugin, int x, int y);
108                 int handle_event();
109                 ChromaKeyHSV *plugin;
110 };
111
112 class ChromaKeyMaxBrightness : public BC_FSlider
113 {
114         public:
115                 ChromaKeyMaxBrightness(ChromaKeyHSV *plugin, int x, int y);
116                 int handle_event();
117                 ChromaKeyHSV *plugin;
118 };
119
120 class ChromaKeySaturation : public BC_FSlider
121 {
122         public:
123                 ChromaKeySaturation(ChromaKeyHSV *plugin, int x, int y);
124                 int handle_event();
125                 ChromaKeyHSV *plugin;
126 };
127
128 class ChromaKeyMinSaturation : public BC_FSlider
129 {
130         public:
131                 ChromaKeyMinSaturation(ChromaKeyHSV *plugin, int x, int y);
132                 int handle_event();
133                 ChromaKeyHSV *plugin;
134 };
135
136
137
138 class ChromaKeyTolerance : public BC_FSlider
139 {
140 public:
141         ChromaKeyTolerance(ChromaKeyHSV *plugin, int x, int y);
142         int handle_event();
143         ChromaKeyHSV *plugin;
144 };
145
146 class ChromaKeyInSlope : public BC_FSlider
147 {
148         public:
149                 ChromaKeyInSlope(ChromaKeyHSV *plugin, int x, int y);
150                 int handle_event();
151                 ChromaKeyHSV *plugin;
152 };
153
154 class ChromaKeyOutSlope : public BC_FSlider
155 {
156         public:
157                 ChromaKeyOutSlope(ChromaKeyHSV *plugin, int x, int y);
158                 int handle_event();
159                 ChromaKeyHSV *plugin;
160 };
161
162 class ChromaKeyAlphaOffset : public BC_FSlider
163 {
164         public:
165                 ChromaKeyAlphaOffset(ChromaKeyHSV *plugin, int x, int y);
166                 int handle_event();
167                 ChromaKeyHSV *plugin;
168 };
169
170 class ChromaKeySpillThreshold : public BC_FSlider
171 {
172 public:
173         ChromaKeySpillThreshold(ChromaKeyHSV *plugin, int x, int y);
174         int handle_event();
175         ChromaKeyHSV *plugin;
176 };
177 class ChromaKeySpillAmount : public BC_FSlider
178 {
179 public:
180         ChromaKeySpillAmount(ChromaKeyHSV *plugin, int x, int y);
181         int handle_event();
182         ChromaKeyHSV *plugin;
183 };
184
185 class ChromaKeyUseColorPicker : public BC_GenericButton
186 {
187 public:
188         ChromaKeyUseColorPicker(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
189         int handle_event();
190         ChromaKeyHSV *plugin;
191         ChromaKeyWindow *gui;
192 };
193
194
195 class ChromaKeyColorThread : public ColorPicker
196 {
197 public:
198         ChromaKeyColorThread(ChromaKeyHSV *plugin, ChromaKeyWindow *gui);
199         int handle_new_color(int output, int alpha);
200         ChromaKeyHSV *plugin;
201         ChromaKeyWindow *gui;
202 };
203
204 class ChromaKeyShowMask : public BC_CheckBox
205 {
206 public:
207         ChromaKeyShowMask(ChromaKeyHSV *plugin, int x, int y);
208         int handle_event();
209         ChromaKeyHSV *plugin;
210 };
211
212
213
214 class ChromaKeyWindow : public PluginClientWindow
215 {
216 public:
217         ChromaKeyWindow(ChromaKeyHSV *plugin);
218         ~ChromaKeyWindow();
219
220         void create_objects();
221         void update_sample();
222         void update_gui();
223         void done_event(int result);
224
225         ChromaKeyColor *color;
226         ChromaKeyUseColorPicker *use_colorpicker;
227         ChromaKeyMinBrightness *min_brightness;
228         ChromaKeyMaxBrightness *max_brightness;
229         ChromaKeySaturation *saturation;
230         ChromaKeyMinSaturation *min_saturation;
231         ChromaKeyTolerance *tolerance;
232         ChromaKeyInSlope *in_slope;
233         ChromaKeyOutSlope *out_slope;
234         ChromaKeyAlphaOffset *alpha_offset;
235         ChromaKeySpillThreshold *spill_threshold;
236         ChromaKeySpillAmount *spill_amount;
237         ChromaKeyShowMask *show_mask;
238         ChromaKeyReset *reset;
239         BC_SubWindow *sample;
240         ChromaKeyHSV *plugin;
241         ChromaKeyColorThread *color_thread;
242 };
243
244
245
246
247
248
249
250 class ChromaKeyServer : public LoadServer
251 {
252 public:
253         ChromaKeyServer(ChromaKeyHSV *plugin);
254         void init_packages();
255         LoadClient* new_client();
256         LoadPackage* new_package();
257         ChromaKeyHSV *plugin;
258 };
259
260 class ChromaKeyPackage : public LoadPackage
261 {
262 public:
263         ChromaKeyPackage();
264         int y1, y2;
265 };
266
267 class ChromaKeyUnit : public LoadClient
268 {
269 public:
270         ChromaKeyUnit(ChromaKeyHSV *plugin, ChromaKeyServer *server);
271         void process_package(LoadPackage *package);
272         template <typename component_type> void process_chromakey(int components, component_type max, bool use_yuv, ChromaKeyPackage *pkg);
273         bool is_same_color(float r, float g, float b, float rk,float bk,float gk, float color_threshold, float light_threshold, int key_main_component);
274
275         ChromaKeyHSV *plugin;
276
277 };
278
279
280
281
282 class ChromaKeyHSV : public PluginVClient
283 {
284 public:
285         ChromaKeyHSV(PluginServer *server);
286         ~ChromaKeyHSV();
287
288         PLUGIN_CLASS_MEMBERS(ChromaKeyConfig);
289         int process_buffer(VFrame *frame,
290                 int64_t start_position,
291                 double frame_rate);
292         int handle_opengl();
293         int is_realtime();
294         void save_data(KeyFrame *keyframe);
295         void read_data(KeyFrame *keyframe);
296         void update_gui();
297
298         VFrame *input, *output;
299         ChromaKeyServer *engine;
300 };
301
302
303
304
305
306
307
308
309 #endif
310
311
312
313
314
315
316