我开始探索renderscript的功能。
尝试使用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数组超出其大小吗?
最佳答案
如果要查看相邻像素(并且您正在使用rs_allocations),则应仅使用单个全局rs_allocation,而不要将其作为* v_in传递。看起来像:
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);
}
不幸的是,没有一种好的方法可以通过常规的rs_allocation获得自动夹紧,但是您可以调整代码以手动进行边缘夹紧。将maxX,maxY保留为传递给脚本的全局变量,然后动态检查是否在任何rsGetElementAt *()之前。如果确实需要自动钳位/包装行为,则还可以签出rs_sampler和rsSample()API。
关于android - Renderscript-获取邻居像素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17399255/