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
25 #include "colorpicker.h"
28 #include "loadbalance.h"
29 #include "pluginvclient.h"
31 #define RESET_DEFAULT_SETTINGS 20
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
46 class ChromaKeyWindow;
48 class ChromaKeySlider;
52 class ChromaKeyRecall;
53 class ChromaKeyExchange;
57 CHROMAKEY_POSTPROCESS_NONE,
58 CHROMAKEY_POSTPROCESS_BLUR,
59 CHROMAKEY_POSTPROCESS_DILATE
67 void reset(int clear);
68 void copy_from(ChromaKeyConfig &src);
69 int equivalent(ChromaKeyConfig &src);
70 void interpolate(ChromaKeyConfig &prev,
71 ChromaKeyConfig &next,
74 int64_t current_frame);
79 // Key color definition
83 // Key shade definition
86 // distance of wedge point from the center
87 float saturation_start;
88 // minimum saturation after wedge point
89 float saturation_line;
96 // Spill light compensation
97 float spill_saturation;
100 // Instances for Store
101 bool store_show_mask;
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
121 float undo_min_brightness;
122 float undo_max_brightness;
123 float undo_saturation_start;
124 float undo_saturation_line;
125 float undo_tolerance;
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;
135 class ChromaKeyColor : public BC_GenericButton
138 ChromaKeyColor(ChromaKeyAvid *plugin,
139 ChromaKeyWindow *gui,
145 ChromaKeyAvid *plugin;
146 ChromaKeyWindow *gui;
149 class ChromaKeyReset : public BC_GenericButton
152 ChromaKeyReset(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
154 ChromaKeyAvid *plugin;
155 ChromaKeyWindow *gui;
158 class ChromaKeyStore : public BC_GenericButton
161 ChromaKeyStore(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
163 ChromaKeyAvid *plugin;
164 ChromaKeyWindow *gui;
167 class ChromaKeyRecall : public BC_GenericButton
170 ChromaKeyRecall(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
172 ChromaKeyAvid *plugin;
173 ChromaKeyWindow *gui;
176 class ChromaKeyExchange : public BC_GenericButton
179 ChromaKeyExchange(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
181 ChromaKeyAvid *plugin;
182 ChromaKeyWindow *gui;
185 class ChromaKeyUndo : public BC_GenericButton
188 ChromaKeyUndo(ChromaKeyAvid *plugin, ChromaKeyWindow *gui, int x, int y);
190 ChromaKeyAvid *plugin;
191 ChromaKeyWindow *gui;
194 class ChromaKeyText : public BC_TumbleTextBox
197 ChromaKeyText(ChromaKeyAvid *plugin, ChromaKeyWindow *gui,
198 ChromaKeySlider *slider, int x, int y,
199 float min, float max, float *output);
202 ChromaKeyAvid *plugin;
203 ChromaKeyWindow *gui;
204 ChromaKeySlider *slider;
209 class ChromaKeySlider : public BC_FSlider
212 ChromaKeySlider(ChromaKeyAvid *plugin, ChromaKeyText *text,
213 int x, int y, int w, float min, float max, float *output);
216 ChromaKeyAvid *plugin;
221 class ChromaKeyClr : public BC_Button
224 ChromaKeyClr(ChromaKeyAvid *plugin, ChromaKeyWindow *gui,
225 int x, int y, int clear);
228 ChromaKeyAvid *plugin;
229 ChromaKeyWindow *gui;
234 class ChromaKeyUseColorPicker : public BC_GenericButton
237 ChromaKeyUseColorPicker(ChromaKeyAvid *plugin,
238 ChromaKeyWindow *gui, int x, int y);
240 ChromaKeyAvid *plugin;
241 ChromaKeyWindow *gui;
244 class ChromaKeyColorThread : public ColorPicker
247 ChromaKeyColorThread(ChromaKeyAvid *plugin, ChromaKeyWindow *gui);
248 int handle_new_color(int output, int alpha);
249 ChromaKeyAvid *plugin;
250 ChromaKeyWindow *gui;
253 class ChromaKeyToggle : public BC_CheckBox
256 ChromaKeyToggle(ChromaKeyAvid *plugin,
260 const char *caption);
262 ChromaKeyAvid *plugin;
268 class ChromaKeyWindow : public PluginClientWindow
271 ChromaKeyWindow(ChromaKeyAvid *plugin);
274 void create_objects();
275 void update_sample();
276 void update_gui(int clear);
277 void done_event(int result);
279 ChromaKeyColor *color;
280 ChromaKeyUseColorPicker *use_colorpicker;
282 ChromaKeyText *min_brightness_text;
283 ChromaKeySlider *min_brightness;
284 ChromaKeyClr *min_brightness_clr;
286 ChromaKeyText *max_brightness_text;
287 ChromaKeySlider *max_brightness;
288 ChromaKeyClr *max_brightness_clr;
290 ChromaKeyText *saturation_start_text;
291 ChromaKeySlider *saturation_start;
292 ChromaKeyClr *saturation_start_clr;
294 ChromaKeyText *saturation_line_text;
295 ChromaKeySlider *saturation_line;
296 ChromaKeyClr *saturation_line_clr;
298 ChromaKeyText *tolerance_text;
299 ChromaKeySlider *tolerance;
300 ChromaKeyClr *tolerance_clr;
302 ChromaKeyText *in_slope_text;
303 ChromaKeySlider *in_slope;
304 ChromaKeyClr *in_slope_clr;
306 ChromaKeyText *out_slope_text;
307 ChromaKeySlider *out_slope;
308 ChromaKeyClr *out_slope_clr;
310 ChromaKeyText *alpha_offset_text;
311 ChromaKeySlider *alpha_offset;
312 ChromaKeyClr *alpha_offset_clr;
314 ChromaKeyText *spill_saturation_text;
315 ChromaKeySlider *spill_saturation;
316 ChromaKeyClr *spill_saturation_clr;
318 ChromaKeyText *spill_angle_text;
319 ChromaKeySlider *spill_angle;
320 ChromaKeyClr *spill_angle_clr;
322 ChromaKeyToggle *desaturate_only;
323 ChromaKeyToggle *show_mask;
325 ChromaKeyReset *reset;
326 ChromaKeyStore *store;
327 ChromaKeyRecall *recall;
328 ChromaKeyExchange *exchange;
331 BC_SubWindow *sample;
332 ChromaKeyAvid *plugin;
333 ChromaKeyColorThread *color_thread;
336 class ChromaKeyServer : public LoadServer
339 ChromaKeyServer(ChromaKeyAvid *plugin);
340 void init_packages();
341 LoadClient* new_client();
342 LoadPackage* new_package();
344 ChromaKeyAvid *plugin;
347 class ChromaKeyPackage : public LoadPackage
354 class ChromaKeyUnit : public LoadClient
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);
364 ChromaKeyAvid *plugin;
367 class ChromaKeyAvid : public PluginVClient
370 ChromaKeyAvid(PluginServer *server);
373 PLUGIN_CLASS_MEMBERS(ChromaKeyConfig);
374 int process_buffer(VFrame *frame, int64_t start_position, double frame_rate);
377 void save_data(KeyFrame *keyframe);
378 void read_data(KeyFrame *keyframe);
381 VFrame *input, *output;
382 ChromaKeyServer *engine;