如何在Renderscript中获取位图分配的邻近像素?

Win*_*Oak 0 android image-processing renderscript

我想执行需要相邻像素的图像处理操作,但我不确定如何从分配中访问它们.我见过的大多数内核都在单个像素上运行,更新它,然后返回它.有没有办法可以在下面的方法中访问(x,y)的邻居.

uchar4 __attribute__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) {

  uchar4 neighbor = allocation[x+1][y]; // How do I do this in renderscript?
  uchar4 otherNeighbor = allocation[x-1][y]; 
  ...
}
Run Code Online (Sandbox Code Playgroud)

Ste*_*nes 5

隐式连接的标准输入/输出分配对于相邻像素更难访问,但您可以通过创建rs_allocation类型的全局变量来获取它们.

rs_allocation input;
uchar4 __attribute__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) {

uchar4 neighbor = rsGetElementAt_uchar4(input, x+1, y);
uchar4 otherNeighbor = rsGetElementAt_uchar4(input, x-1, y);
...
}
Run Code Online (Sandbox Code Playgroud)

在Java中,在内核上调用forEach之前,您只需要执行以下操作:

myScript.set_input(myInputAllocation);
myScript.forEach_invert(myInputAllocation, myOutputAllocation);
Run Code Online (Sandbox Code Playgroud)