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 "filesystem.h"
29 #include "scopewindow.h"
34 ScopePackage::ScopePackage()
39 ScopeUnit::ScopeUnit(ScopeGUI *gui,
47 #define incr_point(rows,h, iv,comp) { \
48 if(iy >= 0 && iy < h) { \
49 uint8_t *vp = rows[iy] + ix*3 + (comp); \
50 int v = *vp+(iv); *vp = v>0xff ? 0xff : v; } \
52 #define incr_points(rows,h, rv,gv,bv) { \
53 if(iy >= 0 && iy < h) { \
54 uint8_t *vp = rows[iy] + ix*3; \
55 int v = *vp+(rv); *vp++ = v>0xff ? 0xff : v; \
56 v = *vp+(gv); *vp++ = v>0xff ? 0xff : v; \
57 v = *vp+(bv); *vp = v>0xff ? 0xff : v; } \
59 #define decr_points(rows,h, rv,gv,bv) { \
60 if(iy >= 0 && iy < h) { \
61 uint8_t *vp = rows[iy] + ix*3; \
62 int v = *vp-(rv); *vp++ = v<0 ? 0 : v; \
63 v = *vp-(gv); *vp++ = v<0 ? 0 : v; \
64 v = *vp-(bv); *vp = v<0 ? 0 : v; } \
66 #define clip_points(rows,h, rv,gv,bv) { \
67 if(iy >= 0 && iy < h) { \
68 uint8_t *vp = rows[iy] + ix*3; \
69 int v = *vp+(rv); *vp++ = v>0xff ? 0xff : v<0 ? 0 : v; \
70 v = *vp+(gv); *vp++ = v>0xff ? 0xff : v<0 ? 0 : v; \
71 v = *vp+(bv); *vp = v>0xff ? 0xff : v<0 ? 0 : v; } \
74 #define PROCESS_PIXEL(column) { \
75 /* Calculate histogram */ \
77 int v_i = (intensity - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
78 CLAMP(v_i, 0, TOTAL_BINS - 1); \
81 if(use_hist_parade) { \
82 int r_i = (r - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
83 int g_i = (g - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
84 int b_i = (b - FLOAT_MIN) * (TOTAL_BINS / (FLOAT_MAX - FLOAT_MIN)); \
85 CLAMP(r_i, 0, TOTAL_BINS - 1); \
86 CLAMP(g_i, 0, TOTAL_BINS - 1); \
87 CLAMP(b_i, 0, TOTAL_BINS - 1); \
92 /* Calculate waveform */ \
93 if(use_wave || use_wave_parade) { \
94 int ix = column * wave_w / dat_w; \
95 if(ix >= 0 && ix < wave_w-1) { \
96 if(use_wave_parade > 0) { \
98 int iy = wave_h - ((r - FLOAT_MIN) / \
99 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
100 incr_point(waveform_rows,wave_h, winc,0); \
102 iy = wave_h - ((g - FLOAT_MIN) / \
103 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
104 incr_point(waveform_rows,wave_h, winc,1); \
106 iy = wave_h - ((b - FLOAT_MIN) / \
107 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
108 incr_point(waveform_rows,wave_h, winc,2); \
110 else if(use_wave_parade < 0) { \
111 int iy = wave_h - ((r - FLOAT_MIN) / \
112 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
113 clip_points(waveform_rows,wave_h, winc,-winc,-winc); \
114 iy = wave_h - ((g - FLOAT_MIN) / \
115 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
116 clip_points(waveform_rows,wave_h, -winc,winc,-winc); \
117 iy = wave_h - ((b - FLOAT_MIN) / \
118 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
119 clip_points(waveform_rows,wave_h, -winc,-winc,winc); \
121 else { float yinc = 3*winc; \
122 float rinc = yinc*(r-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
123 float ginc = yinc*(g-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
124 float binc = yinc*(b-FLOAT_MIN) / (FLOAT_MAX-FLOAT_MIN) + 3; \
125 int iy = wave_h - ((intensity - FLOAT_MIN) / \
126 (FLOAT_MAX - FLOAT_MIN) * wave_h); \
127 incr_points(waveform_rows,wave_h, rinc, ginc, binc); \
131 /* Calculate vectorscope */ \
132 if(use_vector > 0) { \
133 double t = TO_RAD(-h); \
134 float adjacent = sin(t), opposite = cos(t); \
135 int ix = vector_cx + adjacent * (s) / (FLOAT_MAX) * radius; \
136 int iy = vector_cy - opposite * (s) / (FLOAT_MAX) * radius; \
137 CLAMP(ix, 0, vector_w - 1); \
138 HSV::hsv_to_rgb(r, g, b, h, s, vincf); \
142 incr_points(vector_rows,vector_h, rv,gv,bv); \
144 else if(use_vector < 0) { \
145 double t = TO_RAD(-h); \
146 float adjacent = sin(t), opposite = cos(t); \
147 int ix = vector_cx + adjacent * (s) / (FLOAT_MAX) * radius; \
148 int iy = vector_cy - opposite * (s) / (FLOAT_MAX) * radius; \
149 CLAMP(ix, 0, vector_w - 1); \
150 decr_points(vector_rows,vector_h, vinc,vinc,vinc); \
154 #define PROCESS_RGB_PIXEL(type,max, column) { \
155 type *rp = (type *)row; \
156 r = (float)rp[0] / max; \
157 g = (float)rp[1] / max; \
158 b = (float)rp[2] / max; \
159 HSV::rgb_to_hsv(r, g, b, h, s, v); \
161 PROCESS_PIXEL(column) \
164 #define PROCESS_BGR_PIXEL(type,max, column) { \
165 type *rp = (type *)row; \
166 b = (float)rp[0] / max; \
167 g = (float)rp[1] / max; \
168 r = (float)rp[2] / max; \
169 HSV::rgb_to_hsv(r, g, b, h, s, v); \
171 PROCESS_PIXEL(column) \
174 #define PROCESS_YUV_PIXEL(column, y_in, u_in, v_in) { \
175 YUV::yuv.yuv_to_rgb_f(r, g, b, y_in, u_in, v_in); \
176 HSV::rgb_to_hsv(r, g, b, h, s, v); \
178 PROCESS_PIXEL(column) \
181 void ScopeUnit::process_package(LoadPackage *package)
183 ScopePackage *pkg = (ScopePackage*)package;
188 int use_hist = gui->use_hist;
189 int use_hist_parade = gui->use_hist_parade;
190 int use_vector = gui->use_vector;
191 int use_wave = gui->use_wave;
192 int use_wave_parade = gui->use_wave_parade;
193 int vector_cx = gui->vector_cx;
194 int vector_cy = gui->vector_cy;
195 int radius = gui->radius;
196 VFrame *waveform_vframe = gui->waveform_vframe;
197 VFrame *vector_vframe = gui->vector_vframe;
198 int wave_h = waveform_vframe->get_h();
199 int wave_w = waveform_vframe->get_w();
200 int vector_h = vector_vframe->get_h();
201 int vector_w = vector_vframe->get_w();
202 int dat_w = gui->data_frame->get_w();
203 int dat_h = gui->data_frame->get_h();
204 int winc = (wave_w * wave_h) / (dat_w * dat_h);
205 if( use_wave_parade ) winc *= 3;
206 winc += 2; winc = (winc << gui->use_wave_gain) / 4;
207 int vinc = 3*(vector_w * vector_h) / (dat_w * dat_h);
208 vinc += 2; vinc = (vinc << gui->use_vect_gain) / 4;
210 uint8_t **waveform_rows = waveform_vframe->get_rows();
211 uint8_t **vector_rows = vector_vframe->get_rows();
212 uint8_t **rows = gui->data_frame->get_rows();
214 switch( gui->data_frame->get_color_model() ) {
216 for( int y=pkg->row1; y<pkg->row2; ++y ) {
217 uint8_t *row = rows[y];
218 for( int x=0; x<dat_w; ++x ) {
219 PROCESS_RGB_PIXEL(uint8_t,0xff, x)
220 row += 3*sizeof(uint8_t);
225 for( int y=pkg->row1; y<pkg->row2; ++y ) {
226 uint8_t *row = rows[y];
227 for( int x=0; x<dat_w; ++x ) {
228 PROCESS_RGB_PIXEL(uint8_t,0xff, x)
229 row += 4*sizeof(uint8_t);
234 for( int y=pkg->row1; y<pkg->row2; ++y ) {
235 uint8_t *row = rows[y];
236 for( int x=0; x<dat_w; ++x ) {
237 PROCESS_RGB_PIXEL(uint16_t,0xffff, x)
238 row += 3*sizeof(uint16_t);
242 case BC_RGBA16161616:
243 for( int y=pkg->row1; y<pkg->row2; ++y ) {
244 uint8_t *row = rows[y];
245 for( int x=0; x<dat_w; ++x ) {
246 PROCESS_RGB_PIXEL(uint16_t,0xffff, x)
247 row += 4*sizeof(uint16_t);
252 for( int y=pkg->row1; y<pkg->row2; ++y ) {
253 uint8_t *row = rows[y];
254 for( int x=0; x<dat_w; ++x ) {
255 PROCESS_BGR_PIXEL(uint8_t,0xff, x)
256 row += 3*sizeof(uint8_t);
261 for( int y=pkg->row1; y<pkg->row2; ++y ) {
262 uint8_t *row = rows[y];
263 for( int x=0; x<dat_w; ++x ) {
264 PROCESS_BGR_PIXEL(uint8_t,0xff, x)
265 row += 4*sizeof(uint8_t);
270 for( int y=pkg->row1; y<pkg->row2; ++y ) {
271 uint8_t *row = rows[y];
272 for( int x=0; x<dat_w; ++x ) {
273 PROCESS_RGB_PIXEL(float,1.f, x)
274 row += 3*sizeof(float);
279 for( int y=pkg->row1; y<pkg->row2; ++y ) {
280 uint8_t *row = rows[y];
281 for( int x=0; x<dat_w; ++x ) {
282 PROCESS_RGB_PIXEL(float,1.f, x)
283 row += 4*sizeof(float);
288 for( int y=pkg->row1; y<pkg->row2; ++y ) {
289 uint8_t *row = rows[y];
290 for( int x=0; x<dat_w; ++x ) {
291 PROCESS_YUV_PIXEL(x, row[0], row[1], row[2])
292 row += 3*sizeof(uint8_t);
298 for( int y=pkg->row1; y<pkg->row2; ++y ) {
299 uint8_t *row = rows[y];
300 for( int x=0; x<dat_w; ++x ) {
301 PROCESS_YUV_PIXEL(x, row[0], row[1], row[2])
302 row += 4*sizeof(uint8_t);
307 uint8_t *yp = gui->data_frame->get_y();
308 uint8_t *up = gui->data_frame->get_u();
309 uint8_t *vp = gui->data_frame->get_v();
310 for( int y=pkg->row1; y<pkg->row2; ++y ) {
311 uint8_t *y_row = yp + y * dat_w;
312 uint8_t *u_row = up + (y / 2) * (dat_w / 2);
313 uint8_t *v_row = vp + (y / 2) * (dat_w / 2);
314 for( int x=0; x<dat_w; x+=2 ) {
315 PROCESS_YUV_PIXEL(x, *y_row, *u_row, *v_row);
317 PROCESS_YUV_PIXEL(x + 1, *y_row, *u_row, *v_row);
318 ++y_row; ++u_row; ++v_row;
323 for( int y=pkg->row1; y<pkg->row2; ++y ) {
324 uint8_t *row = rows[y];
325 for( int x=0; x<dat_w; x+=2 ) {
326 PROCESS_YUV_PIXEL(x, row[0], row[1], row[3]);
327 PROCESS_YUV_PIXEL(x + 1, row[2], row[1], row[3]);
328 row += 4*sizeof(uint8_t);
334 printf("ScopeUnit::process_package %d: color_model=%d unrecognized\n",
335 __LINE__, gui->data_frame->get_color_model());
341 ScopeEngine::ScopeEngine(ScopeGUI *gui, int cpus)
342 : LoadServer(cpus, cpus)
344 //printf("ScopeEngine::ScopeEngine %d cpus=%d\n", __LINE__, cpus);
348 ScopeEngine::~ScopeEngine()
352 void ScopeEngine::init_packages()
354 int y = 0, h = gui->data_frame->get_h();
355 for( int i=0,n=LoadServer::get_total_packages(); i<n; ) {
356 ScopePackage *pkg = (ScopePackage*)get_package(i);
358 pkg->row2 = y = (++i * h) / n;
361 for( int i=0,n=LoadServer::get_total_packages(); i<n; ++i ) {
362 ScopeUnit *unit = (ScopeUnit*)get_client(i);
363 for( int j=0; j<HIST_SECTIONS; ++j )
364 bzero(unit->bins[j], sizeof(int) * TOTAL_BINS);
369 LoadClient* ScopeEngine::new_client()
371 return new ScopeUnit(gui, this);
374 LoadPackage* ScopeEngine::new_package()
376 return new ScopePackage;
379 void ScopeEngine::process()
383 for(int i = 0; i < HIST_SECTIONS; i++)
384 bzero(gui->bins[i], sizeof(int) * TOTAL_BINS);
386 for(int i=0,n=get_total_clients(); i<n; ++i ) {
387 ScopeUnit *unit = (ScopeUnit*)get_client(i);
388 for( int j=0; j<HIST_SECTIONS; ++j ) {
389 int *bp = gui->bins[j], *up = unit->bins[j];
390 for( int k=TOTAL_BINS; --k>=0; ++bp,++up ) *bp += *up;
396 ScopeGUI::ScopeGUI(Theme *theme,
397 int x, int y, int w, int h, int cpus)
398 : PluginClientWindow(_(PROGRAM_NAME ": Scopes"),
399 x, y, w, h, MIN_SCOPE_W, MIN_SCOPE_H, 1)
410 ScopeGUI::ScopeGUI(PluginClient *plugin, int w, int h)
411 : PluginClientWindow(plugin, w, h, MIN_SCOPE_W, MIN_SCOPE_H, 1)
417 this->theme = plugin->get_theme();
418 this->cpus = plugin->PluginClient::smp + 1;
422 ScopeGUI::~ScopeGUI()
424 delete waveform_vframe;
425 delete vector_vframe;
436 void ScopeGUI::reset()
467 vector_w = vector_h = 0;
468 vector_cx = vector_cy = 0;
471 dark_color = (text_color>>2) & 0x3f3f3f;
472 BC_Resources *resources = BC_WindowBase::get_resources();
473 if( resources->bg_color == 0xffffff )
474 text_color = dark_color;
477 void ScopeGUI::create_objects()
479 if( use_hist && use_hist_parade )
481 if( use_wave && use_wave_parade )
483 if( !engine ) engine = new ScopeEngine(this, cpus);
485 lock_window("ScopeGUI::create_objects");
486 int x = theme->widget_border;
487 int y = theme->widget_border;
488 add_subwindow(smooth = new ScopeSmooth(this, x, y));
489 y += smooth->get_h() + theme->widget_border;
490 add_subwindow(scope_menu = new ScopeMenu(this, x, y));
491 scope_menu->create_objects();
492 x += scope_menu->get_w() + theme->widget_border;
493 add_subwindow(value_text = new BC_Title(x, y, ""));
494 y += scope_menu->get_h() + theme->widget_border;
503 void ScopeGUI::create_panels()
505 calculate_sizes(get_w(), get_h());
506 int slider_w = xS(100);
507 if( (use_wave || use_wave_parade) ) {
508 int px = wave_x + wave_w - slider_w - xS(5);
509 int py = wave_y - ScopeGain::calculate_h() - yS(5);
511 add_subwindow(waveform = new ScopeWaveform(this,
512 wave_x, wave_y, wave_w, wave_h));
513 waveform->create_objects();
514 wave_slider = new ScopeWaveSlider(this, px, py, slider_w);
515 wave_slider->create_objects();
518 waveform->reposition_window(
519 wave_x, wave_y, wave_w, wave_h);
520 waveform->clear_box(0, 0, wave_w, wave_h);
521 wave_slider->reposition_window(px, py);
524 else if( !(use_wave || use_wave_parade) && waveform ) {
525 delete waveform; waveform = 0;
526 delete wave_slider; wave_slider = 0;
530 int vx = vector_x + vector_w - slider_w - xS(5);
531 int vy = vector_y - ScopeGain::calculate_h() - yS(5);
533 add_subwindow(vectorscope = new ScopeVectorscope(this,
534 vector_x, vector_y, vector_w, vector_h));
535 vectorscope->create_objects();
536 vect_slider = new ScopeVectSlider(this, vx, vy, slider_w);
537 vect_slider->create_objects();
538 if( use_vector < 0 ) {
539 add_subwindow(vect_grads = new ScopeVectGrads(this, vector_x, vy));
540 vect_grads->create_objects();
544 vectorscope->reposition_window(
545 vector_x, vector_y, vector_w, vector_h);
546 vectorscope->clear_box(0, 0, vector_w, vector_h);
547 vect_slider->reposition_window(vx, vy);
548 if( use_vector > 0 ) {
549 delete vect_grads; vect_grads = 0;
551 else if( !vect_grads ) {
552 add_subwindow(vect_grads = new ScopeVectGrads(this, vector_x, vy));
553 vect_grads->create_objects();
556 vect_grads->reposition_window(vector_x, vy);
559 else if( !use_vector && vectorscope ) {
560 delete vectorscope; vectorscope = 0;
561 delete vect_slider; vect_slider = 0;
562 delete vect_grads; vect_grads = 0;
565 if( (use_hist || use_hist_parade) ) {
567 // printf("ScopeGUI::create_panels %d %d %d %d %d\n", __LINE__,
568 // hist_x, hist_y, hist_w, hist_h);
569 add_subwindow(histogram = new ScopeHistogram(this,
570 hist_x, hist_y, hist_w, hist_h));
571 histogram->create_objects();
574 histogram->reposition_window(
575 hist_x, hist_y, hist_w, hist_h);
576 histogram->clear_box(0, 0, hist_w, hist_h);
579 else if( !(use_hist || use_hist_parade) ) {
580 delete histogram; histogram = 0;
585 draw_overlays(1, 1, 0);
588 void ScopeGUI::clear_points(int flash)
591 histogram->clear_point();
593 waveform->clear_point();
595 vectorscope->clear_point();
596 if( histogram && flash )
598 if( waveform && flash )
600 if( vectorscope && flash )
601 vectorscope->flash(0);
604 void ScopeGUI::toggle_event()
608 void ScopeGUI::calculate_sizes(int w, int h)
610 int margin = theme->widget_border;
611 int menu_h = smooth->get_h() + scope_menu->get_h() + margin * 3;
612 int text_w = get_text_width(SMALLFONT, "000") + margin * 2;
613 int total_panels = ((use_hist || use_hist_parade) ? 1 : 0) +
614 ((use_wave || use_wave_parade) ? 1 : 0) +
615 (use_vector ? 1 : 0);
618 int panel_w = (w - margin) / (total_panels > 0 ? total_panels : 1);
619 // Vectorscope determines the size of everything else
623 vector_x = w - panel_w + text_w;
624 vector_w = w - margin - vector_x;
626 vector_h = h - vector_y - margin;
628 if( vector_w > vector_h ) {
630 vector_x = w - theme->widget_border - vector_w;
634 panel_w = (vector_x - text_w - margin) / total_panels;
636 vector_cx = vector_w / 2;
637 vector_cy = vector_h / 2;
638 radius = bmin(vector_cx, vector_cy);
640 // Histogram is always 1st panel
641 if( use_hist || use_hist_parade ) {
644 hist_w = panel_w - margin;
645 hist_h = h - hist_y - margin;
651 if( use_wave || use_wave_parade ) {
654 wave_w = panel_w - margin - text_w;
655 wave_h = h - wave_y - margin;
661 void ScopeGUI::allocate_vframes()
663 if(waveform_vframe) delete waveform_vframe;
664 if(vector_vframe) delete vector_vframe;
665 if(wheel_vframe) delete wheel_vframe;
668 //printf("ScopeGUI::allocate_vframes %d %d %d %d %d\n", __LINE__,
669 // wave_w, wave_h, vector_w, vector_h);
670 int xs16 = xS(16), ys16 = yS(16);
671 w = MAX(wave_w, xs16);
672 h = MAX(wave_h, ys16);
673 waveform_vframe = new VFrame(w, h, BC_RGB888);
674 w = MAX(vector_w, xs16);
675 h = MAX(vector_h, ys16);
676 vector_vframe = new VFrame(w, h, BC_RGB888);
681 int ScopeGUI::resize_event(int w, int h)
683 clear_box(0, 0, w, h);
686 calculate_sizes(w, h);
687 int margin = theme->widget_border;
690 waveform->reposition_window(wave_x, wave_y, wave_w, wave_h);
691 waveform->clear_box(0, 0, wave_w, wave_h);
692 int px = wave_x + wave_w - wave_slider->get_w() - margin;
693 int py = wave_y - wave_slider->get_h() - margin;
694 wave_slider->reposition_window(px, py);
698 histogram->reposition_window(hist_x, hist_y, hist_w, hist_h);
699 histogram->clear_box(0, 0, hist_w, hist_h);
703 vectorscope->reposition_window(vector_x, vector_y, vector_w, vector_h);
704 vectorscope->clear_box(0, 0, vector_w, vector_h);
705 int vx = vector_x + vector_w - vect_slider->get_w() - margin;
706 int vy = vector_y - vect_slider->get_h() - margin;
707 vect_slider->reposition_window(vx, vy);
709 vect_grads->reposition_window(vector_x, vy);
715 draw_overlays(1, 1, 1);
719 int ScopeGUI::translation_event()
723 PluginClientWindow::translation_event();
728 void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
730 if( overlays && borders ) {
731 clear_box(0, 0, get_w(), get_h());
736 set_color(text_color);
739 if( histogram && (use_hist || use_hist_parade) ) {
740 histogram->draw_line(hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), 0,
741 hist_w * -FLOAT_MIN / (FLOAT_MAX - FLOAT_MIN), hist_h);
742 histogram->draw_line(hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), 0,
743 hist_w * (1.0 - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN), hist_h);
745 histogram->draw_point();
751 if( waveform && (use_wave || use_wave_parade) ) {
752 for( int i=0; i<=WAVEFORM_DIVISIONS; ++i ) {
753 int y = wave_h * i / WAVEFORM_DIVISIONS;
754 int text_y = y + wave_y + get_text_ascent(SMALLFONT) / 2;
755 CLAMP(text_y, waveform->get_y() + get_text_ascent(SMALLFONT), waveform->get_y() + waveform->get_h() - 1);
756 char string[BCTEXTLEN];
757 sprintf(string, "%d", (int)lround((FLOAT_MAX -
758 i * (FLOAT_MAX - FLOAT_MIN) / WAVEFORM_DIVISIONS) * 100));
759 int text_x = wave_x - get_text_width(SMALLFONT, string) - theme->widget_border;
760 set_color(text_color);
761 draw_text(text_x, text_y, string);
762 CLAMP(y, 0, waveform->get_h() - 1);
763 set_color(dark_color);
764 waveform->draw_line(0, y, wave_w, y);
765 waveform->draw_rectangle(0, 0, wave_w, wave_h);
768 waveform->draw_point();
772 // Vectorscope overlay
773 if( vectorscope && use_vector ) {
775 set_color(text_color);
776 vectorscope->draw_point();
777 vectorscope->flash(0);
781 set_font(MEDIUMFONT);
786 if( use_hist || use_hist_parade ) {
787 draw_3d_border(hist_x - 2, hist_y - 2, hist_w + 4, hist_h + 4,
788 get_bg_color(), BLACK, MDGREY, get_bg_color());
790 if( use_wave || use_wave_parade ) {
791 draw_3d_border(wave_x - 2, wave_y - 2, wave_w + 4, wave_h + 4,
792 get_bg_color(), BLACK, MDGREY, get_bg_color());
795 draw_3d_border(vector_x - 2, vector_y - 2, vector_w + 4, vector_h + 4,
796 get_bg_color(), BLACK, MDGREY, get_bg_color());
801 if(flush) this->flush();
804 void ScopeGUI::draw_gradical()
806 if( use_vector > 0 ) {
807 int margin = theme->widget_border;
809 for( int i=1; i<=VECTORSCOPE_DIVISIONS; i+=2 ) {
810 int y = vector_cy - radius * i / VECTORSCOPE_DIVISIONS;
811 int text_y = y + vector_y + get_text_ascent(SMALLFONT) / 2;
812 set_color(text_color);
813 char string[BCTEXTLEN];
814 sprintf(string, "%d",
815 (int)((FLOAT_MAX / VECTORSCOPE_DIVISIONS * i) * 100));
816 int text_x = vector_x - get_text_width(SMALLFONT, string) - margin;
817 draw_text(text_x, text_y, string);
818 int x = vector_cx - radius * i / VECTORSCOPE_DIVISIONS;
819 int w = radius * i / VECTORSCOPE_DIVISIONS * 2;
820 int h = radius * i / VECTORSCOPE_DIVISIONS * 2;
821 if( i+2 > VECTORSCOPE_DIVISIONS )
823 set_color(dark_color);
824 vectorscope->draw_circle(x, y, w, h);
826 float th = TO_RAD(90 + 32.875);
827 vectorscope->draw_radient(th, 0.1f, .75f, dark_color);
829 else if( use_vector < 0 ) {
830 if( grad_image && grad_idx != vector_gradical ) {
831 delete grad_image; grad_image = 0;
834 if( !grad_image && grad_idx > 0 ) {
835 grad_image = VFramePng::vframe_png(grad_paths[grad_idx]);
838 if( grad_pixmap && (!vector_gradical ||
839 rr != grad_pixmap->get_w() || rr != grad_pixmap->get_h()) ) {
840 delete grad_pixmap; grad_pixmap = 0;
843 if( !grad_pixmap && grad_image ) {
844 VFrame grad(rr, rr, BC_RGBA8888);
845 grad.transfer_from(grad_image);
846 grad_pixmap = new BC_Pixmap(this, &grad, PIXMAP_ALPHA);
847 vector_gradical = grad_idx;
850 int px = vector_cx - radius, py = vector_cy - radius;
851 vectorscope->draw_pixmap(grad_pixmap, px, py);
852 // vectorscope->flash(0);
858 void ScopeGUI::update_gradical(int idx)
864 void ScopeGUI::draw_colorwheel(VFrame *dst, int bg_color)
866 float cx = vector_cx, cy = vector_cy, rad = radius;
867 int color_model = dst->get_color_model();
868 int bpp = BC_CModels::calculate_pixelsize(color_model);
869 int bg_r = (bg_color>>16) & 0xff;
870 int bg_g = (bg_color>> 8) & 0xff;
871 int bg_b = (bg_color>> 0) & 0xff;
872 int w = dst->get_w(), h = dst->get_h();
873 unsigned char **rows = dst->get_rows();
874 for( int y=0; y<h; ++y ) {
875 unsigned char *row = rows[y];
876 for( int x=0; x<w; ++x,row+=bpp ) {
877 int dx = cx-x, dy = cy-y;
878 float d = sqrt(dx*dx + dy*dy);
881 float h = TO_DEG(atan2(cx-x, cy-y));
882 if( h < 0 ) h += 360;
883 float s = d / rad, v = 255;
884 HSV::hsv_to_rgb(r, g, b, h, s, v);
887 r = bg_r; g = bg_g; b = bg_b;
889 row[0] = r; row[1] = g; row[2] = b;
895 void ScopeGUI::process(VFrame *output_frame)
897 lock_window("ScopeGUI::process");
898 this->output_frame = output_frame;
899 int ow = output_frame->get_w(), oh = output_frame->get_h();
901 VFrame::get_temp(temp_frame, ow, oh, BC_RGB161616);
902 temp_frame->transfer_from(output_frame);
903 if( !box_blur ) box_blur = new BoxBlur(cpus);
904 box_blur->blur(temp_frame, temp_frame, 2, 2);
905 data_frame = temp_frame;
908 data_frame = output_frame;
909 frame_w = data_frame->get_w();
910 bzero(waveform_vframe->get_data(), waveform_vframe->get_data_size());
912 bzero(vector_vframe->get_data(), vector_vframe->get_data_size());
913 else if( use_vector < 0 ) {
914 if( wheel_vframe && (
915 wheel_vframe->get_w() != vector_w ||
916 wheel_vframe->get_h() != vector_h ) ) {
917 delete wheel_vframe; wheel_vframe = 0;
919 if( !wheel_vframe ) {
920 wheel_vframe = new VFrame(vector_w, vector_h, BC_RGB888);
921 draw_colorwheel(wheel_vframe, BLACK);
923 vector_vframe->copy_from(wheel_vframe);
928 histogram->draw(0, 0);
930 waveform->draw_vframe(waveform_vframe);
932 vectorscope->draw_vframe(vector_vframe);
934 draw_overlays(1, 0, 1);
938 void ScopeGUI::update_toggles()
940 scope_menu->update_toggles();
943 ScopePanel::ScopePanel(ScopeGUI *gui, int x, int y, int w, int h)
944 : BC_SubWindow(x, y, w, h, BLACK)
950 void ScopePanel::create_objects()
952 set_cursor(CROSS_CURSOR, 0, 0);
953 clear_box(0, 0, get_w(), get_h());
956 void ScopePanel::update_point(int x, int y)
960 void ScopePanel::draw_point()
964 void ScopePanel::clear_point()
968 int ScopePanel::button_press_event()
970 if( is_event_win() && cursor_inside() ) {
971 gui->clear_points(1);
973 int x = get_cursor_x();
974 int y = get_cursor_y();
975 CLAMP(x, 0, get_w() - 1);
976 CLAMP(y, 0, get_h() - 1);
984 int ScopePanel::cursor_motion_event()
987 int x = get_cursor_x();
988 int y = get_cursor_y();
989 CLAMP(x, 0, get_w() - 1);
990 CLAMP(y, 0, get_h() - 1);
998 int ScopePanel::button_release_event()
1008 ScopeWaveform::ScopeWaveform(ScopeGUI *gui,
1009 int x, int y, int w, int h)
1010 : ScopePanel(gui, x, y, w, h)
1016 void ScopeWaveform::update_point(int x, int y)
1021 int frame_x = x * gui->frame_w / get_w();
1023 if( gui->use_wave_parade ) {
1024 if( x > get_w() / 3 * 2 )
1025 frame_x = (x - get_w() / 3 * 2) * gui->frame_w / (get_w() / 3);
1026 else if( x > get_w() / 3 )
1027 frame_x = (x - get_w() / 3) * gui->frame_w / (get_w() / 3);
1029 frame_x = x * gui->frame_w / (get_w() / 3);
1032 float value = ((float)get_h() - y) / get_h() * (FLOAT_MAX - FLOAT_MIN) + FLOAT_MIN;
1033 char string[BCTEXTLEN];
1034 sprintf(string, "X: %d Value: %.3f", frame_x, value);
1035 gui->value_text->update(string, 0);
1041 void ScopeWaveform::draw_point()
1045 set_color(0xffffff);
1047 draw_line(0, drag_y, get_w(), drag_y);
1048 draw_line(drag_x, 0, drag_x, get_h());
1054 void ScopeWaveform::clear_point()
1061 ScopeVectorscope::ScopeVectorscope(ScopeGUI *gui,
1062 int x, int y, int w, int h)
1063 : ScopePanel(gui, x, y, w, h)
1069 void ScopeVectorscope::clear_point()
1077 void ScopeVectorscope::update_point(int x, int y)
1081 int dx = x - gui->vector_cx, dy = y - gui->vector_cy;
1082 drag_radius = sqrt(dx*dx + dy*dy);
1083 if( drag_radius > gui->radius ) drag_radius = gui->radius;
1084 float saturation = (float)drag_radius / gui->radius * FLOAT_MAX;
1085 drag_angle = atan2(-dy, dx);
1086 float hue = TO_DEG(drag_angle) - 90;
1087 if( hue < 0 ) hue += 360;
1089 char string[BCTEXTLEN];
1090 sprintf(string, "Hue: %.3f Sat: %.3f", hue, saturation);
1091 gui->value_text->update(string, 0);
1098 void ScopeVectorscope::draw_point()
1101 draw_point(drag_angle, drag_radius, RED);
1105 void ScopeVectorscope::draw_point(float th, float r, int color)
1110 int cx = gui->vector_cx, cy = gui->vector_cy;
1111 draw_circle(cx-r, cy-r, r*2, r*2);
1113 float radius = gui->radius;
1114 draw_radient(th, 0.f, drag_radius/radius, color);
1118 void ScopeVectorscope::draw_radient(float th, float r1, float r2, int color)
1120 if( r2 > 0 && r2 >= r1 ) {
1123 int r = gui->radius;
1124 double cth = r*cos(th), sth = -r*sin(th);
1125 int cx = gui->vector_cx, cy = gui->vector_cy;
1126 draw_line(cx+r1*cth, cy+r1*sth, cx+r2*cth, cy+r2*sth);
1132 ScopeHistogram::ScopeHistogram(ScopeGUI *gui,
1133 int x, int y, int w, int h)
1134 : ScopePanel(gui, x, y, w, h)
1139 void ScopeHistogram::clear_point()
1146 void ScopeHistogram::draw_point()
1150 set_color(0xffffff);
1152 draw_line(drag_x, 0, drag_x, get_h());
1158 void ScopeHistogram::update_point(int x, int y)
1162 float value = (float)x / get_w() * (FLOAT_MAX - FLOAT_MIN) + FLOAT_MIN;
1164 char string[BCTEXTLEN];
1165 sprintf(string, "Value: %.3f", value);
1166 gui->value_text->update(string, 0);
1174 void ScopeHistogram::draw_mode(int mode, int color, int y, int h)
1176 // Highest of all bins
1177 int normalize = 1, w = get_w();
1178 int *bin = gui->bins[mode], v;
1179 for( int i=0; i<TOTAL_BINS; ++i )
1180 if( (v=bin[i]) > normalize ) normalize = v;
1181 double norm = normalize>1 ? log(normalize) : 1e-4;
1182 double vnorm = h / norm;
1184 for( int x=0; x<w; ++x ) {
1185 int accum_start = (int)(x * TOTAL_BINS / w);
1186 int accum_end = (int)((x + 1) * TOTAL_BINS / w);
1187 CLAMP(accum_start, 0, TOTAL_BINS);
1188 CLAMP(accum_end, 0, TOTAL_BINS);
1190 for(int i=accum_start; i<accum_end; ++i )
1191 if( (v=bin[i]) > max ) max = v;
1192 // max = max * h / normalize;
1193 max = log(max) * vnorm;
1194 draw_line(x,y+h - max, x,y+h);
1197 void ScopeHistogram::draw(int flash, int flush)
1199 clear_box(0, 0, get_w(), get_h());
1200 if( gui->use_hist_parade ) {
1201 draw_mode(0, 0xff0000, 0, get_h() / 3);
1202 draw_mode(1, 0x00ff00, get_h() / 3, get_h() / 3);
1203 draw_mode(2, 0x0000ff, get_h() / 3 * 2, get_h() / 3);
1206 draw_mode(3, LTGREY, 0, get_h());
1209 if(flash) this->flash(0);
1210 if(flush) this->flush();
1214 ScopeScopesOn::ScopeScopesOn(ScopeMenu *scope_menu, const char *text, int id)
1217 this->scope_menu = scope_menu;
1221 int ScopeScopesOn::handle_event()
1223 int v = get_checked() ? 0 : 1;
1225 ScopeGUI *gui = scope_menu->gui;
1227 case SCOPE_HISTOGRAM:
1229 if( v ) gui->use_hist_parade = 0;
1231 case SCOPE_HISTOGRAM_RGB:
1232 gui->use_hist_parade = v;
1233 if( v ) gui->use_hist = 0;
1235 case SCOPE_WAVEFORM:
1237 if( v ) gui->use_wave_parade = 0;
1239 case SCOPE_WAVEFORM_RGB:
1240 gui->use_wave_parade = v;
1241 if( v ) gui->use_wave = 0;
1243 case SCOPE_WAVEFORM_PLY:
1244 gui->use_wave_parade = -v;
1245 if( v ) gui->use_wave = 0;
1247 case SCOPE_VECTORSCOPE:
1248 gui->use_vector = v;
1250 case SCOPE_VECTORWHEEL:
1251 gui->use_vector = -v;
1254 gui->toggle_event();
1255 gui->update_toggles();
1256 gui->create_panels();
1257 gui->update_scope();
1262 ScopeMenu::ScopeMenu(ScopeGUI *gui, int x, int y)
1263 : BC_PopupMenu(x, y, xS(100), _("Scopes"))
1268 void ScopeMenu::create_objects()
1271 new ScopeScopesOn(this, _("Histogram"), SCOPE_HISTOGRAM));
1272 add_item(hist_rgb_on =
1273 new ScopeScopesOn(this, _("Histogram RGB"), SCOPE_HISTOGRAM_RGB));
1274 add_item(new BC_MenuItem("-"));
1276 new ScopeScopesOn(this, _("Waveform"), SCOPE_WAVEFORM));
1277 add_item(wave_rgb_on =
1278 new ScopeScopesOn(this, _("Waveform RGB"), SCOPE_WAVEFORM_RGB));
1279 add_item(wave_ply_on =
1280 new ScopeScopesOn(this, _("Waveform ply"), SCOPE_WAVEFORM_PLY));
1281 add_item(new BC_MenuItem("-"));
1283 new ScopeScopesOn(this, _("Vectorscope"), SCOPE_VECTORSCOPE));
1284 add_item(vect_wheel =
1285 new ScopeScopesOn(this, _("VectorWheel"), SCOPE_VECTORWHEEL));
1288 void ScopeMenu::update_toggles()
1290 hist_on->set_checked(gui->use_hist);
1291 hist_rgb_on->set_checked(gui->use_hist_parade);
1292 wave_on->set_checked(gui->use_wave);
1293 wave_rgb_on->set_checked(gui->use_wave_parade>0);
1294 wave_ply_on->set_checked(gui->use_wave_parade<0);
1295 vect_on->set_checked(gui->use_vector>0);
1296 vect_wheel->set_checked(gui->use_vector<0);
1300 ScopeVectGrads::ScopeVectGrads(ScopeGUI *gui, int x, int y)
1301 : BC_PopupMenu(x, y, xS(40), "", 1, 0, 0)
1306 #define SCOPE_SEARCHPATH "/scopes"
1307 void ScopeVectGrads::create_objects()
1309 gui->grad_paths.remove_all_objects();
1310 ScopeGradItem *item;
1311 add_item(item = new ScopeGradItem(this, _("none"), 0));
1312 if( item->idx == gui->vector_gradical ) item->set_checked(1);
1313 gui->grad_paths.append(0);
1315 fs.set_filter("[*.png][*.jpg]");
1316 char scope_path[BCTEXTLEN];
1317 sprintf(scope_path, "%s%s", File::get_plugin_path(), SCOPE_SEARCHPATH);
1318 fs.update(scope_path);
1319 for( int i=0; i<fs.total_files(); ++i ) {
1320 FileItem *file_item = fs.get_entry(i);
1321 if( file_item->get_is_dir() ) continue;
1322 strcpy(scope_path, file_item->get_name());
1323 char *cp = strrchr(scope_path, '.');
1325 add_item(item = new ScopeGradItem(this, scope_path, gui->grad_paths.size()));
1326 if( item->idx == gui->vector_gradical ) item->set_checked(1);
1327 gui->grad_paths.append(cstrdup(file_item->get_path()));
1331 ScopeGradItem::ScopeGradItem(ScopeVectGrads *vect_grads, const char *text, int idx)
1334 this->vect_grads = vect_grads;
1338 int ScopeGradItem::handle_event()
1340 for( int i=0,n=vect_grads->total_items(); i<n; ++i ) {
1341 ScopeGradItem *item = (ScopeGradItem *)vect_grads->get_item(i);
1342 item->set_checked(item == this);
1344 vect_grads->gui->update_gradical(idx);
1349 ScopeGainReset::ScopeGainReset(ScopeGain *gain, int x, int y)
1350 : BC_Button(x, y, gain->gui->theme->get_image_set("reset_button"))
1355 int ScopeGainReset::calculate_w(BC_Theme *theme)
1357 VFrame *vfrm = *theme->get_image_set("reset_button");
1358 return vfrm->get_w();
1361 int ScopeGainReset::handle_event()
1363 gain->slider->update(5);
1364 return gain->handle_event();
1367 ScopeGainSlider::ScopeGainSlider(ScopeGain *gain, int x, int y, int w)
1368 : BC_ISlider(x, y, 0, w, w, 1, 9, *gain->value)
1373 int ScopeGainSlider::handle_event()
1375 return gain->handle_event();
1378 ScopeGain::ScopeGain(ScopeGUI *gui, int x, int y, int w, int *value)
1384 this->value = value;
1389 ScopeGain::~ScopeGain()
1395 int ScopeGain::calculate_h()
1397 return BC_ISlider::get_span(0);
1400 void ScopeGain::create_objects()
1402 reset_w = ScopeGainReset::calculate_w(gui->theme);
1403 gui->add_subwindow(slider = new ScopeGainSlider(this, x, y, w-reset_w-xS(5)));
1404 gui->add_subwindow(reset = new ScopeGainReset(this, x+w-reset_w, y));
1407 int ScopeGain::handle_event()
1409 *value = slider->get_value();
1410 gui->update_scope();
1411 gui->toggle_event();
1415 void ScopeGain::reposition_window(int x, int y)
1417 this->x = x; this->y = y;
1418 slider->reposition_window(x, y);
1419 reset->reposition_window(x+w-reset_w, y);
1422 ScopeWaveSlider::ScopeWaveSlider(ScopeGUI *gui, int x, int y, int w)
1423 : ScopeGain(gui, x, y, w, &gui->use_wave_gain)
1427 ScopeVectSlider::ScopeVectSlider(ScopeGUI *gui, int x, int y, int w)
1428 : ScopeGain(gui, x, y, w, &gui->use_vect_gain)
1432 ScopeSmooth::ScopeSmooth(ScopeGUI *gui, int x, int y)
1433 : BC_CheckBox(x, y, gui->use_smooth, _("Smooth"))
1438 int ScopeSmooth::handle_event()
1440 gui->use_smooth = get_value();
1441 gui->update_scope();
1442 gui->toggle_event();