【问题标题】:Renderscript - why is the type of parameter 'in' a uchar4?Renderscript - 为什么参数的类型是'in' a uchar4?
【发布时间】:2019-05-25 18:27:33
【问题描述】:

我看了这个例子https://github.com/googlesamples/android-BasicRenderScript。在那个项目中,他们有以下行:

mInAllocation = Allocation.createFromBitmap(rs, mBitmapIn);

其中 mBitmapIn 是表示要处理的图像的位图类型。 之后,他们通过AsyncTask异步调用.rs文件中名为saturation的内核函数:

mScript.forEach_saturation(mInAllocation, mOutAllocations[index]);

在saturation.rs 文件中,它们有:

uchar4 __attribute__((kernel)) saturation(uchar4 in)
{
    float4 f4 = rsUnpackColor8888(in);
    ... 

从这个线程Renderscript, what is the `in` parameter?我知道参数'in'指向要处理的数据(在我们的例子中是一个像素,对吗?)所以,我知道一个像素由4个颜色通道组成,因此他们使用 uchar4 ,它是 4 个 uchar 的向量(参见 https://developer.android.com/guide/topics/renderscript/reference/rs_value_types.html#android_rs:uchar4 )。但是为什么是 uchar 呢?为什么不呢,比如说 uint4 ?还是直接ufloat4??

【问题讨论】:

    标签: android types parameters renderscript


    【解决方案1】:

    Renderscript 使用 C99 标准定义,并在此处列出类型的 sizeof 值:

    https://developer.android.com/guide/topics/renderscript/reference/rs_value_types

    所以从那张图表来看:

    uchar 有一个 8 位无符号值大小

    uint 具有 32 位无符号值大小

    浮点数为 32 位

    Android 位图通常经过配置 ARGB_8888 格式,因此每个像素都有 3 个颜色通道以及 alpha 通道和由 8 位组成的通道。

    即使在您的示例中,您也可以看到转换为用于计算目的的浮点数:

    float4 f4 = rsUnpackColor8888(in);
    

    有关 C 类型大小的更全面讨论,请参阅:Is the size of C “int” 2 bytes or 4 bytes?

    【讨论】:

      猜你喜欢
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多