Commit RELEASE-NOTES line for the wgCategories js variable I added some time ago.
[lhc/web/wiklou.git] / js2 / mwEmbed / libClipEdit / pixastic-lib / actions / mosaic.js
1 /*
2 * Pixastic Lib - Mosaic 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.mosaic = {
8
9 process : function(params) {
10 var blockSize = Math.max(1,parseInt(params.options.blockSize,10));
11
12 if (Pixastic.Client.hasCanvasImageData()) {
13 var rect = params.options.rect;
14 var w = rect.width;
15 var h = rect.height;
16 var w4 = w*4;
17 var y = h;
18
19 var ctx = params.canvas.getContext("2d");
20
21 var pixel = document.createElement("canvas");
22 pixel.width = pixel.height = 1;
23 var pixelCtx = pixel.getContext("2d");
24
25 var copy = document.createElement("canvas");
26 copy.width = w;
27 copy.height = h;
28 var copyCtx = copy.getContext("2d");
29 copyCtx.drawImage(params.canvas,rect.left,rect.top,w,h, 0,0,w,h);
30
31 for (var y=0;y<h;y+=blockSize) {
32 for (var x=0;x<w;x+=blockSize) {
33 pixelCtx.drawImage(copy, x, y, blockSize, blockSize, 0, 0, 1, 1);
34 var data = pixelCtx.getImageData(0,0,1,1).data;
35 ctx.fillStyle = "rgb(" + data[0] + "," + data[1] + "," + data[2] + ")";
36 ctx.fillRect(rect.left + x, rect.top + y, blockSize, blockSize);
37 }
38 }
39
40 params.useData = false;
41
42 return true;
43 }
44 },
45 checkSupport : function() {
46 return (Pixastic.Client.hasCanvasImageData());
47 }
48 }