| 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: lv_infinite.c,v 1.24 2006/01/30 18:22:50 synap Exp $ |
| 8 |
* |
| 9 |
* This program is free software; you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as |
| 11 |
* published by the Free Software Foundation; either version 2 |
| 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 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 <unistd.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
#include <stdio.h> |
| 30 |
#include <gettext.h> |
| 31 |
|
| 32 |
#include "main.h" |
| 33 |
#include "renderer.h" |
| 34 |
#include "display.h" |
| 35 |
|
| 36 |
int act_infinite_init (VisPluginData *plugin); |
| 37 |
int act_infinite_cleanup (VisPluginData *plugin); |
| 38 |
int act_infinite_dimension (VisPluginData *plugin, VisVideo *video, int width, int height); |
| 39 |
int act_infinite_requisition (VisPluginData *plugin, int *width, int *height); |
| 40 |
int act_infinite_events (VisPluginData *plugin, VisEventQueue *events); |
| 41 |
VisPalette *act_infinite_palette (VisPluginData *plugin); |
| 42 |
int act_infinite_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio); |
| 43 |
|
| 44 |
VISUAL_PLUGIN_API_VERSION_VALIDATOR |
| 45 |
|
| 46 |
const VisPluginInfo *get_plugin_info (int *count) |
| 47 |
{ |
| 48 |
static VisActorPlugin actor[] = {{ |
| 49 |
.requisition = act_infinite_requisition, |
| 50 |
.palette = act_infinite_palette, |
| 51 |
.render = act_infinite_render, |
| 52 |
.vidoptions.depth = VISUAL_VIDEO_DEPTH_8BIT |
| 53 |
}}; |
| 54 |
|
| 55 |
static VisPluginInfo info[] = {{ |
| 56 |
.type = VISUAL_PLUGIN_TYPE_ACTOR, |
| 57 |
|
| 58 |
.plugname = "infinite", |
| 59 |
.name = "infinite plugin", |
| 60 |
.author = N_("Original by: Julien Carme <[email protected]>, Port by: Dennis Smit <[email protected]>"), |
| 61 |
.version = "0.1", |
| 62 |
.about = N_("Infinite visual plugin"), |
| 63 |
.help = N_("This is the libvisual plugin for the infinite visual"), |
| 64 |
.license = VISUAL_PLUGIN_LICENSE_GPL, |
| 65 |
|
| 66 |
.init = act_infinite_init, |
| 67 |
.cleanup = act_infinite_cleanup, |
| 68 |
.events = act_infinite_events, |
| 69 |
|
| 70 |
.plugin = VISUAL_OBJECT (&actor[0]) |
| 71 |
}}; |
| 72 |
|
| 73 |
*count = sizeof (info) / sizeof (*info); |
| 74 |
|
| 75 |
return info; |
| 76 |
} |
| 77 |
|
| 78 |
int act_infinite_init (VisPluginData *plugin) |
| 79 |
{ |
| 80 |
InfinitePrivate *priv; |
| 81 |
|
| 82 |
#if ENABLE_NLS |
| 83 |
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); |
| 84 |
#endif |
| 85 |
|
| 86 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 87 |
|
| 88 |
priv = visual_mem_new0 (InfinitePrivate, 1); |
| 89 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 90 |
|
| 91 |
priv->rcontext = visual_plugin_get_random_context (plugin); |
| 92 |
|
| 93 |
priv->plugwidth = 32; |
| 94 |
priv->plugheight = 32; |
| 95 |
|
| 96 |
visual_palette_allocate_colors (&priv->pal, 256); |
| 97 |
|
| 98 |
_inf_init_renderer (priv); |
| 99 |
_inf_load_random_effect(priv, &priv->current_effect); |
| 100 |
|
| 101 |
|
| 102 |
priv->color = visual_random_context_int_range (priv->rcontext, 0, NB_PALETTES - 1); |
| 103 |
_inf_change_color(priv, priv->old_color, priv->color, 256); |
| 104 |
priv->old_color = priv->color; |
| 105 |
|
| 106 |
priv->color = visual_random_context_int_range (priv->rcontext, 0, NB_PALETTES - 1); |
| 107 |
|
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
int act_infinite_cleanup (VisPluginData *plugin) |
| 112 |
{ |
| 113 |
InfinitePrivate *priv; |
| 114 |
|
| 115 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 116 |
|
| 117 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 118 |
|
| 119 |
_inf_close_renderer (priv); |
| 120 |
|
| 121 |
visual_palette_free_colors (&priv->pal); |
| 122 |
visual_mem_free (priv); |
| 123 |
|
| 124 |
return 0; |
| 125 |
} |
| 126 |
|
| 127 |
int act_infinite_requisition (VisPluginData *plugin, int *width, int *height) |
| 128 |
{ |
| 129 |
int reqw, reqh; |
| 130 |
|
| 131 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 132 |
|
| 133 |
reqw = *width; |
| 134 |
reqh = *height; |
| 135 |
|
| 136 |
while (reqw % 2 || (reqw / 2) % 2) |
| 137 |
reqw--; |
| 138 |
|
| 139 |
while (reqh % 2 || (reqh / 2) % 2) |
| 140 |
reqh--; |
| 141 |
|
| 142 |
if (reqw < 32) |
| 143 |
reqw = 32; |
| 144 |
|
| 145 |
if (reqh < 32) |
| 146 |
reqh = 32; |
| 147 |
|
| 148 |
*width = reqw; |
| 149 |
*height = reqh; |
| 150 |
|
| 151 |
return 0; |
| 152 |
} |
| 153 |
|
| 154 |
int act_infinite_dimension (VisPluginData *plugin, VisVideo *video, int width, int height) |
| 155 |
{ |
| 156 |
InfinitePrivate *priv; |
| 157 |
|
| 158 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 159 |
visual_log_return_val_if_fail (video != NULL, -1); |
| 160 |
|
| 161 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 162 |
priv->plugwidth = width; |
| 163 |
priv->plugheight = height; |
| 164 |
|
| 165 |
visual_video_set_dimension (video, width, height); |
| 166 |
|
| 167 |
_inf_close_renderer (priv); |
| 168 |
|
| 169 |
if (video->depth != VISUAL_VIDEO_DEPTH_8BIT) |
| 170 |
return -1; |
| 171 |
|
| 172 |
_inf_init_renderer (priv); |
| 173 |
|
| 174 |
return 0; |
| 175 |
} |
| 176 |
|
| 177 |
int act_infinite_events (VisPluginData *plugin, VisEventQueue *events) |
| 178 |
{ |
| 179 |
VisEvent ev; |
| 180 |
|
| 181 |
while (visual_event_queue_poll (events, &ev)) { |
| 182 |
switch (ev.type) { |
| 183 |
case VISUAL_EVENT_RESIZE: |
| 184 |
act_infinite_dimension (plugin, ev.event.resize.video, |
| 185 |
ev.event.resize.width, ev.event.resize.height); |
| 186 |
break; |
| 187 |
default: /* to avoid warnings */ |
| 188 |
break; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
return 0; |
| 193 |
} |
| 194 |
|
| 195 |
VisPalette *act_infinite_palette (VisPluginData *plugin) |
| 196 |
{ |
| 197 |
InfinitePrivate *priv; |
| 198 |
|
| 199 |
visual_log_return_val_if_fail (plugin != NULL, NULL); |
| 200 |
|
| 201 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 202 |
|
| 203 |
return &priv->pal; |
| 204 |
} |
| 205 |
|
| 206 |
int act_infinite_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) |
| 207 |
{ |
| 208 |
VisBuffer buffer; |
| 209 |
InfinitePrivate *priv; |
| 210 |
int i; |
| 211 |
|
| 212 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 213 |
visual_log_return_val_if_fail (video != NULL, -1); |
| 214 |
visual_log_return_val_if_fail (audio != NULL, -1); |
| 215 |
|
| 216 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 217 |
|
| 218 |
visual_buffer_set_data_pair (&buffer, priv->pcm_data[0], sizeof (float) * 512); |
| 219 |
visual_audio_get_sample (audio, &buffer, VISUAL_AUDIO_CHANNEL_LEFT); |
| 220 |
|
| 221 |
visual_buffer_set_data_pair (&buffer, priv->pcm_data[1], sizeof (float) * 512); |
| 222 |
visual_audio_get_sample (audio, &buffer, VISUAL_AUDIO_CHANNEL_LEFT); |
| 223 |
|
| 224 |
_inf_renderer (priv); |
| 225 |
_inf_display (priv, (uint8_t *) visual_video_get_pixels (video), video->pitch); |
| 226 |
|
| 227 |
return 0; |
| 228 |
} |
| 229 |
|