titler rework, some code cleanup and 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
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
94 class ChromaKeyMinBrightness : public BC_FSlider
95 {
96         public:
97                 ChromaKeyMinBrightness(ChromaKeyHSV *plugin, int x, int y);
98                 int handle_event();
99                 ChromaKeyHSV *plugin;
100 };
101
102 class ChromaKeyMaxBrightness : public BC_FSlider
103 {
104         public:
105                 ChromaKeyMaxBrightness(ChromaKeyHSV *plugin, int x, int y);
106                 int handle_event();
107                 ChromaKeyHSV *plugin;
108 };
109
110 class ChromaKeySaturation : public BC_FSlider
111 {
112         public:
113                 ChromaKeySaturation(ChromaKeyHSV *plugin, int x, int y);
114                 int handle_event();
115                 ChromaKeyHSV *plugin;
116 };
117
118 class ChromaKeyMinSaturation : public BC_FSlider
119 {
120         public:
121                 ChromaKeyMinSaturation(ChromaKeyHSV *plugin, int x, int y);
122                 int handle_event();
123                 ChromaKeyHSV *plugin;
124 };
125
126
127
128 class ChromaKeyTolerance : public BC_FSlider
129 {
130 public:
131         ChromaKeyTolerance(ChromaKeyHSV *plugin, int x, int y);
132         int handle_event();
133         ChromaKeyHSV *plugin;
134 };
135
136 class ChromaKeyInSlope : public BC_FSlider
137 {
138         public:
139                 ChromaKeyInSlope(ChromaKeyHSV *plugin, int x, int y);
140                 int handle_event();
141                 ChromaKeyHSV *plugin;
142 };
143
144 class ChromaKeyOutSlope : public BC_FSlider
145 {
146         public:
147                 ChromaKeyOutSlope(ChromaKeyHSV *plugin, int x, int y);
148                 int handle_event();
149                 ChromaKeyHSV *plugin;
150 };
151
152 class ChromaKeyAlphaOffset : public BC_FSlider
153 {
154         public:
155                 ChromaKeyAlphaOffset(ChromaKeyHSV *plugin, int x, int y);
156                 int handle_event();
157                 ChromaKeyHSV *plugin;
158 };
159
160 class ChromaKeySpillThreshold : public BC_FSlider
161 {
162 public:
163         ChromaKeySpillThreshold(ChromaKeyHSV *plugin, int x, int y);
164         int handle_event();
165         ChromaKeyHSV *plugin;
166 };
167 class ChromaKeySpillAmount : public BC_FSlider
168 {
169 public:
170         ChromaKeySpillAmount(ChromaKeyHSV *plugin, int x, int y);
171         int handle_event();
172         ChromaKeyHSV *plugin;
173 };
174
175 class ChromaKeyUseColorPicker : public BC_GenericButton
176 {
177 public:
178         ChromaKeyUseColorPicker(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
179         int handle_event();
180         ChromaKeyHSV *plugin;
181         ChromaKeyWindow *gui;
182 };
183
184
185 class ChromaKeyColorThread : public ColorThread
186 {
187 public:
188         ChromaKeyColorThread(ChromaKeyHSV *plugin, ChromaKeyWindow *gui);
189         int handle_new_color(int output, int alpha);
190         ChromaKeyHSV *plugin;
191         ChromaKeyWindow *gui;
192 };
193
194 class ChromaKeyShowMask : public BC_CheckBox
195 {
196 public:
197         ChromaKeyShowMask(ChromaKeyHSV *plugin, int x, int y);
198         int handle_event();
199         ChromaKeyHSV *plugin;
200 };
201
202
203
204 class ChromaKeyWindow : public PluginClientWindow
205 {
206 public:
207         ChromaKeyWindow(ChromaKeyHSV *plugin);
208         ~ChromaKeyWindow();
209
210         void create_objects();
211         void update_sample();
212
213         ChromaKeyColor *color;
214         ChromaKeyUseColorPicker *use_colorpicker;
215         ChromaKeyMinBrightness *min_brightness;
216         ChromaKeyMaxBrightness *max_brightness;
217         ChromaKeySaturation *saturation;
218         ChromaKeyMinSaturation *min_saturation;
219         ChromaKeyTolerance *tolerance;
220         ChromaKeyInSlope *in_slope;
221         ChromaKeyOutSlope *out_slope;
222         ChromaKeyAlphaOffset *alpha_offset;
223         ChromaKeySpillThreshold *spill_threshold;
224         ChromaKeySpillAmount *spill_amount;
225         ChromaKeyShowMask *show_mask;
226         BC_SubWindow *sample;
227         ChromaKeyHSV *plugin;
228         ChromaKeyColorThread *color_thread;
229 };
230
231
232
233
234
235
236
237 class ChromaKeyServer : public LoadServer
238 {
239 public:
240         ChromaKeyServer(ChromaKeyHSV *plugin);
241         void init_packages();
242         LoadClient* new_client();
243         LoadPackage* new_package();
244         ChromaKeyHSV *plugin;
245 };
246
247 class ChromaKeyPackage : public LoadPackage
248 {
249 public:
250         ChromaKeyPackage();
251         int y1, y2;
252 };
253
254 class ChromaKeyUnit : public LoadClient
255 {
256 public:
257         ChromaKeyUnit(ChromaKeyHSV *plugin, ChromaKeyServer *server);
258         void process_package(LoadPackage *package);
259         template <typename component_type> void process_chromakey(int components, component_type max, bool use_yuv, ChromaKeyPackage *pkg);
260         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);
261
262         ChromaKeyHSV *plugin;
263
264 };
265
266
267
268
269 class ChromaKeyHSV : public PluginVClient
270 {
271 public:
272         ChromaKeyHSV(PluginServer *server);
273         ~ChromaKeyHSV();
274
275         PLUGIN_CLASS_MEMBERS(ChromaKeyConfig);
276         int process_buffer(VFrame *frame,
277                 int64_t start_position,
278                 double frame_rate);
279         int handle_opengl();
280         int is_realtime();
281         void save_data(KeyFrame *keyframe);
282         void read_data(KeyFrame *keyframe);
283         void update_gui();
284
285         VFrame *input, *output;
286         ChromaKeyServer *engine;
287 };
288
289
290
291
292
293
294
295
296 #endif
297
298
299
300
301
302
303