Credit Andrew - updating patches for FFmpeg 7.0 as needed since 6.1, now at 7.0,...
[goodguy/cinelerra.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 "theme.h"
31 #include "loadbalance.h"
32 #include "pluginvclient.h"
33
34 #define RESET_DEFAULT_SETTINGS 20
35 #define RESET_ALL               0
36 #define RESET_RGB               1
37 #define RESET_MIN_BRIGHTNESS    2
38 #define RESET_MAX_BRIGHTNESS    3
39 #define RESET_TOLERANCE         4
40 #define RESET_SATURATION        5
41 #define RESET_MIN_SATURATION    6
42 #define RESET_IN_SLOPE          7
43 #define RESET_OUT_SLOPE         8
44 #define RESET_ALPHA_OFFSET      9
45 #define RESET_SPILL_THRESHOLD  10
46 #define RESET_SPILL_AMOUNT     11
47
48 #define MIN_VALUE   0.00
49 #define MAX_VALUE 100.00
50 #define MIN_SLOPE   0.00
51 #define MAX_SLOPE  20.00
52 #define MAX_ALPHA 100.00
53
54 class ChromaKeyHSV;
55 class ChromaKeyWindow;
56 class ChromaKeyFText;
57 class ChromaKeyFSlider;
58 class ChromaKeyReset;
59 class ChromaKeyClr;
60
61 enum {
62         CHROMAKEY_POSTPROCESS_NONE,
63         CHROMAKEY_POSTPROCESS_BLUR,
64         CHROMAKEY_POSTPROCESS_DILATE
65 };
66
67 class ChromaKeyConfig
68 {
69 public:
70         ChromaKeyConfig();
71         void reset(int clear);
72         void copy_from(ChromaKeyConfig &src);
73         int equivalent(ChromaKeyConfig &src);
74         void interpolate(ChromaKeyConfig &prev,
75                 ChromaKeyConfig &next,
76                 int64_t prev_frame,
77                 int64_t next_frame,
78                 int64_t current_frame);
79         int get_color();
80
81         // Output mode
82         bool  show_mask;
83         // Key color definition
84         float red;
85         float green;
86         float blue;
87         // Key shade definition
88         float min_brightness;
89         float max_brightness;
90         float saturation;
91         float min_saturation;
92         float tolerance;
93         // Mask feathering
94         float in_slope;
95         float out_slope;
96         float alpha_offset;
97         // Spill light compensation
98         float spill_threshold;
99         float spill_amount;
100 };
101
102 class ChromaKeyColor : public BC_GenericButton
103 {
104 public:
105         ChromaKeyColor(ChromaKeyHSV *plugin,
106                 ChromaKeyWindow *gui,
107                 int x,
108                 int y);
109
110         int handle_event();
111
112         ChromaKeyHSV *plugin;
113         ChromaKeyWindow *gui;
114 };
115
116 class ChromaKeyReset : public BC_GenericButton
117 {
118 public:
119         ChromaKeyReset(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
120         int handle_event();
121         ChromaKeyHSV *plugin;
122         ChromaKeyWindow *gui;
123 };
124
125 class ChromaKeyFText : public BC_TumbleTextBox
126 {
127 public:
128         ChromaKeyFText(ChromaKeyHSV *plugin, ChromaKeyWindow *gui,
129                 ChromaKeyFSlider *slider, float *output, int x, int y, float min, float max);
130         ~ChromaKeyFText();
131         int handle_event();
132         ChromaKeyHSV *plugin;
133         ChromaKeyWindow *gui;
134         ChromaKeyFSlider *slider;
135         float *output;
136         float min, max;
137 };
138
139 class ChromaKeyFSlider : public BC_FSlider
140 {
141 public:
142         ChromaKeyFSlider(ChromaKeyHSV *plugin,
143                 ChromaKeyFText *text, float *output, int x, int y,
144                 float min, float max, int w);
145         ~ChromaKeyFSlider();
146         int handle_event();
147         ChromaKeyHSV *plugin;
148         ChromaKeyFText *text;
149         float *output;
150 };
151
152 class ChromaKeyClr : public BC_Button
153 {
154 public:
155         ChromaKeyClr(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y, int clear);
156         ~ChromaKeyClr();
157         int handle_event();
158         ChromaKeyHSV *plugin;
159         ChromaKeyWindow *gui;
160         int clear;
161 };
162
163
164 class ChromaKeyUseColorPicker : public BC_GenericButton
165 {
166 public:
167         ChromaKeyUseColorPicker(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
168         int handle_event();
169         ChromaKeyHSV *plugin;
170         ChromaKeyWindow *gui;
171 };
172
173
174 class ChromaKeyColorThread : public ColorPicker
175 {
176 public:
177         ChromaKeyColorThread(ChromaKeyHSV *plugin, ChromaKeyWindow *gui);
178         int handle_new_color(int output, int alpha);
179         ChromaKeyHSV *plugin;
180         ChromaKeyWindow *gui;
181 };
182
183 class ChromaKeyShowMask : public BC_CheckBox
184 {
185 public:
186         ChromaKeyShowMask(ChromaKeyHSV *plugin, int x, int y);
187         int handle_event();
188         ChromaKeyHSV *plugin;
189 };
190
191
192
193 class ChromaKeyWindow : public PluginClientWindow
194 {
195 public:
196         ChromaKeyWindow(ChromaKeyHSV *plugin);
197         ~ChromaKeyWindow();
198
199         void create_objects();
200         void update_sample();
201         void update_gui(int clear);
202         void done_event(int result);
203
204         ChromaKeyColor *color;
205         ChromaKeyUseColorPicker *use_colorpicker;
206
207         ChromaKeyFText *min_brightness_text;
208         ChromaKeyFSlider *min_brightness_slider;
209         ChromaKeyClr *min_brightness_Clr;
210
211         ChromaKeyFText *max_brightness_text;
212         ChromaKeyFSlider *max_brightness_slider;
213         ChromaKeyClr *max_brightness_Clr;
214
215         ChromaKeyFText *saturation_text;
216         ChromaKeyFSlider *saturation_slider;
217         ChromaKeyClr *saturation_Clr;
218
219         ChromaKeyFText *min_saturation_text;
220         ChromaKeyFSlider *min_saturation_slider;
221         ChromaKeyClr *min_saturation_Clr;
222
223         ChromaKeyFText *tolerance_text;
224         ChromaKeyFSlider *tolerance_slider;
225         ChromaKeyClr *tolerance_Clr;
226
227         ChromaKeyFText *in_slope_text;
228         ChromaKeyFSlider *in_slope_slider;
229         ChromaKeyClr *in_slope_Clr;
230
231         ChromaKeyFText *out_slope_text;
232         ChromaKeyFSlider *out_slope_slider;
233         ChromaKeyClr *out_slope_Clr;
234
235         ChromaKeyFText *alpha_offset_text;
236         ChromaKeyFSlider *alpha_offset_slider;
237         ChromaKeyClr *alpha_offset_Clr;
238
239         ChromaKeyFText *spill_threshold_text;
240         ChromaKeyFSlider *spill_threshold_slider;
241         ChromaKeyClr *spill_threshold_Clr;
242
243         ChromaKeyFText *spill_amount_text;
244         ChromaKeyFSlider *spill_amount_slider;
245         ChromaKeyClr *spill_amount_Clr;
246
247         ChromaKeyShowMask *show_mask;
248         ChromaKeyReset *reset;
249         BC_SubWindow *sample;
250         ChromaKeyHSV *plugin;
251         ChromaKeyColorThread *color_thread;
252 };
253
254
255
256
257
258
259
260 class ChromaKeyServer : public LoadServer
261 {
262 public:
263         ChromaKeyServer(ChromaKeyHSV *plugin);
264         void init_packages();
265         LoadClient* new_client();
266         LoadPackage* new_package();
267         ChromaKeyHSV *plugin;
268 };
269
270 class ChromaKeyPackage : public LoadPackage
271 {
272 public:
273         ChromaKeyPackage();
274         int y1, y2;
275 };
276
277 class ChromaKeyUnit : public LoadClient
278 {
279 public:
280         ChromaKeyUnit(ChromaKeyHSV *plugin, ChromaKeyServer *server);
281         void process_package(LoadPackage *package);
282         template <typename component_type> void process_chromakey(int components, component_type max, bool use_yuv, ChromaKeyPackage *pkg);
283         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);
284
285         ChromaKeyHSV *plugin;
286
287 };
288
289
290
291
292 class ChromaKeyHSV : public PluginVClient
293 {
294 public:
295         ChromaKeyHSV(PluginServer *server);
296         ~ChromaKeyHSV();
297
298         PLUGIN_CLASS_MEMBERS(ChromaKeyConfig);
299         int process_buffer(VFrame *frame,
300                 int64_t start_position,
301                 double frame_rate);
302         int handle_opengl();
303         int is_realtime();
304         void save_data(KeyFrame *keyframe);
305         void read_data(KeyFrame *keyframe);
306         void update_gui();
307
308         VFrame *input, *output;
309         ChromaKeyServer *engine;
310 };
311
312
313
314
315
316
317
318
319 #endif