topical media & game development
graphic-canvas-util-pixastic-actions-coloradjust.js / js
/*
* Pixastic Lib - Color adjust filter - v0.1.1
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* MIT License [http://www.opensource.org/licenses/mit-license.php]
*/
Pixastic.Actions.coloradjust = {
process : function(params) {
var red = parseFloat(params.options.red) || 0;
var green = parseFloat(params.options.green) || 0;
var blue = parseFloat(params.options.blue) || 0;
red = Math.round(red*255);
green = Math.round(green*255);
blue = Math.round(blue*255);
if (Pixastic.Client.hasCanvasImageData()) {
var data = Pixastic.prepareData(params);
var rect = params.options.rect;
var p = rect.width*rect.height;
var pix = p*4, pix1, pix2;
var r, g, b;
while (p--) {
pix -= 4;
if (red) {
if ((r = data[pix] + red) < 0 )
data[pix] = 0;
else if (r > 255 )
data[pix] = 255;
else
data[pix] = r;
}
if (green) {
if ((g = data[pix1=pix+1] + green) < 0 )
data[pix1] = 0;
else if (g > 255 )
data[pix1] = 255;
else
data[pix1] = g;
}
if (blue) {
if ((b = data[pix2=pix+2] + blue) < 0 )
data[pix2] = 0;
else if (b > 255 )
data[pix2] = 255;
else
data[pix2] = b;
}
}
return true;
}
},
checkSupport : function() {
return (Pixastic.Client.hasCanvasImageData());
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.