From f32f48ae2673b799878a831ba9e216b26177505a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 13 Apr 2011 19:08:23 -0300 Subject: [PATCH] atrf-path: visualize the limits in GUI mode - gui.c (avg2y, segment): moved mapping from measurement to y position to separate function, to allow for sharing - gui.c (LIMIT_RGBA, draw_limit, gui): draw the limits --- tools/atrf-path/gui.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/atrf-path/gui.c b/tools/atrf-path/gui.c index cd1e25a..4781ee5 100644 --- a/tools/atrf-path/gui.c +++ b/tools/atrf-path/gui.c @@ -33,6 +33,7 @@ #define OK_RGBA 0x00ff00ff #define OVER_RGBA 0xffff00ff #define UNDER_RGBA 0xff0000ff +#define LIMIT_RGBA 0xff0000ff #define CHAN_STEP 20 /* 4 pixels/MHz */ #define SIDE_STEP 2 @@ -45,10 +46,16 @@ #define STATUS_R 8 +static int avg2y(double avg) +{ + return YRES-(avg-Y_MIN)/(Y_MAX-Y_MIN)*YRES-1; +} + + static void segment(SDL_Surface *s, int *last_x, int *last_y, int x, const struct sample *res, int first) { - int y = YRES-(res->avg-Y_MIN)/(Y_MAX-Y_MIN)*YRES-1; + int y = avg2y(res->avg); if (!first) { aalineColor(s, *last_x, *last_y, x, y, FG_RGBA); @@ -83,6 +90,23 @@ static void draw(SDL_Surface *s, const struct sample *res, int cont_tx) } +static void draw_limit(SDL_Surface *s, const double *v) +{ + int x, y, i, last = 0; + + x = CHAN_X_OFFSET; + for (i = 0; i != N_CHAN; i++) { + y = avg2y(*v); + if (i) + vlineColor(s, x-CHAN_STEP/2, last, y, LIMIT_RGBA); + hlineColor(s, x-CHAN_STEP/2, x+CHAN_STEP/2, y, LIMIT_RGBA); + last = y; + x += CHAN_STEP; + v++; + } +} + + static void indicate(SDL_Surface *s, int fail) { static uint32_t last = 0; @@ -179,6 +203,8 @@ void gui(const struct sweep *sweep, int sweeps) clear(surf); + draw_limit(surf, sweep->min); + draw_limit(surf, sweep->max); indicate(surf, fail); draw(surf, res, sweep->cont_tx);