Home | History | Annotate | Download | only in raw
      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 
     27 struct color_s {
     28     char b;
     29     char g;
     30     char r;
     31     char a;
     32 };
     33 
     34 void main() {
     35     int t = uptimeMillis();
     36 
     37     struct color_s *in = (struct color_s *) InPixel;
     38     struct color_s *out = (struct color_s *) OutPixel;
     39 
     40     int count = Params->inWidth * Params->inHeight;
     41     int i;
     42     float threshold = (Params->threshold * 255.f);
     43 
     44     for (i = 0; i < count; i++) {
     45         float luminance = 0.2125f * in->r +
     46                           0.7154f * in->g +
     47                           0.0721f * in->b;
     48         if (luminance > threshold) {
     49             *out = *in;
     50         } else {
     51             *((int *)out) = *((int *)in) & 0xff000000;
     52         }
     53 
     54         in++;
     55         out++;
     56     }
     57 
     58     t= uptimeMillis() - t;
     59     debugI32("Filter time", t);
     60 
     61     sendToClient(&count, 1, 4, 0);
     62 }
     63