I'm working with a simple script in RenderScript. I have to modify the RGBA values on a pixel from a Bitmap. After many attempts I discovered that the Alpha channel doesn't get modified.
I did some researches and I found this old question but I don't understand how and why this happen. Is there a correctly way to modiphy Alpha channel on the script?
Here's a stripped down version of my code:
Java side:
Allocation img= Allocation.createFromBitmap(encodeRS, bmp,Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
RenderScript side:
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
uchar r= (in.r) & 0xFC;
uchar g= (in.g) & 0xFC;
uchar b= (in.b) & 0xFC;
uchar a= (in.a) & 0xFC;
return (uchar4) {r,g,b,a};
}
I also tried with memory binding but results are the same:
void root(uchar4* in, uint32_t x, uint32_t y) {
uchar r= (in->r) & 0xFC;
uchar g= (in->g) & 0xFC;
uchar b= (in->b) & 0xFC;
uchar a= (in->a) & 0xFC;
in->r= r;
in->g= g;
in->b= b;
in->a= a;
}
Then I do the copyTo from the java side (after the forEach) but the alpha channel is setted automatically to 255.
img.copyTo(bmp);
Thanks anyway for the support.
- Update 1:
I forgot to mention that I get the Bitmap from a File with getAbsolutePath() like this:
Bitmap bmp= BitmapFactory.decodeFile(imgFile.getAbsolutePath());