topical media & game development
graphic-canvas-util-pixastic-actions-lighten.js / js
/*
* Pixastic Lib - Lighten filter - v0.1.0
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* MIT License [http://www.opensource.org/licenses/mit-license.php]
*/
Pixastic.Actions.lighten = {
process : function(params) {
var amount = parseFloat(params.options.amount) || 0;
if (Pixastic.Client.hasCanvasImageData()) {
var data = Pixastic.prepareData(params);
var rect = params.options.rect;
var w = rect.width;
var h = rect.height;
var w4 = w*4;
var y = h;
do {
var offsetY = (y-1)*w4;
var x = w;
do {
var offset = offsetY + (x-1)*4;
var r = data[offset];
var g = data[offset+1];
var b = data[offset+2];
r += r*amount;
g += g*amount;
b += b*amount;
if (r < 0 ) r = 0;
if (g < 0 ) g = 0;
if (b < 0 ) b = 0;
if (r > 255 ) r = 255;
if (g > 255 ) g = 255;
if (b > 255 ) b = 255;
data[offset] = r;
data[offset+1] = g;
data[offset+2] = b;
} while (--x);
} while (--y);
return true;
} else if (Pixastic.Client.isIE()) {
var img = params.image;
if (amount < 0) {
img.style.filter += " light()";
img.filters[img.filters.length-1].addAmbient(
255,255,255,
100 * -amount
);
} else if (amount > 0) {
img.style.filter += " light()";
img.filters[img.filters.length-1].addAmbient(
255,255,255,
100
);
img.filters[img.filters.length-1].addAmbient(
255,255,255,
100 * amount
);
}
return true;
}
},
checkSupport : function() {
return (Pixastic.Client.hasCanvasImageData() || Pixastic.Client.isIE());
}
}
(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.