Skip to content

Instantly share code, notes, and snippets.

@CS1000
Last active Aug 29, 2015
Embed
What would you like to do?
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