| 1 |
/* Libvisual-plugins - Standard plugins for libvisual |
| 2 |
* |
| 3 |
* Copyright (C) 2000, 2001 Remi Arquier <[email protected]> |
| 4 |
* |
| 5 |
* Authors: Remi Arquier <[email protected]> |
| 6 |
* Dennis Smit <[email protected]> |
| 7 |
* |
| 8 |
* $Id: jess.c,v 1.25 2006/01/27 20:19:14 synap Exp $ |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as |
| 12 |
* published by the Free Software Foundation; either version 2 |
| 13 |
* of the License, or (at your option) any later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with this program; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <config.h> |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <unistd.h> |
| 30 |
#include <math.h> |
| 31 |
#include <string.h> |
| 32 |
#include <gettext.h> |
| 33 |
|
| 34 |
#include "def.h" |
| 35 |
#include "struct.h" |
| 36 |
#include "distorsion.h" |
| 37 |
#include "analyser.h" |
| 38 |
#include "analyser_struct.h" |
| 39 |
#include "renderer.h" |
| 40 |
#include "pal.h" |
| 41 |
#include "draw_low_level.h" |
| 42 |
#include "jess.h" |
| 43 |
|
| 44 |
int act_jess_init (VisPluginData *plugin); |
| 45 |
int act_jess_cleanup (VisPluginData *plugin); |
| 46 |
int act_jess_requisition (VisPluginData *plugin, int *width, int *height); |
| 47 |
int act_jess_dimension (VisPluginData *plugin, VisVideo *video, int width, int height); |
| 48 |
int act_jess_events (VisPluginData *plugin, VisEventQueue *events); |
| 49 |
VisPalette *act_jess_palette (VisPluginData *plugin); |
| 50 |
int act_jess_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio); |
| 51 |
|
| 52 |
void jess_init (JessPrivate *priv); |
| 53 |
|
| 54 |
VISUAL_PLUGIN_API_VERSION_VALIDATOR |
| 55 |
|
| 56 |
const VisPluginInfo *get_plugin_info (int *count) |
| 57 |
{ |
| 58 |
static VisActorPlugin actor[] = {{ |
| 59 |
.requisition = act_jess_requisition, |
| 60 |
.palette = act_jess_palette, |
| 61 |
.render = act_jess_render, |
| 62 |
.vidoptions.depth = |
| 63 |
VISUAL_VIDEO_DEPTH_8BIT | |
| 64 |
VISUAL_VIDEO_DEPTH_32BIT |
| 65 |
}}; |
| 66 |
|
| 67 |
static VisPluginInfo info[] = {{ |
| 68 |
.type = VISUAL_PLUGIN_TYPE_ACTOR, |
| 69 |
|
| 70 |
.plugname = "jess", |
| 71 |
.name = "jess plugin", |
| 72 |
.author = N_("Original by: Remi Arquier <[email protected]>, Port by: Dennis Smit <[email protected]>"), |
| 73 |
.version = "0.1", |
| 74 |
.about = N_("Jess visual plugin"), |
| 75 |
.help = N_("This is the libvisual plugin for the jess visual"), |
| 76 |
.license = VISUAL_PLUGIN_LICENSE_GPL, |
| 77 |
|
| 78 |
.init = act_jess_init, |
| 79 |
.cleanup = act_jess_cleanup, |
| 80 |
.events = act_jess_events, |
| 81 |
|
| 82 |
.plugin = VISUAL_OBJECT (&actor[0]) |
| 83 |
}}; |
| 84 |
|
| 85 |
*count = sizeof (info) / sizeof (*info); |
| 86 |
|
| 87 |
return info; |
| 88 |
} |
| 89 |
|
| 90 |
int act_jess_init (VisPluginData *plugin) |
| 91 |
{ |
| 92 |
JessPrivate *priv; |
| 93 |
|
| 94 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 95 |
|
| 96 |
#if ENABLE_NLS |
| 97 |
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); |
| 98 |
#endif |
| 99 |
|
| 100 |
priv = visual_mem_new0 (JessPrivate, 1); |
| 101 |
|
| 102 |
if (priv == NULL) { |
| 103 |
visual_log (VISUAL_LOG_CRITICAL, |
| 104 |
_("The given plugin doesn't have private info")); |
| 105 |
return -1; |
| 106 |
} |
| 107 |
|
| 108 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 109 |
|
| 110 |
priv->rcontext = visual_plugin_get_random_context (plugin); |
| 111 |
|
| 112 |
priv->conteur.burn_mode = 4; |
| 113 |
priv->conteur.draw_mode = 4; |
| 114 |
priv->conteur.blur_mode = 3; |
| 115 |
priv->video = 8; |
| 116 |
priv->conteur.term_display = OUI; |
| 117 |
priv->resx = 320; |
| 118 |
priv->resy = 200; |
| 119 |
|
| 120 |
priv->conteur.courbe = 0; |
| 121 |
priv->conteur.angle = 0; |
| 122 |
priv->conteur.angle2 = 0; |
| 123 |
priv->conteur.k1 = 0; |
| 124 |
priv->conteur.k2 = 0; |
| 125 |
priv->conteur.k3 = 10000; |
| 126 |
|
| 127 |
priv->conteur.fps = 40; |
| 128 |
|
| 129 |
priv->conteur.mix_reprise = 1000; |
| 130 |
priv->conteur.last_flash = 1000; |
| 131 |
priv->conteur.burn_mode = 2; |
| 132 |
priv->conteur.draw_mode = 5; |
| 133 |
priv->conteur.v_angle2 = 1; |
| 134 |
priv->conteur.general = 0; |
| 135 |
priv->conteur.blur_mode = 3; |
| 136 |
priv->conteur.freeze = 0; |
| 137 |
priv->conteur.freeze_mode = 0; |
| 138 |
|
| 139 |
priv->lys.E_moyen = 0; |
| 140 |
priv->lys.dEdt_moyen = 0; |
| 141 |
|
| 142 |
visual_palette_allocate_colors (&priv->jess_pal, 256); |
| 143 |
|
| 144 |
visual_buffer_init (&priv->pcm_data1, priv->pcm_data[0], 512 * sizeof (float), NULL); |
| 145 |
visual_buffer_init (&priv->pcm_data2, priv->pcm_data[1], 512 * sizeof (float), NULL); |
| 146 |
|
| 147 |
start_ticks (priv); |
| 148 |
|
| 149 |
return 0; |
| 150 |
} |
| 151 |
|
| 152 |
int act_jess_cleanup (VisPluginData *plugin) |
| 153 |
{ |
| 154 |
JessPrivate *priv; |
| 155 |
int i; |
| 156 |
|
| 157 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 158 |
|
| 159 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 160 |
if (priv == NULL) { |
| 161 |
visual_log (VISUAL_LOG_CRITICAL, |
| 162 |
_("The given plugin doesn't have private info")); |
| 163 |
return -1; |
| 164 |
} |
| 165 |
|
| 166 |
if (priv->big_ball != NULL) |
| 167 |
visual_mem_free (priv->big_ball); |
| 168 |
|
| 169 |
for (i = 0; i < BIG_BALL_SIZE; i++) |
| 170 |
{ |
| 171 |
if (priv->big_ball_scale[i] != NULL) |
| 172 |
visual_mem_free (priv->big_ball_scale[i]); |
| 173 |
} |
| 174 |
|
| 175 |
if (priv->table1 != NULL) |
| 176 |
visual_mem_free (priv->table1); |
| 177 |
|
| 178 |
if (priv->table2 != NULL) |
| 179 |
visual_mem_free (priv->table2); |
| 180 |
|
| 181 |
if (priv->table3 != NULL) |
| 182 |
visual_mem_free (priv->table3); |
| 183 |
|
| 184 |
if (priv->table4 != NULL) |
| 185 |
visual_mem_free (priv->table4); |
| 186 |
|
| 187 |
if (priv->buffer != NULL) |
| 188 |
visual_mem_free (priv->buffer); |
| 189 |
|
| 190 |
visual_palette_free_colors (&priv->jess_pal); |
| 191 |
|
| 192 |
visual_mem_free (priv); |
| 193 |
|
| 194 |
return 0; |
| 195 |
} |
| 196 |
|
| 197 |
int act_jess_requisition (VisPluginData *plugin, int *width, int *height) |
| 198 |
{ |
| 199 |
int reqw, reqh; |
| 200 |
|
| 201 |
visual_log_return_val_if_fail (width != NULL, -1); |
| 202 |
visual_log_return_val_if_fail (height != NULL, -1); |
| 203 |
|
| 204 |
reqw = *width; |
| 205 |
reqh = *height; |
| 206 |
|
| 207 |
while (reqw % 2 || (reqw / 2) % 2) |
| 208 |
reqw--; |
| 209 |
|
| 210 |
while (reqh % 2 || (reqh / 2) % 2) |
| 211 |
reqh--; |
| 212 |
|
| 213 |
if (reqw < 32) |
| 214 |
reqw = 32; |
| 215 |
|
| 216 |
if (reqh < 32) |
| 217 |
reqh = 32; |
| 218 |
|
| 219 |
*width = reqw; |
| 220 |
*height = reqh; |
| 221 |
|
| 222 |
return 0; |
| 223 |
} |
| 224 |
|
| 225 |
int act_jess_dimension (VisPluginData *plugin, VisVideo *video, int width, int height) |
| 226 |
{ |
| 227 |
JessPrivate *priv; |
| 228 |
|
| 229 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 230 |
|
| 231 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 232 |
if (priv == NULL) { |
| 233 |
visual_log (VISUAL_LOG_CRITICAL, |
| 234 |
_("The given plugin doesn't have private info")); |
| 235 |
return -1; |
| 236 |
} |
| 237 |
|
| 238 |
priv->resx = width; |
| 239 |
priv->resy = height; |
| 240 |
|
| 241 |
visual_video_set_dimension (video, width, height); |
| 242 |
|
| 243 |
if (priv->table1 != NULL) |
| 244 |
visual_mem_free (priv->table1); |
| 245 |
|
| 246 |
if (priv->table2 != NULL) |
| 247 |
visual_mem_free (priv->table2); |
| 248 |
|
| 249 |
if (priv->table3 != NULL) |
| 250 |
visual_mem_free (priv->table3); |
| 251 |
|
| 252 |
if (priv->table4 != NULL) |
| 253 |
visual_mem_free (priv->table4); |
| 254 |
|
| 255 |
if (priv->buffer != NULL) |
| 256 |
visual_mem_free (priv->buffer); |
| 257 |
|
| 258 |
priv->pitch = video->pitch; |
| 259 |
priv->video = visual_video_depth_value_from_enum (video->depth); |
| 260 |
priv->bpp = video->bpp; |
| 261 |
|
| 262 |
ball_init (priv); |
| 263 |
jess_init (priv); |
| 264 |
|
| 265 |
return 0; |
| 266 |
} |
| 267 |
|
| 268 |
int act_jess_events (VisPluginData *plugin, VisEventQueue *events) |
| 269 |
{ |
| 270 |
VisEvent ev; |
| 271 |
|
| 272 |
while (visual_event_queue_poll (events, &ev)) { |
| 273 |
switch (ev.type) { |
| 274 |
case VISUAL_EVENT_RESIZE: |
| 275 |
act_jess_dimension (plugin, ev.event.resize.video, |
| 276 |
ev.event.resize.width, ev.event.resize.height); |
| 277 |
break; |
| 278 |
default: /* to avoid warnings */ |
| 279 |
break; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
return 0; |
| 284 |
} |
| 285 |
|
| 286 |
VisPalette *act_jess_palette (VisPluginData *plugin) |
| 287 |
{ |
| 288 |
JessPrivate *priv; |
| 289 |
|
| 290 |
visual_log_return_val_if_fail (plugin != NULL, NULL); |
| 291 |
|
| 292 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 293 |
if (priv == NULL) { |
| 294 |
visual_log (VISUAL_LOG_CRITICAL, |
| 295 |
_("The given plugin doesn't have private info")); |
| 296 |
return NULL; |
| 297 |
} |
| 298 |
|
| 299 |
return &priv->jess_pal; |
| 300 |
} |
| 301 |
|
| 302 |
int act_jess_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) |
| 303 |
{ |
| 304 |
JessPrivate *priv; |
| 305 |
VisBuffer fbuf[2]; |
| 306 |
float freq[2][256]; |
| 307 |
short freqdata[2][256]; |
| 308 |
int i; |
| 309 |
|
| 310 |
visual_log_return_val_if_fail (plugin != NULL, -1); |
| 311 |
visual_log_return_val_if_fail (audio != NULL, -1); |
| 312 |
visual_log_return_val_if_fail (video != NULL, -1); |
| 313 |
|
| 314 |
priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 315 |
|
| 316 |
if (priv == NULL) { |
| 317 |
visual_log (VISUAL_LOG_CRITICAL, |
| 318 |
_("The given plugin doesn't have priv info")); |
| 319 |
return -1; |
| 320 |
} |
| 321 |
|
| 322 |
visual_audio_get_sample (audio, &priv->pcm_data1, VISUAL_AUDIO_CHANNEL_LEFT); |
| 323 |
visual_audio_get_sample (audio, &priv->pcm_data2, VISUAL_AUDIO_CHANNEL_RIGHT); |
| 324 |
|
| 325 |
visual_buffer_set_data_pair (&fbuf[0], freq[0], sizeof (freq[0])); |
| 326 |
visual_buffer_set_data_pair (&fbuf[1], freq[1], sizeof (freq[1])); |
| 327 |
|
| 328 |
visual_audio_get_spectrum_for_sample (&fbuf[0], &priv->pcm_data1, FALSE); |
| 329 |
visual_audio_get_spectrum_for_sample (&fbuf[1], &priv->pcm_data2, FALSE); |
| 330 |
|
| 331 |
for (i = 0;i < 256; i++) { |
| 332 |
freqdata[0][i] = freq[0][i] * 32768; |
| 333 |
freqdata[1][i] = freq[1][i] * 32768; |
| 334 |
} |
| 335 |
|
| 336 |
priv->lys.conteur[ZERO]++; |
| 337 |
priv->lys.conteur[ONE]++; |
| 338 |
|
| 339 |
priv->lys.dt = time_last(priv, TWO, OUI); |
| 340 |
|
| 341 |
spectre_moyen(priv, freqdata); |
| 342 |
C_E_moyen(priv, freqdata); |
| 343 |
C_dEdt_moyen(priv); |
| 344 |
C_dEdt(priv); |
| 345 |
|
| 346 |
priv->pixel = ((uint8_t *) visual_video_get_pixels (video)); |
| 347 |
|
| 348 |
renderer (priv); |
| 349 |
|
| 350 |
return 0; |
| 351 |
} |
| 352 |
|
| 353 |
void jess_init (JessPrivate *priv) |
| 354 |
{ |
| 355 |
visual_log_return_if_fail (priv != NULL); |
| 356 |
|
| 357 |
priv->xres2 = priv->resx / 2; |
| 358 |
priv->yres2 = priv->resy / 2; |
| 359 |
|
| 360 |
priv->conteur.fullscreen = 0; |
| 361 |
priv->conteur.blur_mode = 1; |
| 362 |
|
| 363 |
priv->table1 = (uint32_t *) visual_mem_malloc0 (priv->resx * priv->resy * sizeof (int)); |
| 364 |
priv->table2 = (uint32_t *) visual_mem_malloc0 (priv->resx * priv->resy * sizeof (int)); |
| 365 |
priv->table3 = (uint32_t *) visual_mem_malloc0 (priv->resx * priv->resy * sizeof (int)); |
| 366 |
priv->table4 = (uint32_t *) visual_mem_malloc0 (priv->resx * priv->resy * sizeof (int)); |
| 367 |
|
| 368 |
if (priv->video == 8) |
| 369 |
priv->buffer = (uint8_t *) visual_mem_malloc0 (priv->resx * priv->resy); |
| 370 |
else |
| 371 |
priv->buffer = (uint8_t *) visual_mem_malloc0 (priv->resx * priv->resy * 4); |
| 372 |
|
| 373 |
create_tables(priv); |
| 374 |
} |
| 375 |
|