1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
//
// Game of Life .. what a waste of time
//
#include <stdlib.h>
#include <stdio.h>
#include "plugin.h"
#define BORN 1
#define DYING 2
int dead = 0;
int aroundme(_frame f, int x, int y)
{
int i=0;
if(r16(scanline16(f, y-1)[x-1])>dead) i++;
if(r16(scanline16(f, y-1)[x])>dead) i++;
if(r16(scanline16(f, y-1)[x+1])>dead) i++;
if(r16(scanline16(f, y)[x-1])>dead) i++;
if(r16(scanline16(f, y)[x+1])>dead) i++;
if(r16(scanline16(f, y+1)[x-1])>dead) i++;
if(r16(scanline16(f, y+1)[x])>dead) i++;
if(r16(scanline16(f, y+1)[x+1])>dead) i++;
return i;
}
void setstate(_frame f, byte *t, int x, int y)
{
int i = aroundme(f, x, y);
if(i<=1 || i>=4) t[y*f.width+x]=DYING;
else
if(i==3) t[y*f.width+x]=BORN;
}
void perform_effect(struct frame f, struct args a)
{
int x,y,i,r;
pixel16 *p, c;
byte *t;
if(f.pixelformat!=16) return;
t = malloc(f.width*f.height);
memset(t, 0, f.width*f.height);
for(y=2; y<f.height-3; y++)
{
p = scanline16(f, y);
for(x=2; x<f.width-3; x++)
{
if(r16(p[x])>0)
{
setstate(f, t, x-1, y-1);
setstate(f, t, x, y-1);
setstate(f, t, x+1, y-1);
setstate(f, t, x-1, y);
setstate(f, t, x, y);
setstate(f, t, x+1, y);
setstate(f, t, x-1, y+1);
setstate(f, t, x, y+1);
setstate(f, t, x+1, y+1);
}
}
}
for(y=2; y<f.height-3; y++)
{
p = scanline16(f, y);
for(x=2; x<f.width-3; x++)
{
switch(t[y*f.width+x])
{
case BORN:
c = p[x];
r = r16(c);
p[x] = rgbtocolor16(r>0 ? r : 255, g16(c), b16(c));
break;
case DYING:
c = p[+x];
p[x] = rgbtocolor16(0, g16(c), b16(c));
break;
}
}
}
free(t);
}
|