Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / libClipEdit / pixastic-lib / actions / blurfast.js
blobcaf6b759bc40c4b8fb67afe1560df64f57eae875
1 /*
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]
5  */
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");
18                         ctx.save();
19                         ctx.beginPath();
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);
25                         ctx.closePath();
26                         ctx.clip();
28                         var scale = 2;
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;
36                         var clear = true;
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));
43         
44                                 copyCtx.clearRect(0,0,smallWidth,smallHeight);
45         
46                                 copyCtx.drawImage(
47                                         params.canvas,
48                                         0,0,params.width,params.height,
49                                         0,0,scaledWidth,scaledHeight
50                                 );
51         
52                                 if (clear)
53                                         ctx.clearRect(rect.left,rect.top,rect.width,rect.height);
54         
55                                 ctx.drawImage(
56                                         copy,
57                                         0,0,scaledWidth,scaledHeight,
58                                         0,0,params.width,params.height
59                                 );
60                         }
62                         ctx.restore();
64                         params.useData = false;
65                         return true;
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";
73                         }
75                         return true;
76                 }
77         },
78         checkSupport : function() {
79                 return (Pixastic.Client.hasCanvas() || Pixastic.Client.isIE());
80         }