The ability to create custom filters is a mainstay of any quality graphics application. A robust matrix-based filter engine can generate hundreds of unique effects by simply adjusting the matrices that get passed into the engine.
In this project, I’ve provided a 5×5 custom filter engine with support for scaling/weighting and biasing/offsetting. This is identical to the custom filter engine provided by Photoshop, and mine is even slightly faster (at least for the screen-sized images I’ve been testing).
Besides being fast, the engine is also smart. It is clever enough to estimate edge pixels correctly – even for scaled/weighted filters – and it will automatically validate all input values to make sure they’re appropriate.
Finally, I’ve included 7 sample filters for you to play with, including blur, sharpen, emboss, engrave, grease, unfocus, and vibrate. Below, you can see how each filter looks on a promotional image from Castle, an excellent new NYPD dramedy on ABC.