Reputation: 191
I have a script, that clear pixels certain color.
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;
}
That I run 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);
It works, but I need clear pixel neighbor with certain color pixel in RenderScript? In saturation we processing every pixels, and I don't know how to get access to all pixels.
Upvotes: 0
Views: 235
Reputation: 578
Use a global rs_allocation variable and then use the rsGetElementAt_uchar4 function to sample the image at other locations:
#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);
}
Java:
mScript.set_image(mInAllocation);
mScript.set_width_minus_one(mInAllocation.getType().getX() - 1);
Upvotes: 1