In my Android code, I keep an array of colours I would like to use in my renderscript code as follows:
for(int col = 0; col < imgWidth; col++){
const uchar4 colour = *(const uchar4*)rsGetElementAt(colours, col, 0);
if (in.r == colour.r && in.g == colour.g && in.b == colour.b){
in.r = 255;
in.g = 0;
in.b = 0;
break;
} else {
in.r = 0;
in.g = 255;
in.b = 0;
}
}
return in;
So basically, if the pixel is one of the colours in the array, turn it red. The problem is that I'm struggling to allocate the pixel array. In RS I have:
rs_allocation colours;
int imgWidth;
and in java I have:
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap myBitmap = Bitmap.createBitmap(pickedPanels.size(), 1, conf);
myBitmap.setPixels(myInts, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(),0);
final RenderScript rs = RenderScript.create(this);
// The input image.
final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
// The output image.
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptC_singlesource script = new
ScriptC_singlesource(rs);
// The array of colours.
final Allocation pixels = Allocation.createFromBitmap(rs, myBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
script.set_image(pixels);
script.set_imgWidth(pickedPanels.size());
script.forEach_root(input, output);
// retrieve output
output.copyTo(bitmap);
ImageView destim = (ImageView) findViewById (dest);
destim.setDrawingCacheEnabled(true);
destim.setImageBitmap(bitmap);
I've read that you cannot have more than 2 allocations. So, I'm guessing that's my problem. SO, I want to try and read the colours in as a uchar4* but I cannot find an example of how to do this.