mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-11 19:00:00 +01:00
* contrast module uses changePixel Method * change if block to Math function * fix bug Co-authored-by: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
// /*
|
|
// * Changes the Image Contrast
|
|
// */
|
|
|
|
module.exports = function Contrast(options, UI) {
|
|
|
|
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
|
|
options.contrast = options.contrast || defaults.contrast;
|
|
var output;
|
|
|
|
function draw(input, callback, progressObj) {
|
|
|
|
progressObj.stop(true);
|
|
progressObj.overrideFlag = true;
|
|
|
|
var step = this;
|
|
|
|
let contrast = options.contrast;
|
|
|
|
contrast = Number(contrast);
|
|
if (contrast < -100) contrast = -100;
|
|
if (contrast > 100) contrast = 100;
|
|
contrast = (100.0 + contrast) / 100.0;
|
|
contrast *= contrast;
|
|
|
|
function changeContrast(p){
|
|
p -= 0.5;
|
|
p *= contrast;
|
|
p += 0.5;
|
|
p *= 255;
|
|
p = Math.max(0, p);
|
|
p = Math.min(p, 255);
|
|
return p;
|
|
}
|
|
|
|
function changePixel(r, g, b, a) {
|
|
|
|
return [changeContrast(r / 255), changeContrast(g / 255), changeContrast(b / 255), a];
|
|
}
|
|
|
|
function output(image, datauri, mimetype, wasmSuccess) {
|
|
step.output = { src: datauri, format: mimetype, wasmSuccess, useWasm: options.useWasm };
|
|
}
|
|
|
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
|
output: output,
|
|
ui: options.step.ui,
|
|
changePixel: changePixel,
|
|
format: input.format,
|
|
image: options.image,
|
|
callback: callback,
|
|
inBrowser: options.inBrowser,
|
|
useWasm:options.useWasm
|
|
});
|
|
|
|
}
|
|
return {
|
|
options: options,
|
|
draw: draw,
|
|
output: output,
|
|
UI: UI
|
|
};
|
|
};
|