~ubuntu-branches/debian/sid/audacious-plugins/sid

« back to all changes in this revision

Viewing changes to src/paranormal-ng/general.c

  • Committer: Bazaar Package Importer
  • Author(s): Bilal Akhtar
  • Date: 2011-04-10 18:56:21 UTC
  • mfrom: (1.1.14 upstream) (2.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110410185621-7eg1k5a7v3f4aqrn
Tags: 2.4.4-1
* New upstream release.
  - Fix FTBFS with GCC 4.5 (Closes: #621989)
* Upload to unstable.
* debian/control:
  - Update versioned dependencies according to upstream changes.
  - Bump Standards-Version to 3.9.2 (no changes needed).
  - Since the package will be building against the new FFMpeg libs,
    fix the problem of depending on old uninstallable libav*
    packages (Closes: #617603)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * paranormal: iterated pipeline-driven visualization plugin
3
 
 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org>
4
 
 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com>
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; under version 2 of the License.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 */
19
 
 
20
 
/* FIXME: what to name this file? */
21
 
 
22
 
#include <config.h>
23
 
 
24
 
#include "paranormal.h"
25
 
#include "actuators.h"
26
 
#include "pn_utils.h"
27
 
#include "libcalc/calc.h"
28
 
 
29
 
/* **************** general_fade **************** */
30
 
static struct pn_actuator_option_desc general_fade_opts[] =
31
 
{
32
 
  { "amount", "The amount by which the color index of each "
33
 
    "pixel should be decreased by each frame (MAX 255)",
34
 
    OPT_TYPE_INT, { ival: 3 } },
35
 
  { NULL }
36
 
};
37
 
 
38
 
static void
39
 
general_fade_exec (const struct pn_actuator_option *opts,
40
 
           gpointer data)
41
 
{
42
 
  int amt = opts[0].val.ival > 255 || opts[0].val.ival < 0 ? 3 : opts[0].val.ival;
43
 
  int i, j;
44
 
 
45
 
  for (j=0; j<pn_image_data->height; j++)
46
 
    for (i=0; i<pn_image_data->width; i++)
47
 
      pn_image_data->surface[0][PN_IMG_INDEX (i, j)] =
48
 
        CAPLO (pn_image_data->surface[0][PN_IMG_INDEX (i, j)]
49
 
               - amt, 0);
50
 
}
51
 
 
52
 
struct pn_actuator_desc builtin_general_fade =
53
 
{
54
 
  "general_fade", "Fade-out", "Decreases the color index of each pixel",
55
 
  0, general_fade_opts,
56
 
  NULL, NULL, general_fade_exec
57
 
};
58
 
 
59
 
/* thanks to feelgood_ICBM @ freenode for this */
60
 
#define glError() { GLenum err; for(err = glGetError(); err; err = glGetError()) { fprintf(stderr, "glError: %s caught at %s:%u\n", \
61
 
        (GLchar*)gluErrorString(err), __FILE__, __LINE__); } }
62
 
 
63
 
/* **************** general_blur **************** */
64
 
static void
65
 
general_blur_exec (const struct pn_actuator_option *opts,
66
 
           gpointer data)
67
 
{
68
 
  GLuint texture_id;
69
 
 
70
 
  glGenTextures(1, &texture_id);
71
 
  glBindTexture(GL_TEXTURE_2D, texture_id);
72
 
 
73
 
  glError();
74
 
 
75
 
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_BYTE, NULL);
76
 
 
77
 
  glError();
78
 
 
79
 
  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, -1, -1, 1, 1, 0);
80
 
 
81
 
  glError();
82
 
 
83
 
  glBindTexture(GL_TEXTURE_2D, 0);
84
 
 
85
 
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
86
 
 
87
 
  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
88
 
  glBindTexture(GL_TEXTURE_2D, texture_id);
89
 
 
90
 
  glError();
91
 
 
92
 
  glBegin(GL_QUADS);
93
 
 
94
 
  glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
95
 
  glTexCoord2f(0, 1);
96
 
  glVertex2i(-1, -1);
97
 
  glVertex2i(-1, 1);
98
 
  glVertex2i(1, 1);
99
 
  glVertex2i(1, -1);
100
 
 
101
 
  glEnd();
102
 
  glBindTexture(GL_TEXTURE_2D, 0);
103
 
 
104
 
  glError();
105
 
 
106
 
  glDeleteTextures(1, &texture_id);
107
 
 
108
 
  glFlush();
109
 
 
110
 
  glError();
111
 
}
112
 
 
113
 
struct pn_actuator_desc builtin_general_blur = 
114
 
{
115
 
  "general_blur", "Blur", "A simple radial blur",
116
 
  0, NULL,
117
 
  NULL, NULL, general_blur_exec
118
 
};
119
 
 
120
 
/* **************** general_mosaic **************** */
121
 
/* FIXME: add a variable radius */
122
 
/* FIXME: SPEEEED */
123
 
static struct pn_actuator_option_desc general_mosaic_opts[] =
124
 
{
125
 
  { "radius", "The pixel radius that should be used for the effect.",
126
 
    OPT_TYPE_INT, { ival: 6 } },
127
 
  { NULL }
128
 
};
129
 
 
130
 
static void
131
 
general_mosaic_exec (const struct pn_actuator_option *opts,
132
 
           gpointer data)
133
 
{
134
 
  int i,j;
135
 
  register guchar *srcptr = pn_image_data->surface[0];
136
 
  register guchar *destptr = pn_image_data->surface[1];
137
 
  register int sum;
138
 
  int radius = opts[0].val.ival > 255 || opts[0].val.ival < 0 ? 6 : opts[0].val.ival;
139
 
 
140
 
  for (j=0; j<pn_image_data->height; j += radius)
141
 
    for (i=0; i<pn_image_data->width; i += radius)
142
 
      {
143
 
        int ii = 0, jj = 0;
144
 
        guchar bval = 0;
145
 
 
146
 
        /* find the brightest colour */
147
 
        for (jj = 0; jj < radius && (j + jj < pn_image_data->height); jj++)
148
 
          for (ii = 0; ii < radius && (i + ii < pn_image_data->width); ii++)
149
 
            {
150
 
               guchar val = srcptr[PN_IMG_INDEX(i + ii,  j + jj)];
151
 
 
152
 
               if (val > bval)
153
 
                 bval = val;
154
 
            }
155
 
 
156
 
        for (jj = 0; jj < radius && (j + jj < pn_image_data->height); jj++)
157
 
          for (ii = 0; ii < radius && (i + ii < pn_image_data->width); ii++)
158
 
            {
159
 
               destptr[PN_IMG_INDEX(i + ii, j + jj)] = bval;
160
 
            }
161
 
      }
162
 
 
163
 
  pn_swap_surfaces ();
164
 
}
165
 
 
166
 
struct pn_actuator_desc builtin_general_mosaic = 
167
 
{
168
 
  "general_mosaic", "Mosaic", "A simple mosaic effect.",
169
 
  0, general_mosaic_opts,
170
 
  NULL, NULL, general_mosaic_exec
171
 
};
172
 
 
173
 
/* **************** general_clear **************** */
174
 
static void
175
 
general_clear_exec (const struct pn_actuator_option *opts,
176
 
           gpointer data)
177
 
{
178
 
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
179
 
}
180
 
 
181
 
struct pn_actuator_desc builtin_general_clear =
182
 
{
183
 
  "general_clear", "Clear Surface", "Clears the surface.",
184
 
  0, NULL,
185
 
  NULL, NULL, general_clear_exec
186
 
};
187
 
 
188
 
/* **************** general_setalpha **************** */
189
 
static struct pn_actuator_option_desc general_setalpha_opts[] =
190
 
{
191
 
  { "blend_colour", "The colour which should be used for blending.",
192
 
    OPT_TYPE_COLOR, { cval: {255, 255, 255} } },
193
 
  { "alpha", "The alpha value.",
194
 
    OPT_TYPE_COLOR_INDEX, { ival: 128 } },
195
 
  { NULL }
196
 
};
197
 
 
198
 
static void
199
 
general_setalpha_exec (const struct pn_actuator_option *opts,
200
 
           gpointer data)
201
 
{
202
 
  GLubyte colour[] = { opts[0].val.cval.r, opts[0].val.cval.g, opts[0].val.cval.b,
203
 
                       opts[1].val.ival };
204
 
 
205
 
  glColor4ubv(colour);
206
 
  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
207
 
}
208
 
 
209
 
struct pn_actuator_desc builtin_general_setalpha =
210
 
{
211
 
  "general_setalpha", "Change Blend Setting", "Changes the blending setting (alpha transparency mask).",
212
 
  0, general_setalpha_opts,
213
 
  NULL, NULL, general_setalpha_exec
214
 
};
215
 
 
216
 
/* **************** general_noop **************** */
217
 
static void
218
 
general_noop_exec (const struct pn_actuator_option *opts,
219
 
           gpointer data)
220
 
{
221
 
  return;
222
 
}
223
 
 
224
 
struct pn_actuator_desc builtin_general_noop =
225
 
