color-to-alpha.cl.h 5.15 KB
Newer Older
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 63 64 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"
;