summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPan Xiuli <xiuli.pan@intel.com>2016-03-03 09:52:20 +0800
committerYang Rong <rong.r.yang@intel.com>2016-11-08 20:38:22 +0800
commit2a80244fff19a34e89312756427c19b08b548e5c (patch)
tree05bfb726e4bbea482d864b97e9473a227de6d9b2 /src
parent158ddc130c7503ff1a11a4470fae5ac845237017 (diff)
Runtime: Add suport for sRGB to clEnqueueFillImage
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/cl_mem.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 3c5203f4..75e8efb4 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -36,6 +36,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <math.h>
#define FIELD_SIZE(CASE,TYPE) \
case JOIN(CL_,CASE): \
@@ -1646,6 +1647,8 @@ cl_image_fill(cl_command_queue queue, const void * pattern, struct _cl_mem_image
size_t global_off[] = {0,0,0};
size_t global_sz[] = {1,1,1};
size_t local_sz[] = {LOCAL_SZ_0,LOCAL_SZ_1,LOCAL_SZ_2};
+ uint32_t savedIntelFmt = src_image->intel_fmt;
+
if(region[1] == 1) local_sz[1] = 1;
if(region[2] == 1) local_sz[2] = 1;
@@ -1691,7 +1694,24 @@ cl_image_fill(cl_command_queue queue, const void * pattern, struct _cl_mem_image
return CL_OUT_OF_RESOURCES;
cl_kernel_set_arg(ker, 0, sizeof(cl_mem), &src_image);
- cl_kernel_set_arg(ker, 1, sizeof(float)*4, pattern);
+ if(src_image->fmt.image_channel_order >= CL_sRGBA) {
+#define RGB2sRGB(linear) ( linear <= 0.0031308f )? ( 12.92f * linear ):( 1.055f * powf( linear, 1.0f/2.4f ) - 0.055f);
+ cl_image_format fmt;
+ float newpattern[4] = {0.0,0.0,0.0,((float*)pattern)[3]};
+ int i;
+ for(i = 0;i < 3; i++){
+ if(src_image->fmt.image_channel_order == CL_sRGBA) {
+ newpattern[i] = RGB2sRGB(((float*)pattern)[i]);
+ } else
+ newpattern[2-i] = RGB2sRGB(((float*)pattern)[i]);
+ }
+ cl_kernel_set_arg(ker, 1, sizeof(float)*4, newpattern);
+ fmt.image_channel_order = CL_RGBA;
+ fmt.image_channel_data_type = CL_UNORM_INT8;
+ src_image->intel_fmt = cl_image_get_intel_format(&fmt);
+#undef RGB2sRGB
+ } else
+ cl_kernel_set_arg(ker, 1, sizeof(float)*4, pattern);
cl_kernel_set_arg(ker, 2, sizeof(cl_int), &region[0]);
cl_kernel_set_arg(ker, 3, sizeof(cl_int), &region[1]);
cl_kernel_set_arg(ker, 4, sizeof(cl_int), &region[2]);
@@ -1701,6 +1721,7 @@ cl_image_fill(cl_command_queue queue, const void * pattern, struct _cl_mem_image
ret = cl_command_queue_ND_range(queue, ker, NULL, 3, global_off, global_sz, local_sz);
cl_kernel_delete(ker);
+ src_image->intel_fmt = savedIntelFmt;
return ret;
}