如何知道root()函数内的分配中的当前索引?
现在我通过绑定一个额外的指针 - 分配的开始来做到这一点。像这样:
// Java code Allocation in = Allocation.create...; mScript.bind_gStart(in);
然后在renderscript中使用一些指针算法:
// RS file - assuming 1D array void root(const uint8_t *in) { size_t idx = in - gStart; ... }
这可以保证有效吗?有没有更好/更直接的方法呢?不知何故,我觉得必须有一些curIdx伪变量,或者其他东西。
答案 0 :(得分:1)
一个常见的root()函数原型是:
void root(const uchar4 *data_in, uchar4 *data_out, const void * usrData, uint32_t x, uint32_t y)
x和y参数指定输入分配中的索引。我成功地将它们用于图像处理,例如:
void root(const uchar *data_in, uchar4 *data_out, const void * usrData, uint32_t x, uint32_t y) {
int sum_x;
int sum_y;
unsigned char channel;
int color;
width = rsAllocationGetDimX(gIn);
height = rsAllocationGetDimY(gOut);
if ( (x > 1) & (y > 1) & (x < width-1) & (y < height-1)) {
sum_x = 0;
sum_x += -1 * gPixels[(y-1)*width+x-1];
sum_x += 1 * gPixels[(y-1)*width+x+1];
sum_x += -2 * gPixels[y*width+x-1];
sum_x += 2 * gPixels[y*width+x+1];
sum_x += -1 * gPixels[(y+1)*width+x-1];
sum_x += 1 * gPixels[(y+1)*width+x+1];
sum_y = 0;
sum_y += -1 * gPixels[(y-1)*width+x-1];
sum_y += -2 * gPixels[(y-1)*width+x];
sum_y += -1 * gPixels[(y-1)*width+x+1];
sum_y += 1 * gPixels[(y+1)*width+x-1];
sum_y += 2 * gPixels[(y+1)*width+x];
sum_y += 1 * gPixels[(y+1)*width+x+1];
//channel = (byte) (Math.hypot(sum_x, sum_y)); // L2 norm
channel = (uchar) (abs(sum_x) + abs(sum_y)); // L1 norm
//color = 0xFF000000 | (channel << 16) | (channel << 8) | channel;
data_out->w = 0xFF;
data_out->x = channel;
data_out->y = channel;
data_out->z = channel;
}
else {
data_out->w = 0xFF;
data_out->x = 0xFF;
data_out->y = 0xFF;
data_out->z = 0xFF;
}
}