diff options
author | Thomas Manni <thomas.manni@free.fr> | 2015-07-06 23:50:36 +0200 |
---|---|---|
committer | Thomas Manni <thomas.manni@free.fr> | 2015-07-07 00:04:21 +0200 |
commit | d0bfae0970c6a3b8934600ec09e5ef121cc117e0 (patch) | |
tree | afa7f6c60668614deee0f0a7d1117374f324991e /opencl | |
parent | 3571860697c77c5d83ad913b4b2858029e3121e2 (diff) |
color-exchange: add opencl support
Diffstat (limited to 'opencl')
-rw-r--r-- | opencl/color-exchange.cl | 44 | ||||
-rw-r--r-- | opencl/color-exchange.cl.h | 46 |
2 files changed, 90 insertions, 0 deletions
diff --git a/opencl/color-exchange.cl b/opencl/color-exchange.cl new file mode 100644 index 00000000..2a6be6c3 --- /dev/null +++ b/opencl/color-exchange.cl @@ -0,0 +1,44 @@ +/* This file is an image processing operation for GEGL + * + * GEGL is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * GEGL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GEGL; if not, see <http://www.gnu.org/licenses/>. + * + * Copyright 2015 Thomas Manni <thomas.manni@free.fr> + */ + +__kernel void cl_color_exchange(__global const float4 *in, + __global float4 *out, + float3 color_diff, + float3 min, + float3 max) +{ + int gid = get_global_id(0); + float4 in_v = in[gid]; + float4 out_v; + + if(in_v.x > min.x && in_v.x < max.x && + in_v.y > min.y && in_v.y < max.y && + in_v.z > min.z && in_v.z < max.z) + { + out_v.x = clamp(in_v.x + color_diff.x, 0.0f, 1.0f); + out_v.y = clamp(in_v.y + color_diff.y, 0.0f, 1.0f); + out_v.z = clamp(in_v.z + color_diff.z, 0.0f, 1.0f); + } + else + { + out_v.xyz = in_v.xyz; + } + + out_v.w = in_v.w; + out[gid] = out_v; +} diff --git a/opencl/color-exchange.cl.h b/opencl/color-exchange.cl.h new file mode 100644 index 00000000..99cac4e9 --- /dev/null +++ b/opencl/color-exchange.cl.h @@ -0,0 +1,46 @@ +static const char* color_exchange_cl_source = +"/* This file is an image processing operation for GEGL \n" +" * \n" +" * GEGL is free software; you can redistribute it and/or \n" +" * modify it under the terms of the GNU Lesser General Public \n" +" * License as published by the Free Software Foundation; either \n" +" * version 3 of the License, or (at your option) any later version. \n" +" * \n" +" * GEGL is distributed in the hope that it will be useful, \n" +" * but WITHOUT ANY WARRANTY; without even the implied warranty of \n" +" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \n" +" * Lesser General Public License for more details. \n" +" * \n" +" * You should have received a copy of the GNU Lesser General Public \n" +" * License along with GEGL; if not, see <http://www.gnu.org/licenses/>. \n" +" * \n" +" * Copyright 2015 Thomas Manni <thomas.manni@free.fr> \n" +" */ \n" +" \n" +"__kernel void cl_color_exchange(__global const float4 *in, \n" +" __global float4 *out, \n" +" float3 color_diff, \n" +" float3 min, \n" +" float3 max) \n" +"{ \n" +" int gid = get_global_id(0); \n" +" float4 in_v = in[gid]; \n" +" float4 out_v; \n" +" \n" +" if(in_v.x > min.x && in_v.x < max.x && \n" +" in_v.y > min.y && in_v.y < max.y && \n" +" in_v.z > min.z && in_v.z < max.z) \n" +" { \n" +" out_v.x = clamp(in_v.x + color_diff.x, 0.0f, 1.0f); \n" +" out_v.y = clamp(in_v.y + color_diff.y, 0.0f, 1.0f); \n" +" out_v.z = clamp(in_v.z + color_diff.z, 0.0f, 1.0f); \n" +" } \n" +" else \n" +" { \n" +" out_v.xyz = in_v.xyz; \n" +" } \n" +" \n" +" out_v.w = in_v.w; \n" +" out[gid] = out_v; \n" +"} \n" +; |