-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagefx.c
executable file
·170 lines (123 loc) · 5.59 KB
/
imagefx.c
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// some simple image processing demos
#include "cambadge.h"
#include "globals.h"
// states used by this application
#define s_start 0
#define s_run 1
#define s_quit 2
#define bufsize (128*96+1)
#define bufstart 8
#define linelength 129
char* imagefx(unsigned int action) {
static unsigned int state, effect, page, val1, val2;
unsigned int x, y, i, d, r, g, b,e,f;
static unsigned char explock;
switch (action) {
case act_name: return ("IMAGEFX");
case act_help: return ("Camera effects");
case act_start:
// called once when app is selected from menu
state = s_start;
effect = 0;
cam_enable(cammode_128x96_z1_mono);
cam_grabenable(camen_grab, bufstart - 1, 0);
page = 1;
val1 = val2 = 0;
return (0);
} //switch
if (action != act_poll) return (0);
if (butpress & powerbut) state = s_quit; // exit with nonzero value to indicate we want to quit
if (butpress & but1) {
effect++;
val1 = val2 = 0;
state = s_start;
}
if (butpress & but2) {
explock ^= 1;
cam_setreg(0x13, explock ? 0xe0 : 0xe7);
}
if (butpress & but4) if (led1) led1_on;
else led1_off;
switch (state) {
case s_start:
printf(cls top butcol "EXIT " whi inv "IMAGEFX" inv butcol " LIGHT" bot "Effect");
state = s_run;
for (i = 0; i != cambufsize; cambuffer[i++] = 0);
case s_run:
if (!cam_newframe) break;
printf(tabx9 taby12 butcol);
if (explock) printf(inv "ExLock" inv);
else printf("ExLock");
printf(tabx0 taby11 yel);
switch (effect) {
case 0: // update one line per frame
printf("Slowscan");
monopalette(0, 255);
plotblock(0, 11 + ypixels - val1, xpixels, 1, c_grn);
dispimage(0, 12 + ypixels - val1, xpixels, 1, (img_mono | img_revscan), cambuffer + bufstart + val1 * xpixels);
if (++val1 == ypixels - 1) val1 = 0;
break;
unsigned char* charptr;
unsigned short* shortptr;
case 1: // temporal FIR filter
printf("Ghost");
charptr = cambuffer + bufstart;
shortptr = cambuffer_s + (bufstart + bufsize) / 2; // shorts to store pixel:fraction as fixed-point to avoid rounding errors
y = 250;
for (i = 0; i != xpixels * ypixels; i++) {
x = *charptr++;
d = x * (255 - y)+((unsigned int) *shortptr * y) / 256; // mix proportion of old and new pixel
*shortptr++ = d;
}
monopalette(0, 255);
// img_skip skips over the lsbytes, displaying the MSbyte
dispimage(0, 12, xpixels, ypixels, (img_mono | img_revscan | img_skip1), cambuffer + bufsize + bufstart);
break;
case 3: // use camera capture start parameters to de-stabilise
printf("Unstabilise");
monopalette(0, 255);
xstart = 30 + randnum(-15, 15);
ystart = 30 + randnum(-15, 15);
dispimage(0, 12, xpixels, ypixels, (img_mono | img_revscan), cambuffer + bufstart);
break;
unsigned char * inptr,*outptr;
int op,np,er,z;
case 2 :
printf("Dither");//Floyd=stienberg error diffusion
for(y=0;y!=ypixels;y++) {
for(x=0;x!=xpixels;x++){
inptr=cambuffer+bufstart+x+y*xpixels;
op=*inptr;
if(op>0x80) np=0xff;else np=0;
er=op-np;
*inptr=np;
inptr++;//right
z=(int) *inptr +er*7/16;
if(z<0) z=0; else if(z>255) z=255;
*inptr=z;
inptr+=(xpixels-2); // down & left
z=(int) *inptr +er*3/16;
if(z<0) z=0; else if(z>255) z=255;
*inptr++=z;
z=(int) *inptr +er*5/16;//down
if(z<0) z=0; else if(z>255) z=255;
*inptr++=z;
z=(int) *inptr +er*1/16; //down & right
if(z<0) z=0; else if(z>255) z=255;
*inptr=z;
}//x
}///y
monopalette (0,255);
dispimage(0, 12, xpixels, ypixels, (img_mono | img_revscan), cambuffer+bufstart);
break;
default: effect = 0;
}//switch effect
cam_grabenable(camen_grab, bufstart - 1, 0); // buffer swap for new frame
break;
case s_quit:
cam_grabdisable();
return ("");
break;
}
return (0);
}