1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/* Libvisual-plugins - Standard plugins for libvisual
*
* Copyright (C) 2004, 2005, 2006 Dennis Smit <ds@nerds-incorporated.org>
*
* Authors: Dennis Smit <ds@nerds-incorporated.org>
*
* $Id: actor_lv_scope.c,v 1.21 2006/01/27 20:19:17 synap Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1
* 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 Lesser 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
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <gettext.h>
#include <libvisual/libvisual.h>
#define PCM_SIZE 1024
typedef struct {
VisPalette pal;
VisBuffer pcm;
} ScopePrivate;
int lv_scope_init (VisPluginData *plugin);
int lv_scope_cleanup (VisPluginData *plugin);
int lv_scope_requisition (VisPluginData *plugin, int *width, int *height);
int lv_scope_dimension (VisPluginData *plugin, VisVideo *video, int width, int height);
int lv_scope_events (VisPluginData *plugin, VisEventQueue *events);
VisPalette *lv_scope_palette (VisPluginData *plugin);
int lv_scope_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio);
VISUAL_PLUGIN_API_VERSION_VALIDATOR
const VisPluginInfo *get_plugin_info (int *count)
{
static VisActorPlugin actor[] = {{
.requisition = lv_scope_requisition,
.palette = lv_scope_palette,
.render = lv_scope_render,
.vidoptions.depth = VISUAL_VIDEO_DEPTH_8BIT
}};
static VisPluginInfo info[] = {{
.type = VISUAL_PLUGIN_TYPE_ACTOR,
.plugname = "lv_scope",
.name = "libvisual scope",
.author = "Dennis Smit <ds@nerds-incorporated.org>",
.version = "0.1",
.about = N_("Libvisual scope plugin"),
.help = N_("This is a test plugin that'll display a simple scope"),
.init = lv_scope_init,
.cleanup = lv_scope_cleanup,
.events = lv_scope_events,
.plugin = VISUAL_OBJECT (&actor[0])
}};
*count = sizeof (info) / sizeof (*info);
return info;
}
int lv_scope_init (VisPluginData *plugin)
{
ScopePrivate *priv;
#if ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
#endif
priv = visual_mem_new0 (ScopePrivate, 1);
visual_object_set_private (VISUAL_OBJECT (plugin), priv);
visual_palette_allocate_colors (&priv->pal, 256);
visual_buffer_init_allocate (&priv->pcm, sizeof (float) * PCM_SIZE, visual_buffer_destroyer_free);
return 0;
}
int lv_scope_cleanup (VisPluginData *plugin)
{
ScopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
visual_palette_free_colors (&priv->pal);
visual_object_unref (VISUAL_OBJECT (&priv->pcm));
visual_mem_free (priv);
return 0;
}
int lv_scope_requisition (VisPluginData *plugin, int *width, int *height)
{
int reqw, reqh;
reqw = *width;
reqh = *height;
while (reqw % 2 || (reqw / 2) % 2)
reqw--;
while (reqh % 2 || (reqh / 2) % 2)
reqh--;
if (reqw < 32)
reqw = 32;
if (reqh < 32)
reqh = 32;
*width = reqw;
*height = reqh;
return 0;
}
int lv_scope_dimension (VisPluginData *plugin, VisVideo *video, int width, int height)
{
visual_video_set_dimension (video, width, height);
return 0;
}
int lv_scope_events (VisPluginData *plugin, VisEventQueue *events)
{
VisEvent ev;
while (visual_event_queue_poll (events, &ev)) {
switch (ev.type) {
case VISUAL_EVENT_RESIZE:
lv_scope_dimension (plugin, ev.event.resize.video,
ev.event.resize.width, ev.event.resize.height);
break;
default: /* to avoid warnings */
break;
}
}
return 0;
}
VisPalette *lv_scope_palette (VisPluginData *plugin)
{
ScopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
int i;
for (i = 0; i < 256; i++) {
priv->pal.colors[i].r = i;
priv->pal.colors[i].g = i;
priv->pal.colors[i].b = i;
}
return &priv->pal;
}
int lv_scope_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio)
{
ScopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
VisColor col;
float *pcmbuf;
int i, y, y_old;
uint8_t *buf;
if (video == NULL)
return -1;
y = video->height >> 1;
visual_audio_get_sample_mixed (audio, &priv->pcm, TRUE, 2,
VISUAL_AUDIO_CHANNEL_LEFT,
VISUAL_AUDIO_CHANNEL_RIGHT,
1.0,
1.0);
pcmbuf = visual_buffer_get_data (&priv->pcm);
visual_color_set (&col, 0, 0, 0);
visual_video_fill_color (video, &col);
buf = (uint8_t *) visual_video_get_pixels (video);
y_old = video->height / 2;
for (i = 0; i < video->width; i++) {
int j;
y = (video->height / 2) + (pcmbuf[(i >> 1) % PCM_SIZE] * (video->height / 4));
if (y > y_old) {
for (j = y_old; j < y; j++)
buf[(j * video->pitch) + i] = 255;
} else {
for (j = y; j < y_old; j++)
buf[(j * video->pitch) + i] = 255;
}
}
return 0;
}
|