Last active
August 29, 2015 14:08
-
-
Save CS1000/591704c928b93fa5be74 to your computer and use it in GitHub Desktop.
Logarithmic 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) | |
{ | |
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