Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / libClipEdit / pixastic-lib / actions / lighten.js
blob90381aa86af382ae2e0734ea38ce5b5c178427b7
1 /*
2  * Pixastic Lib - Lighten 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  */
7 Pixastic.Actions.lighten = {
9         process : function(params) {
10                 var amount = parseFloat(params.options.amount) || 0;
12                 if (Pixastic.Client.hasCanvasImageData()) {
13                         var data = Pixastic.prepareData(params);
14                         var rect = params.options.rect;
15                         var w = rect.width;
16                         var h = rect.height;
17                         var w4 = w*4;
18                         var y = h;
19                         do {
20                                 var offsetY = (y-1)*w4;
21                                 var x = w;
22                                 do {
23                                         var offset = offsetY + (x-1)*4;
25                                         var r = data[offset];
26                                         var g = data[offset+1];
27                                         var b = data[offset+2];
29                                         r += r*amount;
30                                         g += g*amount;
31                                         b += b*amount;
33                                         if (r < 0 ) r = 0;
34                                         if (g < 0 ) g = 0;
35                                         if (b < 0 ) b = 0;
36                                         if (r > 255 ) r = 255;
37                                         if (g > 255 ) g = 255;
38                                         if (b > 255 ) b = 255;
40                                         data[offset] = r;
41                                         data[offset+1] = g;
42                                         data[offset+2] = b;
44                                 } while (--x);
45                         } while (--y);
46                         return true;
48                 } else if (Pixastic.Client.isIE()) {
49                         var img = params.image;
50                         if (amount < 0) {
51                                 img.style.filter += " light()";
52                                 img.filters[img.filters.length-1].addAmbient(
53                                         255,255,255,
54                                         100 * -amount
55                                 );
56                         } else if (amount > 0) {
57                                 img.style.filter += " light()";
58                                 img.filters[img.filters.length-1].addAmbient(
59                                         255,255,255,
60                                         100
61                                 );
62                                 img.filters[img.filters.length-1].addAmbient(
63                                         255,255,255,
64                                         100 * amount
65                                 );
66                         }
67                         return true;
68                 }
69         },
70         checkSupport : function() {
71                 return (Pixastic.Client.hasCanvasImageData() || Pixastic.Client.isIE());
72         }