2 * Pixastic Lib - Posterize effect - 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
.posterize
= {
9 process : function(params
) {
13 if (typeof params
.options
.levels
!= "undefined")
14 numLevels
= parseInt(params
.options
.levels
,10)||1;
16 if (Pixastic
.Client
.hasCanvasImageData()) {
17 var data
= Pixastic
.prepareData(params
);
19 numLevels
= Math
.max(2,Math
.min(256,numLevels
));
21 var numAreas
= 256 / numLevels
;
22 var numValues
= 256 / (numLevels
-1);
24 var rect
= params
.options
.rect
;
30 var offsetY
= (y
-1)*w4
;
33 var offset
= offsetY
+ (x
-1)*4;
35 var r
= numValues
* ((data
[offset
] / numAreas
)>>0);
36 var g
= numValues
* ((data
[offset
+1] / numAreas
)>>0);
37 var b
= numValues
* ((data
[offset
+2] / numAreas
)>>0);
52 checkSupport : function() {
53 return Pixastic
.Client
.hasCanvasImageData();