Credit Andrew - fix bug in render farm usage when using in/out pointers or selection
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / chromakeyavid / 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 #include "colorpicker.h"
26 #include "guicast.h"
27 #include "theme.h"
28 #include "loadbalance.h"
29 #include "pluginvclient.h"
30
31 #define RESET_DEFAULT_SETTINGS 20
32 #define RESET_ALL               0
33 #define RESET_RGB               1
34 #define RESET_MIN_BRIGHTNESS    2
35 #define RESET_MAX_BRIGHTNESS    3
36 #define RESET_TOLERANCE         4
37 #define RESET_SATURATION_START  5
38 #define RESET_SATURATION_LINE   6
39 #define RESET_IN_SLOPE          7
40 #define RESET_OUT_SLOPE         8
41 #define RESET_ALPHA_OFFSET      9
42 #define RESET_SPILL_SATURATION 10
43 #define RESET_SPILL_ANGLE      11
44
45 class ChromaKeyAvid;
46 class ChromaKeyWindow;
47 class ChromaKeyText;
48 class ChromaKeySlider;
49 class ChromaKeyClr;
50 class ChromaKeyReset;
51 class ChromaKeyStore;
52 class ChromaKeyRecall;
53 class ChromaKeyExchange;
54 class ChromaKeyUndo;
55
56 enum {
57   CHROMAKEY_POSTPROCESS_NONE,
58   CHROMAKEY_POSTPROCESS_BLUR,
59   CHROMAKEY_POSTPROCESS_DILATE
60 };
61
62
63 class ChromaKeyConfig
64 {
65 public:
66   ChromaKeyConfig();
67   void reset(int clear);
68   void copy_from(ChromaKeyConfig &src);
69   int equivalent(ChromaKeyConfig &src);
70   void interpolate(ChromaKeyConfig &prev,
71                    ChromaKeyConfig &next,
72                    int64_t prev_frame,
73                    int64_t next_frame,
74                    int64_t current_frame);
75   int get_color();
76
77   // Output mode
78   bool  show_mask;
79   // Key color definition
80   float red;
81   float green;
82   float blue;
83   // Key shade definition
84   float min_brightness;
85   float max_brightness;
86   // distance of wedge point from the center
87   float saturation_start;
88   // minimum saturation after wedge point
89   float saturation_line;
90   // hue range
91   float tolerance;
92   // Mask feathering
93   float in_slope;
94   float out_slope;
95   float alpha_offset;
96   // Spill light compensation
97   float spill_saturation;
98   float spill_angle;
99   bool  desaturate_only;
100   // Instances for Store
101   bool  store_show_mask;
102   float store_red;
103   float store_green;
104   float store_blue;
105   float store_min_brightness;
106   float store_max_brightness;
107   float store_saturation_start;
108   float store_saturation_line;
109   float store_tolerance;
110   float store_in_slope;
111   float store_out_slope;
112   float store_alpha_offset;
113   float store_spill_saturation;
114   float store_spill_angle;
115   bool  store_desaturate_only;
116   // Instances for Undo
117   bool  undo_show_mask;
118   float undo_red;
119   float undo_green;
120   float undo_blue;
121   float undo_min_brightness;
122   float undo_max_brightness;
123   float undo_saturation_start;
124   float undo_saturation_line;
125   float undo_tolerance;
126   float undo_in_slope;
127   float undo_out_slope;
128   float undo_alpha_offset;
129   float undo_spill_saturation;
130   float undo_spill_angle;
131   bool  undo_desaturate_only;
132 };
133
134
135 class ChromaKeyColor : public BC_GenericButton
136 {
137 public:
138   ChromaKeyColor(ChromaKeyAvid *plugin,
139                  ChromaKeyWindow *gui,
140                  int x,
141                  int y);
142
143   int handle_event();
144
145   ChromaKeyAvid *plugin;
146   ChromaKeyWindow *gui;
147 };
148
149 class ChromaKeyReset : public BC_GenericButton
150 {
151 public:
152   ChromaKeyReset(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
153   int handle_event();
154   ChromaKeyAvid *plugin;
155   ChromaKeyWindow *gui;
156 };
157
158 class ChromaKeyStore : public BC_GenericButton
159 {
160 public:
161   ChromaKeyStore(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
162   int handle_event();
163   ChromaKeyAvid *plugin;
164   ChromaKeyWindow *gui;
165 };
166
167 class ChromaKeyRecall : public BC_GenericButton
168 {
169 public:
170   ChromaKeyRecall(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
171   int handle_event();
172   ChromaKeyAvid *plugin;
173   ChromaKeyWindow *gui;
174 };
175
176 class ChromaKeyExchange : public BC_GenericButton
177 {
178 public:
179   ChromaKeyExchange(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
180   int handle_event();
181   ChromaKeyAvid *plugin;
182   ChromaKeyWindow *gui;
183 };
184
185 class ChromaKeyUndo : public BC_GenericButton
186 {
187 public:
188   ChromaKeyUndo(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
189   int handle_event();
190   ChromaKeyAvid *plugin;
191   ChromaKeyWindow *gui;
192 };
193
194 class ChromaKeyText : public BC_TumbleTextBox
195 {
196 public:
197   ChromaKeyText(ChromaKeyAvid *plugin, ChromaKeyWindow *gui,
198                 ChromaKeySlider *slider, int x, int y,
199                 float min, float max, float *output);
200   ~ChromaKeyText();
201   int handle_event();
202   ChromaKeyAvid *plugin;
203   ChromaKeyWindow *gui;
204   ChromaKeySlider *slider;
205   float *output;
206   float min, max;
207 };
208
209 class ChromaKeySlider : public BC_FSlider
210 {
211 public:
212   ChromaKeySlider(ChromaKeyAvid *plugin, ChromaKeyText *text,
213                   int x, int y, int w, float min, float max, float *output);
214   ~ChromaKeySlider();
215   int handle_event();
216   ChromaKeyAvid *plugin;
217   ChromaKeyText *text;
218   float *output;
219 };
220
221 class ChromaKeyClr : public BC_Button
222 {
223 public:
224   ChromaKeyClr(ChromaKeyAvid *plugin, ChromaKeyWindow *gui,
225                int x, int y, int clear);
226   ~ChromaKeyClr();
227   int handle_event();
228   ChromaKeyAvid *plugin;
229   ChromaKeyWindow *gui;
230   int clear;
231 };
232
233
234 class ChromaKeyUseColorPicker : public BC_GenericButton
235 {
236 public:
237   ChromaKeyUseColorPicker(ChromaKeyAvid *plugin,
238                           ChromaKeyWindow *gui, int x, int y);
239   int handle_event();
240   ChromaKeyAvid *plugin;
241   ChromaKeyWindow *gui;
242 };
243
244 class ChromaKeyColorThread : public ColorPicker
245 {
246 public:
247   ChromaKeyColorThread(ChromaKeyAvid *plugin, ChromaKeyWindow *gui);
248   int handle_new_color(int output, int alpha);
249   ChromaKeyAvid *plugin;
250   ChromaKeyWindow *gui;
251 };
252
253 class ChromaKeyToggle : public BC_CheckBox
254 {
255 public:
256   ChromaKeyToggle(ChromaKeyAvid *plugin, 
257                   int x, 
258                   int y,
259                   bool *output,
260                   const char *caption);
261   int handle_event();
262   ChromaKeyAvid *plugin;
263   bool *output;
264 };
265
266
267
268 class ChromaKeyWindow : public PluginClientWindow
269 {
270 public:
271   ChromaKeyWindow(ChromaKeyAvid *plugin);
272   ~ChromaKeyWindow();
273
274   void create_objects();
275   void update_sample();
276   void update_gui(int clear);
277   void done_event(int result);
278
279   ChromaKeyColor *color;
280   ChromaKeyUseColorPicker *use_colorpicker;
281
282   ChromaKeyText   *min_brightness_text;
283   ChromaKeySlider *min_brightness;
284   ChromaKeyClr    *min_brightness_clr;
285
286   ChromaKeyText   *max_brightness_text;
287   ChromaKeySlider *max_brightness;
288   ChromaKeyClr    *max_brightness_clr;
289
290   ChromaKeyText   *saturation_start_text;
291   ChromaKeySlider *saturation_start;
292   ChromaKeyClr    *saturation_start_clr;
293
294   ChromaKeyText   *saturation_line_text;
295   ChromaKeySlider *saturation_line;
296   ChromaKeyClr    *saturation_line_clr;
297
298   ChromaKeyText   *tolerance_text;
299   ChromaKeySlider *tolerance;
300   ChromaKeyClr    *tolerance_clr;
301
302   ChromaKeyText   *in_slope_text;
303   ChromaKeySlider *in_slope;
304   ChromaKeyClr    *in_slope_clr;
305
306   ChromaKeyText   *out_slope_text;
307   ChromaKeySlider *out_slope;
308   ChromaKeyClr    *out_slope_clr;
309
310   ChromaKeyText   *alpha_offset_text;
311   ChromaKeySlider *alpha_offset;
312   ChromaKeyClr    *alpha_offset_clr;
313
314   ChromaKeyText   *spill_saturation_text;
315   ChromaKeySlider *spill_saturation;
316   ChromaKeyClr    *spill_saturation_clr;
317
318   ChromaKeyText   *spill_angle_text;
319   ChromaKeySlider *spill_angle;
320   ChromaKeyClr    *spill_angle_clr;
321
322   ChromaKeyToggle *desaturate_only;
323   ChromaKeyToggle *show_mask;
324
325   ChromaKeyReset    *reset;
326   ChromaKeyStore    *store;
327   ChromaKeyRecall   *recall;
328   ChromaKeyExchange *exchange;
329   ChromaKeyUndo     *undo;
330
331   BC_SubWindow *sample;
332   ChromaKeyAvid *plugin;
333   ChromaKeyColorThread *color_thread;
334 };
335
336 class ChromaKeyServer : public LoadServer
337 {
338 public:
339   ChromaKeyServer(ChromaKeyAvid *plugin);
340   void init_packages();
341   LoadClient* new_client();
342   LoadPackage* new_package();
343
344   ChromaKeyAvid *plugin;
345 };
346
347 class ChromaKeyPackage : public LoadPackage
348 {
349 public:
350   ChromaKeyPackage();
351   int y1, y2;
352 };
353
354 class ChromaKeyUnit : public LoadClient
355 {
356 public:
357   ChromaKeyUnit(ChromaKeyAvid *plugin, ChromaKeyServer *server);
358   void process_package(LoadPackage *package);
359   template <typename component_type> void process_chromakey(int components, component_type max, bool use_yuv, ChromaKeyPackage *pkg);
360   bool is_same_color(float r, float g, float b, float rk,float bk,float gk,
361                      float color_threshold, float light_threshold,
362                      int key_main_component);
363
364   ChromaKeyAvid *plugin;
365 };
366
367 class ChromaKeyAvid : public PluginVClient
368 {
369 public:
370   ChromaKeyAvid(PluginServer *server);
371   ~ChromaKeyAvid();
372
373   PLUGIN_CLASS_MEMBERS(ChromaKeyConfig);
374   int process_buffer(VFrame *frame, int64_t start_position, double frame_rate);
375   int handle_opengl();
376   int is_realtime();
377   void save_data(KeyFrame *keyframe);
378   void read_data(KeyFrame *keyframe);
379   void update_gui();
380
381   VFrame *input, *output;
382   ChromaKeyServer *engine;
383 };
384
385 #endif