Function signature for __attribute__(kernel) function and usage of "OutAllocation"

I intend to process RGB data through RenderScript.

For this I've created Allocations in Java and passing them to RS Kernel function as below:

uchar3 __attribute__((kernel)) invert(uchar3 v_in, uint32_t v_out) {
v_in.r = ...;
v_in.g = ...;
v_in.b = ...;

However ideally I would like to work on v_out in similar way i.e. setting values for v_out.r, v_out.g and v_out.b. Currently I can not do this with uint32_t v_out.

Now if I define the above RS kernel as:

uchar3 __attribute__((kernel)) invert(uchar3 v_in, uchar3 v_out) {

I get below compile time error: error: Unexpected kernel invert() parameter 'v_out' of type 'uchar3 *'

Please suggest how to resolve this.

Compile time:

error: Unexpected kernel invert() parameter 'v_out' of type 'uchar3 *'


you should be defining this as

uchar3 __attribute__((kernel)) invert(uchar3 in);

that function will then be reflected as ScriptC_.forEach_invert(Allocation in, Allocation out). each element in in will be passed to invert, and each value returned from invert will be written to the corresponding location in out.

Define your own local variable of uchar3 type and then populate it before returning it:

uchar3 __attribute__((kernel)) invert(uchar3 in) {
    uchar3 out;
    out.r = ...
    out.g = ...
    out.b = ...
    return out;

The compiler is clever enough to notice what you are doing, so there won't be additional copies made of the output items.

Need Your Help

How do I display a string in an Android app?

java android


Scala: Something like Option (Some, None) but with three states: Some, None, Unknown

scala nullable option

I need to return values, and when someone asks for a value, tell them one of three things: