Commit RELEASE-NOTES line for the wgCategories js variable I added some time ago.
[lhc/web/wiklou.git] / js2 / mwEmbed / libClipEdit / pixastic-lib / actions / posterize.js
1 /*
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]
5 */
6
7 Pixastic.Actions.posterize = {
8
9 process : function(params) {
10
11
12 var numLevels = 256;
13 if (typeof params.options.levels != "undefined")
14 numLevels = parseInt(params.options.levels,10)||1;
15
16 if (Pixastic.Client.hasCanvasImageData()) {
17 var data = Pixastic.prepareData(params);
18
19 numLevels = Math.max(2,Math.min(256,numLevels));
20
21 var numAreas = 256 / numLevels;
22 var numValues = 256 / (numLevels-1);
23
24 var rect = params.options.rect;
25 var w = rect.width;
26 var h = rect.height;
27 var w4 = w*4;
28 var y = h;
29 do {
30 var offsetY = (y-1)*w4;
31 var x = w;
32 do {
33 var offset = offsetY + (x-1)*4;
34
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);
38
39 if (r > 255) r = 255;
40 if (g > 255) g = 255;
41 if (b > 255) b = 255;
42
43 data[offset] = r;
44 data[offset+1] = g;
45 data[offset+2] = b;
46
47 } while (--x);
48 } while (--y);
49 return true;
50 }
51 },
52 checkSupport : function() {
53 return Pixastic.Client.hasCanvasImageData();
54 }
55 }
56
57