I am trying to understand Renderscript. Could somebody have a look at this code, and let me know what the in
parameter is ? It is not an Allocation object, so it is an Element? Why is it an array then?
(I got the code from here, and modified it, http://www.jayway.com/2014/02/11/renderscript-on-android-basics/)
#pragma version(1)
#pragma rs java_package_name(foo.bar)
rs_allocation inPixels;
int height;
int width;
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float3 pixel = convert_float4(in[0]).rgb;
pixel.r = (pixel.r + pixel.g + pixel.b)/3;
pixel.g = (pixel.r + pixel.g + pixel.b)/3;
pixel.b = (pixel.r + pixel.g + pixel.b)/3;
int topRight
//float4 f4 = rsUnpackColor8888(*(uchar*)rsGetElementAt(inPixels, x+1, y+1));
out->xyz = convert_uchar3(pixel);
}
What does this line convert_float4(in[0])
do?
The index 0 point to what ? The first pixel? So if I want to access the next pixel I should increase that by one?
The
uchar4
andfloat3
types are essentially the same as what you find in OpenCL. They are vector values containing 4 and 3 components, respectively. Theconvert_float4()
andconvert_uchar3()
functions are provided by Renderscript to do correct, fast conversion between the different types.The
in
parameter is essentially a pointer to the current element in which your kernel is operating. Thex
andy
values tell you exactly whichElement
within yourAllocation
thein
corresponds. You should not attempt to use it as an array and directly access other elements. If you do, you risk touching memory in which your process does not have access. Renderscript is processing your dataset in parallel, which may be done on different threads or a different processor (GPU). It depends on the hardware implementation.