3 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "bcsignals.h"
27 #include "scopewindow.h"
32 ScopePackage::ScopePackage()
37 ScopeUnit::ScopeUnit(ScopeGUI *gui,
45 #define incr_point(rows,h, iv,comp) { \
46 if(iy >= 0 && iy < h) { \
47 uint8_t *vp = rows[iy] + ix*3 + (comp); \
48 int v = *vp+(iv); *vp = v>0xff ? 0xff : v; } \
50 #define incr_points(rows,h, rv,gv,bv) { \
51 if(iy >= 0 && iy < h) { \
52 uint8_t *vp = rows[iy] + ix*3; \
53 int v = *vp+(rv); *vp++ = v>0xff ? 0xff : v; \
54 v = *vp+(gv); *vp++ = v>0xff ? 0xff : v; \
55 v = *vp+(bv); *vp = v>0xff ? 0xff : v; } \
57 #define clip_points(rows,h, rv,gv,bv) { \
58 if(iy >= 0 && iy < h) { \
59 uint8_t *vp = rows[iy] + ix*3; \
60 int v = *vp+(rv); *vp++ = v>0xff ? 0xff : v<0 ? 0 : v; \
61 v = *vp+(gv); *vp++ = v>0xff ? 0xff : v<0 ? 0 : v; \
62 v = *vp+(bv); *vp = v>0xff ? 0xff : v<0 ? 0 : v; } \
65 #define PROCESS_PIXEL(column) { \
66 /* Calculate histogram */ \
68 int v_i = (intensity - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
69 CLAMP(v_i, 0, TOTAL_BINS - 1); \
72 if(use_hist_parade) { \
73 int r_i = (r - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
74 int g_i = (g - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
75 int b_i = (b - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
76 CLAMP(r_i, 0, TOTAL_BINS - 1); \
77 CLAMP(g_i, 0, TOTAL_BINS - 1); \
78 CLAMP(b_i, 0, TOTAL_BINS - 1); \
83 /* Calculate waveform */ \
84 if(use_wave || use_wave_parade) { \
85 int ix = column * wave_w / dat_w; \
86 if(ix >= 0 && ix < wave_w-1) { \
87 if(use_wave_parade > 0) { \
89 int iy = wave_h - ((r - FLOAT_MIN) / \
90 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
91 incr_point(waveform_rows,wave_h, winc,0); \
93 iy = wave_h - ((g - FLOAT_MIN) / \
94 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
95 incr_point(waveform_rows,wave_h, winc,1); \
97 iy = wave_h - ((b - FLOAT_MIN) / \
98 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
99 incr_point(waveform_rows,wave_h, winc,2); \
101 else if(use_wave_parade < 0) { \
102 int iy = wave_h - ((r - FLOAT_MIN) / \
103 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
104 clip_points(waveform_rows,wave_h, winc,-winc,-winc); \
105 iy = wave_h - ((g - FLOAT_MIN) / \
106 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
107 clip_points(waveform_rows,wave_h, -winc,winc,-winc); \
108 iy = wave_h - ((b - FLOAT_MIN) / \
109 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
110 clip_points(waveform_rows,wave_h, -winc,-winc,winc); \
112 else { float yinc = 3*winc; \
113 float rinc = yinc*(r-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
114 float ginc = yinc*(g-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
115 float binc = yinc*(b-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
116 int iy = wave_h - ((intensity - FLOAT_MIN) / \
117 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
118 incr_points(waveform_rows,wave_h, rinc, ginc, binc); \
122 /* Calculate vectorscope */ \
125 if( th < 0 ) th += 360; \
126 double t = TO_RAD(th); \
127 float adjacent = -cos(t), opposite = sin(t); \
128 int ix = vector_w / 2 + adjacent * (s) / (FLOAT_MAX) * radius; \
129 int iy = vector_h / 2 - opposite * (s) / (FLOAT_MAX) * radius; \
130 CLAMP(ix, 0, vector_w - 1); \
131 /* Get color with full saturation & value */ \
132 float r_f, g_f, b_f; \
133 if( (h=h-90) < 0 ) h += 360; \
134 HSV::hsv_to_rgb(r_f, g_f, b_f, h, s, 1); \
135 int rv = CLIP(r_f, 0, 1) * vinc + 3; \
136 int gv = CLIP(g_f, 0, 1) * vinc + 3; \
137 int bv = CLIP(b_f, 0, 1) * vinc + 3; \
138 incr_points(vector_rows,vector_h, rv,gv,bv); \
142 #define PROCESS_RGB_PIXEL(type,max, column) { \
143 type *rp = (type *)row; \
144 r = (float)rp[0] / max; \
145 g = (float)rp[1] / max; \
146 b = (float)rp[2] / max; \
147 HSV::rgb_to_hsv(r, g, b, h, s, v); \
149 PROCESS_PIXEL(column) \
152 #define PROCESS_BGR_PIXEL(type,max, column) { \
153 type *rp = (type *)row; \
154 b = (float)rp[0] / max; \
155 g = (float)rp[1] / max; \
156 r = (float)rp[2] / max; \
157 HSV::rgb_to_hsv(r, g, b, h, s, v); \
159 PROCESS_PIXEL(column) \
162 #define PROCESS_YUV_PIXEL(column, y_in, u_in, v_in) { \
163 YUV::yuv.yuv_to_rgb_f(r, g, b, y_in, u_in, v_in); \
164 HSV::rgb_to_hsv(r, g, b, h, s, v); \
166 PROCESS_PIXEL(column) \
169 void ScopeUnit::process_package(LoadPackage *package)
171 ScopePackage *pkg = (ScopePackage*)package;
176 int use_hist = gui->use_hist;
177 int use_hist_parade = gui->use_hist_parade;
178 int use_vector = gui->use_vector;
179 int use_wave = gui->use_wave;
180 int use_wave_parade = gui->use_wave_parade;
181 VFrame *waveform_vframe = gui->waveform_vframe;
182 VFrame *vector_vframe = gui->vector_vframe;
183 int wave_h = waveform_vframe->get_h();
184 int wave_w = waveform_vframe->get_w();
185 int vector_h = vector_vframe->get_h();
186 int vector_w = vector_vframe->get_w();
187 int dat_w = gui->data_frame->get_w();
188 int dat_h = gui->data_frame->get_h();
189 int winc = (wave_w * wave_h) / (dat_w * dat_h);
190 if( use_wave_parade ) winc *= 3;
191 winc += 2; winc *= gui->use_wave_gain;
192 int vinc = 3*(vector_w * vector_h) / (dat_w * dat_h) + 2;
193 vinc *= gui->use_vect_gain;
194 float radius = MIN(gui->vector_w / 2, gui->vector_h / 2);
195 uint8_t **waveform_rows = waveform_vframe->get_rows();
196 uint8_t **vector_rows = vector_vframe->get_rows();
197 uint8_t **rows = gui->data_frame->get_rows();
199 switch( gui->data_frame->get_color_model() ) {
201 for( int y=pkg->row1; y<pkg->row2; ++y ) {
202 uint8_t *row = rows[y];
203 for( int x=0; x<dat_w; ++x ) {
204 PROCESS_RGB_PIXEL(uint8_t,0xff, x)
205 row += 3*sizeof(uint8_t);
210 for( int y=pkg->row1; y<pkg->row2; ++y ) {
211 uint8_t *row = rows[y];
212 for( int x=0; x<dat_w; ++x ) {
213 PROCESS_RGB_PIXEL(uint8_t,0xff, x)
214 row += 4*sizeof(uint8_t);
219 for( int y=pkg->row1; y<pkg->row2; ++y ) {
220 uint8_t *row = rows[y];
221 for( int x=0; x<dat_w; ++x ) {
222 PROCESS_RGB_PIXEL(uint16_t,0xffff, x)
223 row += 3*sizeof(uint16_t);
227 case BC_RGBA16161616:
228 for( int y=pkg->row1; y<pkg->row2; ++y ) {
229 uint8_t *row = rows[y];
230 for( int x=0; x<dat_w; ++x ) {
231 PROCESS_RGB_PIXEL(uint16_t,0xffff, x)
232 row += 4*sizeof(uint16_t);
237 for( int y=pkg->row1; y<pkg->row2; ++y ) {
238 uint8_t *row = rows[y];
239 for( int x=0; x<dat_w; ++x ) {
240 PROCESS_BGR_PIXEL(uint8_t,0xff, x)
241 row += 3*sizeof(uint8_t);
246 for( int y=pkg->row1; y<pkg->row2; ++y ) {
247 uint8_t *row = rows[y];
248 for( int x=0; x<dat_w; ++x ) {
249 PROCESS_BGR_PIXEL(uint8_t,0xff, x)
250 row += 4*sizeof(uint8_t);
255 for( int y=pkg->row1; y<pkg->row2; ++y ) {
256 uint8_t *row = rows[y];
257 for( int x=0; x<dat_w; ++x ) {
258 PROCESS_RGB_PIXEL(float,1.f, x)
259 row += 3*sizeof(float);
264 for( int y=pkg->row1; y<pkg->row2; ++y ) {
265 uint8_t *row = rows[y];
266 for( int x=0; x<dat_w; ++x ) {
267 PROCESS_RGB_PIXEL(float,1.f, x)
268 row += 4*sizeof(float);
273 for( int y=pkg->row1; y<pkg->row2; ++y ) {
274 uint8_t *row = rows[y];
275 for( int x=0; x<dat_w; ++x ) {
276 PROCESS_YUV_PIXEL(x, row[0], row[1], row[2])
277 row += 3*sizeof(uint8_t);
283 for( int y=pkg->row1; y<pkg->row2; ++y ) {
284 uint8_t *row = rows[y];
285 for( int x=0; x<dat_w; ++x ) {
286 PROCESS_YUV_PIXEL(x, row[0], row[1], row[2])
287 row += 4*sizeof(uint8_t);
292 uint8_t *yp = gui->data_frame->get_y();
293 uint8_t *up = gui->data_frame->get_u();
294 uint8_t *vp = gui->data_frame->get_v();
295 for( int y=pkg->row1; y<pkg->row2; ++y ) {
296 uint8_t *y_row = yp + y * dat_w;
297 uint8_t *u_row = up + (y / 2) * (dat_w / 2);
298 uint8_t *v_row = vp + (y / 2) * (dat_w / 2);
299 for( int x=0; x<dat_w; x+=2 ) {
300 PROCESS_YUV_PIXEL(x, *y_row, *u_row, *v_row);
302 PROCESS_YUV_PIXEL(x + 1, *y_row, *u_row, *v_row);
303 ++y_row; ++u_row; ++v_row;
308 for( int y=pkg->row1; y<pkg->row2; ++y ) {
309 uint8_t *row = rows[y];
310 for( int x=0; x<dat_w; x+=2 ) {
311 PROCESS_YUV_PIXEL(x, row[0], row[1], row[3]);
312 PROCESS_YUV_PIXEL(x + 1, row[2], row[1], row[3]);
313 row += 4*sizeof(uint8_t);
319 printf("ScopeUnit::process_package %d: color_model=%d unrecognized\n",
320 __LINE__, gui->data_frame->get_color_model());
326 ScopeEngine::ScopeEngine(ScopeGUI *gui, int cpus)
327 : LoadServer(cpus, cpus)
329 //printf("ScopeEngine::ScopeEngine %d cpus=%d\n", __LINE__, cpus);
333 ScopeEngine::~ScopeEngine()
337 void ScopeEngine::init_packages()
339 int y = 0, h = gui->data_frame->get_h();
340 for( int i=0,n=LoadServer::get_total_packages(); i<n; ) {
341 ScopePackage *pkg = (ScopePackage*)get_package(i);
343 pkg->row2 = y = (++i * h) / n;
346 for( int i=0,n=LoadServer::get_total_packages(); i<n; ++i ) {
347 ScopeUnit *unit = (ScopeUnit*)get_client(i);
348 for( int j=0; j<HIST_SECTIONS; ++j )
349 bzero(unit->bins[j], sizeof(int) * TOTAL_BINS);
354 LoadClient* ScopeEngine::new_client()
356 return new ScopeUnit(gui, this);
359 LoadPackage* ScopeEngine::new_package()
361 return new ScopePackage;
364 void ScopeEngine::process()
368 for(int i = 0; i < HIST_SECTIONS; i++)
369 bzero(gui->bins[i], sizeof(int) * TOTAL_BINS);
371 for(int i=0,n=get_total_clients(); i<n; ++i ) {
372 ScopeUnit *unit = (ScopeUnit*)get_client(i);
373 for( int j=0; j<HIST_SECTIONS; ++j ) {
374 int *bp = gui->bins[j], *up = unit->bins[j];
375 for( int k=TOTAL_BINS; --k>=0; ++bp,++up ) *bp += *up;
381 ScopeGUI::ScopeGUI(Theme *theme,
382 int x, int y, int w, int h, int cpus)
383 : PluginClientWindow(_(PROGRAM_NAME ": Scopes"),
384 x, y, w, h, MIN_SCOPE_W, MIN_SCOPE_H, 1)
390 this->temp_frame = 0;
396 ScopeGUI::ScopeGUI(PluginClient *plugin, int w, int h)
397 : PluginClientWindow(plugin, w, h, MIN_SCOPE_W, MIN_SCOPE_H, 1)
403 this->temp_frame = 0;
404 this->theme = plugin->get_theme();
405 this->cpus = plugin->PluginClient::smp + 1;
411 ScopeGUI::~ScopeGUI()
413 delete waveform_vframe;
414 delete vector_vframe;
422 void ScopeGUI::reset()
443 vector_w = vector_h = 0;
447 void ScopeGUI::create_objects()
449 if( use_hist && use_hist_parade )
451 if( use_wave && use_wave_parade )
453 if( !engine ) engine = new ScopeEngine(this, cpus);
455 lock_window("ScopeGUI::create_objects");
456 int x = theme->widget_border;
457 int y = theme->widget_border;
458 add_subwindow(smooth = new ScopeSmooth(this, x, y));
459 y += smooth->get_h() + theme->widget_border;
460 add_subwindow(scope_menu = new ScopeMenu(this, x, y));
461 scope_menu->create_objects();
462 x += scope_menu->get_w() + theme->widget_border;
463 add_subwindow(value_text = new BC_Title(x, y, ""));
464 y += scope_menu->get_h() + theme->widget_border;
473 void ScopeGUI::create_panels()
475 calculate_sizes(get_w(), get_h());
476 int slider_w = xS(100);
477 if( (use_wave || use_wave_parade) ) {
478 int px = wave_x + wave_w - slider_w - xS(5);
479 int py = wave_y - ScopeGain::calculate_h() - yS(5);
481 add_subwindow(waveform = new ScopeWaveform(this,
482 wave_x, wave_y, wave_w, wave_h));
483 waveform->create_objects();
484 wave_slider = new ScopeWaveSlider(this, px, py, slider_w);
485 wave_slider->create_objects();
488 waveform->reposition_window(
489 wave_x, wave_y, wave_w, wave_h);
490 waveform->clear_box(0, 0, wave_w, wave_h);
491 wave_slider->reposition_window(px, py);
494 else if( !(use_wave || use_wave_parade) && waveform ) {
495 delete waveform; waveform = 0;
496 delete wave_slider; wave_slider = 0;
500 int vx = vector_x + vector_w - slider_w - xS(5);
501 int vy = vector_y - ScopeGain::calculate_h() - yS(5);
503 add_subwindow(vectorscope = new ScopeVectorscope(this,
504 vector_x, vector_y, vector_w, vector_h));
505 vectorscope->create_objects();
506 vect_slider = new ScopeVectSlider(this, vx, vy, slider_w);
507 vect_slider->create_objects();
510 vectorscope->reposition_window(
511 vector_x, vector_y, vector_w, vector_h);
512 vectorscope->clear_box(0, 0, vector_w, vector_h);
513 vect_slider->reposition_window(vx, vy);
516 else if( !use_vector && vectorscope ) {
517 delete vectorscope; vectorscope = 0;
518 delete vect_slider; vect_slider = 0;
521 if( (use_hist || use_hist_parade) ) {
523 // printf("ScopeGUI::create_panels %d %d %d %d %d\n", __LINE__,
524 // hist_x, hist_y, hist_w, hist_h);
525 add_subwindow(histogram = new ScopeHistogram(this,
526 hist_x, hist_y, hist_w, hist_h));
527 histogram->create_objects();
530 histogram->reposition_window(
531 hist_x, hist_y, hist_w, hist_h);
532 histogram->clear_box(0, 0, hist_w, hist_h);
535 else if( !(use_hist || use_hist_parade) ) {
536 delete histogram; histogram = 0;
541 draw_overlays(1, 1, 0);
544 void ScopeGUI::clear_points(int flash)
547 histogram->clear_point();
549 waveform->clear_point();
551 vectorscope->clear_point();
552 if( histogram && flash )
554 if( waveform && flash )
556 if( vectorscope && flash )
557 vectorscope->flash(0);
560 void ScopeGUI::toggle_event()
564 void ScopeGUI::calculate_sizes(int w, int h)
566 int margin = theme->widget_border;
567 int menu_h = smooth->get_h() + scope_menu->get_h() + margin * 3;
568 int text_w = get_text_width(SMALLFONT, "000") + margin * 2;
569 int total_panels = ((use_hist || use_hist_parade) ? 1 : 0) +
570 ((use_wave || use_wave_parade) ? 1 : 0) +
571 (use_vector ? 1 : 0);
574 int panel_w = (w - margin) / (total_panels > 0 ? total_panels : 1);
575 // Vectorscope determines the size of everything else
579 vector_x = w - panel_w + text_w;
580 vector_w = w - margin - vector_x;
582 vector_h = h - vector_y - margin;
584 if( vector_w > vector_h ) {
586 vector_x = w - theme->widget_border - vector_w;
590 panel_w = (vector_x - text_w - margin) / total_panels;
593 // Histogram is always 1st panel
594 if( use_hist || use_hist_parade ) {
597 hist_w = panel_w - margin;
598 hist_h = h - hist_y - margin;
604 if( use_wave || use_wave_parade ) {
607 wave_w = panel_w - margin - text_w;
608 wave_h = h - wave_y - margin;
614 void ScopeGUI::allocate_vframes()
616 if(waveform_vframe) delete waveform_vframe;
617 if(vector_vframe) delete vector_vframe;
620 //printf("ScopeGUI::allocate_vframes %d %d %d %d %d\n", __LINE__,
621 // wave_w, wave_h, vector_w, vector_h);
622 int xs16 = xS(16), ys16 = yS(16);
623 w = MAX(wave_w, xs16);
624 h = MAX(wave_h, ys16);
625 waveform_vframe = new VFrame(w, h, BC_RGB888);
626 w = MAX(vector_w, xs16);
627 h = MAX(vector_h, ys16);
628 vector_vframe = new VFrame(w, h, BC_RGB888);
632 int ScopeGUI::resize_event(int w, int h)
634 clear_box(0, 0, w, h);
637 calculate_sizes(w, h);
638 int margin = theme->widget_border;
641 waveform->reposition_window(wave_x, wave_y, wave_w, wave_h);
642 waveform->clear_box(0, 0, wave_w, wave_h);
643 int px = wave_x + wave_w - wave_slider->get_w() - margin;
644 int py = wave_y - wave_slider->get_h() - margin;
645 wave_slider->reposition_window(px, py);
649 histogram->reposition_window(hist_x, hist_y, hist_w, hist_h);
650 histogram->clear_box(0, 0, hist_w, hist_h);
654 vectorscope->reposition_window(vector_x, vector_y, vector_w, vector_h);
655 vectorscope->clear_box(0, 0, vector_w, vector_h);
656 int vx = vector_x + vector_w - vect_slider->get_w() - margin;
657 int vy = vector_y - vect_slider->get_h() - margin;
658 vect_slider->reposition_window(vx, vy);
664 draw_overlays(1, 1, 1);
668 int ScopeGUI::translation_event()
672 PluginClientWindow::translation_event();
677 void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
679 BC_Resources *resources = BC_WindowBase::get_resources();
680 int text_color = GREEN;
681 int dark_color = (text_color>>2) & 0x3f3f3f;
682 if( resources->bg_color == 0xffffff ) {
683 text_color = dark_color;
686 if( overlays && borders ) {
687 clear_box(0, 0, get_w(), get_h());
692 set_color(text_color);
695 if( histogram && (use_hist || use_hist_parade) ) {
696 histogram->draw_line(hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), 0,
697 hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), hist_h);
698 histogram->draw_line(hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), 0,
699 hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), hist_h);
701 histogram->draw_point();
707 if( waveform && (use_wave || use_wave_parade) ) {
708 for( int i=0; i<=WAVEFORM_DIVISIONS; ++i ) {
709 int y = wave_h * i / WAVEFORM_DIVISIONS;
710 int text_y = y + wave_y + get_text_ascent(SMALLFONT) / 2;
711 CLAMP(text_y, waveform->get_y() + get_text_ascent(SMALLFONT), waveform->get_y() + waveform->get_h() - 1);
712 char string[BCTEXTLEN];
713 sprintf(string, "%d", (int)lround((FLOAT_MAX -
714 i * (FLOAT_MAX - FLOAT_MIN) / WAVEFORM_DIVISIONS) * 100));
715 int text_x = wave_x - get_text_width(SMALLFONT, string) - theme->widget_border;
716 set_color(text_color);
717 draw_text(text_x, text_y, string);
718 CLAMP(y, 0, waveform->get_h() - 1);
719 set_color(dark_color);
720 waveform->draw_line(0, y, wave_w, y);
721 waveform->draw_rectangle(0, 0, wave_w, wave_h);
724 waveform->draw_point();
728 // Vectorscope overlay
729 if( vectorscope && use_vector ) {
731 int radius = MIN(vector_w / 2, vector_h / 2);
732 for( int i=1; i<=VECTORSCOPE_DIVISIONS; i+=2 ) {
733 int y = vector_h / 2 - radius * i / VECTORSCOPE_DIVISIONS;
734 int text_y = y + vector_y + get_text_ascent(SMALLFONT) / 2;
735 set_color(text_color);
736 char string[BCTEXTLEN];
737 sprintf(string, "%d",
738 (int)((FLOAT_MAX / VECTORSCOPE_DIVISIONS * i) * 100));
739 int text_x = vector_x - get_text_width(SMALLFONT, string) - theme->widget_border;
740 draw_text(text_x, text_y, string);
741 int x = vector_w / 2 - radius * i / VECTORSCOPE_DIVISIONS;
742 int w = radius * i / VECTORSCOPE_DIVISIONS * 2;
743 int h = radius * i / VECTORSCOPE_DIVISIONS * 2;
744 if( i+2 > VECTORSCOPE_DIVISIONS )
746 set_color(dark_color);
747 vectorscope->draw_circle(x, y, w, h);
749 set_color(text_color);
750 vectorscope->draw_point();
752 vectorscope->flash(0);
755 set_font(MEDIUMFONT);
760 if( use_hist || use_hist_parade ) {
761 draw_3d_border(hist_x - 2, hist_y - 2, hist_w + 4, hist_h + 4,
762 get_bg_color(), BLACK, MDGREY, get_bg_color());
764 if( use_wave || use_wave_parade ) {
765 draw_3d_border(wave_x - 2, wave_y - 2, wave_w + 4, wave_h + 4,
766 get_bg_color(), BLACK, MDGREY, get_bg_color());
769 draw_3d_border(vector_x - 2, vector_y - 2, vector_w + 4, vector_h + 4,
770 get_bg_color(), BLACK, MDGREY, get_bg_color());
775 if(flush) this->flush();
780 void ScopeGUI::process(VFrame *output_frame)
782 lock_window("ScopeGUI::process");
783 this->output_frame = output_frame;
784 int ow = output_frame->get_w(), oh = output_frame->get_h();
786 VFrame::get_temp(temp_frame, ow, oh, BC_RGB161616);
787 temp_frame->transfer_from(output_frame);
788 if( !box_blur ) box_blur = new BoxBlur(cpus);
789 box_blur->blur(temp_frame, temp_frame, 2, 2);
790 data_frame = temp_frame;
793 data_frame = output_frame;
794 frame_w = data_frame->get_w();
795 //float radius = MIN(vector_w / 2, vector_h / 2);
796 bzero(waveform_vframe->get_data(), waveform_vframe->get_data_size());
797 bzero(vector_vframe->get_data(), vector_vframe->get_data_size());
801 histogram->draw(0, 0);
803 waveform->draw_vframe(waveform_vframe);
805 vectorscope->draw_vframe(vector_vframe);
807 draw_overlays(1, 0, 1);
811 void ScopeGUI::update_toggles()
813 scope_menu->update_toggles();
816 ScopePanel::ScopePanel(ScopeGUI *gui, int x, int y, int w, int h)
817 : BC_SubWindow(x, y, w, h, BLACK)
823 void ScopePanel::create_objects()
825 set_cursor(CROSS_CURSOR, 0, 0);
826 clear_box(0, 0, get_w(), get_h());
829 void ScopePanel::update_point(int x, int y)
833 void ScopePanel::draw_point()
837 void ScopePanel::clear_point()
841 int ScopePanel::button_press_event()
843 if( is_event_win() && cursor_inside() ) {
844 gui->clear_points(1);
846 int x = get_cursor_x();
847 int y = get_cursor_y();
848 CLAMP(x, 0, get_w() - 1);
849 CLAMP(y, 0, get_h() - 1);
857 int ScopePanel::cursor_motion_event()
860 int x = get_cursor_x();
861 int y = get_cursor_y();
862 CLAMP(x, 0, get_w() - 1);
863 CLAMP(y, 0, get_h() - 1);
871 int ScopePanel::button_release_event()
881 ScopeWaveform::ScopeWaveform(ScopeGUI *gui,
882 int x, int y, int w, int h)
883 : ScopePanel(gui, x, y, w, h)
889 void ScopeWaveform::update_point(int x, int y)
894 int frame_x = x * gui->frame_w / get_w();
896 if( gui->use_wave_parade ) {
897 if( x > get_w() / 3 * 2 )
898 frame_x = (x - get_w() / 3 * 2) * gui->frame_w / (get_w() / 3);
899 else if( x > get_w() / 3 )
900 frame_x = (x - get_w() / 3) * gui->frame_w / (get_w() / 3);
902 frame_x = x * gui->frame_w / (get_w() / 3);
905 float value = ((float)get_h() - y) / get_h() * (FLOAT_MAX - FLOAT_MIN) + FLOAT_MIN;
906 char string[BCTEXTLEN];
907 sprintf(string, "X: %d Value: %.3f", frame_x, value);
908 gui->value_text->update(string, 0);
914 void ScopeWaveform::draw_point()
920 draw_line(0, drag_y, get_w(), drag_y);
921 draw_line(drag_x, 0, drag_x, get_h());
927 void ScopeWaveform::clear_point()
934 ScopeVectorscope::ScopeVectorscope(ScopeGUI *gui,
935 int x, int y, int w, int h)
936 : ScopePanel(gui, x, y, w, h)
942 void ScopeVectorscope::clear_point()
950 void ScopeVectorscope::update_point(int x, int y)
955 int radius = MIN(get_w() / 2, get_h() / 2);
956 drag_radius = sqrt(SQR(x - get_w() / 2) + SQR(y - get_h() / 2));
957 drag_angle = atan2(y - get_h() / 2, x - get_w() / 2);
959 drag_radius = MIN(drag_radius, radius);
961 float saturation = (float)drag_radius / radius * FLOAT_MAX;
962 float hue = -drag_angle * 360 / 2 / M_PI - 90;
963 if( hue < 0 ) hue += 360;
965 char string[BCTEXTLEN];
966 sprintf(string, "Hue: %.3f Sat: %.3f", hue, saturation);
967 gui->value_text->update(string, 0);
974 void ScopeVectorscope::draw_point()
976 if( drag_radius > 0 ) {
977 int radius = MIN(get_w() / 2, get_h() / 2);
981 draw_circle(get_w() / 2 - drag_radius, get_h() / 2 - drag_radius,
982 drag_radius * 2, drag_radius * 2);
983 draw_line(get_w() / 2, get_h() / 2,
984 get_w() / 2 + radius * cos(drag_angle),
985 get_h() / 2 + radius * sin(drag_angle));
993 ScopeHistogram::ScopeHistogram(ScopeGUI *gui,
994 int x, int y, int w, int h)
995 : ScopePanel(gui, x, y, w, h)
1000 void ScopeHistogram::clear_point()
1007 void ScopeHistogram::draw_point()
1011 set_color(0xffffff);
1013 draw_line(drag_x, 0, drag_x, get_h());
1019 void ScopeHistogram::update_point(int x, int y)
1023 float value = (float)x / get_w() * (FLOAT_MAX - FLOAT_MIN) + FLOAT_MIN;
1025 char string[BCTEXTLEN];
1026 sprintf(string, "Value: %.3f", value);
1027 gui->value_text->update(string, 0);
1035 void ScopeHistogram::draw_mode(int mode, int color, int y, int h)
1037 // Highest of all bins
1038 int normalize = 1, w = get_w();
1039 int *bin = gui->bins[mode], v;
1040 for( int i=0; i<TOTAL_BINS; ++i )
1041 if( (v=bin[i]) > normalize ) normalize = v;
1042 double norm = normalize>1 ? log(normalize) : 1e-4;
1043 double vnorm = h / norm;
1045 for( int x=0; x<w; ++x ) {
1046 int accum_start = (int)(x * TOTAL_BINS / w);
1047 int accum_end = (int)((x + 1) * TOTAL_BINS / w);
1048 CLAMP(accum_start, 0, TOTAL_BINS);
1049 CLAMP(accum_end, 0, TOTAL_BINS);
1051 for(int i=accum_start; i<accum_end; ++i )
1052 if( (v=bin[i]) > max ) max = v;
1053 // max = max * h / normalize;
1054 max = log(max) * vnorm;
1055 draw_line(x,y+h - max, x,y+h);
1058 void ScopeHistogram::draw(int flash, int flush)
1060 clear_box(0, 0, get_w(), get_h());
1061 if( gui->use_hist_parade ) {
1062 draw_mode(0, 0xff0000, 0, get_h() / 3);
1063 draw_mode(1, 0x00ff00, get_h() / 3, get_h() / 3);
1064 draw_mode(2, 0x0000ff, get_h() / 3 * 2, get_h() / 3);
1067 draw_mode(3, LTGREY, 0, get_h());
1070 if(flash) this->flash(0);
1071 if(flush) this->flush();
1075 ScopeScopesOn::ScopeScopesOn(ScopeMenu *scope_menu, const char *text, int id)
1078 this->scope_menu = scope_menu;
1082 int ScopeScopesOn::handle_event()
1084 int v = get_checked() ? 0 : 1;
1086 ScopeGUI *gui = scope_menu->gui;
1088 case SCOPE_HISTOGRAM:
1090 if( v ) gui->use_hist_parade = 0;
1092 case SCOPE_HISTOGRAM_RGB:
1093 gui->use_hist_parade = v;
1094 if( v ) gui->use_hist = 0;
1096 case SCOPE_WAVEFORM:
1098 if( v ) gui->use_wave_parade = 0;
1100 case SCOPE_WAVEFORM_RGB:
1101 gui->use_wave_parade = v;
1102 if( v ) gui->use_wave = 0;
1104 case SCOPE_WAVEFORM_PLY:
1105 gui->use_wave_parade = -v;
1106 if( v ) gui->use_wave = 0;
1108 case SCOPE_VECTORSCOPE:
1109 gui->use_vector = v;
1112 gui->toggle_event();
1113 gui->update_toggles();
1114 gui->create_panels();
1115 gui->update_scope();
1120 ScopeMenu::ScopeMenu(ScopeGUI *gui, int x, int y)
1121 : BC_PopupMenu(x, y, xS(100), _("Scopes"))
1126 void ScopeMenu::create_objects()
1129 new ScopeScopesOn(this, _("Histogram"), SCOPE_HISTOGRAM));
1130 add_item(hist_rgb_on =
1131 new ScopeScopesOn(this, _("Histogram RGB"), SCOPE_HISTOGRAM_RGB));
1132 add_item(new BC_MenuItem("-"));
1134 new ScopeScopesOn(this, _("Waveform"), SCOPE_WAVEFORM));
1135 add_item(wave_rgb_on =
1136 new ScopeScopesOn(this, _("Waveform RGB"), SCOPE_WAVEFORM_RGB));
1137 add_item(wave_ply_on =
1138 new ScopeScopesOn(this, _("Waveform ply"), SCOPE_WAVEFORM_PLY));
1139 add_item(new BC_MenuItem("-"));
1141 new ScopeScopesOn(this, _("Vectorscope"), SCOPE_VECTORSCOPE));
1144 void ScopeMenu::update_toggles()
1146 hist_on->set_checked(gui->use_hist);
1147 hist_rgb_on->set_checked(gui->use_hist_parade);
1148 wave_on->set_checked(gui->use_wave);
1149 wave_rgb_on->set_checked(gui->use_wave_parade>0);
1150 wave_ply_on->set_checked(gui->use_wave_parade<0);
1151 vect_on->set_checked(gui->use_vector);
1155 ScopeGainReset::ScopeGainReset(ScopeGain *gain, int x, int y)
1156 : BC_Button(x, y, gain->gui->theme->get_image_set("reset_button"))
1161 int ScopeGainReset::calculate_w(BC_Theme *theme)
1163 VFrame *vfrm = *theme->get_image_set("reset_button");
1164 return vfrm->get_w();
1167 int ScopeGainReset::handle_event()
1169 gain->slider->update(5);
1170 return gain->handle_event();
1173 ScopeGainSlider::ScopeGainSlider(ScopeGain *gain, int x, int y, int w)
1174 : BC_ISlider(x, y, 0, w, w, 1, 9, *gain->value)
1179 int ScopeGainSlider::handle_event()
1181 return gain->handle_event();
1184 ScopeGain::ScopeGain(ScopeGUI *gui, int x, int y, int w, int *value)
1190 this->value = value;
1195 ScopeGain::~ScopeGain()
1201 int ScopeGain::calculate_h()
1203 return BC_ISlider::get_span(0);
1206 void ScopeGain::create_objects()
1208 reset_w = ScopeGainReset::calculate_w(gui->theme);
1209 gui->add_subwindow(slider = new ScopeGainSlider(this, x, y, w-reset_w-xS(5)));
1210 gui->add_subwindow(reset = new ScopeGainReset(this, x+w-reset_w, y));
1213 int ScopeGain::handle_event()
1215 *value = slider->get_value();
1216 gui->update_scope();
1217 gui->toggle_event();
1221 void ScopeGain::reposition_window(int x, int y)
1223 this->x = x; this->y = y;
1224 slider->reposition_window(x, y);
1225 reset->reposition_window(x+w-reset_w, y);
1228 ScopeWaveSlider::ScopeWaveSlider(ScopeGUI *gui, int x, int y, int w)
1229 : ScopeGain(gui, x, y, w, &gui->use_wave_gain)
1233 ScopeVectSlider::ScopeVectSlider(ScopeGUI *gui, int x, int y, int w)
1234 : ScopeGain(gui, x, y, w, &gui->use_vect_gain)
1238 ScopeSmooth::ScopeSmooth(ScopeGUI *gui, int x, int y)
1239 : BC_CheckBox(x, y, gui->use_smooth, _("Smooth"))
1244 int ScopeSmooth::handle_event()
1246 gui->use_smooth = get_value();
1247 gui->update_scope();
1248 gui->toggle_event();