Skip to content

Instantly share code, notes, and snippets.

@CS1000
Created November 2, 2014 09:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CS1000/441779f9b15d2ceab20b to your computer and use it in GitHub Desktop.
Save CS1000/441779f9b15d2ceab20b to your computer and use it in GitHub Desktop.
Linear contrast
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