android/renderscript-intrinsics-replacement-toolkit

Convolution

Opened this issue · 2 comments

ucmax commented

Not getting expected results in convolving, it seems when sum of the coefficients is zero the result is empty.
Untitled-1

cookt commented

Experiencing the same for 5x5 kernels.

I took a look at the code. It appears that when using a RGBA bitmap as input, the convolution is not only applied to the RGB channels, but also the alpha channel. Assuming the alpha channel is always 1 in the original image, when the sum of the matrix coefficients is zero, the alpha channel in the result bitmap is always 0, and thus the result image looks empty. If the alpha channel were restored back to 1 after the convolution, the expected content would appear.

I think this behavior matches with the original RenderScript convolution intrinsics. Since the toolkit is created as a replacement library of the original RenderScript, we would like to keep this behavior. That being said, it might be interesting to have an additional parameter indicating whether the alpha channel should be preserved or not. Contributions are welcome.