一个常见的 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;
}
}