javascript canvas gamma correction

Solutions on MaxInterview for javascript canvas gamma correction by the best coders in the world

showing results for - "javascript canvas gamma correction"
Jerónimo
23 Jul 2018
1var gamma = 2.2;
2var gammaCorrection = 1 / gamma;
3
4for (var y = 0; y < height; y++) {
5  for (var x = 0; x < width; x++) {
6    var oldColor = getPixel(x, y);
7    var newColor = [
8      Math.pow((oldColor[0] / 255), gammaCorrection) * 255,
9      Math.pow((oldColor[1] / 255), gammaCorrection) * 255,
10      Math.pow((oldColor[2] / 255), gammaCorrection) * 255
11    ];
12
13    updatePixel(x, y, newColor[0], newColor[1], newColor[2]);
14  }
15}
16renderPixels();