2 * Pixastic Lib - Blur Fast - v0.1.0
3 * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
4 * MIT License [http://www.opensource.org/licenses/mit-license.php]
7 Pixastic.Actions.blurfast = {
8 process : function(params) {
10 var amount = parseFloat(params.options.amount)||0;
12 amount = Math.max(0,Math.min(5,amount));
14 if (Pixastic.Client.hasCanvas()) {
15 var rect = params.options.rect;
17 var ctx = params.canvas.getContext("2d");
20 ctx.moveTo(rect.left,rect.top);
21 ctx.lineTo(rect.left+rect.width,rect.top);
22 ctx.lineTo(rect.left+rect.width,rect.top+rect.height);
23 ctx.lineTo(rect.left,rect.top+rect.height);
24 ctx.lineTo(rect.left,rect.top);
29 var smallWidth = Math.round(params.width / scale);
30 var smallHeight = Math.round(params.height / scale);
32 var copy = document.createElement("canvas");
33 copy.width = smallWidth;
34 copy.height = smallHeight;
37 var steps = Math.round(amount * 20);
39 var copyCtx = copy.getContext("2d");
40 for (var i=0;i<steps;i++) {
41 var scaledWidth = Math.max(1,Math.round(smallWidth - i));
42 var scaledHeight = Math.max(1,Math.round(smallHeight - i));
44 copyCtx.clearRect(0,0,smallWidth,smallHeight);
48 0,0,params.width,params.height,
49 0,0,scaledWidth,scaledHeight
53 ctx.clearRect(rect.left,rect.top,rect.width,rect.height);
57 0,0,scaledWidth,scaledHeight,
58 0,0,params.width,params.height
64 params.useData = false;
66 } else if (Pixastic.Client.isIE()) {
67 var radius = 10 * amount;
68 params.image.style.filter += " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + radius + ")";
70 if (params.options.fixMargin || 1) {
71 params.image.style.marginLeft = (parseInt(params.image.style.marginLeft,10)||0) - Math.round(radius) + "px";
72 params.image.style.marginTop = (parseInt(params.image.style.marginTop,10)||0) - Math.round(radius) + "px";
78 checkSupport : function() {
79 return (Pixastic.Client.hasCanvas() || Pixastic.Client.isIE());