533f481216670e7f5c01c7221b1a60c0ba2a287f
[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;
81         int use_smooth, use_graticule;
82
83         int w, h;
84         VFrame *input;
85 };
86
87
88 VideoScopeConfig::VideoScopeConfig()
89 {
90 }
91
92 VideoScopeWindow::VideoScopeWindow(VideoScopeEffect *plugin)
93  : ScopeGUI(plugin, plugin->w, plugin->h)
94 {
95         this->plugin = plugin;
96 }
97
98 VideoScopeWindow::~VideoScopeWindow()
99 {
100 }
101
102 void VideoScopeWindow::create_objects()
103 {
104         use_hist = plugin->use_hist;
105         use_wave = plugin->use_wave;
106         use_vector = plugin->use_vector;
107         use_hist_parade = plugin->use_hist_parade;
108         use_wave_parade = plugin->use_wave_parade;
109         use_wave_gain = plugin->use_wave_gain;
110         use_vect_gain = plugin->use_vect_gain;
111         use_smooth = plugin->use_smooth;
112         use_refresh = -1;
113         use_graticule = plugin->use_graticule;
114
115         ScopeGUI::create_objects();
116 }
117
118 void VideoScopeWindow::toggle_event()
119 {
120         plugin->use_hist = use_hist;
121         plugin->use_wave = use_wave;
122         plugin->use_vector = use_vector;
123         plugin->use_hist_parade = use_hist_parade;
124         plugin->use_wave_parade = use_wave_parade;
125         plugin->use_wave_gain = use_wave_gain;
126         plugin->use_vect_gain = use_vect_gain;
127         plugin->use_smooth = use_smooth;
128         plugin->use_graticule = use_graticule;
129 // Make it reprocess
130         plugin->send_configure_change();
131 }
132
133
134 int VideoScopeWindow::resize_event(int w, int h)
135 {
136         ScopeGUI::resize_event(w, h);
137         plugin->w = w;
138         plugin->h = h;
139 // Make it reprocess
140         plugin->send_configure_change();
141         return 1;
142 }
143
144 REGISTER_PLUGIN(VideoScopeEffect)
145
146 VideoScopeEffect::VideoScopeEffect(PluginServer *server)
147  : PluginVClient(server)
148 {
149         w = MIN_SCOPE_W;
150         h = MIN_SCOPE_H;
151         use_hist = 0;
152         use_wave = 0;
153         use_vector = 1;
154         use_hist_parade = 1;
155         use_wave_parade = 1;
156         use_wave_gain = 5;
157         use_vect_gain = 5;
158         use_smooth = 1;
159         use_graticule = 0;
160 }
161
162 VideoScopeEffect::~VideoScopeEffect()
163 {
164 }
165
166 const char* VideoScopeEffect::plugin_title() { return N_("VideoScope"); }
167 int VideoScopeEffect::is_realtime() { return 1; }
168
169 int VideoScopeEffect::load_configuration()
170 {
171         return 0;
172 }
173
174 void VideoScopeEffect::save_data(KeyFrame *keyframe)
175 {
176         FileXML output;
177
178 // cause data to be stored directly in text
179         output.set_shared_output(keyframe->xbuf);
180         output.tag.set_title("VIDEOSCOPE");
181         if( is_defaults() ) {
182                 output.tag.set_property("W", w);
183                 output.tag.set_property("H", h);
184                 output.tag.set_property("USE_HIST", use_hist);
185                 output.tag.set_property("USE_WAVE", use_wave);
186                 output.tag.set_property("USE_VECTOR", use_vector);
187                 output.tag.set_property("USE_HIST_PARADE", use_hist_parade);
188                 output.tag.set_property("USE_WAVE_PARADE", use_wave_parade);
189                 output.tag.set_property("USE_WAVE_GAIN", use_wave_gain);
190                 output.tag.set_property("USE_VECT_GAIN", use_vect_gain);
191                 output.tag.set_property("USE_SMOOTH", use_smooth);
192                 output.tag.set_property("USE_GRATICULE", use_graticule);
193
194         }
195         output.append_tag();
196         output.tag.set_title("/VIDEOSCOPE");
197         output.append_tag();
198         output.append_newline();
199         output.terminate_string();
200 }
201
202 void VideoScopeEffect::read_data(KeyFrame *keyframe)
203 {
204         FileXML input;
205         input.set_shared_input(keyframe->xbuf);
206         int result = 0;
207
208         while( !(result = input.read_tag()) ) {
209                 if( input.tag.title_is("VIDEOSCOPE") ) {
210                         if( is_defaults() ) {
211                                 w = input.tag.get_property("W", w);
212                                 h = input.tag.get_property("H", h);
213                                 use_hist = input.tag.get_property("USE_HIST", use_hist);
214                                 use_wave = input.tag.get_property("USE_WAVE", use_wave);
215                                 use_vector = input.tag.get_property("USE_VECTOR", use_vector);
216                                 use_hist_parade = input.tag.get_property("USE_HIST_PARADE", use_hist_parade);
217                                 use_wave_parade = input.tag.get_property("USE_WAVE_PARADE", use_wave_parade);
218                                 use_wave_gain = input.tag.get_property("USE_WAVE_GAIN", use_wave_gain);
219                                 use_vect_gain = input.tag.get_property("USE_VECT_GAIN", use_vect_gain);
220                                 use_smooth = input.tag.get_property("USE_SMOOTH", use_smooth);
221                                 use_graticule = input.tag.get_property("USE_GRATICULE", use_graticule);
222                         }
223                 }
224         }
225 }
226
227 NEW_WINDOW_MACRO(VideoScopeEffect, VideoScopeWindow)
228
229 int VideoScopeEffect::process_realtime(VFrame *input, VFrame *output)
230 {
231
232         send_render_gui(input);
233         if( input->get_rows()[0] != output->get_rows()[0] )
234                 output->copy_from(input);
235         return 1;
236 }
237
238 void VideoScopeEffect::render_gui(void *input)
239 {
240         if( !thread ) return;
241         VideoScopeWindow *window = ((VideoScopeWindow*)thread->window);
242         window->lock_window();
243         this->input = (VFrame*)input;
244         window->process(this->input);
245         window->unlock_window();
246 }
247