Contrast module now uses changePixel Method (#1482)

* 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>
This commit is contained in:
Rishabh Shukla
2020-01-16 23:17:55 +05:30
committed by Jeffrey Warren
parent 45c54bb9af
commit 94caefa2cd
2 changed files with 22 additions and 34 deletions

View File

@@ -1,30 +0,0 @@
var _ = require('lodash');
const pixelSetter = require('../../util/pixelSetter.js');
module.exports = exports = function(pixels, contrast) {
let oldpix = _.cloneDeep(pixels);
contrast = Number(contrast);
if (contrast < -100) contrast = -100;
if (contrast > 100) contrast = 100;
contrast = (100.0 + contrast) / 100.0;
contrast *= contrast;
for (let i = 0; i < pixels.shape[0]; i++) {
for (let j = 0; j < pixels.shape[1]; j++) {
var rgbarray = [oldpix.get(i, j, 0) / 255.0, oldpix.get(i, j, 1) / 255.0, oldpix.get(i, j, 2) / 255.0];
for(var idx = 0;idx < 3;idx++){
rgbarray[idx] -= 0.5;
rgbarray[idx] *= contrast;
rgbarray[idx] += 0.5;
rgbarray[idx] *= 255;
if (rgbarray[idx] < 0) rgbarray[idx] = 0;
if (rgbarray[idx] > 255) rgbarray[idx] = 255;
}
pixelSetter(i, j, rgbarray, pixels);
}
}
return pixels;
};

View File

@@ -15,9 +15,27 @@ module.exports = function Contrast(options, UI) {
var step = this;
function extraManipulation(pixels) {
pixels = require('./Contrast')(pixels, options.contrast);
return pixels;
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) {
@@ -27,7 +45,7 @@ module.exports = function Contrast(options, UI) {
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
ui: options.step.ui,
extraManipulation: extraManipulation,
changePixel: changePixel,
format: input.format,
image: options.image,
callback: callback,