summaryrefslogtreecommitdiffstats
path: root/libs/rs/java/ImageProcessing/res/raw/threshold.rs
blob: 888f0cdb029ee673f72c3b03d515e197fd4922b2 (plain)
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
/*
// block of defines matching what RS will insert at runtime.
struct Params_s{
    int inHeight;
    int inWidth;
    int outHeight;
    int outWidth;
    float threshold;
};
struct Params_s * Params;
struct InPixel_s{
    char a;
    char b;
    char g;
    char r;
};
struct InPixel_s * InPixel;
struct OutPixel_s{
    char a;
    char b;
    char g;
    char r;
};
struct OutPixel_s * OutPixel;
*/

struct color_s {
    char b;
    char g;
    char r;
    char a;
};

void main() {
    int t = uptimeMillis();

    struct color_s *in = (struct color_s *) InPixel;
    struct color_s *out = (struct color_s *) OutPixel;

    int count = Params->inWidth * Params->inHeight;
    int i;
    float threshold = (Params->threshold * 255.f);

    for (i = 0; i < count; i++) {
        float luminance = 0.2125f * in->r +
                          0.7154f * in->g +
                          0.0721f * in->b;
        if (luminance > threshold) {
            *out = *in;
        } else {
            *((int *)out) = *((int *)in) & 0xff000000;
        }

        in++;
        out++;
    }

    t= uptimeMillis() - t;
    debugI32("Filter time", t);

    sendToClient(&count, 1, 4, 0);
}