{
226
 
  "general_noop", "Do Nothing", "Does absolutely nothing.",
227
 
  0, NULL,
228
 
  NULL, NULL, general_noop_exec
229
 
};
230
 
 
231
 
/* **************** general_invert **************** */
232
 
static void
233
 
general_invert_exec (const struct pn_actuator_option *opts,
234
 
           gpointer data)
235
 
{
236
 
  int i, j;
237
 
 
238
 
  for (j=0; j < pn_image_data->height; j++)
239
 
    for (i=0; i < pn_image_data->width; i++)
240
 
      pn_image_data->surface[0][PN_IMG_INDEX (i, j)] =
241
 
        255 - pn_image_data->surface[0][PN_IMG_INDEX (i, j)];
242
 
}
243
 
 
244
 
struct pn_actuator_desc builtin_general_invert =
245
 
{
246
 
  "general_invert", "Value Invert", "Performs a value invert.",
247
 
  0, NULL,
248
 
  NULL, NULL, general_invert_exec
249
 
};
250
 
 
251
 
/* **************** general_replace **************** */
252
 
static struct pn_actuator_option_desc general_replace_opts[] =
253
 
{
254
 
  { "start", "The beginning colour value that should be replaced by the value of out.",
255
 
    OPT_TYPE_INT, { ival: 250 } },
256
 
  { "end", "The ending colour value that should be replaced by the value of out.",
257
 
    OPT_TYPE_INT, { ival: 255 } },
258
 
  { "out", "The colour value that in is replaced with.",
259
 
    OPT_TYPE_INT, { ival: 0 } },
260
 
  { NULL }
261
 
};
262
 
 
263
 
static void
264
 
general_replace_exec (const struct pn_actuator_option *opts,
265
 
           gpointer data)
266
 
{
267
 
  register int i, j;
268
 
  register guchar val;
269
 
  guchar begin = opts[0].val.ival > 255 || opts[0].val.ival < 0 ? 250 : opts[0].val.ival;
270
 
  guchar end = opts[1].val.ival > 255 || opts[1].val.ival < 0 ? 255 : opts[1].val.ival;
271
 
  guchar out = opts[2].val.ival > 255 || opts[2].val.ival < 0 ? 0 : opts[2].val.ival;
272
 
 
273
 
  for (j=0; j < pn_image_data->height; j++)
274
 
    for (i=0; i < pn_image_data->width; i++)
275
 
      {
276
 
        val = pn_image_data->surface[0][PN_IMG_INDEX (i, j)];
277
 
        if (val >= begin && val <= end)
278
 
          pn_image_data->surface[0][PN_IMG_INDEX (i, j)] = out;
279
 
      }
280
 
}
281
 
 
282
 
struct pn_actuator_desc builtin_general_replace =
283
 
{
284
 
  "general_replace", "Value Replace", "Performs a value replace on a range of values.",
285
 
  0, general_replace_opts,
286
 
  NULL, NULL, general_replace_exec
287
 
};
288
 
 
289
 
/* **************** general_swap **************** */
290
 
static void
291
 
general_swap_exec (const struct pn_actuator_option *opts,
292
 
           gpointer data)
293
 
{
294
 
  pn_swap_surfaces ();
295
 
}
296
 
 
297
 
struct pn_actuator_desc builtin_general_swap =
298
 
{
299
 
  "general_swap", "Swap Surface", "Swaps the surface.",
300
 
  0, NULL,
301
 
  NULL, NULL, general_swap_exec
302
 
};
303
 
 
304
 
/* **************** general_copy **************** */
305
 
static void
306
 
general_copy_exec (const struct pn_actuator_option *opts,
307
 
           gpointer data)
308
 
{
309
 
  memcpy(pn_image_data->surface[1], pn_image_data->surface[0], 
310
 
         (pn_image_data->width * pn_image_data->height));
311
 
}
312
 
 
313
 
struct pn_actuator_desc builtin_general_copy =
314
 
{
315
 
  "general_copy", "Copy Surface", "Copies the surface to the other surface.",
316
 
  0, NULL,
317
 
  NULL, NULL, general_copy_exec
318
 
};
319
 
 
320
 
/* **************** general_flip **************** */
321
 
static struct pn_actuator_option_desc general_flip_opts[] =
322
 
{
323
 
  { "direction", "Negative is horizontal, positive is vertical.",
324
 
    OPT_TYPE_INT, { ival: -1 } },
325
 
  { NULL }
326
 
};
327
 
 
328
 
static void
329
 
general_flip_exec (const struct pn_actuator_option *opts,
330
 
           gpointer data)
