From e3d1a50c0d2a30558e3a46d9ba74d27f153cc670 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Wed, 23 Nov 2011 08:40:49 +0100 Subject: [PATCH] audiovisualizers: add some simple drawing helpers for reuse Add a (uninstalled) header with simple drawing macros --- gst/audiovisualizers/Makefile.am | 2 +- gst/audiovisualizers/gstdrawhelpers.h | 37 +++++++++++++++++++++++++++ gst/audiovisualizers/gstwavescope.c | 34 +++++------------------- 3 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 gst/audiovisualizers/gstdrawhelpers.h diff --git a/gst/audiovisualizers/Makefile.am b/gst/audiovisualizers/Makefile.am index 811c7d831f..f6ee5299d6 100644 --- a/gst/audiovisualizers/Makefile.am +++ b/gst/audiovisualizers/Makefile.am @@ -17,7 +17,7 @@ libgstaudiovisualizers_la_LIBADD = \ libgstaudiovisualizers_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstaudiovisualizers_la_LIBTOOLFLAGS = --tag=disable-static -noinst_HEADERS = gstbaseaudiovisualizer.h \ +noinst_HEADERS = gstbaseaudiovisualizer.h gstdrawhelpers.h \ gstspacescope.h gstspectrascope.h gstsynaescope.h gstwavescope.h Android.mk: Makefile.am $(BUILT_SOURCES) diff --git a/gst/audiovisualizers/gstdrawhelpers.h b/gst/audiovisualizers/gstdrawhelpers.h new file mode 100644 index 0000000000..d3597ff621 --- /dev/null +++ b/gst/audiovisualizers/gstdrawhelpers.h @@ -0,0 +1,37 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Sauer + * + * gstdrawhelpers.h: simple drawing helpers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define draw_dot(_vd, _x, _y, _st, _c) G_STMT_START { \ + _vd[(_y * _st) + _x] = _c; \ +} G_STMT_END + +#define draw_line(_vd, _x1, _x2, _y1, _y2, _st, _c) G_STMT_START { \ + guint _i, _j, _x, _y; \ + gint _dx = _x2 - _x1, _dy = _y2 - _y1; \ + gfloat _f; \ + \ + _j = abs (_dx) > abs (_dy) ? abs (_dx) : abs (_dy); \ + for (_i = 0; _i < _j; _i++) { \ + _f = (gfloat) _i / (gfloat) _j; \ + _x = _x1 + _dx * _f; \ + _y = _y1 + _dy * _f; \ + draw_dot (_vd, _x, _y, _st, _c); \ + } \ +} G_STMT_END diff --git a/gst/audiovisualizers/gstwavescope.c b/gst/audiovisualizers/gstwavescope.c index 5d943373fa..ab97e7dfc5 100644 --- a/gst/audiovisualizers/gstwavescope.c +++ b/gst/audiovisualizers/gstwavescope.c @@ -184,15 +184,16 @@ gst_wave_scope_get_property (GObject * object, guint prop_id, } } +#include "gstdrawhelpers.h" + static void render_dots (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata, guint num_samples) { gint channels = scope->channels; - guint i, c, s, x = 0, y, oy; + guint i, c, s, x, y, oy; gfloat dx, dy; guint w = scope->width; - guint off; /* draw dots */ dx = (gfloat) w / (gfloat) num_samples; @@ -204,40 +205,17 @@ render_dots (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata, x = (guint) ((gfloat) i * dx); y = (guint) (oy + (gfloat) adata[s] * dy); s += channels; - off = (y * w) + x; - vdata[off] = 0x00FFFFFF; + draw_dot (vdata, x, y, w, 0x00FFFFFF); } } } -static void -draw_line (guint32 * vdata, guint x1, guint x2, guint y1, guint y2, guint w) -{ - guint i, j, x, y, off; - gint dx = x2 - x1; - gint dy = y2 - y1; - gfloat f; - - if (abs (dx) > abs (dy)) { - j = abs (dx); - } else { - j = abs (dy); - } - for (i = 0; i < j; i++) { - f = (gfloat) i / (gfloat) j; - x = x1 + dx * f; - y = y1 + dy * f; - off = (y * w) + x; - vdata[off] = 0x00FFFFFF; - } -} - static void render_lines (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata, guint num_samples) { gint channels = scope->channels; - guint i, c, s, x = 0, y, oy; + guint i, c, s, x, y, oy; gfloat dx, dy; guint w = scope->width; gint x2, y2; @@ -254,7 +232,7 @@ render_lines (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata, x = (guint) ((gfloat) i * dx); y = (guint) (oy + (gfloat) adata[s] * dy); s += channels; - draw_line (vdata, x2, x, y2, y, w); + draw_line (vdata, x2, x, y2, y, w, 0x00FFFFFF); x2 = x; y2 = y; }