0

I am trying to call a Renderscript kernel inside a function inside the same Renderscript file, but I have no idea how to do it (and the Google documentation doesn't really help).

So I want to call this kernel:

uchar __attribute__((kernel)) nextPixel(uint32_t x) {
    tImgIndexB = (uint32_t) (lBlackX[rsGetElementAt_uchar(num, x)] + lX) * 426 + (lBlackY[rsGetElementAt_uchar(num, x)] + lY);
    tImgIndexW = (uint32_t) (lWhiteX[rsGetElementAt_uchar(num, x)] + lX) * 426 + (lWhiteY[rsGetElementAt_uchar(num, x)] + lY);
    if (tImg[tImgIndexB] == 0 && tImg[tImgIndexW] == 1) {
        output = 1;
        tImg[lX*426+lY] = 3;
        //lX += lBlackX[rsGetElementAt_uchar(num, x)];
        //lY += lBlackY[rsGetElementAt_uchar(num, x)];
    } else {
        output = 0;
    }
    return output;
}

into a function like this:

void function() {
    // call kernel 'nextPixel'
}

Thank you in advance.

Anton
  • 137
  • 2
  • 14

2 Answers2

1

That's not really how RS is intended to be used. The RS engine calls your kernel with the appropriate data and your kernel can call other functions. However, it's not really a normal case to have a function within your RS code call into an RS kernel.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
0

I get a frame from the camera with a line on it (that starts somewhere at the bottom edge). I need to get every pixel of the left and right edge of the line in two arrays (one for the left edge, one for the right edge), with the first element of the array being the pixel at the bottom edge, and the last element in the array either the pixel on the left, top or right edge.

The frame I get from the camera is in YUV. So I convert it to a binary image (line in black, background in white) with Renderscript (that works).

I could send the processed frame back to Java, set it in a bitmap, and do the line-detection on the bitmap. However, reading and writing data to a bitmap is slow (and I need it to be as fast as possible), so I was trying to do everything in Renderscript. The kernel posted in my first post looks for the next pixel in the line (there are 8 possibilities, so I would like to check the 8 possibilities in parallel).

Anton
  • 137
  • 2
  • 14