331
 
{
332
 
  gint x, y;
333
 
 
334
 
  if (opts[0].val.ival < 0)
335
 
    {
336
 
      for (y = 0; y < pn_image_data->height; y++)
337
 
        for (x = 0; x < pn_image_data->width; x++)
338
 
          {
339
 
             pn_image_data->surface[1][PN_IMG_INDEX(pn_image_data->width - x, y)] = 
340
 
               pn_image_data->surface[0][PN_IMG_INDEX(x, y)];
341
 
          }
342
 
    }
343
 
  else
344
 
    {
345
 
      for (y = 0; y < pn_image_data->height; y++)
346
 
        for (x = 0; x < pn_image_data->width; x++)
347
 
          {
348
 
             pn_image_data->surface[1][PN_IMG_INDEX(x, pn_image_data->height - y)] = 
349
 
               pn_image_data->surface[0][PN_IMG_INDEX(x, y)];
350
 
          }
351
 
    }
352
 
 
353
 
    pn_swap_surfaces ();
354
 
}
355
 
 
356
 
struct pn_actuator_desc builtin_general_flip =
357
 
{
358
 
  "general_flip", "Flip Surface", "Flips the surface.",
359
 
  0, general_flip_opts,
360
 
  NULL, NULL, general_flip_exec
361
 
};
362
 
 
363
 
/* ***************** general_evaluate ***************** */
364
 
 
365
 
static struct pn_actuator_option_desc general_evaluate_opts[] =
366
 
{
367
 
  { "init_script", "Script to run on start.", OPT_TYPE_STRING, {sval: "global_reg0 = 27;"} },
368
 
  { "frame_script", "Script to run.", OPT_TYPE_STRING, {sval: "global_reg0 = global_reg0 + 1;"} },
369
 
  { NULL }
370
 
};
371
 
 
372
 
struct pn_evaluate_ctx
373
 
{
374
 
  expression_t *expr_on_init, *expr_on_frame;
375
 
  symbol_dict_t *dict;
376
 
  gboolean reset;
377
 
};
378
 
 
379
 
static void
380
 
general_evaluate_init(gpointer *data)
381
 
{
382
 
  *data = g_new0(struct pn_evaluate_ctx, 1);
383
 
 
384
 
  ((struct pn_evaluate_ctx *)*data)->reset = TRUE;
385
 
}
386
 
 
387
 
static void
388
 
general_evaluate_cleanup(gpointer op_data)
389
 
{
390
 
  struct pn_evaluate_ctx *data = (struct pn_evaluate_ctx *) op_data;
391
 
 
392
 
  g_return_if_fail(data != NULL);
393
 
 
394
 
  if (data->expr_on_init)
395
 
    expr_free(data->expr_on_init);
396
 
 
397
 
  if (data->expr_on_frame)
398
 
    expr_free(data->expr_on_frame);
399
 
 
400
 
  if (data->dict)
401
 
    dict_free(data->dict);
402
 
 
403
 
  if (data)
404
 
    g_free(data);
405
 
}
406
 
 
407
 
static void
408
 
general_evaluate_exec(const struct pn_actuator_option *opts,
409
 
                      gpointer op_data)
410
 
{
411
 
  struct pn_evaluate_ctx *data = (struct pn_evaluate_ctx *) op_data;
412
 
 
413
 
  if (data->reset)
414
 
    {
415
 
       if (data->dict)
416
 
         dict_free(data->dict);
417
 
 
418
 
       data->dict = dict_new();
419
 
 
420
 
       if (opts[0].val.sval != NULL);
421
 
         data->expr_on_init = expr_compile_string(opts[0].val.sval, data->dict);
422
 
 
423
 
       if (opts[1].val.sval != NULL);
424
 
         data->expr_on_frame = expr_compile_string(opts[1].val.sval, data->dict);
425
 
 
426
 
       if (data->expr_on_init != NULL)
427
 
         expr_execute(data->expr_on_init, data->dict);
428
 
 
429
 
       data->reset = FALSE;
430
 
    }
431
 
 
432
 
  if (data->expr_on_frame != NULL)
433
 
    expr_execute(data->expr_on_frame, data->dict);
434
 
}
435
 
 
436
 
struct pn_actuator_desc builtin_general_evaluate =
437
 
{
438
 
  "general_evaluate", "Evalulate VM Code",
439
 
  "Evaluates arbitrary VM code. Does not draw anything.",
440
 
  0, general_evaluate_opts,
441
 
  general_evaluate_init, general_evaluate_cleanup, general_evaluate_exec
442
 
};
443