1

我开始探索渲染脚本的力量。

尝试使用 2D 图像数据,我可以将像素转换为其他像素。但是,如何从输入分配中获取相邻像素?

例如,当它需要相邻像素进行操作时,我认为内置 convolve3x3 过滤器是如何完成的,并且它很好地夹住了图像边缘的像素。

假设我有功能

void root(const uchar4 *v_in, uchar4 *v_out) {
   float4 f4 = rsUnpackColor8888(*v_in);
   // do something on pixel
   uchar4 u4 = rsPackColorTo8888(f4);
   *v_out = u4;
}

我真的应该像 v_in[1] 或 v_in[k] 那样索引 v_in 来获取其他像素,还是有一些聪明的 rs* 函数来获取相邻的水平/垂直像素,同时为图像大小提供适当的钳位,这样我就不'不索引 v_in 数组超出其大小?

4

1 回答 1

1

If you want to look at neighboring pixels (and you are using rs_allocations), you should just use a single global rs_allocation rather than passing it as *v_in. This would look like:

rs_allocation in;

// Using the new kernel syntax where v_out becomes the return value.
uchar4 __attribute__((kernel)) doSomething(uint32_t x, uint32_t y) {
  uchar4 u4 = rsGetElementAt_uchar4(in, x, y);  // You can adjust x,y here to get neighbor values too.
  float4 f4 = rsUnpackColor8888(u4);
  ...
  return rsPackColorTo8888(f4);
}

Unfortunately, there is no nice way to get automatic clamping with a regular rs_allocation, but you can adjust your code to do the edge clamp manually. Keep maxX, maxY as global variables passed to the Script, and then dynamically check whether or not you are in range before any rsGetElementAt*(). If you do want automatic clamping/wrapping behaviors, you can also check out the rs_sampler and rsSample() APIs.

于 2013-07-01T21:55:23.377 回答