/** * Draw a rectangle * * @param f Video frame * @param x0 Origin X-position * @param y0 Origin Y-position * @param w Rectangle width * @param h Rectangle height * @param r Red color component * @param g Green color component * @param b Blue color component */ void vidframe_draw_rect(struct vidframe *f, unsigned x0, unsigned y0, unsigned w, unsigned h, uint8_t r, uint8_t g, uint8_t b) { if (!f) return; vidframe_draw_hline(f, x0, y0, w, r, g, b); vidframe_draw_hline(f, x0, y0+h-1, w, r, g, b); vidframe_draw_vline(f, x0, y0, h, r, g, b); vidframe_draw_vline(f, x0+w-1, y0, h, r, g, b); }
static void draw_graph(struct panel *panel, struct vidframe *frame) { uint64_t avg; unsigned y0 = panel->yoffs; size_t i; if (rrd_get_average(panel, &avg)) return; for (i=0; i<panel->rrdc; i++) { uint64_t value; double ratio; unsigned pixels; unsigned x = panel->xoffs + (unsigned)i * 2; unsigned y; value = panel->rrdv[i]; ratio = (double)value / (double)avg; pixels = (double)panel->size.h * ratio * 0.5f; pixels = min(pixels, panel->size.h); y = y0 + panel->size.h - pixels; vidframe_draw_vline(frame, x, y, pixels, 220, 220, 220); } }
static int plot_spectrum(const char *filename_png) { struct vidframe *vf = NULL; struct vidsz sz = {NUM_FREQ+1, NUM_FREQ/2}; unsigned long peak_mag = 0; size_t peak_bin = 0; size_t i; unsigned x; int err; err = vidframe_alloc(&vf, VID_FMT_RGB32, &sz); if (err) goto out; /* find the peak amplitude and its bin */ for (i=0; i<NUM_FREQ; i++) { if (magv[i] > peak_mag) { peak_mag = magv[i]; peak_bin = i; } } re_printf("peak magnitude is %u in bin %u\n", peak_mag, peak_bin); vidframe_fill(vf, 255, 255, 255); for (x=0; x<NUM_FREQ; x++) { unsigned h; h = (unsigned)((sz.h-1) * 1.0 * magv[x] / peak_mag); vidframe_draw_vline(vf, x, sz.h-1-h, h, 255, 0, 0); } err = png_save_vidframe(vf, filename_png); if (err) goto out; out: mem_deref(vf); return err; }