lights FAQ Forum

Portable 2D Graphics


Fast box blur

local boxblur = require'boxblur'

Fast box blur algorithm for bgra8 and g8 pixel formats. The implementation is based on the moving-average technique, resulting in constant time for any blur radius, making it suitable for full-screen animated blurs.

Speed is 70 fps @ full HD per pass for the color variant, and 300 fps per pass for the grayscale variant, measured on a CPU with a single-threaded passmark score of around 2000.

API, max_radius, [passes], [format]) -> blur create a blur object for a bitmap, h, format, max_radius, [passes]) -> blur create a blur object for painting on
blur:blur([radius], [passes]) -> bmp blur img (returns a bitmap)
blur:repaint() override with painting code
blur:invalidate() tell blur that the source image changed

A blur object holds all the temporary buffers necessary for blurring the same image multiple times using a different radius without allocating new memory each time. Each call to blur() returns a potentially different bitmap object which contains the blurred image.

Last updated: 5 months ago | Edit on GitHub

Pkg type:C
Version: r1-20-g1ae642e
Last commit:
License: Public Domain
Import ver: 1.0
Requires: none
Required by: none