0

我有一个脚本,可以清除某些颜色的像素。

uchar red = 100;
uchar green = 100;
uchar blue = 100;
float treshold = 100;

uchar4 __attribute__((kernel)) saturation(uchar4 in,uint32_t x, uint32_t y)
{
    float ddd = ((in.r - red)*(in.r - red) + (in.g - green)*(in.g - green) + (in.b - blue)*(in.b - blue));
    float dif = sqrt( ddd );
    if (dif <= treshold){
        in.a = 0;
        in.r = 0;
        in.g = 0;
        in.b = 0;
    }
    return in;
}

我在 Java lile 中运行:

        mScript.set_red((short)r);
        mScript.set_blue((short)b);
        mScript.set_green((short)g);
        mScript.set_treshold(treshold);
        mScript.forEach_saturation(mInAllocation, mOutAllocations);

它有效,但我需要在 RenderScript 中具有特定颜色像素的清晰像素邻居?在饱和度中,我们处理每个像素,我不知道如何访问所有像素。

4

1 回答 1

1

使用全局 rs_allocation 变量,然后使用 rsGetElementAt_uchar4 函数在其他位置对图像进行采样:

#pragma rs_fp_relaxed
rs_allocation image;
int width_minus_one;
void RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {
    int newX = min(x + 1, width_minus_one);
    uchar4 pixel = rsGetElementAt_uchar4(image, newX, y);
}

爪哇:

mScript.set_image(mInAllocation);
mScript.set_width_minus_one(mInAllocation.getType().getX() - 1);
于 2016-12-03T22:16:20.593 回答