Jason Sams | 9415331 | 2010-02-12 17:24:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | // block of defines matching what RS will insert at runtime. |
| 3 | struct Params_s{ |
| 4 | int inHeight; |
| 5 | int inWidth; |
| 6 | int outHeight; |
| 7 | int outWidth; |
| 8 | float threshold; |
| 9 | }; |
| 10 | struct Params_s * Params; |
| 11 | struct InPixel_s{ |
| 12 | char a; |
| 13 | char b; |
| 14 | char g; |
| 15 | char r; |
| 16 | }; |
| 17 | struct InPixel_s * InPixel; |
| 18 | struct OutPixel_s{ |
| 19 | char a; |
| 20 | char b; |
| 21 | char g; |
| 22 | char r; |
| 23 | }; |
| 24 | struct OutPixel_s * OutPixel; |
| 25 | */ |
| 26 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 27 | struct color_s { |
| 28 | char b; |
| 29 | char g; |
| 30 | char r; |
| 31 | char a; |
| 32 | }; |
| 33 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 34 | void main() { |
Jason Sams | ec2746c | 2010-02-10 15:03:24 -0800 | [diff] [blame] | 35 | int t = uptimeMillis(); |
| 36 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 37 | struct color_s *in = (struct color_s *) InPixel; |
| 38 | struct color_s *out = (struct color_s *) OutPixel; |
Jason Sams | ec2746c | 2010-02-10 15:03:24 -0800 | [diff] [blame] | 39 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 40 | int count = Params->inWidth * Params->inHeight; |
| 41 | int i; |
Jason Sams | 1d317d1 | 2010-02-10 16:58:16 -0800 | [diff] [blame] | 42 | float threshold = (Params->threshold * 255.f); |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 43 | |
| 44 | for (i = 0; i < count; i++) { |
Jason Sams | 1d317d1 | 2010-02-10 16:58:16 -0800 | [diff] [blame] | 45 | float luminance = 0.2125f * in->r + |
| 46 | 0.7154f * in->g + |
| 47 | 0.0721f * in->b; |
Jason Sams | 586f3b5 | 2010-02-10 18:07:37 -0800 | [diff] [blame] | 48 | if (luminance > threshold) { |
| 49 | *out = *in; |
| 50 | } else { |
| 51 | *((int *)out) = *((int *)in) & 0xff000000; |
| 52 | } |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 53 | |
| 54 | in++; |
| 55 | out++; |
| 56 | } |
| 57 | |
Jason Sams | ec2746c | 2010-02-10 15:03:24 -0800 | [diff] [blame] | 58 | t= uptimeMillis() - t; |
| 59 | debugI32("Filter time", t); |
| 60 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 61 | sendToClient(&count, 1, 4, 0); |
| 62 | } |