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