According to the comment of the code, ImageBlurring Project is making a comprise between gaussian blurring and box blur. And by further study in the project, I find out another method to blurring the bitmap. It can blur the format of RGB_565:
for (x = 0; x < w; x++) {
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (y == 0) {
vmin[x] = MIN(x + radius + 1, wm);
}
p = pix[yw + vmin[x]];
sir[0] = (((p) & 0xF800) >> 11) << 3;
sir[1] = (((p) & 0x7E0) >> 5) << 2;
sir[2] = ((p) & 0x1F) << 3;
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[(stackpointer) % div];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi++;
}
The key code of this algorithm is
sir[0] = (((p) & 0xF800) >> 11) << 3;
sir[1] = (((p) & 0x7E0) >> 5) << 2;
sir[2] = ((p) & 0x1F) << 3;
RenderScript also provide some APIs for the blurring features:
RenderScript rs = RenderScript.create(getActivity());
Allocation overlayAlloc = Allocation.createFromBitmap(rs, bitmap);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
blur.setInput(overlayAlloc);
blur.setRadius(radius);
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(bitmap);
rs.destroy();
Next article, I will study for RenderScript and NDK.
作者:myfather103 发表于2017/8/8 15:30:11 原文链接
阅读:0 评论:0 查看评论