comparison src/paranormal/general.c @ 149:fd9c0a5871ac trunk

[svn] - new and IMPROVED paranormal visualization studio
author nenolod
date Mon, 30 Oct 2006 23:02:33 -0800
parents
children adf9f4b26039
comparison
equal deleted inserted replaced
148:9d9fc9e1de48 149:fd9c0a5871ac
1 /* FIXME: what to name this file? */
2
3 #ifdef HAVE_CONFIG_H
4 # include <config.h>
5 #endif
6
7 #include "paranormal.h"
8 #include "actuators.h"
9 #include "pn_utils.h"
10
11 /* **************** general_fade **************** */
12 static struct pn_actuator_option_desc general_fade_opts[] =
13 {
14 { "amount", "The amount by which the color index of each "
15 "pixel should be decreased by each frame (MAX 255)",
16 OPT_TYPE_INT, { ival: 3 } },
17 { 0 }
18 };
19
20 static void
21 general_fade_exec (const struct pn_actuator_option *opts,
22 gpointer data)
23 {
24 int amt = opts[0].val.ival > 255 || opts[0].val.ival < 0 ?
25 3 : opts[0].val.ival;
26 int i, j;
27
28 for (j=0; j<pn_image_data->height; j++)
29 for (i=0; i<pn_image_data->width; i++)
30 pn_image_data->surface[0][PN_IMG_INDEX (i, j)] =
31 CAPLO (pn_image_data->surface[0][PN_IMG_INDEX (i, j)]
32 - amt, 0);
33 }
34
35 struct pn_actuator_desc builtin_general_fade =
36 {
37 "general_fade", "Decreases the color index of each pixel",
38 0, general_fade_opts,
39 NULL, NULL, general_fade_exec
40 };
41
42 /* **************** general_blur **************** */
43 /* FIXME: add a variable radius */
44 /* FIXME: SPEEEED */
45 static void
46 general_blur_exec (const struct pn_actuator_option *opts,
47 gpointer data)
48 {
49 int i,j;
50 register guchar *srcptr = pn_image_data->surface[0];
51 register guchar *destptr = pn_image_data->surface[1];
52 register int sum;
53
54 for (j=0; j<pn_image_data->height; j++)
55 for (i=0; i<pn_image_data->width; i++)
56 {
57 sum = *(srcptr)<<2;
58
59 /* top */
60 if (j > 0)
61 {
62 sum += *(srcptr-pn_image_data->width)<<1;
63 if (i > 0)
64 sum += *(srcptr-pn_image_data->width-1);
65 if (i < pn_image_data->width-1)
66 sum += *(srcptr-pn_image_data->width+1);
67 }
68 /* bottom */
69 if (j < pn_image_data->height-1)
70 {
71 sum += *(srcptr+pn_image_data->width)<<1;
72 if (i > 0)
73 sum += *(srcptr+pn_image_data->width-1);
74 if (i < pn_image_data->width-1)
75 sum += *(srcptr+pn_image_data->width+1);
76 }
77 /* left */
78 if (i > 0)
79 sum += *(srcptr-1)<<1;
80 /* right */
81 if (i < pn_image_data->width-1)
82 sum += *(srcptr+1)<<1;
83
84 *destptr++ = (guchar)(sum >> 4);
85 srcptr++;
86 }
87
88 pn_swap_surfaces ();
89 }
90
91 struct pn_actuator_desc builtin_general_blur =
92 {
93 "general_blur", "A simple 1 pixel radius blur",
94 0, NULL,
95 NULL, NULL, general_blur_exec
96 };