gpt4 book ai didi

c++ - openCL:如何将 uint4 转换为 uchar4?

转载 作者:太空狗 更新时间:2023-10-29 21:01:10 25 4
gpt4 key购买 nike

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

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; //

最佳答案

使用它进行简单的转换:

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

关于c++ - openCL:如何将 uint4 转换为 uchar4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19383790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com