Answers for "javascript canvas gamma correction"

0

javascript canvas gamma correction

var gamma = 2.2;
var gammaCorrection = 1 / gamma;

for (var y = 0; y < height; y++) {
  for (var x = 0; x < width; x++) {
    var oldColor = getPixel(x, y);
    var newColor = [
      Math.pow((oldColor[0] / 255), gammaCorrection) * 255,
      Math.pow((oldColor[1] / 255), gammaCorrection) * 255,
      Math.pow((oldColor[2] / 255), gammaCorrection) * 255
    ];

    updatePixel(x, y, newColor[0], newColor[1], newColor[2]);
  }
}
renderPixels();
Posted by: Guest on June-02-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language