summaryrefslogtreecommitdiff
path: root/opencl/value-invert.cl
blob: de029c69ac9ca940aa8db411d9733c05e3c94f66 (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
__kernel void gegl_value_invert (__global const float4     *in,
                                 __global       float4     *out)
{
  int gid = get_global_id(0);
  float4 in_v  = in[gid];
  float4 out_v;

  float value = fmax (in_v.x, fmax (in_v.y, in_v.z));
  float minv  = fmin (in_v.x, fmin (in_v.y, in_v.z));
  float delta = value - minv;

  if (value == 0.0f || delta == 0.0f)
    {
      out_v = (float4) ((1.0f - value),
                        (1.0f - value),
                        (1.0f - value),
                        in_v.w);
    }
  else
    {
      out_v = (float4) ((1.0f - value) * in_v.x / value,
                        (1.0f - value) * in_v.y / value,
                        (1.0f - value) * in_v.z / value,
                        in_v.w);
    }

  out_v.w   =  in_v.w;
  out[gid]  =  out_v;
}