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]
7 Pixastic
.Actions
.mosaic
= {
9 process : function(params
) {
10 var blockSize
= Math
.max(1,parseInt(params
.options
.blockSize
,10));
12 if (Pixastic
.Client
.hasCanvasImageData()) {
13 var rect
= params
.options
.rect
;
19 var ctx
= params
.canvas
.getContext("2d");
21 var pixel
= document
.createElement("canvas");
22 pixel
.width
= pixel
.height
= 1;
23 var pixelCtx
= pixel
.getContext("2d");
25 var copy
= document
.createElement("canvas");
28 var copyCtx
= copy
.getContext("2d");
29 copyCtx
.drawImage(params
.canvas
,rect
.left
,rect
.top
,w
,h
, 0,0,w
,h
);
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
);
40 params
.useData
= false;
45 checkSupport : function() {
46 return (Pixastic
.Client
.hasCanvasImageData());