scopes: draw pixels with signle 32bit writes

https://bugzilla.gnome.org/show_bug.cgi?id=651536
This commit is contained in:
Stefan Kost 2011-05-28 23:22:59 +03:00
parent 2d101863dc
commit 08ecb1acc0
2 changed files with 19 additions and 27 deletions

View file

@ -120,16 +120,16 @@ static gboolean
gst_spectra_scope_setup (GstBaseScope * bscope)
{
GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope);
guint num_freq = bscope->width + 1;
if (scope->fft_ctx)
gst_fft_s16_free (scope->fft_ctx);
if (scope->freq_data)
g_free (scope->freq_data);
g_free (scope->freq_data);
/* we'd need this amount of samples per render() call */
bscope->req_spf = bscope->width * 2 - 2;
bscope->req_spf = num_freq * 2 - 2;
scope->fft_ctx = gst_fft_s16_new (bscope->req_spf, FALSE);
scope->freq_data = g_new (GstFFTS16Complex, bscope->width);
scope->freq_data = g_new (GstFFTS16Complex, num_freq);
return TRUE;
}
@ -139,19 +139,18 @@ gst_spectra_scope_render (GstBaseScope * bscope, GstBuffer * audio,
GstBuffer * video)
{
GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope);
guint8 *vdata = GST_BUFFER_DATA (video);
guint32 *vdata = (guint32 *) GST_BUFFER_DATA (video);
gint16 *adata = (gint16 *) GST_BUFFER_DATA (audio);
GstFFTS16Complex *fdata = scope->freq_data;
guint x, y, off;
guint l, h = bscope->height - 1;
gfloat fr, fi;
guint bpp = gst_video_format_get_pixel_stride (bscope->video_format, 0);
guint bpl = bpp * bscope->width;
guint w = bscope->width;
if (bscope->channels > 1) {
gint ch = bscope->channels;
gint num_samples = GST_BUFFER_SIZE (audio) / (ch * sizeof (gint16));
gint i, c, v, s = 0;
guint ch = bscope->channels;
guint num_samples = GST_BUFFER_SIZE (audio) / (ch * sizeof (gint16));
guint i, c, v, s = 0;
/* deinterleave and mixdown adata */
for (i = 0; i < num_samples; i++) {
@ -171,21 +170,17 @@ gst_spectra_scope_render (GstBaseScope * bscope, GstBuffer * audio,
for (x = 0; x < bscope->width; x++) {
/* figure out the range so that we don't need to clip,
* or even better do a log mapping? */
fr = (gfloat) fdata[x].r / 2048.0;
fi = (gfloat) fdata[x].i / 2048.0;
fr = (gfloat) fdata[1 + x].r / 512.0;
fi = (gfloat) fdata[1 + x].i / 512.0;
y = (guint) (h * fabs (fr * fr + fi * fi));
if (y > h)
y = h;
y = h - y;
off = (y * bpl) + (x * bpp);
vdata[off + 0] = 0xFF;
vdata[off + 1] = 0xFF;
vdata[off + 2] = 0xFF;
off = (y * w) + x;
vdata[off] = 0x00FFFFFF;
for (l = y + 1; l <= h; l++) {
off += bpl;
vdata[off + 0] = 0x7F;
vdata[off + 1] = 0x7F;
vdata[off + 2] = 0x7F;
off += w;
vdata[off] = 0x007F7F7F;
}
}
return TRUE;

View file

@ -104,13 +104,12 @@ static gboolean
gst_wave_scope_render (GstBaseScope * scope, GstBuffer * audio,
GstBuffer * video)
{
guint8 *vdata = GST_BUFFER_DATA (video);
guint32 *vdata = (guint32 *) GST_BUFFER_DATA (video);
gint16 *adata = (gint16 *) GST_BUFFER_DATA (audio);
guint i, c, s, x, y, off, oy;
guint num_samples;
gfloat dx, dy;
guint bpp = gst_video_format_get_pixel_stride (scope->video_format, 0);
guint bpl = bpp * scope->width;
guint w = scope->width;
/* draw dots */
num_samples = GST_BUFFER_SIZE (audio) / (scope->channels * sizeof (gint16));
@ -122,10 +121,8 @@ gst_wave_scope_render (GstBaseScope * scope, GstBuffer * audio,
x = (guint) ((gfloat) i * dx);
for (c = 0; c < scope->channels; c++) {
y = (guint) (oy + (gfloat) adata[s++] * dy);
off = (y * bpl) + (x * bpp);
vdata[off + 0] = 0xFF;
vdata[off + 1] = 0xFF;
vdata[off + 2] = 0xFF;
off = (y * w) + x;
vdata[off] = 0x00FFFFFF;
}
}
return TRUE;