[gegl] opencl: replace CLAMP macros with OpenCL built-in clamp



commit b958869ffca7517ff5f515a05da4ffc86c8551aa
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Sep 16 22:51:05 2015 +0200

    opencl: replace CLAMP macros with OpenCL built-in clamp
    
    Spotted and sorted out by Laura Ekstrand in bug #754914

 opencl/motion-blur-linear.cl   |    9 ++-------
 opencl/motion-blur-linear.cl.h |    8 ++------
 opencl/texturize-canvas.cl     |    3 +--
 opencl/texturize-canvas.cl.h   |    3 +--
 4 files changed, 6 insertions(+), 17 deletions(-)
---
diff --git a/opencl/motion-blur-linear.cl b/opencl/motion-blur-linear.cl
index 88befaf..265b163 100644
--- a/opencl/motion-blur-linear.cl
+++ b/opencl/motion-blur-linear.cl
@@ -1,8 +1,3 @@
-int CLAMP(int val,int lo,int hi)
-{
-    return (val < lo) ? lo : ((hi < val) ? hi : val);
-}
-
 float4 get_pixel_color(const __global float4 *in_buf,
                        int     rect_width,
                        int     rect_height,
@@ -14,8 +9,8 @@ float4 get_pixel_color(const __global float4 *in_buf,
     int ix = x - rect_x;
     int iy = y - rect_y;
 
-    ix = CLAMP(ix, 0, rect_width-1);
-    iy = CLAMP(iy, 0, rect_height-1);
+    ix = clamp(ix, 0, rect_width-1);
+    iy = clamp(iy, 0, rect_height-1);
 
     return in_buf[iy * rect_width + ix];
 }
diff --git a/opencl/motion-blur-linear.cl.h b/opencl/motion-blur-linear.cl.h
index 050286f..f1a6006 100644
--- a/opencl/motion-blur-linear.cl.h
+++ b/opencl/motion-blur-linear.cl.h
@@ -1,8 +1,4 @@
 static const char* motion_blur_linear_cl_source =
-"int CLAMP(int val,int lo,int hi)                                              \n"
-"{                                                                             \n"
-"    return (val < lo) ? lo : ((hi < val) ? hi : val);                         \n"
-"}                                                                             \n"
 "                                                                              \n"
 "float4 get_pixel_color(const __global float4 *in_buf,                         \n"
 "                       int     rect_width,                                    \n"
@@ -15,8 +11,8 @@ static const char* motion_blur_linear_cl_source =
 "    int ix = x - rect_x;                                                      \n"
 "    int iy = y - rect_y;                                                      \n"
 "                                                                              \n"
-"    ix = CLAMP(ix, 0, rect_width-1);                                          \n"
-"    iy = CLAMP(iy, 0, rect_height-1);                                         \n"
+"    ix = clamp(ix, 0, rect_width-1);                                          \n"
+"    iy = clamp(iy, 0, rect_height-1);                                         \n"
 "                                                                              \n"
 "    return in_buf[iy * rect_width + ix];                                      \n"
 "}                                                                             \n"
diff --git a/opencl/texturize-canvas.cl b/opencl/texturize-canvas.cl
index f2891b4..9d68af2 100644
--- a/opencl/texturize-canvas.cl
+++ b/opencl/texturize-canvas.cl
@@ -1,4 +1,3 @@
-#define CLAMP(val,lo,hi) (val < lo) ? lo : ((hi < val) ? hi : val )
 __kernel cl_texturize_canvas(__global const float * in,
                              __global float * out,
                              __global float * sdata,
@@ -23,7 +22,7 @@ __kernel cl_texturize_canvas(__global const float * in,
     for(i=0; i<components; ++i)
     {
        color = tmp + src[index];
-       out[index++] = CLAMP(color,0.0f,1.0f);
+       out[index++] = clamp(color,0.0f,1.0f);
     }
     if(has_alpha)
        out[index] = in[index];
diff --git a/opencl/texturize-canvas.cl.h b/opencl/texturize-canvas.cl.h
index 5fa1566..628756e 100644
--- a/opencl/texturize-canvas.cl.h
+++ b/opencl/texturize-canvas.cl.h
@@ -1,5 +1,4 @@
 static const char* texturize_canvas_cl_source =
-"#define CLAMP(val,lo,hi) (val < lo) ? lo : ((hi < val) ? hi : val )           \n"
 "__kernel cl_texturize_canvas(__global const float * in,                       \n"
 "                             __global float * out,                            \n"
 "                             __global float * sdata,                          \n"
@@ -24,7 +23,7 @@ static const char* texturize_canvas_cl_source =
 "    for(i=0; i<components; ++i)                                               \n"
 "    {                                                                         \n"
 "       color = tmp + src[index];                                              \n"
-"       out[index++] = CLAMP(color,0.0f,1.0f);                                 \n"
+"       out[index++] = clamp(color,0.0f,1.0f);                                 \n"
 "    }                                                                         \n"
 "    if(has_alpha)                                                             \n"
 "       out[index] = in[index];                                                \n"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]