mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 12:32:29 +00:00
audiovisualizers: add some simple drawing helpers for reuse
Add a (uninstalled) header with simple drawing macros
This commit is contained in:
parent
b9c9540735
commit
e3d1a50c0d
3 changed files with 44 additions and 29 deletions
|
@ -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)
|
||||
|
|
37
gst/audiovisualizers/gstdrawhelpers.h
Normal file
37
gst/audiovisualizers/gstdrawhelpers.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <2011> Stefan Sauer <ensonic@users.sf.net>
|
||||
*
|
||||
* 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
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue