Created
November 2, 2014 09:44
-
-
Save CS1000/441779f9b15d2ceab20b to your computer and use it in GitHub Desktop.
Linear contrast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setContrast(rgb, perc) | |
{ | |
perc = perc / 100; | |
ret = {} | |
Object.keys(rgb).map(function(v) { | |
col = rgb[v]; | |
if (perc <= 0) { | |
col += (col - 128) * perc; // ---> 128 | |
} else { | |
if (col < 128) { | |
col *= 1 - perc; // ---> 0 | |
} else { | |
// ---> 255 | |
col += (255 - col) * perc; | |
} | |
} | |
ret[v] = parseInt(col); | |
}); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment