0

I have an image with multiple colours present (lets call it the mask). I also have a list of 'selected' colours. My renderscript makes a new image that I use as an overlay. If a colour is present in both the mask and the selected list, the overlay should be red in that area, else green.

These are the images: enter image description here

enter image description here

Note that the resulting image, with the red mask over it, has a green line in between. I have ensured that anti-aliasing is off when I create the first image, so that there are no unexpected colours in the 'mask'. But, for some reason, it is not seen as the one or the other colour in my renderscript. Here is the code:

#pragma version(1)
#pragma rs java_package_name(za.co.overtake)

int*reds;
int*greens;
int*blues;
int imgWidth;

uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {
   bool colourme = false;

for(int col = 0; col < imgWidth; col++){

    const int red = reds[col];
    const int green = greens[col];
    const int blue = blues[col];

     if (in.r == red && in.g == green && in.b == blue){
        colourme = true;
    }
}
 if (colourme) {
    in.r = 117;
    in.g = 0;
    in.b = 0;
    in.a = 100;
 } else if (in.a > 200) {
     in.r = 10;
     in.g = 60;
     in.b = 10;
     in.a = 100;
 } else {
    in.r = 0;
    in.g = 0;
    in.b = 0;
    in.a = 0;
 }
return in;
}

Any help will be appreciated. I'm still new at this and I've been stuck forever!

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
Zee
  • 1,592
  • 12
  • 26
  • Is the `in` Allocation just the "mask" image you have provided as an example? It looks like it may be the mask with some modifications done to it. Where do the colors in the `reds`, `greens` and `blues` arrays come from? – Larry Schiefer Jul 05 '17 at 11:48
  • Yes, in is just the mask. Reds, greens and blues are fed in from a list of colours that have been selected (I had to split it into 3 arrays because I couldn't really figure out how to read in an array of colours instead. Its on y TODO list) – Zee Jul 05 '17 at 13:18
  • So, the thing which doesn't make sense to me is that the mask you provided doesn't have any alpha, but the code is looking for alpha > 200 to determine when to enable the green overlay output. This looks as though the lines you are concerned about don't match colors in the array, but the alpha has been set > 200 so the green is masked in. Are you sure that when you are taking the mask and adding in the alpha channel you aren't also modifying the colors? – Larry Schiefer Jul 05 '17 at 14:29
  • Can you provide the original input image and the values you have set for reds/greens/blues? – sakridge Jul 05 '17 at 15:58

0 Answers0