4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
28 #include "colorpicker.h"
31 #include "loadbalance.h"
32 #include "pluginvclient.h"
34 #define RESET_DEFAULT_SETTINGS 20
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
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
55 class ChromaKeyWindow;
57 class ChromaKeyFSlider;
62 CHROMAKEY_POSTPROCESS_NONE,
63 CHROMAKEY_POSTPROCESS_BLUR,
64 CHROMAKEY_POSTPROCESS_DILATE
71 void reset(int clear);
72 void copy_from(ChromaKeyConfig &src);
73 int equivalent(ChromaKeyConfig &src);
74 void interpolate(ChromaKeyConfig &prev,
75 ChromaKeyConfig &next,
78 int64_t current_frame);
83 // Key color definition
87 // Key shade definition
97 // Spill light compensation
98 float spill_threshold;
102 class ChromaKeyColor : public BC_GenericButton
105 ChromaKeyColor(ChromaKeyHSV *plugin,
106 ChromaKeyWindow *gui,
112 ChromaKeyHSV *plugin;
113 ChromaKeyWindow *gui;
116 class ChromaKeyReset : public BC_GenericButton
119 ChromaKeyReset(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
121 ChromaKeyHSV *plugin;
122 ChromaKeyWindow *gui;
125 class ChromaKeyFText : public BC_TumbleTextBox
128 ChromaKeyFText(ChromaKeyHSV *plugin, ChromaKeyWindow *gui,
129 ChromaKeyFSlider *slider, float *output, int x, int y, float min, float max);
132 ChromaKeyHSV *plugin;
133 ChromaKeyWindow *gui;
134 ChromaKeyFSlider *slider;
139 class ChromaKeyFSlider : public BC_FSlider
142 ChromaKeyFSlider(ChromaKeyHSV *plugin,
143 ChromaKeyFText *text, float *output, int x, int y,
144 float min, float max, int w);
147 ChromaKeyHSV *plugin;
148 ChromaKeyFText *text;
152 class ChromaKeyClr : public BC_Button
155 ChromaKeyClr(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y, int clear);
158 ChromaKeyHSV *plugin;
159 ChromaKeyWindow *gui;
164 class ChromaKeyUseColorPicker : public BC_GenericButton
167 ChromaKeyUseColorPicker(ChromaKeyHSV *plugin, ChromaKeyWindow *gui, int x, int y);
169 ChromaKeyHSV *plugin;
170 ChromaKeyWindow *gui;
174 class ChromaKeyColorThread : public ColorPicker
177 ChromaKeyColorThread(ChromaKeyHSV *plugin, ChromaKeyWindow *gui);
178 int handle_new_color(int output, int alpha);
179 ChromaKeyHSV *plugin;
180 ChromaKeyWindow *gui;
183 class ChromaKeyShowMask : public BC_CheckBox
186 ChromaKeyShowMask(ChromaKeyHSV *plugin, int x, int y);
188 ChromaKeyHSV *plugin;
193 class ChromaKeyWindow : public PluginClientWindow
196 ChromaKeyWindow(ChromaKeyHSV *plugin);
199 void create_objects();
200 void update_sample();
201 void update_gui(int clear);
202 void done_event(int result);
204 ChromaKeyColor *color;
205 ChromaKeyUseColorPicker *use_colorpicker;
207 ChromaKeyFText *min_brightness_text;
208 ChromaKeyFSlider *min_brightness_slider;
209 ChromaKeyClr *min_brightness_Clr;
211 ChromaKeyFText *max_brightness_text;
212 ChromaKeyFSlider *max_brightness_slider;
213 ChromaKeyClr *max_brightness_Clr;
215 ChromaKeyFText *saturation_text;
216 ChromaKeyFSlider *saturation_slider;
217 ChromaKeyClr *saturation_Clr;
219 ChromaKeyFText *min_saturation_text;
220 ChromaKeyFSlider *min_saturation_slider;
221 ChromaKeyClr *min_saturation_Clr;
223 ChromaKeyFText *tolerance_text;
224 ChromaKeyFSlider *tolerance_slider;
225 ChromaKeyClr *tolerance_Clr;
227 ChromaKeyFText *in_slope_text;
228 ChromaKeyFSlider *in_slope_slider;
229 ChromaKeyClr *in_slope_Clr;
231 ChromaKeyFText *out_slope_text;
232 ChromaKeyFSlider *out_slope_slider;
233 ChromaKeyClr *out_slope_Clr;
235 ChromaKeyFText *alpha_offset_text;
236 ChromaKeyFSlider *alpha_offset_slider;
237 ChromaKeyClr *alpha_offset_Clr;
239 ChromaKeyFText *spill_threshold_text;
240 ChromaKeyFSlider *spill_threshold_slider;
241 ChromaKeyClr *spill_threshold_Clr;
243 ChromaKeyFText *spill_amount_text;
244 ChromaKeyFSlider *spill_amount_slider;
245 ChromaKeyClr *spill_amount_Clr;
247 ChromaKeyShowMask *show_mask;
248 ChromaKeyReset *reset;
249 BC_SubWindow *sample;
250 ChromaKeyHSV *plugin;
251 ChromaKeyColorThread *color_thread;
260 class ChromaKeyServer : public LoadServer
263 ChromaKeyServer(ChromaKeyHSV *plugin);
264 void init_packages();
265 LoadClient* new_client();
266 LoadPackage* new_package();
267 ChromaKeyHSV *plugin;
270 class ChromaKeyPackage : public LoadPackage
277 class ChromaKeyUnit : public LoadClient
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);
285 ChromaKeyHSV *plugin;
292 class ChromaKeyHSV : public PluginVClient
295 ChromaKeyHSV(PluginServer *server);
298 PLUGIN_CLASS_MEMBERS(ChromaKeyConfig);
299 int process_buffer(VFrame *frame,
300 int64_t start_position,
304 void save_data(KeyFrame *keyframe);
305 void read_data(KeyFrame *keyframe);
308 VFrame *input, *output;
309 ChromaKeyServer *engine;