RenderScript多输入参数

Posted mydddfly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RenderScript多输入参数相关的知识,希望对你有一定的参考价值。

https://stackoverflow.com/questions/20783830/how-to-use-renderscript-with-multiple-input-allocations

For the kernel with multiple inputs you would have to manually handle additional inputs.

Let‘s say you want 2 inputs.

example.rs:

rs_allocation extra_alloc;

uchar4 __attribute__((kernel)) kernel(uchar4 i1, uint32_t x, uint32_t y)
{
    // Manually getting current element from the extra input
    uchar4 i2 = rsGetElementAt_uchar4(extra_alloc, x, y);
    // Now process i1 and i2 and generate out
    uchar4 out = ...;
    return out;
}

Java:

Bitmap bitmapIn = ...;
Bitmap bitmapInExtra = ...;
Bitmap bitmapOut = Bitmap.createBitmap(bitmapIn.getWidth(),
                    bitmapIn.getHeight(), bitmapIn.getConfig());

RenderScript rs = RenderScript.create(this);
ScriptC_example script = new ScriptC_example(rs);

Allocation inAllocation = Allocation.createFromBitmap(rs, bitmapIn);
Allocation inAllocationExtra = Allocation.createFromBitmap(rs, bitmapInExtra);
Allocation outAllocation = Allocation.createFromBitmap(rs, bitmapOut);

// Execute this kernel on two inputs
script.set_extra_alloc(inAllocationExtra);
script.forEach_kernel(inAllocation, outAllocation);

// Get the data back into bitmap
outAllocation.copyTo(bitmapOut);

以上是关于RenderScript多输入参数的主要内容,如果未能解决你的问题,请参考以下文章

使用 Renderscript 启动选项裁剪图像数据

Android模糊演示样例-RenderScript-附效果图与代码

Renderscript 致命信号 11 (SIGSEGV) 代码 1 (SEGV_MAPERR) 故障地址

RenderScript在Android 6上崩溃

Android RenderScriptRenderScript 简介 ② ( RenderScript 引入 | RenderScript 简介 )

Chain 2 Renderscript Intrinsics:模糊和色彩矩阵