Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 1x 1x 1x 1x 1x 1x 4x 3x 1x | import { applyFilter } from 'lens-core';
/**
* Iterate over the array applying the gamma transformation
* @param {Object} data
* @param {Number} length
* @param {Object} options
* @param {Number} [options.level]
*/
export const transform = ({ data, length, options }) => {
for (let i = 0; i < length; i += 4) {
data[i] = Math.pow(data[i] / 255, options.level) * 255;
data[i + 1] = Math.pow(data[i + 1] / 255, options.level) * 255;
data[i + 2] = Math.pow(data[i + 2] / 255, options.level) * 255;
}
return data;
};
/**
* @param {ImageData} data - data of a image extracted from a canvas
* @param {Object} options - options to pass to the transformation function
* @param {Number} [options.level] - level to apply in the transformation
* @param {Number} nWorkers - number of workers
* @returns {Promise}
*/
export default function gamma({ data, options, nWorkers } = {}) {
if (!data || !options || !options.level) {
throw new Error('lens-filter-gamma:: invalid options provided');
}
return applyFilter({ data, transform, options, nWorkers });
}
|