upgrades to scopewindow, add blurbox, bd.sh sed tab test, tweak clk2play over window...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / videoscope / videoscope.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 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 #include "bcdisplayinfo.h"
23 #include "bccolors.h"
24 #include "clip.h"
25 #include "bchash.h"
26 #include "filexml.h"
27 #include "guicast.h"
28 #include "language.h"
29 #include "loadbalance.h"
30 #include "bccolors.h"
31 #include "pluginvclient.h"
32 #include "fonts.h"
33 #include "scopewindow.h"
34 #include "theme.h"
35 #include "vframe.h"
36
37 #include <math.h>
38 #include <stdint.h>
39 #include <string.h>
40
41
42 class VideoScopeEffect;
43 class VideoScopeWindow;
44
45 class VideoScopeConfig
46 {
47 public:
48         VideoScopeConfig();
49 };
50
51 class VideoScopeWindow : public ScopeGUI
52 {
53 public:
54         VideoScopeWindow(VideoScopeEffect *plugin);
55         ~VideoScopeWindow();
56
57         void create_objects();
58         void toggle_event();
59         int resize_event(int w, int h);
60
61         VideoScopeEffect *plugin;
62 };
63
64 class VideoScopeEffect : public PluginVClient
65 {
66 public:
67         VideoScopeEffect(PluginServer *server);
68         ~VideoScopeEffect();
69
70
71         PLUGIN_CLASS_MEMBERS2(VideoScopeConfig)
72         int process_realtime(VFrame *input, VFrame *output);
73         int is_realtime();
74         void render_gui(void *input);
75         void save_data(KeyFrame *keyframe);
76         void read_data(KeyFrame *keyframe);
77
78         int use_hist, use_wave, use_vector;
79         int use_hist_parade, use_wave_parade;
80         int use_wave_gain, use_vect_gain, use_smooth;
81
82         int w, h;
83         VFrame *input;
84 };
85
86
87 VideoScopeConfig::VideoScopeConfig()
88 {
89 }
90
91 VideoScopeWindow::VideoScopeWindow(VideoScopeEffect *plugin)
92  : ScopeGUI(plugin, plugin->w, plugin->h)
93 {
94         this->plugin = plugin;
95 }
96
97 VideoScopeWindow::~VideoScopeWindow()
98 {
99 }
100
101 void VideoScopeWindow::create_objects()
102 {
103         use_hist = plugin->use_hist;
104         use_wave = plugin->use_wave;
105         use_vector = plugin->use_vector;
106         use_hist_parade = plugin->use_hist_parade;
107         use_wave_parade = plugin->use_wave_parade;
108         use_wave_gain = plugin->use_wave_gain;
109         use_vect_gain = plugin->use_vect_gain;
110         use_smooth = plugin->use_smooth;
111
112         ScopeGUI::create_objects();
113 }
114
115 void VideoScopeWindow::toggle_event()
116 {
117         plugin->use_hist = use_hist;
118         plugin->use_wave = use_wave;
119         plugin->use_vector = use_vector;
120         plugin->use_hist_parade = use_hist_parade;
121         plugin->use_wave_parade = use_wave_parade;
122         plugin->use_wave_gain = use_wave_gain;
123         plugin->use_vect_gain = use_vect_gain;
124         plugin->use_smooth = use_smooth;
125 // Make it reprocess
126         plugin->send_configure_change();
127 }
128
129
130 int VideoScopeWindow::resize_event(int w, int h)
131 {
132         ScopeGUI::resize_event(w, h);
133         plugin->w = w;
134         plugin->h = h;
135 // Make it reprocess
136         plugin->send_configure_change();
137         return 1;
138 }
139
140 REGISTER_PLUGIN(VideoScopeEffect)
141
142 VideoScopeEffect::VideoScopeEffect(PluginServer *server)
143  : PluginVClient(server)
144 {
145         w = MIN_SCOPE_W;
146         h = MIN_SCOPE_H;
147         use_hist = 0;
148         use_wave = 0;
149         use_vector = 1;
150         use_hist_parade = 1;
151         use_wave_parade = 1;
152         use_wave_gain = 5;
153         use_vect_gain = 5;
154         use_smooth = 1;
155 }
156
157 VideoScopeEffect::~VideoScopeEffect()
158 {
159 }
160
161 const char* VideoScopeEffect::plugin_title() { return N_("VideoScope"); }
162 int VideoScopeEffect::is_realtime() { return 1; }
163
164 int VideoScopeEffect::load_configuration()
165 {
166         return 0;
167 }
168
169 void VideoScopeEffect::save_data(KeyFrame *keyframe)
170 {
171         FileXML output;
172
173 // cause data to be stored directly in text
174         output.set_shared_output(keyframe->xbuf);
175         output.tag.set_title("VIDEOSCOPE");
176         if( is_defaults() ) {
177                 output.tag.set_property("W", w);
178                 output.tag.set_property("H", h);
179                 output.tag.set_property("USE_HIST", use_hist);
180                 output.tag.set_property("USE_WAVE", use_wave);
181                 output.tag.set_property("USE_VECTOR", use_vector);
182                 output.tag.set_property("USE_HIST_PARADE", use_hist_parade);
183                 output.tag.set_property("USE_WAVE_PARADE", use_wave_parade);
184                 output.tag.set_property("USE_WAVE_GAIN", use_wave_gain);
185                 output.tag.set_property("USE_VECT_GAIN", use_vect_gain);
186                 output.tag.set_property("USE_SMOOTH", use_smooth);
187
188         }
189         output.append_tag();
190         output.tag.set_title("/VIDEOSCOPE");
191         output.append_tag();
192         output.append_newline();
193         output.terminate_string();
194 }
195
196 void VideoScopeEffect::read_data(KeyFrame *keyframe)
197 {
198         FileXML input;
199         input.set_shared_input(keyframe->xbuf);
200         int result = 0;
201
202         while( !(result = input.read_tag()) ) {
203                 if( input.tag.title_is("VIDEOSCOPE") ) {
204                         if( is_defaults() ) {
205                                 w = input.tag.get_property("W", w);
206                                 h = input.tag.get_property("H", h);
207                                 use_hist = input.tag.get_property("USE_HIST", use_hist);
208                                 use_wave = input.tag.get_property("USE_WAVE", use_wave);
209                                 use_vector = input.tag.get_property("USE_VECTOR", use_vector);
210                                 use_hist_parade = input.tag.get_property("USE_HIST_PARADE", use_hist_parade);
211                                 use_wave_parade = input.tag.get_property("USE_WAVE_PARADE", use_wave_parade);
212                                 use_wave_gain = input.tag.get_property("USE_WAVE_GAIN", use_wave_gain);
213                                 use_vect_gain = input.tag.get_property("USE_VECT_GAIN", use_vect_gain);
214                                 use_smooth = input.tag.get_property("USE_SMOOTH", use_smooth);
215                         }
216                 }
217         }
218 }
219
220 NEW_WINDOW_MACRO(VideoScopeEffect, VideoScopeWindow)
221
222 int VideoScopeEffect::process_realtime(VFrame *input, VFrame *output)
223 {
224
225         send_render_gui(input);
226         if( input->get_rows()[0] != output->get_rows()[0] )
227                 output->copy_from(input);
228         return 1;
229 }
230
231 void VideoScopeEffect::render_gui(void *input)
232 {
233         if( !thread ) return;
234         VideoScopeWindow *window = ((VideoScopeWindow*)thread->window);
235         window->lock_window();
236         this->input = (VFrame*)input;
237         window->process(this->input);
238         window->unlock_window();
239 }
240