blob: 888f0cdb029ee673f72c3b03d515e197fd4922b2 [file] [log] [blame]
Jason Sams94153312010-02-12 17:24:28 -08001/*
2// block of defines matching what RS will insert at runtime.
3struct Params_s{
4 int inHeight;
5 int inWidth;
6 int outHeight;
7 int outWidth;
8 float threshold;
9};
10struct Params_s * Params;
11struct InPixel_s{
12 char a;
13 char b;
14 char g;
15 char r;
16};
17struct InPixel_s * InPixel;
18struct OutPixel_s{
19 char a;
20 char b;
21 char g;
22 char r;
23};
24struct OutPixel_s * OutPixel;
25*/
26
Romain Guyd7fa1222009-10-09 16:05:25 -070027struct color_s {
28 char b;
29 char g;
30 char r;
31 char a;
32};
33
Romain Guyd7fa1222009-10-09 16:05:25 -070034void main() {
Jason Samsec2746c2010-02-10 15:03:24 -080035 int t = uptimeMillis();
36
Romain Guyd7fa1222009-10-09 16:05:25 -070037 struct color_s *in = (struct color_s *) InPixel;
38 struct color_s *out = (struct color_s *) OutPixel;
Jason Samsec2746c2010-02-10 15:03:24 -080039
Romain Guyd7fa1222009-10-09 16:05:25 -070040 int count = Params->inWidth * Params->inHeight;
41 int i;
Jason Sams1d317d12010-02-10 16:58:16 -080042 float threshold = (Params->threshold * 255.f);
Romain Guyd7fa1222009-10-09 16:05:25 -070043
44 for (i = 0; i < count; i++) {
Jason Sams1d317d12010-02-10 16:58:16 -080045 float luminance = 0.2125f * in->r +
46 0.7154f * in->g +
47 0.0721f * in->b;
Jason Sams586f3b52010-02-10 18:07:37 -080048 if (luminance > threshold) {
49 *out = *in;
50 } else {
51 *((int *)out) = *((int *)in) & 0xff000000;
52 }
Romain Guyd7fa1222009-10-09 16:05:25 -070053
54 in++;
55 out++;
56 }
57
Jason Samsec2746c2010-02-10 15:03:24 -080058 t= uptimeMillis() - t;
59 debugI32("Filter time", t);
60
Romain Guyd7fa1222009-10-09 16:05:25 -070061 sendToClient(&count, 1, 4, 0);
62}