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"
26 #include "scopewindow.h"
31 ScopePackage::ScopePackage()
36 ScopeUnit::ScopeUnit(ScopeGUI *gui,
44 #define incr_point(rows,h, n, comp) \
45 if(iy >= 0 && iy < h) { int v; \
46 uint8_t *vp = rows[iy] + ix*BPP + (comp); \
47 v = *vp+(n); *vp = v>0xff ? 0xff : v; \
49 #define incr_points(rows,h, rv, gv, bv) \
50 if(iy >= 0 && iy < h) { int v; \
51 uint8_t *vp = rows[iy] + ix*BPP; \
52 v = *vp+(rv); *vp++ = v>0xff ? 0xff : v; \
53 v = *vp+(gv); *vp++ = v>0xff ? 0xff : v; \
54 v = *vp+(bv); *vp = v>0xff ? 0xff : v; \
56 #define clip_points(rows,h, rv, gv, bv) \
57 if(iy >= 0 && iy < h) { int v; \
58 uint8_t *vp = rows[iy] + ix*BPP; \
59 v = *vp+(rv); *vp++ = v>0xff ? 0xff : v<0 ? 0 : v; \
60 v = *vp+(gv); *vp++ = v>0xff ? 0xff : v<0 ? 0 : v; \
61 v = *vp+(bv); *vp = v>0xff ? 0xff : v<0 ? 0 : v; \
64 #define PROCESS_PIXEL(column) { \
65 /* Calculate histogram */ \
67 int v_i = (intensity - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
68 CLAMP(v_i, 0, TOTAL_BINS - 1); \
71 if(use_hist_parade) { \
72 int r_i = (r - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
73 int g_i = (g - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
74 int b_i = (b - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
75 CLAMP(r_i, 0, TOTAL_BINS - 1); \
76 CLAMP(g_i, 0, TOTAL_BINS - 1); \
77 CLAMP(b_i, 0, TOTAL_BINS - 1); \
82 /* Calculate waveform */ \
83 if(use_wave || use_wave_parade) { \
84 int ix = (column) * wave_w / out_w; \
85 if(ix >= 0 && ix < wave_w) { \
86 if(use_wave_parade > 0) { \
88 int iy = wave_h - (int)((r - FLOAT_MIN) / \
89 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
90 incr_point(waveform_rows,wave_h, winc, 0); \
92 iy = wave_h - (int)((g - FLOAT_MIN) / \
93 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
94 incr_point(waveform_rows,wave_h, winc, 1); \
96 iy = wave_h - (int)((b - FLOAT_MIN) / \
97 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
98 incr_point(waveform_rows,wave_h, winc, 2); \
100 else if(use_wave_parade < 0) { \
101 int iy = wave_h - (int)((r - FLOAT_MIN) / \
102 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
103 clip_points(waveform_rows,wave_h, winc, -winc, -winc); \
104 iy = wave_h - (int)((g - FLOAT_MIN) / \
105 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
106 clip_points(waveform_rows,wave_h, -winc, winc, -winc); \
107 iy = wave_h - (int)((b - FLOAT_MIN) / \
108 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
109 clip_points(waveform_rows,wave_h, -winc, -winc, winc); \
111 else { int yinc = 3*winc; \
112 int rinc = yinc*(r-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
113 int ginc = yinc*(g-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
114 int binc = yinc*(b-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
115 int iy = wave_h - ((intensity - FLOAT_MIN) / \
116 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
117 incr_points(waveform_rows,wave_h, rinc, ginc, binc); \
121 /* Calculate vectorscope */ \
124 if( th < 0 ) th += 360; \
125 double t = TO_RAD(th); \
126 float adjacent = -cos(t), opposite = sin(t); \
127 int ix = vector_w / 2 + adjacent * (s) / (FLOAT_MAX) * radius; \
128 int iy = vector_h / 2 - opposite * (s) / (FLOAT_MAX) * radius; \
129 CLAMP(ix, 0, vector_w - 1); \
130 /* Get color with full saturation & value */ \
131 float r_f, g_f, b_f; \
132 if( (h=h-90) < 0 ) h += 360; \
133 HSV::hsv_to_rgb(r_f, g_f, b_f, h, s, 1); \
134 int rv = CLIP(r_f, 0, 1) * vinc + 3; \
135 int gv = CLIP(g_f, 0, 1) * vinc + 3; \
136 int bv = CLIP(b_f, 0, 1) * vinc + 3; \
137 incr_points(vector_rows,vector_h, rv, gv, bv); \
141 #define PROCESS_RGB_PIXEL(column, max) { \
142 r = (float)*row++ / max; \
143 g = (float)*row++ / max; \
144 b = (float)*row++ / max; \
145 HSV::rgb_to_hsv(r, g, b, h, s, v); \
147 PROCESS_PIXEL(column) \
150 #define PROCESS_BGR_PIXEL(column, max) { \
151 b = (float)*row++ / max; \
152 g = (float)*row++ / max; \
153 r = (float)*row++ / max; \
154 HSV::rgb_to_hsv(r, g, b, h, s, v); \
156 PROCESS_PIXEL(column) \
159 #define PROCESS_YUV_PIXEL(column, y_in, u_in, v_in) { \
160 YUV::yuv.yuv_to_rgb_f(r, g, b, y_in, u_in, v_in); \
161 HSV::rgb_to_hsv(r, g, b, h, s, v); \
163 PROCESS_PIXEL(column) \
166 void ScopeUnit::process_package(LoadPackage *package)
168 ScopePackage *pkg = (ScopePackage*)package;
173 int use_hist = gui->use_hist;
174 int use_hist_parade = gui->use_hist_parade;
175 int use_vector = gui->use_vector;
176 int use_wave = gui->use_wave;
177 int use_wave_parade = gui->use_wave_parade;
178 VFrame *waveform_vframe = gui->waveform_vframe;
179 VFrame *vector_vframe = gui->vector_vframe;
180 int wave_h = waveform_vframe->get_h();
181 int wave_w = waveform_vframe->get_w();
182 int vector_h = vector_vframe->get_h();
183 int vector_w = vector_vframe->get_w();
184 int out_w = gui->output_frame->get_w();
185 int out_h = gui->output_frame->get_h();
186 int winc = (wave_w * wave_h) / (out_w * out_h);
187 if( use_wave_parade ) winc *= 3;
188 winc += 2; winc *= gui->wdial;
189 int vinc = 3*(vector_w * vector_h) / (out_w * out_h) + 2;
191 float radius = MIN(gui->vector_w / 2, gui->vector_h / 2);
192 unsigned char **waveform_rows = waveform_vframe->get_rows();
193 unsigned char **vector_rows = vector_vframe->get_rows();
194 unsigned char **rows = gui->output_frame->get_rows();
196 switch( gui->output_frame->get_color_model() ) {
198 for( int y=pkg->row1; y<pkg->row2; ++y ) {
199 unsigned char *row = rows[y];
200 for( int x=0; x<out_w; ++x ) {
201 PROCESS_RGB_PIXEL(x, 255)
206 for( int y=pkg->row1; y<pkg->row2; ++y ) {
207 unsigned char *row = rows[y];
208 for( int x=0; x<out_w; ++x ) {
209 PROCESS_RGB_PIXEL(x, 255)
215 for( int y=pkg->row1; y<pkg->row2; ++y ) {
216 unsigned char *row = rows[y];
217 for( int x=0; x<out_w; ++x ) {
218 PROCESS_BGR_PIXEL(x, 255)
223 for( int y=pkg->row1; y<pkg->row2; ++y ) {
224 unsigned char *row = rows[y];
225 for( int x=0; x<out_w; ++x ) {
226 PROCESS_BGR_PIXEL(x, 255)
232 for( int y=pkg->row1; y<pkg->row2; ++y ) {
233 float *row = (float*)rows[y];
234 for( int x=0; x<out_w; ++x ) {
235 PROCESS_RGB_PIXEL(x, 1.0)
240 for( int y=pkg->row1; y<pkg->row2; ++y ) {
241 float *row = (float*)rows[y];
242 for( int x=0; x<out_w; ++x ) {
243 PROCESS_RGB_PIXEL(x, 1.0)
249 for( int y=pkg->row1; y<pkg->row2; ++y ) {
250 unsigned char *row = rows[y];
251 for( int x=0; x<out_w; ++x ) {
252 PROCESS_YUV_PIXEL(x, row[0], row[1], row[2])
259 for( int y=pkg->row1; y<pkg->row2; ++y ) {
260 unsigned char *row = rows[y];
261 for( int x=0; x<out_w; ++x ) {
262 PROCESS_YUV_PIXEL(x, row[0], row[1], row[2])
268 unsigned char *yp = gui->output_frame->get_y();
269 unsigned char *up = gui->output_frame->get_u();
270 unsigned char *vp = gui->output_frame->get_v();
271 for( int y=pkg->row1; y<pkg->row2; ++y ) {
272 unsigned char *y_row = yp + y * out_w;
273 unsigned char *u_row = up + (y / 2) * (out_w / 2);
274 unsigned char *v_row = vp + (y / 2) * (out_w / 2);
275 for( int x=0; x<out_w; x+=2 ) {
276 PROCESS_YUV_PIXEL(x, *y_row, *u_row, *v_row);
278 PROCESS_YUV_PIXEL(x + 1, *y_row, *u_row, *v_row);
285 for( int y=pkg->row1; y<pkg->row2; ++y ) {
286 unsigned char *row = rows[y];
287 for( int x=0; x<out_w; x+=2 ) {
288 PROCESS_YUV_PIXEL(x, row[0], row[1], row[3]);
289 PROCESS_YUV_PIXEL(x + 1, row[2], row[1], row[3]);
296 printf("ScopeUnit::process_package %d: color_model=%d unrecognized\n",
297 __LINE__, gui->output_frame->get_color_model());
303 ScopeEngine::ScopeEngine(ScopeGUI *gui, int cpus)
304 : LoadServer(cpus, cpus)
306 //printf("ScopeEngine::ScopeEngine %d cpus=%d\n", __LINE__, cpus);
310 ScopeEngine::~ScopeEngine()
314 void ScopeEngine::init_packages()
316 int y = 0, h = gui->output_frame->get_h();
317 for( int i=0,n=LoadServer::get_total_packages(); i<n; ) {
318 ScopePackage *pkg = (ScopePackage*)get_package(i);
320 pkg->row2 = y = (++i * h) / n;
323 for( int i=0,n=LoadServer::get_total_packages(); i<n; ++i ) {
324 ScopeUnit *unit = (ScopeUnit*)get_client(i);
325 for( int j=0; j<HIST_SECTIONS; ++j )
326 bzero(unit->bins[j], sizeof(int) * TOTAL_BINS);
331 LoadClient* ScopeEngine::new_client()
333 return new ScopeUnit(gui, this);
336 LoadPackage* ScopeEngine::new_package()
338 return new ScopePackage;
341 void ScopeEngine::process()
345 for(int i = 0; i < HIST_SECTIONS; i++)
346 bzero(gui->bins[i], sizeof(int) * TOTAL_BINS);
348 for(int i=0,n=get_total_clients(); i<n; ++i ) {
349 ScopeUnit *unit = (ScopeUnit*)get_client(i);
350 for( int j=0; j<HIST_SECTIONS; ++j ) {
351 int *bp = gui->bins[j], *up = unit->bins[j];
352 for( int k=TOTAL_BINS; --k>=0; ++bp,++up ) *bp += *up;
358 ScopeGUI::ScopeGUI(Theme *theme,
359 int x, int y, int w, int h, int cpus)
360 : PluginClientWindow(_(PROGRAM_NAME ": Scopes"),
361 x, y, w, h, MIN_SCOPE_W, MIN_SCOPE_H, 1)
372 ScopeGUI::ScopeGUI(PluginClient *plugin, int w, int h)
373 : PluginClientWindow(plugin, w, h, MIN_SCOPE_W, MIN_SCOPE_H, 1)
379 this->theme = plugin->get_theme();
380 this->cpus = plugin->PluginClient::smp + 1;
384 ScopeGUI::~ScopeGUI()
386 delete waveform_vframe;
387 delete vector_vframe;
391 void ScopeGUI::reset()
405 wave_w = wave_h = vector_w = vector_h = 0;
410 void ScopeGUI::create_objects()
412 if( use_hist && use_hist_parade )
414 if( use_wave && use_wave_parade )
416 if( !engine ) engine = new ScopeEngine(this, cpus);
418 lock_window("ScopeGUI::create_objects");
419 int x = theme->widget_border;
420 int y = theme->widget_border +
421 ScopeWaveDial::calculate_h() - ScopeMenu::calculate_h();
422 add_subwindow(scope_menu = new ScopeMenu(this, x, y));
423 scope_menu->create_objects();
424 x += scope_menu->get_w() + theme->widget_border;
425 add_subwindow(value_text = new BC_Title(x, y, ""));
434 void ScopeGUI::create_panels()
436 calculate_sizes(get_w(), get_h());
437 if( (use_wave || use_wave_parade) ) {
438 int px = wave_x + wave_w - ScopeWaveDial::calculate_w() - xS(5);
439 int py = wave_y - ScopeWaveDial::calculate_h() - yS(5);
441 add_subwindow(waveform = new ScopeWaveform(this,
442 wave_x, wave_y, wave_w, wave_h));
443 waveform->create_objects();
444 add_subwindow(wave_dial = new ScopeWaveDial(this, px, py));
447 waveform->reposition_window(
448 wave_x, wave_y, wave_w, wave_h);
449 waveform->clear_box(0, 0, wave_w, wave_h);
450 wave_dial->reposition_window(px, py);
453 else if( !(use_wave || use_wave_parade) && waveform ) {
454 delete waveform; waveform = 0;
455 delete wave_dial; wave_dial = 0;
459 int vx = vector_x + vector_w - ScopeVectDial::calculate_w() - xS(5);
460 int vy = vector_y - ScopeVectDial::calculate_h() - yS(5);
462 add_subwindow(vectorscope = new ScopeVectorscope(this,
463 vector_x, vector_y, vector_w, vector_h));
464 vectorscope->create_objects();
465 add_subwindow(vect_dial = new ScopeVectDial(this, vx, vy));
468 vectorscope->reposition_window(
469 vector_x, vector_y, vector_w, vector_h);
470 vectorscope->clear_box(0, 0, vector_w, vector_h);
471 vect_dial->reposition_window(vx, vy);
474 else if( !use_vector && vectorscope ) {
475 delete vectorscope; vectorscope = 0;
476 delete vect_dial; vect_dial = 0;
479 if( (use_hist || use_hist_parade) ) {
481 // printf("ScopeGUI::create_panels %d %d %d %d %d\n", __LINE__,
482 // hist_x, hist_y, hist_w, hist_h);
483 add_subwindow(histogram = new ScopeHistogram(this,
484 hist_x, hist_y, hist_w, hist_h));
485 histogram->create_objects();
488 histogram->reposition_window(
489 hist_x, hist_y, hist_w, hist_h);
490 histogram->clear_box(0, 0, hist_w, hist_h);
493 else if( !(use_hist || use_hist_parade) ) {
494 delete histogram; histogram = 0;
499 draw_overlays(1, 1, 0);
502 void ScopeGUI::clear_points(int flash)
505 histogram->clear_point();
507 waveform->clear_point();
509 vectorscope->clear_point();
510 if( histogram && flash )
512 if( waveform && flash )
514 if( vectorscope && flash )
515 vectorscope->flash(0);
518 void ScopeGUI::toggle_event()
522 void ScopeGUI::calculate_sizes(int w, int h)
524 int margin = theme->widget_border;
525 int menu_h = ScopeWaveDial::calculate_h() + margin * 2;
526 int text_w = get_text_width(SMALLFONT, "000") + margin * 2;
527 int total_panels = ((use_hist || use_hist_parade) ? 1 : 0) +
528 ((use_wave || use_wave_parade) ? 1 : 0) +
529 (use_vector ? 1 : 0);
532 int panel_w = (w - margin) / (total_panels > 0 ? total_panels : 1);
533 // Vectorscope determines the size of everything else
537 vector_x = w - panel_w + text_w;
538 vector_w = w - margin - vector_x;
540 vector_h = h - vector_y - margin;
542 if( vector_w > vector_h ) {
544 vector_x = w - theme->widget_border - vector_w;
548 panel_w = (vector_x - text_w - margin) / total_panels;
551 // Histogram is always 1st panel
552 if( use_hist || use_hist_parade ) {
555 hist_w = panel_w - margin;
556 hist_h = h - hist_y - margin;
562 if( use_wave || use_wave_parade ) {
565 wave_w = panel_w - margin - text_w;
566 wave_h = h - wave_y - margin;
572 void ScopeGUI::allocate_vframes()
574 if(waveform_vframe) delete waveform_vframe;
575 if(vector_vframe) delete vector_vframe;
578 //printf("ScopeGUI::allocate_vframes %d %d %d %d %d\n", __LINE__,
579 // wave_w, wave_h, vector_w, vector_h);
580 int xs16 = xS(16), ys16 = yS(16);
581 w = MAX(wave_w, xs16);
582 h = MAX(wave_h, ys16);
583 waveform_vframe = new VFrame(w, h, BC_RGB888);
584 w = MAX(vector_w, xs16);
585 h = MAX(vector_h, ys16);
586 vector_vframe = new VFrame(w, h, BC_RGB888);
590 int ScopeGUI::resize_event(int w, int h)
592 clear_box(0, 0, w, h);
595 calculate_sizes(w, h);
598 waveform->reposition_window(wave_x, wave_y, wave_w, wave_h);
599 waveform->clear_box(0, 0, wave_w, wave_h);
600 int px = wave_x + wave_w - ScopeWaveDial::calculate_w() - xS(5);
601 int py = wave_y - ScopeWaveDial::calculate_h() - yS(5);
602 wave_dial->reposition_window(px, py);
606 histogram->reposition_window(hist_x, hist_y, hist_w, hist_h);
607 histogram->clear_box(0, 0, hist_w, hist_h);
611 vectorscope->reposition_window(vector_x, vector_y, vector_w, vector_h);
612 vectorscope->clear_box(0, 0, vector_w, vector_h);
613 int vx = vector_x + vector_w - ScopeVectDial::calculate_w() - xS(5);
614 int vy = vector_y - ScopeVectDial::calculate_h() - yS(5);
615 vect_dial->reposition_window(vx, vy);
621 draw_overlays(1, 1, 1);
625 int ScopeGUI::translation_event()
629 PluginClientWindow::translation_event();
634 void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
636 BC_Resources *resources = BC_WindowBase::get_resources();
637 int text_color = GREEN;
638 int dark_color = (text_color>>2) & 0x3f3f3f;
639 if( resources->bg_color == 0xffffff ) {
640 text_color = dark_color;
643 if( overlays && borders ) {
644 clear_box(0, 0, get_w(), get_h());
649 set_color(text_color);
652 if( histogram && (use_hist || use_hist_parade) ) {
653 histogram->draw_line(hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), 0,
654 hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), hist_h);
655 histogram->draw_line(hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), 0,
656 hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), hist_h);
658 histogram->draw_point();
664 if( waveform && (use_wave || use_wave_parade) ) {
665 for( int i=0; i<=WAVEFORM_DIVISIONS; ++i ) {
666 int y = wave_h * i / WAVEFORM_DIVISIONS;
667 int text_y = y + wave_y + get_text_ascent(SMALLFONT) / 2;
668 CLAMP(text_y, waveform->get_y() + get_text_ascent(SMALLFONT), waveform->get_y() + waveform->get_h() - 1);
669 char string[BCTEXTLEN];
670 sprintf(string, "%d", (int)lround((FLOAT_MAX -
671 i * (FLOAT_MAX - FLOAT_MIN) / WAVEFORM_DIVISIONS) * 100));
672 int text_x = wave_x - get_text_width(SMALLFONT, string) - theme->widget_border;
673 set_color(text_color);
674 draw_text(text_x, text_y, string);
675 CLAMP(y, 0, waveform->get_h() - 1);
676 set_color(dark_color);
677 waveform->draw_line(0, y, wave_w, y);
678 waveform->draw_rectangle(0, 0, wave_w, wave_h);
681 waveform->draw_point();
685 // Vectorscope overlay
686 if( vectorscope && use_vector ) {
688 int radius = MIN(vector_w / 2, vector_h / 2);
689 for( int i=1; i<=VECTORSCOPE_DIVISIONS; i+=2 ) {
690 int y = vector_h / 2 - radius * i / VECTORSCOPE_DIVISIONS;
691 int text_y = y + vector_y + get_text_ascent(SMALLFONT) / 2;
692 set_color(text_color);
693 char string[BCTEXTLEN];
694 sprintf(string, "%d",
695 (int)((FLOAT_MAX / VECTORSCOPE_DIVISIONS * i) * 100));
696 int text_x = vector_x - get_text_width(SMALLFONT, string) - theme->widget_border;
697 draw_text(text_x, text_y, string);
698 int x = vector_w / 2 - radius * i / VECTORSCOPE_DIVISIONS;
699 int w = radius * i / VECTORSCOPE_DIVISIONS * 2;
700 int h = radius * i / VECTORSCOPE_DIVISIONS * 2;
701 if( i+2 > VECTORSCOPE_DIVISIONS )
703 set_color(dark_color);
704 vectorscope->draw_circle(x, y, w, h);
706 set_color(text_color);
707 vectorscope->draw_point();
709 vectorscope->flash(0);
712 set_font(MEDIUMFONT);
717 if( use_hist || use_hist_parade ) {
718 draw_3d_border(hist_x - 2, hist_y - 2, hist_w + 4, hist_h + 4,
719 get_bg_color(), BLACK, MDGREY, get_bg_color());
721 if( use_wave || use_wave_parade ) {
722 draw_3d_border(wave_x - 2, wave_y - 2, wave_w + 4, wave_h + 4,
723 get_bg_color(), BLACK, MDGREY, get_bg_color());
726 draw_3d_border(vector_x - 2, vector_y - 2, vector_w + 4, vector_h + 4,
727 get_bg_color(), BLACK, MDGREY, get_bg_color());
732 if(flush) this->flush();
737 void ScopeGUI::process(VFrame *output_frame)
739 lock_window("ScopeGUI::process");
740 this->output_frame = output_frame;
741 frame_w = output_frame->get_w();
742 //float radius = MIN(vector_w / 2, vector_h / 2);
743 bzero(waveform_vframe->get_data(), waveform_vframe->get_data_size());
744 bzero(vector_vframe->get_data(), vector_vframe->get_data_size());
748 histogram->draw(0, 0);
750 waveform->draw_vframe(waveform_vframe, 1, 0, 0);
752 vectorscope->draw_vframe(vector_vframe, 1, 0, 0);
754 draw_overlays(1, 0, 1);
758 void ScopeGUI::update_toggles()
760 scope_menu->update_toggles();
763 ScopePanel::ScopePanel(ScopeGUI *gui, int x, int y, int w, int h)
764 : BC_SubWindow(x, y, w, h, BLACK)
770 void ScopePanel::create_objects()
772 set_cursor(CROSS_CURSOR, 0, 0);
773 clear_box(0, 0, get_w(), get_h());
776 void ScopePanel::update_point(int x, int y)
780 void ScopePanel::draw_point()
784 void ScopePanel::clear_point()
788 int ScopePanel::button_press_event()
790 if( is_event_win() && cursor_inside() ) {
791 gui->clear_points(1);
793 int x = get_cursor_x();
794 int y = get_cursor_y();
795 CLAMP(x, 0, get_w() - 1);
796 CLAMP(y, 0, get_h() - 1);
804 int ScopePanel::cursor_motion_event()
807 int x = get_cursor_x();
808 int y = get_cursor_y();
809 CLAMP(x, 0, get_w() - 1);
810 CLAMP(y, 0, get_h() - 1);
818 int ScopePanel::button_release_event()
828 ScopeWaveform::ScopeWaveform(ScopeGUI *gui,
829 int x, int y, int w, int h)
830 : ScopePanel(gui, x, y, w, h)
836 void ScopeWaveform::update_point(int x, int y)
841 int frame_x = x * gui->frame_w / get_w();
843 if( gui->use_wave_parade ) {
844 if( x > get_w() / 3 * 2 )
845 frame_x = (x - get_w() / 3 * 2) * gui->frame_w / (get_w() / 3);
846 else if( x > get_w() / 3 )
847 frame_x = (x - get_w() / 3) * gui->frame_w / (get_w() / 3);
849 frame_x = x * gui->frame_w / (get_w() / 3);
852 float value = ((float)get_h() - y) / get_h() * (FLOAT_MAX - FLOAT_MIN) + FLOAT_MIN;
853 char string[BCTEXTLEN];
854 sprintf(string, "X: %d Value: %.3f", frame_x, value);
855 gui->value_text->update(string, 0);
861 void ScopeWaveform::draw_point()
867 draw_line(0, drag_y, get_w(), drag_y);
868 draw_line(drag_x, 0, drag_x, get_h());
874 void ScopeWaveform::clear_point()
881 ScopeVectorscope::ScopeVectorscope(ScopeGUI *gui,
882 int x, int y, int w, int h)
883 : ScopePanel(gui, x, y, w, h)
889 void ScopeVectorscope::clear_point()
897 void ScopeVectorscope::update_point(int x, int y)
902 int radius = MIN(get_w() / 2, get_h() / 2);
903 drag_radius = sqrt(SQR(x - get_w() / 2) + SQR(y - get_h() / 2));
904 drag_angle = atan2(y - get_h() / 2, x - get_w() / 2);
906 drag_radius = MIN(drag_radius, radius);
908 float saturation = (float)drag_radius / radius * FLOAT_MAX;
909 float hue = -drag_angle * 360 / 2 / M_PI - 90;
910 if( hue < 0 ) hue += 360;
912 char string[BCTEXTLEN];
913 sprintf(string, "Hue: %.3f Sat: %.3f", hue, saturation);
914 gui->value_text->update(string, 0);
921 void ScopeVectorscope::draw_point()
923 if( drag_radius > 0 ) {
924 int radius = MIN(get_w() / 2, get_h() / 2);
928 draw_circle(get_w() / 2 - drag_radius, get_h() / 2 - drag_radius,
929 drag_radius * 2, drag_radius * 2);
930 draw_line(get_w() / 2, get_h() / 2,
931 get_w() / 2 + radius * cos(drag_angle),
932 get_h() / 2 + radius * sin(drag_angle));
940 ScopeHistogram::ScopeHistogram(ScopeGUI *gui,
941 int x, int y, int w, int h)
942 : ScopePanel(gui, x, y, w, h)
947 void ScopeHistogram::clear_point()
954 void ScopeHistogram::draw_point()
960 draw_line(drag_x, 0, drag_x, get_h());
966 void ScopeHistogram::update_point(int x, int y)
970 float value = (float)x / get_w() * (FLOAT_MAX - FLOAT_MIN) + FLOAT_MIN;
972 char string[BCTEXTLEN];
973 sprintf(string, "Value: %.3f", value);
974 gui->value_text->update(string, 0);
982 void ScopeHistogram::draw_mode(int mode, int color, int y, int h)
984 // Highest of all bins
985 int normalize = 1, w = get_w();
986 int *bin = gui->bins[mode], v;
987 for( int i=0; i<TOTAL_BINS; ++i )
988 if( (v=bin[i]) > normalize ) normalize = v;
989 double norm = normalize>1 ? log(normalize) : 1e-4;
990 double vnorm = h / norm;
992 for( int x=0; x<w; ++x ) {
993 int accum_start = (int)(x * TOTAL_BINS / w);
994 int accum_end = (int)((x + 1) * TOTAL_BINS / w);
995 CLAMP(accum_start, 0, TOTAL_BINS);
996 CLAMP(accum_end, 0, TOTAL_BINS);
998 for(int i=accum_start; i<accum_end; ++i )
999 if( (v=bin[i]) > max ) max = v;
1000 // max = max * h / normalize;
1001 max = log(max) * vnorm;
1002 draw_line(x,y+h - max, x,y+h);
1005 void ScopeHistogram::draw(int flash, int flush)
1007 clear_box(0, 0, get_w(), get_h());
1008 if( gui->use_hist_parade ) {
1009 draw_mode(0, 0xff0000, 0, get_h() / 3);
1010 draw_mode(1, 0x00ff00, get_h() / 3, get_h() / 3);
1011 draw_mode(2, 0x0000ff, get_h() / 3 * 2, get_h() / 3);
1014 draw_mode(3, LTGREY, 0, get_h());
1017 if(flash) this->flash(0);
1018 if(flush) this->flush();
1022 ScopeScopesOn::ScopeScopesOn(ScopeMenu *scope_menu, const char *text, int id)
1025 this->scope_menu = scope_menu;
1029 int ScopeScopesOn::handle_event()
1031 int v = get_checked() ? 0 : 1;
1033 ScopeGUI *gui = scope_menu->gui;
1035 case SCOPE_HISTOGRAM:
1037 if( v ) gui->use_hist_parade = 0;
1039 case SCOPE_HISTOGRAM_RGB:
1040 gui->use_hist_parade = v;
1041 if( v ) gui->use_hist = 0;
1043 case SCOPE_WAVEFORM:
1045 if( v ) gui->use_wave_parade = 0;
1047 case SCOPE_WAVEFORM_RGB:
1048 gui->use_wave_parade = v;
1049 if( v ) gui->use_wave = 0;
1051 case SCOPE_WAVEFORM_PLY:
1052 gui->use_wave_parade = -v;
1053 if( v ) gui->use_wave = 0;
1055 case SCOPE_VECTORSCOPE:
1056 gui->use_vector = v;
1059 gui->toggle_event();
1060 gui->update_toggles();
1061 gui->create_panels();
1062 gui->update_scope();
1067 ScopeMenu::ScopeMenu(ScopeGUI *gui, int x, int y)
1068 : BC_PopupMenu(x, y, xS(100), _("Scopes"))
1073 void ScopeMenu::create_objects()
1076 new ScopeScopesOn(this, _("Histogram"), SCOPE_HISTOGRAM));
1077 add_item(hist_rgb_on =
1078 new ScopeScopesOn(this, _("Histogram RGB"), SCOPE_HISTOGRAM_RGB));
1080 new ScopeScopesOn(this, _("Waveform"), SCOPE_WAVEFORM));
1081 add_item(wave_rgb_on =
1082 new ScopeScopesOn(this, _("Waveform RGB"), SCOPE_WAVEFORM_RGB));
1083 add_item(wave_ply_on =
1084 new ScopeScopesOn(this, _("Waveform ply"), SCOPE_WAVEFORM_PLY));
1086 new ScopeScopesOn(this, _("Vectorscope"), SCOPE_VECTORSCOPE));
1089 void ScopeMenu::update_toggles()
1091 hist_on->set_checked(gui->use_hist);
1092 hist_rgb_on->set_checked(gui->use_hist_parade);
1093 wave_on->set_checked(gui->use_wave);
1094 wave_rgb_on->set_checked(gui->use_wave_parade>0);
1095 wave_ply_on->set_checked(gui->use_wave_parade<0);
1096 vect_on->set_checked(gui->use_vector);
1099 ScopeWaveDial::ScopeWaveDial(ScopeGUI *gui, int x, int y)
1100 : BC_FPot(x, y, gui->wdial, 1.f, 9.f)
1104 int ScopeWaveDial::handle_event()
1106 gui->wdial = get_value();
1107 gui->update_scope();
1111 ScopeVectDial::ScopeVectDial(ScopeGUI *gui, int x, int y)
1112 : BC_FPot(x, y, gui->vdial, 1.f, 9.f)
1116 int ScopeVectDial::handle_event()
1118 gui->vdial = get_value();
1119 gui->update_scope();