Commit RELEASE-NOTES line for the wgCategories js variable I added some time ago.
[lhc/web/wiklou.git] / js2 / mwEmbed / libClipEdit / pixastic-lib / actions / pointillize.js
1 /*
2 * Pixastic Lib - Pointillize filter - 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 */
6
7 Pixastic.Actions.pointillize = {
8
9 process : function(params) {
10 var radius = Math.max(1,parseInt(params.options.radius,10));
11 var density = Math.min(5,Math.max(0,parseFloat(params.options.density)||0));
12 var noise = Math.max(0,parseFloat(params.options.noise)||0);
13 var transparent = !!params.options.transparent;
14
15 if (Pixastic.Client.hasCanvasImageData()) {
16 var rect = params.options.rect;
17 var w = rect.width;
18 var h = rect.height;
19 var w4 = w*4;
20 var y = h;
21
22 var ctx = params.canvas.getContext("2d");
23
24 var pixel = document.createElement("canvas");
25 pixel.width = pixel.height = 1;
26 var pixelCtx = pixel.getContext("2d");
27
28 var copy = document.createElement("canvas");
29 copy.width = w;
30 copy.height = h;
31 var copyCtx = copy.getContext("2d");
32 copyCtx.drawImage(params.canvas,rect.left,rect.top,w,h, 0,0,w,h);
33
34 var diameter = radius * 2;
35
36 if (transparent)
37 ctx.clearRect(rect.left, rect.top, rect.width, rect.height);
38
39 var noiseRadius = radius * noise;
40
41 var dist = 1 / density;
42
43 for (var y=0;y<h+radius;y+=diameter*dist) {
44 for (var x=0;x<w+radius;x+=diameter*dist) {
45 rndX = noise ? (x+((Math.random()*2-1) * noiseRadius))>>0 : x;
46 rndY = noise ? (y+((Math.random()*2-1) * noiseRadius))>>0 : y;
47
48 var pixX = rndX - radius;
49 var pixY = rndY - radius;
50 if (pixX < 0) pixX = 0;
51 if (pixY < 0) pixY = 0;
52
53 pixelCtx.drawImage(copy, pixX, pixY, diameter, diameter, 0, 0, 1, 1);
54 var data = pixelCtx.getImageData(0,0,1,1).data;
55 ctx.fillStyle = "rgb(" + data[0] + "," + data[1] + "," + data[2] + ")";
56 ctx.beginPath();
57 ctx.arc(rect.left + rndX,rect.top + rndY, radius, 0, Math.PI*2, true);
58 ctx.closePath();
59 ctx.fill();
60 }
61 }
62
63 params.useData = false;
64
65 return true;
66 }
67 },
68 checkSupport : function() {
69 return (Pixastic.Client.hasCanvasImageData());
70 }
71 }