diff options
author | Carlos Zubieta <czubieta.dev@gmail.com> | 2013-07-23 18:08:06 -0500 |
---|---|---|
committer | Téo Mazars <teo.mazars@ensimag.fr> | 2013-10-31 11:41:43 +0100 |
commit | 1f74bccd4adca68d95965c199d5a0a7f49334042 (patch) | |
tree | 38ba47de200fe646e4899d84725b4c615b277c36 /opencl | |
parent | 4f35eba85b1e3910d4e7bf9ee48f8174658bedee (diff) |
Added OpenCL support to color-to-alpha
Diffstat (limited to 'opencl')
-rw-r--r-- | opencl/color-to-alpha.cl | 63 | ||||
-rw-r--r-- | opencl/color-to-alpha.cl.h | 65 |
2 files changed, 128 insertions, 0 deletions
diff --git a/opencl/color-to-alpha.cl b/opencl/color-to-alpha.cl new file mode 100644 index 00000000..9ca08949 --- /dev/null +++ b/opencl/color-to-alpha.cl @@ -0,0 +1,63 @@ +__kernel void cl_color_to_alpha(__global const float4 *in, + __global float4 *out, + float4 color) +{ + int gid = get_global_id(0); + float4 in_v = in[gid]; + float4 out_v = in_v; + float4 alpha; + + alpha.w = in_v.w; + + /*First component*/ + if ( color.x < 0.00001f ) + alpha.x = in_v.x; + else if ( in_v.x > color.x + 0.00001f ) + alpha.x = (in_v.x - color.x) / (1.0f - color.x); + else if ( in_v.x < color.x - 0.00001f ) + alpha.x = (color.x - in_v.x) / color.x; + else + alpha.x = 0.0f; + /*Second component*/ + if ( color.y < 0.00001f ) + alpha.y = in_v.y; + else if ( in_v.y > color.y + 0.00001f ) + alpha.y = (in_v.y - color.y) / (1.0f - color.y); + else if ( in_v.y < color.y - 0.00001f ) + alpha.y = (color.y - in_v.y) / color.y; + else + alpha.y = 0.0f; + /*Third component*/ + if ( color.z < 0.00001f ) + alpha.z = in_v.z; + else if ( in_v.z > color.z + 0.00001f ) + alpha.z = (in_v.z - color.z) / (1.0f - color.z); + else if ( in_v.z < color.z - 0.00001f ) + alpha.z = (color.z - in_v.z) / color.z; + else + alpha.z = 0.0f; + + if (alpha.x > alpha.y) + { + if (alpha.x > alpha.z) + out_v.w = alpha.x; + else + out_v.w = alpha.z; + } + else if (alpha.y > alpha.z) + { + out_v.w = alpha.y; + } + else + { + out_v.w = alpha.z; + } + + if (out_v.w >= 0.00001f) + { + out_v.xyz = (out_v.xyz - color.xyz) / out_v.www + color.xyz; + out_v.w *= alpha.w; + } + + out[gid] = out_v; +} diff --git a/opencl/color-to-alpha.cl.h b/opencl/color-to-alpha.cl.h new file mode 100644 index 00000000..409e0bc6 --- /dev/null +++ b/opencl/color-to-alpha.cl.h @@ -0,0 +1,65 @@ +static const char* color_to_alpha_cl_source = +"__kernel void cl_color_to_alpha(__global const float4 *in, \n" +" __global float4 *out, \n" +" float4 color) \n" +"{ \n" +" int gid = get_global_id(0); \n" +" float4 in_v = in[gid]; \n" +" float4 out_v = in_v; \n" +" float4 alpha; \n" +" \n" +" alpha.w = in_v.w; \n" +" \n" +" /*First component*/ \n" +" if ( color.x < 0.00001f ) \n" +" alpha.x = in_v.x; \n" +" else if ( in_v.x > color.x + 0.00001f ) \n" +" alpha.x = (in_v.x - color.x) / (1.0f - color.x); \n" +" else if ( in_v.x < color.x - 0.00001f ) \n" +" alpha.x = (color.x - in_v.x) / color.x; \n" +" else \n" +" alpha.x = 0.0f; \n" +" /*Second component*/ \n" +" if ( color.y < 0.00001f ) \n" +" alpha.y = in_v.y; \n" +" else if ( in_v.y > color.y + 0.00001f ) \n" +" alpha.y = (in_v.y - color.y) / (1.0f - color.y); \n" +" else if ( in_v.y < color.y - 0.00001f ) \n" +" alpha.y = (color.y - in_v.y) / color.y; \n" +" else \n" +" alpha.y = 0.0f; \n" +" /*Third component*/ \n" +" if ( color.z < 0.00001f ) \n" +" alpha.z = in_v.z; \n" +" else if ( in_v.z > color.z + 0.00001f ) \n" +" alpha.z = (in_v.z - color.z) / (1.0f - color.z); \n" +" else if ( in_v.z < color.z - 0.00001f ) \n" +" alpha.z = (color.z - in_v.z) / color.z; \n" +" else \n" +" alpha.z = 0.0f; \n" +" \n" +" if (alpha.x > alpha.y) \n" +" { \n" +" if (alpha.x > alpha.z) \n" +" out_v.w = alpha.x; \n" +" else \n" +" out_v.w = alpha.z; \n" +" } \n" +" else if (alpha.y > alpha.z) \n" +" { \n" +" out_v.w = alpha.y; \n" +" } \n" +" else \n" +" { \n" +" out_v.w = alpha.z; \n" +" } \n" +" \n" +" if (out_v.w >= 0.00001f) \n" +" { \n" +" out_v.xyz = (out_v.xyz - color.xyz) / out_v.www + color.xyz; \n" +" out_v.w *= alpha.w; \n" +" } \n" +" \n" +" out[gid] = out_v; \n" +"} \n" +; |