I'm trying to use Android RenderScript to render a translucent circle behind an image, but when I return a value from the RenderScript kernel, everything happens very badly.
This is my core:
#pragma version(1) #pragma rs java_package_name(be.abyx.aurora)
The rsPackColorTo8888() function rsPackColorTo8888() accepts 4 floats with a value from 0.0 to 1.0. The resulting ARGB color is then determined by calculating 255 times each float value. Thus, these floats correspond to the color R = 0.686 * 255 = 175, G = 0.686 * 255 = 175, B = 0.686 * 255 = 175 and A = 0.561 * 255 = 143.
The rsPackColorTo8888() function works correctly, but when the found uchar4 value uchar4 returned from the kernel, something really strange happens. The values โโof R, G, and B change respectively to Red * Alpha = 56, Green * Alpha = 56, and Blue * Alpha = 56, where Alpha is 0.561. This means that no value of R, G and B can be greater than A = 0.561 * 255.
Manually setting output instead of using rsPackColorTo8888() gives the exact same behavior. I mean, the following code gives the same result, which in turn proves that rsPackColorTo8888() not a problem:
if (square(x - centerX) + square(y - centerY) < square(radius)) { // Check if current position is transparent, we then need to add the background!) if (f4.a == 0) { uchar4 temp; temp[0] = 175; temp[1] = 175; temp[2] = 175; temp[3] = 143; return temp; } }
This is the Java code from which the script is called:
@Override public Bitmap renderParallel(Bitmap input, int backgroundColour, int padding) { ResizeUtility resizeUtility = new ResizeUtility();
If alpha is set to 255 (or 1.0 as a float), the returned color values โโ(inside the applicationโs Java code) are correct.
Am I doing something wrong, or is it really a mistake somewhere in the RenderScript implementation?
Note. I tested and verified this behavior on Oneplus 3T (Android 7.1.1), Nexus 5 (Android 7.1.2), Android emulator versions 7.1.2 and 6.0