Skip to content

Instantly share code, notes, and snippets.

@CS1000
Last active August 29, 2015 14:08
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/591704c928b93fa5be74 to your computer and use it in GitHub Desktop.
Save CS1000/591704c928b93fa5be74 to your computer and use it in GitHub Desktop.
Logarithmic contrast
function setContrast(rgb, perc)
{
ret = {}
Object.keys(rgb).map(function(v) {
col = rgb[v];
if (perc <= 0) {
col += (col - 128) * perc / 100; // ---> 128
} else {
if (col < 128) {
//bad start
qe = col / Math.log(col);
col = Math.log(101 - perc) * qe; // ---> 0
} else {
//bad start
diff = 255 - col;
qe = diff/Math.log(diff+1);
col = 255 - Math.log(101 - perc) * qe; // ---> 255
}
}
ret[v] = parseInt(col);
});
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment