Created
March 17, 2012 00:28
-
-
Save jonathantneal/2053865 to your computer and use it in GitHub Desktop.
Canvas Prototype: Brightness
This file contains 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
HTMLCanvasElement.prototype.brightness = function (value) { | |
var | |
canvas = this, | |
context = canvas.getContext('2d'), | |
imageData = context.getImageData(0, 0, canvas.width, canvas.height), | |
canvasPixelArray = imageData.data, | |
canvasPixelArrayLength = canvasPixelArray.length, | |
i = 0; | |
value = parseFloat(value) || 0; | |
for (; i < canvasPixelArrayLength; i += 4) { | |
canvasPixelArray[i] += value; | |
canvasPixelArray[i + 1] += value; | |
canvasPixelArray[i + 2] += value; | |
} | |
context.putImageData(imageData, 0, 0); | |
return canvas; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment