Lens are a series of modules to apply image filters on the browser while levaraging image-filters.
You can install and use a filter directly or you can use the chainable module to help you chain multiple filters and apply them to your DOM.
A filter is a function that receives:
data
-Array
- Array with the image dataoptions
-Object
- Any options you need to apply your transformationnWorkers
-Number
- The number of workers to be used
In this function you return the call to lens-core's applyFilter
function while passing in the data
, a transform
function, the options
and the nWorkers
.
The transform function is where you really define your filter, it receives the data
, length
of the array to be transformed and the options
and should return the array of the data transformed.
Here is a simple example of brightness transformer:
import { applyFilter } from 'lens-core';
const transform = ({ data, length, options }) => {
for (let i = 0; i < length; i += 4) {
data[i] += options.level;
data[i + 1] += options.level;
data[i + 2] += options.level;
}
return data;
};
export default brightness = ({ data, options, nWorkers } = {}) =>
applyFilter({ data, transform, options, nWorkers });