openCL:如何将uint4转换为uchar4?

时间:2013-10-15 14:28:08

标签: c++ type-conversion opencl

我想将uint4向量转换为uchar4向量,但我不确定这样做的正确方法是什么:

const uint4 res;
res = read_imageui(input, sampler, pos_read);

output[p]   = res           // error: assigning to '__global uchar4' from incompatible type 'const uint4'; 

output[p]   = (uchar4)res;  // error: invalid conversion between ext-vector type 'uchar4' and 'uint4'

output[p].x = (uchar)res.x; // 
output[p].y = (uchar)res.y; //
output[p].z = (uchar)res.z; // works, but is this the only/right way to go?
output[p].w = (uchar)res.w; //

1 个答案:

答案 0 :(得分:4)

使用它进行简单转换:

output[p] = convert_uchar4(res); //For a simple conversion

或其中一项手工转换:

output[p] = convert_uchar4<_sat><_roundingMode>(res); //For a precise conversion

其中,<_sat>是可选的,用于定义值超出范围时是否饱和。 <_roundingMode>也是可选的,可以是_rte(最近的偶数),_rtp(朝向inf),_rtn(朝向-inf)或_rtz(朝向零) )

如有其他问题,请致电OpenCL Reference Card Page 5。或Conversion of types for OpenCL