Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / libClipEdit / pixastic-lib / actions / posterize.js
blob1bc629a1a9dab1b284310ba13db6eca4377da163
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  */
7 Pixastic.Actions.posterize = {
9         process : function(params) {
11                 
12                 var numLevels = 256;
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));
20         
21                         var numAreas = 256 / numLevels;
22                         var numValues = 256 / (numLevels-1);
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;
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);
39                                         if (r > 255) r = 255;
40                                         if (g > 255) g = 255;
41                                         if (b > 255) b = 255;
43                                         data[offset] = r;
44                                         data[offset+1] = g;
45                                         data[offset+2] = b;
47                                 } while (--x);
48                         } while (--y);
49                         return true;
50                 }
51         },
52         checkSupport : function() {
53                 return Pixastic.Client.hasCanvasImageData();
54         }