3

我想将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; //
4

1 回答 1

4

使用它进行简单的转换:

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

或者其中一个用于手工转换:

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

where,<_sat>是可选的,定义了当值超出范围时是否会饱和。并且<_roundingMode>也是可选的,可以是_rte(最近的偶数)、_rtp(朝向 inf)、_rtn(朝向 -inf)或_rtz(朝向零)

如有更多问题,请参阅OpenCL 参考卡第 5 页。或OpenCL 的类型转换

于 2013-10-15T14:41:40.833 回答